@amityco/ts-sdk 7.5.1-1d67f17.0 → 7.5.1-37cf937.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 (323) hide show
  1. package/dist/@types/core/events.d.ts +7 -0
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +5 -1
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +38 -5
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/client.d.ts +10 -0
  8. package/dist/@types/domains/client.d.ts.map +1 -1
  9. package/dist/@types/domains/community.d.ts +48 -1
  10. package/dist/@types/domains/community.d.ts.map +1 -1
  11. package/dist/@types/domains/invitation.d.ts +87 -0
  12. package/dist/@types/domains/invitation.d.ts.map +1 -0
  13. package/dist/@types/domains/joinRequest.d.ts +53 -0
  14. package/dist/@types/domains/joinRequest.d.ts.map +1 -0
  15. package/dist/@types/domains/notification.d.ts +4 -2
  16. package/dist/@types/domains/notification.d.ts.map +1 -1
  17. package/dist/@types/index.d.ts +3 -0
  18. package/dist/@types/index.d.ts.map +1 -1
  19. package/dist/communityRepository/api/createCommunity.d.ts +2 -2
  20. package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
  21. package/dist/communityRepository/api/getCommunities.d.ts +1 -1
  22. package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
  23. package/dist/communityRepository/api/getCommunity.d.ts +1 -1
  24. package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
  25. package/dist/communityRepository/api/getRecommendedCommunities.d.ts +3 -1
  26. package/dist/communityRepository/api/getRecommendedCommunities.d.ts.map +1 -1
  27. package/dist/communityRepository/api/getTrendingCommunities.d.ts +3 -1
  28. package/dist/communityRepository/api/getTrendingCommunities.d.ts.map +1 -1
  29. package/dist/communityRepository/api/joinCommunity.d.ts +3 -0
  30. package/dist/communityRepository/api/joinCommunity.d.ts.map +1 -1
  31. package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
  32. package/dist/communityRepository/api/updateCommunity.d.ts +2 -2
  33. package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
  34. package/dist/communityRepository/communityMembership/events/index.d.ts +1 -0
  35. package/dist/communityRepository/communityMembership/events/index.d.ts.map +1 -1
  36. package/dist/communityRepository/communityMembership/events/onCommunityJoined.d.ts +1 -1
  37. package/dist/communityRepository/communityMembership/events/onCommunityJoined.d.ts.map +1 -1
  38. package/dist/communityRepository/communityMembership/events/onCommunityLeft.d.ts +1 -1
  39. package/dist/communityRepository/communityMembership/events/onCommunityLeft.d.ts.map +1 -1
  40. package/dist/communityRepository/communityMembership/events/onCommunityUserAdded.d.ts +1 -1
  41. package/dist/communityRepository/communityMembership/events/onCommunityUserAdded.d.ts.map +1 -1
  42. package/dist/communityRepository/communityMembership/events/onCommunityUserBanned.d.ts +1 -1
  43. package/dist/communityRepository/communityMembership/events/onCommunityUserBanned.d.ts.map +1 -1
  44. package/dist/communityRepository/communityMembership/events/onCommunityUserChanged.d.ts +1 -1
  45. package/dist/communityRepository/communityMembership/events/onCommunityUserChanged.d.ts.map +1 -1
  46. package/dist/communityRepository/communityMembership/events/onCommunityUserRemoved.d.ts +1 -1
  47. package/dist/communityRepository/communityMembership/events/onCommunityUserRemoved.d.ts.map +1 -1
  48. package/dist/communityRepository/communityMembership/events/onCommunityUserRoleAdded.d.ts +1 -1
  49. package/dist/communityRepository/communityMembership/events/onCommunityUserRoleAdded.d.ts.map +1 -1
  50. package/dist/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.d.ts +1 -1
  51. package/dist/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.d.ts.map +1 -1
  52. package/dist/communityRepository/communityMembership/events/onCommunityUserUnbanned.d.ts +1 -1
  53. package/dist/communityRepository/communityMembership/events/onCommunityUserUnbanned.d.ts.map +1 -1
  54. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts +2 -0
  55. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts.map +1 -0
  56. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts +1 -1
  57. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts.map +1 -1
  58. package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts +1 -1
  59. package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts.map +1 -1
  60. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts +1 -1
  61. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts.map +1 -1
  62. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts +1 -1
  63. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts.map +1 -1
  64. package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts +1 -1
  65. package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts.map +1 -1
  66. package/dist/communityRepository/communityMembership/events/utils.d.ts +2 -2
  67. package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
  68. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts +2 -2
  69. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +1 -1
  70. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts +2 -2
  71. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts.map +1 -1
  72. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts +1 -1
  73. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts.map +1 -1
  74. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts +1 -1
  75. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts.map +1 -1
  76. package/dist/communityRepository/events/onCommunityCreated.d.ts +1 -1
  77. package/dist/communityRepository/events/onCommunityCreated.d.ts.map +1 -1
  78. package/dist/communityRepository/events/onCommunityDeleted.d.ts +1 -1
  79. package/dist/communityRepository/events/onCommunityDeleted.d.ts.map +1 -1
  80. package/dist/communityRepository/events/onCommunityUpdated.d.ts +1 -1
  81. package/dist/communityRepository/events/onCommunityUpdated.d.ts.map +1 -1
  82. package/dist/communityRepository/events/utils.d.ts +1 -1
  83. package/dist/communityRepository/events/utils.d.ts.map +1 -1
  84. package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts +16 -0
  85. package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts.map +1 -0
  86. package/dist/communityRepository/internalAPI/joinCommunity.d.ts +16 -0
  87. package/dist/communityRepository/internalAPI/joinCommunity.d.ts.map +1 -0
  88. package/dist/communityRepository/joinRequest/events/index.d.ts +4 -0
  89. package/dist/communityRepository/joinRequest/events/index.d.ts.map +1 -0
  90. package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts +17 -0
  91. package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts.map +1 -0
  92. package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts +17 -0
  93. package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts.map +1 -0
  94. package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts +17 -0
  95. package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts.map +1 -0
  96. package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts +16 -0
  97. package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts.map +1 -0
  98. package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts +16 -0
  99. package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts.map +1 -0
  100. package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts +16 -0
  101. package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts.map +1 -0
  102. package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
  103. package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts +2 -2
  104. package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts.map +1 -1
  105. package/dist/communityRepository/observers/getCommunity.d.ts.map +1 -1
  106. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts +14 -0
  107. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts.map +1 -0
  108. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts +9 -0
  109. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts.map +1 -0
  110. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts +15 -0
  111. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts.map +1 -0
  112. package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts +6 -0
  113. package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts.map +1 -0
  114. package/dist/communityRepository/observers/getJoinRequestList.d.ts +12 -0
  115. package/dist/communityRepository/observers/getJoinRequestList.d.ts.map +1 -0
  116. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts +14 -0
  117. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts.map +1 -0
  118. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts +9 -0
  119. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts.map +1 -0
  120. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts +15 -0
  121. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts.map +1 -0
  122. package/dist/communityRepository/observers/getJoinRequests/enum.d.ts +6 -0
  123. package/dist/communityRepository/observers/getJoinRequests/enum.d.ts.map +1 -0
  124. package/dist/communityRepository/observers/getJoinRequests.d.ts +12 -0
  125. package/dist/communityRepository/observers/getJoinRequests.d.ts.map +1 -0
  126. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts.map +1 -1
  127. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts +2 -2
  128. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts.map +1 -1
  129. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts.map +1 -1
  130. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts +2 -2
  131. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts.map +1 -1
  132. package/dist/communityRepository/observers/index.d.ts +1 -0
  133. package/dist/communityRepository/observers/index.d.ts.map +1 -1
  134. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.d.ts.map +1 -1
  135. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts +2 -2
  136. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts.map +1 -1
  137. package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.d.ts +2 -2
  138. package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.d.ts.map +1 -1
  139. package/dist/communityRepository/utils/communityWithMembership.d.ts +1 -1
  140. package/dist/communityRepository/utils/communityWithMembership.d.ts.map +1 -1
  141. package/dist/communityRepository/utils/payload.d.ts +2 -1
  142. package/dist/communityRepository/utils/payload.d.ts.map +1 -1
  143. package/dist/core/events.d.ts +3 -3
  144. package/dist/core/events.d.ts.map +1 -1
  145. package/dist/core/model/idResolvers.d.ts.map +1 -1
  146. package/dist/core/model/index.d.ts.map +1 -1
  147. package/dist/index.cjs.js +2937 -1498
  148. package/dist/index.d.ts +1 -0
  149. package/dist/index.d.ts.map +1 -1
  150. package/dist/index.esm.js +3114 -1676
  151. package/dist/index.umd.js +4 -4
  152. package/dist/invitationRepository/events/index.d.ts +4 -0
  153. package/dist/invitationRepository/events/index.d.ts.map +1 -0
  154. package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts +17 -0
  155. package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts.map +1 -0
  156. package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts +17 -0
  157. package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts.map +1 -0
  158. package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts +17 -0
  159. package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts.map +1 -0
  160. package/dist/invitationRepository/index.d.ts +3 -0
  161. package/dist/invitationRepository/index.d.ts.map +1 -0
  162. package/dist/invitationRepository/internalApi/acceptInvitation.d.ts +16 -0
  163. package/dist/invitationRepository/internalApi/acceptInvitation.d.ts.map +1 -0
  164. package/dist/invitationRepository/internalApi/createInvitations.d.ts +21 -0
  165. package/dist/invitationRepository/internalApi/createInvitations.d.ts.map +1 -0
  166. package/dist/invitationRepository/internalApi/getInvitation.d.ts +17 -0
  167. package/dist/invitationRepository/internalApi/getInvitation.d.ts.map +1 -0
  168. package/dist/invitationRepository/internalApi/index.d.ts +4 -0
  169. package/dist/invitationRepository/internalApi/index.d.ts.map +1 -0
  170. package/dist/invitationRepository/internalApi/rejectInvitation.d.ts +16 -0
  171. package/dist/invitationRepository/internalApi/rejectInvitation.d.ts.map +1 -0
  172. package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts +14 -0
  173. package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts.map +1 -0
  174. package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts +5 -0
  175. package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts.map +1 -0
  176. package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts +15 -0
  177. package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts.map +1 -0
  178. package/dist/invitationRepository/observers/getInvitations/enums.d.ts +6 -0
  179. package/dist/invitationRepository/observers/getInvitations/enums.d.ts.map +1 -0
  180. package/dist/invitationRepository/observers/getInvitations.d.ts +12 -0
  181. package/dist/invitationRepository/observers/getInvitations.d.ts.map +1 -0
  182. package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts +12 -0
  183. package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts.map +1 -0
  184. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts +14 -0
  185. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts.map +1 -0
  186. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts +5 -0
  187. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts.map +1 -0
  188. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts +15 -0
  189. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts.map +1 -0
  190. package/dist/invitationRepository/observers/index.d.ts +2 -0
  191. package/dist/invitationRepository/observers/index.d.ts.map +1 -0
  192. package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts +2 -0
  193. package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts.map +1 -0
  194. package/dist/invitationRepository/utils/index.d.ts +2 -0
  195. package/dist/invitationRepository/utils/index.d.ts.map +1 -0
  196. package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts +2 -0
  197. package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts.map +1 -0
  198. package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts +2 -0
  199. package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts.map +1 -0
  200. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts.map +1 -1
  201. package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
  202. package/dist/subChannelRepository/utils/prepareSubChannelPayload.d.ts.map +1 -1
  203. package/dist/utils/linkedObject/communityLinkedObject.d.ts +2 -0
  204. package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -0
  205. package/dist/utils/linkedObject/index.d.ts +3 -0
  206. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  207. package/dist/utils/linkedObject/invitationLinkedObject.d.ts +2 -0
  208. package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -0
  209. package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts +2 -0
  210. package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts.map +1 -0
  211. package/dist/utils/tests/dummy/post.d.ts +3 -3
  212. package/package.json +1 -1
  213. package/src/@types/core/events.ts +10 -0
  214. package/src/@types/core/model.ts +8 -1
  215. package/src/@types/core/payload.ts +48 -5
  216. package/src/@types/domains/client.ts +12 -0
  217. package/src/@types/domains/community.ts +73 -1
  218. package/src/@types/domains/invitation.ts +115 -0
  219. package/src/@types/domains/joinRequest.ts +66 -0
  220. package/src/@types/domains/notification.ts +2 -0
  221. package/src/@types/index.ts +3 -0
  222. package/src/communityRepository/api/createCommunity.ts +5 -2
  223. package/src/communityRepository/api/getCommunities.ts +9 -2
  224. package/src/communityRepository/api/getCommunity.ts +13 -2
  225. package/src/communityRepository/api/getRecommendedCommunities.ts +11 -4
  226. package/src/communityRepository/api/getTrendingCommunities.ts +11 -4
  227. package/src/communityRepository/api/joinCommunity.ts +4 -1
  228. package/src/communityRepository/api/queryCommunities.ts +6 -1
  229. package/src/communityRepository/api/updateCommunity.ts +13 -3
  230. package/src/communityRepository/communityMembership/events/index.ts +1 -0
  231. package/src/communityRepository/communityMembership/events/onCommunityJoined.ts +1 -1
  232. package/src/communityRepository/communityMembership/events/onCommunityLeft.ts +1 -1
  233. package/src/communityRepository/communityMembership/events/onCommunityUserAdded.ts +1 -1
  234. package/src/communityRepository/communityMembership/events/onCommunityUserBanned.ts +1 -1
  235. package/src/communityRepository/communityMembership/events/onCommunityUserChanged.ts +1 -1
  236. package/src/communityRepository/communityMembership/events/onCommunityUserRemoved.ts +1 -1
  237. package/src/communityRepository/communityMembership/events/onCommunityUserRoleAdded.ts +1 -1
  238. package/src/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.ts +1 -1
  239. package/src/communityRepository/communityMembership/events/onCommunityUserUnbanned.ts +1 -1
  240. package/src/communityRepository/communityMembership/events/onLocalCommunityJoin.ts +20 -0
  241. package/src/communityRepository/communityMembership/events/onLocalCommunityJoined.ts +1 -1
  242. package/src/communityRepository/communityMembership/events/onLocalCommunityLeft.ts +1 -1
  243. package/src/communityRepository/communityMembership/events/onLocalCommunityUserAdded.ts +1 -1
  244. package/src/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.ts +1 -1
  245. package/src/communityRepository/communityMembership/events/onUserDeleted.ts +3 -1
  246. package/src/communityRepository/communityMembership/events/utils.ts +2 -2
  247. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +8 -2
  248. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.ts +8 -2
  249. package/src/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.ts +1 -1
  250. package/src/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.ts +1 -1
  251. package/src/communityRepository/events/onCommunityCreated.ts +1 -1
  252. package/src/communityRepository/events/onCommunityDeleted.ts +1 -1
  253. package/src/communityRepository/events/onCommunityUpdated.ts +1 -1
  254. package/src/communityRepository/events/utils.ts +1 -1
  255. package/src/communityRepository/internalAPI/getMyJoinRequest.ts +43 -0
  256. package/src/communityRepository/internalAPI/joinCommunity.ts +66 -0
  257. package/src/communityRepository/joinRequest/events/index.ts +3 -0
  258. package/src/communityRepository/joinRequest/events/onJoinRequestCreated.ts +33 -0
  259. package/src/communityRepository/joinRequest/events/onJoinRequestDeleted.ts +33 -0
  260. package/src/communityRepository/joinRequest/events/onJoinRequestUpdated.ts +33 -0
  261. package/src/communityRepository/joinRequest/internalAPI/approveJoinRequest.ts +52 -0
  262. package/src/communityRepository/joinRequest/internalAPI/cancelJoinRequest.ts +46 -0
  263. package/src/communityRepository/joinRequest/internalAPI/rejectJoinRequest.ts +52 -0
  264. package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +6 -0
  265. package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +2 -2
  266. package/src/communityRepository/observers/getCommunity.ts +3 -0
  267. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.ts +130 -0
  268. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.ts +30 -0
  269. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.ts +112 -0
  270. package/src/communityRepository/observers/getJoinRequestList/enum.ts +5 -0
  271. package/src/communityRepository/observers/getJoinRequestList.ts +51 -0
  272. package/src/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.ts +126 -0
  273. package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts +26 -0
  274. package/src/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.ts +108 -0
  275. package/src/communityRepository/observers/getJoinRequests/enum.ts +5 -0
  276. package/src/communityRepository/observers/getJoinRequests.ts +44 -0
  277. package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.ts +2 -1
  278. package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.ts +2 -2
  279. package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.ts +2 -1
  280. package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.ts +2 -2
  281. package/src/communityRepository/observers/index.ts +1 -0
  282. package/src/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.ts +1 -0
  283. package/src/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.ts +2 -2
  284. package/src/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.ts +2 -2
  285. package/src/communityRepository/utils/communityWithMembership.ts +9 -5
  286. package/src/communityRepository/utils/payload.ts +28 -2
  287. package/src/core/liveCollection/PaginationController.ts +1 -1
  288. package/src/core/liveCollection/PaginationNoPageController.ts +1 -1
  289. package/src/core/model/idResolvers.ts +3 -0
  290. package/src/core/model/index.ts +3 -0
  291. package/src/index.ts +2 -0
  292. package/src/invitationRepository/events/index.ts +3 -0
  293. package/src/invitationRepository/events/onLocalInvitationCreated.ts +33 -0
  294. package/src/invitationRepository/events/onLocalInvitationDeleted.ts +33 -0
  295. package/src/invitationRepository/events/onLocalInvitationUpdated.ts +33 -0
  296. package/src/invitationRepository/index.ts +2 -0
  297. package/src/invitationRepository/internalApi/acceptInvitation.ts +45 -0
  298. package/src/invitationRepository/internalApi/createInvitations.ts +52 -0
  299. package/src/invitationRepository/internalApi/getInvitation.ts +47 -0
  300. package/src/invitationRepository/internalApi/index.ts +3 -0
  301. package/src/invitationRepository/internalApi/rejectInvitation.ts +45 -0
  302. package/src/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.ts +148 -0
  303. package/src/invitationRepository/observers/getInvitations/InvitationsPaginationController.ts +19 -0
  304. package/src/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.ts +97 -0
  305. package/src/invitationRepository/observers/getInvitations/enums.ts +5 -0
  306. package/src/invitationRepository/observers/getInvitations.ts +44 -0
  307. package/src/invitationRepository/observers/getMyCommunityInvitations.ts +48 -0
  308. package/src/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.ts +148 -0
  309. package/src/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.ts +22 -0
  310. package/src/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.ts +105 -0
  311. package/src/invitationRepository/observers/index.ts +1 -0
  312. package/src/invitationRepository/utils/convertRawInvitationToInternalInvitation.ts +8 -0
  313. package/src/invitationRepository/utils/index.ts +1 -0
  314. package/src/invitationRepository/utils/prepareInvitationPayload.ts +12 -0
  315. package/src/invitationRepository/utils/prepareMyInvitationsPayload.ts +12 -0
  316. package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +3 -3
  317. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts +7 -1
  318. package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +7 -1
  319. package/src/subChannelRepository/utils/prepareSubChannelPayload.ts +4 -0
  320. package/src/utils/linkedObject/communityLinkedObject.ts +58 -0
  321. package/src/utils/linkedObject/index.ts +6 -0
  322. package/src/utils/linkedObject/invitationLinkedObject.ts +37 -0
  323. package/src/utils/linkedObject/joinRequestLinkedObject.ts +31 -0
