@amityco/ts-sdk 6.29.3-b60ec74.0 → 6.29.3-bd024fd.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/dist/@types/core/events.d.ts +41 -11
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +1 -1
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +18 -4
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/core/permissions.d.ts +4 -4
  8. package/dist/@types/core/permissions.d.ts.map +1 -1
  9. package/dist/@types/domains/follow.d.ts +21 -3
  10. package/dist/@types/domains/follow.d.ts.map +1 -1
  11. package/dist/@types/domains/post.d.ts +3 -3
  12. package/dist/@types/domains/post.d.ts.map +1 -1
  13. package/dist/@types/domains/user.d.ts +2 -2
  14. package/dist/@types/domains/user.d.ts.map +1 -1
  15. package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
  16. package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberPaginationController.d.ts.map +1 -1
  17. package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts.map +1 -1
  18. package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberPaginationController.d.ts.map +1 -1
  19. package/dist/channelRepository/events/onUserDeleted.d.ts +2 -0
  20. package/dist/channelRepository/events/onUserDeleted.d.ts.map +1 -0
  21. package/dist/commentRepository/api/createComment.d.ts.map +1 -1
  22. package/dist/commentRepository/api/deleteComment.d.ts.map +1 -1
  23. package/dist/commentRepository/events/onCommentCreatedLocal.d.ts +17 -0
  24. package/dist/commentRepository/events/onCommentCreatedLocal.d.ts.map +1 -0
  25. package/dist/commentRepository/events/onCommentDeletedLocal.d.ts +17 -0
  26. package/dist/commentRepository/events/onCommentDeletedLocal.d.ts.map +1 -0
  27. package/dist/commentRepository/events/onLocalCommentReactionAdded.d.ts +17 -0
  28. package/dist/commentRepository/events/onLocalCommentReactionAdded.d.ts.map +1 -0
  29. package/dist/commentRepository/events/onLocalCommentReactionRemoved.d.ts +17 -0
  30. package/dist/commentRepository/events/onLocalCommentReactionRemoved.d.ts.map +1 -0
  31. package/dist/commentRepository/events/utils.d.ts +1 -0
  32. package/dist/commentRepository/events/utils.d.ts.map +1 -1
  33. package/dist/commentRepository/observers/getComment.d.ts.map +1 -1
  34. package/dist/commentRepository/observers/getComments/CommentLiveCollectionController.d.ts.map +1 -1
  35. package/dist/communityRepository/communityMembership/events/index.d.ts +2 -0
  36. package/dist/communityRepository/communityMembership/events/index.d.ts.map +1 -1
  37. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts +17 -0
  38. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts.map +1 -0
  39. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts +17 -0
  40. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts.map +1 -0
  41. package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts +17 -0
  42. package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts.map +1 -0
  43. package/dist/communityRepository/communityMembership/events/utils.d.ts +1 -0
  44. package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
  45. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -1
  46. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts.map +1 -1
  47. package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts +4 -1
  48. package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts.map +1 -1
  49. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts.map +1 -1
  50. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts.map +1 -1
  51. package/dist/communityRepository/communityModeration/api/addRoles.d.ts.map +1 -1
  52. package/dist/communityRepository/communityModeration/api/removeRoles.d.ts.map +1 -1
  53. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts +17 -0
  54. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts.map +1 -0
  55. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts +17 -0
  56. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts.map +1 -0
  57. package/dist/communityRepository/utils/payload.d.ts +1 -0
  58. package/dist/communityRepository/utils/payload.d.ts.map +1 -1
  59. package/dist/core/events.d.ts +3 -3
  60. package/dist/core/events.d.ts.map +1 -1
  61. package/dist/index.cjs.js +1622 -925
  62. package/dist/index.esm.js +1551 -854
  63. package/dist/index.umd.js +4 -4
  64. package/dist/postRepository/events/onLocalPostDeleted.d.ts +17 -0
  65. package/dist/postRepository/events/onLocalPostDeleted.d.ts.map +1 -0
  66. package/dist/postRepository/events/onLocalPostReactionAdded.d.ts +17 -0
  67. package/dist/postRepository/events/onLocalPostReactionAdded.d.ts.map +1 -0
  68. package/dist/postRepository/events/onLocalPostReactionRemoved.d.ts +17 -0
  69. package/dist/postRepository/events/onLocalPostReactionRemoved.d.ts.map +1 -0
  70. package/dist/postRepository/events/onPostUpdatedLocal.d.ts +17 -0
  71. package/dist/postRepository/events/onPostUpdatedLocal.d.ts.map +1 -0
  72. package/dist/postRepository/events/utils.d.ts +1 -0
  73. package/dist/postRepository/events/utils.d.ts.map +1 -1
  74. package/dist/postRepository/internalApi/index.d.ts +1 -12
  75. package/dist/postRepository/internalApi/index.d.ts.map +1 -1
  76. package/dist/postRepository/observers/getPost.d.ts.map +1 -1
  77. package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
  78. package/dist/postRepository/utils/payload.d.ts.map +1 -1
  79. package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  80. package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  81. package/dist/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts +14 -0
  82. package/dist/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts.map +1 -0
  83. package/dist/userRepository/observers/getBlockedUsers/BlockedUserPaginationController.d.ts +5 -0
  84. package/dist/userRepository/observers/getBlockedUsers/BlockedUserPaginationController.d.ts.map +1 -0
  85. package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts +15 -0
  86. package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts.map +1 -0
  87. package/dist/userRepository/observers/getBlockedUsers.d.ts.map +1 -1
  88. package/dist/userRepository/relationship/block/api/blockUser.d.ts.map +1 -1
  89. package/dist/userRepository/relationship/block/api/unBlockUser.d.ts.map +1 -1
  90. package/dist/userRepository/relationship/follow/api/acceptFollower.d.ts.map +1 -1
  91. package/dist/userRepository/relationship/follow/api/acceptMyFollower.d.ts.map +1 -1
  92. package/dist/userRepository/relationship/follow/api/declineFollower.d.ts.map +1 -1
  93. package/dist/userRepository/relationship/follow/api/declineMyFollower.d.ts.map +1 -1
  94. package/dist/userRepository/relationship/follow/api/follow.d.ts.map +1 -1
  95. package/dist/userRepository/relationship/follow/api/unfollow.d.ts.map +1 -1
  96. package/dist/userRepository/relationship/follow/api/utils.d.ts.map +1 -1
  97. package/dist/userRepository/relationship/follow/enums.d.ts +11 -0
  98. package/dist/userRepository/relationship/follow/enums.d.ts.map +1 -0
  99. package/dist/userRepository/relationship/follow/events/index.d.ts +5 -0
  100. package/dist/userRepository/relationship/follow/events/index.d.ts.map +1 -1
  101. package/dist/userRepository/relationship/follow/events/onFollowInfoUpdated.d.ts.map +1 -1
  102. package/dist/userRepository/relationship/follow/events/onFollowerUserDeleted.d.ts +4 -0
  103. package/dist/userRepository/relationship/follow/events/onFollowerUserDeleted.d.ts.map +1 -0
  104. package/dist/userRepository/relationship/follow/events/onFollowingUserDeleted.d.ts +4 -0
  105. package/dist/userRepository/relationship/follow/events/onFollowingUserDeleted.d.ts.map +1 -0
  106. package/dist/userRepository/relationship/follow/events/onLocalFollowRequestAccepted.d.ts +2 -0
  107. package/dist/userRepository/relationship/follow/events/onLocalFollowRequestAccepted.d.ts.map +1 -0
  108. package/dist/userRepository/relationship/follow/events/onLocalFollowRequestDeclined.d.ts +2 -0
  109. package/dist/userRepository/relationship/follow/events/onLocalFollowRequestDeclined.d.ts.map +1 -0
  110. package/dist/userRepository/relationship/follow/events/onLocalFollowerRequested.d.ts +2 -0
  111. package/dist/userRepository/relationship/follow/events/onLocalFollowerRequested.d.ts.map +1 -0
  112. package/dist/userRepository/relationship/follow/events/onLocalUserFollowed.d.ts +2 -0
  113. package/dist/userRepository/relationship/follow/events/onLocalUserFollowed.d.ts.map +1 -0
  114. package/dist/userRepository/relationship/follow/events/onLocalUserUnfollowed.d.ts +2 -0
  115. package/dist/userRepository/relationship/follow/events/onLocalUserUnfollowed.d.ts.map +1 -0
  116. package/dist/userRepository/relationship/follow/events/utils.d.ts +2 -1
  117. package/dist/userRepository/relationship/follow/events/utils.d.ts.map +1 -1
  118. package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.d.ts +14 -0
  119. package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.d.ts.map +1 -0
  120. package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerPaginationController.d.ts +5 -0
  121. package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerPaginationController.d.ts.map +1 -0
  122. package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerQueryStreamController.d.ts +15 -0
  123. package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerQueryStreamController.d.ts.map +1 -0
  124. package/dist/userRepository/relationship/follow/observers/getFollowers.d.ts.map +1 -1
  125. package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.d.ts +14 -0
  126. package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.d.ts.map +1 -0
  127. package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingPaginationController.d.ts +5 -0
  128. package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingPaginationController.d.ts.map +1 -0
  129. package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingQueryStreamController.d.ts +15 -0
  130. package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingQueryStreamController.d.ts.map +1 -0
  131. package/dist/userRepository/relationship/follow/observers/getFollowings.d.ts.map +1 -1
  132. package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts +1 -1
  133. package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts.map +1 -1
  134. package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts +1 -1
  135. package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts.map +1 -1
  136. package/dist/userRepository/relationship/follow/utils.d.ts +4 -0
  137. package/dist/userRepository/relationship/follow/utils.d.ts.map +1 -0
  138. package/dist/userRepository/utils/convertRawUserToInternalUser.d.ts +2 -0
  139. package/dist/userRepository/utils/convertRawUserToInternalUser.d.ts.map +1 -0
  140. package/dist/userRepository/utils/prepareBlockedUserPayload.d.ts +2 -0
  141. package/dist/userRepository/utils/prepareBlockedUserPayload.d.ts.map +1 -0
  142. package/dist/userRepository/utils/prepareUserPayload.d.ts +2 -0
  143. package/dist/userRepository/utils/prepareUserPayload.d.ts.map +1 -0
  144. package/dist/utils/linkedObject/commentLinkedObject.d.ts.map +1 -1
  145. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  146. package/dist/utils/tests/dummy/block.d.ts +2 -2
  147. package/dist/utils/tests/dummy/follow.d.ts +2 -2
  148. package/package.json +1 -1
  149. package/src/@types/core/events.ts +40 -13
  150. package/src/@types/core/model.ts +1 -1
  151. package/src/@types/core/payload.ts +27 -7
  152. package/src/@types/core/permissions.ts +4 -4
  153. package/src/@types/domains/follow.ts +26 -12
  154. package/src/@types/domains/post.ts +3 -3
  155. package/src/@types/domains/user.ts +2 -2
  156. package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +4 -4
  157. package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberPaginationController.ts +4 -1
  158. package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.ts +6 -0
  159. package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberPaginationController.ts +4 -1
  160. package/src/channelRepository/events/onUserDeleted.ts +46 -0
  161. package/src/channelRepository/utils/prepareChannelPayload.ts +1 -1
  162. package/src/commentRepository/api/createComment.ts +16 -12
  163. package/src/commentRepository/api/deleteComment.ts +23 -13
  164. package/src/commentRepository/events/onCommentCreatedLocal.ts +22 -0
  165. package/src/commentRepository/events/onCommentDeletedLocal.ts +20 -0
  166. package/src/commentRepository/events/onLocalCommentReactionAdded.ts +42 -0
  167. package/src/commentRepository/events/onLocalCommentReactionRemoved.ts +42 -0
  168. package/src/commentRepository/events/utils.ts +78 -1
  169. package/src/commentRepository/observers/getComment.ts +6 -19
  170. package/src/commentRepository/observers/getComments/CommentLiveCollectionController.ts +8 -0
  171. package/src/communityRepository/communityMembership/api/addMembers.ts +1 -1
  172. package/src/communityRepository/communityMembership/api/removeMembers.ts +1 -1
  173. package/src/communityRepository/communityMembership/events/index.ts +2 -0
  174. package/src/communityRepository/communityMembership/events/onLocalCommunityUserAdded.ts +20 -0
  175. package/src/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.ts +20 -0
  176. package/src/communityRepository/communityMembership/events/onUserDeleted.ts +64 -0
  177. package/src/communityRepository/communityMembership/events/utils.ts +50 -2
  178. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +24 -5
  179. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.ts +4 -1
  180. package/src/communityRepository/communityMembership/observers/getMembers/enums.ts +3 -0
  181. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +12 -4
  182. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +4 -1
  183. package/src/communityRepository/communityModeration/api/addRoles.ts +5 -2
  184. package/src/communityRepository/communityModeration/api/removeRoles.ts +5 -2
  185. package/src/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.ts +38 -0
  186. package/src/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.ts +38 -0
  187. package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +3 -3
  188. package/src/communityRepository/utils/payload.ts +29 -0
  189. package/src/core/model/idResolvers.ts +1 -1
  190. package/src/postRepository/api/deletePost.ts +9 -9
  191. package/src/postRepository/api/updatePost.ts +1 -1
  192. package/src/postRepository/events/onLocalPostDeleted.ts +20 -0
  193. package/src/postRepository/events/onLocalPostReactionAdded.ts +38 -0
  194. package/src/postRepository/events/onLocalPostReactionRemoved.ts +41 -0
  195. package/src/postRepository/events/onPostUpdatedLocal.ts +20 -0
  196. package/src/postRepository/events/utils.ts +41 -6
  197. package/src/postRepository/internalApi/index.ts +1 -16
  198. package/src/postRepository/observers/getPost.ts +8 -0
  199. package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +8 -0
  200. package/src/postRepository/utils/payload.ts +10 -2
  201. package/src/reactionRepository/api/addReaction.ts +27 -2
  202. package/src/reactionRepository/api/removeReaction.ts +27 -2
  203. package/src/report/api/createReport.ts +1 -1
  204. package/src/report/api/deleteReport.ts +1 -1
  205. package/src/userRepository/api/flagUser.ts +1 -1
  206. package/src/userRepository/api/getUserByIds.ts +1 -1
  207. package/src/userRepository/api/queryBlockedUsers.ts +1 -1
  208. package/src/userRepository/api/unflagUser.ts +1 -1
  209. package/src/userRepository/api/updateUser.ts +1 -1
  210. package/src/userRepository/events/utils.ts +1 -1
  211. package/src/userRepository/internalApi/getUser.ts +1 -1
  212. package/src/userRepository/internalApi/queryUsers.ts +1 -1
  213. package/src/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.ts +106 -0
  214. package/src/userRepository/observers/getBlockedUsers/BlockedUserPaginationController.ts +24 -0
  215. package/src/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.ts +76 -0
  216. package/src/userRepository/observers/getBlockedUsers.ts +8 -81
  217. package/src/userRepository/observers/getUsers/UserLiveCollectionController.ts +4 -4
  218. package/src/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.ts +1 -1
  219. package/src/userRepository/relationship/block/api/blockUser.ts +4 -1
  220. package/src/userRepository/relationship/block/api/unBlockUser.ts +4 -1
  221. package/src/userRepository/relationship/follow/api/acceptFollower.ts +4 -1
  222. package/src/userRepository/relationship/follow/api/acceptMyFollower.ts +4 -1
  223. package/src/userRepository/relationship/follow/api/declineFollower.ts +5 -2
  224. package/src/userRepository/relationship/follow/api/declineMyFollower.ts +5 -2
  225. package/src/userRepository/relationship/follow/api/follow.ts +8 -1
  226. package/src/userRepository/relationship/follow/api/unfollow.ts +4 -1
  227. package/src/userRepository/relationship/follow/api/utils.ts +6 -2
  228. package/src/userRepository/relationship/follow/enums.ts +10 -0
  229. package/src/userRepository/relationship/follow/events/index.ts +6 -0
  230. package/src/userRepository/relationship/follow/events/onFollowInfoUpdated.ts +6 -1
  231. package/src/userRepository/relationship/follow/events/onFollowerUserDeleted.ts +33 -0
  232. package/src/userRepository/relationship/follow/events/onFollowingUserDeleted.ts +33 -0
  233. package/src/userRepository/relationship/follow/events/onLocalFollowRequestAccepted.ts +5 -0
  234. package/src/userRepository/relationship/follow/events/onLocalFollowRequestDeclined.ts +5 -0
  235. package/src/userRepository/relationship/follow/events/onLocalFollowerRequested.ts +5 -0
  236. package/src/userRepository/relationship/follow/events/onLocalUserFollowed.ts +5 -0
  237. package/src/userRepository/relationship/follow/events/onLocalUserUnfollowed.ts +5 -0
  238. package/src/userRepository/relationship/follow/events/utils.ts +25 -14
  239. package/src/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.ts +132 -0
  240. package/src/userRepository/relationship/follow/observers/getFollowers/FollowerPaginationController.ts +29 -0
  241. package/src/userRepository/relationship/follow/observers/getFollowers/FollowerQueryStreamController.ts +95 -0
  242. package/src/userRepository/relationship/follow/observers/getFollowers.ts +8 -106
  243. package/src/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.ts +136 -0
  244. package/src/userRepository/relationship/follow/observers/getFollowings/FollowingPaginationController.ts +29 -0
  245. package/src/userRepository/relationship/follow/observers/getFollowings/FollowingQueryStreamController.ts +95 -0
  246. package/src/userRepository/relationship/follow/observers/getFollowings.ts +6 -106
  247. package/src/userRepository/relationship/follow/observers/observeFollowers.ts +11 -0
  248. package/src/userRepository/relationship/follow/observers/observeFollowings.ts +11 -0
  249. package/src/userRepository/relationship/follow/utils.ts +36 -0
  250. package/src/userRepository/utils/convertRawUserToInternalUser.ts +6 -0
  251. package/src/userRepository/utils/prepareBlockedUserPayload.ts +19 -0
  252. package/src/userRepository/utils/{index.ts → prepareUserPayload.ts} +1 -6
  253. package/src/utils/linkedObject/commentLinkedObject.ts +13 -16
  254. package/src/utils/linkedObject/postLinkedObject.ts +0 -6
  255. package/dist/postRepository/internalApi/pinPost.d.ts +0 -6
  256. package/dist/postRepository/internalApi/pinPost.d.ts.map +0 -1
  257. package/dist/postRepository/internalApi/unpinPost.d.ts +0 -6
  258. package/dist/postRepository/internalApi/unpinPost.d.ts.map +0 -1
  259. package/dist/userRepository/utils/index.d.ts +0 -3
  260. package/dist/userRepository/utils/index.d.ts.map +0 -1
  261. package/src/postRepository/internalApi/pinPost.ts +0 -28
  262. package/src/postRepository/internalApi/unpinPost.ts +0 -28
