@amityco/ts-sdk-react-native 7.8.0 → 7.8.1

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 (324) hide show
  1. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts +4 -0
  2. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts.map +1 -1
  3. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/client.js.map +1 -1
  4. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/community.d.ts +2 -1
  5. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/community.d.ts.map +1 -1
  6. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/community.js.map +1 -1
  7. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/content.d.ts +1 -0
  8. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/content.d.ts.map +1 -1
  9. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/content.js.map +1 -1
  10. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts +36 -0
  11. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts.map +1 -1
  12. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/feed.js +22 -1
  13. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/feed.js.map +1 -1
  14. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.d.ts +11 -0
  15. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.d.ts.map +1 -0
  16. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.js +2 -0
  17. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.js.map +1 -0
  18. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/notification.d.ts +2 -1
  19. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/notification.d.ts.map +1 -1
  20. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/notification.js.map +1 -1
  21. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/pinnedPost.d.ts +1 -4
  22. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/pinnedPost.d.ts.map +1 -1
  23. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/pinnedPost.js.map +1 -1
  24. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/poll.d.ts +3 -1
  25. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/poll.d.ts.map +1 -1
  26. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/poll.js.map +1 -1
  27. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts +14 -1
  28. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts.map +1 -1
  29. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/post.js.map +1 -1
  30. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/index.d.ts +2 -0
  31. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/index.d.ts.map +1 -1
  32. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/index.js +2 -0
  33. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/index.js.map +1 -1
  34. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.d.ts +16 -0
  35. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.d.ts.map +1 -0
  36. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.js +21 -0
  37. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.js.map +1 -0
  38. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/index.d.ts +2 -0
  39. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/index.d.ts.map +1 -1
  40. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/index.js +2 -0
  41. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/index.js.map +1 -1
  42. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/commentRepository/api/deleteComment.js +6 -6
  43. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/commentRepository/api/deleteComment.js.map +1 -1
  44. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
  45. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.js +3 -2
  46. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.js.map +1 -1
  47. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/core/model/index.d.ts.map +1 -1
  48. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/core/model/index.js +2 -1
  49. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/core/model/index.js.map +1 -1
  50. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/api/index.d.ts +0 -1
  51. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/api/index.d.ts.map +1 -1
  52. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/api/index.js +0 -1
  53. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/api/index.js.map +1 -1
  54. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.d.ts +3 -0
  55. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
  56. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.js +3 -0
  57. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.js.map +1 -1
  58. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts +2 -1
  59. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts.map +1 -1
  60. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/index.js +2 -1
  61. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/index.js.map +1 -1
  62. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts +13 -0
  63. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts.map +1 -0
  64. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.js +60 -0
  65. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.js.map +1 -0
  66. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts +5 -0
  67. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts.map +1 -0
  68. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.js +13 -0
  69. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.js.map +1 -0
  70. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts +15 -0
  71. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts.map +1 -0
  72. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.js +66 -0
  73. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.js.map +1 -0
  74. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts +22 -0
  75. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts.map +1 -0
  76. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.js +45 -0
  77. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.js.map +1 -0
  78. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts +13 -0
  79. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts.map +1 -0
  80. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.js +60 -0
  81. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.js.map +1 -0
  82. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts +5 -0
  83. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts.map +1 -0
  84. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.js +13 -0
  85. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.js.map +1 -0
  86. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts +15 -0
  87. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts.map +1 -0
  88. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.js +66 -0
  89. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.js.map +1 -0
  90. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.d.ts +22 -0
  91. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.d.ts.map +1 -0
  92. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.js +45 -0
  93. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.js.map +1 -0
  94. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts +13 -0
  95. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +1 -0
  96. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.js +108 -0
  97. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.js.map +1 -0
  98. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +5 -0
  99. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +1 -0
  100. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js +15 -0
  101. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js.map +1 -0
  102. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts +15 -0
  103. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +1 -0
  104. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.js +78 -0
  105. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.js.map +1 -0
  106. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts +23 -0
  107. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts.map +1 -0
  108. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js +46 -0
  109. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js.map +1 -0
  110. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts +4 -0
  111. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts.map +1 -0
  112. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js +4 -0
  113. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js.map +1 -0
  114. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.d.ts +6 -0
  115. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.d.ts.map +1 -0
  116. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.js +60 -0
  117. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.js.map +1 -0
  118. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/pollRepository/api/createPoll.d.ts +3 -3
  119. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/pollRepository/api/createPoll.d.ts.map +1 -1
  120. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/pollRepository/api/createPoll.js +2 -2
  121. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/pollRepository/api/createPoll.js.map +1 -1
  122. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/api/createPost.d.ts +1 -1
  123. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/api/createPost.js.map +1 -1
  124. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/api/editPost.d.ts +1 -1
  125. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/api/editPost.js.map +1 -1
  126. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/api/queryPosts.js +2 -2
  127. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/api/queryPosts.js.map +1 -1
  128. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/events/utils.d.ts.map +1 -1
  129. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/events/utils.js +26 -1
  130. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/events/utils.js.map +1 -1
  131. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts.map +1 -1
  132. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.js +5 -0
  133. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.js.map +1 -1
  134. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts.map +1 -1
  135. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.js +5 -1
  136. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.js.map +1 -1
  137. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts +6 -0
  138. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
  139. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.js +17 -0
  140. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.js.map +1 -1
  141. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
  142. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostLiveCollectionController.js +2 -50
  143. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostLiveCollectionController.js.map +1 -1
  144. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts +14 -0
  145. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
  146. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js +126 -0
  147. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js.map +1 -0
  148. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
  149. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
  150. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js +27 -0
  151. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js.map +1 -0
  152. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts +15 -0
  153. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
  154. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js +65 -0
  155. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js.map +1 -0
  156. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts +1 -0
  157. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts.map +1 -1
  158. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js +1 -0
  159. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js.map +1 -1
  160. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
  161. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
  162. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js +45 -0
  163. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js.map +1 -0
  164. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.d.ts +13 -0
  165. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.d.ts.map +1 -0
  166. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.js +61 -0
  167. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.js.map +1 -0
  168. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  169. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/reactionRepository/api/addReaction.js +1 -1
  170. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/reactionRepository/api/addReaction.js.map +1 -1
  171. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  172. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/reactionRepository/api/removeReaction.js +1 -1
  173. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/reactionRepository/api/removeReaction.js.map +1 -1
  174. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  175. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/utils/linkedObject/postLinkedObject.js +9 -4
  176. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/utils/linkedObject/postLinkedObject.js.map +1 -1
  177. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
  178. package/dist/@types/domains/client.d.ts +4 -0
  179. package/dist/@types/domains/client.d.ts.map +1 -1
  180. package/dist/@types/domains/community.d.ts +2 -1
  181. package/dist/@types/domains/community.d.ts.map +1 -1
  182. package/dist/@types/domains/content.d.ts +1 -0
  183. package/dist/@types/domains/content.d.ts.map +1 -1
  184. package/dist/@types/domains/feed.d.ts +36 -0
  185. package/dist/@types/domains/feed.d.ts.map +1 -1
  186. package/dist/@types/domains/hashtag.d.ts +11 -0
  187. package/dist/@types/domains/hashtag.d.ts.map +1 -0
  188. package/dist/@types/domains/notification.d.ts +2 -1
  189. package/dist/@types/domains/notification.d.ts.map +1 -1
  190. package/dist/@types/domains/pinnedPost.d.ts +1 -4
  191. package/dist/@types/domains/pinnedPost.d.ts.map +1 -1
  192. package/dist/@types/domains/poll.d.ts +3 -1
  193. package/dist/@types/domains/poll.d.ts.map +1 -1
  194. package/dist/@types/domains/post.d.ts +14 -1
  195. package/dist/@types/domains/post.d.ts.map +1 -1
  196. package/dist/@types/index.d.ts +2 -0
  197. package/dist/@types/index.d.ts.map +1 -1
  198. package/dist/client/api/getShareableLinkConfiguration.d.ts +16 -0
  199. package/dist/client/api/getShareableLinkConfiguration.d.ts.map +1 -0
  200. package/dist/client/api/index.d.ts +2 -0
  201. package/dist/client/api/index.d.ts.map +1 -1
  202. package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
  203. package/dist/core/model/index.d.ts.map +1 -1
  204. package/dist/feedRepository/api/index.d.ts +0 -1
  205. package/dist/feedRepository/api/index.d.ts.map +1 -1
  206. package/dist/feedRepository/api/queryGlobalFeed.d.ts +3 -0
  207. package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
  208. package/dist/feedRepository/index.d.ts +2 -1
  209. package/dist/feedRepository/index.d.ts.map +1 -1
  210. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts +13 -0
  211. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts.map +1 -0
  212. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts +5 -0
  213. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts.map +1 -0
  214. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts +15 -0
  215. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts.map +1 -0
  216. package/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts +22 -0
  217. package/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts.map +1 -0
  218. package/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts +13 -0
  219. package/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts.map +1 -0
  220. package/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts +5 -0
  221. package/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts.map +1 -0
  222. package/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts +15 -0
  223. package/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts.map +1 -0
  224. package/dist/feedRepository/observers/getGlobalFeed.d.ts +22 -0
  225. package/dist/feedRepository/observers/getGlobalFeed.d.ts.map +1 -0
  226. package/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts +13 -0
  227. package/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +1 -0
  228. package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +5 -0
  229. package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +1 -0
  230. package/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts +15 -0
  231. package/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +1 -0
  232. package/dist/feedRepository/observers/getUserFeed.d.ts +23 -0
  233. package/dist/feedRepository/observers/getUserFeed.d.ts.map +1 -0
  234. package/dist/feedRepository/observers/index.d.ts +4 -0
  235. package/dist/feedRepository/observers/index.d.ts.map +1 -0
  236. package/dist/feedRepository/observers/utils.d.ts +6 -0
  237. package/dist/feedRepository/observers/utils.d.ts.map +1 -0
  238. package/dist/index.cjs.js +2130 -1277
  239. package/dist/index.esm.js +2037 -1184
  240. package/dist/index.umd.js +3 -3
  241. package/dist/pollRepository/api/createPoll.d.ts +3 -3
  242. package/dist/pollRepository/api/createPoll.d.ts.map +1 -1
  243. package/dist/postRepository/api/createPost.d.ts +1 -1
  244. package/dist/postRepository/api/editPost.d.ts +1 -1
  245. package/dist/postRepository/events/utils.d.ts.map +1 -1
  246. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts.map +1 -1
  247. package/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts.map +1 -1
  248. package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts +6 -0
  249. package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
  250. package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
  251. package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts +14 -0
  252. package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
  253. package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
  254. package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
  255. package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts +15 -0
  256. package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
  257. package/dist/postRepository/observers/index.d.ts +1 -0
  258. package/dist/postRepository/observers/index.d.ts.map +1 -1
  259. package/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
  260. package/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
  261. package/dist/postRepository/observers/utils.d.ts +13 -0
  262. package/dist/postRepository/observers/utils.d.ts.map +1 -0
  263. package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  264. package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  265. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  266. package/package.json +1 -1
  267. package/src/@types/domains/client.ts +5 -0
  268. package/src/@types/domains/community.ts +1 -0
  269. package/src/@types/domains/content.ts +1 -0
  270. package/src/@types/domains/feed.ts +60 -0
  271. package/src/@types/domains/hashtag.ts +11 -0
  272. package/src/@types/domains/notification.ts +1 -0
  273. package/src/@types/domains/pinnedPost.ts +1 -4
  274. package/src/@types/domains/poll.ts +3 -1
  275. package/src/@types/domains/post.ts +18 -1
  276. package/src/@types/index.ts +2 -0
  277. package/src/client/api/getShareableLinkConfiguration.ts +26 -0
  278. package/src/client/api/index.ts +4 -0
  279. package/src/commentRepository/api/deleteComment.ts +6 -6
  280. package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +3 -3
  281. package/src/core/model/index.ts +2 -1
  282. package/src/feedRepository/api/index.ts +0 -1
  283. package/src/feedRepository/api/queryGlobalFeed.ts +3 -0
  284. package/src/feedRepository/index.ts +2 -1
  285. package/src/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.ts +95 -0
  286. package/src/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.ts +25 -0
  287. package/src/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.ts +101 -0
  288. package/src/feedRepository/observers/getCustomRankingGlobalFeed.ts +56 -0
  289. package/src/feedRepository/observers/getGlobalFeed/LiveCollectionController.ts +91 -0
  290. package/src/feedRepository/observers/getGlobalFeed/PaginationController.ts +23 -0
  291. package/src/feedRepository/observers/getGlobalFeed/QueryStreamController.ts +99 -0
  292. package/src/feedRepository/observers/getGlobalFeed.ts +56 -0
  293. package/src/feedRepository/observers/getUserFeed/LiveCollectionController.ts +162 -0
  294. package/src/feedRepository/observers/getUserFeed/PaginationController.ts +37 -0
  295. package/src/feedRepository/observers/getUserFeed/QueryStreamController.ts +119 -0
  296. package/src/feedRepository/observers/getUserFeed.ts +56 -0
  297. package/src/feedRepository/observers/index.ts +3 -0
  298. package/src/feedRepository/observers/utils.ts +85 -0
  299. package/src/pollRepository/api/createPoll.ts +3 -3
  300. package/src/postRepository/api/createPost.ts +1 -1
  301. package/src/postRepository/api/editPost.ts +1 -1
  302. package/src/postRepository/api/queryPosts.ts +2 -2
  303. package/src/postRepository/events/utils.ts +35 -1
  304. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.ts +5 -0
  305. package/src/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.ts +7 -1
  306. package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +27 -0
  307. package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +2 -74
  308. package/src/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.ts +183 -0
  309. package/src/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.ts +49 -0
  310. package/src/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.ts +99 -0
  311. package/src/postRepository/observers/index.ts +1 -0
  312. package/src/postRepository/observers/searchPostsByHashtag.ts +56 -0
  313. package/src/postRepository/observers/utils.ts +97 -0
  314. package/src/reactionRepository/api/addReaction.ts +1 -0
  315. package/src/reactionRepository/api/removeReaction.ts +1 -0
  316. package/src/utils/linkedObject/postLinkedObject.ts +3 -3
  317. package/tsconfig.tsbuildinfo +1 -1
  318. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +0 -37
  319. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +0 -1
  320. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.js +0 -83
  321. package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.js.map +0 -1
  322. package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +0 -37
  323. package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +0 -1
  324. package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +0 -115
package/dist/index.cjs.js CHANGED
@@ -174,10 +174,33 @@ exports.JoinResultStatusEnum = void 0;
174
174
  JoinResultStatusEnum["Pending"] = "pending";
175
175
  })(exports.JoinResultStatusEnum || (exports.JoinResultStatusEnum = {}));
176
176
 
177
+ exports.FeedDataTypeEnum = void 0;
178
+ (function (FeedDataTypeEnum) {
179
+ FeedDataTypeEnum["Text"] = "text";
180
+ FeedDataTypeEnum["Video"] = "video";
181
+ FeedDataTypeEnum["Image"] = "image";
182
+ FeedDataTypeEnum["File"] = "file";
183
+ FeedDataTypeEnum["LiveStream"] = "liveStream";
184
+ FeedDataTypeEnum["Clip"] = "clip";
185
+ FeedDataTypeEnum["Poll"] = "poll";
186
+ })(exports.FeedDataTypeEnum || (exports.FeedDataTypeEnum = {}));
187
+ exports.FeedSortByEnum = void 0;
188
+ (function (FeedSortByEnum) {
189
+ FeedSortByEnum["LastCreated"] = "lastCreated";
190
+ FeedSortByEnum["FirstCreated"] = "firstCreated";
191
+ FeedSortByEnum["LastUpdated"] = "lastUpdated";
192
+ FeedSortByEnum["FirstUpdated"] = "firstUpdated";
193
+ })(exports.FeedSortByEnum || (exports.FeedSortByEnum = {}));
194
+ exports.FeedSourceEnum = void 0;
195
+ (function (FeedSourceEnum) {
196
+ FeedSourceEnum["Community"] = "community";
197
+ FeedSourceEnum["User"] = "user";
198
+ })(exports.FeedSourceEnum || (exports.FeedSourceEnum = {}));
199
+
177
200
  function getVersion() {
178
201
  try {
179
- // the string ''v7.8.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
180
- return 'v7.8.0-cjs';
202
+ // the string ''v7.8.1-cjs'' should be replaced by actual value by @rollup/plugin-replace
203
+ return 'v7.8.1-cjs';
181
204
  }
182
205
  catch (error) {
183
206
  return '__dev__';
@@ -679,7 +702,8 @@ const PAYLOAD2MODEL = {
679
702
  };
680
703
  /** hidden */
681
704
  const isOutdated = (prevData, nextData) => {
682
- if ('updatedAt' in nextData && 'updatedAt' in nextData) {
705
+ // Check if the new value is outdated.
706
+ if ('updatedAt' in nextData && 'updatedAt' in prevData) {
683
707
  return new Date(nextData.updatedAt) < new Date(prevData.updatedAt);
684
708
  }
685
709
  return false;
@@ -9945,6 +9969,26 @@ const fetchLinkPreview = async (url) => {
9945
9969
  return data;
9946
9970
  };
9947
9971
 
9972
+ /**
9973
+ * ```js
9974
+ * import Client from '@amityco/ts-sdk'
9975
+ * const shareableLinkConfiguration = await Client.getShareableLinkConfiguration()
9976
+ * const postLinkPattern = shareableLinkConfiguration.post
9977
+ * ```
9978
+ *
9979
+ * Fetches a {@link Amity.ShareableLinkConfiguration} object
9980
+ *
9981
+ * @returns A Promise of {@link Amity.ShareableLinkConfiguration} object
9982
+ *
9983
+ * @category Client API
9984
+ * @async
9985
+ */
9986
+ const getShareableLinkConfiguration = async () => {
9987
+ const client = getActiveClient();
9988
+ const { data } = await client.http.get(`/api/v3/network-settings/shareable-deep-links`);
9989
+ return data;
9990
+ };
9991
+
9948
9992
  /**
9949
9993
  * ```js
9950
9994
  * import { onChannelMarkerFetched } from '@amityco/ts-sdk-react-native'
@@ -10317,6 +10361,8 @@ var index$o = /*#__PURE__*/Object.freeze({
10317
10361
  unregisterPushNotification: unregisterPushNotification,
10318
10362
  onRTEConnectionStateChange: onRTEConnectionStateChange,
10319
10363
  fetchLinkPreview: fetchLinkPreview,
10364
+ getSocialSettings: getSocialSettings,
10365
+ getShareableLinkConfiguration: getShareableLinkConfiguration,
10320
10366
  onConnectionError: onConnectionError,
10321
10367
  onClientDisconnected: onClientDisconnected,
10322
10368
  onClientBanned: onClientBanned,
@@ -12020,15 +12066,18 @@ function isAmityClipPost(post) {
12020
12066
  }
12021
12067
 
12022
12068
  const postLinkedObject = (post) => {
12023
- return Object.assign(Object.assign({}, post), { childrenPosts: post.children
12069
+ return shallowClone(post, {
12070
+ childrenPosts: post.children
12024
12071
  .map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
12025
12072
  .filter(isNonNullable)
12026
- .map(postLinkedObject), analytics: {
12073
+ .map(postLinkedObject),
12074
+ analytics: {
12027
12075
  markAsViewed: () => {
12028
12076
  const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
12029
12077
  analyticsEngineInstance.markPostAsViewed(post.postId);
12030
12078
  },
12031
- }, get latestComments() {
12079
+ },
12080
+ get latestComments() {
12032
12081
  if (!post.comments)
12033
12082
  return [];
12034
12083
  return (post.comments
@@ -12102,7 +12151,8 @@ const postLinkedObject = (post) => {
12102
12151
  return isAmityClipPost(post)
12103
12152
  ? (_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
12104
12153
  : undefined;
12105
- } });
12154
+ },
12155
+ });
12106
12156
  };
12107
12157
 
12108
12158
  const getCachedMarker = (message) => {
@@ -15097,7 +15147,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
15097
15147
  ]);
15098
15148
  if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
15099
15149
  return true;
15100
- 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 }) });
15150
+ 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() });
15101
15151
  if (referenceType === 'comment') {
15102
15152
  fireEvent('local.comment.addReaction', {
15103
15153
  comment: updatedModel,
@@ -15220,7 +15270,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
15220
15270
  ]);
15221
15271
  if (!model)
15222
15272
  return true;
15223
- 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) }) });
15273
+ 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() });
15224
15274
  if (referenceType === 'comment') {
15225
15275
  fireEvent('local.comment.removeReaction', {
15226
15276
  comment: updatedModel,
@@ -15334,6 +15384,26 @@ const prepareSemanticSearchPostPayload = (_a) => {
15334
15384
  return Object.assign(Object.assign({}, processedPostPayload), { polls });
15335
15385
  };
15336
15386
 
15387
+ const processDeleteChildPost = (payload) => {
15388
+ var _a;
15389
+ const post = payload.posts[0];
15390
+ if (!post.parentId)
15391
+ return;
15392
+ const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
15393
+ if (!parentPost)
15394
+ return;
15395
+ pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: parentPost.children.filter(childId => childId !== post.postId) }));
15396
+ };
15397
+ const processCreateChildPost = (payload) => {
15398
+ var _a;
15399
+ const post = payload.posts[0];
15400
+ if (!post.parentId)
15401
+ return;
15402
+ const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
15403
+ if (!parentPost)
15404
+ return;
15405
+ pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: [...new Set([post.postId, ...parentPost.children])] }));
15406
+ };
15337
15407
  const createPostEventSubscriber = (event, callback) => {
15338
15408
  const client = getActiveClient();
15339
15409
  const filter = (payload) => {
@@ -15358,6 +15428,7 @@ const createPostEventSubscriber = (event, callback) => {
15358
15428
  }
15359
15429
  if (event === 'post.deleted') {
15360
15430
  const { postId, postedUserId } = payload.posts[0];
15431
+ processDeleteChildPost(payload);
15361
15432
  try {
15362
15433
  isInTombstone('post', postId);
15363
15434
  }
@@ -15384,6 +15455,8 @@ const createPostEventSubscriber = (event, callback) => {
15384
15455
  }
15385
15456
  queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
15386
15457
  }
15458
+ if (event === 'post.created')
15459
+ processCreateChildPost(payload);
15387
15460
  callback(post.data);
15388
15461
  }
15389
15462
  };
@@ -15410,6 +15483,8 @@ const createLocalPostEventSubscriber = (event, callback) => {
15410
15483
  });
15411
15484
  }
15412
15485
  const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
15486
+ if (event === 'local.post.deleted')
15487
+ processDeleteChildPost(payload);
15413
15488
  callback(post.data);
15414
15489
  }
15415
15490
  };
@@ -21941,10 +22016,10 @@ class CommunityLiveCollectionController extends LiveCollectionController {
21941
22016
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
21942
22017
  if (!collection)
21943
22018
  return;
21944
- const data = this.applyFilter((_b = collection.data
22019
+ const data = (_b = collection.data
21945
22020
  .map(id => pullFromCache(['community', 'get', id]))
21946
22021
  .filter(isNonNullable)
21947
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
22022
+ .map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
21948
22023
  if (!this.shouldNotify(data) && origin === 'event')
21949
22024
  return;
21950
22025
  this.callback({
@@ -23185,6 +23260,9 @@ var index$b = /*#__PURE__*/Object.freeze({
23185
23260
  id: feed.query.global_feed
23186
23261
  */
23187
23262
  /**
23263
+ *
23264
+ * @deprecated This function will to be deprecated. Please use getGlobalFeed instead.
23265
+ *
23188
23266
  * ```js
23189
23267
  * import { queryGlobalFeed } from '@amityco/ts-sdk-react-native'
23190
23268
  * const posts = await queryGlobalFeed()
@@ -23267,1564 +23345,2131 @@ queryGlobalFeed.locally = (query) => {
23267
23345
  : undefined;
23268
23346
  };
23269
23347
 
23270
- /* begin_public_function
23271
- id: feed.query.custom_ranking_feed
23272
- */
23273
- /**
23274
- * ```js
23275
- * import { FeedRepository } from '@amityco/ts-sdk-react-native'
23276
- * const posts = await FeedRepository.getCustomRankingGlobalFeed()
23277
- * ```
23278
- *
23279
- * Queries a paginable list of {@link Amity.Post} objects
23280
- *
23281
- * @param query The query parameters
23282
- * @returns A page of {@link Amity.Post} objects
23283
- *
23284
- * @category Feed API
23285
- * @async
23286
- * */
23287
- const getCustomRankingGlobalFeed = async (query) => {
23288
- const client = getActiveClient();
23289
- client.log('feed/getCustomRankingGlobalFeed', query);
23290
- const _a = query !== null && query !== void 0 ? query : {}, { queryToken, limit } = _a, params = __rest(_a, ["queryToken", "limit"]);
23291
- const options = (() => {
23292
- if (queryToken)
23293
- return { token: queryToken };
23294
- return undefined;
23295
- })();
23296
- const { data: queryPayload } = await client.http.get(`/api/v5/me/global-feeds`, {
23297
- params: Object.assign(Object.assign({}, params), { limit: !queryToken ? limit : undefined, options }),
23298
- });
23299
- const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
23300
- const data = prepareMembershipPayload(payload, 'communityUsers');
23301
- const { posts } = data;
23302
- const cachedAt = client.cache && Date.now();
23303
- if (client.cache) {
23304
- ingestInCache(data);
23305
- const cacheKey = ['customGlobalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
23306
- pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
23348
+ class CustomRankingGlobalFeedPaginationController extends PaginationController {
23349
+ async getRequest(queryParams, token) {
23350
+ const { limit } = queryParams, params = __rest(queryParams, ["limit"]);
23351
+ const options = token ? { token } : { limit };
23352
+ const { data: queryResponse } = await this.http.get(`/api/v5/me/global-feeds`, {
23353
+ params: Object.assign(Object.assign({}, params), { options }),
23354
+ });
23355
+ return queryResponse;
23307
23356
  }
23308
- return { data: posts.map(LinkedObject.post), cachedAt, paging };
23309
- };
23310
- /* end_public_function */
23311
- /**
23312
- * ```js
23313
- * import { FeedRepository } from '@amityco/ts-sdk-react-native'
23314
- * const posts = await FeedRepository.getCustomRankingGlobalFeed.locally()
23315
- * ```
23316
- *
23317
- * Queries a paginable list of {@link Amity.Post} objects from cache
23318
- *
23319
- * @param query The query parameters
23320
- * @returns A page of {@link Amity.Post} objects
23321
- *
23322
- * @category Feed API
23323
- * @async
23324
- * */
23325
- getCustomRankingGlobalFeed.locally = (query) => {
23326
- var _a, _b;
23327
- const client = getActiveClient();
23328
- client.log('post/getCustomRankingGlobalFeed.locally', query);
23329
- if (!client.cache)
23330
- return;
23331
- const params = __rest(query !== null && query !== void 0 ? query : {}, []);
23332
- const queryKey = ['customGlobalFeed', 'query', Object.assign({}, params)];
23333
- const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
23334
- if (!(data === null || data === void 0 ? void 0 : data.posts.length))
23335
- return;
23336
- const posts = data.posts
23337
- .map(postId => pullFromCache(['post', 'get', postId]))
23338
- .filter(Boolean)
23339
- .map(({ data }) => data);
23340
- const { paging } = data;
23341
- return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
23342
- ? { data: posts.map(LinkedObject.post), cachedAt, paging }
23343
- : undefined;
23344
- };
23357
+ }
23345
23358
 
23346
- var index$a = /*#__PURE__*/Object.freeze({
23347
- __proto__: null,
23348
- queryGlobalFeed: queryGlobalFeed,
23349
- getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
23350
- });
23359
+ var EnumPostActions;
23360
+ (function (EnumPostActions) {
23361
+ EnumPostActions["OnPostCreated"] = "onPostCreated";
23362
+ EnumPostActions["OnPostUpdated"] = "onPostUpdated";
23363
+ EnumPostActions["OnPostDeleted"] = "onPostDeleted";
23364
+ EnumPostActions["OnPostFlagged"] = "onPostFlagged";
23365
+ EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
23366
+ EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
23367
+ EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
23368
+ EnumPostActions["OnPostApproved"] = "onPostApproved";
23369
+ EnumPostActions["OnPostDeclined"] = "onPostDeclined";
23370
+ })(EnumPostActions || (EnumPostActions = {}));
23371
+
23372
+ class CustomRankingGlobalFeedQueryStreamController extends QueryStreamController {
23373
+ constructor(query, cacheKey, notifyChange, preparePayload) {
23374
+ super(query, cacheKey);
23375
+ this.notifyChange = notifyChange;
23376
+ this.preparePayload = preparePayload;
23377
+ }
23378
+ async saveToMainDB(response) {
23379
+ const processedPayload = await this.preparePayload(response);
23380
+ const client = getActiveClient();
23381
+ const cachedAt = client.cache && Date.now();
23382
+ if (client.cache) {
23383
+ ingestInCache(processedPayload, { cachedAt });
23384
+ }
23385
+ }
23386
+ appendToQueryStream(response, direction, refresh = false) {
23387
+ var _a, _b;
23388
+ if (refresh) {
23389
+ pushToCache(this.cacheKey, {
23390
+ data: response.posts.map(getResolver('post')),
23391
+ });
23392
+ }
23393
+ else {
23394
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23395
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
23396
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
23397
+ }
23398
+ }
23399
+ reactor(action) {
23400
+ return (post) => {
23401
+ var _a;
23402
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23403
+ if (!collection)
23404
+ return;
23405
+ if (post.parentPostId && !collection.data.includes(post.parentPostId))
23406
+ return;
23407
+ // Delete Action
23408
+ if (action === EnumPostActions.OnPostDeleted) {
23409
+ // Parent Post - Remove from collection
23410
+ collection.data = collection.data.filter(postId => postId !== post.postId);
23411
+ }
23412
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
23413
+ // If the query has dataTypes array with value, check if post.dataType is include in the array
23414
+ if (this.query.dataTypes && this.query.dataTypes.length > 0) {
23415
+ if (!this.query.dataTypes.includes(post.dataType))
23416
+ return;
23417
+ }
23418
+ collection.data = [...new Set([post.postId, ...collection.data])];
23419
+ }
23420
+ if (action === EnumPostActions.OnPostDeclined) {
23421
+ collection.data = collection.data.filter(postId => postId !== post.postId);
23422
+ }
23423
+ pushToCache(this.cacheKey, collection);
23424
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
23425
+ };
23426
+ }
23427
+ subscribeRTE(createSubscriber) {
23428
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
23429
+ }
23430
+ }
23351
23431
 
23352
23432
  /* begin_public_function
23353
- id: post.get_by_ids
23433
+ id: comment.get_by_ids
23354
23434
  */
23355
23435
  /**
23356
23436
  * ```js
23357
- * import { getPostByIds } from '@amityco/ts-sdk-react-native'
23358
- * const { data: posts } = await getPostByIds(['foo', 'bar'])
23437
+ * import { CommentRepository } from '@amityco/ts-sdk-react-native'
23438
+ * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
23359
23439
  * ```
23360
23440
  *
23361
- * Fetches a collection of {@link Amity.Post} objects
23441
+ * Fetches a collection of {@link Amity.Comment} objects
23362
23442
  *
23363
- * @param postIds the IDs of the {@link Amity.Post} to fetch
23364
- * @returns the associated collection of {@link Amity.Post} objects
23443
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
23444
+ * @returns the associated collection of {@link Amity.Comment} objects
23365
23445
  *
23366
- * @category Post API
23446
+ * @category Comment API
23367
23447
  * @async
23368
23448
  */
23369
- const getPostByIds = async (postIds) => {
23449
+ const getCommentByIds = async (commentIds) => {
23370
23450
  const client = getActiveClient();
23371
- client.log('post/getPostByIds', postIds);
23372
- const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
23373
- let payload;
23451
+ client.log('comment/getCommentByIds', commentIds);
23452
+ const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
23453
+ let data;
23374
23454
  try {
23375
23455
  // API-FIX: endpoint should not be /list, parameters should be querystring.
23376
- const response = await client.http.get(`/api/v3/posts/list`, {
23377
- params: { postIds: encodedPostIds },
23456
+ const response = await client.http.get(`/api/v3/comments/list`, {
23457
+ params: { commentIds: encodedCommentIds },
23378
23458
  });
23379
- payload = response.data;
23459
+ data = response.data;
23380
23460
  }
23381
23461
  catch (error) {
23382
- postIds.forEach(postId => {
23462
+ commentIds.forEach(commentId => {
23383
23463
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23384
- pushToTombstone('post', postId);
23464
+ pushToTombstone('comment', commentId);
23385
23465
  }
23386
23466
  });
23387
23467
  throw error;
23388
23468
  }
23389
- const data = prepareMembershipPayload(payload, 'communityUsers');
23390
23469
  const cachedAt = client.cache && Date.now();
23391
23470
  if (client.cache)
23392
23471
  ingestInCache(data, { cachedAt });
23393
23472
  return {
23394
- data: data.posts.map(LinkedObject.post),
23473
+ data: data.comments.map(comment => LinkedObject.comment(comment)),
23395
23474
  cachedAt,
23396
23475
  };
23397
23476
  };
23398
23477
  /* end_public_function */
23399
23478
  /**
23400
23479
  * ```js
23401
- * import { getPostByIds } from '@amityco/ts-sdk-react-native'
23402
- * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
23480
+ * import { getCommentByIds } from '@amityco/ts-sdk-react-native'
23481
+ * const comments = getCommentByIds.locally(['foo', 'bar'])
23403
23482
  * ```
23404
23483
  *
23405
- * Fetches a collection of {@link Amity.Post} objects from cache
23484
+ * Fetches a collection of {@link Amity.Comment} objects from cache
23406
23485
  *
23407
- * @param postIds the IDs of the {@link Amity.Post} to fetch
23408
- * @returns the associated collection of {@link Amity.Post} objects
23486
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
23487
+ * @returns the associated collection of {@link Amity.Comment} objects
23409
23488
  *
23410
- * @category Post API
23489
+ * @category Comment API
23411
23490
  */
23412
- getPostByIds.locally = (postIds) => {
23491
+ getCommentByIds.locally = (commentIds) => {
23413
23492
  var _a;
23414
23493
  const client = getActiveClient();
23415
- client.log('post/getPostByIds.locally', postIds);
23494
+ client.log('comment/getCommentByIds.locally', commentIds);
23416
23495
  if (!client.cache)
23417
23496
  return;
23418
- const cached = postIds
23419
- .map(postId => pullFromCache(['post', 'get', postId]))
23497
+ const cached = commentIds
23498
+ .map(commentId => pullFromCache(['comment', 'get', commentId]))
23420
23499
  .filter(Boolean);
23421
- const posts = cached.map(({ data }) => data);
23500
+ const comments = cached.map(({ data }) => data);
23422
23501
  const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
23423
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
23502
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
23424
23503
  return;
23425
23504
  return {
23426
- data: posts.map(LinkedObject.post),
23505
+ data: comments.map(comment => LinkedObject.comment(comment)),
23427
23506
  cachedAt: oldest.cachedAt,
23428
23507
  };
23429
23508
  };
23430
23509
 
23431
23510
  /* begin_public_function
23432
- 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
23511
+ id: comment.create
23433
23512
  */
23434
23513
  /**
23435
23514
  * ```js
23436
- * import { PostRepository } from '@amityco/ts-sdk-react-native'
23437
- * const created = await PostRepository.createPost({
23438
- * targetType: 'user',
23439
- * targetId: 'foobar',
23440
- * data: { text: 'hello world' }
23441
- * }))
23515
+ * import { CommentRepository } from '@amityco/ts-sdk-react-native'
23516
+ * const newComment = await CommentRepository.createComment(bundle)
23442
23517
  * ```
23443
23518
  *
23444
- * Creates an {@link Amity.Post}
23519
+ * Creates an {@link Amity.Comment}
23445
23520
  *
23446
- * @param bundle The data necessary to create a new {@link Amity.Post}
23447
- * @returns The newly created {@link Amity.Post}
23521
+ * @param bundle The data necessary to create a new {@link Amity.Comment}
23522
+ * @returns The newly created {@link Amity.Comment}
23448
23523
  *
23449
- * @category Post API
23524
+ * @category Comment API
23450
23525
  * @async
23451
23526
  */
23452
- const createPost = async (bundle) => {
23527
+ const createComment = async (bundle) => {
23528
+ var _a;
23453
23529
  const client = getActiveClient();
23454
- client.log('post/createPost', bundle);
23455
- if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
23456
- // eslint-disable-next-line no-param-reassign
23457
- delete bundle.dataType;
23458
- }
23459
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
23460
- fireEvent('post.created', payload);
23461
- const data = preparePostPayload(payload);
23530
+ client.log('comment/createComment', bundle);
23531
+ const { data } = await client.http.post('/api/v3/comments', bundle);
23532
+ const { comments } = data;
23533
+ // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
23534
+ if (comments.length === 0)
23535
+ throw new Error('Comment not created');
23462
23536
  const cachedAt = client.cache && Date.now();
23463
23537
  if (client.cache)
23464
23538
  ingestInCache(data, { cachedAt });
23465
- const { posts } = data;
23539
+ if (['post', 'content'].includes(bundle.referenceType)) {
23540
+ const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
23541
+ if (post) {
23542
+ post.commentsCount += 1;
23543
+ fireEvent('local.post.updated', {
23544
+ posts: [post],
23545
+ categories: [],
23546
+ comments: [],
23547
+ communities: [],
23548
+ communityUsers: data.communityUsers,
23549
+ feeds: [],
23550
+ files: data.files,
23551
+ postChildren: [],
23552
+ users: data.users,
23553
+ videoStreamings: [],
23554
+ });
23555
+ }
23556
+ }
23557
+ else if (bundle.referenceType === 'story') {
23558
+ const storyIndex = pullFromCache([
23559
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23560
+ bundle.referenceId,
23561
+ ]);
23562
+ if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
23563
+ const cacheStory = pullFromCache([
23564
+ "story" /* STORY_KEY_CACHE.STORY */,
23565
+ 'get',
23566
+ storyIndex.data,
23567
+ ]);
23568
+ if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
23569
+ fireEvent('story.updated', {
23570
+ stories: [
23571
+ Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
23572
+ ],
23573
+ categories: [],
23574
+ comments,
23575
+ communities: [],
23576
+ communityUsers: data.communityUsers,
23577
+ files: data.files,
23578
+ users: data.users,
23579
+ });
23580
+ }
23581
+ }
23582
+ }
23583
+ fireEvent('local.comment.created', data);
23466
23584
  return {
23467
- data: LinkedObject.post(posts[0]),
23585
+ data: LinkedObject.comment(comments[0]),
23468
23586
  cachedAt,
23469
23587
  };
23470
23588
  };
23471
23589
  /* end_public_function */
23472
23590
 
23473
23591
  /* begin_public_function
23474
- id: post.edit, post.edit.custom_post
23592
+ id: comment.update_comment
23475
23593
  */
23476
23594
  /**
23477
23595
  * ```js
23478
- * import { PostRepository } from '@amityco/ts-sdk-react-native'
23479
- * const updated = await PostRepository.editPost(postId, {
23596
+ * import { CommentRepository } from '@amityco/ts-sdk-react-native'
23597
+ * const updated = await CommentRepository.updateComment(commentId, {
23480
23598
  * data: { text: 'hello world' }
23481
23599
  * })
23482
23600
  * ```
23483
23601
  *
23484
- * Updates an {@link Amity.Post}
23602
+ * Updates an {@link Amity.Comment}
23485
23603
  *
23486
- * @param postId The ID of the {@link Amity.Post} to edit
23604
+ * @param commentId The ID of the {@link Amity.Comment} to edit
23487
23605
  * @param patch The patch data to apply
23488
- * @returns the updated {@link Amity.Post} object
23606
+ * @returns the updated {@link Amity.Comment} object
23489
23607
  *
23490
- * @category Post API
23608
+ * @category Comment API
23491
23609
  * @async
23492
23610
  */
23493
- const editPost = async (postId, patch) => {
23611
+ const updateComment = async (commentId, patch) => {
23494
23612
  const client = getActiveClient();
23495
- client.log('user/editPost', patch);
23496
- const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
23497
- const data = prepareMembershipPayload(payload, 'communityUsers');
23613
+ client.log('user/updateComment', patch);
23614
+ const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
23498
23615
  const cachedAt = client.cache && Date.now();
23499
23616
  if (client.cache)
23500
23617
  ingestInCache(data, { cachedAt });
23501
- fireEvent('local.post.updated', data);
23502
- const { posts } = data;
23618
+ fireEvent('comment.updated', data);
23619
+ const { comments } = data;
23503
23620
  return {
23504
- data: LinkedObject.post(posts.find(post => post.postId === postId)),
23621
+ data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
23505
23622
  cachedAt,
23506
23623
  };
23507
23624
  };
23508
23625
  /* end_public_function */
23509
23626
 
23627
+ // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
23628
+ const applyMissingField = (rawData, isCreated = false) => {
23629
+ const { storyId, referenceId } = rawData;
23630
+ if (!isCreated) {
23631
+ if (referenceId)
23632
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
23633
+ }
23634
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
23635
+ };
23636
+ const convertRawStoryToInternal = (data, isCreated = false) => {
23637
+ const { stories } = data;
23638
+ const storiesData = stories.map(story => applyMissingField(story, isCreated));
23639
+ return Object.assign(Object.assign({}, data), { stories: storiesData });
23640
+ };
23641
+
23642
+ const getStoryByStoryId$1 = async (storyId) => {
23643
+ const client = getActiveClient();
23644
+ client.log('story/getStoryByStoryId', storyId);
23645
+ // Get story referenceId from cache
23646
+ const cacheReferenceId = pullFromCache([
23647
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23648
+ storyId,
23649
+ ]);
23650
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
23651
+ const { data: referenceId } = cacheReferenceId;
23652
+ isInTombstone('story', referenceId);
23653
+ }
23654
+ let data;
23655
+ try {
23656
+ const response = await client.http.get(`/api/v4/stories/${storyId}`);
23657
+ data = convertRawStoryToInternal(response.data);
23658
+ }
23659
+ catch (error) {
23660
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23661
+ pushToTombstone('story', storyId);
23662
+ }
23663
+ throw error;
23664
+ }
23665
+ const cachedAt = client.cache && Date.now();
23666
+ if (client.cache) {
23667
+ ingestInCache(data, { cachedAt });
23668
+ }
23669
+ return {
23670
+ data: data.stories[0],
23671
+ cachedAt,
23672
+ };
23673
+ };
23674
+ getStoryByStoryId$1.locally = (storyId) => {
23675
+ const client = getActiveClient();
23676
+ client.log('story/getStorybyStoryId', storyId);
23677
+ // Get story referenceId from cache
23678
+ const cacheReferenceId = pullFromCache([
23679
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23680
+ storyId,
23681
+ ]);
23682
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
23683
+ const { data: referenceId } = cacheReferenceId;
23684
+ isInTombstone('story', referenceId);
23685
+ }
23686
+ const cachedAt = client.cache && Date.now();
23687
+ const storyCache = pullFromCache(['story', 'get', storyId]);
23688
+ if (!storyCache)
23689
+ return;
23690
+ return {
23691
+ data: storyCache.data,
23692
+ cachedAt,
23693
+ };
23694
+ };
23695
+
23696
+ /* begin_public_function
23697
+ id: comment.soft_delete, comment.hard_delete
23698
+ */
23510
23699
  /**
23511
23700
  * ```js
23512
- * import { deletePost } from '@amityco/ts-sdk-react-native'
23513
- * const success = await deletePost('foobar')
23701
+ * import { CommentRepository } from '@amityco/ts-sdk-react-native'
23702
+ * const success = await CommentRepository.deleteComment('foobar')
23514
23703
  * ```
23515
23704
  *
23516
- * Deletes a {@link Amity.Post}
23705
+ * Deletes a {@link Amity.Comment}
23517
23706
  *
23518
- * @param postId The {@link Amity.Post} ID to delete
23519
- * @return A success boolean if the {@link Amity.Post} was deleted
23707
+ * @param commentId The {@link Amity.Comment} ID to delete
23708
+ * @return A success boolean if the {@link Amity.Comment} was deleted
23520
23709
  *
23521
- * @private
23710
+ * @category Comment API
23522
23711
  * @async
23523
23712
  */
23524
- const deletePost = async (postId, permanent = false) => {
23713
+ const deleteComment = async (commentId, permanent = false) => {
23525
23714
  var _a;
23526
23715
  const client = getActiveClient();
23527
- const post = await getPost$2(postId);
23528
- await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
23716
+ const comment = await getComment$2(commentId);
23717
+ // API-FIX: This endpoint has not been implemented yet.
23718
+ await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
23529
23719
  params: {
23530
- postId,
23720
+ commentId,
23531
23721
  permanent,
23532
23722
  },
23533
23723
  });
23534
- // there is currently a limitation which doesn't allow us to fire event to tell that community
23535
- // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
23536
- // and so we cannot refetch the community or advertise on events. hopefully this should be solved
23537
- // later when realtime events covers that for us.
23538
- if (post.data.targetType === 'community') {
23539
- const community = await getCommunity$1(post.data.targetId);
23540
- const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
23541
- const communityUsers = communityUsersCache
23542
- .filter(({ key }) => {
23543
- // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
23544
- if (key[0] !== 'communityUsers')
23545
- return false;
23546
- if (key[1] !== 'get')
23547
- return false;
23548
- if (typeof key[2] === 'string')
23549
- return key[2].includes(community.data.communityId);
23550
- return false;
23551
- })
23552
- .map(({ data }) => data);
23553
- fireEvent('community.updated', {
23554
- communities: [community.data],
23724
+ // to support hard deletion
23725
+ const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
23726
+ if (permanent) {
23727
+ scheduleTask(() => pushToTombstone('comment', commentId));
23728
+ }
23729
+ else {
23730
+ upsertInCache(['comment', 'get', commentId], { isDeleted: true });
23731
+ }
23732
+ if (comment.data.referenceType === 'story') {
23733
+ const story = await getStoryByStoryId$1(comment.data.referenceId);
23734
+ fireEvent('local.story.updated', {
23735
+ stories: [story.data],
23555
23736
  categories: [],
23556
- communityUsers,
23557
- feeds: [],
23737
+ comments: [],
23738
+ communities: [],
23739
+ communityUsers: [],
23558
23740
  files: [],
23559
23741
  users: [],
23560
23742
  });
23561
23743
  }
23562
- // to support hard deletion
23563
- const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
23564
- if (permanent) {
23565
- setTimeout(() => {
23566
- pushToTombstone('post', postId);
23567
- }, 0);
23568
- }
23569
23744
  else {
23570
- upsertInCache(['post', 'get', postId], { isDeleted: true });
23745
+ const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
23746
+ if (post) {
23747
+ let removeCount;
23748
+ if (!deleted.parentId) {
23749
+ // NOTE: delete the parent comment will remove all children comments
23750
+ removeCount = deleted.childrenNumber + 1;
23751
+ }
23752
+ else
23753
+ removeCount = 1;
23754
+ post.commentsCount -= removeCount;
23755
+ fireEvent('local.post.updated', {
23756
+ posts: [post],
23757
+ categories: [],
23758
+ comments: [],
23759
+ communities: [],
23760
+ communityUsers: [],
23761
+ feeds: [],
23762
+ files: [],
23763
+ postChildren: [],
23764
+ users: [],
23765
+ videoStreamings: [],
23766
+ });
23767
+ }
23571
23768
  }
23572
- fireEvent('local.post.deleted', {
23573
- posts: [deleted],
23574
- categories: [],
23575
- comments: [],
23576
- communities: [],
23577
- communityUsers: [],
23578
- feeds: [],
23769
+ fireEvent('local.comment.deleted', {
23770
+ comments: [deleted],
23771
+ commentChildren: [],
23579
23772
  files: [],
23580
- postChildren: [],
23581
23773
  users: [],
23582
- videoStreamings: [],
23774
+ communityUsers: [],
23583
23775
  });
23584
- return LinkedObject.post(deleted);
23585
- };
23586
-
23587
- /* begin_public_function
23588
- id: post.soft_delete
23589
- */
23590
- /**
23591
- * ```js
23592
- * import { PostRepository } from '@amityco/ts-sdk-react-native'
23593
- * const success = await PostRepository.softDeletePost('foobar')
23594
- * ```
23595
- *
23596
- * Soft deletes a {@link Amity.Post}
23597
- *
23598
- * @param postId The {@link Amity.Post} ID to soft delete
23599
- * @return A success boolean if the {@link Amity.Post} was deleted
23600
- *
23601
- * @category Post API
23602
- * @async
23603
- */
23604
- const softDeletePost = async (postId) => {
23605
- const client = getActiveClient();
23606
- client.log('post/softDeletePost', postId);
23607
- const softDeleted = await deletePost(postId, false);
23608
- return LinkedObject.post(softDeleted);
23609
- };
23610
- /* end_public_function */
23611
-
23612
- /* begin_public_function
23613
- id: post.hard_delete
23614
- */
23615
- /**
23616
- * ```js
23617
- * import { hardDeletePost } from '@amityco/ts-sdk-react-native'
23618
- * const success = await hardDeletePost('foobar')
23619
- * ```
23620
- *
23621
- * Hard deletes a {@link Amity.Post}
23622
- *
23623
- * @param postId The {@link Amity.Post} ID to be hard delete
23624
- * @return A success boolean if the {@link Amity.Post} was deleted
23625
- *
23626
- * @category Post API
23627
- * @async
23628
- */
23629
- const hardDeletePost = async (postId) => {
23630
- const client = getActiveClient();
23631
- client.log('post/hardDeletePost', postId);
23632
- const hardDeleted = await deletePost(postId, true);
23633
- return LinkedObject.post(hardDeleted);
23776
+ return deleted;
23634
23777
  };
23635
23778
  /* end_public_function */
23636
23779
 
23637
23780
  /* begin_public_function
23638
- id: post.approve
23781
+ id: comment.soft_delete
23639
23782
  */
23640
23783
  /**
23641
23784
  * ```js
23642
- * import { approvePost } from '@amityco/ts-sdk-react-native'
23643
- *
23644
- * const { data: post } = await approvePost('postId')
23785
+ * import { CommentRepository } from '@amityco/ts-sdk-react-native'
23786
+ * const success = await CommentRepository.softDeleteComment('foobar')
23645
23787
  * ```
23646
23788
  *
23647
- * Approves a {@link Amity.Post}
23789
+ * Deletes a {@link Amity.Comment}
23648
23790
  *
23649
- * @param postId The {@link Amity.Post} ID to be approved
23650
- * @return A {@link Amity.Post} that was approved
23791
+ * @param commentId The {@link Amity.Comment} ID to delete
23792
+ * @return A success boolean if the {@link Amity.Comment} was deleted
23651
23793
  *
23652
- * @category Post API
23794
+ * @category Comment API
23653
23795
  * @async
23654
23796
  */
23655
- const approvePost = async (postId) => {
23797
+ const softDeleteComment = async (commentId) => {
23656
23798
  const client = getActiveClient();
23657
- client.log('post/approvePost', postId);
23658
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
23659
- fireEvent('post.approved', payload);
23660
- // fire virtual event for community update
23661
- if (payload.posts[0].targetType === 'community') {
23662
- fireEvent('community.updated', payload);
23663
- }
23664
- const data = prepareMembershipPayload(payload, 'communityUsers');
23665
- const cachedAt = client.cache && Date.now();
23666
- if (client.cache)
23667
- ingestInCache(data, { cachedAt });
23668
- return {
23669
- data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
23670
- cachedAt,
23671
- };
23799
+ client.log('comment/softDeleteComment', commentId);
23800
+ const softDeleted = deleteComment(commentId);
23801
+ return softDeleted;
23672
23802
  };
23673
23803
  /* end_public_function */
23674
23804
 
23675
23805
  /* begin_public_function
23676
- id: post.decline
23806
+ id: comment.hard_delete
23677
23807
  */
23678
23808
  /**
23679
23809
  * ```js
23680
- * import { declinePost } from '@amityco/ts-sdk-react-native'
23681
- *
23682
- * const {data: post} = await declinePost('postId')
23810
+ * import { CommentRepository } from '@amityco/ts-sdk-react-native'
23811
+ * const success = await CommentRepository.hardDeleteComment('foobar')
23683
23812
  * ```
23684
23813
  *
23685
- * Declines a {@link Amity.Post}
23814
+ * Deletes a {@link Amity.Comment}
23686
23815
  *
23687
- * @param postId The {@link Amity.Post} ID to be declined
23688
- * @return A {@link Amity.Post} that was declined
23816
+ * @param commentId The {@link Amity.Comment} ID to delete
23817
+ * @return A success boolean if the {@link Amity.Comment} was deleted
23689
23818
  *
23690
- * @category Post API
23819
+ * @category Comment API
23691
23820
  * @async
23692
23821
  */
23693
- const declinePost = async (postId) => {
23822
+ const hardDeleteComment = async (commentId) => {
23694
23823
  const client = getActiveClient();
23695
- client.log('post/declinePost', postId);
23696
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
23697
- // fire virtual event
23698
- if (payload.posts[0].targetType === 'community') {
23699
- fireEvent('community.updated', payload);
23700
- }
23701
- fireEvent('post.declined', payload);
23702
- const data = prepareMembershipPayload(payload, 'communityUsers');
23703
- const cachedAt = client.cache && Date.now();
23704
- if (client.cache)
23705
- ingestInCache(data, { cachedAt });
23706
- return {
23707
- data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
23708
- cachedAt,
23709
- };
23824
+ client.log('comment/hardDeleteComment', commentId);
23825
+ const hardDeleted = deleteComment(commentId, true);
23826
+ return hardDeleted;
23710
23827
  };
23711
23828
  /* end_public_function */
23712
23829
 
23713
23830
  /* begin_public_function
23714
- id: post.flag
23831
+ id: comment.flag
23715
23832
  */
23716
23833
  /**
23717
23834
  * ```js
23718
- * import { PostRepository } from '@amityco/ts-sdk-react-native'
23719
- * const flagged = await PostRepository.flagPost(postId, reason)
23835
+ * import { CommentRepository } from '@amityco/ts-sdk-react-native'
23836
+ * const flagged = await CommentRepository.flagComment(commentId, reason)
23720
23837
  * ```
23721
23838
  *
23722
- * @param postId of the post to flag
23723
- * @param reason the reason to flag the post
23724
- * @returns a boolean
23839
+ * @param commentId The ID of the comment to flag
23840
+ * @param reason the reason to flag the comment
23841
+ * @returns the created report result
23725
23842
  *
23726
- * @category Post API
23843
+ * @category Comment API
23727
23844
  * @async
23728
23845
  * */
23729
- const flagPost = async (postId, reason) => {
23846
+ const flagComment = async (commentId, reason) => {
23730
23847
  const client = getActiveClient();
23731
- client.log('post/flagPost', postId);
23848
+ client.log('comment/flagComment', commentId);
23732
23849
  const isPredefinedReason = reason &&
23733
23850
  Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
23734
23851
  const body = {
23735
23852
  reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
23736
23853
  detail: reason && !isPredefinedReason ? reason : '',
23737
23854
  };
23738
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
23855
+ const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
23739
23856
  if (client.cache) {
23740
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
23857
+ ingestInCache(payload);
23741
23858
  }
23742
- fireEvent('post.flagged', payload);
23859
+ fireEvent('comment.flagged', payload);
23743
23860
  return !!payload;
23744
23861
  };
23745
23862
  /* end_public_function */
23746
23863
 
23747
23864
  /* begin_public_function
23748
- id: post.unflag
23865
+ id: comment.unflag
23749
23866
  */
23750
23867
  /**
23751
23868
  * ```js
23752
- * import { PostRepository } from '@amityco/ts-sdk-react-native'
23753
- * const unflagged = await PostRepository.unflagPost(postId)
23869
+ * import { CommentRepository } from '@amityco/ts-sdk-react-native'
23870
+ * const unflagged = await CommentRepository.unflagComment('commentId')
23754
23871
  * ```
23755
23872
  *
23756
- * @param postId of the post to unflag
23757
- * @returns the unflag post result
23873
+ * @param commentId The ID of comment to unflag
23874
+ * @returns the unflagged result
23758
23875
  *
23759
- * @category Post API
23876
+ * @category Comment API
23760
23877
  * @async
23761
23878
  * */
23762
- const unflagPost = async (postId) => {
23879
+ const unflagComment = async (commentId) => {
23763
23880
  const client = getActiveClient();
23764
- client.log('post/unflagPost', postId);
23765
- const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
23881
+ client.log('comment/unflagComment', commentId);
23882
+ const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
23766
23883
  if (client.cache) {
23767
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
23884
+ ingestInCache(payload);
23768
23885
  }
23769
- fireEvent('post.unflagged', payload);
23886
+ fireEvent('comment.unflagged', payload);
23770
23887
  return !!payload;
23771
23888
  };
23772
23889
  /* end_public_function */
23773
23890
 
23774
23891
  /* begin_public_function
23775
- id: post.check_flag_by_me
23892
+ id: comment.check_flag_by_me
23776
23893
  */
23777
23894
  /**
23778
23895
  * ```js
23779
- * import { PostRepository } from '@amityco/ts-sdk-react-native'
23780
- * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
23896
+ * import { CommentRepository } from '@amityco/ts-sdk-react-native'
23897
+ * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
23781
23898
  * ```
23782
23899
  *
23783
- * @param postId of the post to check if flagged by current user
23784
- * @returns `true` if the post is flagged by me, `false` if doesn't.
23900
+ * @param commentId The ID of the comment to check if flagged by current user
23901
+ * @returns `true` if the comment is flagged by me, `false` if doesn't.
23785
23902
  *
23786
- * @category Post API
23903
+ * @category Comment API
23787
23904
  * @async
23788
23905
  * */
23789
- const isPostFlaggedByMe = async (postId) => {
23906
+ const isCommentFlaggedByMe = async (commentId) => {
23790
23907
  const client = getActiveClient();
23791
- client.log('post/isPostFlaggedByMe', postId);
23792
- const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
23908
+ client.log('comment/isCommentFlaggedByMe', commentId);
23909
+ const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
23793
23910
  return result;
23794
23911
  };
23795
23912
  /* end_public_function */
23796
23913
 
23797
- /* begin_public_function
23798
- id: post.create.clip_post
23799
- */
23800
- /**
23801
- * ```js
23802
- * import { PostRepository } from '@amityco/ts-sdk'
23803
- * const created = await PostRepository.createClipPost({
23804
- * targetType: 'user',
23805
- * targetId: 'foobar',
23806
- * dataType: 'clip',
23807
- * data: { text: 'hello world' },
23808
- * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
23809
- * }))
23810
- * ```
23811
- *
23812
- * Creates an {@link Amity.Post}
23813
- *
23814
- * @param bundle The data necessary to create a new {@link Amity.Post}
23815
- * @returns The newly created {@link Amity.Post}
23816
- *
23817
- * @category Post API
23818
- * @async
23819
- */
23820
- const createClipPost = async (bundle) => {
23914
+ const getComment$1 = async (commentId) => {
23821
23915
  const client = getActiveClient();
23822
- client.log('post/createPost', bundle);
23823
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
23824
- fireEvent('post.created', payload);
23825
- const data = prepareMembershipPayload(payload, 'communityUsers');
23916
+ client.log('comment/getComment', commentId);
23917
+ isInTombstone('comment', commentId);
23918
+ let data;
23919
+ try {
23920
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
23921
+ const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
23922
+ data = response.data;
23923
+ }
23924
+ catch (error) {
23925
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23926
+ pushToTombstone('comment', commentId);
23927
+ }
23928
+ throw error;
23929
+ }
23826
23930
  const cachedAt = client.cache && Date.now();
23827
23931
  if (client.cache)
23828
23932
  ingestInCache(data, { cachedAt });
23829
- const { posts } = data;
23933
+ const { comments } = data;
23830
23934
  return {
23831
- data: LinkedObject.post(posts[0]),
23935
+ data: comments.find(comment => comment.commentId === commentId),
23832
23936
  cachedAt,
23833
23937
  };
23834
23938
  };
23835
- /* end_public_function */
23939
+ getComment$1.locally = (commentId) => {
23940
+ const client = getActiveClient();
23941
+ client.log('comment/getComment.locally', commentId);
23942
+ if (!client.cache)
23943
+ return;
23944
+ const cached = pullFromCache(['comment', 'get', commentId]);
23945
+ if (!cached)
23946
+ return;
23947
+ return {
23948
+ data: cached.data,
23949
+ cachedAt: cached.cachedAt,
23950
+ };
23951
+ };
23836
23952
 
23837
- /* begin_public_function
23838
- id: comment.get_by_ids
23839
- */
23840
23953
  /**
23841
23954
  * ```js
23842
- * import { CommentRepository } from '@amityco/ts-sdk-react-native'
23843
- * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
23955
+ * import { onCommentDeleteLocal } from '@amityco/ts-sdk-react-native'
23956
+ * const dispose = onCommentDeleteLocal(comment => {
23957
+ * // ...
23958
+ * })
23844
23959
  * ```
23845
23960
  *
23846
- * Fetches a collection of {@link Amity.Comment} objects
23961
+ * Fired when a {@link Amity.InternalComment} has been deleted
23847
23962
  *
23848
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
23849
- * @returns the associated collection of {@link Amity.Comment} objects
23963
+ * @param callback The function to call when the event was fired
23964
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23850
23965
  *
23851
- * @category Comment API
23852
- * @async
23966
+ * @category Comment Events
23853
23967
  */
23854
- const getCommentByIds = async (commentIds) => {
23855
- const client = getActiveClient();
23856
- client.log('comment/getCommentByIds', commentIds);
23857
- const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
23858
- let data;
23859
- try {
23860
- // API-FIX: endpoint should not be /list, parameters should be querystring.
23861
- const response = await client.http.get(`/api/v3/comments/list`, {
23862
- params: { commentIds: encodedCommentIds },
23863
- });
23864
- data = response.data;
23865
- }
23866
- catch (error) {
23867
- commentIds.forEach(commentId => {
23868
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23869
- pushToTombstone('comment', commentId);
23870
- }
23871
- });
23872
- throw error;
23873
- }
23874
- const cachedAt = client.cache && Date.now();
23875
- if (client.cache)
23876
- ingestInCache(data, { cachedAt });
23877
- return {
23878
- data: data.comments.map(comment => LinkedObject.comment(comment)),
23879
- cachedAt,
23880
- };
23881
- };
23882
- /* end_public_function */
23968
+ const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
23969
+
23883
23970
  /**
23884
23971
  * ```js
23885
- * import { getCommentByIds } from '@amityco/ts-sdk-react-native'
23886
- * const comments = getCommentByIds.locally(['foo', 'bar'])
23972
+ * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk-react-native'
23973
+ * const dispose = onLocalCommentReactionAdded(comment => {
23974
+ * // ...
23975
+ * })
23887
23976
  * ```
23888
23977
  *
23889
- * Fetches a collection of {@link Amity.Comment} objects from cache
23978
+ * Fired when a {@link Amity.InternalComment} has been reacted
23890
23979
  *
23891
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
23892
- * @returns the associated collection of {@link Amity.Comment} objects
23980
+ * @param callback The function to call when the event was fired
23981
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23893
23982
  *
23894
- * @category Comment API
23983
+ * @category Comment Events
23895
23984
  */
23896
- getCommentByIds.locally = (commentIds) => {
23897
- var _a;
23985
+ const onLocalCommentReactionAdded = (callback) => {
23898
23986
  const client = getActiveClient();
23899
- client.log('comment/getCommentByIds.locally', commentIds);
23900
- if (!client.cache)
23901
- return;
23902
- const cached = commentIds
23903
- .map(commentId => pullFromCache(['comment', 'get', commentId]))
23904
- .filter(Boolean);
23905
- const comments = cached.map(({ data }) => data);
23906
- const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
23907
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
23908
- return;
23909
- return {
23910
- data: comments.map(comment => LinkedObject.comment(comment)),
23911
- cachedAt: oldest.cachedAt,
23987
+ const filter = ({ comment }) => {
23988
+ if (!client.cache) {
23989
+ callback(comment);
23990
+ }
23991
+ else {
23992
+ upsertInCache(['comment', 'get', comment.commentId], comment);
23993
+ callback(commentLinkedObject(comment));
23994
+ }
23912
23995
  };
23996
+ return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
23913
23997
  };
23914
23998
 
23915
- /* begin_public_function
23916
- id: comment.create
23917
- */
23918
23999
  /**
23919
24000
  * ```js
23920
- * import { CommentRepository } from '@amityco/ts-sdk-react-native'
23921
- * const newComment = await CommentRepository.createComment(bundle)
24001
+ * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk-react-native'
24002
+ * const dispose = onLocalCommentReactionRemoved(comment => {
24003
+ * // ...
24004
+ * })
23922
24005
  * ```
23923
24006
  *
23924
- * Creates an {@link Amity.Comment}
24007
+ * Fired when a {@link Amity.InternalComment} has been reacted
23925
24008
  *
23926
- * @param bundle The data necessary to create a new {@link Amity.Comment}
23927
- * @returns The newly created {@link Amity.Comment}
24009
+ * @param callback The function to call when the event was fired
24010
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23928
24011
  *
23929
- * @category Comment API
23930
- * @async
24012
+ * @category Comment Events
23931
24013
  */
23932
- const createComment = async (bundle) => {
23933
- var _a;
24014
+ const onLocalCommentReactionRemoved = (callback) => {
23934
24015
  const client = getActiveClient();
23935
- client.log('comment/createComment', bundle);
23936
- const { data } = await client.http.post('/api/v3/comments', bundle);
23937
- const { comments } = data;
23938
- // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
23939
- if (comments.length === 0)
23940
- throw new Error('Comment not created');
23941
- const cachedAt = client.cache && Date.now();
23942
- if (client.cache)
23943
- ingestInCache(data, { cachedAt });
23944
- if (['post', 'content'].includes(bundle.referenceType)) {
23945
- const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
23946
- if (post) {
23947
- post.commentsCount += 1;
23948
- fireEvent('local.post.updated', {
23949
- posts: [post],
23950
- categories: [],
23951
- comments: [],
23952
- communities: [],
23953
- communityUsers: data.communityUsers,
23954
- feeds: [],
23955
- files: data.files,
23956
- postChildren: [],
23957
- users: data.users,
23958
- videoStreamings: [],
23959
- });
24016
+ const filter = ({ comment }) => {
24017
+ if (!client.cache) {
24018
+ callback(comment);
23960
24019
  }
23961
- }
23962
- else if (bundle.referenceType === 'story') {
23963
- const storyIndex = pullFromCache([
23964
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23965
- bundle.referenceId,
23966
- ]);
23967
- if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
23968
- const cacheStory = pullFromCache([
23969
- "story" /* STORY_KEY_CACHE.STORY */,
23970
- 'get',
23971
- storyIndex.data,
23972
- ]);
23973
- if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
23974
- fireEvent('story.updated', {
23975
- stories: [
23976
- Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
23977
- ],
23978
- categories: [],
23979
- comments,
23980
- communities: [],
23981
- communityUsers: data.communityUsers,
23982
- files: data.files,
23983
- users: data.users,
23984
- });
23985
- }
24020
+ else {
24021
+ upsertInCache(['comment', 'get', comment.commentId], comment);
24022
+ callback(commentLinkedObject(comment));
23986
24023
  }
23987
- }
23988
- fireEvent('local.comment.created', data);
23989
- return {
23990
- data: LinkedObject.comment(comments[0]),
23991
- cachedAt,
23992
24024
  };
24025
+ return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
23993
24026
  };
23994
- /* end_public_function */
23995
24027
 
23996
24028
  /* begin_public_function
23997
- id: comment.update_comment
24029
+ id: comment.get
23998
24030
  */
23999
24031
  /**
24000
24032
  * ```js
24001
- * import { CommentRepository } from '@amityco/ts-sdk-react-native'
24002
- * const updated = await CommentRepository.updateComment(commentId, {
24003
- * data: { text: 'hello world' }
24004
- * })
24033
+ * import { CommentRepository } from '@amityco/ts-sdk-react-native';
24034
+ *
24035
+ * let comment;
24036
+ *
24037
+ * const unsub = CommentRepository.getComment(commentId, response => {
24038
+ * comment = response.data;
24039
+ * });
24005
24040
  * ```
24006
24041
  *
24007
- * Updates an {@link Amity.Comment}
24042
+ * Observe all mutation on a given {@link Amity.Comment}
24008
24043
  *
24009
- * @param commentId The ID of the {@link Amity.Comment} to edit
24010
- * @param patch The patch data to apply
24011
- * @returns the updated {@link Amity.Comment} object
24044
+ * @param commentId the ID of the comment to observe
24045
+ * @param callback the function to call when new data are available
24046
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
24012
24047
  *
24013
- * @category Comment API
24014
- * @async
24048
+ * @category Comment Live Object
24015
24049
  */
24016
- const updateComment = async (commentId, patch) => {
24017
- const client = getActiveClient();
24018
- client.log('user/updateComment', patch);
24019
- const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
24020
- const cachedAt = client.cache && Date.now();
24021
- if (client.cache)
24022
- ingestInCache(data, { cachedAt });
24023
- fireEvent('comment.updated', data);
24024
- const { comments } = data;
24025
- return {
24026
- data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
24027
- cachedAt,
24028
- };
24050
+ const getComment = (commentId, callback) => {
24051
+ return liveObject(commentId, callback, 'commentId', getComment$1, [
24052
+ onCommentDeleteLocal,
24053
+ onCommentDeleted,
24054
+ onCommentFlagged,
24055
+ onCommentReactionAdded,
24056
+ onCommentReactionRemoved,
24057
+ onCommentUnflagged,
24058
+ onCommentUpdated,
24059
+ onLocalCommentReactionAdded,
24060
+ onLocalCommentReactionRemoved,
24061
+ ]);
24029
24062
  };
24030
24063
  /* end_public_function */
24031
24064
 
24032
- // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
24033
- const applyMissingField = (rawData, isCreated = false) => {
24034
- const { storyId, referenceId } = rawData;
24035
- if (!isCreated) {
24036
- if (referenceId)
24037
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
24065
+ class CommentPaginationController extends PaginationController {
24066
+ async getRequest(queryParams, token) {
24067
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
24068
+ const baseOptions = {
24069
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
24070
+ };
24071
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
24072
+ const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
24073
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
24074
+ });
24075
+ return queryResponse;
24038
24076
  }
24039
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
24040
- };
24041
- const convertRawStoryToInternal = (data, isCreated = false) => {
24042
- const { stories } = data;
24043
- const storiesData = stories.map(story => applyMissingField(story, isCreated));
24044
- return Object.assign(Object.assign({}, data), { stories: storiesData });
24045
- };
24077
+ }
24046
24078
 
24047
- const getStoryByStoryId$1 = async (storyId) => {
24048
- const client = getActiveClient();
24049
- client.log('story/getStoryByStoryId', storyId);
24050
- // Get story referenceId from cache
24051
- const cacheReferenceId = pullFromCache([
24052
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
24053
- storyId,
24054
- ]);
24055
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
24056
- const { data: referenceId } = cacheReferenceId;
24057
- isInTombstone('story', referenceId);
24058
- }
24059
- let data;
24060
- try {
24061
- const response = await client.http.get(`/api/v4/stories/${storyId}`);
24062
- data = convertRawStoryToInternal(response.data);
24063
- }
24064
- catch (error) {
24065
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
24066
- pushToTombstone('story', storyId);
24079
+ var EnumCommentActions;
24080
+ (function (EnumCommentActions) {
24081
+ EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
24082
+ EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
24083
+ EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
24084
+ EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
24085
+ EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
24086
+ EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
24087
+ EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
24088
+ })(EnumCommentActions || (EnumCommentActions = {}));
24089
+
24090
+ class CommentQueryStreamController extends QueryStreamController {
24091
+ constructor(query, cacheKey, notifyChange, preparePayload) {
24092
+ super(query, cacheKey);
24093
+ this.notifyChange = notifyChange;
24094
+ this.preparePayload = preparePayload;
24095
+ }
24096
+ async saveToMainDB(response) {
24097
+ const processedPayload = await this.preparePayload(response);
24098
+ const client = getActiveClient();
24099
+ const cachedAt = client.cache && Date.now();
24100
+ if (client.cache) {
24101
+ ingestInCache(processedPayload, { cachedAt });
24102
+ }
24103
+ }
24104
+ appendToQueryStream(response, direction, refresh = false) {
24105
+ var _a, _b;
24106
+ if (refresh) {
24107
+ pushToCache(this.cacheKey, {
24108
+ data: response.comments.map(getResolver('comment')),
24109
+ });
24110
+ }
24111
+ else {
24112
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24113
+ const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
24114
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
24115
+ }
24116
+ }
24117
+ reactor(action) {
24118
+ return (comment) => {
24119
+ var _a;
24120
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24121
+ if (this.query.referenceId !== comment.referenceId ||
24122
+ this.query.referenceType !== comment.referenceType ||
24123
+ !collection) {
24124
+ return;
24125
+ }
24126
+ if (this.query.parentId && this.query.parentId !== comment.parentId) {
24127
+ return;
24128
+ }
24129
+ if (!this.query.parentId && comment.parentId) {
24130
+ return;
24131
+ }
24132
+ if (action === EnumCommentActions.OnCommentCreated) {
24133
+ collection.data = [...new Set([comment.commentId, ...collection.data])];
24134
+ }
24135
+ pushToCache(this.cacheKey, collection);
24136
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
24137
+ };
24138
+ }
24139
+ subscribeRTE(createSubscriber) {
24140
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
24141
+ }
24142
+ }
24143
+
24144
+ /**
24145
+ * ```js
24146
+ * import { onCommentCreated } from '@amityco/ts-sdk-react-native'
24147
+ * const dispose = onCommentCreated(comment => {
24148
+ * // ...
24149
+ * })
24150
+ * ```
24151
+ *
24152
+ * Fired when a {@link Amity.InternalComment} has been created
24153
+ *
24154
+ * @param callback The function to call when the event was fired
24155
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24156
+ *
24157
+ * @category Comment Events
24158
+ */
24159
+ const onCommentCreatedLocal = (callback) => {
24160
+ return createLocalCommentEventSubscriber('local.comment.created', callback);
24161
+ };
24162
+
24163
+ class CommentLiveCollectionController extends LiveCollectionController {
24164
+ constructor(query, callback) {
24165
+ const queryStreamId = hash__default["default"](query);
24166
+ const cacheKey = ['comments', 'collection', queryStreamId];
24167
+ const paginationController = new CommentPaginationController(query);
24168
+ super(paginationController, queryStreamId, cacheKey, callback);
24169
+ this.query = query;
24170
+ this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
24171
+ this.callback = callback.bind(this);
24172
+ this.loadPage({ initial: true });
24173
+ }
24174
+ setup() {
24175
+ var _a;
24176
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24177
+ if (!collection) {
24178
+ pushToCache(this.cacheKey, {
24179
+ data: [],
24180
+ params: {},
24181
+ });
24182
+ }
24183
+ }
24184
+ async persistModel(queryPayload) {
24185
+ await this.queryStreamController.saveToMainDB(queryPayload);
24186
+ }
24187
+ persistQueryStream({ response, direction, refresh, }) {
24188
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
24189
+ }
24190
+ startSubscription() {
24191
+ return this.queryStreamController.subscribeRTE([
24192
+ { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
24193
+ { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
24194
+ { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
24195
+ { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
24196
+ { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
24197
+ { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
24198
+ { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
24199
+ { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
24200
+ { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
24201
+ { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
24202
+ { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
24203
+ ]);
24204
+ }
24205
+ notifyChange({ origin, loading, error }) {
24206
+ var _a, _b;
24207
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24208
+ if (!collection)
24209
+ return;
24210
+ const data = this.applyFilter((_b = collection.data
24211
+ .map(id => pullFromCache(['comment', 'get', id]))
24212
+ .filter(isNonNullable)
24213
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
24214
+ if (!this.shouldNotify(data) && origin === 'event')
24215
+ return;
24216
+ this.callback({
24217
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
24218
+ data,
24219
+ hasNextPage: !!this.paginationController.getNextToken(),
24220
+ loading,
24221
+ error,
24222
+ });
24223
+ }
24224
+ applyFilter(data) {
24225
+ let comments = data;
24226
+ if (!this.query.includeDeleted) {
24227
+ comments = filterByPropEquality(comments, 'isDeleted', false);
24228
+ }
24229
+ if (this.query.parentId) {
24230
+ comments = comments.filter(comment => comment.parentId === this.query.parentId);
24231
+ }
24232
+ if (typeof this.query.hasFlag === 'boolean') {
24233
+ if (this.query.hasFlag) {
24234
+ comments = comments.filter(comment => comment.hashFlag != null);
24235
+ }
24236
+ else {
24237
+ comments = comments.filter(comment => comment.hashFlag == null);
24238
+ }
24239
+ }
24240
+ if (this.query.dataTypes) {
24241
+ if (this.query.dataTypes.matchType === 'exact') {
24242
+ comments = comments.filter(comment => {
24243
+ var _a, _b;
24244
+ const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
24245
+ const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
24246
+ if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
24247
+ return false;
24248
+ }
24249
+ return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
24250
+ });
24251
+ }
24252
+ if (this.query.dataTypes.matchType === 'any') {
24253
+ 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); }); });
24254
+ }
24255
+ }
24256
+ switch (this.query.sortBy) {
24257
+ case 'firstCreated':
24258
+ comments = comments.sort(sortByFirstCreated);
24259
+ break;
24260
+ case 'lastCreated':
24261
+ default:
24262
+ comments = comments.sort(sortByLastCreated);
24263
+ break;
24264
+ }
24265
+ return comments;
24266
+ }
24267
+ }
24268
+
24269
+ /* begin_public_function
24270
+ id: comment.query
24271
+ */
24272
+ /**
24273
+ * ```js
24274
+ * import { getComments } from '@amityco/ts-sdk-react-native'
24275
+ *
24276
+ * let comments = []
24277
+ * const unsub = getComments({
24278
+ * referenceType: Amity.InternalComment['referenceType'];
24279
+ * referenceId: Amity.InternalComment['referenceId'];
24280
+ * }, response => merge(comments, response.data))
24281
+ * ```
24282
+ *
24283
+ * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
24284
+ *
24285
+ * @param referenceType the type of the target
24286
+ * @param referenceId the ID of the target
24287
+ * @param callback the function to call when new data are available
24288
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
24289
+ *
24290
+ * @category Comments Live Collection
24291
+ */
24292
+ const getComments = (params, callback, config) => {
24293
+ const { log, cache } = getActiveClient();
24294
+ if (!cache) {
24295
+ console.log('For using Live Collection feature you need to enable Cache!');
24296
+ }
24297
+ const timestamp = Date.now();
24298
+ log(`getComments(tmpid: ${timestamp}) > listen`);
24299
+ const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
24300
+ const disposers = commentsLiveCollection.startSubscription();
24301
+ const cacheKey = commentsLiveCollection.getCacheKey();
24302
+ disposers.push(() => dropFromCache(cacheKey));
24303
+ return () => {
24304
+ log(`getComments(tmpid: ${timestamp}) > dispose`);
24305
+ disposers.forEach(fn => fn());
24306
+ };
24307
+ };
24308
+ /* end_public_function */
24309
+
24310
+ var index$a = /*#__PURE__*/Object.freeze({
24311
+ __proto__: null,
24312
+ getCommentByIds: getCommentByIds,
24313
+ createComment: createComment,
24314
+ updateComment: updateComment,
24315
+ deleteComment: deleteComment,
24316
+ softDeleteComment: softDeleteComment,
24317
+ hardDeleteComment: hardDeleteComment,
24318
+ flagComment: flagComment,
24319
+ unflagComment: unflagComment,
24320
+ isCommentFlaggedByMe: isCommentFlaggedByMe,
24321
+ onCommentCreated: onCommentCreated,
24322
+ onCommentUpdated: onCommentUpdated,
24323
+ onCommentDeleted: onCommentDeleted,
24324
+ onCommentFlagged: onCommentFlagged,
24325
+ onCommentUnflagged: onCommentUnflagged,
24326
+ onCommentReactionAdded: onCommentReactionAdded,
24327
+ onCommentReactionRemoved: onCommentReactionRemoved,
24328
+ getComment: getComment,
24329
+ getComments: getComments
24330
+ });
24331
+
24332
+ const getPost$1 = async (postId) => {
24333
+ const client = getActiveClient();
24334
+ client.log('post/getPost', postId);
24335
+ isInTombstone('post', postId);
24336
+ let payload;
24337
+ try {
24338
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
24339
+ const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
24340
+ payload = response.data;
24341
+ }
24342
+ catch (error) {
24343
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
24344
+ pushToTombstone('post', postId);
24345
+ }
24346
+ throw error;
24347
+ }
24348
+ const data = prepareMembershipPayload(payload, 'communityUsers');
24349
+ const cachedAt = client.cache && Date.now();
24350
+ if (client.cache)
24351
+ ingestInCache(data, { cachedAt });
24352
+ const { posts } = data;
24353
+ const result = posts.find(post => post.postId === postId);
24354
+ return {
24355
+ data: result,
24356
+ cachedAt,
24357
+ };
24358
+ };
24359
+ getPost$1.locally = (postId) => {
24360
+ const client = getActiveClient();
24361
+ client.log('post/getPost.locally', postId);
24362
+ if (!client.cache)
24363
+ return;
24364
+ const cached = pullFromCache(['post', 'get', postId]);
24365
+ if (!cached)
24366
+ return;
24367
+ return {
24368
+ data: cached.data,
24369
+ cachedAt: cached.cachedAt,
24370
+ };
24371
+ };
24372
+
24373
+ /**
24374
+ * ```js
24375
+ * import { onLocalPostDeleted } from '@amityco/ts-sdk-react-native'
24376
+ * const dispose = onLocalPostDeleted(post => {
24377
+ * // ...
24378
+ * })
24379
+ * ```
24380
+ *
24381
+ * Fired when a {@link Amity.InternalPost} has been deleted
24382
+ *
24383
+ * @param callback The function to call when the event was fired
24384
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24385
+ *
24386
+ * @category Post Events
24387
+ */
24388
+ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
24389
+
24390
+ /**
24391
+ * ```js
24392
+ * import { onLocalPostReactionAdded } from '@amityco/ts-sdk-react-native'
24393
+ * const dispose = onPostReactionAdded(post => {
24394
+ * // ...
24395
+ * })
24396
+ * ```
24397
+ *
24398
+ * Fired when a {@link Amity.InternalPost} has been reacted
24399
+ *
24400
+ * @param callback The function to call when the event was fired
24401
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24402
+ *
24403
+ * @category Post Events
24404
+ */
24405
+ const onLocalPostReactionAdded = (callback) => {
24406
+ const client = getActiveClient();
24407
+ const filter = ({ post }) => {
24408
+ if (!client.cache) {
24409
+ callback(post);
24067
24410
  }
24068
- throw error;
24411
+ else {
24412
+ upsertInCache(['post', 'get', post.postId], post);
24413
+ callback(post);
24414
+ }
24415
+ };
24416
+ return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
24417
+ };
24418
+
24419
+ /**
24420
+ * ```js
24421
+ * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk-react-native'
24422
+ * const dispose = onPostReactionRemoved(post => {
24423
+ * // ...
24424
+ * })
24425
+ * ```
24426
+ *
24427
+ * Fired when a {@link Amity.InternalPost} has been reacted
24428
+ *
24429
+ * @param callback The function to call when the event was fired
24430
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24431
+ *
24432
+ * @category Post Events
24433
+ */
24434
+ const onLocalPostReactionRemoved = (callback) => {
24435
+ const client = getActiveClient();
24436
+ const filter = ({ post }) => {
24437
+ if (!client.cache) {
24438
+ callback(post);
24439
+ }
24440
+ else {
24441
+ upsertInCache(['post', 'get', post.postId], post);
24442
+ callback(post);
24443
+ }
24444
+ };
24445
+ return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
24446
+ };
24447
+
24448
+ /**
24449
+ * ```js
24450
+ * import { onPostUpdatedLocal } from '@amityco/ts-sdk-react-native'
24451
+ * const dispose = onPostUpdatedLocal(post => {
24452
+ * // ...
24453
+ * })
24454
+ * ```
24455
+ *
24456
+ * Fired when a {@link Amity.InternalPost} has been updated
24457
+ *
24458
+ * @param callback The function to call when the event was fired
24459
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24460
+ *
24461
+ * @category Post Events
24462
+ */
24463
+ const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
24464
+
24465
+ const commentEventHandler$1 = (callback, eventHandler, cacheKey) => {
24466
+ return eventHandler(async (comment) => {
24467
+ var _a;
24468
+ const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24469
+ if (!currentCollection || !currentCollection.data.includes(comment.referenceId))
24470
+ return;
24471
+ await getPost$1(comment.referenceId);
24472
+ callback(comment);
24473
+ });
24474
+ };
24475
+ const generateCommentSubscriptions$1 = (cacheKey) => {
24476
+ const eventHandlers = [
24477
+ onCommentCreated,
24478
+ onCommentDeleted,
24479
+ onCommentReactionAdded,
24480
+ onCommentReactionRemoved,
24481
+ onCommentCreatedLocal,
24482
+ onCommentDeleteLocal,
24483
+ onLocalCommentReactionAdded,
24484
+ onLocalCommentReactionRemoved,
24485
+ ];
24486
+ return eventHandlers.map(handler => ({
24487
+ fn: convertEventPayload((callback) => commentEventHandler$1(callback, handler, cacheKey), 'referenceId', 'post'),
24488
+ action: EnumPostActions.OnPostUpdated,
24489
+ }));
24490
+ };
24491
+ const getGlobalFeedSubscriptions = (cacheKey) => {
24492
+ return [
24493
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
24494
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
24495
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
24496
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
24497
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
24498
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
24499
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
24500
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
24501
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
24502
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
24503
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
24504
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
24505
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
24506
+ ...generateCommentSubscriptions$1(cacheKey),
24507
+ ];
24508
+ };
24509
+
24510
+ class CustomRankingGlobalFeedLiveCollectionController extends LiveCollectionController {
24511
+ constructor(query, callback) {
24512
+ const queryStreamId = hash__default["default"](query);
24513
+ const cacheKey = ['customRankingGlobalFeed', 'collection', queryStreamId];
24514
+ const paginationController = new CustomRankingGlobalFeedPaginationController(query);
24515
+ super(paginationController, queryStreamId, cacheKey, callback);
24516
+ this.query = query;
24517
+ this.queryStreamController = new CustomRankingGlobalFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
24518
+ this.callback = callback.bind(this);
24519
+ this.loadPage({ initial: true });
24069
24520
  }
24070
- const cachedAt = client.cache && Date.now();
24071
- if (client.cache) {
24072
- ingestInCache(data, { cachedAt });
24521
+ setup() {
24522
+ var _a;
24523
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24524
+ if (!collection) {
24525
+ pushToCache(this.cacheKey, {
24526
+ data: [],
24527
+ params: {},
24528
+ });
24529
+ }
24530
+ }
24531
+ async persistModel(queryPayload) {
24532
+ await this.queryStreamController.saveToMainDB(queryPayload);
24533
+ }
24534
+ persistQueryStream({ response, direction, refresh, }) {
24535
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
24536
+ }
24537
+ startSubscription() {
24538
+ return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
24539
+ }
24540
+ notifyChange({ origin, loading, error }) {
24541
+ var _a, _b;
24542
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24543
+ if (!collection)
24544
+ return;
24545
+ const data = ((_b = collection.data
24546
+ .map(id => pullFromCache(['post', 'get', id]))
24547
+ .filter(isNonNullable)
24548
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
24549
+ if (!this.shouldNotify(data) && origin === 'event')
24550
+ return;
24551
+ this.callback({
24552
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
24553
+ data,
24554
+ hasNextPage: !!this.paginationController.getNextToken(),
24555
+ loading,
24556
+ error,
24557
+ });
24558
+ }
24559
+ }
24560
+
24561
+ /* begin_public_function
24562
+ id: feed.query.custom_ranking_feed
24563
+ */
24564
+ /**
24565
+ * ```js
24566
+ * import { FeedRepository } from '@amityco/ts-sdk'
24567
+ *
24568
+ * let posts = []
24569
+ * const unsub = FeedRepository.getGlobalFeed({
24570
+ * dataTypes: ['video','image'],
24571
+ * resolveParent: true,
24572
+ * }, response => processResponse(response))
24573
+ * ```
24574
+ *
24575
+ * Observe all mutations on a list of {@link Amity.Post} for a given target object
24576
+ *
24577
+ * @param params.dataTypes array of data types for the posts
24578
+ * @param callback the function to call when new data are available
24579
+ * @param config
24580
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
24581
+ *
24582
+ * @category Posts Live Collection
24583
+ */
24584
+ const getCustomRankingGlobalFeed = (params, callback, config) => {
24585
+ const { log, cache } = getActiveClient();
24586
+ if (!cache) {
24587
+ console.log(ENABLE_CACHE_MESSAGE);
24588
+ }
24589
+ const timestamp = Date.now();
24590
+ log(`getCustomRankingGlobalFeed(tmpid: ${timestamp}) > listen`);
24591
+ const liveCollection = new CustomRankingGlobalFeedLiveCollectionController(params, callback);
24592
+ const disposers = liveCollection.startSubscription();
24593
+ const cacheKey = liveCollection.getCacheKey();
24594
+ disposers.push(() => dropFromCache(cacheKey));
24595
+ return () => {
24596
+ log(`getCustomRankingGlobalFeed(tmpid: ${timestamp}) > dispose`);
24597
+ disposers.forEach(fn => fn());
24598
+ };
24599
+ };
24600
+ /* end_public_function */
24601
+
24602
+ class GlobalFeedPaginationController extends PaginationController {
24603
+ async getRequest(queryParams, token) {
24604
+ const { limit, resolveParent } = queryParams, params = __rest(queryParams, ["limit", "resolveParent"]);
24605
+ const options = token ? { token } : { limit };
24606
+ const { data: queryResponse } = await this.http.get(`/api/v4/me/global-feeds`, {
24607
+ params: Object.assign(Object.assign({}, params), { resolveParent: resolveParent !== null && resolveParent !== void 0 ? resolveParent : true, options }),
24608
+ });
24609
+ return queryResponse;
24610
+ }
24611
+ }
24612
+
24613
+ class GlobalFeedQueryStreamController extends QueryStreamController {
24614
+ constructor(query, cacheKey, notifyChange, preparePayload) {
24615
+ super(query, cacheKey);
24616
+ this.notifyChange = notifyChange;
24617
+ this.preparePayload = preparePayload;
24618
+ }
24619
+ async saveToMainDB(response) {
24620
+ const processedPayload = await this.preparePayload(response);
24621
+ const client = getActiveClient();
24622
+ const cachedAt = client.cache && Date.now();
24623
+ if (client.cache) {
24624
+ ingestInCache(processedPayload, { cachedAt });
24625
+ }
24626
+ }
24627
+ appendToQueryStream(response, direction, refresh = false) {
24628
+ var _a, _b;
24629
+ if (refresh) {
24630
+ pushToCache(this.cacheKey, {
24631
+ data: response.posts.map(getResolver('post')),
24632
+ });
24633
+ }
24634
+ else {
24635
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24636
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
24637
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
24638
+ }
24639
+ }
24640
+ reactor(action) {
24641
+ return (post) => {
24642
+ var _a;
24643
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24644
+ if (!collection)
24645
+ return;
24646
+ if (post.parentPostId && !collection.data.includes(post.parentPostId))
24647
+ return;
24648
+ // Delete Action
24649
+ if (action === EnumPostActions.OnPostDeleted) {
24650
+ // Parent Post - Remove from collection
24651
+ collection.data = collection.data.filter(postId => postId !== post.postId);
24652
+ }
24653
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
24654
+ // If the query has dataTypes array with value, check if post.dataType is include in the array
24655
+ if (this.query.dataTypes && this.query.dataTypes.length > 0) {
24656
+ if (!this.query.dataTypes.includes(post.dataType))
24657
+ return;
24658
+ }
24659
+ collection.data = [...new Set([post.postId, ...collection.data])];
24660
+ }
24661
+ if (action === EnumPostActions.OnPostDeclined) {
24662
+ collection.data = collection.data.filter(postId => postId !== post.postId);
24663
+ }
24664
+ pushToCache(this.cacheKey, collection);
24665
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
24666
+ };
24667
+ }
24668
+ subscribeRTE(createSubscriber) {
24669
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
24670
+ }
24671
+ }
24672
+
24673
+ class GlobalFeedLiveCollectionController extends LiveCollectionController {
24674
+ constructor(query, callback) {
24675
+ const queryStreamId = hash__default["default"](query);
24676
+ const cacheKey = ['globalFeed', 'collection', queryStreamId];
24677
+ const paginationController = new GlobalFeedPaginationController(query);
24678
+ super(paginationController, queryStreamId, cacheKey, callback);
24679
+ this.query = query;
24680
+ this.queryStreamController = new GlobalFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
24681
+ this.callback = callback.bind(this);
24682
+ this.loadPage({ initial: true });
24683
+ }
24684
+ setup() {
24685
+ var _a;
24686
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24687
+ if (!collection) {
24688
+ pushToCache(this.cacheKey, {
24689
+ data: [],
24690
+ params: {},
24691
+ });
24692
+ }
24693
+ }
24694
+ async persistModel(queryPayload) {
24695
+ await this.queryStreamController.saveToMainDB(queryPayload);
24696
+ }
24697
+ persistQueryStream({ response, direction, refresh, }) {
24698
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
24699
+ }
24700
+ startSubscription() {
24701
+ return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
24073
24702
  }
24074
- return {
24075
- data: data.stories[0],
24076
- cachedAt,
24077
- };
24078
- };
24079
- getStoryByStoryId$1.locally = (storyId) => {
24080
- const client = getActiveClient();
24081
- client.log('story/getStorybyStoryId', storyId);
24082
- // Get story referenceId from cache
24083
- const cacheReferenceId = pullFromCache([
24084
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
24085
- storyId,
24086
- ]);
24087
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
24088
- const { data: referenceId } = cacheReferenceId;
24089
- isInTombstone('story', referenceId);
24703
+ notifyChange({ origin, loading, error }) {
24704
+ var _a, _b;
24705
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24706
+ if (!collection)
24707
+ return;
24708
+ const data = ((_b = collection.data
24709
+ .map(id => pullFromCache(['post', 'get', id]))
24710
+ .filter(isNonNullable)
24711
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
24712
+ if (!this.shouldNotify(data) && origin === 'event')
24713
+ return;
24714
+ this.callback({
24715
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
24716
+ data,
24717
+ hasNextPage: !!this.paginationController.getNextToken(),
24718
+ loading,
24719
+ error,
24720
+ });
24090
24721
  }
24091
- const cachedAt = client.cache && Date.now();
24092
- const storyCache = pullFromCache(['story', 'get', storyId]);
24093
- if (!storyCache)
24094
- return;
24095
- return {
24096
- data: storyCache.data,
24097
- cachedAt,
24098
- };
24099
- };
24722
+ }
24100
24723
 
24101
24724
  /* begin_public_function
24102
- id: comment.soft_delete, comment.hard_delete
24725
+ id: feed.query.global_feed
24103
24726
  */
24104
24727
  /**
24105
24728
  * ```js
24106
- * import { CommentRepository } from '@amityco/ts-sdk-react-native'
24107
- * const success = await CommentRepository.deleteComment('foobar')
24108
- * ```
24729
+ * import { FeedRepository } from '@amityco/ts-sdk'
24109
24730
  *
24110
- * Deletes a {@link Amity.Comment}
24731
+ * let posts = []
24732
+ * const unsub = FeedRepository.getGlobalFeed({
24733
+ * dataTypes: ['video','image'],
24734
+ * resolveParent: true,
24735
+ * }, response => processResponse(response))
24736
+ * ```
24111
24737
  *
24112
- * @param commentId The {@link Amity.Comment} ID to delete
24113
- * @return A success boolean if the {@link Amity.Comment} was deleted
24738
+ * Observe all mutations on a list of {@link Amity.Post} for global feed
24739
+ * @param params.dataTypes array of data types for the posts
24740
+ * @param params.resolveParent
24741
+ * @param callback the function to call when new data are available
24742
+ * @param config
24743
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
24114
24744
  *
24115
- * @category Comment API
24116
- * @async
24745
+ * @category Posts Live Collection
24117
24746
  */
24118
- const deleteComment = async (commentId, permanent = false) => {
24119
- var _a;
24120
- const client = getActiveClient();
24121
- const comment = await getComment$2(commentId);
24122
- // API-FIX: This endpoint has not been implemented yet.
24123
- await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
24124
- params: {
24125
- commentId,
24126
- permanent,
24127
- },
24128
- });
24129
- // to support hard deletion
24130
- const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
24131
- if (comment.data.referenceType === 'story') {
24132
- const story = await getStoryByStoryId$1(comment.data.referenceId);
24133
- fireEvent('local.story.updated', {
24134
- stories: [story.data],
24135
- categories: [],
24136
- comments: [],
24137
- communities: [],
24138
- communityUsers: [],
24139
- files: [],
24140
- users: [],
24747
+ const getGlobalFeed = (params, callback, config) => {
24748
+ const { log, cache } = getActiveClient();
24749
+ if (!cache) {
24750
+ console.log(ENABLE_CACHE_MESSAGE);
24751
+ }
24752
+ const timestamp = Date.now();
24753
+ log(`getGlobalFeed(tmpid: ${timestamp}) > listen`);
24754
+ const liveCollection = new GlobalFeedLiveCollectionController(params, callback);
24755
+ const disposers = liveCollection.startSubscription();
24756
+ const cacheKey = liveCollection.getCacheKey();
24757
+ disposers.push(() => dropFromCache(cacheKey));
24758
+ return () => {
24759
+ log(`getGlobalFeed(tmpid: ${timestamp}) > dispose`);
24760
+ disposers.forEach(fn => fn());
24761
+ };
24762
+ };
24763
+ /* end_public_function */
24764
+
24765
+ class UserFeedPaginationController extends PaginationController {
24766
+ async getRequest(queryParams, token) {
24767
+ const { userId, feedSources, dataTypes, includeDeleted, matchingOnlyParentPost, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["userId", "feedSources", "dataTypes", "includeDeleted", "matchingOnlyParentPost", "limit"]);
24768
+ const options = token ? { token } : { limit };
24769
+ const { data: queryResponse } = await this.http.get(`/api/v4/user-feeds/${userId}`, {
24770
+ 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) }),
24141
24771
  });
24772
+ return queryResponse;
24142
24773
  }
24143
- else {
24144
- const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
24145
- if (post) {
24146
- let removeCount;
24147
- if (!deleted.parentId) {
24148
- // NOTE: delete the parent comment will remove all children comments
24149
- removeCount = deleted.childrenNumber + 1;
24774
+ }
24775
+
24776
+ class UserFeedQueryStreamController extends QueryStreamController {
24777
+ constructor(query, cacheKey, notifyChange, preparePayload) {
24778
+ super(query, cacheKey);
24779
+ this.notifyChange = notifyChange;
24780
+ this.preparePayload = preparePayload;
24781
+ }
24782
+ async saveToMainDB(response) {
24783
+ const processedPayload = await this.preparePayload(response);
24784
+ const client = getActiveClient();
24785
+ const cachedAt = client.cache && Date.now();
24786
+ if (client.cache) {
24787
+ ingestInCache(processedPayload, { cachedAt });
24788
+ }
24789
+ }
24790
+ appendToQueryStream(response, direction, refresh = false) {
24791
+ var _a, _b;
24792
+ if (refresh) {
24793
+ pushToCache(this.cacheKey, {
24794
+ data: response.posts.map(getResolver('post')),
24795
+ });
24796
+ }
24797
+ else {
24798
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24799
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
24800
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
24801
+ }
24802
+ }
24803
+ reactor(action) {
24804
+ return (post) => {
24805
+ var _a, _b;
24806
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24807
+ if (!collection)
24808
+ return;
24809
+ // if the collection is parent post collection and
24810
+ // post is not included in the collection or post is child post
24811
+ if ((!this.query.dataTypes || this.query.dataTypes.length === 0) &&
24812
+ !collection.data.includes(post.parentPostId ? post.parentPostId : post.postId))
24813
+ return;
24814
+ if (action === EnumPostActions.OnPostDeleted) {
24815
+ collection.data = collection.data.filter(postId => postId !== post.postId);
24150
24816
  }
24151
- else
24152
- removeCount = 1;
24153
- post.commentsCount -= removeCount;
24154
- fireEvent('local.post.updated', {
24155
- posts: [post],
24156
- categories: [],
24157
- comments: [],
24158
- communities: [],
24159
- communityUsers: [],
24160
- feeds: [],
24161
- files: [],
24162
- postChildren: [],
24163
- users: [],
24164
- videoStreamings: [],
24817
+ if (post.parentPostId && post.isDeleted) {
24818
+ const parentPost = (_b = pullFromCache([
24819
+ 'post',
24820
+ 'get',
24821
+ post.parentPostId,
24822
+ ])) === null || _b === void 0 ? void 0 : _b.data;
24823
+ if (!parentPost)
24824
+ return;
24825
+ parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
24826
+ pushToCache(['post', 'get', parentPost.postId], parentPost);
24827
+ }
24828
+ if (action === EnumPostActions.OnPostDeclined) {
24829
+ collection.data = collection.data.filter(postId => postId !== post.postId);
24830
+ }
24831
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
24832
+ if (this.query.dataTypes &&
24833
+ this.query.dataTypes.length > 0 &&
24834
+ !this.query.dataTypes.includes(post.dataType)) {
24835
+ return;
24836
+ }
24837
+ collection.data = [...new Set([post.postId, ...collection.data])];
24838
+ }
24839
+ pushToCache(this.cacheKey, collection);
24840
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
24841
+ };
24842
+ }
24843
+ subscribeRTE(createSubscriber) {
24844
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
24845
+ }
24846
+ }
24847
+
24848
+ class UserFeedLiveCollectionController extends LiveCollectionController {
24849
+ constructor(query, callback) {
24850
+ const queryStreamId = hash__default["default"](query);
24851
+ const cacheKey = ['userFeed', 'collection', queryStreamId];
24852
+ const paginationController = new UserFeedPaginationController(query);
24853
+ super(paginationController, queryStreamId, cacheKey, callback);
24854
+ this.query = query;
24855
+ this.queryStreamController = new UserFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
24856
+ this.callback = callback.bind(this);
24857
+ this.loadPage({ initial: true });
24858
+ }
24859
+ setup() {
24860
+ var _a;
24861
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24862
+ if (!collection) {
24863
+ pushToCache(this.cacheKey, {
24864
+ data: [],
24865
+ params: {},
24165
24866
  });
24166
24867
  }
24167
24868
  }
24168
- fireEvent('local.comment.deleted', {
24169
- comments: [deleted],
24170
- commentChildren: [],
24171
- files: [],
24172
- users: [],
24173
- communityUsers: [],
24174
- });
24175
- if (permanent) {
24176
- scheduleTask(() => pushToTombstone('comment', commentId));
24869
+ async persistModel(queryPayload) {
24870
+ await this.queryStreamController.saveToMainDB(queryPayload);
24177
24871
  }
24178
- else {
24179
- upsertInCache(['comment', 'get', commentId], { isDeleted: true });
24872
+ persistQueryStream({ response, direction, refresh, }) {
24873
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
24874
+ }
24875
+ startSubscription() {
24876
+ return this.queryStreamController.subscribeRTE([
24877
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
24878
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
24879
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
24880
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
24881
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
24882
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
24883
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
24884
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
24885
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
24886
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
24887
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
24888
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
24889
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
24890
+ {
24891
+ fn: convertEventPayload((callback) => {
24892
+ return onCommentCreated(async (comment) => {
24893
+ var _a;
24894
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24895
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
24896
+ return;
24897
+ await getPost$1(comment.referenceId);
24898
+ callback(comment);
24899
+ });
24900
+ }, 'referenceId', 'post'),
24901
+ action: EnumPostActions.OnPostUpdated,
24902
+ },
24903
+ {
24904
+ fn: convertEventPayload((callback) => {
24905
+ return onCommentDeleted(async (comment) => {
24906
+ var _a;
24907
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24908
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
24909
+ return;
24910
+ await getPost$1(comment.referenceId);
24911
+ callback(comment);
24912
+ });
24913
+ }, 'referenceId', 'post'),
24914
+ action: EnumPostActions.OnPostUpdated,
24915
+ },
24916
+ ]);
24917
+ }
24918
+ notifyChange({ origin, loading, error }) {
24919
+ var _a, _b;
24920
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24921
+ if (!collection)
24922
+ return;
24923
+ const data = ((_b = collection.data
24924
+ .map(id => pullFromCache(['post', 'get', id]))
24925
+ .filter(isNonNullable)
24926
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
24927
+ if (!this.shouldNotify(data) && origin === 'event')
24928
+ return;
24929
+ this.callback({
24930
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
24931
+ data,
24932
+ hasNextPage: !!this.paginationController.getNextToken(),
24933
+ loading,
24934
+ error,
24935
+ });
24180
24936
  }
24181
- return deleted;
24182
- };
24183
- /* end_public_function */
24937
+ }
24184
24938
 
24185
24939
  /* begin_public_function
24186
- id: comment.soft_delete
24940
+ id: feed.query.user_feed
24187
24941
  */
24188
24942
  /**
24189
24943
  * ```js
24190
- * import { CommentRepository } from '@amityco/ts-sdk-react-native'
24191
- * const success = await CommentRepository.softDeleteComment('foobar')
24192
- * ```
24944
+ * import { FeedRepository } from '@amityco/ts-sdk'
24193
24945
  *
24194
- * Deletes a {@link Amity.Comment}
24195
- *
24196
- * @param commentId The {@link Amity.Comment} ID to delete
24197
- * @return A success boolean if the {@link Amity.Comment} was deleted
24198
- *
24199
- * @category Comment API
24200
- * @async
24201
- */
24202
- const softDeleteComment = async (commentId) => {
24203
- const client = getActiveClient();
24204
- client.log('comment/softDeleteComment', commentId);
24205
- const softDeleted = deleteComment(commentId);
24206
- return softDeleted;
24207
- };
24208
- /* end_public_function */
24209
-
24210
- /* begin_public_function
24211
- id: comment.hard_delete
24212
- */
24213
- /**
24214
- * ```js
24215
- * import { CommentRepository } from '@amityco/ts-sdk-react-native'
24216
- * const success = await CommentRepository.hardDeleteComment('foobar')
24946
+ * let posts = []
24947
+ * const unsubscribe = FeedRepository.getUserFeed({
24948
+ * userId: string,
24949
+ * feedSources: ['user', 'community'],
24950
+ * }, response => response => processResponse(response))
24217
24951
  * ```
24218
24952
  *
24219
- * Deletes a {@link Amity.Comment}
24953
+ * Observe all mutations on a list of {@link Amity.Post} for a given user and feedSources
24220
24954
  *
24221
- * @param commentId The {@link Amity.Comment} ID to delete
24222
- * @return A success boolean if the {@link Amity.Comment} was deleted
24955
+ * @param params.userId the ID of the user
24956
+ * @param params.feedSources the sources of the feed
24957
+ * @param callback the function to call when new data are available
24958
+ * @param config
24959
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
24223
24960
  *
24224
- * @category Comment API
24225
- * @async
24961
+ * @category Posts Live Collection
24226
24962
  */
24227
- const hardDeleteComment = async (commentId) => {
24228
- const client = getActiveClient();
24229
- client.log('comment/hardDeleteComment', commentId);
24230
- const hardDeleted = deleteComment(commentId, true);
24231
- return hardDeleted;
24232
- };
24233
- /* end_public_function */
24234
-
24235
- /* begin_public_function
24236
- id: comment.flag
24237
- */
24238
- /**
24239
- * ```js
24240
- * import { CommentRepository } from '@amityco/ts-sdk-react-native'
24241
- * const flagged = await CommentRepository.flagComment(commentId, reason)
24242
- * ```
24243
- *
24244
- * @param commentId The ID of the comment to flag
24245
- * @param reason the reason to flag the comment
24246
- * @returns the created report result
24247
- *
24248
- * @category Comment API
24249
- * @async
24250
- * */
24251
- const flagComment = async (commentId, reason) => {
24252
- const client = getActiveClient();
24253
- client.log('comment/flagComment', commentId);
24254
- const isPredefinedReason = reason &&
24255
- Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
24256
- const body = {
24257
- reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
24258
- detail: reason && !isPredefinedReason ? reason : '',
24259
- };
24260
- const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
24261
- if (client.cache) {
24262
- ingestInCache(payload);
24963
+ const getUserFeed = (params, callback, config) => {
24964
+ const { log, cache } = getActiveClient();
24965
+ if (!cache) {
24966
+ console.log(ENABLE_CACHE_MESSAGE);
24263
24967
  }
24264
- fireEvent('comment.flagged', payload);
24265
- return !!payload;
24968
+ const timestamp = Date.now();
24969
+ log(`getUserFeed(tmpid: ${timestamp}) > listen`);
24970
+ const userFeedLiveCollection = new UserFeedLiveCollectionController(params, callback);
24971
+ const disposers = userFeedLiveCollection.startSubscription();
24972
+ const cacheKey = userFeedLiveCollection.getCacheKey();
24973
+ disposers.push(() => dropFromCache(cacheKey));
24974
+ return () => {
24975
+ log(`getUserFeed(tmpid: ${timestamp}) > dispose`);
24976
+ disposers.forEach(fn => fn());
24977
+ };
24266
24978
  };
24267
24979
  /* end_public_function */
24268
24980
 
24269
- /* begin_public_function
24270
- id: comment.unflag
24271
- */
24272
- /**
24273
- * ```js
24274
- * import { CommentRepository } from '@amityco/ts-sdk-react-native'
24275
- * const unflagged = await CommentRepository.unflagComment('commentId')
24276
- * ```
24277
- *
24278
- * @param commentId The ID of comment to unflag
24279
- * @returns the unflagged result
24280
- *
24281
- * @category Comment API
24282
- * @async
24283
- * */
24284
- const unflagComment = async (commentId) => {
24285
- const client = getActiveClient();
24286
- client.log('comment/unflagComment', commentId);
24287
- const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
24288
- if (client.cache) {
24289
- ingestInCache(payload);
24290
- }
24291
- fireEvent('comment.unflagged', payload);
24292
- return !!payload;
24293
- };
24294
- /* end_public_function */
24981
+ var index$9 = /*#__PURE__*/Object.freeze({
24982
+ __proto__: null,
24983
+ queryGlobalFeed: queryGlobalFeed,
24984
+ getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
24985
+ getGlobalFeed: getGlobalFeed,
24986
+ getUserFeed: getUserFeed
24987
+ });
24295
24988
 
24296
24989
  /* begin_public_function
24297
- id: comment.check_flag_by_me
24990
+ id: post.get_by_ids
24298
24991
  */
24299
24992
  /**
24300
24993
  * ```js
24301
- * import { CommentRepository } from '@amityco/ts-sdk-react-native'
24302
- * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
24994
+ * import { getPostByIds } from '@amityco/ts-sdk-react-native'
24995
+ * const { data: posts } = await getPostByIds(['foo', 'bar'])
24303
24996
  * ```
24304
24997
  *
24305
- * @param commentId The ID of the comment to check if flagged by current user
24306
- * @returns `true` if the comment is flagged by me, `false` if doesn't.
24998
+ * Fetches a collection of {@link Amity.Post} objects
24307
24999
  *
24308
- * @category Comment API
25000
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
25001
+ * @returns the associated collection of {@link Amity.Post} objects
25002
+ *
25003
+ * @category Post API
24309
25004
  * @async
24310
- * */
24311
- const isCommentFlaggedByMe = async (commentId) => {
24312
- const client = getActiveClient();
24313
- client.log('comment/isCommentFlaggedByMe', commentId);
24314
- const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
24315
- return result;
24316
- };
24317
- /* end_public_function */
24318
-
24319
- const getComment$1 = async (commentId) => {
25005
+ */
25006
+ const getPostByIds = async (postIds) => {
24320
25007
  const client = getActiveClient();
24321
- client.log('comment/getComment', commentId);
24322
- isInTombstone('comment', commentId);
24323
- let data;
25008
+ client.log('post/getPostByIds', postIds);
25009
+ const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
25010
+ let payload;
24324
25011
  try {
24325
25012
  // API-FIX: endpoint should not be /list, parameters should be querystring.
24326
- const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
24327
- data = response.data;
25013
+ const response = await client.http.get(`/api/v3/posts/list`, {
25014
+ params: { postIds: encodedPostIds },
25015
+ });
25016
+ payload = response.data;
24328
25017
  }
24329
25018
  catch (error) {
24330
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
24331
- pushToTombstone('comment', commentId);
24332
- }
25019
+ postIds.forEach(postId => {
25020
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
25021
+ pushToTombstone('post', postId);
25022
+ }
25023
+ });
24333
25024
  throw error;
24334
25025
  }
25026
+ const data = prepareMembershipPayload(payload, 'communityUsers');
24335
25027
  const cachedAt = client.cache && Date.now();
24336
25028
  if (client.cache)
24337
25029
  ingestInCache(data, { cachedAt });
24338
- const { comments } = data;
24339
25030
  return {
24340
- data: comments.find(comment => comment.commentId === commentId),
25031
+ data: data.posts.map(LinkedObject.post),
24341
25032
  cachedAt,
24342
25033
  };
24343
25034
  };
24344
- getComment$1.locally = (commentId) => {
25035
+ /* end_public_function */
25036
+ /**
25037
+ * ```js
25038
+ * import { getPostByIds } from '@amityco/ts-sdk-react-native'
25039
+ * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
25040
+ * ```
25041
+ *
25042
+ * Fetches a collection of {@link Amity.Post} objects from cache
25043
+ *
25044
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
25045
+ * @returns the associated collection of {@link Amity.Post} objects
25046
+ *
25047
+ * @category Post API
25048
+ */
25049
+ getPostByIds.locally = (postIds) => {
25050
+ var _a;
24345
25051
  const client = getActiveClient();
24346
- client.log('comment/getComment.locally', commentId);
25052
+ client.log('post/getPostByIds.locally', postIds);
24347
25053
  if (!client.cache)
24348
25054
  return;
24349
- const cached = pullFromCache(['comment', 'get', commentId]);
24350
- if (!cached)
25055
+ const cached = postIds
25056
+ .map(postId => pullFromCache(['post', 'get', postId]))
25057
+ .filter(Boolean);
25058
+ const posts = cached.map(({ data }) => data);
25059
+ const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
25060
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
24351
25061
  return;
24352
25062
  return {
24353
- data: cached.data,
24354
- cachedAt: cached.cachedAt,
25063
+ data: posts.map(LinkedObject.post),
25064
+ cachedAt: oldest.cachedAt,
24355
25065
  };
24356
25066
  };
24357
25067
 
25068
+ /* begin_public_function
25069
+ 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
25070
+ */
24358
25071
  /**
24359
25072
  * ```js
24360
- * import { onCommentDeleteLocal } from '@amityco/ts-sdk-react-native'
24361
- * const dispose = onCommentDeleteLocal(comment => {
24362
- * // ...
24363
- * })
25073
+ * import { PostRepository } from '@amityco/ts-sdk-react-native'
25074
+ * const created = await PostRepository.createPost({
25075
+ * targetType: 'user',
25076
+ * targetId: 'foobar',
25077
+ * data: { text: 'hello world' }
25078
+ * }))
24364
25079
  * ```
24365
25080
  *
24366
- * Fired when a {@link Amity.InternalComment} has been deleted
25081
+ * Creates an {@link Amity.Post}
24367
25082
  *
24368
- * @param callback The function to call when the event was fired
24369
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25083
+ * @param bundle The data necessary to create a new {@link Amity.Post}
25084
+ * @returns The newly created {@link Amity.Post}
24370
25085
  *
24371
- * @category Comment Events
25086
+ * @category Post API
25087
+ * @async
24372
25088
  */
24373
- const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
25089
+ const createPost = async (bundle) => {
25090
+ const client = getActiveClient();
25091
+ client.log('post/createPost', bundle);
25092
+ if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
25093
+ // eslint-disable-next-line no-param-reassign
25094
+ delete bundle.dataType;
25095
+ }
25096
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
25097
+ fireEvent('post.created', payload);
25098
+ const data = preparePostPayload(payload);
25099
+ const cachedAt = client.cache && Date.now();
25100
+ if (client.cache)
25101
+ ingestInCache(data, { cachedAt });
25102
+ const { posts } = data;
25103
+ return {
25104
+ data: LinkedObject.post(posts[0]),
25105
+ cachedAt,
25106
+ };
25107
+ };
25108
+ /* end_public_function */
24374
25109
 
25110
+ /* begin_public_function
25111
+ id: post.edit, post.edit.custom_post
25112
+ */
24375
25113
  /**
24376
25114
  * ```js
24377
- * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk-react-native'
24378
- * const dispose = onLocalCommentReactionAdded(comment => {
24379
- * // ...
25115
+ * import { PostRepository } from '@amityco/ts-sdk-react-native'
25116
+ * const updated = await PostRepository.editPost(postId, {
25117
+ * data: { text: 'hello world' }
24380
25118
  * })
24381
25119
  * ```
24382
25120
  *
24383
- * Fired when a {@link Amity.InternalComment} has been reacted
25121
+ * Updates an {@link Amity.Post}
24384
25122
  *
24385
- * @param callback The function to call when the event was fired
24386
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25123
+ * @param postId The ID of the {@link Amity.Post} to edit
25124
+ * @param patch The patch data to apply
25125
+ * @returns the updated {@link Amity.Post} object
24387
25126
  *
24388
- * @category Comment Events
25127
+ * @category Post API
25128
+ * @async
24389
25129
  */
24390
- const onLocalCommentReactionAdded = (callback) => {
25130
+ const editPost = async (postId, patch) => {
24391
25131
  const client = getActiveClient();
24392
- const filter = ({ comment }) => {
24393
- if (!client.cache) {
24394
- callback(comment);
24395
- }
24396
- else {
24397
- upsertInCache(['comment', 'get', comment.commentId], comment);
24398
- callback(commentLinkedObject(comment));
24399
- }
25132
+ client.log('user/editPost', patch);
25133
+ const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
25134
+ const data = prepareMembershipPayload(payload, 'communityUsers');
25135
+ const cachedAt = client.cache && Date.now();
25136
+ if (client.cache)
25137
+ ingestInCache(data, { cachedAt });
25138
+ fireEvent('local.post.updated', data);
25139
+ const { posts } = data;
25140
+ return {
25141
+ data: LinkedObject.post(posts.find(post => post.postId === postId)),
25142
+ cachedAt,
24400
25143
  };
24401
- return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
24402
25144
  };
25145
+ /* end_public_function */
24403
25146
 
24404
25147
  /**
24405
25148
  * ```js
24406
- * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk-react-native'
24407
- * const dispose = onLocalCommentReactionRemoved(comment => {
24408
- * // ...
24409
- * })
25149
+ * import { deletePost } from '@amityco/ts-sdk-react-native'
25150
+ * const success = await deletePost('foobar')
24410
25151
  * ```
24411
25152
  *
24412
- * Fired when a {@link Amity.InternalComment} has been reacted
25153
+ * Deletes a {@link Amity.Post}
24413
25154
  *
24414
- * @param callback The function to call when the event was fired
24415
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25155
+ * @param postId The {@link Amity.Post} ID to delete
25156
+ * @return A success boolean if the {@link Amity.Post} was deleted
24416
25157
  *
24417
- * @category Comment Events
25158
+ * @private
25159
+ * @async
24418
25160
  */
24419
- const onLocalCommentReactionRemoved = (callback) => {
25161
+ const deletePost = async (postId, permanent = false) => {
25162
+ var _a;
24420
25163
  const client = getActiveClient();
24421
- const filter = ({ comment }) => {
24422
- if (!client.cache) {
24423
- callback(comment);
24424
- }
24425
- else {
24426
- upsertInCache(['comment', 'get', comment.commentId], comment);
24427
- callback(commentLinkedObject(comment));
24428
- }
24429
- };
24430
- return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
25164
+ const post = await getPost$2(postId);
25165
+ await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
25166
+ params: {
25167
+ postId,
25168
+ permanent,
25169
+ },
25170
+ });
25171
+ // there is currently a limitation which doesn't allow us to fire event to tell that community
25172
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
25173
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
25174
+ // later when realtime events covers that for us.
25175
+ if (post.data.targetType === 'community') {
25176
+ const community = await getCommunity$1(post.data.targetId);
25177
+ const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
25178
+ const communityUsers = communityUsersCache
25179
+ .filter(({ key }) => {
25180
+ // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
25181
+ if (key[0] !== 'communityUsers')
25182
+ return false;
25183
+ if (key[1] !== 'get')
25184
+ return false;
25185
+ if (typeof key[2] === 'string')
25186
+ return key[2].includes(community.data.communityId);
25187
+ return false;
25188
+ })
25189
+ .map(({ data }) => data);
25190
+ fireEvent('community.updated', {
25191
+ communities: [community.data],
25192
+ categories: [],
25193
+ communityUsers,
25194
+ feeds: [],
25195
+ files: [],
25196
+ users: [],
25197
+ });
25198
+ }
25199
+ // to support hard deletion
25200
+ const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
25201
+ if (permanent) {
25202
+ setTimeout(() => {
25203
+ pushToTombstone('post', postId);
25204
+ }, 0);
25205
+ }
25206
+ else {
25207
+ upsertInCache(['post', 'get', postId], { isDeleted: true });
25208
+ }
25209
+ fireEvent('local.post.deleted', {
25210
+ posts: [deleted],
25211
+ categories: [],
25212
+ comments: [],
25213
+ communities: [],
25214
+ communityUsers: [],
25215
+ feeds: [],
25216
+ files: [],
25217
+ postChildren: [],
25218
+ users: [],
25219
+ videoStreamings: [],
25220
+ });
25221
+ return LinkedObject.post(deleted);
24431
25222
  };
24432
25223
 
24433
25224
  /* begin_public_function
24434
- id: comment.get
25225
+ id: post.soft_delete
24435
25226
  */
24436
25227
  /**
24437
25228
  * ```js
24438
- * import { CommentRepository } from '@amityco/ts-sdk-react-native';
24439
- *
24440
- * let comment;
24441
- *
24442
- * const unsub = CommentRepository.getComment(commentId, response => {
24443
- * comment = response.data;
24444
- * });
25229
+ * import { PostRepository } from '@amityco/ts-sdk-react-native'
25230
+ * const success = await PostRepository.softDeletePost('foobar')
24445
25231
  * ```
24446
25232
  *
24447
- * Observe all mutation on a given {@link Amity.Comment}
25233
+ * Soft deletes a {@link Amity.Post}
24448
25234
  *
24449
- * @param commentId the ID of the comment to observe
24450
- * @param callback the function to call when new data are available
24451
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
25235
+ * @param postId The {@link Amity.Post} ID to soft delete
25236
+ * @return A success boolean if the {@link Amity.Post} was deleted
24452
25237
  *
24453
- * @category Comment Live Object
25238
+ * @category Post API
25239
+ * @async
24454
25240
  */
24455
- const getComment = (commentId, callback) => {
24456
- return liveObject(commentId, callback, 'commentId', getComment$1, [
24457
- onCommentDeleteLocal,
24458
- onCommentDeleted,
24459
- onCommentFlagged,
24460
- onCommentReactionAdded,
24461
- onCommentReactionRemoved,
24462
- onCommentUnflagged,
24463
- onCommentUpdated,
24464
- onLocalCommentReactionAdded,
24465
- onLocalCommentReactionRemoved,
24466
- ]);
25241
+ const softDeletePost = async (postId) => {
25242
+ const client = getActiveClient();
25243
+ client.log('post/softDeletePost', postId);
25244
+ const softDeleted = await deletePost(postId, false);
25245
+ return LinkedObject.post(softDeleted);
24467
25246
  };
24468
25247
  /* end_public_function */
24469
25248
 
24470
- class CommentPaginationController extends PaginationController {
24471
- async getRequest(queryParams, token) {
24472
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
24473
- const baseOptions = {
24474
- type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
24475
- };
24476
- const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
24477
- const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
24478
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
24479
- });
24480
- return queryResponse;
24481
- }
24482
- }
24483
-
24484
- var EnumCommentActions;
24485
- (function (EnumCommentActions) {
24486
- EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
24487
- EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
24488
- EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
24489
- EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
24490
- EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
24491
- EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
24492
- EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
24493
- })(EnumCommentActions || (EnumCommentActions = {}));
24494
-
24495
- class CommentQueryStreamController extends QueryStreamController {
24496
- constructor(query, cacheKey, notifyChange, preparePayload) {
24497
- super(query, cacheKey);
24498
- this.notifyChange = notifyChange;
24499
- this.preparePayload = preparePayload;
24500
- }
24501
- async saveToMainDB(response) {
24502
- const processedPayload = await this.preparePayload(response);
24503
- const client = getActiveClient();
24504
- const cachedAt = client.cache && Date.now();
24505
- if (client.cache) {
24506
- ingestInCache(processedPayload, { cachedAt });
24507
- }
24508
- }
24509
- appendToQueryStream(response, direction, refresh = false) {
24510
- var _a, _b;
24511
- if (refresh) {
24512
- pushToCache(this.cacheKey, {
24513
- data: response.comments.map(getResolver('comment')),
24514
- });
24515
- }
24516
- else {
24517
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24518
- const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
24519
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
24520
- }
24521
- }
24522
- reactor(action) {
24523
- return (comment) => {
24524
- var _a;
24525
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24526
- if (this.query.referenceId !== comment.referenceId ||
24527
- this.query.referenceType !== comment.referenceType ||
24528
- !collection) {
24529
- return;
24530
- }
24531
- if (this.query.parentId && this.query.parentId !== comment.parentId) {
24532
- return;
24533
- }
24534
- if (!this.query.parentId && comment.parentId) {
24535
- return;
24536
- }
24537
- if (action === EnumCommentActions.OnCommentCreated) {
24538
- collection.data = [...new Set([comment.commentId, ...collection.data])];
24539
- }
24540
- pushToCache(this.cacheKey, collection);
24541
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
24542
- };
24543
- }
24544
- subscribeRTE(createSubscriber) {
24545
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
24546
- }
24547
- }
25249
+ /* begin_public_function
25250
+ id: post.hard_delete
25251
+ */
25252
+ /**
25253
+ * ```js
25254
+ * import { hardDeletePost } from '@amityco/ts-sdk-react-native'
25255
+ * const success = await hardDeletePost('foobar')
25256
+ * ```
25257
+ *
25258
+ * Hard deletes a {@link Amity.Post}
25259
+ *
25260
+ * @param postId The {@link Amity.Post} ID to be hard delete
25261
+ * @return A success boolean if the {@link Amity.Post} was deleted
25262
+ *
25263
+ * @category Post API
25264
+ * @async
25265
+ */
25266
+ const hardDeletePost = async (postId) => {
25267
+ const client = getActiveClient();
25268
+ client.log('post/hardDeletePost', postId);
25269
+ const hardDeleted = await deletePost(postId, true);
25270
+ return LinkedObject.post(hardDeleted);
25271
+ };
25272
+ /* end_public_function */
24548
25273
 
25274
+ /* begin_public_function
25275
+ id: post.approve
25276
+ */
24549
25277
  /**
24550
25278
  * ```js
24551
- * import { onCommentCreated } from '@amityco/ts-sdk-react-native'
24552
- * const dispose = onCommentCreated(comment => {
24553
- * // ...
24554
- * })
25279
+ * import { approvePost } from '@amityco/ts-sdk-react-native'
25280
+ *
25281
+ * const { data: post } = await approvePost('postId')
24555
25282
  * ```
24556
25283
  *
24557
- * Fired when a {@link Amity.InternalComment} has been created
25284
+ * Approves a {@link Amity.Post}
24558
25285
  *
24559
- * @param callback The function to call when the event was fired
24560
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25286
+ * @param postId The {@link Amity.Post} ID to be approved
25287
+ * @return A {@link Amity.Post} that was approved
24561
25288
  *
24562
- * @category Comment Events
25289
+ * @category Post API
25290
+ * @async
24563
25291
  */
24564
- const onCommentCreatedLocal = (callback) => {
24565
- return createLocalCommentEventSubscriber('local.comment.created', callback);
24566
- };
24567
-
24568
- class CommentLiveCollectionController extends LiveCollectionController {
24569
- constructor(query, callback) {
24570
- const queryStreamId = hash__default["default"](query);
24571
- const cacheKey = ['comments', 'collection', queryStreamId];
24572
- const paginationController = new CommentPaginationController(query);
24573
- super(paginationController, queryStreamId, cacheKey, callback);
24574
- this.query = query;
24575
- this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
24576
- this.callback = callback.bind(this);
24577
- this.loadPage({ initial: true });
24578
- }
24579
- setup() {
24580
- var _a;
24581
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24582
- if (!collection) {
24583
- pushToCache(this.cacheKey, {
24584
- data: [],
24585
- params: {},
24586
- });
24587
- }
24588
- }
24589
- async persistModel(queryPayload) {
24590
- await this.queryStreamController.saveToMainDB(queryPayload);
24591
- }
24592
- persistQueryStream({ response, direction, refresh, }) {
24593
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
24594
- }
24595
- startSubscription() {
24596
- return this.queryStreamController.subscribeRTE([
24597
- { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
24598
- { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
24599
- { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
24600
- { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
24601
- { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
24602
- { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
24603
- { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
24604
- { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
24605
- { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
24606
- { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
24607
- { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
24608
- ]);
24609
- }
24610
- notifyChange({ origin, loading, error }) {
24611
- var _a, _b;
24612
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24613
- if (!collection)
24614
- return;
24615
- const data = this.applyFilter((_b = collection.data
24616
- .map(id => pullFromCache(['comment', 'get', id]))
24617
- .filter(isNonNullable)
24618
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
24619
- if (!this.shouldNotify(data) && origin === 'event')
24620
- return;
24621
- this.callback({
24622
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
24623
- data,
24624
- hasNextPage: !!this.paginationController.getNextToken(),
24625
- loading,
24626
- error,
24627
- });
24628
- }
24629
- applyFilter(data) {
24630
- let comments = data;
24631
- if (!this.query.includeDeleted) {
24632
- comments = filterByPropEquality(comments, 'isDeleted', false);
24633
- }
24634
- if (this.query.parentId) {
24635
- comments = comments.filter(comment => comment.parentId === this.query.parentId);
24636
- }
24637
- if (typeof this.query.hasFlag === 'boolean') {
24638
- if (this.query.hasFlag) {
24639
- comments = comments.filter(comment => comment.hashFlag != null);
24640
- }
24641
- else {
24642
- comments = comments.filter(comment => comment.hashFlag == null);
24643
- }
24644
- }
24645
- if (this.query.dataTypes) {
24646
- if (this.query.dataTypes.matchType === 'exact') {
24647
- comments = comments.filter(comment => {
24648
- var _a, _b;
24649
- const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
24650
- const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
24651
- if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
24652
- return false;
24653
- }
24654
- return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
24655
- });
24656
- }
24657
- if (this.query.dataTypes.matchType === 'any') {
24658
- 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); }); });
24659
- }
24660
- }
24661
- switch (this.query.sortBy) {
24662
- case 'firstCreated':
24663
- comments = comments.sort(sortByFirstCreated);
24664
- break;
24665
- case 'lastCreated':
24666
- default:
24667
- comments = comments.sort(sortByLastCreated);
24668
- break;
24669
- }
24670
- return comments;
25292
+ const approvePost = async (postId) => {
25293
+ const client = getActiveClient();
25294
+ client.log('post/approvePost', postId);
25295
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
25296
+ fireEvent('post.approved', payload);
25297
+ // fire virtual event for community update
25298
+ if (payload.posts[0].targetType === 'community') {
25299
+ fireEvent('community.updated', payload);
24671
25300
  }
24672
- }
25301
+ const data = prepareMembershipPayload(payload, 'communityUsers');
25302
+ const cachedAt = client.cache && Date.now();
25303
+ if (client.cache)
25304
+ ingestInCache(data, { cachedAt });
25305
+ return {
25306
+ data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
25307
+ cachedAt,
25308
+ };
25309
+ };
25310
+ /* end_public_function */
24673
25311
 
24674
25312
  /* begin_public_function
24675
- id: comment.query
25313
+ id: post.decline
24676
25314
  */
24677
25315
  /**
24678
25316
  * ```js
24679
- * import { getComments } from '@amityco/ts-sdk-react-native'
25317
+ * import { declinePost } from '@amityco/ts-sdk-react-native'
24680
25318
  *
24681
- * let comments = []
24682
- * const unsub = getComments({
24683
- * referenceType: Amity.InternalComment['referenceType'];
24684
- * referenceId: Amity.InternalComment['referenceId'];
24685
- * }, response => merge(comments, response.data))
25319
+ * const {data: post} = await declinePost('postId')
24686
25320
  * ```
24687
25321
  *
24688
- * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
25322
+ * Declines a {@link Amity.Post}
24689
25323
  *
24690
- * @param referenceType the type of the target
24691
- * @param referenceId the ID of the target
24692
- * @param callback the function to call when new data are available
24693
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
25324
+ * @param postId The {@link Amity.Post} ID to be declined
25325
+ * @return A {@link Amity.Post} that was declined
24694
25326
  *
24695
- * @category Comments Live Collection
25327
+ * @category Post API
25328
+ * @async
24696
25329
  */
24697
- const getComments = (params, callback, config) => {
24698
- const { log, cache } = getActiveClient();
24699
- if (!cache) {
24700
- console.log('For using Live Collection feature you need to enable Cache!');
25330
+ const declinePost = async (postId) => {
25331
+ const client = getActiveClient();
25332
+ client.log('post/declinePost', postId);
25333
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
25334
+ // fire virtual event
25335
+ if (payload.posts[0].targetType === 'community') {
25336
+ fireEvent('community.updated', payload);
24701
25337
  }
24702
- const timestamp = Date.now();
24703
- log(`getComments(tmpid: ${timestamp}) > listen`);
24704
- const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
24705
- const disposers = commentsLiveCollection.startSubscription();
24706
- const cacheKey = commentsLiveCollection.getCacheKey();
24707
- disposers.push(() => dropFromCache(cacheKey));
24708
- return () => {
24709
- log(`getComments(tmpid: ${timestamp}) > dispose`);
24710
- disposers.forEach(fn => fn());
25338
+ fireEvent('post.declined', payload);
25339
+ const data = prepareMembershipPayload(payload, 'communityUsers');
25340
+ const cachedAt = client.cache && Date.now();
25341
+ if (client.cache)
25342
+ ingestInCache(data, { cachedAt });
25343
+ return {
25344
+ data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
25345
+ cachedAt,
24711
25346
  };
24712
25347
  };
24713
25348
  /* end_public_function */
24714
25349
 
24715
- var index$9 = /*#__PURE__*/Object.freeze({
24716
- __proto__: null,
24717
- getCommentByIds: getCommentByIds,
24718
- createComment: createComment,
24719
- updateComment: updateComment,
24720
- deleteComment: deleteComment,
24721
- softDeleteComment: softDeleteComment,
24722
- hardDeleteComment: hardDeleteComment,
24723
- flagComment: flagComment,
24724
- unflagComment: unflagComment,
24725
- isCommentFlaggedByMe: isCommentFlaggedByMe,
24726
- onCommentCreated: onCommentCreated,
24727
- onCommentUpdated: onCommentUpdated,
24728
- onCommentDeleted: onCommentDeleted,
24729
- onCommentFlagged: onCommentFlagged,
24730
- onCommentUnflagged: onCommentUnflagged,
24731
- onCommentReactionAdded: onCommentReactionAdded,
24732
- onCommentReactionRemoved: onCommentReactionRemoved,
24733
- getComment: getComment,
24734
- getComments: getComments
24735
- });
24736
-
25350
+ /* begin_public_function
25351
+ id: post.flag
25352
+ */
24737
25353
  /**
24738
25354
  * ```js
24739
- * import { onPostUpdatedLocal } from '@amityco/ts-sdk-react-native'
24740
- * const dispose = onPostUpdatedLocal(post => {
24741
- * // ...
24742
- * })
25355
+ * import { PostRepository } from '@amityco/ts-sdk-react-native'
25356
+ * const flagged = await PostRepository.flagPost(postId, reason)
24743
25357
  * ```
24744
25358
  *
24745
- * Fired when a {@link Amity.InternalPost} has been updated
24746
- *
24747
- * @param callback The function to call when the event was fired
24748
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25359
+ * @param postId of the post to flag
25360
+ * @param reason the reason to flag the post
25361
+ * @returns a boolean
24749
25362
  *
24750
- * @category Post Events
24751
- */
24752
- const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
25363
+ * @category Post API
25364
+ * @async
25365
+ * */
25366
+ const flagPost = async (postId, reason) => {
25367
+ const client = getActiveClient();
25368
+ client.log('post/flagPost', postId);
25369
+ const isPredefinedReason = reason &&
25370
+ Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
25371
+ const body = {
25372
+ reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
25373
+ detail: reason && !isPredefinedReason ? reason : '',
25374
+ };
25375
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
25376
+ if (client.cache) {
25377
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
25378
+ }
25379
+ fireEvent('post.flagged', payload);
25380
+ return !!payload;
25381
+ };
25382
+ /* end_public_function */
24753
25383
 
25384
+ /* begin_public_function
25385
+ id: post.unflag
25386
+ */
24754
25387
  /**
24755
25388
  * ```js
24756
- * import { onLocalPostReactionAdded } from '@amityco/ts-sdk-react-native'
24757
- * const dispose = onPostReactionAdded(post => {
24758
- * // ...
24759
- * })
25389
+ * import { PostRepository } from '@amityco/ts-sdk-react-native'
25390
+ * const unflagged = await PostRepository.unflagPost(postId)
24760
25391
  * ```
24761
25392
  *
24762
- * Fired when a {@link Amity.InternalPost} has been reacted
24763
- *
24764
- * @param callback The function to call when the event was fired
24765
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25393
+ * @param postId of the post to unflag
25394
+ * @returns the unflag post result
24766
25395
  *
24767
- * @category Post Events
24768
- */
24769
- const onLocalPostReactionAdded = (callback) => {
25396
+ * @category Post API
25397
+ * @async
25398
+ * */
25399
+ const unflagPost = async (postId) => {
24770
25400
  const client = getActiveClient();
24771
- const filter = ({ post }) => {
24772
- if (!client.cache) {
24773
- callback(post);
24774
- }
24775
- else {
24776
- upsertInCache(['post', 'get', post.postId], post);
24777
- callback(post);
24778
- }
24779
- };
24780
- return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
25401
+ client.log('post/unflagPost', postId);
25402
+ const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
25403
+ if (client.cache) {
25404
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
25405
+ }
25406
+ fireEvent('post.unflagged', payload);
25407
+ return !!payload;
24781
25408
  };
25409
+ /* end_public_function */
24782
25410
 
25411
+ /* begin_public_function
25412
+ id: post.check_flag_by_me
25413
+ */
24783
25414
  /**
24784
25415
  * ```js
24785
- * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk-react-native'
24786
- * const dispose = onPostReactionRemoved(post => {
24787
- * // ...
24788
- * })
25416
+ * import { PostRepository } from '@amityco/ts-sdk-react-native'
25417
+ * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
24789
25418
  * ```
24790
25419
  *
24791
- * Fired when a {@link Amity.InternalPost} has been reacted
24792
- *
24793
- * @param callback The function to call when the event was fired
24794
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25420
+ * @param postId of the post to check if flagged by current user
25421
+ * @returns `true` if the post is flagged by me, `false` if doesn't.
24795
25422
  *
24796
- * @category Post Events
24797
- */
24798
- const onLocalPostReactionRemoved = (callback) => {
25423
+ * @category Post API
25424
+ * @async
25425
+ * */
25426
+ const isPostFlaggedByMe = async (postId) => {
24799
25427
  const client = getActiveClient();
24800
- const filter = ({ post }) => {
24801
- if (!client.cache) {
24802
- callback(post);
24803
- }
24804
- else {
24805
- upsertInCache(['post', 'get', post.postId], post);
24806
- callback(post);
24807
- }
24808
- };
24809
- return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
25428
+ client.log('post/isPostFlaggedByMe', postId);
25429
+ const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
25430
+ return result;
24810
25431
  };
25432
+ /* end_public_function */
24811
25433
 
25434
+ /* begin_public_function
25435
+ id: post.create.clip_post
25436
+ */
24812
25437
  /**
24813
25438
  * ```js
24814
- * import { onLocalPostDeleted } from '@amityco/ts-sdk-react-native'
24815
- * const dispose = onLocalPostDeleted(post => {
24816
- * // ...
24817
- * })
25439
+ * import { PostRepository } from '@amityco/ts-sdk'
25440
+ * const created = await PostRepository.createClipPost({
25441
+ * targetType: 'user',
25442
+ * targetId: 'foobar',
25443
+ * dataType: 'clip',
25444
+ * data: { text: 'hello world' },
25445
+ * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
25446
+ * }))
24818
25447
  * ```
24819
25448
  *
24820
- * Fired when a {@link Amity.InternalPost} has been deleted
25449
+ * Creates an {@link Amity.Post}
24821
25450
  *
24822
- * @param callback The function to call when the event was fired
24823
- * @returns an {@link Amity.Unsubscriber} function to stop listening
25451
+ * @param bundle The data necessary to create a new {@link Amity.Post}
25452
+ * @returns The newly created {@link Amity.Post}
24824
25453
  *
24825
- * @category Post Events
25454
+ * @category Post API
25455
+ * @async
24826
25456
  */
24827
- const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
25457
+ const createClipPost = async (bundle) => {
25458
+ const client = getActiveClient();
25459
+ client.log('post/createPost', bundle);
25460
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
25461
+ fireEvent('post.created', payload);
25462
+ const data = prepareMembershipPayload(payload, 'communityUsers');
25463
+ const cachedAt = client.cache && Date.now();
25464
+ if (client.cache)
25465
+ ingestInCache(data, { cachedAt });
25466
+ const { posts } = data;
25467
+ return {
25468
+ data: LinkedObject.post(posts[0]),
25469
+ cachedAt,
25470
+ };
25471
+ };
25472
+ /* end_public_function */
24828
25473
 
24829
25474
  /* begin_public_function
24830
25475
  id: post.get
@@ -24848,7 +25493,7 @@ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.p
24848
25493
  *
24849
25494
  * @category Post Live Object
24850
25495
  */
24851
- const getPost$1 = (postId, callback) => {
25496
+ const getPost = (postId, callback) => {
24852
25497
  const responder = (snapshot) => {
24853
25498
  const { data } = snapshot;
24854
25499
  callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
@@ -24937,19 +25582,6 @@ class PostPaginationController extends PaginationController {
24937
25582
  }
24938
25583
  }
24939
25584
 
24940
- var EnumPostActions;
24941
- (function (EnumPostActions) {
24942
- EnumPostActions["OnPostCreated"] = "onPostCreated";
24943
- EnumPostActions["OnPostUpdated"] = "onPostUpdated";
24944
- EnumPostActions["OnPostDeleted"] = "onPostDeleted";
24945
- EnumPostActions["OnPostFlagged"] = "onPostFlagged";
24946
- EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
24947
- EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
24948
- EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
24949
- EnumPostActions["OnPostApproved"] = "onPostApproved";
24950
- EnumPostActions["OnPostDeclined"] = "onPostDeclined";
24951
- })(EnumPostActions || (EnumPostActions = {}));
24952
-
24953
25585
  class PostQueryStreamController extends QueryStreamController {
24954
25586
  constructor(query, cacheKey, notifyChange, preparePayload) {
24955
25587
  super(query, cacheKey);
@@ -25015,116 +25647,81 @@ class PostQueryStreamController extends QueryStreamController {
25015
25647
  }
25016
25648
  }
25017
25649
 
25018
- const getPost = async (postId) => {
25019
- const client = getActiveClient();
25020
- client.log('post/getPost', postId);
25021
- isInTombstone('post', postId);
25022
- let payload;
25023
- try {
25024
- // API-FIX: endpoint should not be /list, parameters should be querystring.
25025
- const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
25026
- payload = response.data;
25027
- }
25028
- catch (error) {
25029
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
25030
- pushToTombstone('post', postId);
25031
- }
25032
- throw error;
25033
- }
25034
- const data = prepareMembershipPayload(payload, 'communityUsers');
25035
- const cachedAt = client.cache && Date.now();
25036
- if (client.cache)
25037
- ingestInCache(data, { cachedAt });
25038
- const { posts } = data;
25039
- const result = posts.find(post => post.postId === postId);
25040
- return {
25041
- data: result,
25042
- cachedAt,
25043
- };
25650
+ const commentEventHandler = (callback, eventHandler, cacheKey, resolveId) => {
25651
+ return eventHandler(async (comment) => {
25652
+ var _a;
25653
+ const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25654
+ if (!currentCollection ||
25655
+ !currentCollection.data.includes(resolveId ? resolveId(comment.referenceId) : comment.referenceId))
25656
+ return;
25657
+ await getPost$1(comment.referenceId);
25658
+ callback(comment);
25659
+ });
25044
25660
  };
25045
- getPost.locally = (postId) => {
25046
- const client = getActiveClient();
25047
- client.log('post/getPost.locally', postId);
25048
- if (!client.cache)
25049
- return;
25050
- const cached = pullFromCache(['post', 'get', postId]);
25051
- if (!cached)
25052
- return;
25053
- return {
25054
- data: cached.data,
25055
- cachedAt: cached.cachedAt,
25056
- };
25661
+ const generateCommentSubscriptions = ({ cacheKey, resolveId, }) => {
25662
+ const eventHandlers = [
25663
+ onCommentCreated,
25664
+ onCommentDeleted,
25665
+ onCommentReactionAdded,
25666
+ onCommentReactionRemoved,
25667
+ onCommentCreatedLocal,
25668
+ onCommentDeleteLocal,
25669
+ onLocalCommentReactionAdded,
25670
+ onLocalCommentReactionRemoved,
25671
+ ];
25672
+ return eventHandlers.map(handler => ({
25673
+ fn: convertEventPayload((callback) => commentEventHandler(callback, handler, cacheKey, resolveId), 'referenceId', 'post'),
25674
+ action: EnumPostActions.OnPostUpdated,
25675
+ }));
25676
+ };
25677
+ const getPostSubscription = (cacheKey) => {
25678
+ return [
25679
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
25680
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
25681
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
25682
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
25683
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
25684
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
25685
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
25686
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
25687
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
25688
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
25689
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
25690
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
25691
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
25692
+ ...generateCommentSubscriptions({ cacheKey }),
25693
+ ];
25057
25694
  };
25058
25695
 
25059
25696
  class PostLiveCollectionController extends LiveCollectionController {
25060
25697
  constructor(query, callback) {
25061
- const queryStreamId = hash__default["default"](query);
25062
- const cacheKey = ['posts', 'collection', queryStreamId];
25063
- const paginationController = new PostPaginationController(query);
25064
- super(paginationController, queryStreamId, cacheKey, callback);
25065
- this.query = query;
25066
- this.queryStreamController = new PostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
25067
- this.callback = callback.bind(this);
25068
- this.loadPage({ initial: true });
25069
- }
25070
- setup() {
25071
- var _a;
25072
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25073
- if (!collection) {
25074
- pushToCache(this.cacheKey, {
25075
- data: [],
25076
- params: {},
25077
- });
25078
- }
25079
- }
25080
- async persistModel(queryPayload) {
25081
- await this.queryStreamController.saveToMainDB(queryPayload);
25082
- }
25083
- persistQueryStream({ response, direction, refresh, }) {
25084
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
25085
- }
25086
- startSubscription() {
25087
- return this.queryStreamController.subscribeRTE([
25088
- { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
25089
- { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
25090
- { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
25091
- { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
25092
- { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
25093
- { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
25094
- { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
25095
- { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
25096
- { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
25097
- { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
25098
- { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
25099
- { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
25100
- { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
25101
- {
25102
- fn: convertEventPayload((callback) => {
25103
- return onCommentCreated(async (comment) => {
25104
- var _a;
25105
- const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25106
- if (!currentCollection || currentCollection.data.includes(comment.referenceId))
25107
- return;
25108
- await getPost(comment.referenceId);
25109
- callback(comment);
25110
- });
25111
- }, 'referenceId', 'post'),
25112
- action: EnumPostActions.OnPostUpdated,
25113
- },
25114
- {
25115
- fn: convertEventPayload((callback) => {
25116
- return onCommentDeleted(async (comment) => {
25117
- var _a;
25118
- const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25119
- if (!currentCollection || currentCollection.data.includes(comment.referenceId))
25120
- return;
25121
- await getPost(comment.referenceId);
25122
- callback(comment);
25123
- });
25124
- }, 'referenceId', 'post'),
25125
- action: EnumPostActions.OnPostUpdated,
25126
- },
25127
- ]);
25698
+ const queryStreamId = hash__default["default"](query);
25699
+ const cacheKey = ['posts', 'collection', queryStreamId];
25700
+ const paginationController = new PostPaginationController(query);
25701
+ super(paginationController, queryStreamId, cacheKey, callback);
25702
+ this.query = query;
25703
+ this.queryStreamController = new PostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
25704
+ this.callback = callback.bind(this);
25705
+ this.loadPage({ initial: true });
25706
+ }
25707
+ setup() {
25708
+ var _a;
25709
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25710
+ if (!collection) {
25711
+ pushToCache(this.cacheKey, {
25712
+ data: [],
25713
+ params: {},
25714
+ });
25715
+ }
25716
+ }
25717
+ async persistModel(queryPayload) {
25718
+ await this.queryStreamController.saveToMainDB(queryPayload);
25719
+ }
25720
+ persistQueryStream({ response, direction, refresh, }) {
25721
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
25722
+ }
25723
+ startSubscription() {
25724
+ return this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
25128
25725
  }
25129
25726
  notifyChange({ origin, loading, error }) {
25130
25727
  var _a, _b;
@@ -25259,6 +25856,22 @@ class PinnedPostQueryStreamController extends QueryStreamController {
25259
25856
  });
25260
25857
  }
25261
25858
  }
25859
+ reactor(action) {
25860
+ return (post) => {
25861
+ var _a;
25862
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25863
+ if (!collection)
25864
+ return;
25865
+ if (action === EnumPostActions.OnPostDeleted) {
25866
+ collection.data = collection.data.filter(referenceId => referenceId !== `global#${post.postId}`);
25867
+ }
25868
+ pushToCache(this.cacheKey, collection);
25869
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
25870
+ };
25871
+ }
25872
+ subscribeRTE(createSubscriber) {
25873
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
25874
+ }
25262
25875
  }
25263
25876
 
25264
25877
  class PinnedPostLiveCollectionController extends LiveCollectionController {
@@ -25290,7 +25903,10 @@ class PinnedPostLiveCollectionController extends LiveCollectionController {
25290
25903
  }
25291
25904
  // eslint-disable-next-line class-methods-use-this
25292
25905
  startSubscription() {
25293
- return [];
25906
+ return this.queryStreamController.subscribeRTE(generateCommentSubscriptions({
25907
+ cacheKey: this.cacheKey,
25908
+ resolveId: id => `${this.query.placement}#${id}`,
25909
+ }));
25294
25910
  }
25295
25911
  notifyChange({ origin, loading, error }) {
25296
25912
  var _a, _b;
@@ -25442,6 +26058,10 @@ class GlobalPinnedPostLiveCollectionController extends LiveCollectionController
25442
26058
  fn: onPostDeleted,
25443
26059
  action: EnumPostActions.OnPostDeleted,
25444
26060
  },
26061
+ ...generateCommentSubscriptions({
26062
+ cacheKey: this.cacheKey,
26063
+ resolveId: id => `global#${id}`,
26064
+ }),
25445
26065
  ]);
25446
26066
  }
25447
26067
  notifyChange({ origin, loading, error }) {
@@ -25721,6 +26341,238 @@ const semanticSearchPosts = (params, callback, config) => {
25721
26341
  };
25722
26342
  };
25723
26343
 
26344
+ class SearchPostPaginationController extends PaginationController {
26345
+ async getRequest(queryParams, token) {
26346
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, matchingOnlyParentPost, hashtags, dataTypes, targetType = 'all' } = queryParams, params = __rest(queryParams, ["limit", "matchingOnlyParentPost", "hashtags", "dataTypes", "targetType"]);
26347
+ const baseOptions = {
26348
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
26349
+ };
26350
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
26351
+ const { data: queryResponse } = await this.http.get(`/api/v1/search/posts`, {
26352
+ params: Object.assign(Object.assign({}, params), { hashtags,
26353
+ dataTypes,
26354
+ targetType,
26355
+ /*
26356
+ * when creating post like image, file, video BE will create 2 posts
26357
+ * 1. parent post to store text with dataType=text
26358
+ * 2. child post to store dataTypes post data
26359
+ *
26360
+ * By default, BE queries only parent post
26361
+ */
26362
+ matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
26363
+ });
26364
+ return queryResponse;
26365
+ }
26366
+ }
26367
+
26368
+ class SearchPostQueryStreamController extends QueryStreamController {
26369
+ constructor(query, cacheKey, notifyChange, preparePayload) {
26370
+ super(query, cacheKey);
26371
+ this.notifyChange = notifyChange;
26372
+ this.preparePayload = preparePayload;
26373
+ }
26374
+ async saveToMainDB(response) {
26375
+ const processedPayload = await this.preparePayload(response);
26376
+ const client = getActiveClient();
26377
+ const cachedAt = client.cache && Date.now();
26378
+ if (client.cache) {
26379
+ ingestInCache(processedPayload, { cachedAt });
26380
+ }
26381
+ }
26382
+ appendToQueryStream(response, direction, refresh = false) {
26383
+ var _a, _b;
26384
+ if (refresh) {
26385
+ pushToCache(this.cacheKey, {
26386
+ data: response.posts.map(getResolver('post')),
26387
+ });
26388
+ }
26389
+ else {
26390
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26391
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
26392
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
26393
+ }
26394
+ }
26395
+ reactor(action) {
26396
+ return (post) => {
26397
+ var _a, _b;
26398
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26399
+ if (!collection)
26400
+ return;
26401
+ if (post.parentPostId && post.isDeleted) {
26402
+ const parentPost = (_b = pullFromCache([
26403
+ 'post',
26404
+ 'get',
26405
+ post.parentPostId,
26406
+ ])) === null || _b === void 0 ? void 0 : _b.data;
26407
+ if (!parentPost)
26408
+ return;
26409
+ parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
26410
+ pushToCache(['post', 'get', parentPost.postId], parentPost);
26411
+ }
26412
+ if (action === EnumPostActions.OnPostDeclined) {
26413
+ collection.data = collection.data.filter(postId => postId !== post.postId);
26414
+ }
26415
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
26416
+ collection.data = [...new Set([post.postId, ...collection.data])];
26417
+ }
26418
+ pushToCache(this.cacheKey, collection);
26419
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
26420
+ };
26421
+ }
26422
+ subscribeRTE(createSubscriber) {
26423
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
26424
+ }
26425
+ }
26426
+
26427
+ class SearchPostLiveCollectionController extends LiveCollectionController {
26428
+ constructor(query, callback) {
26429
+ const queryStreamId = hash__default["default"](query);
26430
+ const cacheKey = ['posts', 'collection', queryStreamId];
26431
+ const paginationController = new SearchPostPaginationController(query);
26432
+ super(paginationController, queryStreamId, cacheKey, callback);
26433
+ this.query = query;
26434
+ this.queryStreamController = new SearchPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
26435
+ this.callback = callback.bind(this);
26436
+ this.loadPage({ initial: true });
26437
+ }
26438
+ setup() {
26439
+ var _a;
26440
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26441
+ if (!collection) {
26442
+ pushToCache(this.cacheKey, {
26443
+ data: [],
26444
+ params: {},
26445
+ });
26446
+ }
26447
+ }
26448
+ async persistModel(queryPayload) {
26449
+ await this.queryStreamController.saveToMainDB(queryPayload);
26450
+ }
26451
+ persistQueryStream({ response, direction, refresh, }) {
26452
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
26453
+ }
26454
+ startSubscription() {
26455
+ return this.queryStreamController.subscribeRTE([
26456
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
26457
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
26458
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
26459
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
26460
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
26461
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
26462
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
26463
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
26464
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
26465
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
26466
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
26467
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
26468
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
26469
+ {
26470
+ fn: convertEventPayload((callback) => {
26471
+ return onCommentCreated(async (comment) => {
26472
+ var _a;
26473
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26474
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
26475
+ return;
26476
+ await getPost$1(comment.referenceId);
26477
+ callback(comment);
26478
+ });
26479
+ }, 'referenceId', 'post'),
26480
+ action: EnumPostActions.OnPostUpdated,
26481
+ },
26482
+ {
26483
+ fn: convertEventPayload((callback) => {
26484
+ return onCommentDeleted(async (comment) => {
26485
+ var _a;
26486
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26487
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
26488
+ return;
26489
+ await getPost$1(comment.referenceId);
26490
+ callback(comment);
26491
+ });
26492
+ }, 'referenceId', 'post'),
26493
+ action: EnumPostActions.OnPostUpdated,
26494
+ },
26495
+ ]);
26496
+ }
26497
+ notifyChange({ origin, loading, error }) {
26498
+ var _a, _b;
26499
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26500
+ if (!collection)
26501
+ return;
26502
+ const data = this.applyFilter((_b = collection.data
26503
+ .map(id => pullFromCache(['post', 'get', id]))
26504
+ .filter(isNonNullable)
26505
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
26506
+ if (!this.shouldNotify(data) && origin === 'event')
26507
+ return;
26508
+ this.callback({
26509
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
26510
+ data,
26511
+ hasNextPage: !!this.paginationController.getNextToken(),
26512
+ loading,
26513
+ error,
26514
+ });
26515
+ }
26516
+ applyFilter(data) {
26517
+ var _a;
26518
+ let posts = data;
26519
+ if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
26520
+ posts = filterByPostDataTypes(posts, this.query.dataTypes);
26521
+ }
26522
+ switch (this.query.sortBy) {
26523
+ case 'firstCreated':
26524
+ posts = posts.sort(sortByFirstCreated);
26525
+ break;
26526
+ case 'lastCreated':
26527
+ default:
26528
+ posts = posts.sort(sortByLastCreated);
26529
+ break;
26530
+ }
26531
+ return posts;
26532
+ }
26533
+ }
26534
+
26535
+ /* begin_public_function
26536
+ id: post.query
26537
+ */
26538
+ /**
26539
+ * ```js
26540
+ * import { PostRepository } from '@amityco/ts-sdk'
26541
+ *
26542
+ * let posts = []
26543
+ * const unsub = PostRepository.searchPostsByHashtag({
26544
+ * hashtags: ['amity'],
26545
+ * limit: 10,
26546
+ * }, response => merge(posts, response.data))
26547
+ * ```
26548
+ *
26549
+ * Observe all mutations on a list of {@link Amity.Post} for a given target object
26550
+ *
26551
+ * @param params.hashtags the hashtags to search for
26552
+ * @param callback the function to call when new data are available
26553
+ * @param config
26554
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
26555
+ *
26556
+ * @category Posts Live Collection
26557
+ */
26558
+ const searchPostsByHashtag = (params, callback, config) => {
26559
+ const { log, cache } = getActiveClient();
26560
+ if (!cache) {
26561
+ console.log(ENABLE_CACHE_MESSAGE);
26562
+ }
26563
+ const timestamp = Date.now();
26564
+ log(`searchPostsByHashtag(tmpid: ${timestamp}) > listen`);
26565
+ const postsLiveCollection = new SearchPostLiveCollectionController(params, callback);
26566
+ const disposers = postsLiveCollection.startSubscription();
26567
+ const cacheKey = postsLiveCollection.getCacheKey();
26568
+ disposers.push(() => dropFromCache(cacheKey));
26569
+ return () => {
26570
+ log(`searchPostsByHashtag(tmpid: ${timestamp}) > dispose`);
26571
+ disposers.forEach(fn => fn());
26572
+ };
26573
+ };
26574
+ /* end_public_function */
26575
+
25724
26576
  var index$8 = /*#__PURE__*/Object.freeze({
25725
26577
  __proto__: null,
25726
26578
  getPostByIds: getPostByIds,
@@ -25744,11 +26596,12 @@ var index$8 = /*#__PURE__*/Object.freeze({
25744
26596
  onPostUnflagged: onPostUnflagged,
25745
26597
  onPostReactionAdded: onPostReactionAdded,
25746
26598
  onPostReactionRemoved: onPostReactionRemoved,
25747
- getPost: getPost$1,
26599
+ getPost: getPost,
25748
26600
  getPosts: getPosts,
25749
26601
  getPinnedPosts: getPinnedPosts,
25750
26602
  getGlobalPinnedPosts: getGlobalPinnedPosts,
25751
- semanticSearchPosts: semanticSearchPosts
26603
+ semanticSearchPosts: semanticSearchPosts,
26604
+ searchPostsByHashtag: searchPostsByHashtag
25752
26605
  });
25753
26606
 
25754
26607
  /* begin_public_function
@@ -26346,8 +27199,8 @@ var index$7 = /*#__PURE__*/Object.freeze({
26346
27199
  * const created = await createPoll({
26347
27200
  * question: 'question',
26348
27201
  * answers: [
26349
- * { dataType: 'text', data: 'answer1' },
26350
- * { dataType: 'text', data: 'answer2' },
27202
+ * { dataType: 'text', data: 'answer1', fileId: 'fileId1' },
27203
+ * { dataType: 'text', data: 'answer2', fileId: 'fileId2' },
26351
27204
  * ],
26352
27205
  * closedIn: 1649136484
26353
27206
  * }))
@@ -28939,13 +29792,13 @@ exports.AdRepository = index$3;
28939
29792
  exports.CategoryRepository = index$b;
28940
29793
  exports.ChannelRepository = index$f;
28941
29794
  exports.Client = index$o;
28942
- exports.CommentRepository = index$9;
29795
+ exports.CommentRepository = index$a;
28943
29796
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
28944
29797
  exports.CommunityPostSettings = CommunityPostSettings;
28945
29798
  exports.CommunityRepository = index$c;
28946
29799
  exports.ContentFeedType = ContentFeedType;
28947
29800
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
28948
- exports.FeedRepository = index$a;
29801
+ exports.FeedRepository = index$9;
28949
29802
  exports.FileRepository = index$l;
28950
29803
  exports.FileType = FileType;
28951
29804
  exports.InvitationRepository = index$1;