@@ -0,0 +1,46 @@
1
+ import { fireEvent } from '~/core/events';
2
+ import { dropFromCache, pullFromCache } from '~/cache/api';
3
+ import { getActiveClient } from '~/client/api/activeClient';
4
+
5
+ /* begin_public_function
6
+ id: joinRequest.cancel
7
+ */
8
+ /**
9
+ * ```js
10
+ * import { joinRequest } from '@amityco/ts-sdk'
11
+ * const isCanceled = await joinRequest.cancel()
12
+ * ```
13
+ *
14
+ * Cancels a {@link Amity.JoinRequest} object
15
+ *
16
+ * @param joinRequest the {@link Amity.JoinRequest} to cancel
17
+ * @returns A success boolean if the {@link Amity.JoinRequest} was canceled
18
+ *
19
+ * @category Join Request API
20
+ * @async
21
+ */
22
+ export const cancelJoinRequest = async (
23
+ joinRequest: Amity.InternalJoinRequest,
24
+ ): Promise<boolean> => {
25
+ const client = getActiveClient();
26
+ client.log('joinRequest/cancelJoinRequest', joinRequest.joinRequestId);
27
+
28
+ const { data } = await client.http.delete<{ success: boolean }>(
29
+ `/api/v4/communities/${joinRequest.targetId}/join`,
30
+ );
31
+
32
+ const joinRequestCache = pullFromCache<Amity.InternalJoinRequest>([
33
+ 'joinRequest',
34
+ 'get',
35
+ joinRequest.joinRequestId,
36
+ ])?.data;
37
+
38
+ if (joinRequestCache) {
39
+ dropFromCache(['joinRequest', 'get', joinRequest.joinRequestId]);
40
+
41
+ fireEvent('local.joinRequest.deleted', [joinRequestCache]);
42
+ }
43
+
44
+ return data.success;
45
+ };
46
+ /* end_public_function */
@@ -0,0 +1,52 @@
1
+ import { fireEvent } from '~/core/events';
2
+ import { pullFromCache, upsertInCache } from '~/cache/api';
3
+ import { getActiveClient } from '~/client/api/activeClient';
4
+ import { JoinRequestStatusEnum } from '~/@types/domains/joinRequest';
5
+
6
+ /* begin_public_function
7
+ id: joinRequest.reject
8
+ */
9
+ /**
10
+ * ```js
11
+ * import { joinRequest } from '@amityco/ts-sdk'
12
+ * const isRejected = await joinRequest.reject()
13
+ * ```
14
+ *
15
+ * Rejects a {@link Amity.JoinRequest} object
16
+ *
17
+ * @param joinRequest the {@link Amity.JoinRequest} to reject
18
+ * @returns A success boolean if the {@link Amity.JoinRequest} was rejected
19
+ *
20
+ * @category Join Request API
21
+ * @async
22
+ */
23
+ export const rejectJoinRequest = async (
24
+ joinRequest: Amity.InternalJoinRequest,
25
+ ): Promise<boolean> => {
26
+ const client = getActiveClient();
27
+ client.log('joinRequest/rejectJoinRequest', joinRequest.joinRequestId);
28
+
29
+ const { data } = await client.http.post<{ success: boolean }>(
30
+ `/api/v4/communities/${joinRequest.targetId}/join/reject`,
31
+ {
32
+ userId: joinRequest.requestorInternalId,
33
+ },
34
+ );
35
+
36
+ const joinRequestCache = pullFromCache<Amity.InternalJoinRequest>([
37
+ 'joinRequest',
38
+ 'get',
39
+ joinRequest.joinRequestId,
40
+ ])?.data;
41
+
42
+ if (joinRequestCache) {
43
+ upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
44
+ status: JoinRequestStatusEnum.Rejected,
45
+ });
46
+
47
+ fireEvent('local.joinRequest.updated', [joinRequestCache]);
48
+ }
49
+
50
+ return data.success;
51
+ };
52
+ /* end_public_function */
@@ -25,8 +25,10 @@ import {
25
25
  onLocalCommunityJoined,
26
26
  onLocalCommunityLeft,
27
27
  onCommunityUserChanged,
28
+ onLocalCommunityJoin,
28
29
  } from '~/communityRepository/communityMembership';
