@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.esm.js CHANGED
@@ -137,10 +137,33 @@ var JoinResultStatusEnum;
137
137
  JoinResultStatusEnum["Pending"] = "pending";
138
138
  })(JoinResultStatusEnum || (JoinResultStatusEnum = {}));
139
139
 
140
+ var FeedDataTypeEnum;
141
+ (function (FeedDataTypeEnum) {
142
+ FeedDataTypeEnum["Text"] = "text";
143
+ FeedDataTypeEnum["Video"] = "video";
144
+ FeedDataTypeEnum["Image"] = "image";
145
+ FeedDataTypeEnum["File"] = "file";
146
+ FeedDataTypeEnum["LiveStream"] = "liveStream";
147
+ FeedDataTypeEnum["Clip"] = "clip";
148
+ FeedDataTypeEnum["Poll"] = "poll";
149
+ })(FeedDataTypeEnum || (FeedDataTypeEnum = {}));
150
+ var FeedSortByEnum;
151
+ (function (FeedSortByEnum) {
152
+ FeedSortByEnum["LastCreated"] = "lastCreated";
153
+ FeedSortByEnum["FirstCreated"] = "firstCreated";
154
+ FeedSortByEnum["LastUpdated"] = "lastUpdated";
155
+ FeedSortByEnum["FirstUpdated"] = "firstUpdated";
156
+ })(FeedSortByEnum || (FeedSortByEnum = {}));
157
+ var FeedSourceEnum;
158
+ (function (FeedSourceEnum) {
159
+ FeedSourceEnum["Community"] = "community";
160
+ FeedSourceEnum["User"] = "user";
161
+ })(FeedSourceEnum || (FeedSourceEnum = {}));
162
+
140
163
  function getVersion() {
141
164
  try {
142
- // the string ''v7.8.0-esm'' should be replaced by actual value by @rollup/plugin-replace
143
- return 'v7.8.0-esm';
165
+ // the string ''v7.8.1-esm'' should be replaced by actual value by @rollup/plugin-replace
166
+ return 'v7.8.1-esm';
144
167
  }
145
168
  catch (error) {
146
169
  return '__dev__';
@@ -642,7 +665,8 @@ const PAYLOAD2MODEL = {
642
665
  };
643
666
  /** hidden */
644
667
  const isOutdated = (prevData, nextData) => {
645
- if ('updatedAt' in nextData && 'updatedAt' in nextData) {
668
+ // Check if the new value is outdated.
669
+ if ('updatedAt' in nextData && 'updatedAt' in prevData) {
646
670
  return new Date(nextData.updatedAt) < new Date(prevData.updatedAt);
647
671
  }
648
672
  return false;
@@ -25872,6 +25896,26 @@ const fetchLinkPreview = async (url) => {
25872
25896
  return data;
25873
25897
  };
25874
25898
 
25899
+ /**
25900
+ * ```js
25901
+ * import Client from '@amityco/ts-sdk'
25902
+ * const shareableLinkConfiguration = await Client.getShareableLinkConfiguration()
25903
+ * const postLinkPattern = shareableLinkConfiguration.post
25904
+ * ```
25905
+ *
25906
+ * Fetches a {@link Amity.ShareableLinkConfiguration} object
25907
+ *
25908
+ * @returns A Promise of {@link Amity.ShareableLinkConfiguration} object
25909
+ *
25910
+ * @category Client API
25911
+ * @async
25912
+ */
25913
+ const getShareableLinkConfiguration = async () => {
25914
+ const client = getActiveClient();
25915
+ const { data } = await client.http.get(`/api/v3/network-settings/shareable-deep-links`);
25916
+ return data;
25917
+ };
25918
+
25875
25919
  /**
25876
25920
  * ```js
25877
25921
  * import { onChannelMarkerFetched } from '@amityco/ts-sdk'
@@ -26241,6 +26285,8 @@ var index$o = /*#__PURE__*/Object.freeze({
26241
26285
  enableUnreadCount: enableUnreadCount,
26242
26286
  setUploadedFileAccessType: setUploadedFileAccessType,
26243
26287
  fetchLinkPreview: fetchLinkPreview,
26288
+ getSocialSettings: getSocialSettings,
26289
+ getShareableLinkConfiguration: getShareableLinkConfiguration,
26244
26290
  onConnectionError: onConnectionError,
26245
26291
  onClientDisconnected: onClientDisconnected,
26246
26292
  onClientBanned: onClientBanned,
@@ -27944,15 +27990,18 @@ function isAmityClipPost(post) {
27944
27990
  }
27945
27991
 
27946
27992
  const postLinkedObject = (post) => {
27947
- return Object.assign(Object.assign({}, post), { childrenPosts: post.children
27993
+ return shallowClone(post, {
27994
+ childrenPosts: post.children
27948
27995
  .map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
27949
27996
  .filter(isNonNullable)
27950
- .map(postLinkedObject), analytics: {
27997
+ .map(postLinkedObject),
27998
+ analytics: {
27951
27999
  markAsViewed: () => {
27952
28000
  const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
27953
28001
  analyticsEngineInstance.markPostAsViewed(post.postId);
27954
28002
  },
27955
- }, get latestComments() {
28003
+ },
28004
+ get latestComments() {
27956
28005
  if (!post.comments)
27957
28006
  return [];
27958
28007
  return (post.comments
@@ -28026,7 +28075,8 @@ const postLinkedObject = (post) => {
28026
28075
  return isAmityClipPost(post)
28027
28076
  ? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
28028
28077
  : undefined;
28029
- } });
28078
+ },
28079
+ });
28030
28080
  };
28031
28081
 
28032
28082
  const getCachedMarker = (message) => {
@@ -31021,7 +31071,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
31021
31071
  ]);
31022
31072
  if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
31023
31073
  return true;
31024
- const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
31074
+ const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }), updatedAt: new Date().toISOString() });
31025
31075
  if (referenceType === 'comment') {
31026
31076
  fireEvent('local.comment.addReaction', {
31027
31077
  comment: updatedModel,
@@ -31144,7 +31194,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
31144
31194
  ]);
31145
31195
  if (!model)
31146
31196
  return true;
31147
- const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }) });
31197
+ const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }), updatedAt: new Date().toISOString() });
31148
31198
  if (referenceType === 'comment') {
31149
31199
  fireEvent('local.comment.removeReaction', {
31150
31200
  comment: updatedModel,
@@ -31258,6 +31308,33 @@ const prepareSemanticSearchPostPayload = (_a) => {
31258
31308
  return Object.assign(Object.assign({}, processedPostPayload), { polls });
31259
31309
  };
31260
31310
 
31311
+ const processDeleteChildPost = (payload) => {
31312
+ var _a;
31313
+ const post = payload.posts[0];
31314
+ if (!post.parentId) {
31315
+ // post is parent post => should mark child post as delete as well
31316
+ post.children.forEach(childrenId => mergeInCache(['post', 'get', childrenId], {
31317
+ isDeleted: true,
31318
+ }));
31319
+ }
31320
+ else {
31321
+ // child post in a parent post
31322
+ const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
31323
+ if (!parentPost)
31324
+ return;
31325
+ pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: parentPost.children.filter(childId => childId !== post.postId) }));
31326
+ }
31327
+ };
31328
+ const processCreateChildPost = (payload) => {
31329
+ var _a;
31330
+ const post = payload.posts[0];
31331
+ if (!post.parentId)
31332
+ return;
31333
+ const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
31334
+ if (!parentPost)
31335
+ return;
31336
+ pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: [...new Set([post.postId, ...parentPost.children])] }));
31337
+ };
31261
31338
  const createPostEventSubscriber = (event, callback) => {
31262
31339
  const client = getActiveClient();
31263
31340
  const filter = (payload) => {
@@ -31282,6 +31359,7 @@ const createPostEventSubscriber = (event, callback) => {
31282
31359
  }
31283
31360
  if (event === 'post.deleted') {
31284
31361
  const { postId, postedUserId } = payload.posts[0];
31362
+ processDeleteChildPost(payload);
31285
31363
  try {
31286
31364
  isInTombstone('post', postId);
31287
31365
  }
@@ -31308,6 +31386,8 @@ const createPostEventSubscriber = (event, callback) => {
31308
31386
  }
31309
31387
  queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
31310
31388
  }
31389
+ if (event === 'post.created')
31390
+ processCreateChildPost(payload);
31311
31391
  callback(post.data);
31312
31392
  }
31313
31393
  };
@@ -31334,6 +31414,8 @@ const createLocalPostEventSubscriber = (event, callback) => {
31334
31414
  });
31335
31415
  }
31336
31416
  const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
31417
+ if (event === 'local.post.deleted')
31418
+ processDeleteChildPost(payload);
31337
31419
  callback(post.data);
31338
31420
  }
31339
31421
  };
