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