29
30
  import { isNonNullable } from '~/utils';
31
+ import { convertEventPayload } from '~/utils/event';
30
32
 
31
33
  export class CommunityLiveCollectionController extends LiveCollectionController<
32
34
  'community',
@@ -92,6 +94,10 @@ export class CommunityLiveCollectionController extends LiveCollectionController<
92
94
  { fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnMemberCountChanged },
93
95
  { fn: onLocalCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
94
96
  { fn: onLocalCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
97
+ {
98
+ fn: convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
99
+ action: EnumCommunityActions.OnCommunityUpdated,
100
+ },
95
101
  ]);
96
102
  }
97
103
 
@@ -60,7 +60,7 @@ export class CommunitiesQueryStreamController extends QueryStreamController<
60
60
  }
61
61
 
62
62
  reactor(action: EnumCommunityActions | EnumCommunityMemberActions) {
63
- return (community: Amity.Community) => {
63
+ return (community: Amity.InternalCommunity) => {
64
64
  const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(this.cacheKey)?.data;
65
65
  if (!collection) return;
66
66
 
@@ -76,7 +76,7 @@ export class CommunitiesQueryStreamController extends QueryStreamController<
76
76
 
77
77
  subscribeRTE(
78
78
  createSubscriber: {
79
- fn: (reactor: (channel: Amity.Community) => void) => Amity.Unsubscriber;
79
+ fn: (reactor: (channel: Amity.InternalCommunity) => void) => Amity.Unsubscriber;
80
80
  action: EnumCommunityActions | EnumCommunityMemberActions;
81
81
  }[],
82
82
  ) {
@@ -9,7 +9,9 @@ import {
9
9
  onCommunityLeft,
10
10
  onLocalCommunityJoined,
11
11
  onLocalCommunityLeft,
12
+ onLocalCommunityJoin,
12
13
  } from '../communityMembership/events';
14
+ import { convertEventPayload } from '~/utils/event';
13
15
 
14
16
  /* begin_public_function
15
17
  id: community.get
@@ -47,6 +49,7 @@ export const getCommunity = (
47
49
  onCommunityUserBanned,
48
50
  onCommunityUserUnbanned,
49
51
  onCommunityUserChanged,
52
+ convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
50
53
  ]);
51
54
  };
52
55
  /* end_public_function */
@@ -0,0 +1,130 @@
1
+ import hash from 'object-hash';
2
+ import { pullFromCache, pushToCache } from '~/cache/api';
3
+ import { JoinRequestListPaginationController } from './JoinRequestListPaginationController';
4
+ import { JoinRequestListQueryStreamController } from './JoinRequestListQueryStreamController';
5
+ import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
6
+ import { sortByFirstCreated, sortByLastCreated } from '~/core/query';
7
+ import { prepareCommunityJoinRequestPayload } from '~/communityRepository/utils';
8
+ import { EnumJoinRequestAction } from './enum';
9
+ import { isNonNullable } from '~/utils';
10
+ import { joinRequestLinkedObject } from '~/utils/linkedObject/joinRequestLinkedObject';
11
+ import {
12
+ onJoinRequestCreated,
13
+ onJoinRequestDeleted,
14
+ onJoinRequestUpdated,
15
+ } from '~/communityRepository/joinRequest/events/';
16
+
17
+ export class JoinRequestListLiveCollectionController extends LiveCollectionController<
18
+ 'joinRequest',
19
+ Amity.JoinRequestListLiveCollection,
20
+ Amity.JoinRequest,
21
+ JoinRequestListPaginationController
22
+ > {
23
+ private queryStreamController: JoinRequestListQueryStreamController;
24
+
25
+ private query: Amity.JoinRequestListLiveCollection;
26
+
27
+ constructor(
28
+ query: Amity.JoinRequestListLiveCollection,
29
+ callback: Amity.LiveCollectionCallback<Amity.JoinRequest>,
30
+ ) {
31
+ const queryStreamId = hash(query);
32
+ const cacheKey = ['joinRequestList', 'collection', queryStreamId];
33
+ const paginationController = new JoinRequestListPaginationController(query);
34
+
35
+ super(paginationController, queryStreamId, cacheKey, callback);
36
+
37
+ this.query = query;
38
+ this.queryStreamController = new JoinRequestListQueryStreamController(
39
+ this.query,
40
+ this.cacheKey,
41
+ this.notifyChange.bind(this),
42
+ prepareCommunityJoinRequestPayload,
43
+ );
44
+
45
+ this.callback = callback.bind(this);
46
+ this.loadPage({ initial: true });
47
+ }
48
+
49
+ protected setup() {
50
+ const collection = pullFromCache<Amity.JoinRequestListLiveCollectionCache>(this.cacheKey)?.data;
51
+
52
+ if (!collection) {
53
+ pushToCache(this.cacheKey, {
54
+ data: [],
55
+ params: this.query,
56
+ });
57
+ }
58
+ }
59
+
60
+ protected async persistModel(queryPayload: Amity.CommunityJoinRequestPayload & Amity.Pagination) {
61
+ await this.queryStreamController.saveToMainDB(queryPayload);
62
+ }
63
+
64
+ protected persistQueryStream({
65
+ response,
66
+ direction,
67
+ refresh,
68
+ }: Amity.LiveCollectionPersistQueryStreamParams<'joinRequest'>) {
69
+ const joinRequestResponse = response as unknown as Amity.CommunityJoinRequestPayload &
70
+ Partial<Amity.Pagination>;
71
+ this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
72
+ }
73
+
74
+ startSubscription() {
75
+ return this.queryStreamController.subscribeRTE([
76
+ { fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
77
+ { fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
78
+ { fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
79
+ ]);
80
+ }
81
+
82
+ notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
83
+ const collection = pullFromCache<Amity.JoinRequestListLiveCollectionCache>(this.cacheKey)?.data;
84
+
85
+ if (!collection) return;
86
+
87
+ const data = this.applyFilter(
88
+ collection.data
89
+ .map(id => pullFromCache<Amity.InternalJoinRequest>(['joinRequest', 'get', id])!)
90
+ .filter(isNonNullable)
91
+ .map(({ data }) => data)
92
+ .map(joinRequestLinkedObject),
93
+ );
94
+
95
+ if (!this.shouldNotify(data) && origin === 'event') return;
96
+
97
+ this.callback({
98
+ onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
99
+ data,
100
+ hasNextPage: !!this.paginationController.getNextToken(),
101
+ loading,
102
+ error,
103
+ });
104
+ }
105
+
106
+ applyFilter(data: Amity.JoinRequest[]) {
107
+ let joinRequest = data;
108
+
109
+ if (this.query.communityIds && this.query.communityIds.length > 0) {
110
+ joinRequest = joinRequest.filter(joinRequest =>
111
+ this.query.communityIds.some(id => id === joinRequest.targetId),
112
+ );
113
+ }
114
+
115
+ const sortFn = (() => {
116
+ switch (this.query.sortBy) {
117
+ case 'firstCreated':
118
+ return sortByFirstCreated;
119
+ case 'lastCreated':
120
+ return sortByLastCreated;
121
+ default:
122
+ return sortByLastCreated;
123
+ }
124
+ })();
125
+
126
+ joinRequest = joinRequest.sort(sortFn);
127
+
128
+ return joinRequest;
129
+ }
130
+ }
@@ -0,0 +1,30 @@
1
+ import { PaginationController } from '~/core/liveCollection/PaginationController';
2
+ import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
3
+
4
+ /**
5
+ * TODO: handle cache receive cache option, and cache policy
6
+ * TODO: check if querybyIds is supported
7
+ */
8
+ export class JoinRequestListPaginationController extends PaginationController<
9
+ 'joinRequest',
10
+ Amity.JoinRequestListLiveCollection
11
+ > {
12
+ async getRequest(queryParams: Amity.JoinRequestListLiveCollection, token: string | undefined) {
13
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityIds, ...params } = queryParams;
14
+ const options = token ? { token } : { limit };
15
+
16
+ const encodedChannelIds = communityIds.map(communityId => encodeURIComponent(communityId));
17
+
18
+ const { data: queryResponse } = await this.http.get<
19
+ Amity.CommunityJoinRequestPayload & Amity.Pagination
20
+ >(`/api/v4/communities/join/requests`, {
21
+ params: {
22
+ ...params,
23
+ options,
24
+ communityIds: encodedChannelIds,
25
+ },
26
+ });
27
+
28
+ return queryResponse;
29
+ }
30
+ }
@@ -0,0 +1,112 @@
1
+ import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
2
+ import { pullFromCache, pushToCache } from '~/cache/api';
3
+ import { ingestInCache } from '~/cache/api/ingestInCache';
4
+ import { getResolver } from '~/core/model';
5
+ import { getActiveClient } from '~/client/api/activeClient';
6
+ import { EnumJoinRequestAction } from './enum';
7
+
8
+ export class JoinRequestListQueryStreamController extends QueryStreamController<
9
+ Amity.CommunityJoinRequestPayload,
10
+ Amity.JoinRequestListLiveCollection
11
+ > {
12
+ private notifyChange: (params: Amity.LiveCollectionNotifyParams) => void;
13
+
14
+ private preparePayload: (
15
+ response: Amity.CommunityJoinRequestPayload,
16
+ ) => Amity.ProcessedJoinRequestPayload;
17
+
18
+ constructor(
19
+ query: Amity.JoinRequestListLiveCollection,
20
+ cacheKey: string[],
21
+ notifyChange: (params: Amity.LiveCollectionNotifyParams) => void,
22
+ preparePayload: (
23
+ response: Amity.CommunityJoinRequestPayload,
24
+ ) => Amity.ProcessedJoinRequestPayload,
25
+ ) {
26
+ super(query, cacheKey);
27
+ this.notifyChange = notifyChange;
28
+ this.preparePayload = preparePayload;
29
+ }
30
+
31
+ async saveToMainDB(response: Amity.CommunityJoinRequestPayload) {
32
+ const processedPayload = await this.preparePayload(response);
33
+
34
+ const client = getActiveClient();
35
+ const cachedAt = client.cache && Date.now();
36
+
37
+ if (client.cache) {
38
+ ingestInCache(processedPayload, { cachedAt });
39
+ }
40
+ }
41
+
42
+ appendToQueryStream(
43
+ response: Amity.CommunityJoinRequestPayload & Partial<Amity.Pagination>,
44
+ direction: Amity.LiveCollectionPageDirection,
45
+ refresh = false,
46
+ ) {
47
+ if (refresh) {
48
+ pushToCache(this.cacheKey, {
49
+ data: response.joinRequests.map(joinRequest =>
50
+ getResolver('joinRequest')({ joinRequestId: joinRequest._id }),
51
+ ),
52
+ });
53
+ } else {
54
+ const collection = pullFromCache<Amity.JoinRequestListLiveCollectionCache>(
55
+ this.cacheKey,
56
+ )?.data;
57
+
58
+ const joinRequests = collection?.data ?? [];
59
+
60
+ pushToCache(this.cacheKey, {
61
+ ...collection,
62
+ data: [
63
+ ...new Set([
64
+ ...joinRequests,
65
+ ...response.joinRequests.map(joinRequest =>
66
+ getResolver('joinRequest')({ joinRequestId: joinRequest._id }),
67
+ ),
68
+ ]),
69
+ ],
70
+ });
71
+ }
72
+ }
73
+
74
+ reactor(action: EnumJoinRequestAction) {
75
+ return (joinRequest: Amity.InternalJoinRequest[]) => {
76
+ const collection = pullFromCache<Amity.JoinRequestListLiveCollectionCache>(
77
+ this.cacheKey,
78
+ )?.data;
79
+ if (!collection) return;
80
+
81
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
82
+ const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
83
+ if (!isExist) return;
84
+ }
85
+
86
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
87
+ collection.data = [
88
+ ...new Set([
89
+ ...joinRequest.map(joinRequest => joinRequest.joinRequestId),
90
+ ...collection.data,
91
+ ]),
92
+ ];
93
+ }
94
+
95
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
96
+ collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
97
+ }
98
+
99
+ pushToCache(this.cacheKey, collection);
100
+ this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
101
+ };
102
+ }
103
+
104
+ subscribeRTE(
105
+ createSubscriber: {
106
+ fn: (reactor: Amity.Listener<Amity.InternalJoinRequest[]>) => Amity.Unsubscriber;
107
+ action: EnumJoinRequestAction;
108
+ }[],
109
+ ) {
110
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
111
+ }
112
+ }
@@ -0,0 +1,5 @@
1
+ export enum EnumJoinRequestAction {
2
+ OnLocalJoinRequestCreated = 'OnLocalJoinRequestCreated',
3
+ OnLocalJoinRequestUpdated = 'OnLocalJoinRequestUpdated',
4
+ OnLocalJoinRequestDeleted = 'OnLocalJoinRequestDeleted',
5
+ }
@@ -0,0 +1,51 @@
1
+ import { dropFromCache } from '~/cache/api/dropFromCache';
2
+ import { getActiveClient } from '~/client/api/activeClient';
3
+ import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
4
+ import { JoinRequestListLiveCollectionController } from './getJoinRequestList/JoinRequestListLiveCollectionController';
5
+
6
+ /* begin_public_function
7
+ id: community.getJoinRequestList
8
+ */
9
+ /**
10
+ * Get Join Requests
11
+ *
12
+ * @param params the query parameters
13
+ * @param callback the callback to be called when the join request are updated
14
+ * @returns joinRequest[]
15
+ *
16
+ * @category joinRequestList Live Collection
17
+ *
18
+ */
19
+ export const getJoinRequestList = (
20
+ params: Amity.JoinRequestListLiveCollection,
21
+ callback: Amity.LiveCollectionCallback<Amity.JoinRequest>,
22
+ config?: Amity.LiveCollectionConfig,
23
+ ) => {
24
+ const { log, cache } = getActiveClient();
25
+
26
+ if (!cache) {
27
+ console.log(ENABLE_CACHE_MESSAGE);
28
+ }
29
+
30
+ const timestamp = Date.now();
31
+ log(`getJoinRequestList: (tmpid: ${timestamp}) > listen`);
32
+
33
+ const joinRequestListLiveCollection = new JoinRequestListLiveCollectionController(
34
+ params,
35
+ callback,
36
+ );
37
+
38
+ const disposers = joinRequestListLiveCollection.startSubscription();
39
+
40
+ const cacheKey = joinRequestListLiveCollection.getCacheKey();
41
+
42
+ disposers.push(() => {
43
+ dropFromCache(cacheKey);
44
+ });
45
+
46
+ return () => {
47
+ log(`getJoinRequestList (tmpid: ${timestamp}) > dispose`);
48
+ disposers.forEach(fn => fn());
49
+ };
50
+ };
51
+ /* end_public_function */
@@ -0,0 +1,126 @@
1
+ import hash from 'object-hash';
2
+ import { pullFromCache, pushToCache } from '~/cache/api';
3
+ import { JoinRequestsPaginationController } from './JoinRequestsPaginationController';
4
+ import { JoinRequestsQueryStreamController } from './JoinRequestsQueryStreamController';
5
+ import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
6
+ import { sortByFirstCreated, sortByLastCreated } from '~/core/query';
7
+ import { prepareCommunityJoinRequestPayload } from '~/communityRepository/utils';
8
+ import { EnumJoinRequestAction } from './enum';
9
+ import { isNonNullable } from '~/utils';
10
+ import { joinRequestLinkedObject } from '~/utils/linkedObject/joinRequestLinkedObject';
11
+ import {
12
+ onJoinRequestCreated,
13
+ onJoinRequestDeleted,
14
+ onJoinRequestUpdated,
15
+ } from '~/communityRepository/joinRequest/events/';
16
+
17
+ export class JoinRequestsLiveCollectionController extends LiveCollectionController<
18
+ 'joinRequest',
19
+ Amity.JoinRequestLiveCollection,
20
+ Amity.JoinRequest,
21
+ JoinRequestsPaginationController
22
+ > {
23
+ private queryStreamController: JoinRequestsQueryStreamController;
24
+
25
+ private query: Amity.JoinRequestLiveCollection;
26
+
27
+ constructor(
28
+ query: Amity.JoinRequestLiveCollection,
29
+ callback: Amity.LiveCollectionCallback<Amity.JoinRequest>,
30
+ ) {
31
+ const queryStreamId = hash(query);
32
+ const cacheKey = ['joinRequest', 'collection', queryStreamId];
33
+ const paginationController = new JoinRequestsPaginationController(query);
34
+
35
+ super(paginationController, queryStreamId, cacheKey, callback);
36
+
37
+ this.query = query;
38
+ this.queryStreamController = new JoinRequestsQueryStreamController(
39
+ this.query,
40
+ this.cacheKey,
41
+ this.notifyChange.bind(this),
42
+ prepareCommunityJoinRequestPayload,
43
+ );
44
+
45
+ this.callback = callback.bind(this);
46
+ this.loadPage({ initial: true });
47
+ }
48
+
49
+ protected setup() {
50
+ const collection = pullFromCache<Amity.JoinRequestLiveCollectionCache>(this.cacheKey)?.data;
51
+ if (!collection) {
52
+ pushToCache(this.cacheKey, {
53
+ data: [],
54
+ params: this.query,
55
+ });
56
+ }
57
+ }
58
+
59
+ protected async persistModel(queryPayload: Amity.CommunityJoinRequestPayload & Amity.Pagination) {
60
+ await this.queryStreamController.saveToMainDB(queryPayload);
61
+ }
62
+
63
+ protected persistQueryStream({
64
+ response,
65
+ direction,
66
+ refresh,
67
+ }: Amity.LiveCollectionPersistQueryStreamParams<'joinRequest'>) {
68
+ const joinRequestResponse = response as unknown as Amity.CommunityJoinRequestPayload &
69
+ Partial<Amity.Pagination>;
70
+ this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
71
+ }
72
+
73
+ startSubscription() {
74
+ return this.queryStreamController.subscribeRTE([
75
+ { fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
76
+ { fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
77
+ { fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
78
+ ]);
79
+ }
80
+
81
+ notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
82
+ const collection = pullFromCache<Amity.JoinRequestLiveCollectionCache>(this.cacheKey)?.data;
83
+ if (!collection) return;
84
+
85
+ const data = this.applyFilter(
86
+ collection.data
87
+ .map(id => pullFromCache<Amity.InternalJoinRequest>(['joinRequest', 'get', id])!)
88
+ .filter(isNonNullable)
89
+ .map(({ data }) => data)
90
+ .map(joinRequestLinkedObject),
91
+ );
92
+
93
+ if (!this.shouldNotify(data) && origin === 'event') return;
94
+
95
+ this.callback({
96
+ onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
97
+ data,
98
+ hasNextPage: !!this.paginationController.getNextToken(),
99
+ loading,
100
+ error,
101
+ });
102
+ }
103
+
104
+ applyFilter(data: Amity.JoinRequest[]) {
105
+ let joinRequest = data;
106
+
107
+ if (this.query.status) {
108
+ joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
109
+ }
110
+
111
+ const sortFn = (() => {
112
+ switch (this.query.sortBy) {
113
+ case 'firstCreated':
114
+ return sortByFirstCreated;
115
+ case 'lastCreated':
116
+ return sortByLastCreated;
117
+ default:
118
+ return sortByLastCreated;
119
+ }
120
+ })();
121
+
122
+ joinRequest = joinRequest.sort(sortFn);
123
+
124
+ return joinRequest;
125
+ }
126
+ }
@@ -0,0 +1,26 @@
1
+ import { PaginationController } from '~/core/liveCollection/PaginationController';
2
+ import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
3
+
4
+ /**
5
+ * TODO: handle cache receive cache option, and cache policy
6
+ * TODO: check if querybyIds is supported
7
+ */
8
+ export class JoinRequestsPaginationController extends PaginationController<
9
+ 'joinRequest',
10
+ Amity.JoinRequestLiveCollection
11
+ > {
12
+ async getRequest(queryParams: Amity.JoinRequestLiveCollection, token: string | undefined) {
13
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityId, ...params } = queryParams;
14
+ const options = token ? { token } : { limit };
15
+
16
+ const { data: queryResponse } = await this.http.get<
17
+ Amity.CommunityJoinRequestPayload & Amity.Pagination
18
+ >(`/api/v4/communities/${communityId}/join`, {
19
+ params: {
20
+ ...params,
21
+ options,
22
+ },
23
+ });
24
+ return queryResponse;
25
+ }
26
+ }