@@ -37865,10 +37947,10 @@ class CommunityLiveCollectionController extends LiveCollectionController {
37865
37947
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
37866
37948
  if (!collection)
37867
37949
  return;
37868
- const data = this.applyFilter((_b = collection.data
37950
+ const data = (_b = collection.data
37869
37951
  .map(id => pullFromCache(['community', 'get', id]))
37870
37952
  .filter(isNonNullable)
37871
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
37953
+ .map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
37872
37954
  if (!this.shouldNotify(data) && origin === 'event')
37873
37955
  return;
37874
37956
  this.callback({
@@ -39109,6 +39191,9 @@ var index$b = /*#__PURE__*/Object.freeze({
39109
39191
  id: feed.query.global_feed
39110
39192
  */
39111
39193
  /**
39194
+ *
39195
+ * @deprecated This function will to be deprecated. Please use getGlobalFeed instead.
39196
+ *
39112
39197
  * ```js
39113
39198
  * import { queryGlobalFeed } from '@amityco/ts-sdk'
39114
39199
  * const posts = await queryGlobalFeed()
@@ -39191,1086 +39276,1023 @@ queryGlobalFeed.locally = (query) => {
39191
39276
  : undefined;
39192
39277
  };
39193
39278
 
39194
- /* begin_public_function
39195
- id: feed.query.custom_ranking_feed
39196
- */
39197
- /**
39198
- * ```js
39199
- * import { FeedRepository } from '@amityco/ts-sdk'
39200
- * const posts = await FeedRepository.getCustomRankingGlobalFeed()
39201
- * ```
39202
- *
39203
- * Queries a paginable list of {@link Amity.Post} objects
39204
- *
39205
- * @param query The query parameters
39206
- * @returns A page of {@link Amity.Post} objects
39207
- *
39208
- * @category Feed API
39209
- * @async
39210
- * */
39211
- const getCustomRankingGlobalFeed = async (query) => {
39212
- const client = getActiveClient();
39213
- client.log('feed/getCustomRankingGlobalFeed', query);
39214
- const _a = query !== null && query !== void 0 ? query : {}, { queryToken, limit } = _a, params = __rest(_a, ["queryToken", "limit"]);
39215
- const options = (() => {
39216
- if (queryToken)
39217
- return { token: queryToken };
39218
- return undefined;
39219
- })();
39220
- const { data: queryPayload } = await client.http.get(`/api/v5/me/global-feeds`, {
39221
- params: Object.assign(Object.assign({}, params), { limit: !queryToken ? limit : undefined, options }),
39222
- });
39223
- const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
39224
- const data = prepareMembershipPayload(payload, 'communityUsers');
39225
- const { posts } = data;
39226
- const cachedAt = client.cache && Date.now();
39227
- if (client.cache) {
39228
- ingestInCache(data);
39229
- const cacheKey = ['customGlobalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
39230
- pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
39279
+ class CustomRankingGlobalFeedPaginationController extends PaginationController {
39280
+ async getRequest(queryParams, token) {
39281
+ const { limit } = queryParams, params = __rest(queryParams, ["limit"]);
39282
+ const options = token ? { token } : { limit };
39283
+ const { data: queryResponse } = await this.http.get(`/api/v5/me/global-feeds`, {
39284
+ params: Object.assign(Object.assign({}, params), { options }),
39285
+ });
39286
+ return queryResponse;
39231
39287
  }
39232
- return { data: posts.map(LinkedObject.post), cachedAt, paging };
39233
- };
39234
- /* end_public_function */
39235
- /**
39236
- * ```js
39237
- * import { FeedRepository } from '@amityco/ts-sdk'
39238
- * const posts = await FeedRepository.getCustomRankingGlobalFeed.locally()
39239
- * ```
39240
- *
39241
- * Queries a paginable list of {@link Amity.Post} objects from cache
39242
- *
39243
- * @param query The query parameters
39244
- * @returns A page of {@link Amity.Post} objects
39245
- *
39246
- * @category Feed API
39247
- * @async
39248
- * */
39249
- getCustomRankingGlobalFeed.locally = (query) => {
39250
- var _a, _b;
39251
- const client = getActiveClient();
39252
- client.log('post/getCustomRankingGlobalFeed.locally', query);
39253
- if (!client.cache)
39254
- return;
39255
- const params = __rest(query !== null && query !== void 0 ? query : {}, []);
39256
- const queryKey = ['customGlobalFeed', 'query', Object.assign({}, params)];
39257
- const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
39258
- if (!(data === null || data === void 0 ? void 0 : data.posts.length))
39259
- return;
39260
- const posts = data.posts
39261
- .map(postId => pullFromCache(['post', 'get', postId]))
39262
- .filter(Boolean)
39263
- .map(({ data }) => data);
39264
- const { paging } = data;
39265
- return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
39266
- ? { data: posts.map(LinkedObject.post), cachedAt, paging }
39267
- : undefined;
39268
- };
39288
+ }
39269
39289
 
39270
- var index$a = /*#__PURE__*/Object.freeze({
39271
- __proto__: null,
39272
- queryGlobalFeed: queryGlobalFeed,
39273
- getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
39274
- });
39290
+ var EnumPostActions;
39291
+ (function (EnumPostActions) {
39292
+ EnumPostActions["OnPostCreated"] = "onPostCreated";
39293
+ EnumPostActions["OnPostUpdated"] = "onPostUpdated";
39294
+ EnumPostActions["OnPostDeleted"] = "onPostDeleted";
39295
+ EnumPostActions["OnPostFlagged"] = "onPostFlagged";
39296
+ EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
39297
+ EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
39298
+ EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
39299
+ EnumPostActions["OnPostApproved"] = "onPostApproved";
39300
+ EnumPostActions["OnPostDeclined"] = "onPostDeclined";
39301
+ })(EnumPostActions || (EnumPostActions = {}));
39302
+
39303
+ class CustomRankingGlobalFeedQueryStreamController extends QueryStreamController {
39304
+ constructor(query, cacheKey, notifyChange, preparePayload) {
39305
+ super(query, cacheKey);
39306
+ this.notifyChange = notifyChange;
39307
+ this.preparePayload = preparePayload;
39308
+ }
39309
+ async saveToMainDB(response) {
39310
+ const processedPayload = await this.preparePayload(response);
39311
+ const client = getActiveClient();
39312
+ const cachedAt = client.cache && Date.now();
39313
+ if (client.cache) {
39314
+ ingestInCache(processedPayload, { cachedAt });
39315
+ }
39316
+ }
39317
+ appendToQueryStream(response, direction, refresh = false) {
39318
+ var _a, _b;
39319
+ if (refresh) {
39320
+ pushToCache(this.cacheKey, {
39321
+ data: response.posts.map(getResolver('post')),
39322
+ });
39323
+ }
39324
+ else {
39325
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
39326
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
39327
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
39328
+ }
39329
+ }
39330
+ reactor(action) {
39331
+ return (post) => {
39332
+ var _a;
39333
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
39334
+ if (!collection)
39335
+ return;
39336
+ if (post.parentPostId && !collection.data.includes(post.parentPostId))
39337
+ return;
39338
+ // Delete Action
39339
+ if (action === EnumPostActions.OnPostDeleted) {
39340
+ // Parent Post - Remove from collection
39341
+ collection.data = collection.data.filter(postId => postId !== post.postId);
39342
+ }
39343
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
39344
+ // If the query has dataTypes array with value, check if post.dataType is include in the array
39345
+ if (this.query.dataTypes && this.query.dataTypes.length > 0) {
39346
+ if (!this.query.dataTypes.includes(post.dataType))
39347
+ return;
39348
+ }
39349
+ collection.data = [...new Set([post.postId, ...collection.data])];
39350
+ }
39351
+ if (action === EnumPostActions.OnPostDeclined) {
39352
+ collection.data = collection.data.filter(postId => postId !== post.postId);
39353
+ }
39354
+ pushToCache(this.cacheKey, collection);
39355
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
39356
+ };
39357
+ }
39358
+ subscribeRTE(createSubscriber) {
39359
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
39360
+ }
39361
+ }
39275
39362
 
39276
39363
  /* begin_public_function
39277
- id: post.get_by_ids
39364
+ id: comment.get_by_ids
39278
39365
  */
39279
39366
  /**
39280
39367
  * ```js
39281
- * import { getPostByIds } from '@amityco/ts-sdk'
39282
- * const { data: posts } = await getPostByIds(['foo', 'bar'])
39368
+ * import { CommentRepository } from '@amityco/ts-sdk'
39369
+ * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
39283
39370
  * ```
39284
39371
  *
39285
- * Fetches a collection of {@link Amity.Post} objects
39372
+ * Fetches a collection of {@link Amity.Comment} objects
39286
39373
  *
39287
- * @param postIds the IDs of the {@link Amity.Post} to fetch
39288
- * @returns the associated collection of {@link Amity.Post} objects
39374
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39375
+ * @returns the associated collection of {@link Amity.Comment} objects
39289
39376
  *
39290
- * @category Post API
39377
+ * @category Comment API
39291
39378
  * @async
39292
39379
  */
39293
- const getPostByIds = async (postIds) => {
39380
+ const getCommentByIds = async (commentIds) => {
39294
39381
  const client = getActiveClient();
39295
- client.log('post/getPostByIds', postIds);
39296
- const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
39297
- let payload;
39382
+ client.log('comment/getCommentByIds', commentIds);
39383
+ const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
39384
+ let data;
39298
39385
  try {
39299
39386
  // API-FIX: endpoint should not be /list, parameters should be querystring.
39300
- const response = await client.http.get(`/api/v3/posts/list`, {
39301
- params: { postIds: encodedPostIds },
39387
+ const response = await client.http.get(`/api/v3/comments/list`, {
39388
+ params: { commentIds: encodedCommentIds },
39302
39389
  });
39303
- payload = response.data;
39390
+ data = response.data;
39304
39391
  }
39305
39392
  catch (error) {
39306
- postIds.forEach(postId => {
39393
+ commentIds.forEach(commentId => {
39307
39394
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39308
- pushToTombstone('post', postId);
39395
+ pushToTombstone('comment', commentId);
39309
39396
  }
39310
39397
  });
39311
39398
  throw error;
39312
39399
  }
39313
- const data = prepareMembershipPayload(payload, 'communityUsers');
39314
39400
  const cachedAt = client.cache && Date.now();
39315
39401
  if (client.cache)
39316
39402
  ingestInCache(data, { cachedAt });
39317
39403
  return {
39318
- data: data.posts.map(LinkedObject.post),
39404
+ data: data.comments.map(comment => LinkedObject.comment(comment)),
39319
39405
  cachedAt,
39320
39406
  };
39321
39407
  };
39322
39408
  /* end_public_function */
39323
39409
  /**
39324
39410
  * ```js
39325
- * import { getPostByIds } from '@amityco/ts-sdk'
39326
- * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
39411
+ * import { getCommentByIds } from '@amityco/ts-sdk'
39412
+ * const comments = getCommentByIds.locally(['foo', 'bar'])
39327
39413
  * ```
39328
39414
  *
39329
- * Fetches a collection of {@link Amity.Post} objects from cache
39415
+ * Fetches a collection of {@link Amity.Comment} objects from cache
39330
39416
  *
39331
- * @param postIds the IDs of the {@link Amity.Post} to fetch
39332
- * @returns the associated collection of {@link Amity.Post} objects
39417
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39418
+ * @returns the associated collection of {@link Amity.Comment} objects
39333
39419
  *
39334
- * @category Post API
39420
+ * @category Comment API
39335
39421
  */
39336
- getPostByIds.locally = (postIds) => {
39422
+ getCommentByIds.locally = (commentIds) => {
39337
39423
  var _a;
39338
39424
  const client = getActiveClient();
39339
- client.log('post/getPostByIds.locally', postIds);
39425
+ client.log('comment/getCommentByIds.locally', commentIds);
39340
39426
  if (!client.cache)
39341
39427
  return;
39342
- const cached = postIds
39343
- .map(postId => pullFromCache(['post', 'get', postId]))
39428
+ const cached = commentIds
39429
+ .map(commentId => pullFromCache(['comment', 'get', commentId]))
39344
39430
  .filter(Boolean);
39345
- const posts = cached.map(({ data }) => data);
39431
+ const comments = cached.map(({ data }) => data);
39346
39432
  const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
39347
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
39433
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
39348
39434
  return;
39349
39435
  return {
39350
- data: posts.map(LinkedObject.post),
39436
+ data: comments.map(comment => LinkedObject.comment(comment)),
39351
39437
  cachedAt: oldest.cachedAt,
39352
39438
  };
39353
39439
  };
39354
39440
 
39355
39441
  /* begin_public_function
39356
- id: post.create.text_post, post.create.image_post, post.create.file_post, post.create.video_post, post.create.poll_post, post.create.livestream_post, post.create.custom_post
39442
+ id: comment.create
39357
39443
  */
39358
39444
  /**
39359
39445
  * ```js
39360
- * import { PostRepository } from '@amityco/ts-sdk'
39361
- * const created = await PostRepository.createPost({
39362
- * targetType: 'user',
39363
- * targetId: 'foobar',
39364
- * data: { text: 'hello world' }
39365
- * }))
39446
+ * import { CommentRepository } from '@amityco/ts-sdk'
39447
+ * const newComment = await CommentRepository.createComment(bundle)
39366
39448
  * ```
39367
39449
  *
39368
- * Creates an {@link Amity.Post}
39450
+ * Creates an {@link Amity.Comment}
39369
39451
  *
39370
- * @param bundle The data necessary to create a new {@link Amity.Post}
39371
- * @returns The newly created {@link Amity.Post}
39452
+ * @param bundle The data necessary to create a new {@link Amity.Comment}
39453
+ * @returns The newly created {@link Amity.Comment}
39372
39454
  *
39373
- * @category Post API
39455
+ * @category Comment API
39374
39456
  * @async
39375
39457
  */
39376
- const createPost = async (bundle) => {
39458
+ const createComment = async (bundle) => {
39459
+ var _a;
39377
39460
  const client = getActiveClient();
39378
- client.log('post/createPost', bundle);
39379
- if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
39380
- // eslint-disable-next-line no-param-reassign
39381
- delete bundle.dataType;
39382
- }
39383
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
39384
- fireEvent('post.created', payload);
39385
- const data = preparePostPayload(payload);
39461
+ client.log('comment/createComment', bundle);
39462
+ const { data } = await client.http.post('/api/v3/comments', bundle);
39463
+ const { comments } = data;
39464
+ // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
39465
+ if (comments.length === 0)
39466
+ throw new Error('Comment not created');
39386
39467
  const cachedAt = client.cache && Date.now();
39387
39468
  if (client.cache)
39388
39469
  ingestInCache(data, { cachedAt });
39389
- const { posts } = data;
39470
+ if (['post', 'content'].includes(bundle.referenceType)) {
39471
+ const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
39472
+ if (post) {
39473
+ post.commentsCount += 1;
39474
+ fireEvent('local.post.updated', {
39475
+ posts: [post],
39476
+ categories: [],
39477
+ comments: [],
39478
+ communities: [],
39479
+ communityUsers: data.communityUsers,
39480
+ feeds: [],
39481
+ files: data.files,
39482
+ postChildren: [],
39483
+ users: data.users,
39484
+ videoStreamings: [],
39485
+ });
39486
+ }
39487
+ }
39488
+ else if (bundle.referenceType === 'story') {
39489
+ const storyIndex = pullFromCache([
39490
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39491
+ bundle.referenceId,
39492
+ ]);
39493
+ if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
39494
+ const cacheStory = pullFromCache([
39495
+ "story" /* STORY_KEY_CACHE.STORY */,
39496
+ 'get',
39497
+ storyIndex.data,
39498
+ ]);
39499
+ if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
39500
+ fireEvent('story.updated', {
39501
+ stories: [
39502
+ Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
39503
+ ],
39504
+ categories: [],
39505
+ comments,
39506
+ communities: [],
39507
+ communityUsers: data.communityUsers,
39508
+ files: data.files,
39509
+ users: data.users,
39510
+ });
39511
+ }
39512
+ }
39513
+ }
39514
+ fireEvent('local.comment.created', data);
39390
39515
  return {
39391
- data: LinkedObject.post(posts[0]),
39516
+ data: LinkedObject.comment(comments[0]),
39392
39517
  cachedAt,
39393
39518
  };
39394
39519
  };
39395
39520
  /* end_public_function */
39396
39521
 
39397
39522
  /* begin_public_function
39398
- id: post.edit, post.edit.custom_post
39523
+ id: comment.update_comment
39399
39524
  */
39400
39525
  /**
39401
39526
  * ```js
39402
- * import { PostRepository } from '@amityco/ts-sdk'
39403
- * const updated = await PostRepository.editPost(postId, {
39527
+ * import { CommentRepository } from '@amityco/ts-sdk'
39528
+ * const updated = await CommentRepository.updateComment(commentId, {
39404
39529
  * data: { text: 'hello world' }
39405
39530
  * })
39406
39531
  * ```
39407
39532
  *
39408
- * Updates an {@link Amity.Post}
39533
+ * Updates an {@link Amity.Comment}
39409
39534
  *
39410
- * @param postId The ID of the {@link Amity.Post} to edit
39535
+ * @param commentId The ID of the {@link Amity.Comment} to edit
39411
39536
  * @param patch The patch data to apply
39412
- * @returns the updated {@link Amity.Post} object
39537
+ * @returns the updated {@link Amity.Comment} object
39413
39538
  *
39414
- * @category Post API
39539
+ * @category Comment API
39415
39540
  * @async
39416
39541
  */
39417
- const editPost = async (postId, patch) => {
39542
+ const updateComment = async (commentId, patch) => {
39418
39543
  const client = getActiveClient();
39419
- client.log('user/editPost', patch);
39420
- const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
39421
- const data = prepareMembershipPayload(payload, 'communityUsers');
39544
+ client.log('user/updateComment', patch);
39545
+ const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
39422
39546
  const cachedAt = client.cache && Date.now();
39423
39547
  if (client.cache)
39424
39548
  ingestInCache(data, { cachedAt });
39425
- fireEvent('local.post.updated', data);
39426
- const { posts } = data;
39549
+ fireEvent('comment.updated', data);
39550
+ const { comments } = data;
39427
39551
  return {
39428
- data: LinkedObject.post(posts.find(post => post.postId === postId)),
39552
+ data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
39429
39553
  cachedAt,
39430
39554
  };
39431
39555
  };
39432
39556
  /* end_public_function */
39433
39557
 
39558
+ // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
39559
+ const applyMissingField = (rawData, isCreated = false) => {
39560
+ const { storyId, referenceId } = rawData;
39561
+ if (!isCreated) {
39562
+ if (referenceId)
39563
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
39564
+ }
39565
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
39566
+ };
39567
+ const convertRawStoryToInternal = (data, isCreated = false) => {
39568
+ const { stories } = data;
39569
+ const storiesData = stories.map(story => applyMissingField(story, isCreated));
39570
+ return Object.assign(Object.assign({}, data), { stories: storiesData });
39571
+ };
39572
+
39573
+ const getStoryByStoryId$1 = async (storyId) => {
39574
+ const client = getActiveClient();
39575
+ client.log('story/getStoryByStoryId', storyId);
39576
+ // Get story referenceId from cache
39577
+ const cacheReferenceId = pullFromCache([
39578
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39579
+ storyId,
39580
+ ]);
39581
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
39582
+ const { data: referenceId } = cacheReferenceId;
39583
+ isInTombstone('story', referenceId);
39584
+ }
39585
+ let data;
39586
+ try {
39587
+ const response = await client.http.get(`/api/v4/stories/${storyId}`);
39588
+ data = convertRawStoryToInternal(response.data);
39589
+ }
39590
+ catch (error) {
39591
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39592
+ pushToTombstone('story', storyId);
39593
+ }
39594
+ throw error;
39595
+ }
39596
+ const cachedAt = client.cache && Date.now();
39597
+ if (client.cache) {
39598
+ ingestInCache(data, { cachedAt });
39599
+ }
39600
+ return {
39601
+ data: data.stories[0],
39602
+ cachedAt,
39603
+ };
39604
+ };
39605
+ getStoryByStoryId$1.locally = (storyId) => {
39606
+ const client = getActiveClient();
39607
+ client.log('story/getStorybyStoryId', storyId);
39608
+ // Get story referenceId from cache
39609
+ const cacheReferenceId = pullFromCache([
39610
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39611
+ storyId,
39612
+ ]);
39613
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
39614
+ const { data: referenceId } = cacheReferenceId;
39615
+ isInTombstone('story', referenceId);
39616
+ }
39617
+ const cachedAt = client.cache && Date.now();
39618
+ const storyCache = pullFromCache(['story', 'get', storyId]);
39619
+ if (!storyCache)
39620
+ return;
39621
+ return {
39622
+ data: storyCache.data,
39623
+ cachedAt,
39624
+ };
39625
+ };
39626
+
39627
+ /* begin_public_function
39628
+ id: comment.soft_delete, comment.hard_delete
39629
+ */
39434
39630
  /**
39435
39631
  * ```js
39436
- * import { deletePost } from '@amityco/ts-sdk'
39437
- * const success = await deletePost('foobar')
39632
+ * import { CommentRepository } from '@amityco/ts-sdk'
39633
+ * const success = await CommentRepository.deleteComment('foobar')
39438
39634
  * ```
39439
39635
  *
39440
- * Deletes a {@link Amity.Post}
39636
+ * Deletes a {@link Amity.Comment}
39441
39637
  *
39442
- * @param postId The {@link Amity.Post} ID to delete
39443
- * @return A success boolean if the {@link Amity.Post} was deleted
39638
+ * @param commentId The {@link Amity.Comment} ID to delete
39639
+ * @return A success boolean if the {@link Amity.Comment} was deleted
39444
39640
  *
39445
- * @private
39641
+ * @category Comment API
39446
39642
  * @async
39447
39643
  */
39448
- const deletePost = async (postId, permanent = false) => {
39644
+ const deleteComment = async (commentId, permanent = false) => {
39449
39645
  var _a;
39450
39646
  const client = getActiveClient();
39451
- const post = await getPost$2(postId);
39452
- await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
39647
+ const comment = await getComment$2(commentId);
39648
+ // API-FIX: This endpoint has not been implemented yet.
39649
+ await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
39453
39650
  params: {
39454
- postId,
39651
+ commentId,
39455
39652
  permanent,
39456
39653
  },
39457
39654
  });
39458
- // there is currently a limitation which doesn't allow us to fire event to tell that community
39459
- // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
39460
- // and so we cannot refetch the community or advertise on events. hopefully this should be solved
39461
- // later when realtime events covers that for us.
39462
- if (post.data.targetType === 'community') {
39463
- const community = await getCommunity$1(post.data.targetId);
39464
- const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
39465
- const communityUsers = communityUsersCache
39466
- .filter(({ key }) => {
39467
- // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
39468
- if (key[0] !== 'communityUsers')
39469
- return false;
39470
- if (key[1] !== 'get')
39471
- return false;
39472
- if (typeof key[2] === 'string')
39473
- return key[2].includes(community.data.communityId);
39474
- return false;
39475
- })
39476
- .map(({ data }) => data);
39477
- fireEvent('community.updated', {
39478
- communities: [community.data],
39655
+ // to support hard deletion
39656
+ const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
39657
+ if (permanent) {
39658
+ scheduleTask(() => pushToTombstone('comment', commentId));
39659
+ }
39660
+ else {
39661
+ upsertInCache(['comment', 'get', commentId], { isDeleted: true });
39662
+ }
39663
+ if (comment.data.referenceType === 'story') {
39664
+ const story = await getStoryByStoryId$1(comment.data.referenceId);
39665
+ fireEvent('local.story.updated', {
39666
+ stories: [story.data],
39479
39667
  categories: [],
39480
- communityUsers,
39481
- feeds: [],
39668
+ comments: [],
39669
+ communities: [],
39670
+ communityUsers: [],
39482
39671
  files: [],
39483
39672
  users: [],
39484
39673
  });
39485
39674
  }
39486
- // to support hard deletion
39487
- const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
39488
- if (permanent) {
39489
- setTimeout(() => {
39490
- pushToTombstone('post', postId);
39491
- }, 0);
39492
- }
39493
39675
  else {
39494
- upsertInCache(['post', 'get', postId], { isDeleted: true });
39676
+ const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
39677
+ if (post) {
39678
+ let removeCount;
39679
+ if (!deleted.parentId) {
39680
+ // NOTE: delete the parent comment will remove all children comments
39681
+ removeCount = deleted.childrenNumber + 1;
39682
+ }
39683
+ else
39684
+ removeCount = 1;
39685
+ post.commentsCount -= removeCount;
39686
+ fireEvent('local.post.updated', {
39687
+ posts: [post],
39688
+ categories: [],
39689
+ comments: [],
39690
+ communities: [],
39691
+ communityUsers: [],
39692
+ feeds: [],
39693
+ files: [],
39694
+ postChildren: [],
39695
+ users: [],
39696
+ videoStreamings: [],
39697
+ });
39698
+ }
39495
39699
  }
39496
- fireEvent('local.post.deleted', {
39497
- posts: [deleted],
39498
- categories: [],
39499
- comments: [],
39500
- communities: [],
39501
- communityUsers: [],
39502
- feeds: [],
39503
- files: [],
39504
- postChildren: [],
39700
+ fireEvent('local.comment.deleted', {
39701
+ comments: [deleted],
39702
+ commentChildren: [],
39703
+ files: [],
39505
39704
  users: [],
39506
- videoStreamings: [],
39705
+ communityUsers: [],
39507
39706
  });
39508
- return LinkedObject.post(deleted);
39509
- };
39510
-
39511
- /* begin_public_function
39512
- id: post.soft_delete
39513
- */
39514
- /**
39515
- * ```js
39516
- * import { PostRepository } from '@amityco/ts-sdk'
39517
- * const success = await PostRepository.softDeletePost('foobar')
39518
- * ```
39519
- *
39520
- * Soft deletes a {@link Amity.Post}
39521
- *
39522
- * @param postId The {@link Amity.Post} ID to soft delete
39523
- * @return A success boolean if the {@link Amity.Post} was deleted
39524
- *
39525
- * @category Post API
39526
- * @async
39527
- */
39528
- const softDeletePost = async (postId) => {
39529
- const client = getActiveClient();
39530
- client.log('post/softDeletePost', postId);
39531
- const softDeleted = await deletePost(postId, false);
39532
- return LinkedObject.post(softDeleted);
39533
- };
39534
- /* end_public_function */
39535
-
39536
- /* begin_public_function
39537
- id: post.hard_delete
39538
- */
39539
- /**
39540
- * ```js
39541
- * import { hardDeletePost } from '@amityco/ts-sdk'
39542
- * const success = await hardDeletePost('foobar')
39543
- * ```
39544
- *
39545
- * Hard deletes a {@link Amity.Post}
39546
- *
39547
- * @param postId The {@link Amity.Post} ID to be hard delete
39548
- * @return A success boolean if the {@link Amity.Post} was deleted
39549
- *
39550
- * @category Post API
39551
- * @async
39552
- */
39553
- const hardDeletePost = async (postId) => {
39554
- const client = getActiveClient();
39555
- client.log('post/hardDeletePost', postId);
39556
- const hardDeleted = await deletePost(postId, true);
39557
- return LinkedObject.post(hardDeleted);
39707
+ return deleted;
39558
39708
  };
39559
39709
  /* end_public_function */
39560
39710
 
39561
39711
  /* begin_public_function
39562
- id: post.approve
39712
+ id: comment.soft_delete
39563
39713
  */
39564
39714
  /**
39565
39715
  * ```js
39566
- * import { approvePost } from '@amityco/ts-sdk'
39567
- *
39568
- * const { data: post } = await approvePost('postId')
39716
+ * import { CommentRepository } from '@amityco/ts-sdk'
39717
+ * const success = await CommentRepository.softDeleteComment('foobar')
39569
39718
  * ```
39570
39719
  *
39571
- * Approves a {@link Amity.Post}
39720
+ * Deletes a {@link Amity.Comment}
39572
39721
  *
39573
- * @param postId The {@link Amity.Post} ID to be approved
39574
- * @return A {@link Amity.Post} that was approved
39722
+ * @param commentId The {@link Amity.Comment} ID to delete
39723
+ * @return A success boolean if the {@link Amity.Comment} was deleted
39575
39724
  *
39576
- * @category Post API
39725
+ * @category Comment API
39577
39726
  * @async
39578
39727
  */
39579
- const approvePost = async (postId) => {
39728
+ const softDeleteComment = async (commentId) => {
39580
39729
  const client = getActiveClient();
39581
- client.log('post/approvePost', postId);
39582
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
39583
- fireEvent('post.approved', payload);
39584
- // fire virtual event for community update
39585
- if (payload.posts[0].targetType === 'community') {
39586
- fireEvent('community.updated', payload);
39587
- }
39588
- const data = prepareMembershipPayload(payload, 'communityUsers');
39589
- const cachedAt = client.cache && Date.now();
39590
- if (client.cache)
39591
- ingestInCache(data, { cachedAt });
39592
- return {
39593
- data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
39594
- cachedAt,
39595
- };
39730
+ client.log('comment/softDeleteComment', commentId);
39731
+ const softDeleted = deleteComment(commentId);
39732
+ return softDeleted;
39596
39733
  };
39597
39734
  /* end_public_function */
39598
39735
 
39599
39736
  /* begin_public_function
39600
- id: post.decline
39737
+ id: comment.hard_delete
39601
39738
  */
39602
39739
  /**
39603
39740
  * ```js
39604
- * import { declinePost } from '@amityco/ts-sdk'
39605
- *
39606
- * const {data: post} = await declinePost('postId')
39741
+ * import { CommentRepository } from '@amityco/ts-sdk'
39742
+ * const success = await CommentRepository.hardDeleteComment('foobar')
39607
39743
  * ```
39608
39744
  *
39609
- * Declines a {@link Amity.Post}
39745
+ * Deletes a {@link Amity.Comment}
39610
39746
  *
39611
- * @param postId The {@link Amity.Post} ID to be declined
39612
- * @return A {@link Amity.Post} that was declined
39747
+ * @param commentId The {@link Amity.Comment} ID to delete
39748
+ * @return A success boolean if the {@link Amity.Comment} was deleted
39613
39749
  *
39614
- * @category Post API
39750
+ * @category Comment API
39615
39751
  * @async
39616
39752
  */
39617
- const declinePost = async (postId) => {
39753
+ const hardDeleteComment = async (commentId) => {
39618
39754
  const client = getActiveClient();
39619
- client.log('post/declinePost', postId);
39620
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
39621
- // fire virtual event
39622
- if (payload.posts[0].targetType === 'community') {
39623
- fireEvent('community.updated', payload);
39624
- }
39625
- fireEvent('post.declined', payload);
39626
- const data = prepareMembershipPayload(payload, 'communityUsers');
39627
- const cachedAt = client.cache && Date.now();
39628
- if (client.cache)
39629
- ingestInCache(data, { cachedAt });
39630
- return {
39631
- data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
39632
- cachedAt,
39633
- };
39755
+ client.log('comment/hardDeleteComment', commentId);
39756
+ const hardDeleted = deleteComment(commentId, true);
39757
+ return hardDeleted;
39634
39758
  };
39635
39759
  /* end_public_function */
39636
39760
 
39637
39761
  /* begin_public_function
39638
- id: post.flag
39762
+ id: comment.flag
39639
39763
  */
39640
39764
  /**
39641
39765
  * ```js
39642
- * import { PostRepository } from '@amityco/ts-sdk'
39643
- * const flagged = await PostRepository.flagPost(postId, reason)
39766
+ * import { CommentRepository } from '@amityco/ts-sdk'
39767
+ * const flagged = await CommentRepository.flagComment(commentId, reason)
39644
39768
  * ```
39645
39769
  *
39646
- * @param postId of the post to flag
39647
- * @param reason the reason to flag the post
39648
- * @returns a boolean
39770
+ * @param commentId The ID of the comment to flag
39771
+ * @param reason the reason to flag the comment
39772
+ * @returns the created report result
39649
39773
  *
39650
- * @category Post API
39774
+ * @category Comment API
39651
39775
  * @async
39652
39776
  * */
39653
- const flagPost = async (postId, reason) => {
39777
+ const flagComment = async (commentId, reason) => {
39654
39778
  const client = getActiveClient();
39655
- client.log('post/flagPost', postId);
39779
+ client.log('comment/flagComment', commentId);
39656
39780
  const isPredefinedReason = reason &&
39657
39781
  Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
39658
39782
  const body = {
39659
39783
  reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
39660
39784
  detail: reason && !isPredefinedReason ? reason : '',
39661
39785
  };
39662
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
39786
+ const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
39663
39787
  if (client.cache) {
39664
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
39788
+ ingestInCache(payload);
39665
39789
  }
39666
- fireEvent('post.flagged', payload);
39790
+ fireEvent('comment.flagged', payload);
39667
39791
  return !!payload;
39668
39792
  };
39669
39793
  /* end_public_function */
39670
39794
 
39671
39795
  /* begin_public_function
39672
- id: post.unflag
39796
+ id: comment.unflag
39673
39797
  */
39674
39798
  /**
39675
39799
  * ```js
39676
- * import { PostRepository } from '@amityco/ts-sdk'
39677
- * const unflagged = await PostRepository.unflagPost(postId)
39800
+ * import { CommentRepository } from '@amityco/ts-sdk'
39801
+ * const unflagged = await CommentRepository.unflagComment('commentId')
39678
39802
  * ```
39679
39803
  *
39680
- * @param postId of the post to unflag
39681
- * @returns the unflag post result
39804
+ * @param commentId The ID of comment to unflag
39805
+ * @returns the unflagged result
39682
39806
  *
39683
- * @category Post API
39807
+ * @category Comment API
39684
39808
  * @async
39685
39809
  * */
39686
- const unflagPost = async (postId) => {
39810
+ const unflagComment = async (commentId) => {
39687
39811
  const client = getActiveClient();
39688
- client.log('post/unflagPost', postId);
39689
- const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
39812
+ client.log('comment/unflagComment', commentId);
39813
+ const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
39690
39814
  if (client.cache) {
39691
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
39815
+ ingestInCache(payload);
39692
39816
  }
39693
- fireEvent('post.unflagged', payload);
39817
+ fireEvent('comment.unflagged', payload);
39694
39818
  return !!payload;
39695
39819
  };
39696
39820
  /* end_public_function */
39697
39821
 
39698
39822
  /* begin_public_function
39699
- id: post.check_flag_by_me
39823
+ id: comment.check_flag_by_me
39700
39824
  */
39701
39825
  /**
39702
39826
  * ```js
39703
- * import { PostRepository } from '@amityco/ts-sdk'
39704
- * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
39827
+ * import { CommentRepository } from '@amityco/ts-sdk'
39828
+ * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
39705
39829
  * ```
39706
39830
  *
39707
- * @param postId of the post to check if flagged by current user
39708
- * @returns `true` if the post is flagged by me, `false` if doesn't.
39831
+ * @param commentId The ID of the comment to check if flagged by current user
39832
+ * @returns `true` if the comment is flagged by me, `false` if doesn't.
39709
39833
  *
39710
- * @category Post API
39834
+ * @category Comment API
39711
39835
  * @async
39712
39836
  * */
39713
- const isPostFlaggedByMe = async (postId) => {
39837
+ const isCommentFlaggedByMe = async (commentId) => {
39714
39838
  const client = getActiveClient();
39715
- client.log('post/isPostFlaggedByMe', postId);
39716
- const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
39839
+ client.log('comment/isCommentFlaggedByMe', commentId);
39840
+ const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
39717
39841
  return result;
39718
39842
  };
39719
39843
  /* end_public_function */
39720
39844
 
39721
- /* begin_public_function
39722
- id: post.create.clip_post
39723
- */
39724
- /**
39725
- * ```js
39726
- * import { PostRepository } from '@amityco/ts-sdk'
39727
- * const created = await PostRepository.createClipPost({
39728
- * targetType: 'user',
39729
- * targetId: 'foobar',
39730
- * dataType: 'clip',
39731
- * data: { text: 'hello world' },
39732
- * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
39733
- * }))
39734
- * ```
39735
- *
39736
- * Creates an {@link Amity.Post}
39737
- *
39738
- * @param bundle The data necessary to create a new {@link Amity.Post}
39739
- * @returns The newly created {@link Amity.Post}
39740
- *
39741
- * @category Post API
39742
- * @async
39743
- */
39744
- const createClipPost = async (bundle) => {
39745
- const client = getActiveClient();
39746
- client.log('post/createPost', bundle);
39747
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
39748
- fireEvent('post.created', payload);
39749
- const data = prepareMembershipPayload(payload, 'communityUsers');
39750
- const cachedAt = client.cache && Date.now();
39751
- if (client.cache)
39752
- ingestInCache(data, { cachedAt });
39753
- const { posts } = data;
39754
- return {
39755
- data: LinkedObject.post(posts[0]),
39756
- cachedAt,
39757
- };
39758
- };
39759
- /* end_public_function */
39760
-
39761
- /* begin_public_function
39762
- id: comment.get_by_ids
39763
- */
39764
- /**
39765
- * ```js
39766
- * import { CommentRepository } from '@amityco/ts-sdk'
39767
- * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
39768
- * ```
39769
- *
39770
- * Fetches a collection of {@link Amity.Comment} objects
39771
- *
39772
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39773
- * @returns the associated collection of {@link Amity.Comment} objects
39774
- *
39775
- * @category Comment API
39776
- * @async
39777
- */
39778
- const getCommentByIds = async (commentIds) => {
39845
+ const getComment$1 = async (commentId) => {
39779
39846
  const client = getActiveClient();
39780
- client.log('comment/getCommentByIds', commentIds);
39781
- const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
39847
+ client.log('comment/getComment', commentId);
39848
+ isInTombstone('comment', commentId);
39782
39849
  let data;
39783
39850
  try {
39784
39851
  // API-FIX: endpoint should not be /list, parameters should be querystring.
39785
- const response = await client.http.get(`/api/v3/comments/list`, {
39786
- params: { commentIds: encodedCommentIds },
39787
- });
39852
+ const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
39788
39853
  data = response.data;
39789
39854
  }
39790
39855
  catch (error) {
39791
- commentIds.forEach(commentId => {
39792
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39793
- pushToTombstone('comment', commentId);
39794
- }
39795
- });
39856
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39857
+ pushToTombstone('comment', commentId);
39858
+ }
39796
39859
  throw error;
39797
39860
  }
39798
39861
  const cachedAt = client.cache && Date.now();
39799
39862
  if (client.cache)
39800
39863
  ingestInCache(data, { cachedAt });
39864
+ const { comments } = data;
39801
39865
  return {
39802
- data: data.comments.map(comment => LinkedObject.comment(comment)),
39866
+ data: comments.find(comment => comment.commentId === commentId),
39803
39867
  cachedAt,
39804
39868
  };
39805
39869
  };
39806
- /* end_public_function */
39807
- /**
39808
- * ```js
39809
- * import { getCommentByIds } from '@amityco/ts-sdk'
39810
- * const comments = getCommentByIds.locally(['foo', 'bar'])
39811
- * ```
39812
- *
39813
- * Fetches a collection of {@link Amity.Comment} objects from cache
39814
- *
39815
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39816
- * @returns the associated collection of {@link Amity.Comment} objects
39817
- *
39818
- * @category Comment API
39819
- */
39820
- getCommentByIds.locally = (commentIds) => {
39821
- var _a;
39870
+ getComment$1.locally = (commentId) => {
39822
39871
  const client = getActiveClient();
39823
- client.log('comment/getCommentByIds.locally', commentIds);
39872
+ client.log('comment/getComment.locally', commentId);
39824
39873
  if (!client.cache)
39825
39874
  return;
39826
- const cached = commentIds
39827
- .map(commentId => pullFromCache(['comment', 'get', commentId]))
39828
- .filter(Boolean);
39829
- const comments = cached.map(({ data }) => data);
39830
- const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
39831
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
39875
+ const cached = pullFromCache(['comment', 'get', commentId]);
39876
+ if (!cached)
39832
39877
  return;
39833
39878
  return {
39834
- data: comments.map(comment => LinkedObject.comment(comment)),
39835
- cachedAt: oldest.cachedAt,
39879
+ data: cached.data,
39880
+ cachedAt: cached.cachedAt,
39836
39881
  };
39837
39882
  };
39838
39883
 
39839
- /* begin_public_function
39840
- id: comment.create
39841
- */
39842
39884
  /**
39843
39885
  * ```js
39844
- * import { CommentRepository } from '@amityco/ts-sdk'
39845
- * const newComment = await CommentRepository.createComment(bundle)
39886
+ * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
39887
+ * const dispose = onCommentDeleteLocal(comment => {
39888
+ * // ...
39889
+ * })
39846
39890
  * ```
39847
39891
  *
39848
- * Creates an {@link Amity.Comment}
39892
+ * Fired when a {@link Amity.InternalComment} has been deleted
39849
39893
  *
39850
- * @param bundle The data necessary to create a new {@link Amity.Comment}
39851
- * @returns The newly created {@link Amity.Comment}
39894
+ * @param callback The function to call when the event was fired
39895
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
39852
39896
  *
39853
- * @category Comment API
39854
- * @async
39897
+ * @category Comment Events
39855
39898
  */
39856
- const createComment = async (bundle) => {
39857
- var _a;
39899
+ const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
39900
+
39901
+ /**
39902
+ * ```js
39903
+ * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
39904
+ * const dispose = onLocalCommentReactionAdded(comment => {
39905
+ * // ...
39906
+ * })
39907
+ * ```
39908
+ *
39909
+ * Fired when a {@link Amity.InternalComment} has been reacted
39910
+ *
39911
+ * @param callback The function to call when the event was fired
39912
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
39913
+ *
39914
+ * @category Comment Events
39915
+ */
39916
+ const onLocalCommentReactionAdded = (callback) => {
39858
39917
  const client = getActiveClient();
39859
- client.log('comment/createComment', bundle);
39860
- const { data } = await client.http.post('/api/v3/comments', bundle);
39861
- const { comments } = data;
39862
- // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
39863
- if (comments.length === 0)
39864
- throw new Error('Comment not created');
39865
- const cachedAt = client.cache && Date.now();
39866
- if (client.cache)
39867
- ingestInCache(data, { cachedAt });
39868
- if (['post', 'content'].includes(bundle.referenceType)) {
39869
- const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
39870
- if (post) {
39871
- post.commentsCount += 1;
39872
- fireEvent('local.post.updated', {
39873
- posts: [post],
39874
- categories: [],
39875
- comments: [],
39876
- communities: [],
39877
- communityUsers: data.communityUsers,
39878
- feeds: [],
39879
- files: data.files,
39880
- postChildren: [],
39881
- users: data.users,
39882
- videoStreamings: [],
39883
- });
39918
+ const filter = ({ comment }) => {
39919
+ if (!client.cache) {
39920
+ callback(comment);
39884
39921
  }
39885
- }
39886
- else if (bundle.referenceType === 'story') {
39887
- const storyIndex = pullFromCache([
39888
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39889
- bundle.referenceId,
39890
- ]);
39891
- if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
39892
- const cacheStory = pullFromCache([
39893
- "story" /* STORY_KEY_CACHE.STORY */,
39894
- 'get',
39895
- storyIndex.data,
39896
- ]);
39897
- if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
39898
- fireEvent('story.updated', {
39899
- stories: [
39900
- Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
39901
- ],
39902
- categories: [],
39903
- comments,
39904
- communities: [],
39905
- communityUsers: data.communityUsers,
39906
- files: data.files,
39907
- users: data.users,
39908
- });
39909
- }
39922
+ else {
39923
+ upsertInCache(['comment', 'get', comment.commentId], comment);
39924
+ callback(commentLinkedObject(comment));
39910
39925
  }
39911
- }
39912
- fireEvent('local.comment.created', data);
39913
- return {
39914
- data: LinkedObject.comment(comments[0]),
39915
- cachedAt,
39916
39926
  };
39927
+ return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
39917
39928
  };
39918
- /* end_public_function */
39919
39929
 
39920
- /* begin_public_function
39921
- id: comment.update_comment
39922
- */
39923
39930
  /**
39924
39931
  * ```js
39925
- * import { CommentRepository } from '@amityco/ts-sdk'
39926
- * const updated = await CommentRepository.updateComment(commentId, {
39927
- * data: { text: 'hello world' }
39932
+ * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
39933
+ * const dispose = onLocalCommentReactionRemoved(comment => {
39934
+ * // ...
39928
39935
  * })
39929
39936
  * ```
39930
39937
  *
39931
- * Updates an {@link Amity.Comment}
39938
+ * Fired when a {@link Amity.InternalComment} has been reacted
39932
39939
  *
39933
- * @param commentId The ID of the {@link Amity.Comment} to edit
39934
- * @param patch The patch data to apply
39935
- * @returns the updated {@link Amity.Comment} object
39940
+ * @param callback The function to call when the event was fired
39941
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
39936
39942
  *
39937
- * @category Comment API
39938
- * @async
39943
+ * @category Comment Events
39939
39944
  */
39940
- const updateComment = async (commentId, patch) => {
39941
- const client = getActiveClient();
39942
- client.log('user/updateComment', patch);
39943
- const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
39944
- const cachedAt = client.cache && Date.now();
39945
- if (client.cache)
39946
- ingestInCache(data, { cachedAt });
39947
- fireEvent('comment.updated', data);
39948
- const { comments } = data;
39949
- return {
39950
- data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
39951
- cachedAt,
39952
- };
39953
- };
39954
- /* end_public_function */
39955
-
39956
- // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
39957
- const applyMissingField = (rawData, isCreated = false) => {
39958
- const { storyId, referenceId } = rawData;
39959
- if (!isCreated) {
39960
- if (referenceId)
39961
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
39962
- }
39963
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
39964
- };
39965
- const convertRawStoryToInternal = (data, isCreated = false) => {
39966
- const { stories } = data;
39967
- const storiesData = stories.map(story => applyMissingField(story, isCreated));
39968
- return Object.assign(Object.assign({}, data), { stories: storiesData });
39969
- };
39970
-
39971
- const getStoryByStoryId$1 = async (storyId) => {
39945
+ const onLocalCommentReactionRemoved = (callback) => {
39972
39946
  const client = getActiveClient();
39973
- client.log('story/getStoryByStoryId', storyId);
39974
- // Get story referenceId from cache
39975
- const cacheReferenceId = pullFromCache([
39976
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39977
- storyId,
39978
- ]);
39979
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
39980
- const { data: referenceId } = cacheReferenceId;
39981
- isInTombstone('story', referenceId);
39982
- }
39983
- let data;
39984
- try {
39985
- const response = await client.http.get(`/api/v4/stories/${storyId}`);
39986
- data = convertRawStoryToInternal(response.data);
39987
- }
39988
- catch (error) {
39989
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39990
- pushToTombstone('story', storyId);
39947
+ const filter = ({ comment }) => {
39948
+ if (!client.cache) {
39949
+ callback(comment);
39950
+ }
39951
+ else {
39952
+ upsertInCache(['comment', 'get', comment.commentId], comment);
39953
+ callback(commentLinkedObject(comment));
39991
39954
  }
39992
- throw error;
39993
- }
39994
- const cachedAt = client.cache && Date.now();
39995
- if (client.cache) {
39996
- ingestInCache(data, { cachedAt });
39997
- }
39998
- return {
39999
- data: data.stories[0],
40000
- cachedAt,
40001
- };
40002
- };
40003
- getStoryByStoryId$1.locally = (storyId) => {
40004
- const client = getActiveClient();
40005
- client.log('story/getStorybyStoryId', storyId);
40006
- // Get story referenceId from cache
40007
- const cacheReferenceId = pullFromCache([
40008
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
40009
- storyId,
40010
- ]);
40011
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
40012
- const { data: referenceId } = cacheReferenceId;
40013
- isInTombstone('story', referenceId);
40014
- }
40015
- const cachedAt = client.cache && Date.now();
40016
- const storyCache = pullFromCache(['story', 'get', storyId]);
40017
- if (!storyCache)
40018
- return;
40019
- return {
40020
- data: storyCache.data,
40021
- cachedAt,
40022
39955
  };
39956
+ return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
40023
39957
  };
40024
39958
 
40025
39959
  /* begin_public_function
40026
- id: comment.soft_delete, comment.hard_delete
39960
+ id: comment.get
40027
39961
  */
40028
39962
  /**
40029
39963
  * ```js
40030
- * import { CommentRepository } from '@amityco/ts-sdk'
40031
- * const success = await CommentRepository.deleteComment('foobar')
39964
+ * import { CommentRepository } from '@amityco/ts-sdk';
39965
+ *
39966
+ * let comment;
39967
+ *
39968
+ * const unsub = CommentRepository.getComment(commentId, response => {
39969
+ * comment = response.data;
39970
+ * });
40032
39971
  * ```
40033
39972
  *
40034
- * Deletes a {@link Amity.Comment}
39973
+ * Observe all mutation on a given {@link Amity.Comment}
40035
39974
  *
40036
- * @param commentId The {@link Amity.Comment} ID to delete
40037
- * @return A success boolean if the {@link Amity.Comment} was deleted
39975
+ * @param commentId the ID of the comment to observe
39976
+ * @param callback the function to call when new data are available
39977
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
40038
39978
  *
40039
- * @category Comment API
40040
- * @async
39979
+ * @category Comment Live Object
40041
39980
  */
40042
- const deleteComment = async (commentId, permanent = false) => {
40043
- var _a;
40044
- const client = getActiveClient();
40045
- const comment = await getComment$2(commentId);
40046
- // API-FIX: This endpoint has not been implemented yet.
40047
- await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
40048
- params: {
40049
- commentId,
40050
- permanent,
40051
- },
40052
- });
40053
- // to support hard deletion
40054
- const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
40055
- if (comment.data.referenceType === 'story') {
40056
- const story = await getStoryByStoryId$1(comment.data.referenceId);
40057
- fireEvent('local.story.updated', {
40058
- stories: [story.data],
40059
- categories: [],
40060
- comments: [],
40061
- communities: [],
40062
- communityUsers: [],
40063
- files: [],
40064
- users: [],
39981
+ const getComment = (commentId, callback) => {
39982
+ return liveObject(commentId, callback, 'commentId', getComment$1, [
39983
+ onCommentDeleteLocal,
39984
+ onCommentDeleted,
39985
+ onCommentFlagged,
39986
+ onCommentReactionAdded,
39987
+ onCommentReactionRemoved,
39988
+ onCommentUnflagged,
39989
+ onCommentUpdated,
39990
+ onLocalCommentReactionAdded,
39991
+ onLocalCommentReactionRemoved,
39992
+ ]);
39993
+ };
39994
+ /* end_public_function */
39995
+
39996
+ class CommentPaginationController extends PaginationController {
39997
+ async getRequest(queryParams, token) {
39998
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
39999
+ const baseOptions = {
40000
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
40001
+ };
40002
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
40003
+ const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
40004
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
40065
40005
  });
40006
+ return queryResponse;
40066
40007
  }
40067
- else {
40068
- const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
40069
- if (post) {
40070
- let removeCount;
40071
- if (!deleted.parentId) {
40072
- // NOTE: delete the parent comment will remove all children comments
40073
- removeCount = deleted.childrenNumber + 1;
40074
- }
40075
- else
40076
- removeCount = 1;
40077
- post.commentsCount -= removeCount;
40078
- fireEvent('local.post.updated', {
40079
- posts: [post],
40080
- categories: [],
40081
- comments: [],
40082
- communities: [],
40083
- communityUsers: [],
40084
- feeds: [],
40085
- files: [],
40086
- postChildren: [],
40087
- users: [],
40088
- videoStreamings: [],
40008
+ }
40009
+
40010
+ var EnumCommentActions;
40011
+ (function (EnumCommentActions) {
40012
+ EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
40013
+ EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
40014
+ EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
40015
+ EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
40016
+ EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
40017
+ EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
40018
+ EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
40019
+ })(EnumCommentActions || (EnumCommentActions = {}));
40020
+
40021
+ class CommentQueryStreamController extends QueryStreamController {
40022
+ constructor(query, cacheKey, notifyChange, preparePayload) {
40023
+ super(query, cacheKey);
40024
+ this.notifyChange = notifyChange;
40025
+ this.preparePayload = preparePayload;
40026
+ }
40027
+ async saveToMainDB(response) {
40028
+ const processedPayload = await this.preparePayload(response);
40029
+ const client = getActiveClient();
40030
+ const cachedAt = client.cache && Date.now();
40031
+ if (client.cache) {
40032
+ ingestInCache(processedPayload, { cachedAt });
40033
+ }
40034
+ }
40035
+ appendToQueryStream(response, direction, refresh = false) {
40036
+ var _a, _b;
40037
+ if (refresh) {
40038
+ pushToCache(this.cacheKey, {
40039
+ data: response.comments.map(getResolver('comment')),
40089
40040
  });
40090
40041
  }
40042
+ else {
40043
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40044
+ const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
40045
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
40046
+ }
40091
40047
  }
40092
- fireEvent('local.comment.deleted', {
40093
- comments: [deleted],
40094
- commentChildren: [],
40095
- files: [],
40096
- users: [],
40097
- communityUsers: [],
40098
- });
40099
- if (permanent) {
40100
- scheduleTask(() => pushToTombstone('comment', commentId));
40048
+ reactor(action) {
40049
+ return (comment) => {
40050
+ var _a;
40051
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40052
+ if (this.query.referenceId !== comment.referenceId ||
40053
+ this.query.referenceType !== comment.referenceType ||
40054
+ !collection) {
40055
+ return;
40056
+ }
40057
+ if (this.query.parentId && this.query.parentId !== comment.parentId) {
40058
+ return;
40059
+ }
40060
+ if (!this.query.parentId && comment.parentId) {
40061
+ return;
40062
+ }
40063
+ if (action === EnumCommentActions.OnCommentCreated) {
40064
+ collection.data = [...new Set([comment.commentId, ...collection.data])];
40065
+ }
40066
+ pushToCache(this.cacheKey, collection);
40067
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
40068
+ };
40101
40069
  }
40102
- else {
40103
- upsertInCache(['comment', 'get', commentId], { isDeleted: true });
40070
+ subscribeRTE(createSubscriber) {
40071
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
40104
40072
  }
40105
- return deleted;
40106
- };
40107
- /* end_public_function */
40108
-
40109
- /* begin_public_function
40110
- id: comment.soft_delete
40111
- */
40112
- /**
40113
- * ```js
40114
- * import { CommentRepository } from '@amityco/ts-sdk'
40115
- * const success = await CommentRepository.softDeleteComment('foobar')
40116
- * ```
40117
- *
40118
- * Deletes a {@link Amity.Comment}
40119
- *
40120
- * @param commentId The {@link Amity.Comment} ID to delete
40121
- * @return A success boolean if the {@link Amity.Comment} was deleted
40122
- *
40123
- * @category Comment API
40124
- * @async
40125
- */
40126
- const softDeleteComment = async (commentId) => {
40127
- const client = getActiveClient();
40128
- client.log('comment/softDeleteComment', commentId);
40129
- const softDeleted = deleteComment(commentId);
40130
- return softDeleted;
40131
- };
40132
- /* end_public_function */
40073
+ }
40133
40074
 
40134
- /* begin_public_function
40135
- id: comment.hard_delete
40136
- */
40137
40075
  /**
40138
40076
  * ```js
40139
- * import { CommentRepository } from '@amityco/ts-sdk'
40140
- * const success = await CommentRepository.hardDeleteComment('foobar')
40077
+ * import { onCommentCreated } from '@amityco/ts-sdk'
40078
+ * const dispose = onCommentCreated(comment => {
40079
+ * // ...
40080
+ * })
40141
40081
  * ```
40142
40082
  *
40143
- * Deletes a {@link Amity.Comment}
40083
+ * Fired when a {@link Amity.InternalComment} has been created
40144
40084
  *
40145
- * @param commentId The {@link Amity.Comment} ID to delete
40146
- * @return A success boolean if the {@link Amity.Comment} was deleted
40085
+ * @param callback The function to call when the event was fired
40086
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40147
40087
  *
40148
- * @category Comment API
40149
- * @async
40088
+ * @category Comment Events
40150
40089
  */
40151
- const hardDeleteComment = async (commentId) => {
40152
- const client = getActiveClient();
40153
- client.log('comment/hardDeleteComment', commentId);
40154
- const hardDeleted = deleteComment(commentId, true);
40155
- return hardDeleted;
40090
+ const onCommentCreatedLocal = (callback) => {
40091
+ return createLocalCommentEventSubscriber('local.comment.created', callback);
40156
40092
  };
40157
- /* end_public_function */
40158
40093
 
40159
- /* begin_public_function
40160
- id: comment.flag
40161
- */
40162
- /**
40163
- * ```js
40164
- * import { CommentRepository } from '@amityco/ts-sdk'
40165
- * const flagged = await CommentRepository.flagComment(commentId, reason)
40166
- * ```
40167
- *
40168
- * @param commentId The ID of the comment to flag
40169
- * @param reason the reason to flag the comment
40170
- * @returns the created report result
40171
- *
40172
- * @category Comment API
40173
- * @async
40174
- * */
40175
- const flagComment = async (commentId, reason) => {
40176
- const client = getActiveClient();
40177
- client.log('comment/flagComment', commentId);
40178
- const isPredefinedReason = reason &&
40179
- Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
40180
- const body = {
40181
- reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
40182
- detail: reason && !isPredefinedReason ? reason : '',
40183
- };
40184
- const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
40185
- if (client.cache) {
40186
- ingestInCache(payload);
40094
+ class CommentLiveCollectionController extends LiveCollectionController {
40095
+ constructor(query, callback) {
40096
+ const queryStreamId = hash(query);
40097
+ const cacheKey = ['comments', 'collection', queryStreamId];
40098
+ const paginationController = new CommentPaginationController(query);
40099
+ super(paginationController, queryStreamId, cacheKey, callback);
40100
+ this.query = query;
40101
+ this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
40102
+ this.callback = callback.bind(this);
40103
+ this.loadPage({ initial: true });
40187
40104
  }
40188
- fireEvent('comment.flagged', payload);
40189
- return !!payload;
40190
- };
40191
- /* end_public_function */
40105
+ setup() {
40106
+ var _a;
40107
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40108
+ if (!collection) {
40109
+ pushToCache(this.cacheKey, {
40110
+ data: [],
40111
+ params: {},
40112
+ });
40113
+ }
40114
+ }
40115
+ async persistModel(queryPayload) {
40116
+ await this.queryStreamController.saveToMainDB(queryPayload);
40117
+ }
40118
+ persistQueryStream({ response, direction, refresh, }) {
40119
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
40120
+ }
40121
+ startSubscription() {
40122
+ return this.queryStreamController.subscribeRTE([
40123
+ { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
40124
+ { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
40125
+ { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
40126
+ { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
40127
+ { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
40128
+ { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
40129
+ { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
40130
+ { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40131
+ { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40132
+ { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40133
+ { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40134
+ ]);
40135
+ }
40136
+ notifyChange({ origin, loading, error }) {
40137
+ var _a, _b;
40138
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40139
+ if (!collection)
40140
+ return;
40141
+ const data = this.applyFilter((_b = collection.data
40142
+ .map(id => pullFromCache(['comment', 'get', id]))
40143
+ .filter(isNonNullable)
40144
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
40145
+ if (!this.shouldNotify(data) && origin === 'event')
40146
+ return;
40147
+ this.callback({
40148
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40149
+ data,
40150
+ hasNextPage: !!this.paginationController.getNextToken(),
40151
+ loading,
40152
+ error,
40153
+ });
40154
+ }
40155
+ applyFilter(data) {
40156
+ let comments = data;
40157
+ if (!this.query.includeDeleted) {
40158
+ comments = filterByPropEquality(comments, 'isDeleted', false);
40159
+ }
40160
+ if (this.query.parentId) {
40161
+ comments = comments.filter(comment => comment.parentId === this.query.parentId);
40162
+ }
40163
+ if (typeof this.query.hasFlag === 'boolean') {
40164
+ if (this.query.hasFlag) {
40165
+ comments = comments.filter(comment => comment.hashFlag != null);
40166
+ }
40167
+ else {
40168
+ comments = comments.filter(comment => comment.hashFlag == null);
40169
+ }
40170
+ }
40171
+ if (this.query.dataTypes) {
40172
+ if (this.query.dataTypes.matchType === 'exact') {
40173
+ comments = comments.filter(comment => {
40174
+ var _a, _b;
40175
+ const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
40176
+ const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
40177
+ if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
40178
+ return false;
40179
+ }
40180
+ return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
40181
+ });
40182
+ }
40183
+ if (this.query.dataTypes.matchType === 'any') {
40184
+ 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); }); });
40185
+ }
40186
+ }
40187
+ switch (this.query.sortBy) {
40188
+ case 'firstCreated':
40189
+ comments = comments.sort(sortByFirstCreated);
40190
+ break;
40191
+ case 'lastCreated':
40192
+ default:
40193
+ comments = comments.sort(sortByLastCreated);
40194
+ break;
40195
+ }
40196
+ return comments;
40197
+ }
40198
+ }
40192
40199
 
40193
40200
  /* begin_public_function
40194
- id: comment.unflag
40201
+ id: comment.query
40195
40202
  */
40196
40203
  /**
40197
40204
  * ```js
40198
- * import { CommentRepository } from '@amityco/ts-sdk'
40199
- * const unflagged = await CommentRepository.unflagComment('commentId')
40205
+ * import { getComments } from '@amityco/ts-sdk'
40206
+ *
40207
+ * let comments = []
40208
+ * const unsub = getComments({
40209
+ * referenceType: Amity.InternalComment['referenceType'];
40210
+ * referenceId: Amity.InternalComment['referenceId'];
40211
+ * }, response => merge(comments, response.data))
40200
40212
  * ```
40201
40213
  *
40202
- * @param commentId The ID of comment to unflag
40203
- * @returns the unflagged result
40214
+ * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
40204
40215
  *
40205
- * @category Comment API
40206
- * @async
40207
- * */
40208
- const unflagComment = async (commentId) => {
40209
- const client = getActiveClient();
40210
- client.log('comment/unflagComment', commentId);
40211
- const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
40212
- if (client.cache) {
40213
- ingestInCache(payload);
40216
+ * @param referenceType the type of the target
40217
+ * @param referenceId the ID of the target
40218
+ * @param callback the function to call when new data are available
40219
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
40220
+ *
40221
+ * @category Comments Live Collection
40222
+ */
40223
+ const getComments = (params, callback, config) => {
40224
+ const { log, cache } = getActiveClient();
40225
+ if (!cache) {
40226
+ console.log('For using Live Collection feature you need to enable Cache!');
40214
40227
  }
40215
- fireEvent('comment.unflagged', payload);
40216
- return !!payload;
40228
+ const timestamp = Date.now();
40229
+ log(`getComments(tmpid: ${timestamp}) > listen`);
40230
+ const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
40231
+ const disposers = commentsLiveCollection.startSubscription();
40232
+ const cacheKey = commentsLiveCollection.getCacheKey();
40233
+ disposers.push(() => dropFromCache(cacheKey));
40234
+ return () => {
40235
+ log(`getComments(tmpid: ${timestamp}) > dispose`);
40236
+ disposers.forEach(fn => fn());
40237
+ };
40217
40238
  };
40218
40239
  /* end_public_function */
40219
40240
 
40220
- /* begin_public_function
40221
- id: comment.check_flag_by_me
40222
- */
40223
- /**
40224
- * ```js
40225
- * import { CommentRepository } from '@amityco/ts-sdk'
40226
- * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
40227
- * ```
40228
- *
40229
- * @param commentId The ID of the comment to check if flagged by current user
40230
- * @returns `true` if the comment is flagged by me, `false` if doesn't.
40231
- *
40232
- * @category Comment API
40233
- * @async
40234
- * */
40235
- const isCommentFlaggedByMe = async (commentId) => {
40236
- const client = getActiveClient();
40237
- client.log('comment/isCommentFlaggedByMe', commentId);
40238
- const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
40239
- return result;
40240
- };
40241
- /* end_public_function */
40241
+ var index$a = /*#__PURE__*/Object.freeze({
40242
+ __proto__: null,
40243
+ getCommentByIds: getCommentByIds,
40244
+ createComment: createComment,
40245
+ updateComment: updateComment,
40246
+ deleteComment: deleteComment,
40247
+ softDeleteComment: softDeleteComment,
40248
+ hardDeleteComment: hardDeleteComment,
40249
+ flagComment: flagComment,
40250
+ unflagComment: unflagComment,
40251
+ isCommentFlaggedByMe: isCommentFlaggedByMe,
40252
+ onCommentCreated: onCommentCreated,
40253
+ onCommentUpdated: onCommentUpdated,
40254
+ onCommentDeleted: onCommentDeleted,
40255
+ onCommentFlagged: onCommentFlagged,
40256
+ onCommentUnflagged: onCommentUnflagged,
40257
+ onCommentReactionAdded: onCommentReactionAdded,
40258
+ onCommentReactionRemoved: onCommentReactionRemoved,
40259
+ getComment: getComment,
40260
+ getComments: getComments
40261
+ });
40242
40262
 
40243
- const getComment$1 = async (commentId) => {
40263
+ const getPost$1 = async (postId) => {
40244
40264
  const client = getActiveClient();
40245
- client.log('comment/getComment', commentId);
40246
- isInTombstone('comment', commentId);
40247
- let data;
40265
+ client.log('post/getPost', postId);
40266
+ isInTombstone('post', postId);
40267
+ let payload;
40248
40268
  try {
40249
40269
  // API-FIX: endpoint should not be /list, parameters should be querystring.
40250
- const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
40251
- data = response.data;
40270
+ const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
40271
+ payload = response.data;
40252
40272
  }
40253
40273
  catch (error) {
40254
40274
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
40255
- pushToTombstone('comment', commentId);
40275
+ pushToTombstone('post', postId);
40256
40276
  }
40257
40277
  throw error;
40258
40278
  }
40279
+ const data = prepareMembershipPayload(payload, 'communityUsers');
40259
40280
  const cachedAt = client.cache && Date.now();
40260
40281
  if (client.cache)
40261
40282
  ingestInCache(data, { cachedAt });
40262
- const { comments } = data;
40283
+ const { posts } = data;
40284
+ const result = posts.find(post => post.postId === postId);
40263
40285
  return {
40264
- data: comments.find(comment => comment.commentId === commentId),
40286
+ data: result,
40265
40287
  cachedAt,
40266
40288
  };
40267
40289
  };
40268
- getComment$1.locally = (commentId) => {
40290
+ getPost$1.locally = (postId) => {
40269
40291
  const client = getActiveClient();
40270
- client.log('comment/getComment.locally', commentId);
40292
+ client.log('post/getPost.locally', postId);
40271
40293
  if (!client.cache)
40272
40294
  return;
40273
- const cached = pullFromCache(['comment', 'get', commentId]);
40295
+ const cached = pullFromCache(['post', 'get', postId]);
40274
40296
  if (!cached)
40275
40297
  return;
40276
40298
  return {
@@ -40281,142 +40303,245 @@ getComment$1.locally = (commentId) => {
40281
40303
 
40282
40304
  /**
40283
40305
  * ```js
40284
- * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
40285
- * const dispose = onCommentDeleteLocal(comment => {
40306
+ * import { onLocalPostDeleted } from '@amityco/ts-sdk'
40307
+ * const dispose = onLocalPostDeleted(post => {
40286
40308
  * // ...
40287
40309
  * })
40288
40310
  * ```
40289
40311
  *
40290
- * Fired when a {@link Amity.InternalComment} has been deleted
40312
+ * Fired when a {@link Amity.InternalPost} has been deleted
40291
40313
  *
40292
40314
  * @param callback The function to call when the event was fired
40293
40315
  * @returns an {@link Amity.Unsubscriber} function to stop listening
40294
40316
  *
40295
- * @category Comment Events
40317
+ * @category Post Events
40296
40318
  */
40297
- const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
40319
+ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
40298
40320
 
40299
40321
  /**
40300
40322
  * ```js
40301
- * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
40302
- * const dispose = onLocalCommentReactionAdded(comment => {
40323
+ * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
40324
+ * const dispose = onPostReactionAdded(post => {
40303
40325
  * // ...
40304
40326
  * })
40305
40327
  * ```
40306
40328
  *
40307
- * Fired when a {@link Amity.InternalComment} has been reacted
40329
+ * Fired when a {@link Amity.InternalPost} has been reacted
40308
40330
  *
40309
40331
  * @param callback The function to call when the event was fired
40310
40332
  * @returns an {@link Amity.Unsubscriber} function to stop listening
40311
40333
  *
40312
- * @category Comment Events
40334
+ * @category Post Events
40313
40335
  */
40314
- const onLocalCommentReactionAdded = (callback) => {
40336
+ const onLocalPostReactionAdded = (callback) => {
40315
40337
  const client = getActiveClient();
40316
- const filter = ({ comment }) => {
40338
+ const filter = ({ post }) => {
40317
40339
  if (!client.cache) {
40318
- callback(comment);
40340
+ callback(post);
40319
40341
  }
40320
40342
  else {
40321
- upsertInCache(['comment', 'get', comment.commentId], comment);
40322
- callback(commentLinkedObject(comment));
40343
+ upsertInCache(['post', 'get', post.postId], post);
40344
+ callback(post);
40323
40345
  }
40324
40346
  };
40325
- return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
40347
+ return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
40326
40348
  };
40327
40349
 
40328
40350
  /**
40329
40351
  * ```js
40330
- * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
40331
- * const dispose = onLocalCommentReactionRemoved(comment => {
40352
+ * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
40353
+ * const dispose = onPostReactionRemoved(post => {
40332
40354
  * // ...
40333
40355
  * })
40334
40356
  * ```
40335
40357
  *
40336
- * Fired when a {@link Amity.InternalComment} has been reacted
40358
+ * Fired when a {@link Amity.InternalPost} has been reacted
40337
40359
  *
40338
40360
  * @param callback The function to call when the event was fired
40339
40361
  * @returns an {@link Amity.Unsubscriber} function to stop listening
40340
40362
  *
40341
- * @category Comment Events
40363
+ * @category Post Events
40342
40364
  */
40343
- const onLocalCommentReactionRemoved = (callback) => {
40365
+ const onLocalPostReactionRemoved = (callback) => {
40344
40366
  const client = getActiveClient();
40345
- const filter = ({ comment }) => {
40367
+ const filter = ({ post }) => {
40346
40368
  if (!client.cache) {
40347
- callback(comment);
40369
+ callback(post);
40348
40370
  }
40349
40371
  else {
40350
- upsertInCache(['comment', 'get', comment.commentId], comment);
40351
- callback(commentLinkedObject(comment));
40372
+ upsertInCache(['post', 'get', post.postId], post);
40373
+ callback(post);
40352
40374
  }
40353
40375
  };
40354
- return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
40376
+ return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
40355
40377
  };
40356
40378
 
40357
- /* begin_public_function
40358
- id: comment.get
40359
- */
40360
40379
  /**
40361
40380
  * ```js
40362
- * import { CommentRepository } from '@amityco/ts-sdk';
40363
- *
40364
- * let comment;
40365
- *
40366
- * const unsub = CommentRepository.getComment(commentId, response => {
40367
- * comment = response.data;
40368
- * });
40381
+ * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
40382
+ * const dispose = onPostUpdatedLocal(post => {
40383
+ * // ...
40384
+ * })
40369
40385
  * ```
40370
40386
  *
40371
- * Observe all mutation on a given {@link Amity.Comment}
40387
+ * Fired when a {@link Amity.InternalPost} has been updated
40372
40388
  *
40373
- * @param commentId the ID of the comment to observe
40374
- * @param callback the function to call when new data are available
40375
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
40389
+ * @param callback The function to call when the event was fired
40390
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40376
40391
  *
40377
- * @category Comment Live Object
40392
+ * @category Post Events
40378
40393
  */
40379
- const getComment = (commentId, callback) => {
40380
- return liveObject(commentId, callback, 'commentId', getComment$1, [
40381
- onCommentDeleteLocal,
40394
+ const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
40395
+
40396
+ const commentEventHandler$1 = (callback, eventHandler, cacheKey) => {
40397
+ return eventHandler(async (comment) => {
40398
+ var _a;
40399
+ const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40400
+ if (!currentCollection || !currentCollection.data.includes(comment.referenceId))
40401
+ return;
40402
+ await getPost$1(comment.referenceId);
40403
+ callback(comment);
40404
+ });
40405
+ };
40406
+ const generateCommentSubscriptions$1 = (cacheKey) => {
40407
+ const eventHandlers = [
40408
+ onCommentCreated,
40382
40409
  onCommentDeleted,
40383
- onCommentFlagged,
40384
40410
  onCommentReactionAdded,
40385
40411
  onCommentReactionRemoved,
40386
- onCommentUnflagged,
40387
- onCommentUpdated,
40412
+ onCommentCreatedLocal,
40413
+ onCommentDeleteLocal,
40388
40414
  onLocalCommentReactionAdded,
40389
40415
  onLocalCommentReactionRemoved,
40390
- ]);
40416
+ ];
40417
+ return eventHandlers.map(handler => ({
40418
+ fn: convertEventPayload((callback) => commentEventHandler$1(callback, handler, cacheKey), 'referenceId', 'post'),
40419
+ action: EnumPostActions.OnPostUpdated,
40420
+ }));
40421
+ };
40422
+ const getGlobalFeedSubscriptions = (cacheKey) => {
40423
+ return [
40424
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
40425
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
40426
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
40427
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
40428
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
40429
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
40430
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
40431
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
40432
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
40433
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
40434
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
40435
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
40436
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
40437
+ ...generateCommentSubscriptions$1(cacheKey),
40438
+ ];
40439
+ };
40440
+
40441
+ class CustomRankingGlobalFeedLiveCollectionController extends LiveCollectionController {
40442
+ constructor(query, callback) {
40443
+ const queryStreamId = hash(query);
40444
+ const cacheKey = ['customRankingGlobalFeed', 'collection', queryStreamId];
40445
+ const paginationController = new CustomRankingGlobalFeedPaginationController(query);
40446
+ super(paginationController, queryStreamId, cacheKey, callback);
40447
+ this.query = query;
40448
+ this.queryStreamController = new CustomRankingGlobalFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
40449
+ this.callback = callback.bind(this);
40450
+ this.loadPage({ initial: true });
40451
+ }
40452
+ setup() {
40453
+ var _a;
40454
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40455
+ if (!collection) {
40456
+ pushToCache(this.cacheKey, {
40457
+ data: [],
40458
+ params: {},
40459
+ });
40460
+ }
40461
+ }
40462
+ async persistModel(queryPayload) {
40463
+ await this.queryStreamController.saveToMainDB(queryPayload);
40464
+ }
40465
+ persistQueryStream({ response, direction, refresh, }) {
40466
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
40467
+ }
40468
+ startSubscription() {
40469
+ return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
40470
+ }
40471
+ notifyChange({ origin, loading, error }) {
40472
+ var _a, _b;
40473
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40474
+ if (!collection)
40475
+ return;
40476
+ const data = ((_b = collection.data
40477
+ .map(id => pullFromCache(['post', 'get', id]))
40478
+ .filter(isNonNullable)
40479
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
40480
+ if (!this.shouldNotify(data) && origin === 'event')
40481
+ return;
40482
+ this.callback({
40483
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40484
+ data,
40485
+ hasNextPage: !!this.paginationController.getNextToken(),
40486
+ loading,
40487
+ error,
40488
+ });
40489
+ }
40490
+ }
40491
+
40492
+ /* begin_public_function
40493
+ id: feed.query.custom_ranking_feed
40494
+ */
40495
+ /**
40496
+ * ```js
40497
+ * import { FeedRepository } from '@amityco/ts-sdk'
40498
+ *
40499
+ * let posts = []
40500
+ * const unsub = FeedRepository.getGlobalFeed({
40501
+ * dataTypes: ['video','image'],
40502
+ * resolveParent: true,
40503
+ * }, response => processResponse(response))
40504
+ * ```
40505
+ *
40506
+ * Observe all mutations on a list of {@link Amity.Post} for a given target object
40507
+ *
40508
+ * @param params.dataTypes array of data types for the posts
40509
+ * @param callback the function to call when new data are available
40510
+ * @param config
40511
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
40512
+ *
40513
+ * @category Posts Live Collection
40514
+ */
40515
+ const getCustomRankingGlobalFeed = (params, callback, config) => {
40516
+ const { log, cache } = getActiveClient();
40517
+ if (!cache) {
40518
+ console.log(ENABLE_CACHE_MESSAGE);
40519
+ }
40520
+ const timestamp = Date.now();
40521
+ log(`getCustomRankingGlobalFeed(tmpid: ${timestamp}) > listen`);
40522
+ const liveCollection = new CustomRankingGlobalFeedLiveCollectionController(params, callback);
40523
+ const disposers = liveCollection.startSubscription();
40524
+ const cacheKey = liveCollection.getCacheKey();
40525
+ disposers.push(() => dropFromCache(cacheKey));
40526
+ return () => {
40527
+ log(`getCustomRankingGlobalFeed(tmpid: ${timestamp}) > dispose`);
40528
+ disposers.forEach(fn => fn());
40529
+ };
40391
40530
  };
40392
40531
  /* end_public_function */
40393
40532
 
40394
- class CommentPaginationController extends PaginationController {
40533
+ class GlobalFeedPaginationController extends PaginationController {
40395
40534
  async getRequest(queryParams, token) {
40396
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
40397
- const baseOptions = {
40398
- type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
40399
- };
40400
- const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
40401
- const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
40402
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
40535
+ const { limit, resolveParent } = queryParams, params = __rest(queryParams, ["limit", "resolveParent"]);
40536
+ const options = token ? { token } : { limit };
40537
+ const { data: queryResponse } = await this.http.get(`/api/v4/me/global-feeds`, {
40538
+ params: Object.assign(Object.assign({}, params), { resolveParent: resolveParent !== null && resolveParent !== void 0 ? resolveParent : true, options }),
40403
40539
  });
40404
40540
  return queryResponse;
40405
40541
  }
40406
40542
  }
40407
40543
 
40408
- var EnumCommentActions;
40409
- (function (EnumCommentActions) {
40410
- EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
40411
- EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
40412
- EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
40413
- EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
40414
- EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
40415
- EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
40416
- EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
40417
- })(EnumCommentActions || (EnumCommentActions = {}));
40418
-
40419
- class CommentQueryStreamController extends QueryStreamController {
40544
+ class GlobalFeedQueryStreamController extends QueryStreamController {
40420
40545
  constructor(query, cacheKey, notifyChange, preparePayload) {
40421
40546
  super(query, cacheKey);
40422
40547
  this.notifyChange = notifyChange;
@@ -40434,321 +40559,848 @@ class CommentQueryStreamController extends QueryStreamController {
40434
40559
  var _a, _b;
40435
40560
  if (refresh) {
40436
40561
  pushToCache(this.cacheKey, {
40437
- data: response.comments.map(getResolver('comment')),
40562
+ data: response.posts.map(getResolver('post')),
40438
40563
  });
40439
40564
  }
40440
40565
  else {
40441
40566
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40442
- const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
40443
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
40567
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
40568
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
40444
40569
  }
40445
40570
  }
40446
40571
  reactor(action) {
40447
- return (comment) => {
40572
+ return (post) => {
40448
40573
  var _a;
40449
40574
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40450
- if (this.query.referenceId !== comment.referenceId ||
40451
- this.query.referenceType !== comment.referenceType ||
40452
- !collection) {
40575
+ if (!collection)
40453
40576
  return;
40454
- }
40455
- if (this.query.parentId && this.query.parentId !== comment.parentId) {
40577
+ if (post.parentPostId && !collection.data.includes(post.parentPostId))
40456
40578
  return;
40579
+ // Delete Action
40580
+ if (action === EnumPostActions.OnPostDeleted) {
40581
+ // Parent Post - Remove from collection
40582
+ collection.data = collection.data.filter(postId => postId !== post.postId);
40457
40583
  }
40458
- if (!this.query.parentId && comment.parentId) {
40584
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
40585
+ // If the query has dataTypes array with value, check if post.dataType is include in the array
40586
+ if (this.query.dataTypes && this.query.dataTypes.length > 0) {
40587
+ if (!this.query.dataTypes.includes(post.dataType))
40588
+ return;
40589
+ }
40590
+ collection.data = [...new Set([post.postId, ...collection.data])];
40591
+ }
40592
+ if (action === EnumPostActions.OnPostDeclined) {
40593
+ collection.data = collection.data.filter(postId => postId !== post.postId);
40594
+ }
40595
+ pushToCache(this.cacheKey, collection);
40596
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
40597
+ };
40598
+ }
40599
+ subscribeRTE(createSubscriber) {
40600
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
40601
+ }
40602
+ }
40603
+
40604
+ class GlobalFeedLiveCollectionController extends LiveCollectionController {
40605
+ constructor(query, callback) {
40606
+ const queryStreamId = hash(query);
40607
+ const cacheKey = ['globalFeed', 'collection', queryStreamId];
40608
+ const paginationController = new GlobalFeedPaginationController(query);
40609
+ super(paginationController, queryStreamId, cacheKey, callback);
40610
+ this.query = query;
40611
+ this.queryStreamController = new GlobalFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
40612
+ this.callback = callback.bind(this);
40613
+ this.loadPage({ initial: true });
40614
+ }
40615
+ setup() {
40616
+ var _a;
40617
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40618
+ if (!collection) {
40619
+ pushToCache(this.cacheKey, {
40620
+ data: [],
40621
+ params: {},
40622
+ });
40623
+ }
40624
+ }
40625
+ async persistModel(queryPayload) {
40626
+ await this.queryStreamController.saveToMainDB(queryPayload);
40627
+ }
40628
+ persistQueryStream({ response, direction, refresh, }) {
40629
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
40630
+ }
40631
+ startSubscription() {
40632
+ return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
40633
+ }
40634
+ notifyChange({ origin, loading, error }) {
40635
+ var _a, _b;
40636
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40637
+ if (!collection)
40638
+ return;
40639
+ const data = ((_b = collection.data
40640
+ .map(id => pullFromCache(['post', 'get', id]))
40641
+ .filter(isNonNullable)
40642
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
40643
+ if (!this.shouldNotify(data) && origin === 'event')
40644
+ return;
40645
+ this.callback({
40646
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40647
+ data,
40648
+ hasNextPage: !!this.paginationController.getNextToken(),
40649
+ loading,
40650
+ error,
40651
+ });
40652
+ }
40653
+ }
40654
+
40655
+ /* begin_public_function
40656
+ id: feed.query.global_feed
40657
+ */
40658
+ /**
40659
+ * ```js
40660
+ * import { FeedRepository } from '@amityco/ts-sdk'
40661
+ *
40662
+ * let posts = []
40663
+ * const unsub = FeedRepository.getGlobalFeed({
40664
+ * dataTypes: ['video','image'],
40665
+ * resolveParent: true,
40666
+ * }, response => processResponse(response))
40667
+ * ```
40668
+ *
40669
+ * Observe all mutations on a list of {@link Amity.Post} for global feed
40670
+ * @param params.dataTypes array of data types for the posts
40671
+ * @param params.resolveParent
40672
+ * @param callback the function to call when new data are available
40673
+ * @param config
40674
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
40675
+ *
40676
+ * @category Posts Live Collection
40677
+ */
40678
+ const getGlobalFeed = (params, callback, config) => {
40679
+ const { log, cache } = getActiveClient();
40680
+ if (!cache) {
40681
+ console.log(ENABLE_CACHE_MESSAGE);
40682
+ }
40683
+ const timestamp = Date.now();
40684
+ log(`getGlobalFeed(tmpid: ${timestamp}) > listen`);
40685
+ const liveCollection = new GlobalFeedLiveCollectionController(params, callback);
40686
+ const disposers = liveCollection.startSubscription();
40687
+ const cacheKey = liveCollection.getCacheKey();
40688
+ disposers.push(() => dropFromCache(cacheKey));
40689
+ return () => {
40690
+ log(`getGlobalFeed(tmpid: ${timestamp}) > dispose`);
40691
+ disposers.forEach(fn => fn());
40692
+ };
40693
+ };
40694
+ /* end_public_function */
40695
+
40696
+ class UserFeedPaginationController extends PaginationController {
40697
+ async getRequest(queryParams, token) {
40698
+ const { userId, feedSources, dataTypes, includeDeleted, matchingOnlyParentPost, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["userId", "feedSources", "dataTypes", "includeDeleted", "matchingOnlyParentPost", "limit"]);
40699
+ const options = token ? { token } : { limit };
40700
+ const { data: queryResponse } = await this.http.get(`/api/v4/user-feeds/${userId}`, {
40701
+ 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) }),
40702
+ });
40703
+ return queryResponse;
40704
+ }
40705
+ }
40706
+
40707
+ class UserFeedQueryStreamController extends QueryStreamController {
40708
+ constructor(query, cacheKey, notifyChange, preparePayload) {
40709
+ super(query, cacheKey);
40710
+ this.notifyChange = notifyChange;
40711
+ this.preparePayload = preparePayload;
40712
+ }
40713
+ async saveToMainDB(response) {
40714
+ const processedPayload = await this.preparePayload(response);
40715
+ const client = getActiveClient();
40716
+ const cachedAt = client.cache && Date.now();
40717
+ if (client.cache) {
40718
+ ingestInCache(processedPayload, { cachedAt });
40719
+ }
40720
+ }
40721
+ appendToQueryStream(response, direction, refresh = false) {
40722
+ var _a, _b;
40723
+ if (refresh) {
40724
+ pushToCache(this.cacheKey, {
40725
+ data: response.posts.map(getResolver('post')),
40726
+ });
40727
+ }
40728
+ else {
40729
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40730
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
40731
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
40732
+ }
40733
+ }
40734
+ reactor(action) {
40735
+ return (post) => {
40736
+ var _a, _b;
40737
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40738
+ if (!collection)
40739
+ return;
40740
+ // if the collection is parent post collection and
40741
+ // post is not included in the collection or post is child post
40742
+ if ((!this.query.dataTypes || this.query.dataTypes.length === 0) &&
40743
+ !collection.data.includes(post.parentPostId ? post.parentPostId : post.postId))
40459
40744
  return;
40745
+ if (action === EnumPostActions.OnPostDeleted) {
40746
+ collection.data = collection.data.filter(postId => postId !== post.postId);
40460
40747
  }
40461
- if (action === EnumCommentActions.OnCommentCreated) {
40462
- collection.data = [...new Set([comment.commentId, ...collection.data])];
40748
+ if (post.parentPostId && post.isDeleted) {
40749
+ const parentPost = (_b = pullFromCache([
40750
+ 'post',
40751
+ 'get',
40752
+ post.parentPostId,
40753
+ ])) === null || _b === void 0 ? void 0 : _b.data;
40754
+ if (!parentPost)
40755
+ return;
40756
+ parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
40757
+ pushToCache(['post', 'get', parentPost.postId], parentPost);
40758
+ }
40759
+ if (action === EnumPostActions.OnPostDeclined) {
40760
+ collection.data = collection.data.filter(postId => postId !== post.postId);
40761
+ }
40762
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
40763
+ if (this.query.dataTypes &&
40764
+ this.query.dataTypes.length > 0 &&
40765
+ !this.query.dataTypes.includes(post.dataType)) {
40766
+ return;
40767
+ }
40768
+ collection.data = [...new Set([post.postId, ...collection.data])];
40463
40769
  }
40464
40770
  pushToCache(this.cacheKey, collection);
40465
40771
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
40466
40772
  };
40467
40773
  }
40468
- subscribeRTE(createSubscriber) {
40469
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
40774
+ subscribeRTE(createSubscriber) {
40775
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
40776
+ }
40777
+ }
40778
+
40779
+ class UserFeedLiveCollectionController extends LiveCollectionController {
40780
+ constructor(query, callback) {
40781
+ const queryStreamId = hash(query);
40782
+ const cacheKey = ['userFeed', 'collection', queryStreamId];
40783
+ const paginationController = new UserFeedPaginationController(query);
40784
+ super(paginationController, queryStreamId, cacheKey, callback);
40785
+ this.query = query;
40786
+ this.queryStreamController = new UserFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
40787
+ this.callback = callback.bind(this);
40788
+ this.loadPage({ initial: true });
40789
+ }
40790
+ setup() {
40791
+ var _a;
40792
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40793
+ if (!collection) {
40794
+ pushToCache(this.cacheKey, {
40795
+ data: [],
40796
+ params: {},
40797
+ });
40798
+ }
40799
+ }
40800
+ async persistModel(queryPayload) {
40801
+ await this.queryStreamController.saveToMainDB(queryPayload);
40802
+ }
40803
+ persistQueryStream({ response, direction, refresh, }) {
40804
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
40805
+ }
40806
+ startSubscription() {
40807
+ return this.queryStreamController.subscribeRTE([
40808
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
40809
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
40810
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
40811
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
40812
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
40813
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
40814
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
40815
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
40816
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
40817
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
40818
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
40819
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
40820
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
40821
+ {
40822
+ fn: convertEventPayload((callback) => {
40823
+ return onCommentCreated(async (comment) => {
40824
+ var _a;
40825
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40826
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
40827
+ return;
40828
+ await getPost$1(comment.referenceId);
40829
+ callback(comment);
40830
+ });
40831
+ }, 'referenceId', 'post'),
40832
+ action: EnumPostActions.OnPostUpdated,
40833
+ },
40834
+ {
40835
+ fn: convertEventPayload((callback) => {
40836
+ return onCommentDeleted(async (comment) => {
40837
+ var _a;
40838
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40839
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
40840
+ return;
40841
+ await getPost$1(comment.referenceId);
40842
+ callback(comment);
40843
+ });
40844
+ }, 'referenceId', 'post'),
40845
+ action: EnumPostActions.OnPostUpdated,
40846
+ },
40847
+ ]);
40848
+ }
40849
+ notifyChange({ origin, loading, error }) {
40850
+ var _a, _b;
40851
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40852
+ if (!collection)
40853
+ return;
40854
+ const data = ((_b = collection.data
40855
+ .map(id => pullFromCache(['post', 'get', id]))
40856
+ .filter(isNonNullable)
40857
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
40858
+ if (!this.shouldNotify(data) && origin === 'event')
40859
+ return;
40860
+ this.callback({
40861
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40862
+ data,
40863
+ hasNextPage: !!this.paginationController.getNextToken(),
40864
+ loading,
40865
+ error,
40866
+ });
40867
+ }
40868
+ }
40869
+
40870
+ /* begin_public_function
40871
+ id: feed.query.user_feed
40872
+ */
40873
+ /**
40874
+ * ```js
40875
+ * import { FeedRepository } from '@amityco/ts-sdk'
40876
+ *
40877
+ * let posts = []
40878
+ * const unsubscribe = FeedRepository.getUserFeed({
40879
+ * userId: string,
40880
+ * feedSources: ['user', 'community'],
40881
+ * }, response => response => processResponse(response))
40882
+ * ```
40883
+ *
40884
+ * Observe all mutations on a list of {@link Amity.Post} for a given user and feedSources
40885
+ *
40886
+ * @param params.userId the ID of the user
40887
+ * @param params.feedSources the sources of the feed
40888
+ * @param callback the function to call when new data are available
40889
+ * @param config
40890
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
40891
+ *
40892
+ * @category Posts Live Collection
40893
+ */
40894
+ const getUserFeed = (params, callback, config) => {
40895
+ const { log, cache } = getActiveClient();
40896
+ if (!cache) {
40897
+ console.log(ENABLE_CACHE_MESSAGE);
40898
+ }
40899
+ const timestamp = Date.now();
40900
+ log(`getUserFeed(tmpid: ${timestamp}) > listen`);
40901
+ const userFeedLiveCollection = new UserFeedLiveCollectionController(params, callback);
40902
+ const disposers = userFeedLiveCollection.startSubscription();
40903
+ const cacheKey = userFeedLiveCollection.getCacheKey();
40904
+ disposers.push(() => dropFromCache(cacheKey));
40905
+ return () => {
40906
+ log(`getUserFeed(tmpid: ${timestamp}) > dispose`);
40907
+ disposers.forEach(fn => fn());
40908
+ };
40909
+ };
40910
+ /* end_public_function */
40911
+
40912
+ var index$9 = /*#__PURE__*/Object.freeze({
40913
+ __proto__: null,
40914
+ queryGlobalFeed: queryGlobalFeed,
40915
+ getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
40916
+ getGlobalFeed: getGlobalFeed,
40917
+ getUserFeed: getUserFeed
40918
+ });
40919
+
40920
+ /* begin_public_function
40921
+ id: post.get_by_ids
40922
+ */
40923
+ /**
40924
+ * ```js
40925
+ * import { getPostByIds } from '@amityco/ts-sdk'
40926
+ * const { data: posts } = await getPostByIds(['foo', 'bar'])
40927
+ * ```
40928
+ *
40929
+ * Fetches a collection of {@link Amity.Post} objects
40930
+ *
40931
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
40932
+ * @returns the associated collection of {@link Amity.Post} objects
40933
+ *
40934
+ * @category Post API
40935
+ * @async
40936
+ */
40937
+ const getPostByIds = async (postIds) => {
40938
+ const client = getActiveClient();
40939
+ client.log('post/getPostByIds', postIds);
40940
+ const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
40941
+ let payload;
40942
+ try {
40943
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
40944
+ const response = await client.http.get(`/api/v3/posts/list`, {
40945
+ params: { postIds: encodedPostIds },
40946
+ });
40947
+ payload = response.data;
40948
+ }
40949
+ catch (error) {
40950
+ postIds.forEach(postId => {
40951
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
40952
+ pushToTombstone('post', postId);
40953
+ }
40954
+ });
40955
+ throw error;
40956
+ }
40957
+ const data = prepareMembershipPayload(payload, 'communityUsers');
40958
+ const cachedAt = client.cache && Date.now();
40959
+ if (client.cache)
40960
+ ingestInCache(data, { cachedAt });
40961
+ return {
40962
+ data: data.posts.map(LinkedObject.post),
40963
+ cachedAt,
40964
+ };
40965
+ };
40966
+ /* end_public_function */
40967
+ /**
40968
+ * ```js
40969
+ * import { getPostByIds } from '@amityco/ts-sdk'
40970
+ * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
40971
+ * ```
40972
+ *
40973
+ * Fetches a collection of {@link Amity.Post} objects from cache
40974
+ *
40975
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
40976
+ * @returns the associated collection of {@link Amity.Post} objects
40977
+ *
40978
+ * @category Post API
40979
+ */
40980
+ getPostByIds.locally = (postIds) => {
40981
+ var _a;
40982
+ const client = getActiveClient();
40983
+ client.log('post/getPostByIds.locally', postIds);
40984
+ if (!client.cache)
40985
+ return;
40986
+ const cached = postIds
40987
+ .map(postId => pullFromCache(['post', 'get', postId]))
40988
+ .filter(Boolean);
40989
+ const posts = cached.map(({ data }) => data);
40990
+ const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
40991
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
40992
+ return;
40993
+ return {
40994
+ data: posts.map(LinkedObject.post),
40995
+ cachedAt: oldest.cachedAt,
40996
+ };
40997
+ };
40998
+
40999
+ /* begin_public_function
41000
+ 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
41001
+ */
41002
+ /**
41003
+ * ```js
41004
+ * import { PostRepository } from '@amityco/ts-sdk'
41005
+ * const created = await PostRepository.createPost({
41006
+ * targetType: 'user',
41007
+ * targetId: 'foobar',
41008
+ * data: { text: 'hello world' }
41009
+ * }))
41010
+ * ```
41011
+ *
41012
+ * Creates an {@link Amity.Post}
41013
+ *
41014
+ * @param bundle The data necessary to create a new {@link Amity.Post}
41015
+ * @returns The newly created {@link Amity.Post}
41016
+ *
41017
+ * @category Post API
41018
+ * @async
41019
+ */
41020
+ const createPost = async (bundle) => {
41021
+ const client = getActiveClient();
41022
+ client.log('post/createPost', bundle);
41023
+ if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
41024
+ // eslint-disable-next-line no-param-reassign
41025
+ delete bundle.dataType;
41026
+ }
41027
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
41028
+ fireEvent('post.created', payload);
41029
+ const data = preparePostPayload(payload);
41030
+ const cachedAt = client.cache && Date.now();
41031
+ if (client.cache)
41032
+ ingestInCache(data, { cachedAt });
41033
+ const { posts } = data;
41034
+ return {
41035
+ data: LinkedObject.post(posts[0]),
41036
+ cachedAt,
41037
+ };
41038
+ };
41039
+ /* end_public_function */
41040
+
41041
+ /* begin_public_function
41042
+ id: post.edit, post.edit.custom_post
41043
+ */
41044
+ /**
41045
+ * ```js
41046
+ * import { PostRepository } from '@amityco/ts-sdk'
41047
+ * const updated = await PostRepository.editPost(postId, {
41048
+ * data: { text: 'hello world' }
41049
+ * })
41050
+ * ```
41051
+ *
41052
+ * Updates an {@link Amity.Post}
41053
+ *
41054
+ * @param postId The ID of the {@link Amity.Post} to edit
41055
+ * @param patch The patch data to apply
41056
+ * @returns the updated {@link Amity.Post} object
41057
+ *
41058
+ * @category Post API
41059
+ * @async
41060
+ */
41061
+ const editPost = async (postId, patch) => {
41062
+ const client = getActiveClient();
41063
+ client.log('user/editPost', patch);
41064
+ const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
41065
+ const data = prepareMembershipPayload(payload, 'communityUsers');
41066
+ const cachedAt = client.cache && Date.now();
41067
+ if (client.cache)
41068
+ ingestInCache(data, { cachedAt });
41069
+ fireEvent('local.post.updated', data);
41070
+ const { posts } = data;
41071
+ return {
41072
+ data: LinkedObject.post(posts.find(post => post.postId === postId)),
41073
+ cachedAt,
41074
+ };
41075
+ };
41076
+ /* end_public_function */
41077
+
41078
+ /**
41079
+ * ```js
41080
+ * import { deletePost } from '@amityco/ts-sdk'
41081
+ * const success = await deletePost('foobar')
41082
+ * ```
41083
+ *
41084
+ * Deletes a {@link Amity.Post}
41085
+ *
41086
+ * @param postId The {@link Amity.Post} ID to delete
41087
+ * @return A success boolean if the {@link Amity.Post} was deleted
41088
+ *
41089
+ * @private
41090
+ * @async
41091
+ */
41092
+ const deletePost = async (postId, permanent = false) => {
41093
+ var _a;
41094
+ const client = getActiveClient();
41095
+ const post = await getPost$2(postId);
41096
+ await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
41097
+ params: {
41098
+ postId,
41099
+ permanent,
41100
+ },
41101
+ });
41102
+ // there is currently a limitation which doesn't allow us to fire event to tell that community
41103
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
41104
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
41105
+ // later when realtime events covers that for us.
41106
+ if (post.data.targetType === 'community') {
41107
+ const community = await getCommunity$1(post.data.targetId);
41108
+ const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
41109
+ const communityUsers = communityUsersCache
41110
+ .filter(({ key }) => {
41111
+ // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
41112
+ if (key[0] !== 'communityUsers')
41113
+ return false;
41114
+ if (key[1] !== 'get')
41115
+ return false;
41116
+ if (typeof key[2] === 'string')
41117
+ return key[2].includes(community.data.communityId);
41118
+ return false;
41119
+ })
41120
+ .map(({ data }) => data);
41121
+ fireEvent('community.updated', {
41122
+ communities: [community.data],
41123
+ categories: [],
41124
+ communityUsers,
41125
+ feeds: [],
41126
+ files: [],
41127
+ users: [],
41128
+ });
41129
+ }
41130
+ // to support hard deletion
41131
+ const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
41132
+ if (permanent) {
41133
+ setTimeout(() => {
41134
+ pushToTombstone('post', postId);
41135
+ }, 0);
40470
41136
  }
40471
- }
41137
+ else {
41138
+ upsertInCache(['post', 'get', postId], { isDeleted: true });
41139
+ }
41140
+ fireEvent('local.post.deleted', {
41141
+ posts: [deleted],
41142
+ categories: [],
41143
+ comments: [],
41144
+ communities: [],
41145
+ communityUsers: [],
41146
+ feeds: [],
41147
+ files: [],
41148
+ postChildren: [],
41149
+ users: [],
41150
+ videoStreamings: [],
41151
+ });
41152
+ return LinkedObject.post(deleted);
41153
+ };
40472
41154
 
41155
+ /* begin_public_function
41156
+ id: post.soft_delete
41157
+ */
40473
41158
  /**
40474
41159
  * ```js
40475
- * import { onCommentCreated } from '@amityco/ts-sdk'
40476
- * const dispose = onCommentCreated(comment => {
40477
- * // ...
40478
- * })
41160
+ * import { PostRepository } from '@amityco/ts-sdk'
41161
+ * const success = await PostRepository.softDeletePost('foobar')
40479
41162
  * ```
40480
41163
  *
40481
- * Fired when a {@link Amity.InternalComment} has been created
41164
+ * Soft deletes a {@link Amity.Post}
40482
41165
  *
40483
- * @param callback The function to call when the event was fired
40484
- * @returns an {@link Amity.Unsubscriber} function to stop listening
41166
+ * @param postId The {@link Amity.Post} ID to soft delete
41167
+ * @return A success boolean if the {@link Amity.Post} was deleted
40485
41168
  *
40486
- * @category Comment Events
41169
+ * @category Post API
41170
+ * @async
40487
41171
  */
40488
- const onCommentCreatedLocal = (callback) => {
40489
- return createLocalCommentEventSubscriber('local.comment.created', callback);
41172
+ const softDeletePost = async (postId) => {
41173
+ const client = getActiveClient();
41174
+ client.log('post/softDeletePost', postId);
41175
+ const softDeleted = await deletePost(postId, false);
41176
+ return LinkedObject.post(softDeleted);
40490
41177
  };
41178
+ /* end_public_function */
40491
41179
 
40492
- class CommentLiveCollectionController extends LiveCollectionController {
40493
- constructor(query, callback) {
40494
- const queryStreamId = hash(query);
40495
- const cacheKey = ['comments', 'collection', queryStreamId];
40496
- const paginationController = new CommentPaginationController(query);
40497
- super(paginationController, queryStreamId, cacheKey, callback);
40498
- this.query = query;
40499
- this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
40500
- this.callback = callback.bind(this);
40501
- this.loadPage({ initial: true });
40502
- }
40503
- setup() {
40504
- var _a;
40505
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40506
- if (!collection) {
40507
- pushToCache(this.cacheKey, {
40508
- data: [],
40509
- params: {},
40510
- });
40511
- }
40512
- }
40513
- async persistModel(queryPayload) {
40514
- await this.queryStreamController.saveToMainDB(queryPayload);
40515
- }
40516
- persistQueryStream({ response, direction, refresh, }) {
40517
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
40518
- }
40519
- startSubscription() {
40520
- return this.queryStreamController.subscribeRTE([
40521
- { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
40522
- { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
40523
- { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
40524
- { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
40525
- { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
40526
- { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
40527
- { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
40528
- { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40529
- { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40530
- { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40531
- { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40532
- ]);
40533
- }
40534
- notifyChange({ origin, loading, error }) {
40535
- var _a, _b;
40536
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40537
- if (!collection)
40538
- return;
40539
- const data = this.applyFilter((_b = collection.data
40540
- .map(id => pullFromCache(['comment', 'get', id]))
40541
- .filter(isNonNullable)
40542
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
40543
- if (!this.shouldNotify(data) && origin === 'event')
40544
- return;
40545
- this.callback({
40546
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40547
- data,
40548
- hasNextPage: !!this.paginationController.getNextToken(),
40549
- loading,
40550
- error,
40551
- });
40552
- }
40553
- applyFilter(data) {
40554
- let comments = data;
40555
- if (!this.query.includeDeleted) {
40556
- comments = filterByPropEquality(comments, 'isDeleted', false);
40557
- }
40558
- if (this.query.parentId) {
40559
- comments = comments.filter(comment => comment.parentId === this.query.parentId);
40560
- }
40561
- if (typeof this.query.hasFlag === 'boolean') {
40562
- if (this.query.hasFlag) {
40563
- comments = comments.filter(comment => comment.hashFlag != null);
40564
- }
40565
- else {
40566
- comments = comments.filter(comment => comment.hashFlag == null);
40567
- }
40568
- }
40569
- if (this.query.dataTypes) {
40570
- if (this.query.dataTypes.matchType === 'exact') {
40571
- comments = comments.filter(comment => {
40572
- var _a, _b;
40573
- const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
40574
- const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
40575
- if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
40576
- return false;
40577
- }
40578
- return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
40579
- });
40580
- }
40581
- if (this.query.dataTypes.matchType === 'any') {
40582
- comments = comments.filter(comment => { var _a; return (_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.some(value => { var _a; return (_a = comment.dataTypes) === null || _a === void 0 ? void 0 : _a.includes(value); }); });
40583
- }
40584
- }
40585
- switch (this.query.sortBy) {
40586
- case 'firstCreated':
40587
- comments = comments.sort(sortByFirstCreated);
40588
- break;
40589
- case 'lastCreated':
40590
- default:
40591
- comments = comments.sort(sortByLastCreated);
40592
- break;
40593
- }
40594
- return comments;
40595
- }
40596
- }
41180
+ /* begin_public_function
41181
+ id: post.hard_delete
41182
+ */
41183
+ /**
41184
+ * ```js
41185
+ * import { hardDeletePost } from '@amityco/ts-sdk'
41186
+ * const success = await hardDeletePost('foobar')
41187
+ * ```
41188
+ *
41189
+ * Hard deletes a {@link Amity.Post}
41190
+ *
41191
+ * @param postId The {@link Amity.Post} ID to be hard delete
41192
+ * @return A success boolean if the {@link Amity.Post} was deleted
41193
+ *
41194
+ * @category Post API
41195
+ * @async
41196
+ */
41197
+ const hardDeletePost = async (postId) => {
41198
+ const client = getActiveClient();
41199
+ client.log('post/hardDeletePost', postId);
41200
+ const hardDeleted = await deletePost(postId, true);
41201
+ return LinkedObject.post(hardDeleted);
41202
+ };
41203
+ /* end_public_function */
40597
41204
 
40598
41205
  /* begin_public_function
40599
- id: comment.query
41206
+ id: post.approve
40600
41207
  */
40601
41208
  /**
40602
41209
  * ```js
40603
- * import { getComments } from '@amityco/ts-sdk'
41210
+ * import { approvePost } from '@amityco/ts-sdk'
40604
41211
  *
40605
- * let comments = []
40606
- * const unsub = getComments({
40607
- * referenceType: Amity.InternalComment['referenceType'];
40608
- * referenceId: Amity.InternalComment['referenceId'];
40609
- * }, response => merge(comments, response.data))
41212
+ * const { data: post } = await approvePost('postId')
40610
41213
  * ```
40611
41214
  *
40612
- * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
41215
+ * Approves a {@link Amity.Post}
40613
41216
  *
40614
- * @param referenceType the type of the target
40615
- * @param referenceId the ID of the target
40616
- * @param callback the function to call when new data are available
40617
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
41217
+ * @param postId The {@link Amity.Post} ID to be approved
41218
+ * @return A {@link Amity.Post} that was approved
40618
41219
  *
40619
- * @category Comments Live Collection
41220
+ * @category Post API
41221
+ * @async
40620
41222
  */
40621
- const getComments = (params, callback, config) => {
40622
- const { log, cache } = getActiveClient();
40623
- if (!cache) {
40624
- console.log('For using Live Collection feature you need to enable Cache!');
41223
+ const approvePost = async (postId) => {
41224
+ const client = getActiveClient();
41225
+ client.log('post/approvePost', postId);
41226
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
41227
+ fireEvent('post.approved', payload);
41228
+ // fire virtual event for community update
41229
+ if (payload.posts[0].targetType === 'community') {
41230
+ fireEvent('community.updated', payload);
40625
41231
  }
40626
- const timestamp = Date.now();
40627
- log(`getComments(tmpid: ${timestamp}) > listen`);
40628
- const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
40629
- const disposers = commentsLiveCollection.startSubscription();
40630
- const cacheKey = commentsLiveCollection.getCacheKey();
40631
- disposers.push(() => dropFromCache(cacheKey));
40632
- return () => {
40633
- log(`getComments(tmpid: ${timestamp}) > dispose`);
40634
- disposers.forEach(fn => fn());
41232
+ const data = prepareMembershipPayload(payload, 'communityUsers');
41233
+ const cachedAt = client.cache && Date.now();
41234
+ if (client.cache)
41235
+ ingestInCache(data, { cachedAt });
41236
+ return {
41237
+ data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
41238
+ cachedAt,
40635
41239
  };
40636
41240
  };
40637
41241
  /* end_public_function */
40638
41242
 
40639
- var index$9 = /*#__PURE__*/Object.freeze({
40640
- __proto__: null,
40641
- getCommentByIds: getCommentByIds,
40642
- createComment: createComment,
40643
- updateComment: updateComment,
40644
- deleteComment: deleteComment,
40645
- softDeleteComment: softDeleteComment,
40646
- hardDeleteComment: hardDeleteComment,
40647
- flagComment: flagComment,
40648
- unflagComment: unflagComment,
40649
- isCommentFlaggedByMe: isCommentFlaggedByMe,
40650
- onCommentCreated: onCommentCreated,
40651
- onCommentUpdated: onCommentUpdated,
40652
- onCommentDeleted: onCommentDeleted,
40653
- onCommentFlagged: onCommentFlagged,
40654
- onCommentUnflagged: onCommentUnflagged,
40655
- onCommentReactionAdded: onCommentReactionAdded,
40656
- onCommentReactionRemoved: onCommentReactionRemoved,
40657
- getComment: getComment,
40658
- getComments: getComments
40659
- });
40660
-
41243
+ /* begin_public_function
41244
+ id: post.decline
41245
+ */
40661
41246
  /**
40662
41247
  * ```js
40663
- * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
40664
- * const dispose = onPostUpdatedLocal(post => {
40665
- * // ...
40666
- * })
41248
+ * import { declinePost } from '@amityco/ts-sdk'
41249
+ *
41250
+ * const {data: post} = await declinePost('postId')
40667
41251
  * ```
40668
41252
  *
40669
- * Fired when a {@link Amity.InternalPost} has been updated
41253
+ * Declines a {@link Amity.Post}
40670
41254
  *
40671
- * @param callback The function to call when the event was fired
40672
- * @returns an {@link Amity.Unsubscriber} function to stop listening
41255
+ * @param postId The {@link Amity.Post} ID to be declined
41256
+ * @return A {@link Amity.Post} that was declined
40673
41257
  *
40674
- * @category Post Events
41258
+ * @category Post API
41259
+ * @async
40675
41260
  */
40676
- const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
41261
+ const declinePost = async (postId) => {
41262
+ const client = getActiveClient();
41263
+ client.log('post/declinePost', postId);
41264
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
41265
+ // fire virtual event
41266
+ if (payload.posts[0].targetType === 'community') {
41267
+ fireEvent('community.updated', payload);
41268
+ }
41269
+ fireEvent('post.declined', payload);
41270
+ const data = prepareMembershipPayload(payload, 'communityUsers');
41271
+ const cachedAt = client.cache && Date.now();
41272
+ if (client.cache)
41273
+ ingestInCache(data, { cachedAt });
41274
+ return {
41275
+ data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
41276
+ cachedAt,
41277
+ };
41278
+ };
41279
+ /* end_public_function */
40677
41280
 
41281
+ /* begin_public_function
41282
+ id: post.flag
41283
+ */
40678
41284
  /**
40679
41285
  * ```js
40680
- * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
40681
- * const dispose = onPostReactionAdded(post => {
40682
- * // ...
40683
- * })
41286
+ * import { PostRepository } from '@amityco/ts-sdk'
41287
+ * const flagged = await PostRepository.flagPost(postId, reason)
40684
41288
  * ```
40685
41289
  *
40686
- * Fired when a {@link Amity.InternalPost} has been reacted
40687
- *
40688
- * @param callback The function to call when the event was fired
40689
- * @returns an {@link Amity.Unsubscriber} function to stop listening
41290
+ * @param postId of the post to flag
41291
+ * @param reason the reason to flag the post
41292
+ * @returns a boolean
40690
41293
  *
40691
- * @category Post Events
40692
- */
40693
- const onLocalPostReactionAdded = (callback) => {
41294
+ * @category Post API
41295
+ * @async
41296
+ * */
41297
+ const flagPost = async (postId, reason) => {
40694
41298
  const client = getActiveClient();
40695
- const filter = ({ post }) => {
40696
- if (!client.cache) {
40697
- callback(post);
40698
- }
40699
- else {
40700
- upsertInCache(['post', 'get', post.postId], post);
40701
- callback(post);
40702
- }
41299
+ client.log('post/flagPost', postId);
41300
+ const isPredefinedReason = reason &&
41301
+ Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
41302
+ const body = {
41303
+ reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
41304
+ detail: reason && !isPredefinedReason ? reason : '',
40703
41305
  };
40704
- return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
41306
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
41307
+ if (client.cache) {
41308
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
41309
+ }
41310
+ fireEvent('post.flagged', payload);
41311
+ return !!payload;
40705
41312
  };
41313
+ /* end_public_function */
40706
41314
 
41315
+ /* begin_public_function
41316
+ id: post.unflag
41317
+ */
40707
41318
  /**
40708
41319
  * ```js
40709
- * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
40710
- * const dispose = onPostReactionRemoved(post => {
40711
- * // ...
40712
- * })
41320
+ * import { PostRepository } from '@amityco/ts-sdk'
41321
+ * const unflagged = await PostRepository.unflagPost(postId)
40713
41322
  * ```
40714
41323
  *
40715
- * Fired when a {@link Amity.InternalPost} has been reacted
41324
+ * @param postId of the post to unflag
41325
+ * @returns the unflag post result
40716
41326
  *
40717
- * @param callback The function to call when the event was fired
40718
- * @returns an {@link Amity.Unsubscriber} function to stop listening
41327
+ * @category Post API
41328
+ * @async
41329
+ * */
41330
+ const unflagPost = async (postId) => {
41331
+ const client = getActiveClient();
41332
+ client.log('post/unflagPost', postId);
41333
+ const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
41334
+ if (client.cache) {
41335
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
41336
+ }
41337
+ fireEvent('post.unflagged', payload);
41338
+ return !!payload;
41339
+ };
41340
+ /* end_public_function */
41341
+
41342
+ /* begin_public_function
41343
+ id: post.check_flag_by_me
41344
+ */
41345
+ /**
41346
+ * ```js
41347
+ * import { PostRepository } from '@amityco/ts-sdk'
41348
+ * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
41349
+ * ```
40719
41350
  *
40720
- * @category Post Events
40721
- */
40722
- const onLocalPostReactionRemoved = (callback) => {
41351
+ * @param postId of the post to check if flagged by current user
41352
+ * @returns `true` if the post is flagged by me, `false` if doesn't.
41353
+ *
41354
+ * @category Post API
41355
+ * @async
41356
+ * */
41357
+ const isPostFlaggedByMe = async (postId) => {
40723
41358
  const client = getActiveClient();
40724
- const filter = ({ post }) => {
40725
- if (!client.cache) {
40726
- callback(post);
40727
- }
40728
- else {
40729
- upsertInCache(['post', 'get', post.postId], post);
40730
- callback(post);
40731
- }
40732
- };
40733
- return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
41359
+ client.log('post/isPostFlaggedByMe', postId);
41360
+ const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
41361
+ return result;
40734
41362
  };
41363
+ /* end_public_function */
40735
41364
 
41365
+ /* begin_public_function
41366
+ id: post.create.clip_post
41367
+ */
40736
41368
  /**
40737
41369
  * ```js
40738
- * import { onLocalPostDeleted } from '@amityco/ts-sdk'
40739
- * const dispose = onLocalPostDeleted(post => {
40740
- * // ...
40741
- * })
41370
+ * import { PostRepository } from '@amityco/ts-sdk'
41371
+ * const created = await PostRepository.createClipPost({
41372
+ * targetType: 'user',
41373
+ * targetId: 'foobar',
41374
+ * dataType: 'clip',
41375
+ * data: { text: 'hello world' },
41376
+ * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
41377
+ * }))
40742
41378
  * ```
40743
41379
  *
40744
- * Fired when a {@link Amity.InternalPost} has been deleted
41380
+ * Creates an {@link Amity.Post}
40745
41381
  *
40746
- * @param callback The function to call when the event was fired
40747
- * @returns an {@link Amity.Unsubscriber} function to stop listening
41382
+ * @param bundle The data necessary to create a new {@link Amity.Post}
41383
+ * @returns The newly created {@link Amity.Post}
40748
41384
  *
40749
- * @category Post Events
41385
+ * @category Post API
41386
+ * @async
40750
41387
  */
40751
- const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
41388
+ const createClipPost = async (bundle) => {
41389
+ const client = getActiveClient();
41390
+ client.log('post/createPost', bundle);
41391
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
41392
+ fireEvent('post.created', payload);
41393
+ const data = prepareMembershipPayload(payload, 'communityUsers');
41394
+ const cachedAt = client.cache && Date.now();
41395
+ if (client.cache)
41396
+ ingestInCache(data, { cachedAt });
41397
+ const { posts } = data;
41398
+ return {
41399
+ data: LinkedObject.post(posts[0]),
41400
+ cachedAt,
41401
+ };
41402
+ };
41403
+ /* end_public_function */
40752
41404
 
40753
41405
  /* begin_public_function
40754
41406
  id: post.get
@@ -40772,7 +41424,7 @@ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.p
40772
41424
  *
40773
41425
  * @category Post Live Object
40774
41426
  */
40775
- const getPost$1 = (postId, callback) => {
41427
+ const getPost = (postId, callback) => {
40776
41428
  const responder = (snapshot) => {
40777
41429
  const { data } = snapshot;
40778
41430
  callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
@@ -40861,19 +41513,6 @@ class PostPaginationController extends PaginationController {
40861
41513
  }
40862
41514
  }
40863
41515
 
40864
- var EnumPostActions;
40865
- (function (EnumPostActions) {
40866
- EnumPostActions["OnPostCreated"] = "onPostCreated";
40867
- EnumPostActions["OnPostUpdated"] = "onPostUpdated";
40868
- EnumPostActions["OnPostDeleted"] = "onPostDeleted";
40869
- EnumPostActions["OnPostFlagged"] = "onPostFlagged";
40870
- EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
40871
- EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
40872
- EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
40873
- EnumPostActions["OnPostApproved"] = "onPostApproved";
40874
- EnumPostActions["OnPostDeclined"] = "onPostDeclined";
40875
- })(EnumPostActions || (EnumPostActions = {}));
40876
-
40877
41516
  class PostQueryStreamController extends QueryStreamController {
40878
41517
  constructor(query, cacheKey, notifyChange, preparePayload) {
40879
41518
  super(query, cacheKey);
@@ -40939,45 +41578,50 @@ class PostQueryStreamController extends QueryStreamController {
40939
41578
  }
40940
41579
  }
40941
41580
 
40942
- const getPost = async (postId) => {
40943
- const client = getActiveClient();
40944
- client.log('post/getPost', postId);
40945
- isInTombstone('post', postId);
40946
- let payload;
40947
- try {
40948
- // API-FIX: endpoint should not be /list, parameters should be querystring.
40949
- const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
40950
- payload = response.data;
40951
- }
40952
- catch (error) {
40953
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
40954
- pushToTombstone('post', postId);
40955
- }
40956
- throw error;
40957
- }
40958
- const data = prepareMembershipPayload(payload, 'communityUsers');
40959
- const cachedAt = client.cache && Date.now();
40960
- if (client.cache)
40961
- ingestInCache(data, { cachedAt });
40962
- const { posts } = data;
40963
- const result = posts.find(post => post.postId === postId);
40964
- return {
40965
- data: result,
40966
- cachedAt,
40967
- };
41581
+ const commentEventHandler = (callback, eventHandler, cacheKey, resolveId) => {
41582
+ return eventHandler(async (comment) => {
41583
+ var _a;
41584
+ const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41585
+ if (!currentCollection ||
41586
+ !currentCollection.data.includes(resolveId ? resolveId(comment.referenceId) : comment.referenceId))
41587
+ return;
41588
+ await getPost$1(comment.referenceId);
41589
+ callback(comment);
41590
+ });
40968
41591
  };
40969
- getPost.locally = (postId) => {
40970
- const client = getActiveClient();
40971
- client.log('post/getPost.locally', postId);
40972
- if (!client.cache)
40973
- return;
40974
- const cached = pullFromCache(['post', 'get', postId]);
40975
- if (!cached)
40976
- return;
40977
- return {
40978
- data: cached.data,
40979
- cachedAt: cached.cachedAt,
40980
- };
41592
+ const generateCommentSubscriptions = ({ cacheKey, resolveId, }) => {
41593
+ const eventHandlers = [
41594
+ onCommentCreated,
41595
+ onCommentDeleted,
41596
+ onCommentReactionAdded,
41597
+ onCommentReactionRemoved,
41598
+ onCommentCreatedLocal,
41599
+ onCommentDeleteLocal,
41600
+ onLocalCommentReactionAdded,
41601
+ onLocalCommentReactionRemoved,
41602
+ ];
41603
+ return eventHandlers.map(handler => ({
41604
+ fn: convertEventPayload((callback) => commentEventHandler(callback, handler, cacheKey, resolveId), 'referenceId', 'post'),
41605
+ action: EnumPostActions.OnPostUpdated,
41606
+ }));
41607
+ };
41608
+ const getPostSubscription = (cacheKey) => {
41609
+ return [
41610
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
41611
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
41612
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
41613
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
41614
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
41615
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
41616
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
41617
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
41618
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
41619
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
41620
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
41621
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
41622
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
41623
+ ...generateCommentSubscriptions({ cacheKey }),
41624
+ ];
40981
41625
  };
40982
41626
 
40983
41627
  class PostLiveCollectionController extends LiveCollectionController {
@@ -41008,47 +41652,7 @@ class PostLiveCollectionController extends LiveCollectionController {
41008
41652
  this.queryStreamController.appendToQueryStream(response, direction, refresh);
41009
41653
  }
41010
41654
  startSubscription() {
41011
- return this.queryStreamController.subscribeRTE([
41012
- { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
41013
- { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
41014
- { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
41015
- { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
41016
- { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
41017
- { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
41018
- { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
41019
- { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
41020
- { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
41021
- { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
41022
- { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
41023
- { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
41024
- { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
41025
- {
41026
- fn: convertEventPayload((callback) => {
41027
- return onCommentCreated(async (comment) => {
41028
- var _a;
41029
- const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41030
- if (!currentCollection || currentCollection.data.includes(comment.referenceId))
41031
- return;
41032
- await getPost(comment.referenceId);
41033
- callback(comment);
41034
- });
41035
- }, 'referenceId', 'post'),
41036
- action: EnumPostActions.OnPostUpdated,
41037
- },
41038
- {
41039
- fn: convertEventPayload((callback) => {
41040
- return onCommentDeleted(async (comment) => {
41041
- var _a;
41042
- const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41043
- if (!currentCollection || currentCollection.data.includes(comment.referenceId))
41044
- return;
41045
- await getPost(comment.referenceId);
41046
- callback(comment);
41047
- });
41048
- }, 'referenceId', 'post'),
41049
- action: EnumPostActions.OnPostUpdated,
41050
- },
41051
- ]);
41655
+ return this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
41052
41656
  }
41053
41657
  notifyChange({ origin, loading, error }) {
41054
41658
  var _a, _b;
@@ -41183,6 +41787,22 @@ class PinnedPostQueryStreamController extends QueryStreamController {
41183
41787
  });
41184
41788
  }
41185
41789
  }
41790
+ reactor(action) {
41791
+ return (post) => {
41792
+ var _a;
41793
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41794
+ if (!collection)
41795
+ return;
41796
+ if (action === EnumPostActions.OnPostDeleted) {
41797
+ collection.data = collection.data.filter(referenceId => referenceId !== `global#${post.postId}`);
41798
+ }
41799
+ pushToCache(this.cacheKey, collection);
41800
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
41801
+ };
41802
+ }
41803
+ subscribeRTE(createSubscriber) {
41804
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
41805
+ }
41186
41806
  }
41187
41807
 
41188
41808
  class PinnedPostLiveCollectionController extends LiveCollectionController {
@@ -41214,7 +41834,10 @@ class PinnedPostLiveCollectionController extends LiveCollectionController {
41214
41834
  }
41215
41835
  // eslint-disable-next-line class-methods-use-this
41216
41836
  startSubscription() {
41217
- return [];
41837
+ return this.queryStreamController.subscribeRTE(generateCommentSubscriptions({
41838
+ cacheKey: this.cacheKey,
41839
+ resolveId: id => `${this.query.placement}#${id}`,
41840
+ }));
41218
41841
  }
41219
41842
  notifyChange({ origin, loading, error }) {
41220
41843
  var _a, _b;
@@ -41366,6 +41989,10 @@ class GlobalPinnedPostLiveCollectionController extends LiveCollectionController
41366
41989
  fn: onPostDeleted,
41367
41990
  action: EnumPostActions.OnPostDeleted,
41368
41991
  },
41992
+ ...generateCommentSubscriptions({
41993
+ cacheKey: this.cacheKey,
41994
+ resolveId: id => `global#${id}`,
41995
+ }),
41369
41996
  ]);
41370
41997
  }
41371
41998
  notifyChange({ origin, loading, error }) {
@@ -41645,6 +42272,238 @@ const semanticSearchPosts = (params, callback, config) => {
41645
42272
  };
41646
42273
  };
41647
42274
 
42275
+ class SearchPostPaginationController extends PaginationController {
42276
+ async getRequest(queryParams, token) {
42277
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, matchingOnlyParentPost, hashtags, dataTypes, targetType = 'all' } = queryParams, params = __rest(queryParams, ["limit", "matchingOnlyParentPost", "hashtags", "dataTypes", "targetType"]);
42278
+ const baseOptions = {
42279
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
42280
+ };
42281
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
42282
+ const { data: queryResponse } = await this.http.get(`/api/v1/search/posts`, {
42283
+ params: Object.assign(Object.assign({}, params), { hashtags,
42284
+ dataTypes,
42285
+ targetType,
42286
+ /*
42287
+ * when creating post like image, file, video BE will create 2 posts
42288
+ * 1. parent post to store text with dataType=text
42289
+ * 2. child post to store dataTypes post data
42290
+ *
42291
+ * By default, BE queries only parent post
42292
+ */
42293
+ matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
42294
+ });
42295
+ return queryResponse;
42296
+ }
42297
+ }
42298
+
42299
+ class SearchPostQueryStreamController extends QueryStreamController {
42300
+ constructor(query, cacheKey, notifyChange, preparePayload) {
42301
+ super(query, cacheKey);
42302
+ this.notifyChange = notifyChange;
42303
+ this.preparePayload = preparePayload;
42304
+ }
42305
+ async saveToMainDB(response) {
42306
+ const processedPayload = await this.preparePayload(response);
42307
+ const client = getActiveClient();
42308
+ const cachedAt = client.cache && Date.now();
42309
+ if (client.cache) {
42310
+ ingestInCache(processedPayload, { cachedAt });
42311
+ }
42312
+ }
42313
+ appendToQueryStream(response, direction, refresh = false) {
42314
+ var _a, _b;
42315
+ if (refresh) {
42316
+ pushToCache(this.cacheKey, {
42317
+ data: response.posts.map(getResolver('post')),
42318
+ });
42319
+ }
42320
+ else {
42321
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42322
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
42323
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
42324
+ }
42325
+ }
42326
+ reactor(action) {
42327
+ return (post) => {
42328
+ var _a, _b;
42329
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42330
+ if (!collection)
42331
+ return;
42332
+ if (post.parentPostId && post.isDeleted) {
42333
+ const parentPost = (_b = pullFromCache([
42334
+ 'post',
42335
+ 'get',
42336
+ post.parentPostId,
42337
+ ])) === null || _b === void 0 ? void 0 : _b.data;
42338
+ if (!parentPost)
42339
+ return;
42340
+ parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
42341
+ pushToCache(['post', 'get', parentPost.postId], parentPost);
42342
+ }
42343
+ if (action === EnumPostActions.OnPostDeclined) {
42344
+ collection.data = collection.data.filter(postId => postId !== post.postId);
42345
+ }
42346
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
42347
+ collection.data = [...new Set([post.postId, ...collection.data])];
42348
+ }
42349
+ pushToCache(this.cacheKey, collection);
42350
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
42351
+ };
42352
+ }
42353
+ subscribeRTE(createSubscriber) {
42354
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
42355
+ }
42356
+ }
42357
+
42358
+ class SearchPostLiveCollectionController extends LiveCollectionController {
42359
+ constructor(query, callback) {
42360
+ const queryStreamId = hash(query);
42361
+ const cacheKey = ['posts', 'collection', queryStreamId];
42362
+ const paginationController = new SearchPostPaginationController(query);
42363
+ super(paginationController, queryStreamId, cacheKey, callback);
42364
+ this.query = query;
42365
+ this.queryStreamController = new SearchPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
42366
+ this.callback = callback.bind(this);
42367
+ this.loadPage({ initial: true });
42368
+ }
42369
+ setup() {
42370
+ var _a;
42371
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42372
+ if (!collection) {
42373
+ pushToCache(this.cacheKey, {
42374
+ data: [],
42375
+ params: {},
42376
+ });
42377
+ }
42378
+ }
42379
+ async persistModel(queryPayload) {
42380
+ await this.queryStreamController.saveToMainDB(queryPayload);
42381
+ }
42382
+ persistQueryStream({ response, direction, refresh, }) {
42383
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
42384
+ }
42385
+ startSubscription() {
42386
+ return this.queryStreamController.subscribeRTE([
42387
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
42388
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
42389
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
42390
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
42391
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
42392
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
42393
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
42394
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
42395
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
42396
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
42397
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
42398
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
42399
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
42400
+ {
42401
+ fn: convertEventPayload((callback) => {
42402
+ return onCommentCreated(async (comment) => {
42403
+ var _a;
42404
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42405
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
42406
+ return;
42407
+ await getPost$1(comment.referenceId);
42408
+ callback(comment);
42409
+ });
42410
+ }, 'referenceId', 'post'),
42411
+ action: EnumPostActions.OnPostUpdated,
42412
+ },
42413
+ {
42414
+ fn: convertEventPayload((callback) => {
42415
+ return onCommentDeleted(async (comment) => {
42416
+ var _a;
42417
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42418
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
42419
+ return;
42420
+ await getPost$1(comment.referenceId);
42421
+ callback(comment);
42422
+ });
42423
+ }, 'referenceId', 'post'),
42424
+ action: EnumPostActions.OnPostUpdated,
42425
+ },
42426
+ ]);
42427
+ }
42428
+ notifyChange({ origin, loading, error }) {
42429
+ var _a, _b;
42430
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42431
+ if (!collection)
42432
+ return;
42433
+ const data = this.applyFilter((_b = collection.data
42434
+ .map(id => pullFromCache(['post', 'get', id]))
42435
+ .filter(isNonNullable)
42436
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
42437
+ if (!this.shouldNotify(data) && origin === 'event')
42438
+ return;
42439
+ this.callback({
42440
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
42441
+ data,
42442
+ hasNextPage: !!this.paginationController.getNextToken(),
42443
+ loading,
42444
+ error,
42445
+ });
42446
+ }
42447
+ applyFilter(data) {
42448
+ var _a;
42449
+ let posts = data;
42450
+ if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
42451
+ posts = filterByPostDataTypes(posts, this.query.dataTypes);
42452
+ }
42453
+ switch (this.query.sortBy) {
42454
+ case 'firstCreated':
42455
+ posts = posts.sort(sortByFirstCreated);
42456
+ break;
42457
+ case 'lastCreated':
42458
+ default:
42459
+ posts = posts.sort(sortByLastCreated);
42460
+ break;
42461
+ }
42462
+ return posts;
42463
+ }
42464
+ }
42465
+
42466
+ /* begin_public_function
42467
+ id: post.query
42468
+ */
42469
+ /**
42470
+ * ```js
42471
+ * import { PostRepository } from '@amityco/ts-sdk'
42472
+ *
42473
+ * let posts = []
42474
+ * const unsub = PostRepository.searchPostsByHashtag({
42475
+ * hashtags: ['amity'],
42476
+ * limit: 10,
42477
+ * }, response => merge(posts, response.data))
42478
+ * ```
42479
+ *
42480
+ * Observe all mutations on a list of {@link Amity.Post} for a given target object
42481
+ *
42482
+ * @param params.hashtags the hashtags to search for
42483
+ * @param callback the function to call when new data are available
42484
+ * @param config
42485
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
42486
+ *
42487
+ * @category Posts Live Collection
42488
+ */
42489
+ const searchPostsByHashtag = (params, callback, config) => {
42490
+ const { log, cache } = getActiveClient();
42491
+ if (!cache) {
42492
+ console.log(ENABLE_CACHE_MESSAGE);
42493
+ }
42494
+ const timestamp = Date.now();
42495
+ log(`searchPostsByHashtag(tmpid: ${timestamp}) > listen`);
42496
+ const postsLiveCollection = new SearchPostLiveCollectionController(params, callback);
42497
+ const disposers = postsLiveCollection.startSubscription();
42498
+ const cacheKey = postsLiveCollection.getCacheKey();
42499
+ disposers.push(() => dropFromCache(cacheKey));
42500
+ return () => {
42501
+ log(`searchPostsByHashtag(tmpid: ${timestamp}) > dispose`);
42502
+ disposers.forEach(fn => fn());
42503
+ };
42504
+ };
42505
+ /* end_public_function */
42506
+
41648
42507
  var index$8 = /*#__PURE__*/Object.freeze({
41649
42508
  __proto__: null,
41650
42509
  getPostByIds: getPostByIds,
@@ -41668,11 +42527,12 @@ var index$8 = /*#__PURE__*/Object.freeze({
41668
42527
  onPostUnflagged: onPostUnflagged,
41669
42528
  onPostReactionAdded: onPostReactionAdded,
41670
42529
  onPostReactionRemoved: onPostReactionRemoved,
41671
- getPost: getPost$1,
42530
+ getPost: getPost,
41672
42531
  getPosts: getPosts,
41673
42532
  getPinnedPosts: getPinnedPosts,
41674
42533
  getGlobalPinnedPosts: getGlobalPinnedPosts,
41675
- semanticSearchPosts: semanticSearchPosts
42534
+ semanticSearchPosts: semanticSearchPosts,
42535
+ searchPostsByHashtag: searchPostsByHashtag
41676
42536
  });
41677
42537
 
41678
42538
  /* begin_public_function
@@ -42277,8 +43137,8 @@ var index$7 = /*#__PURE__*/Object.freeze({
42277
43137
  * const created = await createPoll({
42278
43138
  * question: 'question',
42279
43139
  * answers: [
42280
- * { dataType: 'text', data: 'answer1' },
42281
- * { dataType: 'text', data: 'answer2' },
43140
+ * { dataType: 'text', data: 'answer1', fileId: 'fileId1' },
43141
+ * { dataType: 'text', data: 'answer2', fileId: 'fileId2' },
42282
43142
  * ],
42283
43143
  * closedIn: 1649136484
42284
43144
  * }))
@@ -44866,4 +45726,4 @@ var index = /*#__PURE__*/Object.freeze({
44866
45726
  getReactions: getReactions
44867
45727
  });
44868
45728
 
44869
- export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$9 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$c as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$a as FeedRepository, FileAccessTypeEnum, index$l as FileRepository, FileType, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$j as MessageRepository, index$6 as PollRepository, PostContentType, index$8 as PostRepository, index$k as ReactionRepository, index$4 as StoryRepository, index$7 as StreamRepository, index$i as SubChannelRepository, SubscriptionLevels, index$m as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$2 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
45729
+ export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$a as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$c as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, FeedDataTypeEnum, index$9 as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$l as FileRepository, FileType, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$j as MessageRepository, index$6 as PollRepository, PostContentType, index$8 as PostRepository, index$k as ReactionRepository, index$4 as StoryRepository, index$7 as StreamRepository, index$i as SubChannelRepository, SubscriptionLevels, index$m as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$2 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };