@amityco/ts-sdk 7.8.0 → 7.8.1-0c348c9.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 (308) hide show
  1. package/.env +26 -26
  2. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts +4 -0
  3. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts.map +1 -1
  4. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.js.map +1 -1
  5. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/content.d.ts +1 -0
  6. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/content.d.ts.map +1 -1
  7. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/content.js.map +1 -1
  8. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts +36 -0
  9. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts.map +1 -1
  10. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js +22 -1
  11. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js.map +1 -1
  12. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.d.ts +11 -0
  13. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.d.ts.map +1 -0
  14. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.js +2 -0
  15. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.js.map +1 -0
  16. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/notification.d.ts +2 -1
  17. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/notification.d.ts.map +1 -1
  18. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/notification.js.map +1 -1
  19. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/poll.d.ts +3 -1
  20. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/poll.d.ts.map +1 -1
  21. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/poll.js.map +1 -1
  22. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts +14 -1
  23. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts.map +1 -1
  24. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.js.map +1 -1
  25. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.d.ts +2 -0
  26. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.d.ts.map +1 -1
  27. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.js +2 -0
  28. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.js.map +1 -1
  29. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.d.ts +16 -0
  30. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.d.ts.map +1 -0
  31. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.js +21 -0
  32. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.js.map +1 -0
  33. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.d.ts +1 -0
  34. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.d.ts.map +1 -1
  35. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.js +1 -0
  36. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.js.map +1 -1
  37. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/commentRepository/api/deleteComment.js +6 -6
  38. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/commentRepository/api/deleteComment.js.map +1 -1
  39. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/core/model/index.d.ts.map +1 -1
  40. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/core/model/index.js +2 -1
  41. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/core/model/index.js.map +1 -1
  42. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/index.d.ts +0 -1
  43. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/index.d.ts.map +1 -1
  44. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/index.js +0 -1
  45. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/index.js.map +1 -1
  46. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.d.ts +3 -0
  47. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
  48. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.js +3 -0
  49. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.js.map +1 -1
  50. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts +2 -1
  51. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts.map +1 -1
  52. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js +2 -1
  53. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js.map +1 -1
  54. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts +13 -0
  55. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts.map +1 -0
  56. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.js +60 -0
  57. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.js.map +1 -0
  58. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts +5 -0
  59. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts.map +1 -0
  60. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.js +13 -0
  61. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.js.map +1 -0
  62. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts +15 -0
  63. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts.map +1 -0
  64. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.js +66 -0
  65. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.js.map +1 -0
  66. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts +22 -0
  67. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts.map +1 -0
  68. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.js +45 -0
  69. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.js.map +1 -0
  70. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts +13 -0
  71. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts.map +1 -0
  72. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.js +60 -0
  73. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.js.map +1 -0
  74. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts +5 -0
  75. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts.map +1 -0
  76. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.js +13 -0
  77. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.js.map +1 -0
  78. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts +15 -0
  79. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts.map +1 -0
  80. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.js +66 -0
  81. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.js.map +1 -0
  82. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.d.ts +22 -0
  83. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.d.ts.map +1 -0
  84. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.js +45 -0
  85. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.js.map +1 -0
  86. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts +13 -0
  87. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +1 -0
  88. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.js +108 -0
  89. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.js.map +1 -0
  90. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +5 -0
  91. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +1 -0
  92. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js +15 -0
  93. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js.map +1 -0
  94. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts +15 -0
  95. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +1 -0
  96. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.js +78 -0
  97. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.js.map +1 -0
  98. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts +23 -0
  99. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts.map +1 -0
  100. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js +46 -0
  101. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js.map +1 -0
  102. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts +4 -0
  103. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts.map +1 -0
  104. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js +4 -0
  105. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js.map +1 -0
  106. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.d.ts +6 -0
  107. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.d.ts.map +1 -0
  108. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.js +60 -0
  109. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.js.map +1 -0
  110. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/pollRepository/api/createPoll.d.ts +3 -3
  111. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/pollRepository/api/createPoll.d.ts.map +1 -1
  112. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/pollRepository/api/createPoll.js +2 -2
  113. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/pollRepository/api/createPoll.js.map +1 -1
  114. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/createPost.d.ts +1 -1
  115. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/createPost.js.map +1 -1
  116. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/editPost.d.ts +1 -1
  117. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/editPost.js.map +1 -1
  118. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/queryPosts.js +2 -2
  119. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/queryPosts.js.map +1 -1
  120. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/events/utils.d.ts.map +1 -1
  121. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/events/utils.js +26 -1
  122. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/events/utils.js.map +1 -1
  123. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts.map +1 -1
  124. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.js +5 -0
  125. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.js.map +1 -1
  126. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts.map +1 -1
  127. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.js +5 -1
  128. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.js.map +1 -1
  129. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts +6 -0
  130. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
  131. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.js +17 -0
  132. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.js.map +1 -1
  133. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
  134. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostLiveCollectionController.js +2 -50
  135. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostLiveCollectionController.js.map +1 -1
  136. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts +14 -0
  137. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
  138. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js +126 -0
  139. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js.map +1 -0
  140. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
  141. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
  142. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js +27 -0
  143. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js.map +1 -0
  144. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts +15 -0
  145. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
  146. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js +65 -0
  147. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js.map +1 -0
  148. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts +1 -0
  149. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts.map +1 -1
  150. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js +1 -0
  151. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js.map +1 -1
  152. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
  153. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
  154. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js +45 -0
  155. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js.map +1 -0
  156. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.d.ts +13 -0
  157. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.d.ts.map +1 -0
  158. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.js +61 -0
  159. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.js.map +1 -0
  160. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  161. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/addReaction.js +1 -1
  162. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/addReaction.js.map +1 -1
  163. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  164. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/removeReaction.js +1 -1
  165. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/removeReaction.js.map +1 -1
  166. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  167. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/utils/linkedObject/postLinkedObject.js +9 -4
  168. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/utils/linkedObject/postLinkedObject.js.map +1 -1
  169. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
  170. package/dist/@types/domains/client.d.ts +4 -0
  171. package/dist/@types/domains/client.d.ts.map +1 -1
  172. package/dist/@types/domains/content.d.ts +1 -0
  173. package/dist/@types/domains/content.d.ts.map +1 -1
  174. package/dist/@types/domains/feed.d.ts +36 -0
  175. package/dist/@types/domains/feed.d.ts.map +1 -1
  176. package/dist/@types/domains/hashtag.d.ts +11 -0
  177. package/dist/@types/domains/hashtag.d.ts.map +1 -0
  178. package/dist/@types/domains/notification.d.ts +2 -1
  179. package/dist/@types/domains/notification.d.ts.map +1 -1
  180. package/dist/@types/domains/poll.d.ts +3 -1
  181. package/dist/@types/domains/poll.d.ts.map +1 -1
  182. package/dist/@types/domains/post.d.ts +14 -1
  183. package/dist/@types/domains/post.d.ts.map +1 -1
  184. package/dist/@types/index.d.ts +2 -0
  185. package/dist/@types/index.d.ts.map +1 -1
  186. package/dist/client/api/getShareableLinkConfiguration.d.ts +16 -0
  187. package/dist/client/api/getShareableLinkConfiguration.d.ts.map +1 -0
  188. package/dist/client/api/index.d.ts +1 -0
  189. package/dist/client/api/index.d.ts.map +1 -1
  190. package/dist/core/model/index.d.ts.map +1 -1
  191. package/dist/feedRepository/api/index.d.ts +0 -1
  192. package/dist/feedRepository/api/index.d.ts.map +1 -1
  193. package/dist/feedRepository/api/queryGlobalFeed.d.ts +3 -0
  194. package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
  195. package/dist/feedRepository/index.d.ts +2 -1
  196. package/dist/feedRepository/index.d.ts.map +1 -1
  197. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts +13 -0
  198. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts.map +1 -0
  199. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts +5 -0
  200. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts.map +1 -0
  201. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts +15 -0
  202. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts.map +1 -0
  203. package/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts +22 -0
  204. package/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts.map +1 -0
  205. package/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts +13 -0
  206. package/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts.map +1 -0
  207. package/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts +5 -0
  208. package/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts.map +1 -0
  209. package/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts +15 -0
  210. package/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts.map +1 -0
  211. package/dist/feedRepository/observers/getGlobalFeed.d.ts +22 -0
  212. package/dist/feedRepository/observers/getGlobalFeed.d.ts.map +1 -0
  213. package/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts +13 -0
  214. package/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +1 -0
  215. package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +5 -0
  216. package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +1 -0
  217. package/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts +15 -0
  218. package/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +1 -0
  219. package/dist/feedRepository/observers/getUserFeed.d.ts +23 -0
  220. package/dist/feedRepository/observers/getUserFeed.d.ts.map +1 -0
  221. package/dist/feedRepository/observers/index.d.ts +4 -0
  222. package/dist/feedRepository/observers/index.d.ts.map +1 -0
  223. package/dist/feedRepository/observers/utils.d.ts +6 -0
  224. package/dist/feedRepository/observers/utils.d.ts.map +1 -0
  225. package/dist/index.cjs.js +2132 -1280
  226. package/dist/index.esm.js +2034 -1182
  227. package/dist/index.umd.js +4 -4
  228. package/dist/pollRepository/api/createPoll.d.ts +3 -3
  229. package/dist/pollRepository/api/createPoll.d.ts.map +1 -1
  230. package/dist/postRepository/api/createPost.d.ts +1 -1
  231. package/dist/postRepository/api/editPost.d.ts +1 -1
  232. package/dist/postRepository/events/utils.d.ts.map +1 -1
  233. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts.map +1 -1
  234. package/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts.map +1 -1
  235. package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts +6 -0
  236. package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
  237. package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
  238. package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts +14 -0
  239. package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
  240. package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
  241. package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
  242. package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts +15 -0
  243. package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
  244. package/dist/postRepository/observers/index.d.ts +1 -0
  245. package/dist/postRepository/observers/index.d.ts.map +1 -1
  246. package/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
  247. package/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
  248. package/dist/postRepository/observers/utils.d.ts +13 -0
  249. package/dist/postRepository/observers/utils.d.ts.map +1 -0
  250. package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  251. package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  252. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  253. package/package.json +1 -1
  254. package/src/@types/domains/client.ts +5 -0
  255. package/src/@types/domains/content.ts +1 -0
  256. package/src/@types/domains/feed.ts +60 -0
  257. package/src/@types/domains/hashtag.ts +11 -0
  258. package/src/@types/domains/notification.ts +1 -0
  259. package/src/@types/domains/poll.ts +3 -1
  260. package/src/@types/domains/post.ts +18 -1
  261. package/src/@types/index.ts +2 -0
  262. package/src/client/api/getShareableLinkConfiguration.ts +26 -0
  263. package/src/client/api/index.ts +2 -0
  264. package/src/commentRepository/api/deleteComment.ts +6 -6
  265. package/src/core/model/index.ts +2 -1
  266. package/src/feedRepository/api/index.ts +0 -1
  267. package/src/feedRepository/api/queryGlobalFeed.ts +3 -0
  268. package/src/feedRepository/index.ts +2 -1
  269. package/src/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.ts +95 -0
  270. package/src/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.ts +25 -0
  271. package/src/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.ts +101 -0
  272. package/src/feedRepository/observers/getCustomRankingGlobalFeed.ts +56 -0
  273. package/src/feedRepository/observers/getGlobalFeed/LiveCollectionController.ts +91 -0
  274. package/src/feedRepository/observers/getGlobalFeed/PaginationController.ts +23 -0
  275. package/src/feedRepository/observers/getGlobalFeed/QueryStreamController.ts +99 -0
  276. package/src/feedRepository/observers/getGlobalFeed.ts +56 -0
  277. package/src/feedRepository/observers/getUserFeed/LiveCollectionController.ts +162 -0
  278. package/src/feedRepository/observers/getUserFeed/PaginationController.ts +37 -0
  279. package/src/feedRepository/observers/getUserFeed/QueryStreamController.ts +119 -0
  280. package/src/feedRepository/observers/getUserFeed.ts +56 -0
  281. package/src/feedRepository/observers/index.ts +3 -0
  282. package/src/feedRepository/observers/utils.ts +85 -0
  283. package/src/pollRepository/api/createPoll.ts +3 -3
  284. package/src/postRepository/api/createPost.ts +1 -1
  285. package/src/postRepository/api/editPost.ts +1 -1
  286. package/src/postRepository/api/queryPosts.ts +2 -2
  287. package/src/postRepository/events/utils.ts +35 -1
  288. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.ts +5 -0
  289. package/src/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.ts +7 -1
  290. package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +27 -0
  291. package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +2 -74
  292. package/src/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.ts +183 -0
  293. package/src/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.ts +49 -0
  294. package/src/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.ts +99 -0
  295. package/src/postRepository/observers/index.ts +1 -0
  296. package/src/postRepository/observers/searchPostsByHashtag.ts +56 -0
  297. package/src/postRepository/observers/utils.ts +97 -0
  298. package/src/reactionRepository/api/addReaction.ts +1 -0
  299. package/src/reactionRepository/api/removeReaction.ts +1 -0
  300. package/src/utils/linkedObject/postLinkedObject.ts +3 -3
  301. package/tsconfig.tsbuildinfo +1 -1
  302. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +0 -37
  303. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +0 -1
  304. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.js +0 -83
  305. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.js.map +0 -1
  306. package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +0 -37
  307. package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +0 -1
  308. package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +0 -115
package/dist/index.cjs.js CHANGED
@@ -153,6 +153,29 @@ exports.JoinResultStatusEnum = void 0;
153
153
  JoinResultStatusEnum["Pending"] = "pending";
154
154
  })(exports.JoinResultStatusEnum || (exports.JoinResultStatusEnum = {}));
155
155
 
156
+ exports.FeedDataTypeEnum = void 0;
157
+ (function (FeedDataTypeEnum) {
158
+ FeedDataTypeEnum["Text"] = "text";
159
+ FeedDataTypeEnum["Video"] = "video";
160
+ FeedDataTypeEnum["Image"] = "image";
161
+ FeedDataTypeEnum["File"] = "file";
162
+ FeedDataTypeEnum["LiveStream"] = "liveStream";
163
+ FeedDataTypeEnum["Clip"] = "clip";
164
+ FeedDataTypeEnum["Poll"] = "poll";
165
+ })(exports.FeedDataTypeEnum || (exports.FeedDataTypeEnum = {}));
166
+ exports.FeedSortByEnum = void 0;
167
+ (function (FeedSortByEnum) {
168
+ FeedSortByEnum["LastCreated"] = "lastCreated";
169
+ FeedSortByEnum["FirstCreated"] = "firstCreated";
170
+ FeedSortByEnum["LastUpdated"] = "lastUpdated";
171
+ FeedSortByEnum["FirstUpdated"] = "firstUpdated";
172
+ })(exports.FeedSortByEnum || (exports.FeedSortByEnum = {}));
173
+ exports.FeedSourceEnum = void 0;
174
+ (function (FeedSourceEnum) {
175
+ FeedSourceEnum["Community"] = "community";
176
+ FeedSourceEnum["User"] = "user";
177
+ })(exports.FeedSourceEnum || (exports.FeedSourceEnum = {}));
178
+
156
179
  function getVersion() {
157
180
  try {
158
181
  // the string ''v7.8.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
@@ -658,7 +681,8 @@ const PAYLOAD2MODEL = {
658
681
  };
659
682
  /** hidden */
660
683
  const isOutdated = (prevData, nextData) => {
661
- if ('updatedAt' in nextData && 'updatedAt' in nextData) {
684
+ // Check if the new value is outdated.
685
+ if ('updatedAt' in nextData && 'updatedAt' in prevData) {
662
686
  return new Date(nextData.updatedAt) < new Date(prevData.updatedAt);
663
687
  }
664
688
  return false;
@@ -9781,6 +9805,26 @@ const fetchLinkPreview = async (url) => {
9781
9805
  return data;
9782
9806
  };
9783
9807
 
9808
+ /**
9809
+ * ```js
9810
+ * import Client from '@amityco/ts-sdk'
9811
+ * const shareableLinkConfiguration = await Client.getShareableLinkConfiguration()
9812
+ * const postLinkPattern = shareableLinkConfiguration.post
9813
+ * ```
9814
+ *
9815
+ * Fetches a {@link Amity.ShareableLinkConfiguration} object
9816
+ *
9817
+ * @returns A Promise of {@link Amity.ShareableLinkConfiguration} object
9818
+ *
9819
+ * @category Client API
9820
+ * @async
9821
+ */
9822
+ const getShareableLinkConfiguration = async () => {
9823
+ const client = getActiveClient();
9824
+ const { data } = await client.http.get(`/api/v3/network-settings/shareable-deep-links`);
9825
+ return data;
9826
+ };
9827
+
9784
9828
  /**
9785
9829
  * ```js
9786
9830
  * import { onChannelMarkerFetched } from '@amityco/ts-sdk'
@@ -10150,6 +10194,7 @@ var index$o = /*#__PURE__*/Object.freeze({
10150
10194
  enableUnreadCount: enableUnreadCount,
10151
10195
  setUploadedFileAccessType: setUploadedFileAccessType,
10152
10196
  fetchLinkPreview: fetchLinkPreview,
10197
+ getShareableLinkConfiguration: getShareableLinkConfiguration,
10153
10198
  onConnectionError: onConnectionError,
10154
10199
  onClientDisconnected: onClientDisconnected,
10155
10200
  onClientBanned: onClientBanned,
@@ -11853,15 +11898,18 @@ function isAmityClipPost(post) {
11853
11898
  }
11854
11899
 
11855
11900
  const postLinkedObject = (post) => {
11856
- return Object.assign(Object.assign({}, post), { childrenPosts: post.children
11901
+ return shallowClone(post, {
11902
+ childrenPosts: post.children
11857
11903
  .map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
11858
11904
  .filter(isNonNullable)
11859
- .map(postLinkedObject), analytics: {
11905
+ .map(postLinkedObject),
11906
+ analytics: {
11860
11907
  markAsViewed: () => {
11861
11908
  const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
11862
11909
  analyticsEngineInstance.markPostAsViewed(post.postId);
11863
11910
  },
11864
- }, get latestComments() {
11911
+ },
11912
+ get latestComments() {
11865
11913
  if (!post.comments)
11866
11914
  return [];
11867
11915
  return (post.comments
@@ -11935,7 +11983,8 @@ const postLinkedObject = (post) => {
11935
11983
  return isAmityClipPost(post)
11936
11984
  ? (_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
11937
11985
  : undefined;
11938
- } });
11986
+ },
11987
+ });
11939
11988
  };
11940
11989
 
11941
11990
  const getCachedMarker = (message) => {
@@ -14930,7 +14979,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
14930
14979
  ]);
14931
14980
  if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
14932
14981
  return true;
14933
- 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 }) });
14982
+ 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() });
14934
14983
  if (referenceType === 'comment') {
14935
14984
  fireEvent('local.comment.addReaction', {
14936
14985
  comment: updatedModel,
@@ -15053,7 +15102,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
15053
15102
  ]);
15054
15103
  if (!model)
15055
15104
  return true;
15056
- 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) }) });
15105
+ 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() });
15057
15106
  if (referenceType === 'comment') {
15058
15107
  fireEvent('local.comment.removeReaction', {
15059
15108
  comment: updatedModel,
@@ -15167,6 +15216,26 @@ const prepareSemanticSearchPostPayload = (_a) => {
15167
15216
  return Object.assign(Object.assign({}, processedPostPayload), { polls });
15168
15217
  };
15169
15218
 
15219
+ const processDeleteChildPost = (payload) => {
15220
+ var _a;
15221
+ const post = payload.posts[0];
15222
+ if (!post.parentId)
15223
+ return;
15224
+ const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
15225
+ if (!parentPost)
15226
+ return;
15227
+ pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: parentPost.children.filter(childId => childId !== post.postId) }));
15228
+ };
15229
+ const processCreateChildPost = (payload) => {
15230
+ var _a;
15231
+ const post = payload.posts[0];
15232
+ if (!post.parentId)
15233
+ return;
15234
+ const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
15235
+ if (!parentPost)
15236
+ return;
15237
+ pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: [...new Set([post.postId, ...parentPost.children])] }));
15238
+ };
15170
15239
  const createPostEventSubscriber = (event, callback) => {
15171
15240
  const client = getActiveClient();
15172
15241
  const filter = (payload) => {
@@ -15191,6 +15260,7 @@ const createPostEventSubscriber = (event, callback) => {
15191
15260
  }
15192
15261
  if (event === 'post.deleted') {
15193
15262
  const { postId, postedUserId } = payload.posts[0];
15263
+ processDeleteChildPost(payload);
15194
15264
  try {
15195
15265
  isInTombstone('post', postId);
15196
15266
  }
@@ -15217,6 +15287,8 @@ const createPostEventSubscriber = (event, callback) => {
15217
15287
  }
15218
15288
  queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
15219
15289
  }
15290
+ if (event === 'post.created')
15291
+ processCreateChildPost(payload);
15220
15292
  callback(post.data);
15221
15293
  }
15222
15294
  };
@@ -15243,6 +15315,8 @@ const createLocalPostEventSubscriber = (event, callback) => {
15243
15315
  });
15244
15316
  }
15245
15317
  const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
15318
+ if (event === 'local.post.deleted')
15319
+ processDeleteChildPost(payload);
15246
15320
  callback(post.data);
15247
15321
  }
15248
15322
  };
@@ -23018,6 +23092,9 @@ var index$b = /*#__PURE__*/Object.freeze({
23018
23092
  id: feed.query.global_feed
23019
23093
  */
23020
23094
  /**
23095
+ *
23096
+ * @deprecated This function will to be deprecated. Please use getGlobalFeed instead.
23097
+ *
23021
23098
  * ```js
23022
23099
  * import { queryGlobalFeed } from '@amityco/ts-sdk'
23023
23100
  * const posts = await queryGlobalFeed()
@@ -23100,1564 +23177,2131 @@ queryGlobalFeed.locally = (query) => {
23100
23177
  : undefined;
23101
23178
  };
23102
23179
 
23103
- /* begin_public_function
23104
- id: feed.query.custom_ranking_feed
23105
- */
23106
- /**
23107
- * ```js
23108
- * import { FeedRepository } from '@amityco/ts-sdk'
23109
- * const posts = await FeedRepository.getCustomRankingGlobalFeed()
23110
- * ```
23111
- *
23112
- * Queries a paginable list of {@link Amity.Post} objects
23113
- *
23114
- * @param query The query parameters
23115
- * @returns A page of {@link Amity.Post} objects
23116
- *
23117
- * @category Feed API
23118
- * @async
23119
- * */
23120
- const getCustomRankingGlobalFeed = async (query) => {
23121
- const client = getActiveClient();
23122
- client.log('feed/getCustomRankingGlobalFeed', query);
23123
- const _a = query !== null && query !== void 0 ? query : {}, { queryToken, limit } = _a, params = __rest(_a, ["queryToken", "limit"]);
23124
- const options = (() => {
23125
- if (queryToken)
23126
- return { token: queryToken };
23127
- return undefined;
23128
- })();
23129
- const { data: queryPayload } = await client.http.get(`/api/v5/me/global-feeds`, {
23130
- params: Object.assign(Object.assign({}, params), { limit: !queryToken ? limit : undefined, options }),
23131
- });
23132
- const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
23133
- const data = prepareMembershipPayload(payload, 'communityUsers');
23134
- const { posts } = data;
23135
- const cachedAt = client.cache && Date.now();
23136
- if (client.cache) {
23137
- ingestInCache(data);
23138
- const cacheKey = ['customGlobalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
23139
- pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
23180
+ class CustomRankingGlobalFeedPaginationController extends PaginationController {
23181
+ async getRequest(queryParams, token) {
23182
+ const { limit } = queryParams, params = __rest(queryParams, ["limit"]);
23183
+ const options = token ? { token } : { limit };
23184
+ const { data: queryResponse } = await this.http.get(`/api/v5/me/global-feeds`, {
23185
+ params: Object.assign(Object.assign({}, params), { options }),
23186
+ });
23187
+ return queryResponse;
23140
23188
  }
23141
- return { data: posts.map(LinkedObject.post), cachedAt, paging };
23142
- };
23143
- /* end_public_function */
23144
- /**
23145
- * ```js
23146
- * import { FeedRepository } from '@amityco/ts-sdk'
23147
- * const posts = await FeedRepository.getCustomRankingGlobalFeed.locally()
23148
- * ```
23149
- *
23150
- * Queries a paginable list of {@link Amity.Post} objects from cache
23151
- *
23152
- * @param query The query parameters
23153
- * @returns A page of {@link Amity.Post} objects
23154
- *
23155
- * @category Feed API
23156
- * @async
23157
- * */
23158
- getCustomRankingGlobalFeed.locally = (query) => {
23159
- var _a, _b;
23160
- const client = getActiveClient();
23161
- client.log('post/getCustomRankingGlobalFeed.locally', query);
23162
- if (!client.cache)
23163
- return;
23164
- const params = __rest(query !== null && query !== void 0 ? query : {}, []);
23165
- const queryKey = ['customGlobalFeed', 'query', Object.assign({}, params)];
23166
- const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
23167
- if (!(data === null || data === void 0 ? void 0 : data.posts.length))
23168
- return;
23169
- const posts = data.posts
23170
- .map(postId => pullFromCache(['post', 'get', postId]))
23171
- .filter(Boolean)
23172
- .map(({ data }) => data);
23173
- const { paging } = data;
23174
- return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
23175
- ? { data: posts.map(LinkedObject.post), cachedAt, paging }
23176
- : undefined;
23177
- };
23189
+ }
23178
23190
 
23179
- var index$a = /*#__PURE__*/Object.freeze({
23180
- __proto__: null,
23181
- queryGlobalFeed: queryGlobalFeed,
23182
- getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
23183
- });
23191
+ var EnumPostActions;
23192
+ (function (EnumPostActions) {
23193
+ EnumPostActions["OnPostCreated"] = "onPostCreated";
23194
+ EnumPostActions["OnPostUpdated"] = "onPostUpdated";
23195
+ EnumPostActions["OnPostDeleted"] = "onPostDeleted";
23196
+ EnumPostActions["OnPostFlagged"] = "onPostFlagged";
23197
+ EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
23198
+ EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
23199
+ EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
23200
+ EnumPostActions["OnPostApproved"] = "onPostApproved";
23201
+ EnumPostActions["OnPostDeclined"] = "onPostDeclined";
23202
+ })(EnumPostActions || (EnumPostActions = {}));
23203
+
23204
+ class CustomRankingGlobalFeedQueryStreamController extends QueryStreamController {
23205
+ constructor(query, cacheKey, notifyChange, preparePayload) {
23206
+ super(query, cacheKey);
23207
+ this.notifyChange = notifyChange;
23208
+ this.preparePayload = preparePayload;
23209
+ }
23210
+ async saveToMainDB(response) {
23211
+ const processedPayload = await this.preparePayload(response);
23212
+ const client = getActiveClient();
23213
+ const cachedAt = client.cache && Date.now();
23214
+ if (client.cache) {
23215
+ ingestInCache(processedPayload, { cachedAt });
23216
+ }
23217
+ }
23218
+ appendToQueryStream(response, direction, refresh = false) {
23219
+ var _a, _b;
23220
+ if (refresh) {
23221
+ pushToCache(this.cacheKey, {
23222
+ data: response.posts.map(getResolver('post')),
23223
+ });
23224
+ }
23225
+ else {
23226
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23227
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
23228
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
23229
+ }
23230
+ }
23231
+ reactor(action) {
23232
+ return (post) => {
23233
+ var _a;
23234
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23235
+ if (!collection)
23236
+ return;
23237
+ if (post.parentPostId && !collection.data.includes(post.parentPostId))
23238
+ return;
23239
+ // Delete Action
23240
+ if (action === EnumPostActions.OnPostDeleted) {
23241
+ // Parent Post - Remove from collection
23242
+ collection.data = collection.data.filter(postId => postId !== post.postId);
23243
+ }
23244
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
23245
+ // If the query has dataTypes array with value, check if post.dataType is include in the array
23246
+ if (this.query.dataTypes && this.query.dataTypes.length > 0) {
23247
+ if (!this.query.dataTypes.includes(post.dataType))
23248
+ return;
23249
+ }
23250
+ collection.data = [...new Set([post.postId, ...collection.data])];
23251
+ }
23252
+ if (action === EnumPostActions.OnPostDeclined) {
23253
+ collection.data = collection.data.filter(postId => postId !== post.postId);
23254
+ }
23255
+ pushToCache(this.cacheKey, collection);
23256
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
23257
+ };
23258
+ }
23259
+ subscribeRTE(createSubscriber) {
23260
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
23261
+ }
23262
+ }
23184
23263
 
23185
23264
  /* begin_public_function
23186
- id: post.get_by_ids
23265
+ id: comment.get_by_ids
23187
23266
  */
23188
23267
  /**
23189
23268
  * ```js
23190
- * import { getPostByIds } from '@amityco/ts-sdk'
23191
- * const { data: posts } = await getPostByIds(['foo', 'bar'])
23269
+ * import { CommentRepository } from '@amityco/ts-sdk'
23270
+ * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
23192
23271
  * ```
23193
23272
  *
23194
- * Fetches a collection of {@link Amity.Post} objects
23273
+ * Fetches a collection of {@link Amity.Comment} objects
23195
23274
  *
23196
- * @param postIds the IDs of the {@link Amity.Post} to fetch
23197
- * @returns the associated collection of {@link Amity.Post} objects
23275
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
23276
+ * @returns the associated collection of {@link Amity.Comment} objects
23198
23277
  *
23199
- * @category Post API
23278
+ * @category Comment API
23200
23279
  * @async
23201
23280
  */
23202
- const getPostByIds = async (postIds) => {
23281
+ const getCommentByIds = async (commentIds) => {
23203
23282
  const client = getActiveClient();
23204
- client.log('post/getPostByIds', postIds);
23205
- const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
23206
- let payload;
23283
+ client.log('comment/getCommentByIds', commentIds);
23284
+ const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
23285
+ let data;
23207
23286
  try {
23208
23287
  // API-FIX: endpoint should not be /list, parameters should be querystring.
23209
- const response = await client.http.get(`/api/v3/posts/list`, {
23210
- params: { postIds: encodedPostIds },
23288
+ const response = await client.http.get(`/api/v3/comments/list`, {
23289
+ params: { commentIds: encodedCommentIds },
23211
23290
  });
23212
- payload = response.data;
23291
+ data = response.data;
23213
23292
  }
23214
23293
  catch (error) {
23215
- postIds.forEach(postId => {
23294
+ commentIds.forEach(commentId => {
23216
23295
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23217
- pushToTombstone('post', postId);
23296
+ pushToTombstone('comment', commentId);
23218
23297
  }
23219
23298
  });
23220
23299
  throw error;
23221
23300
  }
23222
- const data = prepareMembershipPayload(payload, 'communityUsers');
23223
23301
  const cachedAt = client.cache && Date.now();
23224
23302
  if (client.cache)
23225
23303
  ingestInCache(data, { cachedAt });
23226
23304
  return {
23227
- data: data.posts.map(LinkedObject.post),
23305
+ data: data.comments.map(comment => LinkedObject.comment(comment)),
23228
23306
  cachedAt,
23229
23307
  };
23230
23308
  };
23231
23309
  /* end_public_function */
23232
23310
  /**
23233
23311
  * ```js
23234
- * import { getPostByIds } from '@amityco/ts-sdk'
23235
- * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
23312
+ * import { getCommentByIds } from '@amityco/ts-sdk'
23313
+ * const comments = getCommentByIds.locally(['foo', 'bar'])
23236
23314
  * ```
23237
23315
  *
23238
- * Fetches a collection of {@link Amity.Post} objects from cache
23316
+ * Fetches a collection of {@link Amity.Comment} objects from cache
23239
23317
  *
23240
- * @param postIds the IDs of the {@link Amity.Post} to fetch
23241
- * @returns the associated collection of {@link Amity.Post} objects
23318
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
23319
+ * @returns the associated collection of {@link Amity.Comment} objects
23242
23320
  *
23243
- * @category Post API
23321
+ * @category Comment API
23244
23322
  */
23245
- getPostByIds.locally = (postIds) => {
23323
+ getCommentByIds.locally = (commentIds) => {
23246
23324
  var _a;
23247
23325
  const client = getActiveClient();
23248
- client.log('post/getPostByIds.locally', postIds);
23326
+ client.log('comment/getCommentByIds.locally', commentIds);
23249
23327
  if (!client.cache)
23250
23328
  return;
23251
- const cached = postIds
23252
- .map(postId => pullFromCache(['post', 'get', postId]))
23329
+ const cached = commentIds
23330
+ .map(commentId => pullFromCache(['comment', 'get', commentId]))
23253
23331
  .filter(Boolean);
23254
- const posts = cached.map(({ data }) => data);
23332
+ const comments = cached.map(({ data }) => data);
23255
23333
  const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
23256
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
23334
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
23257
23335
  return;
23258
23336
  return {
23259
- data: posts.map(LinkedObject.post),
23337
+ data: comments.map(comment => LinkedObject.comment(comment)),
23260
23338
  cachedAt: oldest.cachedAt,
23261
23339
  };
23262
23340
  };
23263
23341
 
23264
23342
  /* begin_public_function
23265
- 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
23343
+ id: comment.create
23266
23344
  */
23267
23345
  /**
23268
23346
  * ```js
23269
- * import { PostRepository } from '@amityco/ts-sdk'
23270
- * const created = await PostRepository.createPost({
23271
- * targetType: 'user',
23272
- * targetId: 'foobar',
23273
- * data: { text: 'hello world' }
23274
- * }))
23347
+ * import { CommentRepository } from '@amityco/ts-sdk'
23348
+ * const newComment = await CommentRepository.createComment(bundle)
23275
23349
  * ```
23276
23350
  *
23277
- * Creates an {@link Amity.Post}
23351
+ * Creates an {@link Amity.Comment}
23278
23352
  *
23279
- * @param bundle The data necessary to create a new {@link Amity.Post}
23280
- * @returns The newly created {@link Amity.Post}
23353
+ * @param bundle The data necessary to create a new {@link Amity.Comment}
23354
+ * @returns The newly created {@link Amity.Comment}
23281
23355
  *
23282
- * @category Post API
23356
+ * @category Comment API
23283
23357
  * @async
23284
23358
  */
23285
- const createPost = async (bundle) => {
23359
+ const createComment = async (bundle) => {
23360
+ var _a;
23286
23361
  const client = getActiveClient();
23287
- client.log('post/createPost', bundle);
23288
- if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
23289
- // eslint-disable-next-line no-param-reassign
23290
- delete bundle.dataType;
23291
- }
23292
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
23293
- fireEvent('post.created', payload);
23294
- const data = preparePostPayload(payload);
23295
- const cachedAt = client.cache && Date.now();
23296
- if (client.cache)
23362
+ client.log('comment/createComment', bundle);
23363
+ const { data } = await client.http.post('/api/v3/comments', bundle);
23364
+ const { comments } = data;
23365
+ // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
23366
+ if (comments.length === 0)
23367
+ throw new Error('Comment not created');
23368
+ const cachedAt = client.cache && Date.now();
23369
+ if (client.cache)
23297
23370
  ingestInCache(data, { cachedAt });
23298
- const { posts } = data;
23371
+ if (['post', 'content'].includes(bundle.referenceType)) {
23372
+ const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
23373
+ if (post) {
23374
+ post.commentsCount += 1;
23375
+ fireEvent('local.post.updated', {
23376
+ posts: [post],
23377
+ categories: [],
23378
+ comments: [],
23379
+ communities: [],
23380
+ communityUsers: data.communityUsers,
23381
+ feeds: [],
23382
+ files: data.files,
23383
+ postChildren: [],
23384
+ users: data.users,
23385
+ videoStreamings: [],
23386
+ });
23387
+ }
23388
+ }
23389
+ else if (bundle.referenceType === 'story') {
23390
+ const storyIndex = pullFromCache([
23391
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23392
+ bundle.referenceId,
23393
+ ]);
23394
+ if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
23395
+ const cacheStory = pullFromCache([
23396
+ "story" /* STORY_KEY_CACHE.STORY */,
23397
+ 'get',
23398
+ storyIndex.data,
23399
+ ]);
23400
+ if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
23401
+ fireEvent('story.updated', {
23402
+ stories: [
23403
+ Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
23404
+ ],
23405
+ categories: [],
23406
+ comments,
23407
+ communities: [],
23408
+ communityUsers: data.communityUsers,
23409
+ files: data.files,
23410
+ users: data.users,
23411
+ });
23412
+ }
23413
+ }
23414
+ }
23415
+ fireEvent('local.comment.created', data);
23299
23416
  return {
23300
- data: LinkedObject.post(posts[0]),
23417
+ data: LinkedObject.comment(comments[0]),
23301
23418
  cachedAt,
23302
23419
  };
23303
23420
  };
23304
23421
  /* end_public_function */
23305
23422
 
23306
23423
  /* begin_public_function
23307
- id: post.edit, post.edit.custom_post
23424
+ id: comment.update_comment
23308
23425
  */
23309
23426
  /**
23310
23427
  * ```js
23311
- * import { PostRepository } from '@amityco/ts-sdk'
23312
- * const updated = await PostRepository.editPost(postId, {
23428
+ * import { CommentRepository } from '@amityco/ts-sdk'
23429
+ * const updated = await CommentRepository.updateComment(commentId, {
23313
23430
  * data: { text: 'hello world' }
23314
23431
  * })
23315
23432
  * ```
23316
23433
  *
23317
- * Updates an {@link Amity.Post}
23434
+ * Updates an {@link Amity.Comment}
23318
23435
  *
23319
- * @param postId The ID of the {@link Amity.Post} to edit
23436
+ * @param commentId The ID of the {@link Amity.Comment} to edit
23320
23437
  * @param patch The patch data to apply
23321
- * @returns the updated {@link Amity.Post} object
23438
+ * @returns the updated {@link Amity.Comment} object
23322
23439
  *
23323
- * @category Post API
23440
+ * @category Comment API
23324
23441
  * @async
23325
23442
  */
23326
- const editPost = async (postId, patch) => {
23443
+ const updateComment = async (commentId, patch) => {
23327
23444
  const client = getActiveClient();
23328
- client.log('user/editPost', patch);
23329
- const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
23330
- const data = prepareMembershipPayload(payload, 'communityUsers');
23445
+ client.log('user/updateComment', patch);
23446
+ const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
23331
23447
  const cachedAt = client.cache && Date.now();
23332
23448
  if (client.cache)
23333
23449
  ingestInCache(data, { cachedAt });
23334
- fireEvent('local.post.updated', data);
23335
- const { posts } = data;
23450
+ fireEvent('comment.updated', data);
23451
+ const { comments } = data;
23336
23452
  return {
23337
- data: LinkedObject.post(posts.find(post => post.postId === postId)),
23453
+ data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
23338
23454
  cachedAt,
23339
23455
  };
23340
23456
  };
23341
23457
  /* end_public_function */
23342
23458
 
23459
+ // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
23460
+ const applyMissingField = (rawData, isCreated = false) => {
23461
+ const { storyId, referenceId } = rawData;
23462
+ if (!isCreated) {
23463
+ if (referenceId)
23464
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
23465
+ }
23466
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
23467
+ };
23468
+ const convertRawStoryToInternal = (data, isCreated = false) => {
23469
+ const { stories } = data;
23470
+ const storiesData = stories.map(story => applyMissingField(story, isCreated));
23471
+ return Object.assign(Object.assign({}, data), { stories: storiesData });
23472
+ };
23473
+
23474
+ const getStoryByStoryId$1 = async (storyId) => {
23475
+ const client = getActiveClient();
23476
+ client.log('story/getStoryByStoryId', storyId);
23477
+ // Get story referenceId from cache
23478
+ const cacheReferenceId = pullFromCache([
23479
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23480
+ storyId,
23481
+ ]);
23482
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
23483
+ const { data: referenceId } = cacheReferenceId;
23484
+ isInTombstone('story', referenceId);
23485
+ }
23486
+ let data;
23487
+ try {
23488
+ const response = await client.http.get(`/api/v4/stories/${storyId}`);
23489
+ data = convertRawStoryToInternal(response.data);
23490
+ }
23491
+ catch (error) {
23492
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23493
+ pushToTombstone('story', storyId);
23494
+ }
23495
+ throw error;
23496
+ }
23497
+ const cachedAt = client.cache && Date.now();
23498
+ if (client.cache) {
23499
+ ingestInCache(data, { cachedAt });
23500
+ }
23501
+ return {
23502
+ data: data.stories[0],
23503
+ cachedAt,
23504
+ };
23505
+ };
23506
+ getStoryByStoryId$1.locally = (storyId) => {
23507
+ const client = getActiveClient();
23508
+ client.log('story/getStorybyStoryId', storyId);
23509
+ // Get story referenceId from cache
23510
+ const cacheReferenceId = pullFromCache([
23511
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23512
+ storyId,
23513
+ ]);
23514
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
23515
+ const { data: referenceId } = cacheReferenceId;
23516
+ isInTombstone('story', referenceId);
23517
+ }
23518
+ const cachedAt = client.cache && Date.now();
23519
+ const storyCache = pullFromCache(['story', 'get', storyId]);
23520
+ if (!storyCache)
23521
+ return;
23522
+ return {
23523
+ data: storyCache.data,
23524
+ cachedAt,
23525
+ };
23526
+ };
23527
+
23528
+ /* begin_public_function
23529
+ id: comment.soft_delete, comment.hard_delete
23530
+ */
23343
23531
  /**
23344
23532
  * ```js
23345
- * import { deletePost } from '@amityco/ts-sdk'
23346
- * const success = await deletePost('foobar')
23533
+ * import { CommentRepository } from '@amityco/ts-sdk'
23534
+ * const success = await CommentRepository.deleteComment('foobar')
23347
23535
  * ```
23348
23536
  *
23349
- * Deletes a {@link Amity.Post}
23537
+ * Deletes a {@link Amity.Comment}
23350
23538
  *
23351
- * @param postId The {@link Amity.Post} ID to delete
23352
- * @return A success boolean if the {@link Amity.Post} was deleted
23539
+ * @param commentId The {@link Amity.Comment} ID to delete
23540
+ * @return A success boolean if the {@link Amity.Comment} was deleted
23353
23541
  *
23354
- * @private
23542
+ * @category Comment API
23355
23543
  * @async
23356
23544
  */
23357
- const deletePost = async (postId, permanent = false) => {
23545
+ const deleteComment = async (commentId, permanent = false) => {
23358
23546
  var _a;
23359
23547
  const client = getActiveClient();
23360
- const post = await getPost$2(postId);
23361
- await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
23548
+ const comment = await getComment$2(commentId);
23549
+ // API-FIX: This endpoint has not been implemented yet.
23550
+ await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
23362
23551
  params: {
23363
- postId,
23552
+ commentId,
23364
23553
  permanent,
23365
23554
  },
23366
23555
  });
23367
- // there is currently a limitation which doesn't allow us to fire event to tell that community
23368
- // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
23369
- // and so we cannot refetch the community or advertise on events. hopefully this should be solved
23370
- // later when realtime events covers that for us.
23371
- if (post.data.targetType === 'community') {
23372
- const community = await getCommunity$1(post.data.targetId);
23373
- const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
23374
- const communityUsers = communityUsersCache
23375
- .filter(({ key }) => {
23376
- // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
23377
- if (key[0] !== 'communityUsers')
23378
- return false;
23379
- if (key[1] !== 'get')
23380
- return false;
23381
- if (typeof key[2] === 'string')
23382
- return key[2].includes(community.data.communityId);
23383
- return false;
23384
- })
23385
- .map(({ data }) => data);
23386
- fireEvent('community.updated', {
23387
- communities: [community.data],
23556
+ // to support hard deletion
23557
+ const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
23558
+ if (permanent) {
23559
+ scheduleTask(() => pushToTombstone('comment', commentId));
23560
+ }
23561
+ else {
23562
+ upsertInCache(['comment', 'get', commentId], { isDeleted: true });
23563
+ }
23564
+ if (comment.data.referenceType === 'story') {
23565
+ const story = await getStoryByStoryId$1(comment.data.referenceId);
23566
+ fireEvent('local.story.updated', {
23567
+ stories: [story.data],
23388
23568
  categories: [],
23389
- communityUsers,
23390
- feeds: [],
23569
+ comments: [],
23570
+ communities: [],
23571
+ communityUsers: [],
23391
23572
  files: [],
23392
23573
  users: [],
23393
23574
  });
23394
23575
  }
23395
- // to support hard deletion
23396
- const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
23397
- if (permanent) {
23398
- setTimeout(() => {
23399
- pushToTombstone('post', postId);
23400
- }, 0);
23401
- }
23402
23576
  else {
23403
- upsertInCache(['post', 'get', postId], { isDeleted: true });
23577
+ const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
23578
+ if (post) {
23579
+ let removeCount;
23580
+ if (!deleted.parentId) {
23581
+ // NOTE: delete the parent comment will remove all children comments
23582
+ removeCount = deleted.childrenNumber + 1;
23583
+ }
23584
+ else
23585
+ removeCount = 1;
23586
+ post.commentsCount -= removeCount;
23587
+ fireEvent('local.post.updated', {
23588
+ posts: [post],
23589
+ categories: [],
23590
+ comments: [],
23591
+ communities: [],
23592
+ communityUsers: [],
23593
+ feeds: [],
23594
+ files: [],
23595
+ postChildren: [],
23596
+ users: [],
23597
+ videoStreamings: [],
23598
+ });
23599
+ }
23404
23600
  }
23405
- fireEvent('local.post.deleted', {
23406
- posts: [deleted],
23407
- categories: [],
23408
- comments: [],
23409
- communities: [],
23410
- communityUsers: [],
23411
- feeds: [],
23601
+ fireEvent('local.comment.deleted', {
23602
+ comments: [deleted],
23603
+ commentChildren: [],
23412
23604
  files: [],
23413
- postChildren: [],
23414
23605
  users: [],
23415
- videoStreamings: [],
23606
+ communityUsers: [],
23416
23607
  });
23417
- return LinkedObject.post(deleted);
23418
- };
23419
-
23420
- /* begin_public_function
23421
- id: post.soft_delete
23422
- */
23423
- /**
23424
- * ```js
23425
- * import { PostRepository } from '@amityco/ts-sdk'
23426
- * const success = await PostRepository.softDeletePost('foobar')
23427
- * ```
23428
- *
23429
- * Soft deletes a {@link Amity.Post}
23430
- *
23431
- * @param postId The {@link Amity.Post} ID to soft delete
23432
- * @return A success boolean if the {@link Amity.Post} was deleted
23433
- *
23434
- * @category Post API
23435
- * @async
23436
- */
23437
- const softDeletePost = async (postId) => {
23438
- const client = getActiveClient();
23439
- client.log('post/softDeletePost', postId);
23440
- const softDeleted = await deletePost(postId, false);
23441
- return LinkedObject.post(softDeleted);
23442
- };
23443
- /* end_public_function */
23444
-
23445
- /* begin_public_function
23446
- id: post.hard_delete
23447
- */
23448
- /**
23449
- * ```js
23450
- * import { hardDeletePost } from '@amityco/ts-sdk'
23451
- * const success = await hardDeletePost('foobar')
23452
- * ```
23453
- *
23454
- * Hard deletes a {@link Amity.Post}
23455
- *
23456
- * @param postId The {@link Amity.Post} ID to be hard delete
23457
- * @return A success boolean if the {@link Amity.Post} was deleted
23458
- *
23459
- * @category Post API
23460
- * @async
23461
- */
23462
- const hardDeletePost = async (postId) => {
23463
- const client = getActiveClient();
23464
- client.log('post/hardDeletePost', postId);
23465
- const hardDeleted = await deletePost(postId, true);
23466
- return LinkedObject.post(hardDeleted);
23608
+ return deleted;
23467
23609
  };
23468
23610
  /* end_public_function */
23469
23611
 
23470
23612
  /* begin_public_function
23471
- id: post.approve
23613
+ id: comment.soft_delete
23472
23614
  */
23473
23615
  /**
23474
23616
  * ```js
23475
- * import { approvePost } from '@amityco/ts-sdk'
23476
- *
23477
- * const { data: post } = await approvePost('postId')
23617
+ * import { CommentRepository } from '@amityco/ts-sdk'
23618
+ * const success = await CommentRepository.softDeleteComment('foobar')
23478
23619
  * ```
23479
23620
  *
23480
- * Approves a {@link Amity.Post}
23621
+ * Deletes a {@link Amity.Comment}
23481
23622
  *
23482
- * @param postId The {@link Amity.Post} ID to be approved
23483
- * @return A {@link Amity.Post} that was approved
23623
+ * @param commentId The {@link Amity.Comment} ID to delete
23624
+ * @return A success boolean if the {@link Amity.Comment} was deleted
23484
23625
  *
23485
- * @category Post API
23626
+ * @category Comment API
23486
23627
  * @async
23487
23628
  */
23488
- const approvePost = async (postId) => {
23629
+ const softDeleteComment = async (commentId) => {
23489
23630
  const client = getActiveClient();
23490
- client.log('post/approvePost', postId);
23491
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
23492
- fireEvent('post.approved', payload);
23493
- // fire virtual event for community update
23494
- if (payload.posts[0].targetType === 'community') {
23495
- fireEvent('community.updated', payload);
23496
- }
23497
- const data = prepareMembershipPayload(payload, 'communityUsers');
23498
- const cachedAt = client.cache && Date.now();
23499
- if (client.cache)
23500
- ingestInCache(data, { cachedAt });
23501
- return {
23502
- data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
23503
- cachedAt,
23504
- };
23631
+ client.log('comment/softDeleteComment', commentId);
23632
+ const softDeleted = deleteComment(commentId);
23633
+ return softDeleted;
23505
23634
  };
23506
23635
  /* end_public_function */
23507
23636
 
23508
23637
  /* begin_public_function
23509
- id: post.decline
23638
+ id: comment.hard_delete
23510
23639
  */
23511
23640
  /**
23512
23641
  * ```js
23513
- * import { declinePost } from '@amityco/ts-sdk'
23514
- *
23515
- * const {data: post} = await declinePost('postId')
23642
+ * import { CommentRepository } from '@amityco/ts-sdk'
23643
+ * const success = await CommentRepository.hardDeleteComment('foobar')
23516
23644
  * ```
23517
23645
  *
23518
- * Declines a {@link Amity.Post}
23646
+ * Deletes a {@link Amity.Comment}
23519
23647
  *
23520
- * @param postId The {@link Amity.Post} ID to be declined
23521
- * @return A {@link Amity.Post} that was declined
23648
+ * @param commentId The {@link Amity.Comment} ID to delete
23649
+ * @return A success boolean if the {@link Amity.Comment} was deleted
23522
23650
  *
23523
- * @category Post API
23651
+ * @category Comment API
23524
23652
  * @async
23525
23653
  */
23526
- const declinePost = async (postId) => {
23654
+ const hardDeleteComment = async (commentId) => {
23527
23655
  const client = getActiveClient();
23528
- client.log('post/declinePost', postId);
23529
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
23530
- // fire virtual event
23531
- if (payload.posts[0].targetType === 'community') {
23532
- fireEvent('community.updated', payload);
23533
- }
23534
- fireEvent('post.declined', payload);
23535
- const data = prepareMembershipPayload(payload, 'communityUsers');
23536
- const cachedAt = client.cache && Date.now();
23537
- if (client.cache)
23538
- ingestInCache(data, { cachedAt });
23539
- return {
23540
- data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
23541
- cachedAt,
23542
- };
23656
+ client.log('comment/hardDeleteComment', commentId);
23657
+ const hardDeleted = deleteComment(commentId, true);
23658
+ return hardDeleted;
23543
23659
  };
23544
23660
  /* end_public_function */
23545
23661
 
23546
23662
  /* begin_public_function
23547
- id: post.flag
23663
+ id: comment.flag
23548
23664
  */
23549
23665
  /**
23550
23666
  * ```js
23551
- * import { PostRepository } from '@amityco/ts-sdk'
23552
- * const flagged = await PostRepository.flagPost(postId, reason)
23667
+ * import { CommentRepository } from '@amityco/ts-sdk'
23668
+ * const flagged = await CommentRepository.flagComment(commentId, reason)
23553
23669
  * ```
23554
23670
  *
23555
- * @param postId of the post to flag
23556
- * @param reason the reason to flag the post
23557
- * @returns a boolean
23671
+ * @param commentId The ID of the comment to flag
23672
+ * @param reason the reason to flag the comment
23673
+ * @returns the created report result
23558
23674
  *
23559
- * @category Post API
23675
+ * @category Comment API
23560
23676
  * @async
23561
23677
  * */
23562
- const flagPost = async (postId, reason) => {
23678
+ const flagComment = async (commentId, reason) => {
23563
23679
  const client = getActiveClient();
23564
- client.log('post/flagPost', postId);
23680
+ client.log('comment/flagComment', commentId);
23565
23681
  const isPredefinedReason = reason &&
23566
23682
  Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
23567
23683
  const body = {
23568
23684
  reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
23569
23685
  detail: reason && !isPredefinedReason ? reason : '',
23570
23686
  };
23571
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
23687
+ const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
23572
23688
  if (client.cache) {
23573
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
23689
+ ingestInCache(payload);
23574
23690
  }
23575
- fireEvent('post.flagged', payload);
23691
+ fireEvent('comment.flagged', payload);
23576
23692
  return !!payload;
23577
23693
  };
23578
23694
  /* end_public_function */
23579
23695
 
23580
23696
  /* begin_public_function
23581
- id: post.unflag
23697
+ id: comment.unflag
23582
23698
  */
23583
23699
  /**
23584
23700
  * ```js
23585
- * import { PostRepository } from '@amityco/ts-sdk'
23586
- * const unflagged = await PostRepository.unflagPost(postId)
23701
+ * import { CommentRepository } from '@amityco/ts-sdk'
23702
+ * const unflagged = await CommentRepository.unflagComment('commentId')
23587
23703
  * ```
23588
23704
  *
23589
- * @param postId of the post to unflag
23590
- * @returns the unflag post result
23705
+ * @param commentId The ID of comment to unflag
23706
+ * @returns the unflagged result
23591
23707
  *
23592
- * @category Post API
23708
+ * @category Comment API
23593
23709
  * @async
23594
23710
  * */
23595
- const unflagPost = async (postId) => {
23711
+ const unflagComment = async (commentId) => {
23596
23712
  const client = getActiveClient();
23597
- client.log('post/unflagPost', postId);
23598
- const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
23713
+ client.log('comment/unflagComment', commentId);
23714
+ const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
23599
23715
  if (client.cache) {
23600
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
23716
+ ingestInCache(payload);
23601
23717
  }
23602
- fireEvent('post.unflagged', payload);
23718
+ fireEvent('comment.unflagged', payload);
23603
23719
  return !!payload;
23604
23720
  };
23605
23721
  /* end_public_function */
23606
23722
 
23607
23723
  /* begin_public_function
23608
- id: post.check_flag_by_me
23724
+ id: comment.check_flag_by_me
23609
23725
  */
23610
23726
  /**
23611
23727
  * ```js
23612
- * import { PostRepository } from '@amityco/ts-sdk'
23613
- * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
23728
+ * import { CommentRepository } from '@amityco/ts-sdk'
23729
+ * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
23614
23730
  * ```
23615
23731
  *
23616
- * @param postId of the post to check if flagged by current user
23617
- * @returns `true` if the post is flagged by me, `false` if doesn't.
23732
+ * @param commentId The ID of the comment to check if flagged by current user
23733
+ * @returns `true` if the comment is flagged by me, `false` if doesn't.
23618
23734
  *
23619
- * @category Post API
23735
+ * @category Comment API
23620
23736
  * @async
23621
23737
  * */
23622
- const isPostFlaggedByMe = async (postId) => {
23738
+ const isCommentFlaggedByMe = async (commentId) => {
23623
23739
  const client = getActiveClient();
23624
- client.log('post/isPostFlaggedByMe', postId);
23625
- const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
23740
+ client.log('comment/isCommentFlaggedByMe', commentId);
23741
+ const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
23626
23742
  return result;
23627
23743
  };
23628
23744
  /* end_public_function */
23629
23745
 
23630
- /* begin_public_function
23631
- id: post.create.clip_post
23632
- */
23633
- /**
23634
- * ```js
23635
- * import { PostRepository } from '@amityco/ts-sdk'
23636
- * const created = await PostRepository.createClipPost({
23637
- * targetType: 'user',
23638
- * targetId: 'foobar',
23639
- * dataType: 'clip',
23640
- * data: { text: 'hello world' },
23641
- * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
23642
- * }))
23643
- * ```
23644
- *
23645
- * Creates an {@link Amity.Post}
23646
- *
23647
- * @param bundle The data necessary to create a new {@link Amity.Post}
23648
- * @returns The newly created {@link Amity.Post}
23649
- *
23650
- * @category Post API
23651
- * @async
23652
- */
23653
- const createClipPost = async (bundle) => {
23746
+ const getComment$1 = async (commentId) => {
23654
23747
  const client = getActiveClient();
23655
- client.log('post/createPost', bundle);
23656
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
23657
- fireEvent('post.created', payload);
23658
- const data = prepareMembershipPayload(payload, 'communityUsers');
23748
+ client.log('comment/getComment', commentId);
23749
+ isInTombstone('comment', commentId);
23750
+ let data;
23751
+ try {
23752
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
23753
+ const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
23754
+ data = response.data;
23755
+ }
23756
+ catch (error) {
23757
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23758
+ pushToTombstone('comment', commentId);
23759
+ }
23760
+ throw error;
23761
+ }
23659
23762
  const cachedAt = client.cache && Date.now();
23660
23763
  if (client.cache)
23661
23764
  ingestInCache(data, { cachedAt });
23662
- const { posts } = data;
23765
+ const { comments } = data;
23663
23766
  return {
23664
- data: LinkedObject.post(posts[0]),
23767
+ data: comments.find(comment => comment.commentId === commentId),
23665
23768
  cachedAt,
23666
23769
  };
23667
23770
  };
23668
- /* end_public_function */
23771
+ getComment$1.locally = (commentId) => {
23772
+ const client = getActiveClient();
23773
+ client.log('comment/getComment.locally', commentId);
23774
+ if (!client.cache)
23775
+ return;
23776
+ const cached = pullFromCache(['comment', 'get', commentId]);
23777
+ if (!cached)
23778
+ return;
23779
+ return {
23780
+ data: cached.data,
23781
+ cachedAt: cached.cachedAt,
23782
+ };
23783
+ };
23669
23784
 
23670
- /* begin_public_function
23671
- id: comment.get_by_ids
23672
- */
23673
23785
  /**
23674
23786
  * ```js
23675
- * import { CommentRepository } from '@amityco/ts-sdk'
23676
- * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
23677
- * ```
23678
- *
23679
- * Fetches a collection of {@link Amity.Comment} objects
23787
+ * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
23788
+ * const dispose = onCommentDeleteLocal(comment => {
23789
+ * // ...
23790
+ * })
23791
+ * ```
23680
23792
  *
23681
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
23682
- * @returns the associated collection of {@link Amity.Comment} objects
23793
+ * Fired when a {@link Amity.InternalComment} has been deleted
23683
23794
  *
23684
- * @category Comment API
23685
- * @async
23795
+ * @param callback The function to call when the event was fired
23796
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23797
+ *
23798
+ * @category Comment Events
23686
23799
  */
23687
- const getCommentByIds = async (commentIds) => {
23688
- const client = getActiveClient();
23689
- client.log('comment/getCommentByIds', commentIds);
23690
- const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
23691
- let data;
23692
- try {
23693
- // API-FIX: endpoint should not be /list, parameters should be querystring.
23694
- const response = await client.http.get(`/api/v3/comments/list`, {
23695
- params: { commentIds: encodedCommentIds },
23696
- });
23697
- data = response.data;
23698
- }
23699
- catch (error) {
23700
- commentIds.forEach(commentId => {
23701
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23702
- pushToTombstone('comment', commentId);
23703
- }
23704
- });
23705
- throw error;
23706
- }
23707
- const cachedAt = client.cache && Date.now();
23708
- if (client.cache)
23709
- ingestInCache(data, { cachedAt });
23710
- return {
23711
- data: data.comments.map(comment => LinkedObject.comment(comment)),
23712
- cachedAt,
23713
- };
23714
- };
23715
- /* end_public_function */
23800
+ const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
23801
+
23716
23802
  /**
23717
23803
  * ```js
23718
- * import { getCommentByIds } from '@amityco/ts-sdk'
23719
- * const comments = getCommentByIds.locally(['foo', 'bar'])
23804
+ * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
23805
+ * const dispose = onLocalCommentReactionAdded(comment => {
23806
+ * // ...
23807
+ * })
23720
23808
  * ```
23721
23809
  *
23722
- * Fetches a collection of {@link Amity.Comment} objects from cache
23810
+ * Fired when a {@link Amity.InternalComment} has been reacted
23723
23811
  *
23724
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
23725
- * @returns the associated collection of {@link Amity.Comment} objects
23812
+ * @param callback The function to call when the event was fired
23813
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23726
23814
  *
23727
- * @category Comment API
23815
+ * @category Comment Events
23728
23816
  */
23729
- getCommentByIds.locally = (commentIds) => {
23730
- var _a;
23817
+ const onLocalCommentReactionAdded = (callback) => {
23731
23818
  const client = getActiveClient();
23732
- client.log('comment/getCommentByIds.locally', commentIds);
23733
- if (!client.cache)
23734
- return;
23735
- const cached = commentIds
23736
- .map(commentId => pullFromCache(['comment', 'get', commentId]))
23737
- .filter(Boolean);
23738
- const comments = cached.map(({ data }) => data);
23739
- const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
23740
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
23741
- return;
23742
- return {
23743
- data: comments.map(comment => LinkedObject.comment(comment)),
23744
- cachedAt: oldest.cachedAt,
23819
+ const filter = ({ comment }) => {
23820
+ if (!client.cache) {
23821
+ callback(comment);
23822
+ }
23823
+ else {
23824
+ upsertInCache(['comment', 'get', comment.commentId], comment);
23825
+ callback(commentLinkedObject(comment));
23826
+ }
23745
23827
  };
23828
+ return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
23746
23829
  };
23747
23830
 
23748
- /* begin_public_function
23749
- id: comment.create
23750
- */
23751
23831
  /**
23752
23832
  * ```js
23753
- * import { CommentRepository } from '@amityco/ts-sdk'
23754
- * const newComment = await CommentRepository.createComment(bundle)
23833
+ * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
23834
+ * const dispose = onLocalCommentReactionRemoved(comment => {
23835
+ * // ...
23836
+ * })
23755
23837
  * ```
23756
23838
  *
23757
- * Creates an {@link Amity.Comment}
23839
+ * Fired when a {@link Amity.InternalComment} has been reacted
23758
23840
  *
23759
- * @param bundle The data necessary to create a new {@link Amity.Comment}
23760
- * @returns The newly created {@link Amity.Comment}
23841
+ * @param callback The function to call when the event was fired
23842
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23761
23843
  *
23762
- * @category Comment API
23763
- * @async
23844
+ * @category Comment Events
23764
23845
  */
23765
- const createComment = async (bundle) => {
23766
- var _a;
23846
+ const onLocalCommentReactionRemoved = (callback) => {
23767
23847
  const client = getActiveClient();
23768
- client.log('comment/createComment', bundle);
23769
- const { data } = await client.http.post('/api/v3/comments', bundle);
23770
- const { comments } = data;
23771
- // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
23772
- if (comments.length === 0)
23773
- throw new Error('Comment not created');
23774
- const cachedAt = client.cache && Date.now();
23775
- if (client.cache)
23776
- ingestInCache(data, { cachedAt });
23777
- if (['post', 'content'].includes(bundle.referenceType)) {
23778
- const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
23779
- if (post) {
23780
- post.commentsCount += 1;
23781
- fireEvent('local.post.updated', {
23782
- posts: [post],
23783
- categories: [],
23784
- comments: [],
23785
- communities: [],
23786
- communityUsers: data.communityUsers,
23787
- feeds: [],
23788
- files: data.files,
23789
- postChildren: [],
23790
- users: data.users,
23791
- videoStreamings: [],
23792
- });
23848
+ const filter = ({ comment }) => {
23849
+ if (!client.cache) {
23850
+ callback(comment);
23793
23851
  }
23794
- }
23795
- else if (bundle.referenceType === 'story') {
23796
- const storyIndex = pullFromCache([
23797
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23798
- bundle.referenceId,
23799
- ]);
23800
- if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
23801
- const cacheStory = pullFromCache([
23802
- "story" /* STORY_KEY_CACHE.STORY */,
23803
- 'get',
23804
- storyIndex.data,
23805
- ]);
23806
- if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
23807
- fireEvent('story.updated', {
23808
- stories: [
23809
- Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
23810
- ],
23811
- categories: [],
23812
- comments,
23813
- communities: [],
23814
- communityUsers: data.communityUsers,
23815
- files: data.files,
23816
- users: data.users,
23817
- });
23818
- }
23852
+ else {
23853
+ upsertInCache(['comment', 'get', comment.commentId], comment);
23854
+ callback(commentLinkedObject(comment));
23819
23855
  }
23820
- }
23821
- fireEvent('local.comment.created', data);
23822
- return {
23823
- data: LinkedObject.comment(comments[0]),
23824
- cachedAt,
23825
23856
  };
23857
+ return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
23826
23858
  };
23827
- /* end_public_function */
23828
23859
 
23829
23860
  /* begin_public_function
23830
- id: comment.update_comment
23861
+ id: comment.get
23831
23862
  */
23832
23863
  /**
23833
23864
  * ```js
23834
- * import { CommentRepository } from '@amityco/ts-sdk'
23835
- * const updated = await CommentRepository.updateComment(commentId, {
23836
- * data: { text: 'hello world' }
23837
- * })
23865
+ * import { CommentRepository } from '@amityco/ts-sdk';
23866
+ *
23867
+ * let comment;
23868
+ *
23869
+ * const unsub = CommentRepository.getComment(commentId, response => {
23870
+ * comment = response.data;
23871
+ * });
23838
23872
  * ```
23839
23873
  *
23840
- * Updates an {@link Amity.Comment}
23874
+ * Observe all mutation on a given {@link Amity.Comment}
23841
23875
  *
23842
- * @param commentId The ID of the {@link Amity.Comment} to edit
23843
- * @param patch The patch data to apply
23844
- * @returns the updated {@link Amity.Comment} object
23876
+ * @param commentId the ID of the comment to observe
23877
+ * @param callback the function to call when new data are available
23878
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
23845
23879
  *
23846
- * @category Comment API
23847
- * @async
23880
+ * @category Comment Live Object
23848
23881
  */
23849
- const updateComment = async (commentId, patch) => {
23850
- const client = getActiveClient();
23851
- client.log('user/updateComment', patch);
23852
- const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
23853
- const cachedAt = client.cache && Date.now();
23854
- if (client.cache)
23855
- ingestInCache(data, { cachedAt });
23856
- fireEvent('comment.updated', data);
23857
- const { comments } = data;
23858
- return {
23859
- data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
23860
- cachedAt,
23861
- };
23882
+ const getComment = (commentId, callback) => {
23883
+ return liveObject(commentId, callback, 'commentId', getComment$1, [
23884
+ onCommentDeleteLocal,
23885
+ onCommentDeleted,
23886
+ onCommentFlagged,
23887
+ onCommentReactionAdded,
23888
+ onCommentReactionRemoved,
23889
+ onCommentUnflagged,
23890
+ onCommentUpdated,
23891
+ onLocalCommentReactionAdded,
23892
+ onLocalCommentReactionRemoved,
23893
+ ]);
23862
23894
  };
23863
23895
  /* end_public_function */
23864
23896
 
23865
- // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
23866
- const applyMissingField = (rawData, isCreated = false) => {
23867
- const { storyId, referenceId } = rawData;
23868
- if (!isCreated) {
23869
- if (referenceId)
23870
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
23897
+ class CommentPaginationController extends PaginationController {
23898
+ async getRequest(queryParams, token) {
23899
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
23900
+ const baseOptions = {
23901
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
23902
+ };
23903
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
23904
+ const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
23905
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
23906
+ });
23907
+ return queryResponse;
23871
23908
  }
23872
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
23873
- };
23874
- const convertRawStoryToInternal = (data, isCreated = false) => {
23875
- const { stories } = data;
23876
- const storiesData = stories.map(story => applyMissingField(story, isCreated));
23877
- return Object.assign(Object.assign({}, data), { stories: storiesData });
23878
- };
23909
+ }
23879
23910
 
23880
- const getStoryByStoryId$1 = async (storyId) => {
23881
- const client = getActiveClient();
23882
- client.log('story/getStoryByStoryId', storyId);
23883
- // Get story referenceId from cache
23884
- const cacheReferenceId = pullFromCache([
23885
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23886
- storyId,
23887
- ]);
23888
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
23889
- const { data: referenceId } = cacheReferenceId;
23890
- isInTombstone('story', referenceId);
23891
- }
23892
- let data;
23893
- try {
23894
- const response = await client.http.get(`/api/v4/stories/${storyId}`);
23895
- data = convertRawStoryToInternal(response.data);
23911
+ var EnumCommentActions;
23912
+ (function (EnumCommentActions) {
23913
+ EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
23914
+ EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
23915
+ EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
23916
+ EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
23917
+ EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
23918
+ EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
23919
+ EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
23920
+ })(EnumCommentActions || (EnumCommentActions = {}));
23921
+
23922
+ class CommentQueryStreamController extends QueryStreamController {
23923
+ constructor(query, cacheKey, notifyChange, preparePayload) {
23924
+ super(query, cacheKey);
23925
+ this.notifyChange = notifyChange;
23926
+ this.preparePayload = preparePayload;
23896
23927
  }
23897
- catch (error) {
23898
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23899
- pushToTombstone('story', storyId);
23928
+ async saveToMainDB(response) {
23929
+ const processedPayload = await this.preparePayload(response);
23930
+ const client = getActiveClient();
23931
+ const cachedAt = client.cache && Date.now();
23932
+ if (client.cache) {
23933
+ ingestInCache(processedPayload, { cachedAt });
23900
23934
  }
23901
- throw error;
23902
23935
  }
23903
- const cachedAt = client.cache && Date.now();
23904
- if (client.cache) {
23905
- ingestInCache(data, { cachedAt });
23936
+ appendToQueryStream(response, direction, refresh = false) {
23937
+ var _a, _b;
23938
+ if (refresh) {
23939
+ pushToCache(this.cacheKey, {
23940
+ data: response.comments.map(getResolver('comment')),
23941
+ });
23942
+ }
23943
+ else {
23944
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23945
+ const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
23946
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
23947
+ }
23906
23948
  }
23907
- return {
23908
- data: data.stories[0],
23909
- cachedAt,
23910
- };
23911
- };
23912
- getStoryByStoryId$1.locally = (storyId) => {
23913
- const client = getActiveClient();
23914
- client.log('story/getStorybyStoryId', storyId);
23915
- // Get story referenceId from cache
23916
- const cacheReferenceId = pullFromCache([
23917
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23918
- storyId,
23919
- ]);
23920
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
23921
- const { data: referenceId } = cacheReferenceId;
23922
- isInTombstone('story', referenceId);
23949
+ reactor(action) {
23950
+ return (comment) => {
23951
+ var _a;
23952
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23953
+ if (this.query.referenceId !== comment.referenceId ||
23954
+ this.query.referenceType !== comment.referenceType ||
23955
+ !collection) {
23956
+ return;
23957
+ }
23958
+ if (this.query.parentId && this.query.parentId !== comment.parentId) {
23959
+ return;
23960
+ }
23961
+ if (!this.query.parentId && comment.parentId) {
23962
+ return;
23963
+ }
23964
+ if (action === EnumCommentActions.OnCommentCreated) {
23965
+ collection.data = [...new Set([comment.commentId, ...collection.data])];
23966
+ }
23967
+ pushToCache(this.cacheKey, collection);
23968
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
23969
+ };
23923
23970
  }
23924
- const cachedAt = client.cache && Date.now();
23925
- const storyCache = pullFromCache(['story', 'get', storyId]);
23926
- if (!storyCache)
23927
- return;
23928
- return {
23929
- data: storyCache.data,
23930
- cachedAt,
23931
- };
23932
- };
23971
+ subscribeRTE(createSubscriber) {
23972
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
23973
+ }
23974
+ }
23933
23975
 
23934
- /* begin_public_function
23935
- id: comment.soft_delete, comment.hard_delete
23936
- */
23937
23976
  /**
23938
23977
  * ```js
23939
- * import { CommentRepository } from '@amityco/ts-sdk'
23940
- * const success = await CommentRepository.deleteComment('foobar')
23978
+ * import { onCommentCreated } from '@amityco/ts-sdk'
23979
+ * const dispose = onCommentCreated(comment => {
23980
+ * // ...
23981
+ * })
23941
23982
  * ```
23942
23983
  *
23943
- * Deletes a {@link Amity.Comment}
23984
+ * Fired when a {@link Amity.InternalComment} has been created
23944
23985
  *
23945
- * @param commentId The {@link Amity.Comment} ID to delete
23946
- * @return A success boolean if the {@link Amity.Comment} was deleted
23986
+ * @param callback The function to call when the event was fired
23987
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23947
23988
  *
23948
- * @category Comment API
23949
- * @async
23989
+ * @category Comment Events
23950
23990
  */
23951
- const deleteComment = async (commentId, permanent = false) => {
23952
- var _a;
23953
- const client = getActiveClient();
23954
- const comment = await getComment$2(commentId);
23955
- // API-FIX: This endpoint has not been implemented yet.
23956
- await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
23957
- params: {
23958
- commentId,
23959
- permanent,
23960
- },
23961
- });
23962
- // to support hard deletion
23963
- const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
23964
- if (comment.data.referenceType === 'story') {
23965
- const story = await getStoryByStoryId$1(comment.data.referenceId);
23966
- fireEvent('local.story.updated', {
23967
- stories: [story.data],
23968
- categories: [],
23969
- comments: [],
23970
- communities: [],
23971
- communityUsers: [],
23972
- files: [],
23973
- users: [],
23974
- });
23991
+ const onCommentCreatedLocal = (callback) => {
23992
+ return createLocalCommentEventSubscriber('local.comment.created', callback);
23993
+ };
23994
+
23995
+ class CommentLiveCollectionController extends LiveCollectionController {
23996
+ constructor(query, callback) {
23997
+ const queryStreamId = hash__default["default"](query);
23998
+ const cacheKey = ['comments', 'collection', queryStreamId];
23999
+ const paginationController = new CommentPaginationController(query);
24000
+ super(paginationController, queryStreamId, cacheKey, callback);
24001
+ this.query = query;
24002
+ this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
24003
+ this.callback = callback.bind(this);
24004
+ this.loadPage({ initial: true });
23975
24005
  }
23976
- else {
23977
- const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
23978
- if (post) {
23979
- let removeCount;
23980
- if (!deleted.parentId) {
23981
- // NOTE: delete the parent comment will remove all children comments
23982
- removeCount = deleted.childrenNumber + 1;
23983
- }
23984
- else
23985
- removeCount = 1;
23986
- post.commentsCount -= removeCount;
23987
- fireEvent('local.post.updated', {
23988
- posts: [post],
23989
- categories: [],
23990
- comments: [],
23991
- communities: [],
23992
- communityUsers: [],
23993
- feeds: [],
23994
- files: [],
23995
- postChildren: [],
23996
- users: [],
23997
- videoStreamings: [],
24006
+ setup() {
24007
+ var _a;
24008
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24009
+ if (!collection) {
24010
+ pushToCache(this.cacheKey, {
24011
+ data: [],
24012
+ params: {},
23998
24013
  });
23999
24014
  }
24000
24015
  }
24001
- fireEvent('local.comment.deleted', {
24002
- comments: [deleted],
24003
- commentChildren: [],
24004
- files: [],
24005
- users: [],
24006
- communityUsers: [],
24007
- });
24008
- if (permanent) {
24009
- scheduleTask(() => pushToTombstone('comment', commentId));
24016
+ async persistModel(queryPayload) {
24017
+ await this.queryStreamController.saveToMainDB(queryPayload);
24010
24018
  }
24011
- else {
24012
- upsertInCache(['comment', 'get', commentId], { isDeleted: true });
24019
+ persistQueryStream({ response, direction, refresh, }) {
24020
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
24021
+ }
24022
+ startSubscription() {
24023
+ return this.queryStreamController.subscribeRTE([
24024
+ { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
24025
+ { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
24026
+ { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
24027
+ { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
24028
+ { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
24029
+ { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
24030
+ { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
24031
+ { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
24032
+ { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
24033
+ { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
24034
+ { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
24035
+ ]);
24036
+ }
24037
+ notifyChange({ origin, loading, error }) {
24038
+ var _a, _b;
24039
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24040
+ if (!collection)
24041
+ return;
24042
+ const data = this.applyFilter((_b = collection.data
24043
+ .map(id => pullFromCache(['comment', 'get', id]))
24044
+ .filter(isNonNullable)
24045
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
24046
+ if (!this.shouldNotify(data) && origin === 'event')
24047
+ return;
24048
+ this.callback({
24049
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
24050
+ data,
24051
+ hasNextPage: !!this.paginationController.getNextToken(),
24052
+ loading,
24053
+ error,
24054
+ });
24055
+ }
24056
+ applyFilter(data) {
24057
+ let comments = data;
24058
+ if (!this.query.includeDeleted) {
24059
+ comments = filterByPropEquality(comments, 'isDeleted', false);
24060
+ }
24061
+ if (this.query.parentId) {
24062
+ comments = comments.filter(comment => comment.parentId === this.query.parentId);
24063
+ }
24064
+ if (typeof this.query.hasFlag === 'boolean') {
24065
+ if (this.query.hasFlag) {
24066
+ comments = comments.filter(comment => comment.hashFlag != null);
24067
+ }
24068
+ else {
24069
+ comments = comments.filter(comment => comment.hashFlag == null);
24070
+ }
24071
+ }
24072
+ if (this.query.dataTypes) {
24073
+ if (this.query.dataTypes.matchType === 'exact') {
24074
+ comments = comments.filter(comment => {
24075
+ var _a, _b;
24076
+ const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
24077
+ const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
24078
+ if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
24079
+ return false;
24080
+ }
24081
+ return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
24082
+ });
24083
+ }
24084
+ if (this.query.dataTypes.matchType === 'any') {
24085
+ 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); }); });
24086
+ }
24087
+ }
24088
+ switch (this.query.sortBy) {
24089
+ case 'firstCreated':
24090
+ comments = comments.sort(sortByFirstCreated);
24091
+ break;
24092
+ case 'lastCreated':
24093
+ default:
24094
+ comments = comments.sort(sortByLastCreated);
24095
+ break;
24096
+ }
24097
+ return comments;
24098
+ }
24099
+ }
24100
+
24101
+ /* begin_public_function
24102
+ id: comment.query
24103
+ */
24104
+ /**
24105
+ * ```js
24106
+ * import { getComments } from '@amityco/ts-sdk'
24107
+ *
24108
+ * let comments = []
24109
+ * const unsub = getComments({
24110
+ * referenceType: Amity.InternalComment['referenceType'];
24111
+ * referenceId: Amity.InternalComment['referenceId'];
24112
+ * }, response => merge(comments, response.data))
24113
+ * ```
24114
+ *
24115
+ * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
24116
+ *
24117
+ * @param referenceType the type of the target
24118
+ * @param referenceId the ID of the target
24119
+ * @param callback the function to call when new data are available
24120
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
24121
+ *
24122
+ * @category Comments Live Collection
24123
+ */
24124
+ const getComments = (params, callback, config) => {
24125
+ const { log, cache } = getActiveClient();
24126
+ if (!cache) {
24127
+ console.log('For using Live Collection feature you need to enable Cache!');
24128
+ }
24129
+ const timestamp = Date.now();
24130
+ log(`getComments(tmpid: ${timestamp}) > listen`);
24131
+ const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
24132
+ const disposers = commentsLiveCollection.startSubscription();
24133
+ const cacheKey = commentsLiveCollection.getCacheKey();
24134
+ disposers.push(() => dropFromCache(cacheKey));
24135
+ return () => {
24136
+ log(`getComments(tmpid: ${timestamp}) > dispose`);
24137
+ disposers.forEach(fn => fn());
24138
+ };
24139
+ };
24140
+ /* end_public_function */
24141
+
24142
+ var index$a = /*#__PURE__*/Object.freeze({
24143
+ __proto__: null,
24144
+ getCommentByIds: getCommentByIds,
24145
+ createComment: createComment,
24146
+ updateComment: updateComment,
24147
+ deleteComment: deleteComment,
24148
+ softDeleteComment: softDeleteComment,
24149
+ hardDeleteComment: hardDeleteComment,
24150
+ flagComment: flagComment,
24151
+ unflagComment: unflagComment,
24152
+ isCommentFlaggedByMe: isCommentFlaggedByMe,
24153
+ onCommentCreated: onCommentCreated,
24154
+ onCommentUpdated: onCommentUpdated,
24155
+ onCommentDeleted: onCommentDeleted,
24156
+ onCommentFlagged: onCommentFlagged,
24157
+ onCommentUnflagged: onCommentUnflagged,
24158
+ onCommentReactionAdded: onCommentReactionAdded,
24159
+ onCommentReactionRemoved: onCommentReactionRemoved,
24160
+ getComment: getComment,
24161
+ getComments: getComments
24162
+ });
24163
+
24164
+ const getPost$1 = async (postId) => {
24165
+ const client = getActiveClient();
24166
+ client.log('post/getPost', postId);
24167
+ isInTombstone('post', postId);
24168
+ let payload;
24169
+ try {
24170
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
24171
+ const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
24172
+ payload = response.data;
24173
+ }
24174
+ catch (error) {
24175
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
24176
+ pushToTombstone('post', postId);
24177
+ }
24178
+ throw error;
24179
+ }
24180
+ const data = prepareMembershipPayload(payload, 'communityUsers');
24181
+ const cachedAt = client.cache && Date.now();
24182
+ if (client.cache)
24183
+ ingestInCache(data, { cachedAt });
24184
+ const { posts } = data;
24185
+ const result = posts.find(post => post.postId === postId);
24186
+ return {
24187
+ data: result,
24188
+ cachedAt,
24189
+ };
24190
+ };
24191
+ getPost$1.locally = (postId) => {
24192
+ const client = getActiveClient();
24193
+ client.log('post/getPost.locally', postId);
24194
+ if (!client.cache)
24195
+ return;
24196
+ const cached = pullFromCache(['post', 'get', postId]);
24197
+ if (!cached)
24198
+ return;
24199
+ return {
24200
+ data: cached.data,
24201
+ cachedAt: cached.cachedAt,
24202
+ };
24203
+ };
24204
+
24205
+ /**
24206
+ * ```js
24207
+ * import { onLocalPostDeleted } from '@amityco/ts-sdk'
24208
+ * const dispose = onLocalPostDeleted(post => {
24209
+ * // ...
24210
+ * })
24211
+ * ```
24212
+ *
24213
+ * Fired when a {@link Amity.InternalPost} has been deleted
24214
+ *
24215
+ * @param callback The function to call when the event was fired
24216
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24217
+ *
24218
+ * @category Post Events
24219
+ */
24220
+ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
24221
+
24222
+ /**
24223
+ * ```js
24224
+ * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
24225
+ * const dispose = onPostReactionAdded(post => {
24226
+ * // ...
24227
+ * })
24228
+ * ```
24229
+ *
24230
+ * Fired when a {@link Amity.InternalPost} has been reacted
24231
+ *
24232
+ * @param callback The function to call when the event was fired
24233
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24234
+ *
24235
+ * @category Post Events
24236
+ */
24237
+ const onLocalPostReactionAdded = (callback) => {
24238
+ const client = getActiveClient();
24239
+ const filter = ({ post }) => {
24240
+ if (!client.cache) {
24241
+ callback(post);
24242
+ }
24243
+ else {
24244
+ upsertInCache(['post', 'get', post.postId], post);
24245
+ callback(post);
24246
+ }
24247
+ };
24248
+ return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
24249
+ };
24250
+
24251
+ /**
24252
+ * ```js
24253
+ * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
24254
+ * const dispose = onPostReactionRemoved(post => {
24255
+ * // ...
24256
+ * })
24257
+ * ```
24258
+ *
24259
+ * Fired when a {@link Amity.InternalPost} has been reacted
24260
+ *
24261
+ * @param callback The function to call when the event was fired
24262
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24263
+ *
24264
+ * @category Post Events
24265
+ */
24266
+ const onLocalPostReactionRemoved = (callback) => {
24267
+ const client = getActiveClient();
24268
+ const filter = ({ post }) => {
24269
+ if (!client.cache) {
24270
+ callback(post);
24271
+ }
24272
+ else {
24273
+ upsertInCache(['post', 'get', post.postId], post);
24274
+ callback(post);
24275
+ }
24276
+ };
24277
+ return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
24278
+ };
24279
+
24280
+ /**
24281
+ * ```js
24282
+ * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
24283
+ * const dispose = onPostUpdatedLocal(post => {
24284
+ * // ...
24285
+ * })
24286
+ * ```
24287
+ *
24288
+ * Fired when a {@link Amity.InternalPost} has been updated
24289
+ *
24290
+ * @param callback The function to call when the event was fired
24291
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24292
+ *
24293
+ * @category Post Events
24294
+ */
24295
+ const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
24296
+
24297
+ const commentEventHandler$1 = (callback, eventHandler, cacheKey) => {
24298
+ return eventHandler(async (comment) => {
24299
+ var _a;
24300
+ const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24301
+ if (!currentCollection || !currentCollection.data.includes(comment.referenceId))
24302
+ return;
24303
+ await getPost$1(comment.referenceId);
24304
+ callback(comment);
24305
+ });
24306
+ };
24307
+ const generateCommentSubscriptions$1 = (cacheKey) => {
24308
+ const eventHandlers = [
24309
+ onCommentCreated,
24310
+ onCommentDeleted,
24311
+ onCommentReactionAdded,
24312
+ onCommentReactionRemoved,
24313
+ onCommentCreatedLocal,
24314
+ onCommentDeleteLocal,
24315
+ onLocalCommentReactionAdded,
24316
+ onLocalCommentReactionRemoved,
24317
+ ];
24318
+ return eventHandlers.map(handler => ({
24319
+ fn: convertEventPayload((callback) => commentEventHandler$1(callback, handler, cacheKey), 'referenceId', 'post'),
24320
+ action: EnumPostActions.OnPostUpdated,
24321
+ }));
24322
+ };
24323
+ const getGlobalFeedSubscriptions = (cacheKey) => {
24324
+ return [
24325
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
24326
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
24327
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
24328
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
24329
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
24330
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
24331
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
24332
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
24333
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
24334
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
24335
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
24336
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
24337
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
24338
+ ...generateCommentSubscriptions$1(cacheKey),
24339
+ ];
24340
+ };
24341
+
24342
+ class CustomRankingGlobalFeedLiveCollectionController extends LiveCollectionController {
24343
+ constructor(query, callback) {
24344
+ const queryStreamId = hash__default["default"](query);
24345
+ const cacheKey = ['customRankingGlobalFeed', 'collection', queryStreamId];
24346
+ const paginationController = new CustomRankingGlobalFeedPaginationController(query);
24347
+ super(paginationController, queryStreamId, cacheKey, callback);
24348
+ this.query = query;
24349
+ this.queryStreamController = new CustomRankingGlobalFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
24350
+ this.callback = callback.bind(this);
24351
+ this.loadPage({ initial: true });
24352
+ }
24353
+ setup() {
24354
+ var _a;
24355
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24356
+ if (!collection) {
24357
+ pushToCache(this.cacheKey, {
24358
+ data: [],
24359
+ params: {},
24360
+ });
24361
+ }
24362
+ }
24363
+ async persistModel(queryPayload) {
24364
+ await this.queryStreamController.saveToMainDB(queryPayload);
24365
+ }
24366
+ persistQueryStream({ response, direction, refresh, }) {
24367
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
24368
+ }
24369
+ startSubscription() {
24370
+ return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
24371
+ }
24372
+ notifyChange({ origin, loading, error }) {
24373
+ var _a, _b;
24374
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24375
+ if (!collection)
24376
+ return;
24377
+ const data = ((_b = collection.data
24378
+ .map(id => pullFromCache(['post', 'get', id]))
24379
+ .filter(isNonNullable)
24380
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
24381
+ if (!this.shouldNotify(data) && origin === 'event')
24382
+ return;
24383
+ this.callback({
24384
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
24385
+ data,
24386
+ hasNextPage: !!this.paginationController.getNextToken(),
24387
+ loading,
24388
+ error,
24389
+ });
24390
+ }
24391
+ }
24392
+
24393
+ /* begin_public_function
24394
+ id: feed.query.custom_ranking_feed
24395
+ */
24396
+ /**
24397
+ * ```js
24398
+ * import { FeedRepository } from '@amityco/ts-sdk'
24399
+ *
24400
+ * let posts = []
24401
+ * const unsub = FeedRepository.getGlobalFeed({
24402
+ * dataTypes: ['video','image'],
24403
+ * resolveParent: true,
24404
+ * }, response => processResponse(response))
24405
+ * ```
24406
+ *
24407
+ * Observe all mutations on a list of {@link Amity.Post} for a given target object
24408
+ *
24409
+ * @param params.dataTypes array of data types for the posts
24410
+ * @param callback the function to call when new data are available
24411
+ * @param config
24412
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
24413
+ *
24414
+ * @category Posts Live Collection
24415
+ */
24416
+ const getCustomRankingGlobalFeed = (params, callback, config) => {
24417
+ const { log, cache } = getActiveClient();
24418
+ if (!cache) {
24419
+ console.log(ENABLE_CACHE_MESSAGE);
24420
+ }
24421
+ const timestamp = Date.now();
24422
+ log(`getCustomRankingGlobalFeed(tmpid: ${timestamp}) > listen`);
24423
+ const liveCollection = new CustomRankingGlobalFeedLiveCollectionController(params, callback);
24424
+ const disposers = liveCollection.startSubscription();
24425
+ const cacheKey = liveCollection.getCacheKey();
24426
+ disposers.push(() => dropFromCache(cacheKey));
24427
+ return () => {
24428
+ log(`getCustomRankingGlobalFeed(tmpid: ${timestamp}) > dispose`);
24429
+ disposers.forEach(fn => fn());
24430
+ };
24431
+ };
24432
+ /* end_public_function */
24433
+
24434
+ class GlobalFeedPaginationController extends PaginationController {
24435
+ async getRequest(queryParams, token) {
24436
+ const { limit, resolveParent } = queryParams, params = __rest(queryParams, ["limit", "resolveParent"]);
24437
+ const options = token ? { token } : { limit };
24438
+ const { data: queryResponse } = await this.http.get(`/api/v4/me/global-feeds`, {
24439
+ params: Object.assign(Object.assign({}, params), { resolveParent: resolveParent !== null && resolveParent !== void 0 ? resolveParent : true, options }),
24440
+ });
24441
+ return queryResponse;
24442
+ }
24443
+ }
24444
+
24445
+ class GlobalFeedQueryStreamController extends QueryStreamController {
24446
+ constructor(query, cacheKey, notifyChange, preparePayload) {
24447
+ super(query, cacheKey);
24448
+ this.notifyChange = notifyChange;
24449
+ this.preparePayload = preparePayload;
24450
+ }
24451
+ async saveToMainDB(response) {
24452
+ const processedPayload = await this.preparePayload(response);
24453
+ const client = getActiveClient();
24454
+ const cachedAt = client.cache && Date.now();
24455
+ if (client.cache) {
24456
+ ingestInCache(processedPayload, { cachedAt });
24457
+ }
24458
+ }
24459
+ appendToQueryStream(response, direction, refresh = false) {
24460
+ var _a, _b;
24461
+ if (refresh) {
24462
+ pushToCache(this.cacheKey, {
24463
+ data: response.posts.map(getResolver('post')),
24464
+ });
24465
+ }
24466
+ else {
24467
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24468
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
24469
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
24470
+ }
24471
+ }
24472
+ reactor(action) {
24473
+ return (post) => {
24474
+ var _a;
24475
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24476
+ if (!collection)
24477
+ return;
24478
+ if (post.parentPostId && !collection.data.includes(post.parentPostId))
24479
+ return;
24480
+ // Delete Action
24481
+ if (action === EnumPostActions.OnPostDeleted) {
24482
+ // Parent Post - Remove from collection
24483
+ collection.data = collection.data.filter(postId => postId !== post.postId);
24484
+ }
24485
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
24486
+ // If the query has dataTypes array with value, check if post.dataType is include in the array
24487
+ if (this.query.dataTypes && this.query.dataTypes.length > 0) {
24488
+ if (!this.query.dataTypes.includes(post.dataType))
24489
+ return;
24490
+ }
24491
+ collection.data = [...new Set([post.postId, ...collection.data])];
24492
+ }
24493
+ if (action === EnumPostActions.OnPostDeclined) {
24494
+ collection.data = collection.data.filter(postId => postId !== post.postId);
24495
+ }
24496
+ pushToCache(this.cacheKey, collection);
24497
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
24498
+ };
24499
+ }
24500
+ subscribeRTE(createSubscriber) {
24501
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
24502
+ }
24503
+ }
24504
+
24505
+ class GlobalFeedLiveCollectionController extends LiveCollectionController {
24506
+ constructor(query, callback) {
24507
+ const queryStreamId = hash__default["default"](query);
24508
+ const cacheKey = ['globalFeed', 'collection', queryStreamId];
24509
+ const paginationController = new GlobalFeedPaginationController(query);
24510
+ super(paginationController, queryStreamId, cacheKey, callback);
24511
+ this.query = query;
24512
+ this.queryStreamController = new GlobalFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
24513
+ this.callback = callback.bind(this);
24514
+ this.loadPage({ initial: true });
24515
+ }
24516
+ setup() {
24517
+ var _a;
24518
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24519
+ if (!collection) {
24520
+ pushToCache(this.cacheKey, {
24521
+ data: [],
24522
+ params: {},
24523
+ });
24524
+ }
24525
+ }
24526
+ async persistModel(queryPayload) {
24527
+ await this.queryStreamController.saveToMainDB(queryPayload);
24528
+ }
24529
+ persistQueryStream({ response, direction, refresh, }) {
24530
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
24531
+ }
24532
+ startSubscription() {
24533
+ return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
24534
+ }
24535
+ notifyChange({ origin, loading, error }) {
24536
+ var _a, _b;
24537
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24538
+ if (!collection)
24539
+ return;
24540
+ const data = ((_b = collection.data
24541
+ .map(id => pullFromCache(['post', 'get', id]))
24542
+ .filter(isNonNullable)
24543
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
24544
+ if (!this.shouldNotify(data) && origin === 'event')
24545
+ return;
24546
+ this.callback({
24547
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
24548
+ data,
24549
+ hasNextPage: !!this.paginationController.getNextToken(),
24550
+ loading,
24551
+ error,
24552
+ });
24553
+ }
24554
+ }
24555
+
24556
+ /* begin_public_function
24557
+ id: feed.query.global_feed
24558
+ */
24559
+ /**
24560
+ * ```js
24561
+ * import { FeedRepository } from '@amityco/ts-sdk'
24562
+ *
24563
+ * let posts = []
24564
+ * const unsub = FeedRepository.getGlobalFeed({
24565
+ * dataTypes: ['video','image'],
24566
+ * resolveParent: true,
24567
+ * }, response => processResponse(response))
24568
+ * ```
24569
+ *
24570
+ * Observe all mutations on a list of {@link Amity.Post} for global feed
24571
+ * @param params.dataTypes array of data types for the posts
24572
+ * @param params.resolveParent
24573
+ * @param callback the function to call when new data are available
24574
+ * @param config
24575
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
24576
+ *
24577
+ * @category Posts Live Collection
24578
+ */
24579
+ const getGlobalFeed = (params, callback, config) => {
24580
+ const { log, cache } = getActiveClient();
24581
+ if (!cache) {
24582
+ console.log(ENABLE_CACHE_MESSAGE);
24583
+ }
24584
+ const timestamp = Date.now();
24585
+ log(`getGlobalFeed(tmpid: ${timestamp}) > listen`);
24586
+ const liveCollection = new GlobalFeedLiveCollectionController(params, callback);
24587
+ const disposers = liveCollection.startSubscription();
24588
+ const cacheKey = liveCollection.getCacheKey();
24589
+ disposers.push(() => dropFromCache(cacheKey));
24590
+ return () => {
24591
+ log(`getGlobalFeed(tmpid: ${timestamp}) > dispose`);
24592
+ disposers.forEach(fn => fn());
24593
+ };
24594
+ };
24595
+ /* end_public_function */
24596
+
24597
+ class UserFeedPaginationController extends PaginationController {
24598
+ async getRequest(queryParams, token) {
24599
+ const { userId, feedSources, dataTypes, includeDeleted, matchingOnlyParentPost, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["userId", "feedSources", "dataTypes", "includeDeleted", "matchingOnlyParentPost", "limit"]);
24600
+ const options = token ? { token } : { limit };
24601
+ const { data: queryResponse } = await this.http.get(`/api/v4/user-feeds/${userId}`, {
24602
+ params: Object.assign(Object.assign({}, params), { options, dataTypes: (dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length) ? dataTypes : undefined, includePostedFeed: feedSources, isDeleted: inferIsDeleted(includeDeleted), matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length) }),
24603
+ });
24604
+ return queryResponse;
24605
+ }
24606
+ }
24607
+
24608
+ class UserFeedQueryStreamController extends QueryStreamController {
24609
+ constructor(query, cacheKey, notifyChange, preparePayload) {
24610
+ super(query, cacheKey);
24611
+ this.notifyChange = notifyChange;
24612
+ this.preparePayload = preparePayload;
24613
+ }
24614
+ async saveToMainDB(response) {
24615
+ const processedPayload = await this.preparePayload(response);
24616
+ const client = getActiveClient();
24617
+ const cachedAt = client.cache && Date.now();
24618
+ if (client.cache) {
24619
+ ingestInCache(processedPayload, { cachedAt });
24620
+ }
24621
+ }
24622
+ appendToQueryStream(response, direction, refresh = false) {
24623
+ var _a, _b;
24624
+ if (refresh) {
24625
+ pushToCache(this.cacheKey, {
24626
+ data: response.posts.map(getResolver('post')),
24627
+ });
24628
+ }
24629
+ else {
24630
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24631
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
24632
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
24633
+ }
24634
+ }
24635
+ reactor(action) {
24636
+ return (post) => {
24637
+ var _a, _b;
24638
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24639
+ if (!collection)
24640
+ return;
24641
+ // if the collection is parent post collection and
24642
+ // post is not included in the collection or post is child post
24643
+ if ((!this.query.dataTypes || this.query.dataTypes.length === 0) &&
24644
+ !collection.data.includes(post.parentPostId ? post.parentPostId : post.postId))
24645
+ return;
24646
+ if (action === EnumPostActions.OnPostDeleted) {
24647
+ collection.data = collection.data.filter(postId => postId !== post.postId);
24648
+ }
24649
+ if (post.parentPostId && post.isDeleted) {
24650
+ const parentPost = (_b = pullFromCache([
24651
+ 'post',
24652
+ 'get',
24653
+ post.parentPostId,
24654
+ ])) === null || _b === void 0 ? void 0 : _b.data;
24655
+ if (!parentPost)
24656
+ return;
24657
+ parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
24658
+ pushToCache(['post', 'get', parentPost.postId], parentPost);
24659
+ }
24660
+ if (action === EnumPostActions.OnPostDeclined) {
24661
+ collection.data = collection.data.filter(postId => postId !== post.postId);
24662
+ }
24663
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
24664
+ if (this.query.dataTypes &&
24665
+ this.query.dataTypes.length > 0 &&
24666
+ !this.query.dataTypes.includes(post.dataType)) {
24667
+ return;
24668
+ }
24669
+ collection.data = [...new Set([post.postId, ...collection.data])];
24670
+ }
24671
+ pushToCache(this.cacheKey, collection);
24672
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
24673
+ };
24674
+ }
24675
+ subscribeRTE(createSubscriber) {
24676
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
24677
+ }
24678
+ }
24679
+
24680
+ class UserFeedLiveCollectionController extends LiveCollectionController {
24681
+ constructor(query, callback) {
24682
+ const queryStreamId = hash__default["default"](query);
24683
+ const cacheKey = ['userFeed', 'collection', queryStreamId];
24684
+ const paginationController = new UserFeedPaginationController(query);
24685
+ super(paginationController, queryStreamId, cacheKey, callback);
24686
+ this.query = query;
24687
+ this.queryStreamController = new UserFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
24688
+ this.callback = callback.bind(this);
24689
+ this.loadPage({ initial: true });
24690
+ }
24691
+ setup() {
24692
+ var _a;
24693
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24694
+ if (!collection) {
24695
+ pushToCache(this.cacheKey, {
24696
+ data: [],
24697
+ params: {},
24698
+ });
24699
+ }
24700
+ }
24701
+ async persistModel(queryPayload) {
24702
+ await this.queryStreamController.saveToMainDB(queryPayload);
24703
+ }
24704
+ persistQueryStream({ response, direction, refresh, }) {
24705
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
24706
+ }
24707
+ startSubscription() {
24708
+ return this.queryStreamController.subscribeRTE([
24709
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
24710
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
24711
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
24712
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
24713
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
24714
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
24715
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
24716
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
24717
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
24718
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
24719
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
24720
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
24721
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
24722
+ {
24723
+ fn: convertEventPayload((callback) => {
24724
+ return onCommentCreated(async (comment) => {
24725
+ var _a;
24726
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24727
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
24728
+ return;
24729
+ await getPost$1(comment.referenceId);
24730
+ callback(comment);
24731
+ });
24732
+ }, 'referenceId', 'post'),
24733
+ action: EnumPostActions.OnPostUpdated,
24734
+ },
24735
+ {
24736
+ fn: convertEventPayload((callback) => {
24737
+ return onCommentDeleted(async (comment) => {
24738
+ var _a;
24739
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24740
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
24741
+ return;
24742
+ await getPost$1(comment.referenceId);
24743
+ callback(comment);
24744
+ });
24745
+ }, 'referenceId', 'post'),
24746
+ action: EnumPostActions.OnPostUpdated,
24747
+ },
24748
+ ]);
24749
+ }
24750
+ notifyChange({ origin, loading, error }) {
24751
+ var _a, _b;
24752
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24753
+ if (!collection)
24754
+ return;
24755
+ const data = ((_b = collection.data
24756
+ .map(id => pullFromCache(['post', 'get', id]))
24757
+ .filter(isNonNullable)
24758
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
24759
+ if (!this.shouldNotify(data) && origin === 'event')
24760
+ return;
24761
+ this.callback({
24762
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
24763
+ data,
24764
+ hasNextPage: !!this.paginationController.getNextToken(),
24765
+ loading,
24766
+ error,
24767
+ });
24013
24768
  }
24014
- return deleted;
24015
- };
24016
- /* end_public_function */
24769
+ }
24017
24770
 
24018
24771
  /* begin_public_function
24019
- id: comment.soft_delete
24772
+ id: feed.query.user_feed
24020
24773
  */
24021
24774
  /**
24022
24775
  * ```js
24023
- * import { CommentRepository } from '@amityco/ts-sdk'
24024
- * const success = await CommentRepository.softDeleteComment('foobar')
24025
- * ```
24026
- *
24027
- * Deletes a {@link Amity.Comment}
24028
- *
24029
- * @param commentId The {@link Amity.Comment} ID to delete
24030
- * @return A success boolean if the {@link Amity.Comment} was deleted
24776
+ * import { FeedRepository } from '@amityco/ts-sdk'
24031
24777
  *
24032
- * @category Comment API
24033
- * @async
24034
- */
24035
- const softDeleteComment = async (commentId) => {
24036
- const client = getActiveClient();
24037
- client.log('comment/softDeleteComment', commentId);
24038
- const softDeleted = deleteComment(commentId);
24039
- return softDeleted;
24040
- };
24041
- /* end_public_function */
24042
-
24043
- /* begin_public_function
24044
- id: comment.hard_delete
24045
- */
24046
- /**
24047
- * ```js
24048
- * import { CommentRepository } from '@amityco/ts-sdk'
24049
- * const success = await CommentRepository.hardDeleteComment('foobar')
24778
+ * let posts = []
24779
+ * const unsubscribe = FeedRepository.getUserFeed({
24780
+ * userId: string,
24781
+ * feedSources: ['user', 'community'],
24782
+ * }, response => response => processResponse(response))
24050
24783
  * ```
24051
24784
  *
24052
- * Deletes a {@link Amity.Comment}
24785
+ * Observe all mutations on a list of {@link Amity.Post} for a given user and feedSources
24053
24786
  *
24054
- * @param commentId The {@link Amity.Comment} ID to delete
24055
- * @return A success boolean if the {@link Amity.Comment} was deleted
24787
+ * @param params.userId the ID of the user
24788
+ * @param params.feedSources the sources of the feed
24789
+ * @param callback the function to call when new data are available
24790
+ * @param config
24791
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
24056
24792
  *
24057
- * @category Comment API
24058
- * @async
24793
+ * @category Posts Live Collection
24059
24794
  */
24060
- const hardDeleteComment = async (commentId) => {
24061
- const client = getActiveClient();
24062
- client.log('comment/hardDeleteComment', commentId);
24063
- const hardDeleted = deleteComment(commentId, true);
24064
- return hardDeleted;
24065
- };
24066
- /* end_public_function */
24067
-
24068
- /* begin_public_function
24069
- id: comment.flag
24070
- */
24071
- /**
24072
- * ```js
24073
- * import { CommentRepository } from '@amityco/ts-sdk'
24074
- * const flagged = await CommentRepository.flagComment(commentId, reason)
24075
- * ```
24076
- *
24077
- * @param commentId The ID of the comment to flag
24078
- * @param reason the reason to flag the comment
24079
- * @returns the created report result
24080
- *
24081
- * @category Comment API
24082
- * @async
24083
- * */
24084
- const flagComment = async (commentId, reason) => {
24085
- const client = getActiveClient();
24086
- client.log('comment/flagComment', commentId);
24087
- const isPredefinedReason = reason &&
24088
- Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
24089
- const body = {
24090
- reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
24091
- detail: reason && !isPredefinedReason ? reason : '',
24092
- };
24093
- const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
24094
- if (client.cache) {
24095
- ingestInCache(payload);
24795
+ const getUserFeed = (params, callback, config) => {
24796
+ const { log, cache } = getActiveClient();
24797
+ if (!cache) {
24798
+ console.log(ENABLE_CACHE_MESSAGE);
24096
24799
  }
24097
- fireEvent('comment.flagged', payload);
24098
- return !!payload;
24800
+ const timestamp = Date.now();
24801
+ log(`getUserFeed(tmpid: ${timestamp}) > listen`);
24802
+ const userFeedLiveCollection = new UserFeedLiveCollectionController(params, callback);
24803
+ const disposers = userFeedLiveCollection.startSubscription();
24804
+ const cacheKey = userFeedLiveCollection.getCacheKey();
24805
+ disposers.push(() => dropFromCache(cacheKey));
24806
+ return () => {
24807
+ log(`getUserFeed(tmpid: ${timestamp}) > dispose`);
24808
+ disposers.forEach(fn => fn());
24809
+ };
24099
24810
  };
24100
24811
  /* end_public_function */
24101
24812
 
24102
- /* begin_public_function
24103
- id: comment.unflag
24104
- */
24105
- /**
24106
- * ```js
24107
- * import { CommentRepository } from '@amityco/ts-sdk'
24108
- * const unflagged = await CommentRepository.unflagComment('commentId')
24109
- * ```
24110
- *
24111
- * @param commentId The ID of comment to unflag
24112
- * @returns the unflagged result
24113
- *
24114
- * @category Comment API
24115
- * @async
24116
- * */
24117
- const unflagComment = async (commentId) => {
24118
- const client = getActiveClient();
24119
- client.log('comment/unflagComment', commentId);
24120
- const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
24121
- if (client.cache) {
24122
- ingestInCache(payload);
24123
- }
24124
- fireEvent('comment.unflagged', payload);
24125
- return !!payload;
24126
- };
24127
- /* end_public_function */
24813
+ var index$9 = /*#__PURE__*/Object.freeze({
24814
+ __proto__: null,
24815
+ queryGlobalFeed: queryGlobalFeed,
24816
+ getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
24817
+ getGlobalFeed: getGlobalFeed,
24818
+ getUserFeed: getUserFeed
24819
+ });
24128
24820
 
24129
24821
  /* begin_public_function
24130
- id: comment.check_flag_by_me
24822
+ id: post.get_by_ids
24131
24823
  */
24132
24824
  /**
24133
24825
  * ```js
24134
- * import { CommentRepository } from '@amityco/ts-sdk'
24135
- * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
24826
+ * import { getPostByIds } from '@amityco/ts-sdk'
24827
+ * const { data: posts } = await getPostByIds(['foo', 'bar'])
24136
24828
  * ```
24137
24829
  *
24138
- * @param commentId The ID of the comment to check if flagged by current user
24139
- * @returns `true` if the comment is flagged by me, `false` if doesn't.
24830
+ * Fetches a collection of {@link Amity.Post} objects
24140
24831
  *
24141
- * @category Comment API
24832
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
24833
+ * @returns the associated collection of {@link Amity.Post} objects
24834
+ *
24835
+ * @category Post API
24142
24836
  * @async
24143
- * */
24144
- const isCommentFlaggedByMe = async (commentId) => {
24145
- const client = getActiveClient();
24146
- client.log('comment/isCommentFlaggedByMe', commentId);
24147
- const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
24148
- return result;
24149
- };
24150
- /* end_public_function */
24151
-
24152
- const getComment$1 = async (commentId) => {
24837
+ */
24838
+ const getPostByIds = async (postIds) => {
24153
24839
  const client = getActiveClient();
24154
- client.log('comment/getComment', commentId);
24155
- isInTombstone('comment', commentId);
24156
- let data;
24840
+ client.log('post/getPostByIds', postIds);
24841
+ const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
24842
+ let payload;
24157
24843
  try {
24158
24844
  // API-FIX: endpoint should not be /list, parameters should be querystring.
24159
- const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
24160
- data = response.data;
24845
+ const response = await client.http.get(`/api/v3/posts/list`, {
24846
+ params: { postIds: encodedPostIds },
24847
+ });
24848
+ payload = response.data;
24161
24849
  }
24162
24850
  catch (error) {
24163
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
24164
- pushToTombstone('comment', commentId);
24165
- }
24851
+ postIds.forEach(postId => {
24852
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
24853
+ pushToTombstone('post', postId);
24854
+ }
24855
+ });
24166
24856
  throw error;
24167
24857
  }
24858
+ const data = prepareMembershipPayload(payload, 'communityUsers');
24168
24859
  const cachedAt = client.cache && Date.now();
24169
24860
  if (client.cache)
24170
24861
  ingestInCache(data, { cachedAt });
24171
- const { comments } = data;
24172
24862
  return {
24173
- data: comments.find(comment => comment.commentId === commentId),
24863
+ data: data.posts.map(LinkedObject.post),
24174
24864
  cachedAt,
24175
24865
  };
24176
24866
  };
24177
- getComment$1.locally = (commentId) => {
24867
+ /* end_public_function */
24868
+ /**
24869
+ * ```js
24870
+ * import { getPostByIds } from '@amityco/ts-sdk'
24871
+ * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
24872
+ * ```
24873
+ *
24874
+ * Fetches a collection of {@link Amity.Post} objects from cache
24875
+ *
24876
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
24877
+ * @returns the associated collection of {@link Amity.Post} objects
24878
+ *
24879
+ * @category Post API
24880
+ */
24881
+ getPostByIds.locally = (postIds) => {
24882
+ var _a;
24178
24883
  const client = getActiveClient();
24179
- client.log('comment/getComment.locally', commentId);
24884
+ client.log('post/getPostByIds.locally', postIds);
24180
24885
  if (!client.cache)
24181
24886
  return;
24182
- const cached = pullFromCache(['comment', 'get', commentId]);
24183
- if (!cached)
24887
+ const cached = postIds
24888
+ .map(postId => pullFromCache(['post', 'get', postId]))
24889
+ .filter(Boolean);
24890
+ const posts = cached.map(({ data }) => data);
24891
+ const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
24892
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
24184
24893
  return;
24185
24894
  return {
24186
- data: cached.data,
24187
- cachedAt: cached.cachedAt,
24895
+ data: posts.map(LinkedObject.post),
24896
+ cachedAt: oldest.cachedAt,
24188
24897
  };
24189
24898
  };
24190
24899
 
24900
+ /* begin_public_function
24901
+ 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
24902
+ */
24191
24903
  /**
24192
24904
  * ```js
24193
- * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
24194
- * const dispose = onCommentDeleteLocal(comment => {
24195
- * // ...
24196
- * })
24905
+ * import { PostRepository } from '@amityco/ts-sdk'
24906
+ * const created = await PostRepository.createPost({
24907
+ * targetType: 'user',
24908
+ * targetId: 'foobar',
24909
+ * data: { text: 'hello world' }
24910
+ * }))
24197
24911
  * ```
24198
24912
  *
24199
- * Fired when a {@link Amity.InternalComment} has been deleted
24913
+ * Creates an {@link Amity.Post}
24200
24914
  *
24201
- * @param callback The function to call when the event was fired
24202
- * @returns an {@link Amity.Unsubscriber} function to stop listening
24915
+ * @param bundle The data necessary to create a new {@link Amity.Post}
24916
+ * @returns The newly created {@link Amity.Post}
24203
24917
  *
24204
- * @category Comment Events
24918
+ * @category Post API
24919
+ * @async
24205
24920
  */
24206
- const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
24921
+ const createPost = async (bundle) => {
24922
+ const client = getActiveClient();
24923
+ client.log('post/createPost', bundle);
24924
+ if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
24925
+ // eslint-disable-next-line no-param-reassign
24926
+ delete bundle.dataType;
24927
+ }
24928
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
24929
+ fireEvent('post.created', payload);
24930
+ const data = preparePostPayload(payload);
24931
+ const cachedAt = client.cache && Date.now();
24932
+ if (client.cache)
24933
+ ingestInCache(data, { cachedAt });
24934
+ const { posts } = data;
24935
+ return {
24936
+ data: LinkedObject.post(posts[0]),
24937
+ cachedAt,
24938
+ };
24939
+ };
24940
+ /* end_public_function */
24207
24941
 
24942
+ /* begin_public_function
24943
+ id: post.edit, post.edit.custom_post
24944
+ */
24208
24945
  /**
24209
24946
  * ```js
24210
- * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
24211
- * const dispose = onLocalCommentReactionAdded(comment => {
24212
- * // ...
24947
+ * import { PostRepository } from '@amityco/ts-sdk'
24948
+ * const updated = await PostRepository.editPost(postId, {
24949
+ * data: { text: 'hello world' }
24213
24950
  * })
24214
24951
  * ```
24215
24952
  *
24216
- * Fired when a {@link Amity.InternalComment} has been reacted
24953
+ * Updates an {@link Amity.Post}
24217
24954
  *
24218
- * @param callback The function to call when the event was fired
24219
- * @returns an {@link Amity.Unsubscriber} function to stop listening
24955
+ * @param postId The ID of the {@link Amity.Post} to edit
24956
+ * @param patch The patch data to apply
24957
+ * @returns the updated {@link Amity.Post} object
24220
24958
  *
24221
- * @category Comment Events
24959
+ * @category Post API
24960
+ * @async
24222
24961
  */
24223
- const onLocalCommentReactionAdded = (callback) => {
24962
+ const editPost = async (postId, patch) => {
24224
24963
  const client = getActiveClient();
24225
- const filter = ({ comment }) => {
24226
- if (!client.cache) {
24227
- callback(comment);
24228
- }
24229
- else {
24230
- upsertInCache(['comment', 'get', comment.commentId], comment);
24231
- callback(commentLinkedObject(comment));
24232
- }
24964
+ client.log('user/editPost', patch);
24965
+ const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
24966
+ const data = prepareMembershipPayload(payload, 'communityUsers');
24967
+ const cachedAt = client.cache && Date.now();
24968
+ if (client.cache)
24969
+ ingestInCache(data, { cachedAt });
24970
+ fireEvent('local.post.updated', data);
24971
+ const { posts } = data;
24972
+ return {
24973
+ data: LinkedObject.post(posts.find(post => post.postId === postId)),
24974
+ cachedAt,
24233
24975
  };
24234
- return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
24235
24976
  };
24977
+ /* end_public_function */
24236
24978
 
24237
24979
  /**
24238
24980
  * ```js
24239
- * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
24240
- * const dispose = onLocalCommentReactionRemoved(comment => {
24241
- * // ...
24242
- * })
24981
+ * import { deletePost } from '@amityco/ts-sdk'
24982
+ * const success = await deletePost('foobar')
24243
24983
  * ```
24244
24984
  *
24245
- * Fired when a {@link Amity.InternalComment} has been reacted
24985
+ * Deletes a {@link Amity.Post}
24246
24986
  *
24247
- * @param callback The function to call when the event was fired
24248
- * @returns an {@link Amity.Unsubscriber} function to stop listening
24987
+ * @param postId The {@link Amity.Post} ID to delete
24988
+ * @return A success boolean if the {@link Amity.Post} was deleted
24249
24989
  *
24250
- * @category Comment Events
24990
+ * @private
24991
+ * @async
24251
24992
  */
24252
- const onLocalCommentReactionRemoved = (callback) => {
24993
+ const deletePost = async (postId, permanent = false) => {
24994
+ var _a;
24253
24995
  const client = getActiveClient();
24254
- const filter = ({ comment }) => {
24255
- if (!client.cache) {
24256
- callback(comment);
24257
- }
24258
- else {
24259
- upsertInCache(['comment', 'get', comment.commentId], comment);
24260
- callback(commentLinkedObject(comment));
24261
- }
24262
- };
24263
- return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
24996
+ const post = await getPost$2(postId);
24997
+ await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
24998
+ params: {
24999
+ postId,
25000
+ permanent,
25001
+ },
25002
+ });
25003
+ // there is currently a limitation which doesn't allow us to fire event to tell that community
25004
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
25005
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
25006
+ // later when realtime events covers that for us.
25007
+ if (post.data.targetType === 'community') {
25008
+ const community = await getCommunity$1(post.data.targetId);
25009
+ const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
25010
+ const communityUsers = communityUsersCache
25011
+ .filter(({ key }) => {
25012
+ // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
25013
+ if (key[0] !== 'communityUsers')
25014
+ return false;
25015
+ if (key[1] !== 'get')
25016
+ return false;
25017
+ if (typeof key[2] === 'string')
25018
+ return key[2].includes(community.data.communityId);
25019
+ return false;
25020
+ })
25021
+ .map(({ data }) => data);
25022
+ fireEvent('community.updated', {
25023
+ communities: [community.data],
25024
+ categories: [],
25025
+ communityUsers,
25026
+ feeds: [],
25027
+ files: [],
25028
+ users: [],
25029
+ });
25030
+ }
25031
+ // to support hard deletion
25032
+ const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
25033
+ if (permanent) {
25034
+ setTimeout(() => {
25035
+ pushToTombstone('post', postId);
25036
+ }, 0);
25037
+ }
25038
+ else {
25039
+ upsertInCache(['post', 'get', postId], { isDeleted: true });
25040
+ }
25041
+ fireEvent('local.post.deleted', {
25042
+ posts: [deleted],
25043
+ categories: [],
25044
+ comments: [],
25045
+ communities: [],
25046
+ communityUsers: [],
25047
+ feeds: [],
25048
+ files: [],
25049
+ postChildren: [],
25050
+ users: [],
25051
+ videoStreamings: [],
25052
+ });
25053
+ return LinkedObject.post(deleted);
24264
25054
  };
24265
25055
 
24266
25056
  /* begin_public_function
24267
- id: comment.get
25057
+ id: post.soft_delete
24268
25058
  */
24269
25059
  /**
24270
25060
  * ```js
24271
- * import { CommentRepository } from '@amityco/ts-sdk';
24272
- *
24273
- * let comment;
24274
- *
24275
- * const unsub = CommentRepository.getComment(commentId, response => {
24276
- * comment = response.data;
24277
- * });
25061
+ * import { PostRepository } from '@amityco/ts-sdk'
25062
+ * const success = await PostRepository.softDeletePost('foobar')
24278
25063
  * ```
24279
25064
  *
24280
- * Observe all mutation on a given {@link Amity.Comment}
25065
+ * Soft deletes a {@link Amity.Post}
24281
25066
  *
24282
- * @param commentId the ID of the comment to observe
24283
- * @param callback the function to call when new data are available
24284
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
25067
+ * @param postId The {@link Amity.Post} ID to soft delete
25068
+ * @return A success boolean if the {@link Amity.Post} was deleted
24285
25069
  *
24286
- * @category Comment Live Object
25070
+ * @category Post API
25071
+ * @async
24287
25072
  */
24288
- const getComment = (commentId, callback) => {
24289
- return liveObject(commentId, callback, 'commentId', getComment$1, [
24290
- onCommentDeleteLocal,
24291
- onCommentDeleted,
24292
- onCommentFlagged,
24293
- onCommentReactionAdded,
24294
- onCommentReactionRemoved,
24295
- onCommentUnflagged,
24296
- onCommentUpdated,
24297
- onLocalCommentReactionAdded,
24298
- onLocalCommentReactionRemoved,
24299
- ]);
25073
+ const softDeletePost = async (postId) => {
25074
+ const client = getActiveClient();
25075
+ client.log('post/softDeletePost', postId);
25076
+ const softDeleted = await deletePost(postId, false);
25077
+ return LinkedObject.post(softDeleted);
24300
25078
  };
24301
25079
  /* end_public_function */
24302
25080
 
24303
- class CommentPaginationController extends PaginationController {
24304
- async getRequest(queryParams, token) {
24305
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
24306
- const baseOptions = {
24307
- type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
24308
- };
24309
- const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
24310
- const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
24311
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
24312
- });
24313
- return queryResponse;
24314
- }
24315
- }
24316
-
24317
- var EnumCommentActions;
24318
- (function (EnumCommentActions) {
24319
- EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
24320
- EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
24321
- EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
24322
- EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
24323
- EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
24324
- EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
24325
- EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
24326
- })(EnumCommentActions || (EnumCommentActions = {}));
24327
-
24328
- class CommentQueryStreamController extends QueryStreamController {
24329
- constructor(query, cacheKey, notifyChange, preparePayload) {
24330
- super(query, cacheKey);
24331
- this.notifyChange = notifyChange;
24332
- this.preparePayload = preparePayload;
24333
- }
24334
- async saveToMainDB(response) {
24335
- const processedPayload = await this.preparePayload(response);
24336
- const client = getActiveClient();
24337
- const cachedAt = client.cache && Date.now();
24338
- if (client.cache) {
24339
- ingestInCache(processedPayload, { cachedAt });
24340
- }
24341
- }
24342
- appendToQueryStream(response, direction, refresh = false) {
24343
- var _a, _b;
24344
- if (refresh) {
24345
- pushToCache(this.cacheKey, {
24346
- data: response.comments.map(getResolver('comment')),
24347
- });
24348
- }
24349
- else {
24350
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24351
- const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
24352
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
24353
- }
24354
- }
24355
- reactor(action) {
24356
- return (comment) => {
24357
- var _a;
24358
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24359
- if (this.query.referenceId !== comment.referenceId ||
24360
- this.query.referenceType !== comment.referenceType ||
24361
- !collection) {
24362
- return;
24363
- }
24364
- if (this.query.parentId && this.query.parentId !== comment.parentId) {
24365
- return;
24366
- }
24367
- if (!this.query.parentId && comment.parentId) {
24368
- return;
24369
- }
24370
- if (action === EnumCommentActions.OnCommentCreated) {
24371
- collection.data = [...new Set([comment.commentId, ...collection.data])];
24372
- }
24373
- pushToCache(this.cacheKey, collection);
24374
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
24375
- };
24376
- }
24377
- subscribeRTE(createSubscriber) {
24378
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
24379
- }
24380
- }
25081
+ /* begin_public_function
25082
+ id: post.hard_delete
25083
+ */
25084
+ /**
25085
+ * ```js
25086
+ * import { hardDeletePost } from '@amityco/ts-sdk'
25087
+ * const success = await hardDeletePost('foobar')
25088
+ * ```
25089
+ *
25090
+ * Hard deletes a {@link Amity.Post}
25091
+ *
25092
+ * @param postId The {@link Amity.Post} ID to be hard delete
25093
+ * @return A success boolean if the {@link Amity.Post} was deleted
25094
+ *
25095
+ * @category Post API
25096
+ * @async
25097
+ */
25098
+ const hardDeletePost = async (postId) => {
25099
+ const client = getActiveClient();
25100
+ client.log('post/hardDeletePost', postId);
25101
+ const hardDeleted = await deletePost(postId, true);
25102
+ return LinkedObject.post(hardDeleted);
25103
+ };
25104
+ /* end_public_function */
24381
25105
 
25106
+ /* begin_public_function
25107
+ id: post.approve
25108
+ */
24382
25109
  /**
24383
25110
  * ```js
24384
- * import { onCommentCreated } from '@amityco/ts-sdk'
24385
- * const dispose = onCommentCreated(comment => {
24386
- * // ...
24387
- * })
25111
+ * import { approvePost } from '@amityco/ts-sdk'
25112
+ *
25113
+ * const { data: post } = await approvePost('postId')
24388
25114
  * ```
24389
25115
  *
24390
- * Fired when a {@link Amity.InternalComment} has been created
25116
+ * Approves a {@link Amity.Post}
24391
25117
  *
24392
- * @param callback The function to call when the event was fired
24393
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25118
+ * @param postId The {@link Amity.Post} ID to be approved
25119
+ * @return A {@link Amity.Post} that was approved
24394
25120
  *
24395
- * @category Comment Events
25121
+ * @category Post API
25122
+ * @async
24396
25123
  */
24397
- const onCommentCreatedLocal = (callback) => {
24398
- return createLocalCommentEventSubscriber('local.comment.created', callback);
24399
- };
24400
-
24401
- class CommentLiveCollectionController extends LiveCollectionController {
24402
- constructor(query, callback) {
24403
- const queryStreamId = hash__default["default"](query);
24404
- const cacheKey = ['comments', 'collection', queryStreamId];
24405
- const paginationController = new CommentPaginationController(query);
24406
- super(paginationController, queryStreamId, cacheKey, callback);
24407
- this.query = query;
24408
- this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
24409
- this.callback = callback.bind(this);
24410
- this.loadPage({ initial: true });
24411
- }
24412
- setup() {
24413
- var _a;
24414
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24415
- if (!collection) {
24416
- pushToCache(this.cacheKey, {
24417
- data: [],
24418
- params: {},
24419
- });
24420
- }
24421
- }
24422
- async persistModel(queryPayload) {
24423
- await this.queryStreamController.saveToMainDB(queryPayload);
24424
- }
24425
- persistQueryStream({ response, direction, refresh, }) {
24426
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
24427
- }
24428
- startSubscription() {
24429
- return this.queryStreamController.subscribeRTE([
24430
- { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
24431
- { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
24432
- { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
24433
- { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
24434
- { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
24435
- { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
24436
- { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
24437
- { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
24438
- { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
24439
- { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
24440
- { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
24441
- ]);
24442
- }
24443
- notifyChange({ origin, loading, error }) {
24444
- var _a, _b;
24445
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24446
- if (!collection)
24447
- return;
24448
- const data = this.applyFilter((_b = collection.data
24449
- .map(id => pullFromCache(['comment', 'get', id]))
24450
- .filter(isNonNullable)
24451
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
24452
- if (!this.shouldNotify(data) && origin === 'event')
24453
- return;
24454
- this.callback({
24455
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
24456
- data,
24457
- hasNextPage: !!this.paginationController.getNextToken(),
24458
- loading,
24459
- error,
24460
- });
24461
- }
24462
- applyFilter(data) {
24463
- let comments = data;
24464
- if (!this.query.includeDeleted) {
24465
- comments = filterByPropEquality(comments, 'isDeleted', false);
24466
- }
24467
- if (this.query.parentId) {
24468
- comments = comments.filter(comment => comment.parentId === this.query.parentId);
24469
- }
24470
- if (typeof this.query.hasFlag === 'boolean') {
24471
- if (this.query.hasFlag) {
24472
- comments = comments.filter(comment => comment.hashFlag != null);
24473
- }
24474
- else {
24475
- comments = comments.filter(comment => comment.hashFlag == null);
24476
- }
24477
- }
24478
- if (this.query.dataTypes) {
24479
- if (this.query.dataTypes.matchType === 'exact') {
24480
- comments = comments.filter(comment => {
24481
- var _a, _b;
24482
- const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
24483
- const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
24484
- if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
24485
- return false;
24486
- }
24487
- return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
24488
- });
24489
- }
24490
- if (this.query.dataTypes.matchType === 'any') {
24491
- 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); }); });
24492
- }
24493
- }
24494
- switch (this.query.sortBy) {
24495
- case 'firstCreated':
24496
- comments = comments.sort(sortByFirstCreated);
24497
- break;
24498
- case 'lastCreated':
24499
- default:
24500
- comments = comments.sort(sortByLastCreated);
24501
- break;
24502
- }
24503
- return comments;
25124
+ const approvePost = async (postId) => {
25125
+ const client = getActiveClient();
25126
+ client.log('post/approvePost', postId);
25127
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
25128
+ fireEvent('post.approved', payload);
25129
+ // fire virtual event for community update
25130
+ if (payload.posts[0].targetType === 'community') {
25131
+ fireEvent('community.updated', payload);
24504
25132
  }
24505
- }
25133
+ const data = prepareMembershipPayload(payload, 'communityUsers');
25134
+ const cachedAt = client.cache && Date.now();
25135
+ if (client.cache)
25136
+ ingestInCache(data, { cachedAt });
25137
+ return {
25138
+ data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
25139
+ cachedAt,
25140
+ };
25141
+ };
25142
+ /* end_public_function */
24506
25143
 
24507
25144
  /* begin_public_function
24508
- id: comment.query
25145
+ id: post.decline
24509
25146
  */
24510
25147
  /**
24511
25148
  * ```js
24512
- * import { getComments } from '@amityco/ts-sdk'
25149
+ * import { declinePost } from '@amityco/ts-sdk'
24513
25150
  *
24514
- * let comments = []
24515
- * const unsub = getComments({
24516
- * referenceType: Amity.InternalComment['referenceType'];
24517
- * referenceId: Amity.InternalComment['referenceId'];
24518
- * }, response => merge(comments, response.data))
25151
+ * const {data: post} = await declinePost('postId')
24519
25152
  * ```
24520
25153
  *
24521
- * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
25154
+ * Declines a {@link Amity.Post}
24522
25155
  *
24523
- * @param referenceType the type of the target
24524
- * @param referenceId the ID of the target
24525
- * @param callback the function to call when new data are available
24526
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
25156
+ * @param postId The {@link Amity.Post} ID to be declined
25157
+ * @return A {@link Amity.Post} that was declined
24527
25158
  *
24528
- * @category Comments Live Collection
25159
+ * @category Post API
25160
+ * @async
24529
25161
  */
24530
- const getComments = (params, callback, config) => {
24531
- const { log, cache } = getActiveClient();
24532
- if (!cache) {
24533
- console.log('For using Live Collection feature you need to enable Cache!');
25162
+ const declinePost = async (postId) => {
25163
+ const client = getActiveClient();
25164
+ client.log('post/declinePost', postId);
25165
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
25166
+ // fire virtual event
25167
+ if (payload.posts[0].targetType === 'community') {
25168
+ fireEvent('community.updated', payload);
24534
25169
  }
24535
- const timestamp = Date.now();
24536
- log(`getComments(tmpid: ${timestamp}) > listen`);
24537
- const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
24538
- const disposers = commentsLiveCollection.startSubscription();
24539
- const cacheKey = commentsLiveCollection.getCacheKey();
24540
- disposers.push(() => dropFromCache(cacheKey));
24541
- return () => {
24542
- log(`getComments(tmpid: ${timestamp}) > dispose`);
24543
- disposers.forEach(fn => fn());
25170
+ fireEvent('post.declined', payload);
25171
+ const data = prepareMembershipPayload(payload, 'communityUsers');
25172
+ const cachedAt = client.cache && Date.now();
25173
+ if (client.cache)
25174
+ ingestInCache(data, { cachedAt });
25175
+ return {
25176
+ data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
25177
+ cachedAt,
24544
25178
  };
24545
25179
  };
24546
25180
  /* end_public_function */
24547
25181
 
24548
- var index$9 = /*#__PURE__*/Object.freeze({
24549
- __proto__: null,
24550
- getCommentByIds: getCommentByIds,
24551
- createComment: createComment,
24552
- updateComment: updateComment,
24553
- deleteComment: deleteComment,
24554
- softDeleteComment: softDeleteComment,
24555
- hardDeleteComment: hardDeleteComment,
24556
- flagComment: flagComment,
24557
- unflagComment: unflagComment,
24558
- isCommentFlaggedByMe: isCommentFlaggedByMe,
24559
- onCommentCreated: onCommentCreated,
24560
- onCommentUpdated: onCommentUpdated,
24561
- onCommentDeleted: onCommentDeleted,
24562
- onCommentFlagged: onCommentFlagged,
24563
- onCommentUnflagged: onCommentUnflagged,
24564
- onCommentReactionAdded: onCommentReactionAdded,
24565
- onCommentReactionRemoved: onCommentReactionRemoved,
24566
- getComment: getComment,
24567
- getComments: getComments
24568
- });
24569
-
25182
+ /* begin_public_function
25183
+ id: post.flag
25184
+ */
24570
25185
  /**
24571
25186
  * ```js
24572
- * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
24573
- * const dispose = onPostUpdatedLocal(post => {
24574
- * // ...
24575
- * })
25187
+ * import { PostRepository } from '@amityco/ts-sdk'
25188
+ * const flagged = await PostRepository.flagPost(postId, reason)
24576
25189
  * ```
24577
25190
  *
24578
- * Fired when a {@link Amity.InternalPost} has been updated
24579
- *
24580
- * @param callback The function to call when the event was fired
24581
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25191
+ * @param postId of the post to flag
25192
+ * @param reason the reason to flag the post
25193
+ * @returns a boolean
24582
25194
  *
24583
- * @category Post Events
24584
- */
24585
- const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
25195
+ * @category Post API
25196
+ * @async
25197
+ * */
25198
+ const flagPost = async (postId, reason) => {
25199
+ const client = getActiveClient();
25200
+ client.log('post/flagPost', postId);
25201
+ const isPredefinedReason = reason &&
25202
+ Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
25203
+ const body = {
25204
+ reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
25205
+ detail: reason && !isPredefinedReason ? reason : '',
25206
+ };
25207
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
25208
+ if (client.cache) {
25209
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
25210
+ }
25211
+ fireEvent('post.flagged', payload);
25212
+ return !!payload;
25213
+ };
25214
+ /* end_public_function */
24586
25215
 
25216
+ /* begin_public_function
25217
+ id: post.unflag
25218
+ */
24587
25219
  /**
24588
25220
  * ```js
24589
- * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
24590
- * const dispose = onPostReactionAdded(post => {
24591
- * // ...
24592
- * })
25221
+ * import { PostRepository } from '@amityco/ts-sdk'
25222
+ * const unflagged = await PostRepository.unflagPost(postId)
24593
25223
  * ```
24594
25224
  *
24595
- * Fired when a {@link Amity.InternalPost} has been reacted
24596
- *
24597
- * @param callback The function to call when the event was fired
24598
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25225
+ * @param postId of the post to unflag
25226
+ * @returns the unflag post result
24599
25227
  *
24600
- * @category Post Events
24601
- */
24602
- const onLocalPostReactionAdded = (callback) => {
25228
+ * @category Post API
25229
+ * @async
25230
+ * */
25231
+ const unflagPost = async (postId) => {
24603
25232
  const client = getActiveClient();
24604
- const filter = ({ post }) => {
24605
- if (!client.cache) {
24606
- callback(post);
24607
- }
24608
- else {
24609
- upsertInCache(['post', 'get', post.postId], post);
24610
- callback(post);
24611
- }
24612
- };
24613
- return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
25233
+ client.log('post/unflagPost', postId);
25234
+ const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
25235
+ if (client.cache) {
25236
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
25237
+ }
25238
+ fireEvent('post.unflagged', payload);
25239
+ return !!payload;
24614
25240
  };
25241
+ /* end_public_function */
24615
25242
 
25243
+ /* begin_public_function
25244
+ id: post.check_flag_by_me
25245
+ */
24616
25246
  /**
24617
25247
  * ```js
24618
- * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
24619
- * const dispose = onPostReactionRemoved(post => {
24620
- * // ...
24621
- * })
25248
+ * import { PostRepository } from '@amityco/ts-sdk'
25249
+ * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
24622
25250
  * ```
24623
25251
  *
24624
- * Fired when a {@link Amity.InternalPost} has been reacted
24625
- *
24626
- * @param callback The function to call when the event was fired
24627
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25252
+ * @param postId of the post to check if flagged by current user
25253
+ * @returns `true` if the post is flagged by me, `false` if doesn't.
24628
25254
  *
24629
- * @category Post Events
24630
- */
24631
- const onLocalPostReactionRemoved = (callback) => {
25255
+ * @category Post API
25256
+ * @async
25257
+ * */
25258
+ const isPostFlaggedByMe = async (postId) => {
24632
25259
  const client = getActiveClient();
24633
- const filter = ({ post }) => {
24634
- if (!client.cache) {
24635
- callback(post);
24636
- }
24637
- else {
24638
- upsertInCache(['post', 'get', post.postId], post);
24639
- callback(post);
24640
- }
24641
- };
24642
- return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
25260
+ client.log('post/isPostFlaggedByMe', postId);
25261
+ const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
25262
+ return result;
24643
25263
  };
25264
+ /* end_public_function */
24644
25265
 
25266
+ /* begin_public_function
25267
+ id: post.create.clip_post
25268
+ */
24645
25269
  /**
24646
25270
  * ```js
24647
- * import { onLocalPostDeleted } from '@amityco/ts-sdk'
24648
- * const dispose = onLocalPostDeleted(post => {
24649
- * // ...
24650
- * })
25271
+ * import { PostRepository } from '@amityco/ts-sdk'
25272
+ * const created = await PostRepository.createClipPost({
25273
+ * targetType: 'user',
25274
+ * targetId: 'foobar',
25275
+ * dataType: 'clip',
25276
+ * data: { text: 'hello world' },
25277
+ * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
25278
+ * }))
24651
25279
  * ```
24652
25280
  *
24653
- * Fired when a {@link Amity.InternalPost} has been deleted
25281
+ * Creates an {@link Amity.Post}
24654
25282
  *
24655
- * @param callback The function to call when the event was fired
24656
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25283
+ * @param bundle The data necessary to create a new {@link Amity.Post}
25284
+ * @returns The newly created {@link Amity.Post}
24657
25285
  *
24658
- * @category Post Events
25286
+ * @category Post API
25287
+ * @async
24659
25288
  */
24660
- const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
25289
+ const createClipPost = async (bundle) => {
25290
+ const client = getActiveClient();
25291
+ client.log('post/createPost', bundle);
25292
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
25293
+ fireEvent('post.created', payload);
25294
+ const data = prepareMembershipPayload(payload, 'communityUsers');
25295
+ const cachedAt = client.cache && Date.now();
25296
+ if (client.cache)
25297
+ ingestInCache(data, { cachedAt });
25298
+ const { posts } = data;
25299
+ return {
25300
+ data: LinkedObject.post(posts[0]),
25301
+ cachedAt,
25302
+ };
25303
+ };
25304
+ /* end_public_function */
24661
25305
 
24662
25306
  /* begin_public_function
24663
25307
  id: post.get
@@ -24681,7 +25325,7 @@ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.p
24681
25325
  *
24682
25326
  * @category Post Live Object
24683
25327
  */
24684
- const getPost$1 = (postId, callback) => {
25328
+ const getPost = (postId, callback) => {
24685
25329
  const responder = (snapshot) => {
24686
25330
  const { data } = snapshot;
24687
25331
  callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
@@ -24770,19 +25414,6 @@ class PostPaginationController extends PaginationController {
24770
25414
  }
24771
25415
  }
24772
25416
 
24773
- var EnumPostActions;
24774
- (function (EnumPostActions) {
24775
- EnumPostActions["OnPostCreated"] = "onPostCreated";
24776
- EnumPostActions["OnPostUpdated"] = "onPostUpdated";
24777
- EnumPostActions["OnPostDeleted"] = "onPostDeleted";
24778
- EnumPostActions["OnPostFlagged"] = "onPostFlagged";
24779
- EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
24780
- EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
24781
- EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
24782
- EnumPostActions["OnPostApproved"] = "onPostApproved";
24783
- EnumPostActions["OnPostDeclined"] = "onPostDeclined";
24784
- })(EnumPostActions || (EnumPostActions = {}));
24785
-
24786
25417
  class PostQueryStreamController extends QueryStreamController {
24787
25418
  constructor(query, cacheKey, notifyChange, preparePayload) {
24788
25419
  super(query, cacheKey);
@@ -24848,116 +25479,81 @@ class PostQueryStreamController extends QueryStreamController {
24848
25479
  }
24849
25480
  }
24850
25481
 
24851
- const getPost = async (postId) => {
24852
- const client = getActiveClient();
24853
- client.log('post/getPost', postId);
24854
- isInTombstone('post', postId);
24855
- let payload;
24856
- try {
24857
- // API-FIX: endpoint should not be /list, parameters should be querystring.
24858
- const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
24859
- payload = response.data;
24860
- }
24861
- catch (error) {
24862
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
24863
- pushToTombstone('post', postId);
24864
- }
24865
- throw error;
24866
- }
24867
- const data = prepareMembershipPayload(payload, 'communityUsers');
24868
- const cachedAt = client.cache && Date.now();
24869
- if (client.cache)
24870
- ingestInCache(data, { cachedAt });
24871
- const { posts } = data;
24872
- const result = posts.find(post => post.postId === postId);
24873
- return {
24874
- data: result,
24875
- cachedAt,
24876
- };
25482
+ const commentEventHandler = (callback, eventHandler, cacheKey, resolveId) => {
25483
+ return eventHandler(async (comment) => {
25484
+ var _a;
25485
+ const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25486
+ if (!currentCollection ||
25487
+ !currentCollection.data.includes(resolveId ? resolveId(comment.referenceId) : comment.referenceId))
25488
+ return;
25489
+ await getPost$1(comment.referenceId);
25490
+ callback(comment);
25491
+ });
24877
25492
  };
24878
- getPost.locally = (postId) => {
24879
- const client = getActiveClient();
24880
- client.log('post/getPost.locally', postId);
24881
- if (!client.cache)
24882
- return;
24883
- const cached = pullFromCache(['post', 'get', postId]);
24884
- if (!cached)
24885
- return;
24886
- return {
24887
- data: cached.data,
24888
- cachedAt: cached.cachedAt,
24889
- };
25493
+ const generateCommentSubscriptions = ({ cacheKey, resolveId, }) => {
25494
+ const eventHandlers = [
25495
+ onCommentCreated,
25496
+ onCommentDeleted,
25497
+ onCommentReactionAdded,
25498
+ onCommentReactionRemoved,
25499
+ onCommentCreatedLocal,
25500
+ onCommentDeleteLocal,
25501
+ onLocalCommentReactionAdded,
25502
+ onLocalCommentReactionRemoved,
25503
+ ];
25504
+ return eventHandlers.map(handler => ({
25505
+ fn: convertEventPayload((callback) => commentEventHandler(callback, handler, cacheKey, resolveId), 'referenceId', 'post'),
25506
+ action: EnumPostActions.OnPostUpdated,
25507
+ }));
25508
+ };
25509
+ const getPostSubscription = (cacheKey) => {
25510
+ return [
25511
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
25512
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
25513
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
25514
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
25515
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
25516
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
25517
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
25518
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
25519
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
25520
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
25521
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
25522
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
25523
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
25524
+ ...generateCommentSubscriptions({ cacheKey }),
25525
+ ];
24890
25526
  };
24891
25527
 
24892
25528
  class PostLiveCollectionController extends LiveCollectionController {
24893
25529
  constructor(query, callback) {
24894
- const queryStreamId = hash__default["default"](query);
24895
- const cacheKey = ['posts', 'collection', queryStreamId];
24896
- const paginationController = new PostPaginationController(query);
24897
- super(paginationController, queryStreamId, cacheKey, callback);
24898
- this.query = query;
24899
- this.queryStreamController = new PostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
24900
- this.callback = callback.bind(this);
24901
- this.loadPage({ initial: true });
24902
- }
24903
- setup() {
24904
- var _a;
24905
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24906
- if (!collection) {
24907
- pushToCache(this.cacheKey, {
24908
- data: [],
24909
- params: {},
24910
- });
24911
- }
24912
- }
24913
- async persistModel(queryPayload) {
24914
- await this.queryStreamController.saveToMainDB(queryPayload);
24915
- }
24916
- persistQueryStream({ response, direction, refresh, }) {
24917
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
24918
- }
24919
- startSubscription() {
24920
- return this.queryStreamController.subscribeRTE([
24921
- { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
24922
- { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
24923
- { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
24924
- { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
24925
- { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
24926
- { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
24927
- { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
24928
- { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
24929
- { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
24930
- { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
24931
- { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
24932
- { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
24933
- { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
24934
- {
24935
- fn: convertEventPayload((callback) => {
24936
- return onCommentCreated(async (comment) => {
24937
- var _a;
24938
- const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24939
- if (!currentCollection || currentCollection.data.includes(comment.referenceId))
24940
- return;
24941
- await getPost(comment.referenceId);
24942
- callback(comment);
24943
- });
24944
- }, 'referenceId', 'post'),
24945
- action: EnumPostActions.OnPostUpdated,
24946
- },
24947
- {
24948
- fn: convertEventPayload((callback) => {
24949
- return onCommentDeleted(async (comment) => {
24950
- var _a;
24951
- const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24952
- if (!currentCollection || currentCollection.data.includes(comment.referenceId))
24953
- return;
24954
- await getPost(comment.referenceId);
24955
- callback(comment);
24956
- });
24957
- }, 'referenceId', 'post'),
24958
- action: EnumPostActions.OnPostUpdated,
24959
- },
24960
- ]);
25530
+ const queryStreamId = hash__default["default"](query);
25531
+ const cacheKey = ['posts', 'collection', queryStreamId];
25532
+ const paginationController = new PostPaginationController(query);
25533
+ super(paginationController, queryStreamId, cacheKey, callback);
25534
+ this.query = query;
25535
+ this.queryStreamController = new PostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
25536
+ this.callback = callback.bind(this);
25537
+ this.loadPage({ initial: true });
25538
+ }
25539
+ setup() {
25540
+ var _a;
25541
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25542
+ if (!collection) {
25543
+ pushToCache(this.cacheKey, {
25544
+ data: [],
25545
+ params: {},
25546
+ });
25547
+ }
25548
+ }
25549
+ async persistModel(queryPayload) {
25550
+ await this.queryStreamController.saveToMainDB(queryPayload);
25551
+ }
25552
+ persistQueryStream({ response, direction, refresh, }) {
25553
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
25554
+ }
25555
+ startSubscription() {
25556
+ return this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
24961
25557
  }
24962
25558
  notifyChange({ origin, loading, error }) {
24963
25559
  var _a, _b;
@@ -25092,6 +25688,22 @@ class PinnedPostQueryStreamController extends QueryStreamController {
25092
25688
  });
25093
25689
  }
25094
25690
  }
25691
+ reactor(action) {
25692
+ return (post) => {
25693
+ var _a;
25694
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25695
+ if (!collection)
25696
+ return;
25697
+ if (action === EnumPostActions.OnPostDeleted) {
25698
+ collection.data = collection.data.filter(referenceId => referenceId !== `global#${post.postId}`);
25699
+ }
25700
+ pushToCache(this.cacheKey, collection);
25701
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
25702
+ };
25703
+ }
25704
+ subscribeRTE(createSubscriber) {
25705
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
25706
+ }
25095
25707
  }
25096
25708
 
25097
25709
  class PinnedPostLiveCollectionController extends LiveCollectionController {
@@ -25123,7 +25735,10 @@ class PinnedPostLiveCollectionController extends LiveCollectionController {
25123
25735
  }
25124
25736
  // eslint-disable-next-line class-methods-use-this
25125
25737
  startSubscription() {
25126
- return [];
25738
+ return this.queryStreamController.subscribeRTE(generateCommentSubscriptions({
25739
+ cacheKey: this.cacheKey,
25740
+ resolveId: id => `${this.query.placement}#${id}`,
25741
+ }));
25127
25742
  }
25128
25743
  notifyChange({ origin, loading, error }) {
25129
25744
  var _a, _b;
@@ -25275,6 +25890,10 @@ class GlobalPinnedPostLiveCollectionController extends LiveCollectionController
25275
25890
  fn: onPostDeleted,
25276
25891
  action: EnumPostActions.OnPostDeleted,
25277
25892
  },
25893
+ ...generateCommentSubscriptions({
25894
+ cacheKey: this.cacheKey,
25895
+ resolveId: id => `global#${id}`,
25896
+ }),
25278
25897
  ]);
25279
25898
  }
25280
25899
  notifyChange({ origin, loading, error }) {
@@ -25554,6 +26173,238 @@ const semanticSearchPosts = (params, callback, config) => {
25554
26173
  };
25555
26174
  };
25556
26175
 
26176
+ class SearchPostPaginationController extends PaginationController {
26177
+ async getRequest(queryParams, token) {
26178
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, matchingOnlyParentPost, hashtags, dataTypes, targetType = 'all' } = queryParams, params = __rest(queryParams, ["limit", "matchingOnlyParentPost", "hashtags", "dataTypes", "targetType"]);
26179
+ const baseOptions = {
26180
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
26181
+ };
26182
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
26183
+ const { data: queryResponse } = await this.http.get(`/api/v1/search/posts`, {
26184
+ params: Object.assign(Object.assign({}, params), { hashtags,
26185
+ dataTypes,
26186
+ targetType,
26187
+ /*
26188
+ * when creating post like image, file, video BE will create 2 posts
26189
+ * 1. parent post to store text with dataType=text
26190
+ * 2. child post to store dataTypes post data
26191
+ *
26192
+ * By default, BE queries only parent post
26193
+ */
26194
+ matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
26195
+ });
26196
+ return queryResponse;
26197
+ }
26198
+ }
26199
+
26200
+ class SearchPostQueryStreamController extends QueryStreamController {
26201
+ constructor(query, cacheKey, notifyChange, preparePayload) {
26202
+ super(query, cacheKey);
26203
+ this.notifyChange = notifyChange;
26204
+ this.preparePayload = preparePayload;
26205
+ }
26206
+ async saveToMainDB(response) {
26207
+ const processedPayload = await this.preparePayload(response);
26208
+ const client = getActiveClient();
26209
+ const cachedAt = client.cache && Date.now();
26210
+ if (client.cache) {
26211
+ ingestInCache(processedPayload, { cachedAt });
26212
+ }
26213
+ }
26214
+ appendToQueryStream(response, direction, refresh = false) {
26215
+ var _a, _b;
26216
+ if (refresh) {
26217
+ pushToCache(this.cacheKey, {
26218
+ data: response.posts.map(getResolver('post')),
26219
+ });
26220
+ }
26221
+ else {
26222
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26223
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
26224
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
26225
+ }
26226
+ }
26227
+ reactor(action) {
26228
+ return (post) => {
26229
+ var _a, _b;
26230
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26231
+ if (!collection)
26232
+ return;
26233
+ if (post.parentPostId && post.isDeleted) {
26234
+ const parentPost = (_b = pullFromCache([
26235
+ 'post',
26236
+ 'get',
26237
+ post.parentPostId,
26238
+ ])) === null || _b === void 0 ? void 0 : _b.data;
26239
+ if (!parentPost)
26240
+ return;
26241
+ parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
26242
+ pushToCache(['post', 'get', parentPost.postId], parentPost);
26243
+ }
26244
+ if (action === EnumPostActions.OnPostDeclined) {
26245
+ collection.data = collection.data.filter(postId => postId !== post.postId);
26246
+ }
26247
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
26248
+ collection.data = [...new Set([post.postId, ...collection.data])];
26249
+ }
26250
+ pushToCache(this.cacheKey, collection);
26251
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
26252
+ };
26253
+ }
26254
+ subscribeRTE(createSubscriber) {
26255
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
26256
+ }
26257
+ }
26258
+
26259
+ class SearchPostLiveCollectionController extends LiveCollectionController {
26260
+ constructor(query, callback) {
26261
+ const queryStreamId = hash__default["default"](query);
26262
+ const cacheKey = ['posts', 'collection', queryStreamId];
26263
+ const paginationController = new SearchPostPaginationController(query);
26264
+ super(paginationController, queryStreamId, cacheKey, callback);
26265
+ this.query = query;
26266
+ this.queryStreamController = new SearchPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
26267
+ this.callback = callback.bind(this);
26268
+ this.loadPage({ initial: true });
26269
+ }
26270
+ setup() {
26271
+ var _a;
26272
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26273
+ if (!collection) {
26274
+ pushToCache(this.cacheKey, {
26275
+ data: [],
26276
+ params: {},
26277
+ });
26278
+ }
26279
+ }
26280
+ async persistModel(queryPayload) {
26281
+ await this.queryStreamController.saveToMainDB(queryPayload);
26282
+ }
26283
+ persistQueryStream({ response, direction, refresh, }) {
26284
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
26285
+ }
26286
+ startSubscription() {
26287
+ return this.queryStreamController.subscribeRTE([
26288
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
26289
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
26290
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
26291
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
26292
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
26293
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
26294
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
26295
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
26296
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
26297
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
26298
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
26299
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
26300
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
26301
+ {
26302
+ fn: convertEventPayload((callback) => {
26303
+ return onCommentCreated(async (comment) => {
26304
+ var _a;
26305
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26306
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
26307
+ return;
26308
+ await getPost$1(comment.referenceId);
26309
+ callback(comment);
26310
+ });
26311
+ }, 'referenceId', 'post'),
26312
+ action: EnumPostActions.OnPostUpdated,
26313
+ },
26314
+ {
26315
+ fn: convertEventPayload((callback) => {
26316
+ return onCommentDeleted(async (comment) => {
26317
+ var _a;
26318
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26319
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
26320
+ return;
26321
+ await getPost$1(comment.referenceId);
26322
+ callback(comment);
26323
+ });
26324
+ }, 'referenceId', 'post'),
26325
+ action: EnumPostActions.OnPostUpdated,
26326
+ },
26327
+ ]);
26328
+ }
26329
+ notifyChange({ origin, loading, error }) {
26330
+ var _a, _b;
26331
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26332
+ if (!collection)
26333
+ return;
26334
+ const data = this.applyFilter((_b = collection.data
26335
+ .map(id => pullFromCache(['post', 'get', id]))
26336
+ .filter(isNonNullable)
26337
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
26338
+ if (!this.shouldNotify(data) && origin === 'event')
26339
+ return;
26340
+ this.callback({
26341
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
26342
+ data,
26343
+ hasNextPage: !!this.paginationController.getNextToken(),
26344
+ loading,
26345
+ error,
26346
+ });
26347
+ }
26348
+ applyFilter(data) {
26349
+ var _a;
26350
+ let posts = data;
26351
+ if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
26352
+ posts = filterByPostDataTypes(posts, this.query.dataTypes);
26353
+ }
26354
+ switch (this.query.sortBy) {
26355
+ case 'firstCreated':
26356
+ posts = posts.sort(sortByFirstCreated);
26357
+ break;
26358
+ case 'lastCreated':
26359
+ default:
26360
+ posts = posts.sort(sortByLastCreated);
26361
+ break;
26362
+ }
26363
+ return posts;
26364
+ }
26365
+ }
26366
+
26367
+ /* begin_public_function
26368
+ id: post.query
26369
+ */
26370
+ /**
26371
+ * ```js
26372
+ * import { PostRepository } from '@amityco/ts-sdk'
26373
+ *
26374
+ * let posts = []
26375
+ * const unsub = PostRepository.searchPostsByHashtag({
26376
+ * hashtags: ['amity'],
26377
+ * limit: 10,
26378
+ * }, response => merge(posts, response.data))
26379
+ * ```
26380
+ *
26381
+ * Observe all mutations on a list of {@link Amity.Post} for a given target object
26382
+ *
26383
+ * @param params.hashtags the hashtags to search for
26384
+ * @param callback the function to call when new data are available
26385
+ * @param config
26386
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
26387
+ *
26388
+ * @category Posts Live Collection
26389
+ */
26390
+ const searchPostsByHashtag = (params, callback, config) => {
26391
+ const { log, cache } = getActiveClient();
26392
+ if (!cache) {
26393
+ console.log(ENABLE_CACHE_MESSAGE);
26394
+ }
26395
+ const timestamp = Date.now();
26396
+ log(`searchPostsByHashtag(tmpid: ${timestamp}) > listen`);
26397
+ const postsLiveCollection = new SearchPostLiveCollectionController(params, callback);
26398
+ const disposers = postsLiveCollection.startSubscription();
26399
+ const cacheKey = postsLiveCollection.getCacheKey();
26400
+ disposers.push(() => dropFromCache(cacheKey));
26401
+ return () => {
26402
+ log(`searchPostsByHashtag(tmpid: ${timestamp}) > dispose`);
26403
+ disposers.forEach(fn => fn());
26404
+ };
26405
+ };
26406
+ /* end_public_function */
26407
+
25557
26408
  var index$8 = /*#__PURE__*/Object.freeze({
25558
26409
  __proto__: null,
25559
26410
  getPostByIds: getPostByIds,
@@ -25577,11 +26428,12 @@ var index$8 = /*#__PURE__*/Object.freeze({
25577
26428
  onPostUnflagged: onPostUnflagged,
25578
26429
  onPostReactionAdded: onPostReactionAdded,
25579
26430
  onPostReactionRemoved: onPostReactionRemoved,
25580
- getPost: getPost$1,
26431
+ getPost: getPost,
25581
26432
  getPosts: getPosts,
25582
26433
  getPinnedPosts: getPinnedPosts,
25583
26434
  getGlobalPinnedPosts: getGlobalPinnedPosts,
25584
- semanticSearchPosts: semanticSearchPosts
26435
+ semanticSearchPosts: semanticSearchPosts,
26436
+ searchPostsByHashtag: searchPostsByHashtag
25585
26437
  });
25586
26438
 
25587
26439
  /* begin_public_function
@@ -26186,8 +27038,8 @@ var index$7 = /*#__PURE__*/Object.freeze({
26186
27038
  * const created = await createPoll({
26187
27039
  * question: 'question',
26188
27040
  * answers: [
26189
- * { dataType: 'text', data: 'answer1' },
26190
- * { dataType: 'text', data: 'answer2' },
27041
+ * { dataType: 'text', data: 'answer1', fileId: 'fileId1' },
27042
+ * { dataType: 'text', data: 'answer2', fileId: 'fileId2' },
26191
27043
  * ],
26192
27044
  * closedIn: 1649136484
26193
27045
  * }))
@@ -26460,7 +27312,7 @@ var index$6 = /*#__PURE__*/Object.freeze({
26460
27312
  getPoll: getPoll
26461
27313
  });
26462
27314
 
26463
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
27315
+ const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
26464
27316
  /*
26465
27317
  * The crypto algorithm used for importing key and signing string
26466
27318
  */
@@ -28780,13 +29632,13 @@ exports.AdRepository = index$3;
28780
29632
  exports.CategoryRepository = index$b;
28781
29633
  exports.ChannelRepository = index$f;
28782
29634
  exports.Client = index$o;
28783
- exports.CommentRepository = index$9;
29635
+ exports.CommentRepository = index$a;
28784
29636
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
28785
29637
  exports.CommunityPostSettings = CommunityPostSettings;
28786
29638
  exports.CommunityRepository = index$c;
28787
29639
  exports.ContentFeedType = ContentFeedType;
28788
29640
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
28789
- exports.FeedRepository = index$a;
29641
+ exports.FeedRepository = index$9;
28790
29642
  exports.FileRepository = index$l;
28791
29643
  exports.FileType = FileType;
28792
29644
  exports.InvitationRepository = index$1;