package/dist/index.cjs.js CHANGED
@@ -540,7 +540,7 @@ const idResolvers = {
540
540
  storyTarget: ({ targetId }) => targetId,
541
541
  ad: ({ adId }) => adId,
542
542
  advertiser: ({ advertiserId }) => advertiserId,
543
- pin: ({ referenceId }) => referenceId,
543
+ pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
544
544
  pinTarget: ({ targetId }) => targetId,
545
545
  };
546
546
  /**
@@ -5390,6 +5390,80 @@ const categoryLinkedObject = (category) => {
5390
5390
  } });
5391
5391
  };
5392
5392
 
5393
+ /**
5394
+ * ```js
5395
+ * import { isEqual } from '~/utils/isEqual'
5396
+ * const isEqual = isEqual(post1, post2)
5397
+ * ```
5398
+ *
5399
+ * Compares two Amity.Model
5400
+ *
5401
+ * @param x the Amity.Model to compare
5402
+ * @param y the Amity.Model to compare wit x
5403
+ * @returns a boolean based on equality
5404
+ *
5405
+ * @category utility
5406
+ * @private
5407
+ */
5408
+ function isEqual(x, y) {
5409
+ if (x === null || x === undefined || y === null || y === undefined) {
5410
+ return x === y;
5411
+ }
5412
+ // after this just checking type of one would be enough
5413
+ if (x.constructor !== y.constructor) {
5414
+ return false;
5415
+ }
5416
+ // if they are functions, they should exactly refer to same one (because of closures)
5417
+ if (x instanceof Function) {
5418
+ return x === y;
5419
+ }
5420
+ // if they are regexps, they should exactly refer to same one
5421
+ if (x instanceof RegExp) {
5422
+ return x === y;
5423
+ }
5424
+ if (x === y || x.valueOf() === y.valueOf()) {
5425
+ return true;
5426
+ }
5427
+ if (Array.isArray(x) && x.length !== y.length) {
5428
+ return false;
5429
+ }
5430
+ // check each element of the array for equality
5431
+ if (Array.isArray(x) && Array.isArray(y)) {
5432
+ if (x.length !== y.length)
5433
+ return false;
5434
+ for (let i = 0; i < x.length; i += 1) {
5435
+ if (!isEqual(x[i], y[i]))
5436
+ return false;
5437
+ }
5438
+ // if all elements are equal, the arrays are equal
5439
+ return true;
5440
+ }
5441
+ // if they are dates, they must had equal valueOf
5442
+ if (x instanceof Date) {
5443
+ return false;
5444
+ }
5445
+ // if they are strictly equal, they both need to be object at least
5446
+ if (!(x instanceof Object)) {
5447
+ return false;
5448
+ }
5449
+ if (!(y instanceof Object)) {
5450
+ return false;
5451
+ }
5452
+ // recursive object equality check
5453
+ const p = Object.keys(x);
5454
+ return (Object.keys(y).every(i => {
5455
+ // @ts-ignore
5456
+ return p.indexOf(i) !== -1;
5457
+ }) &&
5458
+ p.every(i => {
5459
+ return isEqual(x[i], y[i]);
5460
+ }));
5461
+ }
5462
+
5463
+ function isNonNullable(value) {
5464
+ return value != null;
5465
+ }
5466
+
5393
5467
  const commentLinkedObject = (comment) => {
5394
5468
  return Object.assign(Object.assign({}, comment), { get target() {
5395
5469
  const commentTypes = {
@@ -5420,7 +5494,7 @@ const commentLinkedObject = (comment) => {
5420
5494
  return undefined;
5421
5495
  },
5422
5496
  get childrenComment() {
5423
- return (comment.children
5497
+ return comment.children
5424
5498
  .map(childCommentId => {
5425
5499
  const commentCache = pullFromCache([
5426
5500
  'comment',
@@ -5431,46 +5505,18 @@ const commentLinkedObject = (comment) => {
5431
5505
  return;
5432
5506
  return commentCache === null || commentCache === void 0 ? void 0 : commentCache.data;
5433
5507
  })
5434
- .filter(item => item)
5435
- // Cannot include this loop in the first loop because
5436
- // TS always alert returned value is possibly undefined
5437
- .map(item => commentLinkedObject(item)));
5508
+ .filter(isNonNullable)
5509
+ .map(item => commentLinkedObject(item));
5438
5510
  } });
5439
5511
  };
5440
5512
 
5441
- const pinPost = async ({ communityId, placement, postId, }) => {
5442
- const client = getActiveClient();
5443
- client.log('post/getPost', postId);
5444
- const { data } = await client.http.post(`/api/v1/pinned-posts/communities/${communityId}/${placement}/${postId}`);
5445
- const cachedAt = client.cache && Date.now();
5446
- if (client.cache)
5447
- ingestInCache(data, { cachedAt });
5448
- return {
5449
- data,
5450
- cachedAt,
5451
- };
5452
- };
5453
-
5454
- const unpinPost = async ({ communityId, placement, postId, }) => {
5455
- const client = getActiveClient();
5456
- client.log('post/getPost', postId);
5457
- const { data } = await client.http.delete(`/api/v1/pinned-posts/communities/${communityId}/${placement}/${postId}`);
5458
- const cachedAt = client.cache && Date.now();
5459
- if (client.cache)
5460
- ingestInCache(data, { cachedAt });
5461
- return {
5462
- data,
5463
- cachedAt,
5464
- };
5465
- };
5466
-
5467
5513
  const postLinkedObject = (post) => {
5468
5514
  return Object.assign(Object.assign({}, post), { analytics: {
5469
5515
  markAsViewed: () => {
5470
5516
  const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
5471
5517
  analyticsEngineInstance.markPostAsViewed(post.postId);
5472
5518
  },
5473
- }, pin: (placement) => pinPost({ communityId: post.targetId, placement, postId: post.postId }), unpin: (placement) => unpinPost({ communityId: post.targetId, placement, postId: post.postId }), get latestComments() {
5519
+ }, get latestComments() {
5474
5520
  if (!post.comments)
5475
5521
  return [];
5476
5522
  return (post.comments
@@ -6290,13 +6336,7 @@ const getChannelIsMentioned = (channel, marker) => {
6290
6336
  };
6291
6337
 
6292
6338
  function convertRawUserToInternalUser(rawUser) {
6293
- return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: rawUser.isGlobalBan });
6294
- }
6295
- function prepareUserPayload(response) {
6296
- return {
6297
- users: response.users.map(convertRawUserToInternalUser),
6298
- files: response.files,
6299
- };
6339
+ return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
6300
6340
  }
6301
6341
 
6302
6342
  const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
@@ -7784,6 +7824,13 @@ const onChannelMemberBanned = (callback) => {
7784
7824
  return createEventSubscriber(client, 'onChannelMemberBanned', 'channel.banned', filter);
7785
7825
  };
7786
7826
 
7827
+ function prepareUserPayload(response) {
7828
+ return {
7829
+ users: response.users.map(convertRawUserToInternalUser),
7830
+ files: response.files,
7831
+ };
7832
+ }
7833
+
7787
7834
  const createUserEventSubscriber = (event, callback) => {
7788
7835
  const client = getActiveClient();
7789
7836
  const filter = (data) => {
@@ -7811,7 +7858,7 @@ const createUserEventSubscriber = (event, callback) => {
7811
7858
  *
7812
7859
  * @category User Events
7813
7860
  */
7814
- const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
7861
+ const onUserDeleted$2 = (callback) => createUserEventSubscriber('user.deleted', callback);
7815
7862
 
7816
7863
  var analyticsEngineOnLoginHandler = () => {
7817
7864
  const analyticsEngine = AnalyticsEngine$1.getInstance();
@@ -9073,7 +9120,7 @@ const login = async (params, sessionHandler, config) => {
9073
9120
  terminateClient();
9074
9121
  subscriptions.forEach(fn => fn());
9075
9122
  unsubWatcher();
9076
- }), onUserDeleted((user) => {
9123
+ }), onUserDeleted$2((user) => {
9077
9124
  if (user.userId === client.userId) {
9078
9125
  terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
9079
9126
  subscriptions.forEach(fn => fn());
@@ -9625,76 +9672,6 @@ const removeFunctionProperties = (obj) => {
9625
9672
  return Object.fromEntries(entries);
9626
9673
  };
9627
9674
 
9628
- /**
9629
- * ```js
9630
- * import { isEqual } from '~/utils/isEqual'
9631
- * const isEqual = isEqual(post1, post2)
9632
- * ```
9633
- *
9634
- * Compares two Amity.Model
9635
- *
9636
- * @param x the Amity.Model to compare
9637
- * @param y the Amity.Model to compare wit x
9638
- * @returns a boolean based on equality
9639
- *
9640
- * @category utility
9641
- * @private
9642
- */
9643
- function isEqual(x, y) {
9644
- if (x === null || x === undefined || y === null || y === undefined) {
9645
- return x === y;
9646
- }
9647
- // after this just checking type of one would be enough
9648
- if (x.constructor !== y.constructor) {
9649
- return false;
9650
- }
9651
- // if they are functions, they should exactly refer to same one (because of closures)
9652
- if (x instanceof Function) {
9653
- return x === y;
9654
- }
9655
- // if they are regexps, they should exactly refer to same one
9656
- if (x instanceof RegExp) {
9657
- return x === y;
9658
- }
9659
- if (x === y || x.valueOf() === y.valueOf()) {
9660
- return true;
9661
- }
9662
- if (Array.isArray(x) && x.length !== y.length) {
9663
- return false;
9664
- }
9665
- // check each element of the array for equality
9666
- if (Array.isArray(x) && Array.isArray(y)) {
9667
- if (x.length !== y.length)
9668
- return false;
9669
- for (let i = 0; i < x.length; i += 1) {
9670
- if (!isEqual(x[i], y[i]))
9671
- return false;
9672
- }
9673
- // if all elements are equal, the arrays are equal
9674
- return true;
9675
- }
9676
- // if they are dates, they must had equal valueOf
9677
- if (x instanceof Date) {
9678
- return false;
9679
- }
9680
- // if they are strictly equal, they both need to be object at least
9681
- if (!(x instanceof Object)) {
9682
- return false;
9683
- }
9684
- if (!(y instanceof Object)) {
9685
- return false;
9686
- }
9687
- // recursive object equality check
9688
- const p = Object.keys(x);
9689
- return (Object.keys(y).every(i => {
9690
- // @ts-ignore
9691
- return p.indexOf(i) !== -1;
9692
- }) &&
9693
- p.every(i => {
9694
- return isEqual(x[i], y[i]);
9695
- }));
9696
- }
9697
-
9698
9675
  /**
9699
9676
  * @deprecated This function is deprecated
9700
9677
  */
@@ -9931,6 +9908,19 @@ var index$l = /*#__PURE__*/Object.freeze({
9931
9908
  getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
9932
9909
  });
9933
9910
 
9911
+ function prepareFollowersPayload(response) {
9912
+ const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
9913
+ return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
9914
+ }
9915
+ function prepareFollowingsPayload(response) {
9916
+ const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
9917
+ return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
9918
+ }
9919
+ function prepareFollowStatusPayload(response) {
9920
+ const { follows } = response, rest = __rest(response, ["follows"]);
9921
+ return Object.assign(Object.assign({}, rest), { follows });
9922
+ }
9923
+
9934
9924
  /* begin_public_function
9935
9925
  id: user.relationship.block
9936
9926
  */
@@ -9959,7 +9949,8 @@ const blockUser = async (userId) => {
9959
9949
  ingestInCache(followStatus, { cachedAt });
9960
9950
  upsertInCache(['followInfo', 'get', userId], followCounts[0], { cachedAt });
9961
9951
  }
9962
- fireEvent('follow.unfollowed', followStatus);
9952
+ const payload = prepareFollowStatusPayload(followStatus);
9953
+ fireEvent('local.follow.unfollowed', payload);
9963
9954
  return data;
9964
9955
  };
9965
9956
  /* end_public_function */
@@ -9992,170 +9983,397 @@ const unBlockUser = async (userId) => {
9992
9983
  ingestInCache(followStatus, { cachedAt });
9993
9984
  upsertInCache(['followInfo', 'get', userId], followCounts[0], { cachedAt });
9994
9985
  }
9995
- fireEvent('follow.created', followStatus);
9986
+ const payload = prepareFollowStatusPayload(followStatus);
9987
+ fireEvent('local.follow.created', payload);
9996
9988
  return data;
9997
9989
  };
9998
9990
  /* end_public_function */
9999
9991
 
10000
- /**
10001
- * ```js
10002
- * import { UserRepository } from '@amityco/ts-sdk'
10003
- * const { data: users, prevPage, nextPage, total } = await UserRepository.queryBlockedUsers({ page: Amity.PageRaw, limit: number })
10004
- * ```
10005
- *
10006
- * @param query The query parameters
10007
- * @returns A page of {@link Amity.User} objects
10008
- *
10009
- * @category Block API
10010
- * @async
10011
- */
10012
- const queryBlockedUsers = async (query) => {
10013
- const client = getActiveClient();
10014
- let params = {};
10015
- if (query) {
10016
- const { token, limit } = query;
10017
- params = {
10018
- limit,
10019
- token,
10020
- };
10021
- }
10022
- client.log('user/queryBlockedUsers');
10023
- const { data } = await client.http.get('/api/v4/me/user-blocks', {
10024
- params,
10025
- });
10026
- const payload = prepareUserPayload(data);
10027
- const cachedAt = client.cache && Date.now();
10028
- if (client.cache) {
10029
- ingestInCache(payload, { cachedAt });
10030
- const cacheKey = ['blockedUsers', 'query', params];
10031
- pushToCache(cacheKey, { users: payload.users.map(getResolver('user')), paging: data.paging });
9992
+ class PaginationController {
9993
+ constructor(queryParams) {
9994
+ const { http } = getActiveClient();
9995
+ this.queryParams = queryParams;
9996
+ this.http = http;
10032
9997
  }
10033
- const { next, previous, total } = data.paging;
10034
- const nextPage = toPageRaw(next);
10035
- const prevPage = toPageRaw(previous);
10036
- return { data: payload.users, prevPage, nextPage, total, cachedAt };
10037
- };
10038
- /**
10039
- * ```js
10040
- * import { queryBlockedUsers } from '@amityco/ts-sdk'
10041
- * const { data: users } = queryBlockedUsers.locally({ page: 'page_token' })
10042
- * ```
10043
- *
10044
- * Queries a paginable list of {@link Amity.User} objects from cache
10045
- * Search is performed by displayName such as `.startsWith(search)`
10046
- *
10047
- * @param query The query parameters
10048
- * @returns A page of {@link Amity.User} objects
10049
- *
10050
- * @category Block API
10051
- */
10052
- queryBlockedUsers.locally = (query = {}) => {
10053
- var _a, _b, _c;
10054
- const client = getActiveClient();
10055
- client.log('user/queryBlockedUsers.locally');
10056
- if (!client.cache)
10057
- return;
10058
- let params = {};
10059
- if (query) {
10060
- const { token, limit } = query;
10061
- params = {
10062
- token,
10063
- limit,
10064
- };
9998
+ loadFirstPage() {
9999
+ return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
10065
10000
  }
10066
- const cacheKey = ['blockedUsers', 'query', params];
10067
- const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
10068
- const users = (_b = data === null || data === void 0 ? void 0 : data.users.map(userId => pullFromCache(['user', 'get', userId])).filter(Boolean).map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
10069
- const nextPage = toPageRaw(data === null || data === void 0 ? void 0 : data.paging.next);
10070
- const prevPage = toPageRaw(data === null || data === void 0 ? void 0 : data.paging.previous);
10071
- return users.length > 0 && users.length === ((_c = data === null || data === void 0 ? void 0 : data.users) === null || _c === void 0 ? void 0 : _c.length)
10072
- ? { data: users, nextPage, prevPage, total: data === null || data === void 0 ? void 0 : data.paging.total, cachedAt }
10073
- : undefined;
10074
- };
10075
-
10076
- /* eslint-disable no-use-before-define */
10077
- /* begin_public_function
10078
- id: user.get_blocked_users
10079
- */
10080
- /**
10081
- * ```js
10082
- * import { UserRepository } from '@amityco/ts-sdk'
10083
- * const unblockedUser = await UserRepository.blockUser('userId')
10084
- * ```
10085
- *
10086
- * Blocks a {@link Amity.InternalUser}
10087
- *
10088
- * @param params The params to get blocked {@link Amity.InternalUser}s
10089
- * @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
10090
- * @returns {@link Amity.Unsubscriber} to unsubscribe from collection
10091
- *
10092
- * @category Post API
10093
- * @async
10094
- */
10095
- const getBlockedUsers$1 = (params, callback, config) => {
10096
- const { log, cache } = getActiveClient();
10097
- if (!cache) {
10098
- console.log(ENABLE_CACHE_MESSAGE);
10001
+ loadNextPage() {
10002
+ return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
10099
10003
  }
10100
- const timestamp = Date.now();
10101
- log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
10102
- const { limit: queryLimit } = params;
10103
- const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
10104
- const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
10105
- const disposers = [];
10106
- const cacheKey = ['blockedUsers', 'collection', {}];
10107
- const responder = (data) => {
10108
- var _a, _b;
10109
- const users = (_a = data.data
10110
- .map(userId => pullFromCache(['user', 'get', userId]))
10111
- .filter(Boolean)
10112
- .map(({ data }) => LinkedObject.user(data))) !== null && _a !== void 0 ? _a : [];
10113
- callback({
10114
- onNextPage: onFetch,
10115
- data: users,
10116
- hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
10117
- loading: data.loading,
10118
- error: data.error,
10004
+ loadPreviousPage() {
10005
+ return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
10006
+ }
10007
+ async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
10008
+ var _a, _b, _c, _d;
10009
+ if (direction === 'prev' && !this.previousToken)
10010
+ return;
10011
+ if (direction === 'next' && !this.nextToken)
10012
+ return;
10013
+ let token;
10014
+ if (direction === 'prev')
10015
+ token = this.previousToken;
10016
+ if (direction === 'next')
10017
+ token = this.nextToken;
10018
+ const queryResponse = await this.getRequest(this.queryParams, token);
10019
+ if (direction === 'first') {
10020
+ this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
10021
+ this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
10022
+ }
10023
+ if (direction === 'prev')
10024
+ this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
10025
+ if (direction === 'next')
10026
+ this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
10027
+ return queryResponse;
10028
+ }
10029
+ getNextToken() {
10030
+ return this.nextToken;
10031
+ }
10032
+ getPrevToken() {
10033
+ return this.previousToken;
10034
+ }
10035
+ }
10036
+
10037
+ class BlockedUserPaginationController extends PaginationController {
10038
+ async getRequest(queryParams, token) {
10039
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
10040
+ const options = token ? { token } : { limit };
10041
+ const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
10042
+ params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
10119
10043
  });
10120
- };
10121
- /*
10122
- * const realtimeRouter = () => {
10123
- * @TODO: At the time of creating this api blocked user do not have any
10124
- * observers
10125
- *};
10126
- */
10127
- const onFetch = (initial = false) => {
10044
+ return queryResponse;
10045
+ }
10046
+ }
10047
+
10048
+ class QueryStreamController {
10049
+ constructor(query, cacheKey) {
10050
+ this.query = query;
10051
+ this.cacheKey = cacheKey;
10052
+ }
10053
+ }
10054
+
10055
+ class BlockedUserQueryStreamController extends QueryStreamController {
10056
+ constructor(query, cacheKey, notifyChange, preparePayload) {
10057
+ super(query, cacheKey);
10058
+ this.notifyChange = notifyChange;
10059
+ this.preparePayload = preparePayload;
10060
+ }
10061
+ async saveToMainDB(response) {
10062
+ const processedPayload = await this.preparePayload(response);
10063
+ const client = getActiveClient();
10064
+ const cachedAt = client.cache && Date.now();
10065
+ if (client.cache) {
10066
+ ingestInCache(processedPayload, { cachedAt });
10067
+ }
10068
+ }
10069
+ appendToQueryStream(response, direction, refresh = false) {
10128
10070
  var _a, _b;
10129
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10130
- const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
10131
- if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
10071
+ if (refresh) {
10072
+ pushToCache(this.cacheKey, {
10073
+ data: response.users.map(getResolver('user')),
10074
+ });
10075
+ }
10076
+ else {
10077
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10078
+ const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
10079
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
10080
+ }
10081
+ }
10082
+ reactor(action) {
10083
+ return (followStatus) => {
10084
+ var _a;
10085
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10086
+ pushToCache(this.cacheKey, collection);
10087
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
10088
+ };
10089
+ }
10090
+ subscribeRTE(createSubscriber) {
10091
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
10092
+ }
10093
+ }
10094
+
10095
+ class PaginationNoPageController {
10096
+ constructor(queryParams) {
10097
+ const { http } = getActiveClient();
10098
+ this.queryParams = queryParams;
10099
+ this.http = http;
10100
+ }
10101
+ async onFetch() {
10102
+ const queryResponse = await this.getRequest(this.queryParams);
10103
+ return queryResponse;
10104
+ }
10105
+ }
10106
+
10107
+ class LiveCollectionController {
10108
+ constructor(paginationController, queryStreamId, cacheKey, callback) {
10109
+ this.paginationController = paginationController;
10110
+ this.queryStreamId = queryStreamId;
10111
+ this.cacheKey = cacheKey;
10112
+ this.callback = callback;
10113
+ }
10114
+ async refresh() {
10115
+ try {
10116
+ let result;
10117
+ if (this.paginationController instanceof PaginationNoPageController) {
10118
+ result = await this.paginationController.onFetch();
10119
+ }
10120
+ else {
10121
+ result = await this.paginationController.loadFirstPage();
10122
+ }
10123
+ if (!result)
10124
+ return;
10125
+ await this.persistModel(result);
10126
+ this.persistQueryStream({
10127
+ response: result,
10128
+ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
10129
+ refresh: true,
10130
+ });
10131
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
10132
+ }
10133
+ catch (e) {
10134
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
10135
+ }
10136
+ }
10137
+ loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
10138
+ this.setup();
10139
+ this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
10140
+ if (initial) {
10141
+ this.refresh();
10142
+ }
10143
+ else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
10144
+ this.loadPrevPage();
10145
+ }
10146
+ else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
10147
+ this.loadNextPage();
10148
+ }
10149
+ }
10150
+ async loadNextPage() {
10151
+ try {
10152
+ if (this.paginationController instanceof PaginationNoPageController)
10153
+ return;
10154
+ const result = await this.paginationController.loadNextPage();
10155
+ if (!result)
10156
+ return;
10157
+ await this.persistModel(result);
10158
+ this.persistQueryStream({
10159
+ response: result,
10160
+ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
10161
+ });
10162
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
10163
+ }
10164
+ catch (e) {
10165
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
10166
+ }
10167
+ }
10168
+ async loadPrevPage() {
10169
+ try {
10170
+ if (this.paginationController instanceof PaginationNoPageController)
10171
+ return;
10172
+ const result = await this.paginationController.loadPreviousPage();
10173
+ if (!result)
10174
+ return;
10175
+ await this.persistModel(result);
10176
+ this.persistQueryStream({
10177
+ response: result,
10178
+ direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
10179
+ });
10180
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
10181
+ }
10182
+ catch (e) {
10183
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
10184
+ }
10185
+ }
10186
+ shouldNotify(data) {
10187
+ const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
10188
+ if (isEqual(this.snapshot, newData))
10189
+ return false;
10190
+ this.snapshot = newData;
10191
+ return true;
10192
+ }
10193
+ getCacheKey() {
10194
+ return this.cacheKey;
10195
+ }
10196
+ }
10197
+
10198
+ function prepareBlockedUserPayload(response) {
10199
+ const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
10200
+ return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
10201
+ const followUser = users.find(user => user.userId === follow.from);
10202
+ return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
10203
+ }), users: users.map(convertRawUserToInternalUser) });
10204
+ }
10205
+
10206
+ /**
10207
+ * ```js
10208
+ * import { onUserUpdated } from '@amityco/ts-sdk'
10209
+ * const dispose = onUserUpdated(user => {
10210
+ * // ...
10211
+ * })
10212
+ * ```
10213
+ *
10214
+ * Fired when a {@link Amity.InternalUser} has been updated
10215
+ *
10216
+ * @param callback The function to call when the event was fired
10217
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10218
+ *
10219
+ * @category User Events
10220
+ */
10221
+ const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
10222
+
10223
+ /**
10224
+ * ```js
10225
+ * import { onUserFlagged } from '@amityco/ts-sdk'
10226
+ * const dispose = onUserFlagged(user => {
10227
+ * // ...
10228
+ * })
10229
+ * ```
10230
+ *
10231
+ * Fired when a {@link Amity.InternalUser} has been flagged
10232
+ *
10233
+ * @param callback The function to call when the event was fired
10234
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10235
+ *
10236
+ * @category User Events
10237
+ */
10238
+ const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
10239
+
10240
+ /**
10241
+ * ```js
10242
+ * import { onUserUnflagged } from '@amityco/ts-sdk'
10243
+ * const dispose = onUserUnflagged(user => {
10244
+ * // ...
10245
+ * })
10246
+ * ```
10247
+ *
10248
+ * Fired when a flag has been removed from a {@link Amity.InternalUser}
10249
+ *
10250
+ * @param callback The function to call when the event was fired
10251
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10252
+ *
10253
+ * @category User Events
10254
+ */
10255
+ const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
10256
+
10257
+ /**
10258
+ * ```js
10259
+ * import { onUserFlagCleared } from '@amityco/ts-sdk'
10260
+ * const dispose = onUserFlagCleared(user => {
10261
+ * // ...
10262
+ * })
10263
+ * ```
10264
+ *
10265
+ * Fired when flags have been cleared for a {@link Amity.InternalUser}
10266
+ *
10267
+ * @param callback The function to call when the event was fired
10268
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10269
+ *
10270
+ * @category User Events
10271
+ */
10272
+ const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
10273
+
10274
+ var EnumUserActions;
10275
+ (function (EnumUserActions) {
10276
+ EnumUserActions["OnUserDeleted"] = "onUserDeleted";
10277
+ EnumUserActions["OnUserUpdated"] = "onUserUpdated";
10278
+ EnumUserActions["OnUserFlagged"] = "onUserFlagged";
10279
+ EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
10280
+ EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
10281
+ })(EnumUserActions || (EnumUserActions = {}));
10282
+
10283
+ class BlockedUserLiveCollectionController extends LiveCollectionController {
10284
+ constructor(query, callback) {
10285
+ const queryStreamId = hash__default["default"](query);
10286
+ const cacheKey = ['blockedUsers', 'collection', queryStreamId];
10287
+ const paginationController = new BlockedUserPaginationController(query);
10288
+ super(paginationController, queryStreamId, cacheKey, callback);
10289
+ this.query = query;
10290
+ this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
10291
+ this.callback = callback.bind(this);
10292
+ this.loadPage({ initial: true });
10293
+ }
10294
+ setup() {
10295
+ var _a;
10296
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10297
+ if (!collection) {
10298
+ pushToCache(this.cacheKey, {
10299
+ data: [],
10300
+ params: {},
10301
+ });
10302
+ }
10303
+ }
10304
+ async persistModel(queryPayload) {
10305
+ await this.queryStreamController.saveToMainDB(queryPayload);
10306
+ }
10307
+ persistQueryStream({ response, direction, refresh, }) {
10308
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
10309
+ }
10310
+ startSubscription() {
10311
+ return this.queryStreamController.subscribeRTE([
10312
+ {
10313
+ fn: onUserDeleted$2,
10314
+ action: EnumUserActions.OnUserDeleted,
10315
+ },
10316
+ ]);
10317
+ }
10318
+ notifyChange({ origin, loading, error }) {
10319
+ var _a, _b;
10320
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10321
+ if (!collection)
10132
10322
  return;
10133
- const query = createQuery(queryBlockedUsers, {
10134
- limit,
10135
- token: toToken(!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined, 'afterbeforeraw'),
10323
+ const data = this.applyFilter((_b = collection.data
10324
+ .map(id => pullFromCache(['user', 'get', id]))
10325
+ .filter(isNonNullable)
10326
+ .map(({ data }) => data)
10327
+ .map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
10328
+ if (!this.shouldNotify(data) && origin === 'event')
10329
+ return;
10330
+ this.callback({
10331
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
10332
+ data,
10333
+ hasNextPage: !!this.paginationController.getNextToken(),
10334
+ loading,
10335
+ error,
10136
10336
  });
10137
- runQuery(query,
10138
- // @ts-ignore
10139
- ({ data: result, loading, error, nextPage: page, total }) => {
10140
- const data = {
10141
- loading,
10142
- error,
10143
- params: { page, total },
10144
- data: users,
10145
- };
10146
- if (result) {
10147
- data.data = [...new Set([...users, ...result.map(getResolver('user'))])];
10148
- }
10149
- pushToCache(cacheKey, data);
10150
- responder(data);
10151
- }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
10152
- };
10153
- disposers.push(() => {
10154
- // @TODO -> update once observers added
10155
- });
10156
- onFetch(true);
10337
+ }
10338
+ // eslint-disable-next-line class-methods-use-this
10339
+ applyFilter(data) {
10340
+ let users = data;
10341
+ users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
10342
+ return users;
10343
+ }
10344
+ }
10345
+
10346
+ /* begin_public_function
10347
+ id: user.get_blocked_users
10348
+ */
10349
+ /**
10350
+ * ```js
10351
+ * import { UserRepository } from '@amityco/ts-sdk'
10352
+ * const unblockedUser = await UserRepository.blockUser('userId')
10353
+ * ```
10354
+ *
10355
+ * Blocks a {@link Amity.InternalUser}
10356
+ *
10357
+ * @param params The params to get blocked {@link Amity.InternalUser}s
10358
+ * @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
10359
+ * @returns {@link Amity.Unsubscriber} to unsubscribe from collection
10360
+ *
10361
+ * @category Post API
10362
+ * @async
10363
+ */
10364
+ const getBlockedUsers$1 = (params, callback, config) => {
10365
+ const { log, cache } = getActiveClient();
10366
+ if (!cache) {
10367
+ console.log(ENABLE_CACHE_MESSAGE);
10368
+ }
10369
+ const timestamp = Date.now();
10370
+ log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
10371
+ const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
10372
+ const disposers = blockedUserLiveCollection.startSubscription();
10373
+ const cacheKey = blockedUserLiveCollection.getCacheKey();
10374
+ disposers.push(() => dropFromCache(cacheKey));
10157
10375
  return () => {
10158
- log(`getCategories(tmpid: ${timestamp}) > dispose`);
10376
+ log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
10159
10377
  disposers.forEach(fn => fn());
10160
10378
  dropFromCache(cacheKey);
10161
10379
  };
@@ -10165,7 +10383,7 @@ const getBlockedUsers$1 = (params, callback, config) => {
10165
10383
  /* eslint-disable no-use-before-define */
10166
10384
  const getBlockedUsers = (params, callback, config) => {
10167
10385
  console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
10168
- return getBlockedUsers$1(params, callback, config);
10386
+ return getBlockedUsers$1(params, callback);
10169
10387
  };
10170
10388
 
10171
10389
  /* begin_public_function
@@ -10193,7 +10411,13 @@ const follow = async (userId) => {
10193
10411
  if (client.cache) {
10194
10412
  ingestInCache(data, { cachedAt });
10195
10413
  }
10196
- fireEvent(data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested', data);
10414
+ const payload = prepareFollowStatusPayload(data);
10415
+ if (data.follows[0].status === 'accepted') {
10416
+ fireEvent('local.follow.created', payload);
10417
+ }
10418
+ else {
10419
+ fireEvent('local.follow.requested', payload);
10420
+ }
10197
10421
  return {
10198
10422
  data: data.follows[0],
10199
10423
  cachedAt,
@@ -10225,7 +10449,8 @@ const unfollow = async (userId) => {
10225
10449
  if (client.cache) {
10226
10450
  ingestInCache(data);
10227
10451
  }
10228
- fireEvent('follow.unfollowed', data);
10452
+ const payload = prepareFollowStatusPayload(data);
10453
+ fireEvent('local.follow.unfollowed', payload);
10229
10454
  return true;
10230
10455
  };
10231
10456
  /* end_public_function */
@@ -10254,7 +10479,8 @@ const acceptFollower = async (userId) => {
10254
10479
  if (client.cache) {
10255
10480
  ingestInCache(data);
10256
10481
  }
10257
- fireEvent('follow.accepted', data);
10482
+ const payload = prepareFollowStatusPayload(data);
10483
+ fireEvent('local.follow.accepted', payload);
10258
10484
  return true;
10259
10485
  };
10260
10486
 
@@ -10282,7 +10508,8 @@ const acceptMyFollower = async (userId) => {
10282
10508
  if (client.cache) {
10283
10509
  ingestInCache(data);
10284
10510
  }
10285
- fireEvent('follow.accepted', data);
10511
+ const payload = prepareFollowStatusPayload(data);
10512
+ fireEvent('local.follow.accepted', payload);
10286
10513
  return true;
10287
10514
  };
10288
10515
  /* end_public_function */
@@ -10311,7 +10538,8 @@ const declineFollower = async (userId) => {
10311
10538
  if (client.cache) {
10312
10539
  ingestInCache(data);
10313
10540
  }
10314
- fireEvent('follow.requestDeclined', data);
10541
+ const payload = prepareFollowStatusPayload(data);
10542
+ fireEvent('local.follow.requestDeclined', payload);
10315
10543
  return true;
10316
10544
  };
10317
10545
 
@@ -10339,29 +10567,35 @@ const declineMyFollower = async (userId) => {
10339
10567
  if (client.cache) {
10340
10568
  ingestInCache(data);
10341
10569
  }
10342
- fireEvent('follow.requestDeclined', data);
10570
+ const payload = prepareFollowStatusPayload(data);
10571
+ fireEvent('local.follow.requestDeclined', payload);
10343
10572
  return true;
10344
10573
  };
10345
10574
  /* end_public_function */
10346
10575
 
10347
10576
  const createFollowEventSubscriber = (event, callback) => {
10348
10577
  const client = getActiveClient();
10349
- const filter = (payload) => {
10350
- var _a, _b;
10578
+ const filter = (data) => {
10579
+ const payload = prepareFollowersPayload(data);
10580
+ if (!client.cache) {
10581
+ callback(payload.follows[0]);
10582
+ }
10583
+ else {
10584
+ ingestInCache(payload);
10585
+ callback(payload.follows[0]);
10586
+ }
10587
+ };
10588
+ return createEventSubscriber(client, event, event, filter);
10589
+ };
10590
+ const createLocalFollowEventSubscriber = (event, callback) => {
10591
+ const client = getActiveClient();
10592
+ const filter = (data) => {
10593
+ const payload = prepareFollowStatusPayload(data);
10351
10594
  if (!client.cache) {
10352
10595
  callback(payload.follows[0]);
10353
10596
  }
10354
10597
  else {
10355
10598
  ingestInCache(payload);
10356
- const queries = [
10357
- ...((_a = queryCache(['followers', 'query'])) !== null && _a !== void 0 ? _a : []),
10358
- ...((_b = queryCache(['followings', 'query'])) !== null && _b !== void 0 ? _b : []),
10359
- ];
10360
- queries
10361
- .filter(({ key }) =>
10362
- // @ts-ignore
10363
- key[2].userId === payload.follows[0].from || key[2].userId === payload.follows[0].to)
10364
- .forEach(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
10365
10599
  callback(payload.follows[0]);
10366
10600
  }
10367
10601
  };
@@ -10580,12 +10814,27 @@ const onFollowInfoUpdated = (callback) => {
10580
10814
  createFollowEventSubscriber('follow.requestCanceled', handler),
10581
10815
  createFollowEventSubscriber('follow.requestDeclined', handler),
10582
10816
  createFollowEventSubscriber('follow.followerDeleted', handler),
10817
+ createLocalFollowEventSubscriber('local.follow.created', handler),
10818
+ createLocalFollowEventSubscriber('local.follow.requested', handler),
10819
+ createLocalFollowEventSubscriber('local.follow.accepted', handler),
10820
+ createLocalFollowEventSubscriber('local.follow.unfollowed', handler),
10821
+ createLocalFollowEventSubscriber('local.follow.requestDeclined', handler),
10583
10822
  ];
10584
10823
  return () => {
10585
10824
  disposers.forEach(fn => fn());
10586
10825
  };
10587
10826
  };
10588
10827
 
10828
+ const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
10829
+
10830
+ const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
10831
+
10832
+ const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
10833
+
10834
+ const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
10835
+
10836
+ const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
10837
+
10589
10838
  /**
10590
10839
  * ```js
10591
10840
  * import { observeFollowInfo } from '@amityco/ts-sdk'
@@ -10658,7 +10907,7 @@ const observeFollowers = (userId, callback) => {
10658
10907
  (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
10659
10908
  (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
10660
10909
  };
10661
- disposers.push(onFollowerRequested(x => router(x, 'onRequested')), onFollowRequestAccepted(x => router(x, 'onAccepted')), onFollowRequestDeclined(x => router(x, 'onDeclined')), onFollowRequestCanceled(x => router(x, 'onCanceled')), onUserFollowed(x => router(x, 'onFollowed')), onUserUnfollowed(x => router(x, 'onUnfollowed')), onFollowerDeleted(x => router(x, 'onDeleted')));
10910
+ disposers.push(onFollowerRequested(x => router(x, 'onRequested')), onFollowRequestAccepted(x => router(x, 'onAccepted')), onFollowRequestDeclined(x => router(x, 'onDeclined')), onFollowRequestCanceled(x => router(x, 'onCanceled')), onUserFollowed(x => router(x, 'onFollowed')), onUserUnfollowed(x => router(x, 'onUnfollowed')), onFollowerDeleted(x => router(x, 'onDeleted')), onLocalFollowerRequested(x => router(x, 'onRequested')), onLocalFollowRequestAccepted(x => router(x, 'onAccepted')), onLocalFollowRequestDeclined(x => router(x, 'onDeclined')), onLocalUserFollowed(x => router(x, 'onFollowed')), onLocalUserUnfollowed(x => router(x, 'onUnfollowed')));
10662
10911
  return () => {
10663
10912
  log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
10664
10913
  disposers.forEach(fn => fn());
@@ -10694,216 +10943,397 @@ const observeFollowings = (userId, callback) => {
10694
10943
  (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
10695
10944
  (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
10696
10945
  };
10697
- disposers.push(onFollowerRequested(x => router(x, 'onRequested')), onFollowRequestAccepted(x => router(x, 'onAccepted')), onFollowRequestDeclined(x => router(x, 'onDeclined')), onFollowRequestCanceled(x => router(x, 'onCanceled')), onUserFollowed(x => router(x, 'onFollowed')), onUserUnfollowed(x => router(x, 'onUnfollowed')), onFollowerDeleted(x => router(x, 'onDeleted')));
10946
+ disposers.push(onFollowerRequested(x => router(x, 'onRequested')), onFollowRequestAccepted(x => router(x, 'onAccepted')), onFollowRequestDeclined(x => router(x, 'onDeclined')), onFollowRequestCanceled(x => router(x, 'onCanceled')), onUserFollowed(x => router(x, 'onFollowed')), onUserUnfollowed(x => router(x, 'onUnfollowed')), onFollowerDeleted(x => router(x, 'onDeleted')), onLocalFollowerRequested(x => router(x, 'onRequested')), onLocalFollowRequestAccepted(x => router(x, 'onAccepted')), onLocalFollowRequestDeclined(x => router(x, 'onDeclined')), onLocalUserFollowed(x => router(x, 'onFollowed')), onLocalUserUnfollowed(x => router(x, 'onUnfollowed')));
10698
10947
  return () => {
10699
10948
  log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
10700
10949
  disposers.forEach(fn => fn());
10701
10950
  };
10702
10951
  };
10703
10952
 
10704
- const queryFollows = async (key, query) => {
10705
- const client = getActiveClient();
10706
- client.log(`follow/queryF${key.substring(1)}`, query);
10707
- const { userId, page } = query, params = __rest(query, ["userId", "page"]);
10708
- const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/${key}` : `/api/v4/users/${userId}/${key}`, {
10709
- params: Object.assign(Object.assign({}, params), { token: toToken(page, 'afterbeforeraw') }),
10710
- });
10711
- const { paging } = data, payload = __rest(data, ["paging"]);
10712
- const { follows } = payload;
10713
- const cachedAt = client.cache && Date.now();
10714
- if (client.cache) {
10715
- ingestInCache(payload, { cachedAt });
10716
- const cacheKey = [
10717
- 'follow',
10718
- 'query',
10719
- Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page), type: key }),
10720
- ];
10721
- pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
10722
- }
10723
- const nextPage = toPageRaw(paging.next);
10724
- const prevPage = toPageRaw(paging.previous);
10725
- return { data: follows, cachedAt, prevPage, nextPage };
10726
- };
10727
- queryFollows.locally = (key, query) => {
10728
- var _a, _b;
10729
- const client = getActiveClient();
10730
- client.log(`follow/queryF${key.substring(1)}.locally`, query);
10731
- if (!client.cache)
10732
- return;
10733
- const { page } = query, params = __rest(query, ["page"]);
10734
- const queryKey = [
10735
- 'follow',
10736
- 'query',
10737
- Object.assign(Object.assign({}, params), { options: Object.assign({}, page), type: key }),
10738
- ];
10739
- const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
10740
- if (!(data === null || data === void 0 ? void 0 : data.follows.length)) {
10741
- return;
10953
+ class FollowerPaginationController extends PaginationController {
10954
+ async getRequest(queryParams, token) {
10955
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
10956
+ const options = token ? { token } : { limit };
10957
+ const client = getActiveClient();
10958
+ const path = client.userId === userId ? `/api/v4/me/followers` : `/api/v4/users/${userId}/followers`;
10959
+ const { data: queryResponse } = await this.http.get(path, {
10960
+ params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
10961
+ });
10962
+ return queryResponse;
10742
10963
  }
10743
- const follows = data.follows
10744
- .map(key => pullFromCache(['follow', 'get', key]))
10745
- .filter(Boolean)
10746
- .map(({ data }) => data);
10747
- const prevPage = toPageRaw(data === null || data === void 0 ? void 0 : data.paging.previous);
10748
- const nextPage = toPageRaw(data === null || data === void 0 ? void 0 : data.paging.next);
10749
- return follows.length === ((_b = data === null || data === void 0 ? void 0 : data.follows) === null || _b === void 0 ? void 0 : _b.length)
10750
- ? { data: follows, cachedAt, prevPage, nextPage }
10751
- : undefined;
10752
- };
10753
-
10754
- /**
10755
- * ```js
10756
- * import { queryFollowers } from '@amityco/ts-sdk'
10757
- * const { data: followers, prevPage, nextPage } = await queryFollowers({ userId })
10758
- * ```
10759
- *
10760
- * Queries a paginable list of {@link Amity.FollowStatus}
10761
- *
10762
- * @param query The query parameters
10763
- * @returns followers
10764
- *
10765
- * @category Follow API
10766
- * @async
10767
- */
10768
- const queryFollowers = async (query) => queryFollows('followers', query);
10769
- /**
10770
- * ```js
10771
- * import { queryFollowers } from '@amityco/ts-sdk'
10772
- * const { data: followers, prevPage, nextPage } = queryFollowers.locally({ userId })
10773
- * ```
10774
- *
10775
- * Queries a paginable list of {@link Amity.FollowStatus} objects from cache
10776
- *
10777
- * @param query The query parameters
10778
- * @returns followers
10779
- *
10780
- * @category Post API
10781
- */
10782
- queryFollowers.locally = (query) => queryFollows.locally('followers', query);
10964
+ }
10783
10965
 
10784
- /* begin_public_function
10785
- id: user.relationship.query_my_followers, user.relationship.query_followers
10786
- */
10787
- /**
10788
- * ```js
10789
- * import { getFollowers } from '@amityco/ts-sdk'
10790
- *
10791
- * let followers = []
10792
- * const unsub = getFollowers({
10793
- * userId: Amity.InternalUser['userId'];
10794
- * }, response => merge(followers, response.data))
10795
- * ```
10796
- *
10797
- * Observe all mutations on a list of {@link Amity.FollowStatus} followers for a given userId
10798
- *
10799
- * @param userId the user
10800
- * @param callback the function to call when new data are available
10801
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
10802
- *
10803
- * @category Followers Live Collection
10804
- */
10805
- const getFollowers = (params, callback, config) => {
10806
- const { log, cache } = getActiveClient();
10807
- if (!cache) {
10808
- console.log('For using Live Collection feature you need to enable Cache!');
10966
+ var EnumFollowActions;
10967
+ (function (EnumFollowActions) {
10968
+ EnumFollowActions["OnRequested"] = "onRequested";
10969
+ EnumFollowActions["OnAccepted"] = "onAccepted";
10970
+ EnumFollowActions["OnDeclined"] = "onDeclined";
10971
+ EnumFollowActions["OnCanceled"] = "onCanceled";
10972
+ EnumFollowActions["OnFollowed"] = "onFollowed";
10973
+ EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
10974
+ EnumFollowActions["OnDeleted"] = "onDeleted";
10975
+ EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
10976
+ })(EnumFollowActions || (EnumFollowActions = {}));
10977
+
10978
+ class FollowerQueryStreamController extends QueryStreamController {
10979
+ constructor(query, cacheKey, notifyChange, preparePayload) {
10980
+ super(query, cacheKey);
10981
+ this.notifyChange = notifyChange;
10982
+ this.preparePayload = preparePayload;
10809
10983
  }
10810
- const timestamp = Date.now();
10811
- log(`getFollowers(tmpid: ${timestamp}) > listen`);
10812
- const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
10813
- const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
10814
- const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
10815
- const disposers = [];
10816
- const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'follower' }];
10817
- const responder = (data) => {
10818
- var _a, _b;
10819
- let followers = (_a = data.data
10820
- .map(key => pullFromCache(['follow', 'get', key]))
10821
- .filter(Boolean)
10822
- .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
10823
- if (params.status && params.status !== 'all') {
10824
- followers = filterByPropEquality(followers, 'status', params.status);
10984
+ async saveToMainDB(response) {
10985
+ const processedPayload = await this.preparePayload(response);
10986
+ const client = getActiveClient();
10987
+ const cachedAt = client.cache && Date.now();
10988
+ if (client.cache) {
10989
+ ingestInCache(processedPayload, { cachedAt });
10825
10990
  }
10826
- callback({
10827
- onNextPage: onFetch,
10828
- data: followers,
10829
- hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
10830
- loading: data.loading,
10831
- error: data.error,
10832
- });
10833
- };
10834
- const realtimeRouter = (action) => (followStatus) => {
10835
- var _a;
10836
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10837
- if (params.userId !== followStatus.to || !collection)
10838
- return;
10839
- if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
10840
- collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
10991
+ }
10992
+ appendToQueryStream(response, direction, refresh = false) {
10993
+ var _a, _b;
10994
+ if (refresh) {
10995
+ pushToCache(this.cacheKey, {
10996
+ data: response.follows.map(getResolver('follow')),
10997
+ });
10841
10998
  }
10842
- else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
10843
- collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
10999
+ else {
11000
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11001
+ const follows = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
11002
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...follows, ...response.follows.map(getResolver('follow'))])] }));
10844
11003
  }
10845
- pushToCache(cacheKey, collection);
10846
- responder(collection);
10847
- };
10848
- const onFetch = (initial = false) => {
10849
- var _a, _b, _c, _d;
10850
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10851
- const followers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
10852
- if (!initial && followers.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
10853
- return;
10854
- const query = createQuery(queryFollowers, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
10855
- runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
10856
- const data = {
10857
- loading,
10858
- error,
10859
- params: { page },
10860
- data: followers,
10861
- };
10862
- if (result) {
10863
- data.data = [...new Set([...followers, ...result.map(getResolver('follow'))])];
11004
+ }
11005
+ reactor(action) {
11006
+ return (followStatus) => {
11007
+ var _a;
11008
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11009
+ if (this.query.userId !== followStatus.to || !collection)
11010
+ return;
11011
+ switch (action) {
11012
+ case EnumFollowActions.OnDeclined:
11013
+ case EnumFollowActions.OnCanceled:
11014
+ case EnumFollowActions.OnUnfollowed:
11015
+ case EnumFollowActions.OnDeleted:
11016
+ collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
11017
+ break;
11018
+ case EnumFollowActions.OnRequested:
11019
+ case EnumFollowActions.OnAccepted:
11020
+ case EnumFollowActions.OnFollowed:
11021
+ collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
11022
+ break;
10864
11023
  }
10865
- pushToCache(cacheKey, data);
10866
- responder(data);
10867
- }, queryOptions(policy));
10868
- };
10869
- disposers.push(onFollowerRequested(realtimeRouter('onRequested')), onFollowRequestAccepted(realtimeRouter('onAccepted')), onFollowRequestDeclined(realtimeRouter('onDeclined')), onFollowRequestCanceled(realtimeRouter('onCanceled')), onUserFollowed(realtimeRouter('onFollowed')), onUserUnfollowed(realtimeRouter('onUnfollowed')), onFollowerDeleted(realtimeRouter('onDeleted')));
10870
- onFetch(true);
10871
- return () => {
10872
- log(`getFollowers(tmpid: ${timestamp}) > dispose`);
10873
- disposers.forEach(fn => fn());
11024
+ pushToCache(this.cacheKey, collection);
11025
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
11026
+ };
11027
+ }
11028
+ subscribeRTE(createSubscriber) {
11029
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
11030
+ }
11031
+ }
11032
+
11033
+ const onFollowerUserDeleted = ({ userId }) => (callback) => {
11034
+ const client = getActiveClient();
11035
+ const filter = (data) => {
11036
+ const userPayload = prepareUserPayload(data);
11037
+ ingestInCache(userPayload);
11038
+ const cacheData = pullFromCache([
11039
+ 'follow',
11040
+ 'get',
11041
+ getResolver('follow')({
11042
+ from: userPayload.users[0].userId,
11043
+ to: userId,
11044
+ }),
11045
+ ]);
11046
+ if (!cacheData)
11047
+ return;
11048
+ callback(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data);
10874
11049
  };
10875
- };
10876
- /* end_public_function */
11050
+ return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
11051
+ };
10877
11052
 
11053
+ class FollowerLiveCollectionController extends LiveCollectionController {
11054
+ constructor(query, callback) {
11055
+ const queryStreamId = hash__default["default"](query);
11056
+ const cacheKey = ['follow', 'collection', queryStreamId];
11057
+ const paginationController = new FollowerPaginationController(query);
11058
+ super(paginationController, queryStreamId, cacheKey, callback);
11059
+ this.query = query;
11060
+ this.queryStreamController = new FollowerQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareFollowersPayload);
11061
+ this.callback = callback.bind(this);
11062
+ this.loadPage({ initial: true });
11063
+ }
11064
+ setup() {
11065
+ var _a;
11066
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11067
+ if (!collection) {
11068
+ pushToCache(this.cacheKey, {
11069
+ data: [],
11070
+ params: {},
11071
+ });
11072
+ }
11073
+ }
11074
+ async persistModel(queryPayload) {
11075
+ await this.queryStreamController.saveToMainDB(queryPayload);
11076
+ }
11077
+ persistQueryStream({ response, direction, refresh, }) {
11078
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
11079
+ }
11080
+ startSubscription() {
11081
+ return this.queryStreamController.subscribeRTE([
11082
+ { fn: onUserFollowed, action: EnumFollowActions.OnFollowed },
11083
+ { fn: onUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
11084
+ { fn: onFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
11085
+ { fn: onFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
11086
+ { fn: onFollowRequestCanceled, action: EnumFollowActions.OnCanceled },
11087
+ { fn: onFollowerDeleted, action: EnumFollowActions.OnDeleted },
11088
+ { fn: onLocalFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
11089
+ { fn: onLocalFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
11090
+ { fn: onLocalUserFollowed, action: EnumFollowActions.OnFollowed },
11091
+ { fn: onLocalUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
11092
+ {
11093
+ fn: onFollowerUserDeleted({ userId: this.query.userId }),
11094
+ action: EnumFollowActions.OnUserDeleted,
11095
+ },
11096
+ ]);
11097
+ }
11098
+ notifyChange({ origin, loading, error }) {
11099
+ var _a, _b;
11100
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11101
+ if (!collection)
11102
+ return;
11103
+ const data = this.applyFilter((_b = collection.data
11104
+ .map(id => pullFromCache(['follow', 'get', id]))
11105
+ .filter(isNonNullable)
11106
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
11107
+ if (!this.shouldNotify(data) && origin === 'event')
11108
+ return;
11109
+ this.callback({
11110
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
11111
+ data,
11112
+ hasNextPage: !!this.paginationController.getNextToken(),
11113
+ loading,
11114
+ error,
11115
+ });
11116
+ }
11117
+ applyFilter(data) {
11118
+ let followers = data;
11119
+ if (this.query.status && this.query.status !== "all" /* Amity.FollowStatusTypeEnum.All */) {
11120
+ followers = followers.filter(follower => follower.status === this.query.status);
11121
+ }
11122
+ followers = followers.filter(follower => {
11123
+ var _a;
11124
+ const fromUser = (_a = pullFromCache(['user', 'get', follower.from])) === null || _a === void 0 ? void 0 : _a.data;
11125
+ return (fromUser === null || fromUser === void 0 ? void 0 : fromUser.isDeleted) == null || (fromUser === null || fromUser === void 0 ? void 0 : fromUser.isDeleted) === false;
11126
+ });
11127
+ return followers;
11128
+ }
11129
+ }
11130
+
11131
+ /* begin_public_function
11132
+ id: user.relationship.query_my_followers, user.relationship.query_followers
11133
+ */
10878
11134
  /**
10879
11135
  * ```js
10880
- * import { queryFollowings } from '@amityco/ts-sdk'
10881
- * const { data: followings, prevPage, nextPage } = await queryFollowings({ userId })
10882
- * ```
10883
- *
10884
- * Queries a paginable list of {@link Amity.FollowStatus}
10885
- *
10886
- * @param query The query parameters
10887
- * @returns followings
10888
- *
10889
- * @category Follow API
10890
- * @async
10891
- */
10892
- const queryFollowings = async (query) => queryFollows('following', query);
10893
- /**
10894
- * ```js
10895
- * import { queryFollowings } from '@amityco/ts-sdk'
10896
- * const { data: followings, prevPage, nextPage } = queryFollowings.locally({ userId })
11136
+ * import { getFollowers } from '@amityco/ts-sdk'
11137
+ *
11138
+ * let followers = []
11139
+ * const unsub = getFollowers({
11140
+ * userId: Amity.InternalUser['userId'];
11141
+ * }, response => merge(followers, response.data))
10897
11142
  * ```
10898
11143
  *
10899
- * Queries a paginable list of {@link Amity.FollowStatus} objects from cache
11144
+ * Observe all mutations on a list of {@link Amity.FollowStatus} followers for a given userId
10900
11145
  *
10901
- * @param query The query parameters
10902
- * @returns followings
11146
+ * @param userId the user
11147
+ * @param callback the function to call when new data are available
11148
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
10903
11149
  *
10904
- * @category Post API
11150
+ * @category Followers Live Collection
10905
11151
  */
10906
- queryFollowings.locally = (query) => queryFollows.locally('following', query);
11152
+ const getFollowers = (params, callback, config) => {
11153
+ const { log, cache } = getActiveClient();
11154
+ if (!cache) {
11155
+ console.log(ENABLE_CACHE_MESSAGE);
11156
+ }
11157
+ const timestamp = Date.now();
11158
+ log(`getFollowers(tmpid: ${timestamp}) > listen`);
11159
+ const followerLiveCollection = new FollowerLiveCollectionController(params, callback);
11160
+ const disposers = followerLiveCollection.startSubscription();
11161
+ const cacheKey = followerLiveCollection.getCacheKey();
11162
+ disposers.push(() => dropFromCache(cacheKey));
11163
+ return () => {
11164
+ log(`getFollowers(tmpid: ${timestamp}) > dispose`);
11165
+ disposers.forEach(fn => fn());
11166
+ };
11167
+ };
11168
+ /* end_public_function */
11169
+
11170
+ class FollowingPaginationController extends PaginationController {
11171
+ async getRequest(queryParams, token) {
11172
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
11173
+ const options = token ? { token } : { limit };
11174
+ const client = getActiveClient();
11175
+ const path = client.userId === userId ? `/api/v4/me/following` : `/api/v4/users/${userId}/following`;
11176
+ const { data: queryResponse } = await this.http.get(path, {
11177
+ params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
11178
+ });
11179
+ return queryResponse;
11180
+ }
11181
+ }
11182
+
11183
+ class FollowingQueryStreamController extends QueryStreamController {
11184
+ constructor(query, cacheKey, notifyChange, preparePayload) {
11185
+ super(query, cacheKey);
11186
+ this.notifyChange = notifyChange;
11187
+ this.preparePayload = preparePayload;
11188
+ }
11189
+ async saveToMainDB(response) {
11190
+ const processedPayload = await this.preparePayload(response);
11191
+ const client = getActiveClient();
11192
+ const cachedAt = client.cache && Date.now();
11193
+ if (client.cache) {
11194
+ ingestInCache(processedPayload, { cachedAt });
11195
+ }
11196
+ }
11197
+ appendToQueryStream(response, direction, refresh = false) {
11198
+ var _a, _b;
11199
+ if (refresh) {
11200
+ pushToCache(this.cacheKey, {
11201
+ data: response.follows.map(getResolver('follow')),
11202
+ });
11203
+ }
11204
+ else {
11205
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11206
+ const follows = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
11207
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...follows, ...response.follows.map(getResolver('follow'))])] }));
11208
+ }
11209
+ }
11210
+ reactor(action) {
11211
+ return (followStatus) => {
11212
+ var _a;
11213
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11214
+ if (this.query.userId !== followStatus.from || !collection)
11215
+ return;
11216
+ switch (action) {
11217
+ case EnumFollowActions.OnDeclined:
11218
+ case EnumFollowActions.OnCanceled:
11219
+ case EnumFollowActions.OnUnfollowed:
11220
+ case EnumFollowActions.OnDeleted:
11221
+ collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
11222
+ break;
11223
+ case EnumFollowActions.OnRequested:
11224
+ case EnumFollowActions.OnAccepted:
11225
+ case EnumFollowActions.OnFollowed:
11226
+ collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
11227
+ break;
11228
+ }
11229
+ pushToCache(this.cacheKey, collection);
11230
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
11231
+ };
11232
+ }
11233
+ subscribeRTE(createSubscriber) {
11234
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
11235
+ }
11236
+ }
11237
+
11238
+ const onFollowingUserDeleted = ({ userId }) => (callback) => {
11239
+ const client = getActiveClient();
11240
+ const filter = (data) => {
11241
+ const userPayload = prepareUserPayload(data);
11242
+ ingestInCache(userPayload);
11243
+ const cacheData = pullFromCache([
11244
+ 'follow',
11245
+ 'get',
11246
+ getResolver('follow')({
11247
+ from: userId,
11248
+ to: userPayload.users[0].userId,
11249
+ }),
11250
+ ]);
11251
+ if (!cacheData)
11252
+ return;
11253
+ callback(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data);
11254
+ };
11255
+ return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
11256
+ };
11257
+
11258
+ class FollowingLiveCollectionController extends LiveCollectionController {
11259
+ constructor(query, callback) {
11260
+ const queryStreamId = hash__default["default"](query);
11261
+ const cacheKey = ['follow', 'collection', queryStreamId];
11262
+ const paginationController = new FollowingPaginationController(query);
11263
+ super(paginationController, queryStreamId, cacheKey, callback);
11264
+ this.query = query;
11265
+ this.queryStreamController = new FollowingQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareFollowingsPayload);
11266
+ this.callback = callback.bind(this);
11267
+ this.loadPage({ initial: true });
11268
+ }
11269
+ setup() {
11270
+ var _a;
11271
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11272
+ if (!collection) {
11273
+ pushToCache(this.cacheKey, {
11274
+ data: [],
11275
+ params: {},
11276
+ });
11277
+ }
11278
+ }
11279
+ async persistModel(queryPayload) {
11280
+ await this.queryStreamController.saveToMainDB(queryPayload);
11281
+ }
11282
+ persistQueryStream({ response, direction, refresh, }) {
11283
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
11284
+ }
11285
+ startSubscription() {
11286
+ return this.queryStreamController.subscribeRTE([
11287
+ { fn: onFollowerRequested, action: EnumFollowActions.OnRequested },
11288
+ { fn: onFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
11289
+ { fn: onFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
11290
+ { fn: onFollowRequestCanceled, action: EnumFollowActions.OnCanceled },
11291
+ { fn: onUserFollowed, action: EnumFollowActions.OnFollowed },
11292
+ { fn: onUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
11293
+ { fn: onFollowerDeleted, action: EnumFollowActions.OnDeleted },
11294
+ { fn: onLocalFollowerRequested, action: EnumFollowActions.OnRequested },
11295
+ { fn: onLocalFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
11296
+ { fn: onLocalFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
11297
+ { fn: onLocalUserFollowed, action: EnumFollowActions.OnFollowed },
11298
+ { fn: onLocalUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
11299
+ {
11300
+ fn: onFollowingUserDeleted({ userId: this.query.userId }),
11301
+ action: EnumFollowActions.OnUserDeleted,
11302
+ },
11303
+ ]);
11304
+ }
11305
+ notifyChange({ origin, loading, error }) {
11306
+ var _a, _b;
11307
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
11308
+ if (!collection)
11309
+ return;
11310
+ const data = this.applyFilter((_b = collection.data
11311
+ .map(id => pullFromCache(['follow', 'get', id]))
11312
+ .filter(isNonNullable)
11313
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
11314
+ if (!this.shouldNotify(data) && origin === 'event')
11315
+ return;
11316
+ this.callback({
11317
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
11318
+ data,
11319
+ hasNextPage: !!this.paginationController.getNextToken(),
11320
+ loading,
11321
+ error,
11322
+ });
11323
+ }
11324
+ applyFilter(data) {
11325
+ let followings = data;
11326
+ if (this.query.status && this.query.status !== "all" /* Amity.FollowStatusTypeEnum.All */) {
11327
+ followings = followings.filter(following => following.status === this.query.status);
11328
+ }
11329
+ followings = followings.filter(following => {
11330
+ var _a;
11331
+ const toUser = (_a = pullFromCache(['user', 'get', following.to])) === null || _a === void 0 ? void 0 : _a.data;
11332
+ return (toUser === null || toUser === void 0 ? void 0 : toUser.isDeleted) == null || (toUser === null || toUser === void 0 ? void 0 : toUser.isDeleted) === false;
11333
+ });
11334
+ return followings;
11335
+ }
11336
+ }
10907
11337
 
10908
11338
  /* begin_public_function
10909
11339
  id: user.relationship.query_my_followings, user.relationship.query_followings
@@ -10933,65 +11363,10 @@ const getFollowings = (params, callback, config) => {
10933
11363
  }
10934
11364
  const timestamp = Date.now();
10935
11365
  log(`getFollowings(tmpid: ${timestamp}) > listen`);
10936
- const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
10937
- const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
10938
- const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
10939
- const disposers = [];
10940
- const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'following' }];
10941
- const responder = (data) => {
10942
- var _a, _b;
10943
- let followings = (_a = data.data
10944
- .map(key => pullFromCache(['follow', 'get', key]))
10945
- .filter(Boolean)
10946
- .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
10947
- if (params.status && params.status !== 'all') {
10948
- followings = filterByPropEquality(followings, 'status', params.status);
10949
- }
10950
- callback({
10951
- onNextPage: onFetch,
10952
- data: followings,
10953
- hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
10954
- loading: data.loading,
10955
- error: data.error,
10956
- });
10957
- };
10958
- const realtimeRouter = (action) => (followStatus) => {
10959
- var _a;
10960
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10961
- if (params.userId !== followStatus.from || !collection)
10962
- return;
10963
- if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
10964
- collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
10965
- }
10966
- else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
10967
- collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
10968
- }
10969
- pushToCache(cacheKey, collection);
10970
- responder(collection);
10971
- };
10972
- const onFetch = (initial = false) => {
10973
- var _a, _b, _c, _d;
10974
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10975
- const followings = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
10976
- if (!initial && followings.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
10977
- return;
10978
- const query = createQuery(queryFollowings, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
10979
- runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
10980
- const data = {
10981
- loading,
10982
- error,
10983
- params: { page },
10984
- data: followings,
10985
- };
10986
- if (result) {
10987
- data.data = [...new Set([...followings, ...result.map(getResolver('follow'))])];
10988
- }
10989
- pushToCache(cacheKey, data);
10990
- responder(data);
10991
- }, queryOptions(policy));
10992
- };
10993
- disposers.push(onFollowerRequested(realtimeRouter('onRequested')), onFollowRequestAccepted(realtimeRouter('onAccepted')), onFollowRequestDeclined(realtimeRouter('onDeclined')), onFollowRequestCanceled(realtimeRouter('onCanceled')), onUserFollowed(realtimeRouter('onFollowed')), onUserUnfollowed(realtimeRouter('onUnfollowed')), onFollowerDeleted(realtimeRouter('onDeleted')));
10994
- onFetch(true);
11366
+ const followingLiveCollection = new FollowingLiveCollectionController(params, callback);
11367
+ const disposers = followingLiveCollection.startSubscription();
11368
+ const cacheKey = followingLiveCollection.getCacheKey();
11369
+ disposers.push(() => dropFromCache(cacheKey));
10995
11370
  return () => {
10996
11371
  log(`getFollowings(tmpid: ${timestamp}) > dispose`);
10997
11372
  disposers.forEach(fn => fn());
@@ -11079,6 +11454,11 @@ var index$k = /*#__PURE__*/Object.freeze({
11079
11454
  onFollowRequestAccepted: onFollowRequestAccepted,
11080
11455
  onFollowRequestDeclined: onFollowRequestDeclined,
11081
11456
  onFollowInfoUpdated: onFollowInfoUpdated,
11457
+ onLocalUserFollowed: onLocalUserFollowed,
11458
+ onLocalUserUnfollowed: onLocalUserUnfollowed,
11459
+ onLocalFollowerRequested: onLocalFollowerRequested,
11460
+ onLocalFollowRequestAccepted: onLocalFollowRequestAccepted,
11461
+ onLocalFollowRequestDeclined: onLocalFollowRequestDeclined,
11082
11462
  observeFollowInfo: observeFollowInfo,
11083
11463
  observeFollowers: observeFollowers,
11084
11464
  observeFollowings: observeFollowings,
@@ -11247,95 +11627,27 @@ const unflagUser = async (userId) => {
11247
11627
  /* end_public_function */
11248
11628
 
11249
11629
  /* begin_public_function
11250
- id: user.check_flag_by_me
11251
- */
11252
- /**
11253
- * ```js
11254
- * import { UserRepository } from '@amityco/ts-sdk'
11255
- * const isFlagged = await UserRepository.isUserFlaggedByMe(postId)
11256
- * ```
11257
- *
11258
- * @param userId The ID of the thing to check a report to.
11259
- * @returns `true` if the report is created by me, `false` if doesn't.
11260
- *
11261
- * @category Report API
11262
- * @async
11263
- * */
11264
- const isUserFlaggedByMe = async (userId) => {
11265
- const client = getActiveClient();
11266
- client.log('user/isUserFlaggedByMe', userId);
11267
- const { data: { isFlagByMe }, } = await client.http.get(`/api/v3/users/${userId}/isFlagByMe`);
11268
- return isFlagByMe;
11269
- };
11270
- /* end_public_function */
11271
-
11272
- /**
11273
- * ```js
11274
- * import { onUserUpdated } from '@amityco/ts-sdk'
11275
- * const dispose = onUserUpdated(user => {
11276
- * // ...
11277
- * })
11278
- * ```
11279
- *
11280
- * Fired when a {@link Amity.InternalUser} has been updated
11281
- *
11282
- * @param callback The function to call when the event was fired
11283
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11284
- *
11285
- * @category User Events
11286
- */
11287
- const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
11288
-
11289
- /**
11290
- * ```js
11291
- * import { onUserFlagged } from '@amityco/ts-sdk'
11292
- * const dispose = onUserFlagged(user => {
11293
- * // ...
11294
- * })
11295
- * ```
11296
- *
11297
- * Fired when a {@link Amity.InternalUser} has been flagged
11298
- *
11299
- * @param callback The function to call when the event was fired
11300
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11301
- *
11302
- * @category User Events
11303
- */
11304
- const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
11305
-
11306
- /**
11307
- * ```js
11308
- * import { onUserUnflagged } from '@amityco/ts-sdk'
11309
- * const dispose = onUserUnflagged(user => {
11310
- * // ...
11311
- * })
11312
- * ```
11313
- *
11314
- * Fired when a flag has been removed from a {@link Amity.InternalUser}
11315
- *
11316
- * @param callback The function to call when the event was fired
11317
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11318
- *
11319
- * @category User Events
11320
- */
11321
- const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
11322
-
11630
+ id: user.check_flag_by_me
11631
+ */
11323
11632
  /**
11324
11633
  * ```js
11325
- * import { onUserFlagCleared } from '@amityco/ts-sdk'
11326
- * const dispose = onUserFlagCleared(user => {
11327
- * // ...
11328
- * })
11634
+ * import { UserRepository } from '@amityco/ts-sdk'
11635
+ * const isFlagged = await UserRepository.isUserFlaggedByMe(postId)
11329
11636
  * ```
11330
11637
  *
11331
- * Fired when flags have been cleared for a {@link Amity.InternalUser}
11332
- *
11333
- * @param callback The function to call when the event was fired
11334
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11638
+ * @param userId The ID of the thing to check a report to.
11639
+ * @returns `true` if the report is created by me, `false` if doesn't.
11335
11640
  *
11336
- * @category User Events
11337
- */
11338
- const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
11641
+ * @category Report API
11642
+ * @async
11643
+ * */
11644
+ const isUserFlaggedByMe = async (userId) => {
11645
+ const client = getActiveClient();
11646
+ client.log('user/isUserFlaggedByMe', userId);
11647
+ const { data: { isFlagByMe }, } = await client.http.get(`/api/v3/users/${userId}/isFlagByMe`);
11648
+ return isFlagByMe;
11649
+ };
11650
+ /* end_public_function */
11339
11651
 
11340
11652
  /**
11341
11653
  * ```js
@@ -11447,7 +11759,7 @@ const getUser$1 = (userId, callback) => {
11447
11759
  return liveObject(userId, reactor, 'userId', getUser$2, [
11448
11760
  onUserFetched,
11449
11761
  onUserUpdated,
11450
- onUserDeleted,
11762
+ onUserDeleted$2,
11451
11763
  onUserFlagged,
11452
11764
  onUserUnflagged,
11453
11765
  onUserFlagCleared,
@@ -11455,51 +11767,6 @@ const getUser$1 = (userId, callback) => {
11455
11767
  };
11456
11768
  /* end_public_function */
11457
11769
 
11458
- class PaginationController {
11459
- constructor(queryParams) {
11460
- const { http } = getActiveClient();
11461
- this.queryParams = queryParams;
11462
- this.http = http;
11463
- }
11464
- loadFirstPage() {
11465
- return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
11466
- }
11467
- loadNextPage() {
11468
- return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
11469
- }
11470
- loadPreviousPage() {
11471
- return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
11472
- }
11473
- async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
11474
- var _a, _b, _c, _d;
11475
- if (direction === 'prev' && !this.previousToken)
11476
- return;
11477
- if (direction === 'next' && !this.nextToken)
11478
- return;
11479
- let token;
11480
- if (direction === 'prev')
11481
- token = this.previousToken;
11482
- if (direction === 'next')
11483
- token = this.nextToken;
11484
- const queryResponse = await this.getRequest(this.queryParams, token);
11485
- if (direction === 'first') {
11486
- this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
11487
- this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
11488
- }
11489
- if (direction === 'prev')
11490
- this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
11491
- if (direction === 'next')
11492
- this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
11493
- return queryResponse;
11494
- }
11495
- getNextToken() {
11496
- return this.nextToken;
11497
- }
11498
- getPrevToken() {
11499
- return this.previousToken;
11500
- }
11501
- }
11502
-
11503
11770
  class UserPaginationController extends PaginationController {
11504
11771
  async getRequest(queryParams, token) {
11505
11772
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
@@ -11511,13 +11778,6 @@ class UserPaginationController extends PaginationController {
11511
11778
  }
11512
11779
  }
11513
11780
 
11514
- class QueryStreamController {
11515
- constructor(query, cacheKey) {
11516
- this.query = query;
11517
- this.cacheKey = cacheKey;
11518
- }
11519
- }
11520
-
11521
11781
  class UserQueryStreamController extends QueryStreamController {
11522
11782
  constructor(query, cacheKey, notifyChange, preparePayload) {
11523
11783
  super(query, cacheKey);
@@ -11564,122 +11824,6 @@ class UserQueryStreamController extends QueryStreamController {
11564
11824
  }
11565
11825
  }
11566
11826
 
11567
- class PaginationNoPageController {
11568
- constructor(queryParams) {
11569
- const { http } = getActiveClient();
11570
- this.queryParams = queryParams;
11571
- this.http = http;
11572
- }
11573
- async onFetch() {
11574
- const queryResponse = await this.getRequest(this.queryParams);
11575
- return queryResponse;
11576
- }
11577
- }
11578
-
11579
- class LiveCollectionController {
11580
- constructor(paginationController, queryStreamId, cacheKey, callback) {
11581
- this.paginationController = paginationController;
11582
- this.queryStreamId = queryStreamId;
11583
- this.cacheKey = cacheKey;
11584
- this.callback = callback;
11585
- }
11586
- async refresh() {
11587
- try {
11588
- let result;
11589
- if (this.paginationController instanceof PaginationNoPageController) {
11590
- result = await this.paginationController.onFetch();
11591
- }
11592
- else {
11593
- result = await this.paginationController.loadFirstPage();
11594
- }
11595
- if (!result)
11596
- return;
11597
- await this.persistModel(result);
11598
- this.persistQueryStream({
11599
- response: result,
11600
- direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
11601
- refresh: true,
11602
- });
11603
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
11604
- }
11605
- catch (e) {
11606
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
11607
- }
11608
- }
11609
- loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
11610
- this.setup();
11611
- this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
11612
- if (initial) {
11613
- this.refresh();
11614
- }
11615
- else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
11616
- this.loadPrevPage();
11617
- }
11618
- else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
11619
- this.loadNextPage();
11620
- }
11621
- }
11622
- async loadNextPage() {
11623
- try {
11624
- if (this.paginationController instanceof PaginationNoPageController)
11625
- return;
11626
- const result = await this.paginationController.loadNextPage();
11627
- if (!result)
11628
- return;
11629
- await this.persistModel(result);
11630
- this.persistQueryStream({
11631
- response: result,
11632
- direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
11633
- });
11634
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
11635
- }
11636
- catch (e) {
11637
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
11638
- }
11639
- }
11640
- async loadPrevPage() {
11641
- try {
11642
- if (this.paginationController instanceof PaginationNoPageController)
11643
- return;
11644
- const result = await this.paginationController.loadPreviousPage();
11645
- if (!result)
11646
- return;
11647
- await this.persistModel(result);
11648
- this.persistQueryStream({
11649
- response: result,
11650
- direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
11651
- });
11652
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
11653
- }
11654
- catch (e) {
11655
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
11656
- }
11657
- }
11658
- shouldNotify(data) {
11659
- const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
11660
- if (isEqual(this.snapshot, newData))
11661
- return false;
11662
- this.snapshot = newData;
11663
- return true;
11664
- }
11665
- getCacheKey() {
11666
- return this.cacheKey;
11667
- }
11668
- }
11669
-
11670
- var EnumUserActions;
11671
- (function (EnumUserActions) {
11672
- EnumUserActions["OnUserDeleted"] = "onUserDeleted";
11673
- EnumUserActions["OnUserUpdated"] = "onUserUpdated";
11674
- EnumUserActions["OnUserFlagged"] = "onUserFlagged";
11675
- EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
11676
- EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
11677
- })(EnumUserActions || (EnumUserActions = {}));
11678
-
11679
- function isNonNullable(value) {
11680
- return value != null;
11681
- }
11682
-
11683
11827
  class UserLiveCollectionController extends LiveCollectionController {
11684
11828
  constructor(query, callback) {
11685
11829
  const queryStreamId = hash__default["default"](query);
@@ -11709,7 +11853,7 @@ class UserLiveCollectionController extends LiveCollectionController {
11709
11853
  }
11710
11854
  startSubscription() {
11711
11855
  return this.queryStreamController.subscribeRTE([
11712
- { fn: onUserDeleted, action: EnumUserActions.OnUserDeleted },
11856
+ { fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
11713
11857
  { fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
11714
11858
  { fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
11715
11859
  { fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
@@ -11741,11 +11885,11 @@ class UserLiveCollectionController extends LiveCollectionController {
11741
11885
  if (!this.query.displayName) {
11742
11886
  const sortFn = (() => {
11743
11887
  switch (this.query.sortBy) {
11744
- case Amity.UserSortByEnum.FirstCreated:
11888
+ case 'firstCreated':
11745
11889
  return sortByFirstCreated;
11746
- case Amity.UserSortByEnum.LastCreated:
11890
+ case 'lastCreated':
11747
11891
  return sortByLastCreated;
11748
- case Amity.UserSortByEnum.DisplayName:
11892
+ case 'displayName':
11749
11893
  return sortByDisplayName;
11750
11894
  default:
11751
11895
  return sortByLastCreated;
@@ -11876,7 +12020,7 @@ const observeUser = (userId, callback) => {
11876
12020
  (_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, newResult);
11877
12021
  };
11878
12022
  const disposers = [];
11879
- disposers.push(onUserUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onUserDeleted(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), onUserFlagged(data => router({ data, loading: false, origin: 'event' }, 'onFlagged')), onUserUnflagged(data => router({ data, loading: false, origin: 'event' }, 'onUnflagged')), onUserFlagCleared(data => router({ data, loading: false, origin: 'event' }, 'onFlagCleared')));
12023
+ disposers.push(onUserUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onUserDeleted$2(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), onUserFlagged(data => router({ data, loading: false, origin: 'event' }, 'onFlagged')), onUserUnflagged(data => router({ data, loading: false, origin: 'event' }, 'onUnflagged')), onUserFlagCleared(data => router({ data, loading: false, origin: 'event' }, 'onFlagCleared')));
11880
12024
  runQuery(createQuery(getUser, userId), result => result.data && router(result, 'onFetch'));
11881
12025
  return () => {
11882
12026
  log(`observeUser(tmpid: ${timestamp}) > dispose`);
@@ -11971,7 +12115,7 @@ class SearchUserLiveCollectionController extends LiveCollectionController {
11971
12115
  }
11972
12116
  startSubscription() {
11973
12117
  return this.queryStreamController.subscribeRTE([
11974
- { fn: onUserDeleted, action: EnumUserActions.OnUserDeleted },
12118
+ { fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
11975
12119
  { fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
11976
12120
  { fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
11977
12121
  { fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
@@ -12212,7 +12356,7 @@ var index$j = /*#__PURE__*/Object.freeze({
12212
12356
  unflagUser: unflagUser,
12213
12357
  isUserFlaggedByMe: isUserFlaggedByMe,
12214
12358
  onUserUpdated: onUserUpdated,
12215
- onUserDeleted: onUserDeleted,
12359
+ onUserDeleted: onUserDeleted$2,
12216
12360
  onUserFlagged: onUserFlagged,
12217
12361
  onUserUnflagged: onUserUnflagged,
12218
12362
  onUserFlagCleared: onUserFlagCleared,
@@ -13119,6 +13263,7 @@ const prepareCommentFromFlaggedEvent = (payload) => {
13119
13263
  * @async
13120
13264
  * */
13121
13265
  const addReaction = async (referenceType, referenceId, reactionName) => {
13266
+ var _a, _b;
13122
13267
  const client = getActiveClient();
13123
13268
  client.log('reaction/createReaction', {
13124
13269
  referenceId,
@@ -13137,8 +13282,21 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
13137
13282
  'get',
13138
13283
  referenceId,
13139
13284
  ]);
13140
- (model === null || model === void 0 ? void 0 : model.data) &&
13141
- pushToCache([referenceType, 'get', referenceId], model.data, { cachedAt: Date.now() });
13285
+ if (!model)
13286
+ return true;
13287
+ const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) + 1 }) });
13288
+ if (referenceType === 'comment') {
13289
+ fireEvent('local.comment.addReaction', {
13290
+ comment: updatedModel,
13291
+ });
13292
+ return true;
13293
+ }
13294
+ if (referenceType === 'post') {
13295
+ fireEvent('local.post.addReaction', {
13296
+ post: updatedModel,
13297
+ });
13298
+ return true;
13299
+ }
13142
13300
  }
13143
13301
  return true;
13144
13302
  };
@@ -13203,6 +13361,7 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
13203
13361
  * @async
13204
13362
  * */
13205
13363
  const removeReaction = async (referenceType, referenceId, reactionName) => {
13364
+ var _a, _b;
13206
13365
  const client = getActiveClient();
13207
13366
  client.log('reaction/removeReaction', {
13208
13367
  referenceId,
@@ -13223,8 +13382,21 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
13223
13382
  'get',
13224
13383
  referenceId,
13225
13384
  ]);
13226
- (model === null || model === void 0 ? void 0 : model.data) &&
13227
- pushToCache([referenceType, 'get', referenceId], model.data, { cachedAt: Date.now() });
13385
+ if (!model)
13386
+ return true;
13387
+ 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) }) });
13388
+ if (referenceType === 'comment') {
13389
+ fireEvent('local.comment.removeReaction', {
13390
+ comment: updatedModel,
13391
+ });
13392
+ return true;
13393
+ }
13394
+ if (referenceType === 'post') {
13395
+ fireEvent('local.post.removeReaction', {
13396
+ post: updatedModel,
13397
+ });
13398
+ return true;
13399
+ }
13228
13400
  }
13229
13401
  return true;
13230
13402
  };
@@ -13252,21 +13424,81 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
13252
13424
  referenceType,
13253
13425
  reactionName,
13254
13426
  });
13255
- if (!client.cache)
13256
- return;
13257
- const model = pullFromCache([
13258
- referenceType,
13259
- 'get',
13260
- referenceId,
13261
- ]);
13262
- if (!(model === null || model === void 0 ? void 0 : model.data) || !((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
13263
- return;
13264
- const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) - 1) }) });
13265
- upsertInCache([referenceType, 'get', referenceId], reaction, {
13266
- cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
13427
+ if (!client.cache)
13428
+ return;
13429
+ const model = pullFromCache([
13430
+ referenceType,
13431
+ 'get',
13432
+ referenceId,
13433
+ ]);
13434
+ if (!(model === null || model === void 0 ? void 0 : model.data) || !((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
13435
+ return;
13436
+ const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) - 1) }) });
13437
+ upsertInCache([referenceType, 'get', referenceId], reaction, {
13438
+ cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
13439
+ });
13440
+ dispatchReactable(referenceType, reaction);
13441
+ return (_e = !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName))) !== null && _e !== void 0 ? _e : false;
13442
+ };
13443
+
13444
+ const getMatchPostSetting = (value) => {
13445
+ var _a;
13446
+ return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
13447
+ CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
13448
+ value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
13449
+ };
13450
+ function addPostSetting({ communities }) {
13451
+ return communities.map((_a) => {
13452
+ var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
13453
+ return (Object.assign({ postSetting: getMatchPostSetting({
13454
+ needApprovalOnPostCreation,
13455
+ onlyAdminCanPost,
13456
+ }) }, restCommunityPayload));
13457
+ });
13458
+ }
13459
+ const prepareCommunityPayload = (rawPayload) => {
13460
+ const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
13461
+ // map users with community
13462
+ const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
13463
+ const user = rawPayload.users.find(user => user.userId === communityUser.userId);
13464
+ return Object.assign(Object.assign({}, communityUser), { user });
13465
+ });
13466
+ const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
13467
+ return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
13468
+ };
13469
+ const prepareCommunityMembershipPayload = (rawPayload) => {
13470
+ const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
13471
+ // map users with community
13472
+ const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
13473
+ const user = rawPayload.users.find(user => user.userId === communityUser.userId);
13474
+ return Object.assign(Object.assign({}, communityUser), { user });
13475
+ });
13476
+ const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
13477
+ return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
13478
+ };
13479
+ const prepareCommunityRequest = (params) => {
13480
+ const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
13481
+ return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
13482
+ // Convert story setting to the actual value. (Allow by default)
13483
+ allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
13484
+ };
13485
+
13486
+ const preparePostPayload = (postPayload) => {
13487
+ // Unpack community payload by mapping payload field to postSetting value.
13488
+ const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
13489
+ // map users with community
13490
+ const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
13491
+ const user = postPayload.users.find(user => user.userId === communityUser.userId);
13492
+ return Object.assign(Object.assign({}, communityUser), { user });
13267
13493
  });
13268
- dispatchReactable(referenceType, reaction);
13269
- return (_e = !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName))) !== null && _e !== void 0 ? _e : false;
13494
+ const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
13495
+ // feed type
13496
+ const posts = postPayload.posts.map(post => {
13497
+ var _a;
13498
+ const feedType = (_a = postPayload.feeds.find(feed => feed.feedId === post.feedId)) === null || _a === void 0 ? void 0 : _a.feedType;
13499
+ return Object.assign(Object.assign({}, post), { feedType });
13500
+ });
13501
+ return Object.assign(Object.assign({}, postPayload), { posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
13270
13502
  };
13271
13503
 
13272
13504
  const createPostEventSubscriber = (event, callback) => {
@@ -13277,8 +13509,8 @@ const createPostEventSubscriber = (event, callback) => {
13277
13509
  callback(payload.posts[0]);
13278
13510
  }
13279
13511
  else {
13280
- const { communities } = payload, others = __rest(payload, ["communities"]);
13281
- const data = prepareMembershipPayload(others, 'communityUsers');
13512
+ const data = preparePostPayload(payload);
13513
+ const { communities } = data;
13282
13514
  ingestInCache(data);
13283
13515
  if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['post.updated'].includes(event)) {
13284
13516
  fireEvent('community.updated', {
@@ -13305,7 +13537,7 @@ const createPostEventSubscriber = (event, callback) => {
13305
13537
  // But if it is hard delete, it will pushed into tombstone before fire an event to BE. it means it will stay in tombstone already
13306
13538
  // and will got skip to notify in a previous code block
13307
13539
  if (postedUserId !== client.userId) {
13308
- pushToTombstone('post', postId);
13540
+ dropFromCache(['post', 'get', postId]);
13309
13541
  }
13310
13542
  return callback(payload.posts[0]);
13311
13543
  }
@@ -13322,6 +13554,32 @@ const createPostEventSubscriber = (event, callback) => {
13322
13554
  }
13323
13555
  };
13324
13556
  return createEventSubscriber(client, event, event, filter);
13557
+ };
13558
+ const createLocalPostEventSubscriber = (event, callback) => {
13559
+ const client = getActiveClient();
13560
+ const filter = (payload) => {
13561
+ if (!client.cache) {
13562
+ callback(payload.posts[0]);
13563
+ }
13564
+ else {
13565
+ const data = preparePostPayload(payload);
13566
+ const { communities } = data;
13567
+ ingestInCache(data);
13568
+ if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['local.post.updated'].includes(event)) {
13569
+ fireEvent('community.updated', {
13570
+ communities,
13571
+ categories: [],
13572
+ communityUsers: data.communityUsers,
13573
+ feeds: [],
13574
+ files: [],
13575
+ users: [],
13576
+ });
13577
+ }
13578
+ const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
13579
+ callback(post.data);
13580
+ }
13581
+ };
13582
+ return createEventSubscriber(client, event, event, filter);
13325
13583
  };
13326
13584
 
13327
13585
  /**
@@ -13528,6 +13786,9 @@ const createCommentEventSubscriber = (event, callback) => {
13528
13786
  comments[0].commentId,
13529
13787
  ]);
13530
13788
  if (['comment.created'].includes(event)) {
13789
+ // NOTE: skip adding comment to parent comment children if it's the same user since we use the local event to update instead.
13790
+ if (event === 'comment.created' && comment.data.userId === client.userId)
13791
+ return;
13531
13792
  if (comments[0].parentId) {
13532
13793
  const parentComment = pullFromCache([
13533
13794
  'comment',
@@ -13549,6 +13810,58 @@ const createCommentEventSubscriber = (event, callback) => {
13549
13810
  }
13550
13811
  };
13551
13812
  return createEventSubscriber(client, event, event, filter);
13813
+ };
13814
+ const createLocalCommentEventSubscriber = (event, callback) => {
13815
+ const client = getActiveClient();
13816
+ const filter = (payload) => {
13817
+ var _a;
13818
+ if (!client.cache) {
13819
+ // TODO: here we are missing specific properties here!
13820
+ callback(LinkedObject.comment(payload.comments[0]));
13821
+ }
13822
+ else {
13823
+ const processed = payload;
13824
+ ingestInCache(processed);
13825
+ const { comments } = processed;
13826
+ if (comments.length > 0) {
13827
+ const comment = pullFromCache([
13828
+ 'comment',
13829
+ 'get',
13830
+ comments[0].commentId,
13831
+ ]);
13832
+ if (['local.comment.created'].includes(event)) {
13833
+ if (comments[0].parentId) {
13834
+ const parentComment = pullFromCache([
13835
+ 'comment',
13836
+ 'get',
13837
+ comments[0].parentId,
13838
+ ]);
13839
+ if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
13840
+ // Skip to update parent childComment if current comment already exists
13841
+ if (!parentComment.data.children.includes(comments[0].commentId)) {
13842
+ const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber + 1, children: [...new Set([...parentComment.data.children, comments[0].commentId])] });
13843
+ pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
13844
+ setTimeout(() => {
13845
+ // NOTE: This is workaround solution for emitting event not work properly.
13846
+ fireEvent('comment.updated', {
13847
+ comments: [newParentComment],
13848
+ commentChildren: [],
13849
+ files: [],
13850
+ users: [],
13851
+ communityUsers: [],
13852
+ });
13853
+ }, 200);
13854
+ }
13855
+ }
13856
+ }
13857
+ const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
13858
+ queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
13859
+ }
13860
+ callback(LinkedObject.comment(comment.data));
13861
+ }
13862
+ }
13863
+ };
13864
+ return createEventSubscriber(client, event, event, filter);
13552
13865
  };
13553
13866
 
13554
13867
  /**
@@ -14108,51 +14421,6 @@ var index$h = /*#__PURE__*/Object.freeze({
14108
14421
  getReactions: getReactions
14109
14422
  });
14110
14423
 
14111
- const getMatchPostSetting = (value) => {
14112
- var _a;
14113
- return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
14114
- CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
14115
- value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
14116
- };
14117
- function addPostSetting({ communities }) {
14118
- return communities.map((_a) => {
14119
- var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
14120
- return (Object.assign({ postSetting: getMatchPostSetting({
14121
- needApprovalOnPostCreation,
14122
- onlyAdminCanPost,
14123
- }) }, restCommunityPayload));
14124
- });
14125
- }
14126
- const prepareCommunityPayload = (rawPayload) => {
14127
- const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
14128
- // map users with community
14129
- const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
14130
- const user = rawPayload.users.find(user => user.userId === communityUser.userId);
14131
- return Object.assign(Object.assign({}, communityUser), { user });
14132
- });
14133
- const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
14134
- return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
14135
- };
14136
- const prepareCommunityRequest = (params) => {
14137
- const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
14138
- return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
14139
- // Convert story setting to the actual value. (Allow by default)
14140
- allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
14141
- };
14142
-
14143
- const preparePostPayload = (postPayload) => {
14144
- const { posts } = postPayload;
14145
- // Unpack community payload by mapping payload field to postSetting value.
14146
- const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
14147
- // map users with community
14148
- const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
14149
- const user = postPayload.users.find(user => user.userId === communityUser.userId);
14150
- return Object.assign(Object.assign({}, communityUser), { user });
14151
- });
14152
- const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
14153
- return Object.assign(Object.assign({}, postPayload), { posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
14154
- };
14155
-
14156
14424
  function prepareCommentPayload(commentPayload) {
14157
14425
  const { comments } = commentPayload;
14158
14426
  return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
@@ -17744,10 +18012,12 @@ const removeMembers$1 = async (channelId, userIds) => {
17744
18012
  */
17745
18013
  class ChannelMemberPaginationController extends PaginationController {
17746
18014
  async getRequest(queryParams, token) {
17747
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
18015
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
17748
18016
  const options = token ? { token } : { limit };
18017
+ const isDeleted = includeDeleted === false ? false : undefined;
17749
18018
  const { data: queryResponse } = await this.http.get(`/api/v4/channels/${encodeURIComponent(params.channelId)}/users`, {
17750
- params: Object.assign(Object.assign({}, params), { options }),
18019
+ params: Object.assign(Object.assign({}, params), { options,
18020
+ isDeleted }),
17751
18021
  });
17752
18022
  return queryResponse;
17753
18023
  }
@@ -17813,6 +18083,33 @@ class ChannelMemberQueryStreamController extends QueryStreamController {
17813
18083
  }
17814
18084
  }
17815
18085
 
18086
+ const onUserDeleted$1 = (channelId) => (callback) => {
18087
+ const client = getActiveClient();
18088
+ const filter = (payload) => {
18089
+ var _a, _b;
18090
+ const userPayload = prepareUserPayload(payload);
18091
+ if (userPayload.users.length === 0)
18092
+ return;
18093
+ const user = userPayload.users[0];
18094
+ ingestInCache(userPayload);
18095
+ const channelUserCacheKey = getResolver('channelUsers')({
18096
+ channelId,
18097
+ userId: user.userId,
18098
+ });
18099
+ const cacheData = (_a = pullFromCache([
18100
+ 'channelUsers',
18101
+ 'get',
18102
+ channelUserCacheKey,
18103
+ ])) === null || _a === void 0 ? void 0 : _a.data;
18104
+ upsertInCache(['channelUsers', 'get', channelUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
18105
+ const channel = (_b = pullFromCache(['channel', 'get', channelId])) === null || _b === void 0 ? void 0 : _b.data;
18106
+ if (!channel)
18107
+ return;
18108
+ callback(channel, cacheData);
18109
+ };
18110
+ return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
18111
+ };
18112
+
17816
18113
  /* eslint-disable no-use-before-define */
17817
18114
  class ChannelMemberLiveCollectionController extends LiveCollectionController {
17818
18115
  constructor(query, callback) {
@@ -17851,6 +18148,7 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
17851
18148
  { fn: onChannelMemberUnbanned, action: 'onChannelMemberUnbanned' },
17852
18149
  { fn: onChannelMemberRoleAdded, action: 'onChannelMemberRoleAdded' },
17853
18150
  { fn: onChannelMemberRoleRemoved, action: 'onChannelMemberRoleRemoved' },
18151
+ { fn: onUserDeleted$1(this.query.channelId), action: 'onChannelMemberChanged' },
17854
18152
  ]);
17855
18153
  }
17856
18154
  notifyChange({ origin, loading, error }) {
@@ -17897,8 +18195,8 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
17897
18195
  console.warn('`search` param will be deprecated in the next major release. If you want to search channel members by displayName, Please use `searchMembers()` instead.');
17898
18196
  channelMembers = filterBySearchTerm(channelMembers, this.query.search);
17899
18197
  }
17900
- if (typeof this.query.includeDeleted === 'boolean') {
17901
- channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted) === this.query.includeDeleted; });
18198
+ if (this.query.includeDeleted === false) {
18199
+ channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted) !== true; });
17902
18200
  }
17903
18201
  // sort, 'lastCreated' is the default sort order
17904
18202
  const sortBy = this.query.sortBy ? this.query.sortBy : 'lastCreated';
@@ -18716,7 +19014,7 @@ function getEventRelatedMember(event, payload) {
18716
19014
  }
18717
19015
  // NOTE: backend returns the one who took the action and the one on whom
18718
19016
  // the action was taken. We need the 2nd one
18719
- if (event === 'community.userRemoved') {
19017
+ if (event === 'community.userRemoved' || event === 'local.community.userRemoved') {
18720
19018
  return payload.communityUsers.filter(x => x.communityMembership === 'none');
18721
19019
  }
18722
19020
  if (event === 'community.userBanned') {
@@ -18764,6 +19062,43 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
18764
19062
  }
18765
19063
  };
18766
19064
  return createEventSubscriber(client, event, event, filter);
19065
+ };
19066
+ const createLocalCommunityMemberEventSubscriber = (event, callback) => {
19067
+ const client = getActiveClient();
19068
+ const filter = (payload) => {
19069
+ const preparedPayload = prepareCommunityPayload(payload);
19070
+ const { communities, communityUsers } = preparedPayload;
19071
+ /*
19072
+ * community.isJoined is not part of the communityMembership payload, and needs
19073
+ * to be calculated based on the communityMembership value
19074
+ */
19075
+ const communitiesWithMembership = updateMembershipStatus(communities, communityUsers);
19076
+ preparedPayload.communities = communitiesWithMembership;
19077
+ if (!client.cache) {
19078
+ // TODO: here we are missing specific properties here!
19079
+ callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
19080
+ }
19081
+ else {
19082
+ ingestInCache(preparedPayload);
19083
+ const community = pullFromCache([
19084
+ 'community',
19085
+ 'get',
19086
+ preparedPayload.communities[0].communityId,
19087
+ ]);
19088
+ const members = getEventRelatedMember(event, preparedPayload)
19089
+ .map(member => {
19090
+ const memberCache = pullFromCache([
19091
+ 'communityUsers',
19092
+ 'get',
19093
+ getResolver('communityUsers')(member),
19094
+ ]);
19095
+ return memberCache === null || memberCache === void 0 ? void 0 : memberCache.data;
19096
+ })
19097
+ .filter(isNonNullable);
19098
+ callback(community.data, members);
19099
+ }
19100
+ };
19101
+ return createEventSubscriber(client, event, event, filter);
18767
19102
  };
18768
19103
 
18769
19104
  /**
@@ -18885,6 +19220,40 @@ const onCommunityUserRoleAdded = (callback) => createCommunityMemberEventSubscri
18885
19220
  */
18886
19221
  const onCommunityUserRoleRemoved = (callback) => createCommunityMemberEventSubscriber('community.roleRemoved', callback);
18887
19222
 
19223
+ /**
19224
+ * ```js
19225
+ * import { onLocalCommunityUserAdded } from '@amityco/ts-sdk'
19226
+ * const dispose = onLocalCommunityUserAdded((community, member) => {
19227
+ * // ...
19228
+ * })
19229
+ * ```
19230
+ *
19231
+ * Fired when a user has been added to a {@link Amity.Community}
19232
+ *
19233
+ * @param callback The function to call when the event was fired
19234
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
19235
+ *
19236
+ * @category Community Events
19237
+ */
19238
+ const onLocalCommunityUserAdded = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userAdded', callback);
19239
+
19240
+ /**
19241
+ * ```js
19242
+ * import { onLocalCommunityUserRemoved } from '@amityco/ts-sdk'
19243
+ * const dispose = onLocalCommunityUserRemoved((community, member) => {
19244
+ * // ...
19245
+ * })
19246
+ * ```
19247
+ *
19248
+ * Fired when a user has been removed from a {@link Amity.Community}
19249
+ *
19250
+ * @param callback The function to call when the event was fired
19251
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
19252
+ *
19253
+ * @category Community Events
19254
+ */
19255
+ const onLocalCommunityUserRemoved = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userRemoved', callback);
19256
+
18888
19257
  /**
18889
19258
  * ```js
18890
19259
  * import { onCommunityJoined } from '@amityco/ts-sdk'
@@ -19037,6 +19406,9 @@ var EnumCommunityMemberActions$1;
19037
19406
  EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
19038
19407
  EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
19039
19408
  EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
19409
+ EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
19410
+ EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
19411
+ EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
19040
19412
  })(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
19041
19413
 
19042
19414
  /* begin_public_function
@@ -19061,7 +19433,7 @@ const addMembers = async (communityId, userIds) => {
19061
19433
  const client = getActiveClient();
19062
19434
  client.log('community/moderation/addMembers', communityId, userIds);
19063
19435
  const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
19064
- fireEvent('community.userAdded', payload);
19436
+ fireEvent('local.community.userAdded', payload);
19065
19437
  const data = prepareMembershipPayload(payload, 'communityUsers');
19066
19438
  if (client.cache)
19067
19439
  ingestInCache(data);
@@ -19092,7 +19464,7 @@ const removeMembers = async (communityId, userIds) => {
19092
19464
  const client = getActiveClient();
19093
19465
  client.log('community/moderation/removeMembers', communityId, userIds);
19094
19466
  const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
19095
- fireEvent('community.userRemoved', payload);
19467
+ fireEvent('local.community.userRemoved', payload);
19096
19468
  const data = prepareMembershipPayload(payload, 'communityUsers');
19097
19469
  if (client.cache)
19098
19470
  ingestInCache(data);
@@ -19107,10 +19479,12 @@ const removeMembers = async (communityId, userIds) => {
19107
19479
  */
19108
19480
  class CommunityMembersPaginationController extends PaginationController {
19109
19481
  async getRequest(queryParams, token) {
19110
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
19482
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
19111
19483
  const options = token ? { token } : { limit };
19484
+ const isDeleted = includeDeleted === false ? false : undefined;
19112
19485
  const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
19113
- params: Object.assign(Object.assign({}, params), { options }),
19486
+ params: Object.assign(Object.assign({}, params), { options,
19487
+ isDeleted }),
19114
19488
  });
19115
19489
  return queryResponse;
19116
19490
  }
@@ -19179,6 +19553,96 @@ class CommunityMembersQueryStreamController extends QueryStreamController {
19179
19553
  }
19180
19554
  }
19181
19555
 
19556
+ /**
19557
+ * ```js
19558
+ * import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk'
19559
+ * const dispose = onLocalCommunityRoleRemoved((community, member) => {
19560
+ * // ...
19561
+ * })
19562
+ * ```
19563
+ *
19564
+ * Fired when any {@link Amity.communityUsers} 's role has been added to any {@link Amity.Community}
19565
+ *
19566
+ * @param callback The function to call when the event was fired
19567
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
19568
+ *
19569
+ * @category Community Events
19570
+ */
19571
+ const onLocalCommunityRoleRemoved = (callback) => {
19572
+ const client = getActiveClient();
19573
+ const filter = async (payload) => {
19574
+ const { communities, communityUsers } = payload;
19575
+ callback(communities[0], communityUsers.filter(communityUser => communityUser.communityMembership === 'member'));
19576
+ };
19577
+ return createEventSubscriber(client, 'onLocalCommunityRoleRemoved', 'local.community.roleRemoved', filter);
19578
+ };
19579
+
19580
+ /**
19581
+ * ```js
19582
+ * import { onLocalCommunityRoleAdded } from '@amityco/ts-sdk'
19583
+ * const dispose = onLocalCommunityRoleAdded((community, member) => {
19584
+ * // ...
19585
+ * })
19586
+ * ```
19587
+ *
19588
+ * Fired when any {@link Amity.communityUsers} 's role has been added to any {@link Amity.Community}
19589
+ *
19590
+ * @param callback The function to call when the event was fired
19591
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
19592
+ *
19593
+ * @category Community Events
19594
+ */
19595
+ const onLocalCommunityRoleAdded = (callback) => {
19596
+ const client = getActiveClient();
19597
+ const filter = async (payload) => {
19598
+ const { communities, communityUsers } = payload;
19599
+ callback(communities[0], communityUsers.filter(communityUser => communityUser.communityMembership === 'member'));
19600
+ };
19601
+ return createEventSubscriber(client, 'onLocalCommunityRoleAdded', 'local.community.roleAdded', filter);
19602
+ };
19603
+
19604
+ /**
19605
+ * ```js
19606
+ * import { onUserDeleted } from '@amityco/ts-sdk'
19607
+ * const dispose = onUserDeleted((community, member) => {
19608
+ * // ...
19609
+ * })
19610
+ * ```
19611
+ *
19612
+ * Fired when a {@link Amity.Community} has been joined
19613
+ *
19614
+ * @param callback The function to call when the event was fired
19615
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
19616
+ *
19617
+ * @category Community Events
19618
+ */
19619
+ const onUserDeleted = (communityId) => (callback) => {
19620
+ const client = getActiveClient();
19621
+ const filter = (payload) => {
19622
+ var _a, _b;
19623
+ const userPayload = prepareUserPayload(payload);
19624
+ if (userPayload.users.length === 0)
19625
+ return;
19626
+ const user = userPayload.users[0];
19627
+ ingestInCache(userPayload);
19628
+ const communityUserCacheKey = getResolver('communityUsers')({
19629
+ communityId,
19630
+ userId: user.userId,
19631
+ });
19632
+ const cacheData = (_a = pullFromCache([
19633
+ 'communityUsers',
19634
+ 'get',
19635
+ communityUserCacheKey,
19636
+ ])) === null || _a === void 0 ? void 0 : _a.data;
19637
+ pushToCache(['communityUsers', 'get', communityUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
19638
+ const community = (_b = pullFromCache(['community', 'get', communityId])) === null || _b === void 0 ? void 0 : _b.data;
19639
+ callback(community, [
19640
+ Object.assign(Object.assign({}, cacheData), { user }),
19641
+ ]);
19642
+ };
19643
+ return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
19644
+ };
19645
+
19182
19646
  class CommunityMembersLiveCollectionController extends LiveCollectionController {
19183
19647
  constructor(query, callback) {
19184
19648
  const queryStreamId = hash__default["default"](query);
@@ -19217,7 +19681,24 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
19217
19681
  fn: onCommunityUserRoleRemoved,
19218
19682
  action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
19219
19683
  },
19684
+ {
19685
+ fn: onLocalCommunityRoleAdded,
19686
+ action: EnumCommunityMemberActions$1.OnCommunityUserRoleAdded,
19687
+ },
19688
+ {
19689
+ fn: onLocalCommunityRoleRemoved,
19690
+ action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
19691
+ },
19220
19692
  { fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions$1.OnCommunityUserUnbanned },
19693
+ { fn: onLocalCommunityUserAdded, action: EnumCommunityMemberActions$1.OnCommunityUserAdded },
19694
+ {
19695
+ fn: onLocalCommunityUserRemoved,
19696
+ action: EnumCommunityMemberActions$1.onCommunityUserRemoved,
19697
+ },
19698
+ {
19699
+ fn: onUserDeleted(this.query.communityId),
19700
+ action: EnumCommunityMemberActions$1.OnCommunityUserChanged,
19701
+ },
19221
19702
  ]);
19222
19703
  }
19223
19704
  notifyChange({ origin, loading, error }) {
@@ -19250,8 +19731,8 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
19250
19731
  if (this.query.search) {
19251
19732
  communityMembers = filterBySearchTerm(communityMembers, this.query.search);
19252
19733
  }
19253
- if (typeof this.query.includeDeleted === 'boolean') {
19254
- communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) === this.query.includeDeleted);
19734
+ if (this.query.includeDeleted === false) {
19735
+ communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
19255
19736
  }
19256
19737
  switch (this.query.sortBy) {
19257
19738
  case 'firstCreated':
@@ -19343,10 +19824,12 @@ const getMembers = (params, callback, config) => {
19343
19824
  */
19344
19825
  class SearchCommunityMembersPaginationController extends PaginationController {
19345
19826
  async getRequest(queryParams, token) {
19346
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
19827
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
19347
19828
  const options = token ? { token } : { limit };
19829
+ const isDeleted = includeDeleted === false ? false : undefined;
19348
19830
  const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
19349
- params: Object.assign(Object.assign({}, params), { options }),
19831
+ params: Object.assign(Object.assign({}, params), { options,
19832
+ isDeleted }),
19350
19833
  });
19351
19834
  return queryResponse;
19352
19835
  }
@@ -19453,11 +19936,19 @@ class SearchCommunityMembersLiveCollectionController extends LiveCollectionContr
19453
19936
  { fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
19454
19937
  { fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
19455
19938
  { fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
19939
+ {
19940
+ fn: onLocalCommunityRoleRemoved,
19941
+ action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
19942
+ },
19456
19943
  {
19457
19944
  fn: onCommunityUserRoleRemoved,
19458
19945
  action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
19459
19946
  },
19460
19947
  { fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
19948
+ {
19949
+ fn: onUserDeleted(this.query.communityId),
19950
+ action: EnumCommunityMemberActions.OnCommunityUserChanged,
19951
+ },
19461
19952
  ]);
19462
19953
  }
19463
19954
  notifyChange({ origin, loading, error }) {
@@ -19490,8 +19981,8 @@ class SearchCommunityMembersLiveCollectionController extends LiveCollectionContr
19490
19981
  if (this.query.search) {
19491
19982
  communityMembers = filterBySearchTerm(communityMembers, this.query.search);
19492
19983
  }
19493
- if (typeof this.query.includeDeleted === 'boolean') {
19494
- communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) === this.query.includeDeleted);
19984
+ if (this.query.includeDeleted === false) {
19985
+ communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
19495
19986
  }
19496
19987
  return communityMembers;
19497
19988
  }
@@ -19554,6 +20045,8 @@ var index$b = /*#__PURE__*/Object.freeze({
19554
20045
  onCommunityUserUnbanned: onCommunityUserUnbanned,
19555
20046
  onCommunityUserRoleAdded: onCommunityUserRoleAdded,
19556
20047
  onCommunityUserRoleRemoved: onCommunityUserRoleRemoved,
20048
+ onLocalCommunityUserAdded: onLocalCommunityUserAdded,
20049
+ onLocalCommunityUserRemoved: onLocalCommunityUserRemoved,
19557
20050
  onCommunityJoined: onCommunityJoined,
19558
20051
  onCommunityLeft: onCommunityLeft
19559
20052
  });
@@ -19817,11 +20310,11 @@ class CommunityLiveCollectionController extends LiveCollectionController {
19817
20310
  if (!this.query.displayName) {
19818
20311
  const sortFn = (() => {
19819
20312
  switch (this.query.sortBy) {
19820
- case "firstCreated" /* Amity.CommunitySortByEnum.FirstCreated */:
20313
+ case 'firstCreated':
19821
20314
  return sortByFirstCreated;
19822
- case "lastCreated" /* Amity.CommunitySortByEnum.LastCreated */:
20315
+ case 'lastCreated':
19823
20316
  return sortByLastCreated;
19824
- case "displayName" /* Amity.CommunitySortByEnum.DisplayName */:
20317
+ case 'displayName':
19825
20318
  return sortByDisplayName;
19826
20319
  default:
19827
20320
  return sortByLastCreated;
@@ -20210,9 +20703,10 @@ const addRoles = async (communityId, roleIds, userIds) => {
20210
20703
  const client = getActiveClient();
20211
20704
  client.log('community/moderation/addRoles', communityId, roleIds, userIds);
20212
20705
  const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/users/roles`, { communityId, roles: roleIds, userIds });
20213
- const data = prepareMembershipPayload(payload, 'communityUsers');
20706
+ const data = prepareCommunityMembershipPayload(payload);
20214
20707
  if (client.cache)
20215
20708
  ingestInCache(data);
20709
+ fireEvent('local.community.roleAdded', data);
20216
20710
  const { communityUsers } = data;
20217
20711
  return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
20218
20712
  roleIds.some(role => communityUser.roles.includes(role)));
@@ -20242,9 +20736,10 @@ const removeRoles = async (communityId, roleIds, userIds) => {
20242
20736
  const client = getActiveClient();
20243
20737
  client.log('community/moderation/removeRoles', communityId, roleIds, userIds);
20244
20738
  const { data: payload } = await client.http.delete(`/api/v4/communities/${communityId}/users/roles`, { data: { communityId, roles: roleIds, userIds } });
20245
- const data = prepareMembershipPayload(payload, 'communityUsers');
20739
+ const data = prepareCommunityMembershipPayload(payload);
20246
20740
  if (client.cache)
20247
20741
  ingestInCache(data);
20742
+ fireEvent('local.community.roleRemoved', data);
20248
20743
  const { communityUsers } = data;
20249
20744
  return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
20250
20745
  !roleIds.some(role => communityUser.roles.includes(role)));
@@ -20931,7 +21426,7 @@ const updatePost = async (postId, patch) => {
20931
21426
  const cachedAt = client.cache && Date.now();
20932
21427
  if (client.cache)
20933
21428
  ingestInCache(data, { cachedAt });
20934
- fireEvent('local.post.updated', data);
21429
+ fireEvent('local.post.updated', payload);
20935
21430
  const { posts } = data;
20936
21431
  return {
20937
21432
  data: LinkedObject.post(posts.find(post => post.postId === postId)),
@@ -21031,7 +21526,15 @@ const deletePost = async (postId, permanent = false) => {
21031
21526
  }
21032
21527
  // to support hard deletion
21033
21528
  const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
21034
- fireEvent('post.deleted', {
21529
+ if (permanent) {
21530
+ setTimeout(() => {
21531
+ pushToTombstone('post', postId);
21532
+ }, 0);
21533
+ }
21534
+ else {
21535
+ upsertInCache(['post', 'get', postId], { isDeleted: true });
21536
+ }
21537
+ fireEvent('local.post.deleted', {
21035
21538
  posts: [deleted],
21036
21539
  categories: [],
21037
21540
  comments: [],
@@ -21042,14 +21545,6 @@ const deletePost = async (postId, permanent = false) => {
21042
21545
  postChildren: [],
21043
21546
  users: [],
21044
21547
  });
21045
- if (permanent) {
21046
- setTimeout(() => {
21047
- pushToTombstone('post', postId);
21048
- }, 0);
21049
- }
21050
- else {
21051
- upsertInCache(['post', 'get', postId], { isDeleted: true });
21052
- }
21053
21548
  return LinkedObject.post(deleted);
21054
21549
  };
21055
21550
 
@@ -21437,6 +21932,7 @@ getCommentByIds.locally = (commentIds) => {
21437
21932
  * @async
21438
21933
  */
21439
21934
  const createComment = async (bundle) => {
21935
+ var _a;
21440
21936
  const client = getActiveClient();
21441
21937
  client.log('comment/createComment', bundle);
21442
21938
  const { data } = await client.http.post('/api/v3/comments', bundle);
@@ -21448,18 +21944,21 @@ const createComment = async (bundle) => {
21448
21944
  if (client.cache)
21449
21945
  ingestInCache(data, { cachedAt });
21450
21946
  if (['post', 'content'].includes(bundle.referenceType)) {
21451
- const post = await getPost$2(bundle.referenceId);
21452
- fireEvent('local.post.updated', {
21453
- posts: [post.data],
21454
- categories: [],
21455
- comments: [],
21456
- communities: [],
21457
- communityUsers: [],
21458
- feeds: [],
21459
- files: [],
21460
- postChildren: [],
21461
- users: [],
21462
- });
21947
+ const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
21948
+ if (post) {
21949
+ post.commentsCount += 1;
21950
+ fireEvent('local.post.updated', {
21951
+ posts: [post],
21952
+ categories: [],
21953
+ comments: [],
21954
+ communities: [],
21955
+ communityUsers: data.communityUsers,
21956
+ feeds: [],
21957
+ files: data.files,
21958
+ postChildren: [],
21959
+ users: data.users,
21960
+ });
21961
+ }
21463
21962
  }
21464
21963
  else if (bundle.referenceType === 'story') {
21465
21964
  const storyIndex = pullFromCache([
@@ -21618,6 +22117,7 @@ getStoryByStoryId$1.locally = (storyId) => {
21618
22117
  * @async
21619
22118
  */
21620
22119
  const deleteComment = async (commentId, permanent = false) => {
22120
+ var _a;
21621
22121
  const client = getActiveClient();
21622
22122
  const comment = await getComment$2(commentId);
21623
22123
  // API-FIX: This endpoint has not been implemented yet.
@@ -21642,18 +22142,28 @@ const deleteComment = async (commentId, permanent = false) => {
21642
22142
  });
21643
22143
  }
21644
22144
  else {
21645
- const post = await getPost$2(comment.data.referenceId);
21646
- fireEvent('local.post.updated', {
21647
- posts: [post.data],
21648
- categories: [],
21649
- comments: [],
21650
- communities: [],
21651
- communityUsers: [],
21652
- feeds: [],
21653
- files: [],
21654
- postChildren: [],
21655
- users: [],
21656
- });
22145
+ const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
22146
+ if (post) {
22147
+ let removeCount;
22148
+ if (!deleted.parentId) {
22149
+ // NOTE: delete the parent comment will remove all children comments
22150
+ removeCount = deleted.childrenNumber + 1;
22151
+ }
22152
+ else
22153
+ removeCount = 1;
22154
+ post.commentsCount -= removeCount;
22155
+ fireEvent('local.post.updated', {
22156
+ posts: [post],
22157
+ categories: [],
22158
+ comments: [],
22159
+ communities: [],
22160
+ communityUsers: [],
22161
+ feeds: [],
22162
+ files: [],
22163
+ postChildren: [],
22164
+ users: [],
22165
+ });
22166
+ }
21657
22167
  }
21658
22168
  fireEvent('local.comment.deleted', {
21659
22169
  comments: [deleted],
@@ -21919,6 +22429,81 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
21919
22429
  };
21920
22430
  };
21921
22431
 
22432
+ /**
22433
+ * ```js
22434
+ * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
22435
+ * const dispose = onCommentDeleteLocal(comment => {
22436
+ * // ...
22437
+ * })
22438
+ * ```
22439
+ *
22440
+ * Fired when a {@link Amity.InternalComment} has been deleted
22441
+ *
22442
+ * @param callback The function to call when the event was fired
22443
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
22444
+ *
22445
+ * @category Comment Events
22446
+ */
22447
+ const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
22448
+
22449
+ /**
22450
+ * ```js
22451
+ * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
22452
+ * const dispose = onLocalCommentReactionAdded(comment => {
22453
+ * // ...
22454
+ * })
22455
+ * ```
22456
+ *
22457
+ * Fired when a {@link Amity.InternalComment} has been reacted
22458
+ *
22459
+ * @param callback The function to call when the event was fired
22460
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
22461
+ *
22462
+ * @category Comment Events
22463
+ */
22464
+ const onLocalCommentReactionAdded = (callback) => {
22465
+ const client = getActiveClient();
22466
+ const filter = ({ comment }) => {
22467
+ if (!client.cache) {
22468
+ callback(comment);
22469
+ }
22470
+ else {
22471
+ upsertInCache(['comment', 'get', comment.commentId], comment);
22472
+ callback(commentLinkedObject(comment));
22473
+ }
22474
+ };
22475
+ return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
22476
+ };
22477
+
22478
+ /**
22479
+ * ```js
22480
+ * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
22481
+ * const dispose = onLocalCommentReactionRemoved(comment => {
22482
+ * // ...
22483
+ * })
22484
+ * ```
22485
+ *
22486
+ * Fired when a {@link Amity.InternalComment} has been reacted
22487
+ *
22488
+ * @param callback The function to call when the event was fired
22489
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
22490
+ *
22491
+ * @category Comment Events
22492
+ */
22493
+ const onLocalCommentReactionRemoved = (callback) => {
22494
+ const client = getActiveClient();
22495
+ const filter = ({ comment }) => {
22496
+ if (!client.cache) {
22497
+ callback(comment);
22498
+ }
22499
+ else {
22500
+ upsertInCache(['comment', 'get', comment.commentId], comment);
22501
+ callback(commentLinkedObject(comment));
22502
+ }
22503
+ };
22504
+ return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
22505
+ };
22506
+
21922
22507
  /* begin_public_function
21923
22508
  id: comment.get
21924
22509
  */
@@ -21943,26 +22528,15 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
21943
22528
  */
21944
22529
  const getComment = (commentId, callback) => {
21945
22530
  return liveObject(commentId, callback, 'commentId', getComment$1, [
22531
+ onCommentDeleteLocal,
21946
22532
  onCommentDeleted,
21947
22533
  onCommentFlagged,
21948
22534
  onCommentReactionAdded,
21949
22535
  onCommentReactionRemoved,
21950
22536
  onCommentUnflagged,
21951
22537
  onCommentUpdated,
21952
- (callback) => {
21953
- return onCommentCreated((comment) => {
21954
- if (comment.parentId !== commentId)
21955
- return;
21956
- const cacheParent = pullFromCache([
21957
- 'comment',
21958
- 'get',
21959
- comment.parentId,
21960
- ]);
21961
- if (!(cacheParent === null || cacheParent === void 0 ? void 0 : cacheParent.data))
21962
- return;
21963
- callback(Object.assign(Object.assign({}, cacheParent.data), { childrenNumber: cacheParent.data.childrenNumber + 1, children: [...new Set([...cacheParent.data.children, comment.commentId])] }));
21964
- });
21965
- },
22538
+ onLocalCommentReactionAdded,
22539
+ onLocalCommentReactionRemoved,
21966
22540
  ]);
21967
22541
  };
21968
22542
  /* end_public_function */
@@ -22046,6 +22620,25 @@ class CommentQueryStreamController extends QueryStreamController {
22046
22620
  }
22047
22621
  }
22048
22622
 
22623
+ /**
22624
+ * ```js
22625
+ * import { onCommentCreated } from '@amityco/ts-sdk'
22626
+ * const dispose = onCommentCreated(comment => {
22627
+ * // ...
22628
+ * })
22629
+ * ```
22630
+ *
22631
+ * Fired when a {@link Amity.InternalComment} has been created
22632
+ *
22633
+ * @param callback The function to call when the event was fired
22634
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
22635
+ *
22636
+ * @category Comment Events
22637
+ */
22638
+ const onCommentCreatedLocal = (callback) => {
22639
+ return createLocalCommentEventSubscriber('local.comment.created', callback);
22640
+ };
22641
+
22049
22642
  class CommentLiveCollectionController extends LiveCollectionController {
22050
22643
  constructor(query, callback) {
22051
22644
  const queryStreamId = hash__default["default"](query);
@@ -22075,6 +22668,8 @@ class CommentLiveCollectionController extends LiveCollectionController {
22075
22668
  }
22076
22669
  startSubscription() {
22077
22670
  return this.queryStreamController.subscribeRTE([
22671
+ { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
22672
+ { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
22078
22673
  { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
22079
22674
  { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
22080
22675
  { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
@@ -22082,6 +22677,8 @@ class CommentLiveCollectionController extends LiveCollectionController {
22082
22677
  { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
22083
22678
  { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
22084
22679
  { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
22680
+ { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
22681
+ { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
22085
22682
  ]);
22086
22683
  }
22087
22684
  notifyChange({ origin, loading, error }) {
@@ -22213,6 +22810,98 @@ var index$6 = /*#__PURE__*/Object.freeze({
22213
22810
  getComments: getComments
22214
22811
  });
22215
22812
 
22813
+ /**
22814
+ * ```js
22815
+ * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
22816
+ * const dispose = onPostUpdatedLocal(post => {
22817
+ * // ...
22818
+ * })
22819
+ * ```
22820
+ *
22821
+ * Fired when a {@link Amity.InternalPost} has been updated
22822
+ *
22823
+ * @param callback The function to call when the event was fired
22824
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
22825
+ *
22826
+ * @category Post Events
22827
+ */
22828
+ const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
22829
+
22830
+ /**
22831
+ * ```js
22832
+ * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
22833
+ * const dispose = onPostReactionAdded(post => {
22834
+ * // ...
22835
+ * })
22836
+ * ```
22837
+ *
22838
+ * Fired when a {@link Amity.InternalPost} has been reacted
22839
+ *
22840
+ * @param callback The function to call when the event was fired
22841
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
22842
+ *
22843
+ * @category Post Events
22844
+ */
22845
+ const onLocalPostReactionAdded = (callback) => {
22846
+ const client = getActiveClient();
22847
+ const filter = ({ post }) => {
22848
+ if (!client.cache) {
22849
+ callback(post);
22850
+ }
22851
+ else {
22852
+ upsertInCache(['post', 'get', post.postId], post);
22853
+ callback(post);
22854
+ }
22855
+ };
22856
+ return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
22857
+ };
22858
+
22859
+ /**
22860
+ * ```js
22861
+ * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
22862
+ * const dispose = onPostReactionRemoved(post => {
22863
+ * // ...
22864
+ * })
22865
+ * ```
22866
+ *
22867
+ * Fired when a {@link Amity.InternalPost} has been reacted
22868
+ *
22869
+ * @param callback The function to call when the event was fired
22870
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
22871
+ *
22872
+ * @category Post Events
22873
+ */
22874
+ const onLocalPostReactionRemoved = (callback) => {
22875
+ const client = getActiveClient();
22876
+ const filter = ({ post }) => {
22877
+ if (!client.cache) {
22878
+ callback(post);
22879
+ }
22880
+ else {
22881
+ upsertInCache(['post', 'get', post.postId], post);
22882
+ callback(post);
22883
+ }
22884
+ };
22885
+ return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
22886
+ };
22887
+
22888
+ /**
22889
+ * ```js
22890
+ * import { onLocalPostDeleted } from '@amityco/ts-sdk'
22891
+ * const dispose = onLocalPostDeleted(post => {
22892
+ * // ...
22893
+ * })
22894
+ * ```
22895
+ *
22896
+ * Fired when a {@link Amity.InternalPost} has been deleted
22897
+ *
22898
+ * @param callback The function to call when the event was fired
22899
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
22900
+ *
22901
+ * @category Post Events
22902
+ */
22903
+ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
22904
+
22216
22905
  /* begin_public_function
22217
22906
  id: post.get
22218
22907
  */
@@ -22243,6 +22932,8 @@ const getPost$1 = (postId, callback) => {
22243
22932
  return liveObject(postId, responder, 'postId', getPost$2, [
22244
22933
  onPostApproved,
22245
22934
  onPostDeclined,
22935
+ onLocalPostReactionAdded,
22936
+ onLocalPostReactionRemoved,
22246
22937
  (callback) => {
22247
22938
  return onPostDeleted((post) => {
22248
22939
  var _a;
@@ -22277,6 +22968,8 @@ const getPost$1 = (postId, callback) => {
22277
22968
  },
22278
22969
  onPostUnflagged,
22279
22970
  onPostUpdated,
22971
+ onPostUpdatedLocal,
22972
+ onLocalPostDeleted,
22280
22973
  convertEventPayload((callback) => {
22281
22974
  return onCommentCreated(async (comment) => {
22282
22975
  if (comment.referenceId === postId) {
@@ -22470,6 +23163,7 @@ class PostLiveCollectionController extends LiveCollectionController {
22470
23163
  return this.queryStreamController.subscribeRTE([
22471
23164
  { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
22472
23165
  { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
23166
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
22473
23167
  { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
22474
23168
  { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
22475
23169
  { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
@@ -22477,6 +23171,9 @@ class PostLiveCollectionController extends LiveCollectionController {
22477
23171
  { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
22478
23172
  { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
22479
23173
  { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
23174
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
23175
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
23176
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
22480
23177
  {
22481
23178
  fn: convertEventPayload((callback) => {
22482
23179
  return onCommentCreated(async (comment) => {