@amityco/ts-sdk-react-native 6.36.0 → 7.0.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 (338) hide show
  1. package/dist/@types/core/events.d.ts +6 -6
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/domains/analytics.d.ts +0 -3
  4. package/dist/@types/domains/analytics.d.ts.map +1 -1
  5. package/dist/@types/domains/channel.d.ts +9 -33
  6. package/dist/@types/domains/channel.d.ts.map +1 -1
  7. package/dist/@types/domains/client.d.ts +0 -4
  8. package/dist/@types/domains/client.d.ts.map +1 -1
  9. package/dist/@types/domains/community.d.ts +2 -10
  10. package/dist/@types/domains/community.d.ts.map +1 -1
  11. package/dist/@types/domains/feed.d.ts +0 -11
  12. package/dist/@types/domains/feed.d.ts.map +1 -1
  13. package/dist/@types/domains/message.d.ts +0 -12
  14. package/dist/@types/domains/message.d.ts.map +1 -1
  15. package/dist/@types/domains/subChannel.d.ts +0 -4
  16. package/dist/@types/domains/subChannel.d.ts.map +1 -1
  17. package/dist/@types/domains/user.d.ts +1 -5
  18. package/dist/@types/domains/user.d.ts.map +1 -1
  19. package/dist/channelRepository/api/deleteChannel.d.ts.map +1 -1
  20. package/dist/channelRepository/api/index.d.ts +0 -1
  21. package/dist/channelRepository/api/index.d.ts.map +1 -1
  22. package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
  23. package/dist/channelRepository/channelMembership/observers/getMembers/getMembers.d.ts.map +1 -1
  24. package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts.map +1 -1
  25. package/dist/channelRepository/channelMembership/observers/searchMembers/searchMembers.d.ts.map +1 -1
  26. package/dist/channelRepository/{api → internalApi}/getChannel.d.ts +2 -2
  27. package/dist/channelRepository/internalApi/getChannel.d.ts.map +1 -0
  28. package/dist/channelRepository/internalApi/getChannelByIds.d.ts +32 -0
  29. package/dist/channelRepository/internalApi/getChannelByIds.d.ts.map +1 -0
  30. package/dist/channelRepository/{api → internalApi}/markAsRead.d.ts +0 -3
  31. package/dist/channelRepository/internalApi/markAsRead.d.ts.map +1 -0
  32. package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
  33. package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
  34. package/dist/channelRepository/observers/index.d.ts +0 -2
  35. package/dist/channelRepository/observers/index.d.ts.map +1 -1
  36. package/dist/channelRepository/utils/constructChannelDynamicValue.d.ts.map +1 -1
  37. package/dist/channelRepository/utils/constructChannelObject.d.ts +2 -0
  38. package/dist/channelRepository/utils/constructChannelObject.d.ts.map +1 -0
  39. package/dist/channelRepository/utils/getChannelIsMentioned.d.ts +1 -1
  40. package/dist/channelRepository/utils/getChannelIsMentioned.d.ts.map +1 -1
  41. package/dist/channelRepository/utils/getSubChannelsUnreadCount.d.ts +1 -1
  42. package/dist/channelRepository/utils/getSubChannelsUnreadCount.d.ts.map +1 -1
  43. package/dist/channelRepository/utils/resolveChannels.d.ts.map +1 -1
  44. package/dist/channelRepository/utils/updateChannelCache.d.ts +1 -1
  45. package/dist/channelRepository/utils/updateChannelCache.d.ts.map +1 -1
  46. package/dist/client/observers/index.d.ts +0 -1
  47. package/dist/client/observers/index.d.ts.map +1 -1
  48. package/dist/client/utils/endpoints.d.ts +1 -1
  49. package/dist/client/utils/markerSyncEngine.d.ts +0 -4
  50. package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
  51. package/dist/client/utils/subscribeGlobalTopic.d.ts.map +1 -1
  52. package/dist/commentRepository/observers/index.d.ts +0 -2
  53. package/dist/commentRepository/observers/index.d.ts.map +1 -1
  54. package/dist/communityRepository/api/index.d.ts +0 -1
  55. package/dist/communityRepository/api/index.d.ts.map +1 -1
  56. package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
  57. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -1
  58. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +1 -1
  59. package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
  60. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts +1 -1
  61. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts.map +1 -1
  62. package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
  63. package/dist/communityRepository/observers/getCommunities/CommunitiesPaginationController.d.ts.map +1 -1
  64. package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts.map +1 -1
  65. package/dist/communityRepository/observers/index.d.ts +0 -1
  66. package/dist/communityRepository/observers/index.d.ts.map +1 -1
  67. package/dist/communityRepository/observers/searchCommunities.d.ts +1 -1
  68. package/dist/communityRepository/observers/searchCommunities.d.ts.map +1 -1
  69. package/dist/communityRepository/utils/communityQueryFilter.d.ts.map +1 -1
  70. package/dist/core/events.d.ts +3 -3
  71. package/dist/core/events.d.ts.map +1 -1
  72. package/dist/core/subscription.d.ts +1 -0
  73. package/dist/core/subscription.d.ts.map +1 -1
  74. package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +2 -35
  75. package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +1 -1
  76. package/dist/feedRepository/api/queryGlobalFeed.d.ts +2 -24
  77. package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
  78. package/dist/fileRepository/api/index.d.ts +0 -3
  79. package/dist/fileRepository/api/index.d.ts.map +1 -1
  80. package/dist/fileRepository/index.d.ts +0 -1
  81. package/dist/fileRepository/index.d.ts.map +1 -1
  82. package/dist/index.cjs.js +1261 -2688
  83. package/dist/index.esm.js +1225 -2653
  84. package/dist/index.umd.js +3 -3
  85. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -5
  86. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
  87. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +0 -1
  88. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts.map +1 -1
  89. package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
  90. package/dist/messageRepository/api/index.d.ts +0 -1
  91. package/dist/messageRepository/api/index.d.ts.map +1 -1
  92. package/dist/messageRepository/internalApi/getMessage.d.ts.map +1 -1
  93. package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts.map +1 -1
  94. package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
  95. package/dist/messageRepository/observers/getMessages/getMessages.d.ts +0 -1
  96. package/dist/messageRepository/observers/getMessages/getMessages.d.ts.map +1 -1
  97. package/dist/messageRepository/observers/index.d.ts +0 -2
  98. package/dist/messageRepository/observers/index.d.ts.map +1 -1
  99. package/dist/messageRepository/utils/prepareMessagePayload.d.ts +1 -1
  100. package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
  101. package/dist/pollRepository/observers/index.d.ts +0 -1
  102. package/dist/pollRepository/observers/index.d.ts.map +1 -1
  103. package/dist/postRepository/api/index.d.ts +0 -1
  104. package/dist/postRepository/api/index.d.ts.map +1 -1
  105. package/dist/postRepository/observers/index.d.ts +0 -2
  106. package/dist/postRepository/observers/index.d.ts.map +1 -1
  107. package/dist/role/api/queryRoles.d.ts +0 -7
  108. package/dist/role/api/queryRoles.d.ts.map +1 -1
  109. package/dist/streamRepository/api/index.d.ts +0 -2
  110. package/dist/streamRepository/api/index.d.ts.map +1 -1
  111. package/dist/streamRepository/events/onStreamFlagged.d.ts.map +1 -1
  112. package/dist/streamRepository/internalApi/getStream.d.ts.map +1 -0
  113. package/dist/subChannelRepository/utils/markReadEngine.d.ts +0 -34
  114. package/dist/subChannelRepository/utils/markReadEngine.d.ts.map +1 -1
  115. package/dist/userRepository/internalApi/queryUsers.d.ts.map +1 -1
  116. package/dist/userRepository/observers/getUsers/UserLiveCollectionController.d.ts.map +1 -1
  117. package/dist/userRepository/observers/getUsers/UserPaginationController.d.ts.map +1 -1
  118. package/dist/userRepository/observers/index.d.ts +0 -2
  119. package/dist/userRepository/observers/index.d.ts.map +1 -1
  120. package/dist/userRepository/relationship/block/index.d.ts +0 -1
  121. package/dist/userRepository/relationship/block/index.d.ts.map +1 -1
  122. package/dist/userRepository/relationship/follow/api/index.d.ts +0 -2
  123. package/dist/userRepository/relationship/follow/api/index.d.ts.map +1 -1
  124. package/dist/userRepository/relationship/follow/observers/index.d.ts +0 -3
  125. package/dist/userRepository/relationship/follow/observers/index.d.ts.map +1 -1
  126. package/dist/utils/liveObject.d.ts +1 -1
  127. package/package.json +1 -1
  128. package/src/@types/core/events.ts +8 -9
  129. package/src/@types/domains/analytics.ts +0 -7
  130. package/src/@types/domains/channel.ts +15 -46
  131. package/src/@types/domains/client.ts +0 -4
  132. package/src/@types/domains/community.ts +0 -8
  133. package/src/@types/domains/feed.ts +0 -11
  134. package/src/@types/domains/message.ts +0 -12
  135. package/src/@types/domains/subChannel.ts +0 -4
  136. package/src/@types/domains/user.ts +0 -4
  137. package/src/channelRepository/api/deleteChannel.ts +3 -2
  138. package/src/channelRepository/api/getChannelByIds.ts +5 -5
  139. package/src/channelRepository/api/index.ts +0 -2
  140. package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +0 -8
  141. package/src/channelRepository/channelMembership/observers/getMembers/getMembers.ts +0 -8
  142. package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.ts +0 -8
  143. package/src/channelRepository/channelMembership/observers/searchMembers/searchMembers.ts +0 -8
  144. package/src/channelRepository/{api → internalApi}/getChannel.ts +4 -4
  145. package/src/channelRepository/internalApi/getChannelByIds.ts +105 -0
  146. package/src/channelRepository/{api → internalApi}/markAsRead.ts +0 -3
  147. package/src/channelRepository/observers/getChannel.ts +36 -15
  148. package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +11 -12
  149. package/src/channelRepository/observers/index.ts +0 -2
  150. package/src/channelRepository/utils/constructChannelDynamicValue.ts +4 -9
  151. package/src/channelRepository/utils/constructChannelObject.ts +16 -0
  152. package/src/channelRepository/utils/getChannelIsMentioned.ts +4 -1
  153. package/src/channelRepository/utils/getSubChannelsUnreadCount.ts +1 -1
  154. package/src/channelRepository/utils/resolveChannels.ts +7 -2
  155. package/src/channelRepository/utils/updateChannelCache.ts +4 -1
  156. package/src/client/observers/getUserUnread.ts +1 -1
  157. package/src/client/observers/index.ts +0 -1
  158. package/src/client/utils/endpoints.ts +1 -1
  159. package/src/client/utils/markerSyncEngine.ts +0 -9
  160. package/src/client/utils/subscribeGlobalTopic.ts +3 -0
  161. package/src/commentRepository/observers/index.ts +0 -2
  162. package/src/communityRepository/api/index.ts +0 -3
  163. package/src/communityRepository/api/queryCommunities.ts +1 -2
  164. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +0 -12
  165. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +0 -7
  166. package/src/communityRepository/communityMembership/observers/getMembers.ts +0 -4
  167. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +1 -1
  168. package/src/communityRepository/communityMembership/observers/tests/getMembers.test.ts +0 -1
  169. package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +12 -16
  170. package/src/communityRepository/observers/getCommunities/CommunitiesPaginationController.ts +0 -1
  171. package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +0 -4
  172. package/src/communityRepository/observers/index.ts +0 -2
  173. package/src/communityRepository/observers/searchCommunities.ts +1 -1
  174. package/src/communityRepository/observers/tests/getCommunities.test.ts +0 -1
  175. package/src/communityRepository/utils/communityQueryFilter.ts +1 -8
  176. package/src/core/events.ts +7 -5
  177. package/src/core/subscription.ts +6 -0
  178. package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +8 -55
  179. package/src/feedRepository/api/queryGlobalFeed.ts +6 -58
  180. package/src/feedRepository/api/test/getCustomRankingGlobalFeed.test.ts +1 -1
  181. package/src/feedRepository/api/test/queryGlobalFeed.test.ts +1 -1
  182. package/src/fileRepository/api/index.ts +0 -5
  183. package/src/fileRepository/index.ts +0 -1
  184. package/src/liveStreamPlayer/api/getPlayer.ts +1 -1
  185. package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +2 -2
  186. package/src/messageRepository/api/createMessage.ts +5 -1
  187. package/src/messageRepository/api/index.ts +0 -2
  188. package/src/messageRepository/api/tests/createMessage.test.ts +6 -1
  189. package/src/messageRepository/api/tests/deleteMessage.test.ts +5 -1
  190. package/src/messageRepository/internalApi/getMessage.ts +0 -6
  191. package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +0 -20
  192. package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +0 -10
  193. package/src/messageRepository/observers/getMessages/getMessages.ts +0 -54
  194. package/src/messageRepository/observers/index.ts +0 -3
  195. package/src/messageRepository/utils/prepareMessagePayload.ts +1 -7
  196. package/src/pollRepository/observers/index.ts +0 -1
  197. package/src/postRepository/api/index.ts +0 -1
  198. package/src/postRepository/observers/index.ts +0 -2
  199. package/src/role/api/queryRoles.ts +1 -13
  200. package/src/streamRepository/api/deleteStream.ts +1 -1
  201. package/src/streamRepository/api/index.ts +0 -4
  202. package/src/streamRepository/api/tests/getStream.test.ts +1 -1
  203. package/src/streamRepository/events/onStreamFlagged.ts +1 -6
  204. package/src/streamRepository/events/onStreamRecorded.ts +1 -1
  205. package/src/streamRepository/events/onStreamStarted.ts +1 -1
  206. package/src/streamRepository/events/onStreamStopped.ts +1 -1
  207. package/src/streamRepository/events/onStreamTerminated.ts +1 -1
  208. package/src/streamRepository/observers/getStreamById.ts +1 -1
  209. package/src/subChannelRepository/utils/markReadEngine.ts +0 -106
  210. package/src/userRepository/internalApi/queryUsers.ts +1 -9
  211. package/src/userRepository/observers/getUsers/UserLiveCollectionController.ts +12 -16
  212. package/src/userRepository/observers/getUsers/UserPaginationController.ts +1 -2
  213. package/src/userRepository/observers/index.ts +0 -2
  214. package/src/userRepository/observers/tests/getUsers.test.ts +1 -43
  215. package/src/userRepository/relationship/block/index.ts +0 -1
  216. package/src/userRepository/relationship/follow/api/index.ts +0 -4
  217. package/src/userRepository/relationship/follow/observers/index.ts +0 -4
  218. package/src/utils/linkedObject/channelLinkedObject.ts +1 -1
  219. package/src/utils/liveObject.ts +2 -2
  220. package/dist/channelRepository/api/getChannel.d.ts.map +0 -1
  221. package/dist/channelRepository/api/markAsRead.d.ts.map +0 -1
  222. package/dist/channelRepository/observers/observeChannel.d.ts +0 -18
  223. package/dist/channelRepository/observers/observeChannel.d.ts.map +0 -1
  224. package/dist/channelRepository/observers/observeChannels.d.ts +0 -17
  225. package/dist/channelRepository/observers/observeChannels.d.ts.map +0 -1
  226. package/dist/client/observers/getTotalUnreadCount.d.ts +0 -20
  227. package/dist/client/observers/getTotalUnreadCount.d.ts.map +0 -1
  228. package/dist/client/observers/tests/getTotalUnreadCount.test.d.ts +0 -2
  229. package/dist/client/observers/tests/getTotalUnreadCount.test.d.ts.map +0 -1
  230. package/dist/commentRepository/observers/observeComment.d.ts +0 -18
  231. package/dist/commentRepository/observers/observeComment.d.ts.map +0 -1
  232. package/dist/commentRepository/observers/observeComments.d.ts +0 -26
  233. package/dist/commentRepository/observers/observeComments.d.ts.map +0 -1
  234. package/dist/communityRepository/api/getTopTrendingCommunities.d.ts +0 -35
  235. package/dist/communityRepository/api/getTopTrendingCommunities.d.ts.map +0 -1
  236. package/dist/communityRepository/api/test/getTopTrendingCommunities.test.d.ts +0 -2
  237. package/dist/communityRepository/api/test/getTopTrendingCommunities.test.d.ts.map +0 -1
  238. package/dist/communityRepository/observers/observeCommunity.d.ts +0 -18
  239. package/dist/communityRepository/observers/observeCommunity.d.ts.map +0 -1
  240. package/dist/feedRepository/internalApi/getCustomRankingGlobalFeed.d.ts +0 -8
  241. package/dist/feedRepository/internalApi/getCustomRankingGlobalFeed.d.ts.map +0 -1
  242. package/dist/feedRepository/internalApi/index.d.ts +0 -3
  243. package/dist/feedRepository/internalApi/index.d.ts.map +0 -1
  244. package/dist/feedRepository/internalApi/queryGlobalFeed.d.ts +0 -9
  245. package/dist/feedRepository/internalApi/queryGlobalFeed.d.ts.map +0 -1
  246. package/dist/feedRepository/internalApi/test/getCustomRankingGlobalFeed.test.d.ts +0 -2
  247. package/dist/feedRepository/internalApi/test/getCustomRankingGlobalFeed.test.d.ts.map +0 -1
  248. package/dist/feedRepository/internalApi/test/queryGlobalFeed.test.d.ts +0 -2
  249. package/dist/feedRepository/internalApi/test/queryGlobalFeed.test.d.ts.map +0 -1
  250. package/dist/fileRepository/api/createFile.d.ts +0 -17
  251. package/dist/fileRepository/api/createFile.d.ts.map +0 -1
  252. package/dist/fileRepository/api/createImage.d.ts +0 -17
  253. package/dist/fileRepository/api/createImage.d.ts.map +0 -1
  254. package/dist/fileRepository/api/createVideo.d.ts +0 -18
  255. package/dist/fileRepository/api/createVideo.d.ts.map +0 -1
  256. package/dist/fileRepository/observers/index.d.ts +0 -2
  257. package/dist/fileRepository/observers/index.d.ts.map +0 -1
  258. package/dist/fileRepository/observers/observeFile.d.ts +0 -18
  259. package/dist/fileRepository/observers/observeFile.d.ts.map +0 -1
  260. package/dist/messageRepository/api/getMessage.d.ts +0 -32
  261. package/dist/messageRepository/api/getMessage.d.ts.map +0 -1
  262. package/dist/messageRepository/api/getMessages.d.ts +0 -32
  263. package/dist/messageRepository/api/getMessages.d.ts.map +0 -1
  264. package/dist/messageRepository/observers/observeMessage.d.ts +0 -21
  265. package/dist/messageRepository/observers/observeMessage.d.ts.map +0 -1
  266. package/dist/messageRepository/observers/observeMessages.d.ts +0 -23
  267. package/dist/messageRepository/observers/observeMessages.d.ts.map +0 -1
  268. package/dist/pollRepository/observers/observePoll.d.ts +0 -18
  269. package/dist/pollRepository/observers/observePoll.d.ts.map +0 -1
  270. package/dist/postRepository/api/updatePost.d.ts +0 -24
  271. package/dist/postRepository/api/updatePost.d.ts.map +0 -1
  272. package/dist/postRepository/observers/observePost.d.ts +0 -18
  273. package/dist/postRepository/observers/observePost.d.ts.map +0 -1
  274. package/dist/postRepository/observers/observePosts.d.ts +0 -34
  275. package/dist/postRepository/observers/observePosts.d.ts.map +0 -1
  276. package/dist/streamRepository/api/getStream.d.ts.map +0 -1
  277. package/dist/streamRepository/api/queryStreams.d.ts +0 -25
  278. package/dist/streamRepository/api/queryStreams.d.ts.map +0 -1
  279. package/dist/userRepository/observers/getViewedUsers.d.ts +0 -7
  280. package/dist/userRepository/observers/getViewedUsers.d.ts.map +0 -1
  281. package/dist/userRepository/observers/observeUser.d.ts +0 -17
  282. package/dist/userRepository/observers/observeUser.d.ts.map +0 -1
  283. package/dist/userRepository/observers/tests/getViewedUsers.test.d.ts +0 -2
  284. package/dist/userRepository/observers/tests/getViewedUsers.test.d.ts.map +0 -1
  285. package/dist/userRepository/relationship/block/observers/getBlockedUsers.d.ts +0 -2
  286. package/dist/userRepository/relationship/block/observers/getBlockedUsers.d.ts.map +0 -1
  287. package/dist/userRepository/relationship/block/observers/index.d.ts +0 -2
  288. package/dist/userRepository/relationship/block/observers/index.d.ts.map +0 -1
  289. package/dist/userRepository/relationship/follow/api/acceptFollower.d.ts +0 -19
  290. package/dist/userRepository/relationship/follow/api/acceptFollower.d.ts.map +0 -1
  291. package/dist/userRepository/relationship/follow/api/declineFollower.d.ts +0 -19
  292. package/dist/userRepository/relationship/follow/api/declineFollower.d.ts.map +0 -1
  293. package/dist/userRepository/relationship/follow/observers/observeFollowInfo.d.ts +0 -18
  294. package/dist/userRepository/relationship/follow/observers/observeFollowInfo.d.ts.map +0 -1
  295. package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts +0 -18
  296. package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts.map +0 -1
  297. package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts +0 -18
  298. package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts.map +0 -1
  299. package/src/channelRepository/observers/observeChannel.ts +0 -109
  300. package/src/channelRepository/observers/observeChannels.ts +0 -74
  301. package/src/client/observers/getTotalUnreadCount.ts +0 -53
  302. package/src/client/observers/tests/getTotalUnreadCount.test.ts +0 -101
  303. package/src/commentRepository/observers/observeComment.ts +0 -102
  304. package/src/commentRepository/observers/observeComments.ts +0 -77
  305. package/src/communityRepository/api/getTopTrendingCommunities.ts +0 -97
  306. package/src/communityRepository/api/test/getTopTrendingCommunities.test.ts +0 -102
  307. package/src/communityRepository/observers/observeCommunity.ts +0 -103
  308. package/src/feedRepository/internalApi/getCustomRankingGlobalFeed.ts +0 -87
  309. package/src/feedRepository/internalApi/index.ts +0 -2
  310. package/src/feedRepository/internalApi/queryGlobalFeed.ts +0 -95
  311. package/src/feedRepository/internalApi/test/getCustomRankingGlobalFeed.test.ts +0 -138
  312. package/src/feedRepository/internalApi/test/queryGlobalFeed.test.ts +0 -130
  313. package/src/fileRepository/api/createFile.ts +0 -59
  314. package/src/fileRepository/api/createImage.ts +0 -59
  315. package/src/fileRepository/api/createVideo.ts +0 -69
  316. package/src/fileRepository/observers/index.ts +0 -1
  317. package/src/fileRepository/observers/observeFile.ts +0 -49
  318. package/src/messageRepository/api/getMessage.ts +0 -102
  319. package/src/messageRepository/api/getMessages.ts +0 -83
  320. package/src/messageRepository/observers/observeMessage.ts +0 -94
  321. package/src/messageRepository/observers/observeMessages.ts +0 -89
  322. package/src/pollRepository/observers/observePoll.ts +0 -67
  323. package/src/postRepository/api/updatePost.ts +0 -63
  324. package/src/postRepository/observers/observePost.ts +0 -115
  325. package/src/postRepository/observers/observePosts.ts +0 -86
  326. package/src/streamRepository/api/queryStreams.ts +0 -63
  327. package/src/userRepository/observers/getViewedUsers.ts +0 -99
  328. package/src/userRepository/observers/observeUser.ts +0 -71
  329. package/src/userRepository/observers/tests/getViewedUsers.test.ts +0 -39
  330. package/src/userRepository/relationship/block/observers/getBlockedUsers.ts +0 -13
  331. package/src/userRepository/relationship/block/observers/index.ts +0 -1
  332. package/src/userRepository/relationship/follow/api/acceptFollower.ts +0 -40
  333. package/src/userRepository/relationship/follow/api/declineFollower.ts +0 -40
  334. package/src/userRepository/relationship/follow/observers/observeFollowInfo.ts +0 -64
  335. package/src/userRepository/relationship/follow/observers/observeFollowers.ts +0 -74
  336. package/src/userRepository/relationship/follow/observers/observeFollowings.ts +0 -74
  337. /package/dist/streamRepository/{api → internalApi}/getStream.d.ts +0 -0
  338. /package/src/streamRepository/{api → internalApi}/getStream.ts +0 -0
package/dist/index.esm.js CHANGED
@@ -89,8 +89,8 @@ const PostContentType = Object.freeze({
89
89
 
90
90
  function getVersion() {
91
91
  try {
92
- // the string ''v6.36.0-esm'' should be replaced by actual value by @rollup/plugin-replace
93
- return 'v6.36.0-esm';
92
+ // the string ''v7.0.0-esm'' should be replaced by actual value by @rollup/plugin-replace
93
+ return 'v7.0.0-esm';
94
94
  }
95
95
  catch (error) {
96
96
  return '__dev__';
@@ -1318,9 +1318,6 @@ const WS_EVENTS = [
1318
1318
  'sessionStateChange',
1319
1319
  // for internal use by accessTokenExpiryWatcher
1320
1320
  'tokenExpired',
1321
- 'v3.video-streaming.didRecord',
1322
- 'v3.video-streaming.didStart',
1323
- 'v3.video-streaming.didStop',
1324
1321
  ];
1325
1322
  const MQTT_EVENTS = [
1326
1323
  'connect',
@@ -1330,7 +1327,12 @@ const MQTT_EVENTS = [
1330
1327
  'close',
1331
1328
  'end',
1332
1329
  'reconnect',
1333
- 'user.didGlobalBan',
1330
+ 'video-streaming.didStart',
1331
+ 'video-streaming.didRecord',
1332
+ 'video-streaming.didStop',
1333
+ 'video-streaming.didFlag',
1334
+ 'video-streaming.didTerminate',
1335
+ // 'user.didGlobalBan' remove due to message event,
1334
1336
  ];
1335
1337
  /** @hidden */
1336
1338
  const createEventEmitter = () => {
@@ -1529,7 +1531,11 @@ function subscribeTopic(topic, callback) {
1529
1531
  return () => null;
1530
1532
  modifyMqttConnection();
1531
1533
  return mqtt.subscribe(topic, callback);
1532
- }
1534
+ }
1535
+ const getLiveStreamTopic = () => {
1536
+ const user = getActiveUser();
1537
+ return `${getNetworkId(user)}/videostreaming`;
1538
+ };
1533
1539
 
1534
1540
  var _a;
1535
1541
  /* eslint-disable no-undef */
@@ -1565,7 +1571,7 @@ const API_REGIONS = {
1565
1571
  US: 'us',
1566
1572
  };
1567
1573
  const URLS = {
1568
- http: 'https://api.{region}.amity.co',
1574
+ http: 'https://apix.{region}.amity.co',
1569
1575
  mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
1570
1576
  };
1571
1577
  function computeUrl(type, region) {
@@ -20474,6 +20480,7 @@ const subscribeGlobalTopic = () => {
20474
20480
  // subscribing to user topic is necessary to handle ban event
20475
20481
  subscribeTopic(getUserTopic(getActiveUser())),
20476
20482
  subscribeTopic(getMarkerUserFeedTopic()),
20483
+ subscribeTopic(getLiveStreamTopic()),
20477
20484
  ];
20478
20485
  return () => disposers.forEach(fn => fn());
20479
20486
  };
@@ -22029,9 +22036,6 @@ const reactorLinkedObject = (reactor) => {
22029
22036
  * import { ChannelRepository } from '@amityco/ts-sdk-react-native'
22030
22037
  * const success = await ChannelRepository.markAsRead('channelId')
22031
22038
  * ```
22032
- *
22033
- * @deprecated Please use the {@link Amity.Channel.markAsRead} method instead
22034
- *
22035
22039
  * Updating all {@link Amity.SubChannel} in specify {@link Amity.Channel} as read
22036
22040
  *
22037
22041
  * @param channelId the ID of to specify {@link Amity.Channel}
@@ -22644,7 +22648,7 @@ const prepareMessagePayload = async (payload, event) => {
22644
22648
  var _a, _b;
22645
22649
  const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
22646
22650
  // exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
22647
- const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "hasMentioned", "isMentioned"]);
22651
+ const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "isMentioned"]);
22648
22652
  updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
22649
22653
  });
22650
22654
  }
@@ -22658,15 +22662,12 @@ function convertParams(_a) {
22658
22662
  return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
22659
22663
  }
22660
22664
  function convertQueryParams$1(_a) {
22661
- var { sortBy, subChannelId, tags, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "tags", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
22665
+ var { sortBy, subChannelId, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
22662
22666
  const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: inferIsDeleted(includeDeleted), options: {
22663
22667
  sortBy,
22664
22668
  limit: limit || COLLECTION_DEFAULT_PAGINATION_LIMIT,
22665
22669
  around: aroundMessageId,
22666
22670
  } });
22667
- if (tags) {
22668
- out.includeTags = tags;
22669
- }
22670
22671
  if (includingTags) {
22671
22672
  out.includeTags = includingTags;
22672
22673
  }
@@ -23150,22 +23151,27 @@ const getSubChannelsUnreadCount = (channel, marker) => {
23150
23151
  };
23151
23152
 
23152
23153
  const constructChannelDynamicValue = (channel) => {
23153
- return shallowClone(channel, {
23154
- get unreadCount() {
23155
- return getSubChannelsUnreadCount(channel);
23156
- },
23157
- get hasMentioned() {
23158
- return getChannelIsMentioned(channel);
23159
- },
23154
+ const rest = __rest(channel, ["messageCount"]);
23155
+ return shallowClone(rest, {
23160
23156
  get isMentioned() {
23161
- return getChannelIsMentioned(channel);
23157
+ return getChannelIsMentioned(rest);
23162
23158
  },
23163
23159
  get subChannelsUnreadCount() {
23164
- return getSubChannelsUnreadCount(channel);
23160
+ return getSubChannelsUnreadCount(rest);
23165
23161
  },
23166
23162
  });
23167
23163
  };
23168
23164
 
23165
+ const constructChannelObject = (channel) => {
23166
+ /**
23167
+ * convert internal cache data to be public channel data
23168
+ * 1. [getChannelMessagePreviewWithUser] add messagePreview >> Amity.InternalChannel -> Amity.InternalChannel
23169
+ * 2. [constructChannelDynamicValue] construct getter value >> Amity.StaticInternalChannel -> Amity.Channel
23170
+ * 3. [LinkedObject.channel] add markAsRead >> Amity.InternalChannel -> Amity.Channel
23171
+ */
23172
+ return LinkedObject.channel(constructChannelDynamicValue(getChannelMessagePreviewWithUser(channel)));
23173
+ };
23174
+
23169
23175
  /**
23170
23176
  * ```js
23171
23177
  * import { getChannelByIds } from '@amityco/ts-sdk-react-native'
@@ -23180,7 +23186,7 @@ const constructChannelDynamicValue = (channel) => {
23180
23186
  * @category Channel API
23181
23187
  * @async
23182
23188
  */
23183
- const getChannelByIds = async (channelIds) => {
23189
+ const getChannelByIds$1 = async (channelIds) => {
23184
23190
  const client = getActiveClient();
23185
23191
  client.log('channel/getChannelByIds', channelIds);
23186
23192
  const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
@@ -23210,7 +23216,7 @@ const getChannelByIds = async (channelIds) => {
23210
23216
  ingestInCache(data, { cachedAt });
23211
23217
  fireEvent('local.channel.fetched', data.channels);
23212
23218
  return {
23213
- data: data.channels.map(channel => LinkedObject.channel(constructChannelDynamicValue(channel))),
23219
+ data: data.channels.map(channel => constructChannelObject(channel)),
23214
23220
  cachedAt,
23215
23221
  };
23216
23222
  };
@@ -23227,7 +23233,7 @@ const getChannelByIds = async (channelIds) => {
23227
23233
  *
23228
23234
  * @category Channel API
23229
23235
  */
23230
- getChannelByIds.locally = (channelIds) => {
23236
+ getChannelByIds$1.locally = (channelIds) => {
23231
23237
  var _a, _b;
23232
23238
  const client = getActiveClient();
23233
23239
  client.log('channel/getChannelByIds.locally', channelIds);
@@ -23241,7 +23247,7 @@ getChannelByIds.locally = (channelIds) => {
23241
23247
  const channels = cached.map(({ data }) => data);
23242
23248
  const oldest = (_b = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _b === void 0 ? void 0 : _b[0];
23243
23249
  return {
23244
- data: channels.map(channel => LinkedObject.channel(channel)),
23250
+ data: channels.map(channel => constructChannelObject(channel)),
23245
23251
  cachedAt: oldest.cachedAt,
23246
23252
  };
23247
23253
  };
@@ -23299,35 +23305,6 @@ const setIntervalTask = (handler, timeout) => {
23299
23305
  return () => clearInterval(timer);
23300
23306
  };
23301
23307
 
23302
- const onOnline = (callback) => {
23303
- if (typeof window !== 'undefined' && window.addEventListener) {
23304
- window.addEventListener('online', callback);
23305
- return () => window.removeEventListener('online', callback);
23306
- }
23307
- if (typeof document !== 'undefined' && document.addEventListener) {
23308
- document.addEventListener('online', callback);
23309
- return () => document.removeEventListener('online', callback);
23310
- }
23311
- // @TODO: Please update code below to follow our coding conventions and our TS rules
23312
- if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
23313
- // eslint-disable-next-line @typescript-eslint/no-empty-function
23314
- let unsubscribeFn = () => { };
23315
- import('@react-native-community/netinfo').then(NetInfo => {
23316
- unsubscribeFn = NetInfo.addEventListener(state => {
23317
- if (!state.isConnected)
23318
- return;
23319
- callback();
23320
- });
23321
- });
23322
- return () => {
23323
- unsubscribeFn();
23324
- };
23325
- }
23326
- // Handle unsupported environment
23327
- console.error('Unsupported environment');
23328
- return () => console.error('Unsupported environment');
23329
- };
23330
-
23331
23308
  /**
23332
23309
  * ```js
23333
23310
  * import { SubChannel } from '@amityco/ts-sdk-react-native'
@@ -23360,73 +23337,8 @@ const readingAPI = async (messageFeedIds) => {
23360
23337
  return true;
23361
23338
  };
23362
23339
 
23363
- /**
23364
- * ```js
23365
- * import { SubChannel } from '@amityco/ts-sdk-react-native'
23366
- * const success = await SubChannel('foo')
23367
- * ```
23368
- *
23369
- * Mark all messages as read and start reading message inside channel
23370
- *
23371
- * @param messageFeedId - Sub channel ID to start reading.
23372
- * @return A success boolean if reading of the sub channel had begun.
23373
- *
23374
- * @category Channel API
23375
- * @async
23376
- * @private
23377
- */
23378
- const startReadingAPI = async (messageFeedId) => {
23379
- const client = getActiveClient();
23380
- client.log('subChannel/startReadingAPI', messageFeedId);
23381
- const { data: payload } = await client.http.post(`/api/v1/markers/message-feeds/${messageFeedId}/start-reading`);
23382
- const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, feedMarkers, userMarkers, } = payload;
23383
- const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
23384
- const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
23385
- const cachedAt = client.cache && Date.now();
23386
- if (client.cache)
23387
- ingestInCache({ userEntityMarkers, userFeedMarkers, feedMarkers, userMarkers }, { cachedAt });
23388
- fireEvent('local.feedMarker.fetched', { feedMarkers });
23389
- fireEvent('local.channelMarker.fetched', { userEntityMarkers });
23390
- fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
23391
- fireEvent('local.userMarker.fetched', { userMarkers });
23392
- return true;
23393
- };
23394
-
23395
- /**
23396
- * ```js
23397
- * import { stopReading } from '@amityco/ts-sdk-react-native'
23398
- * const success = await stopReading('foo')
23399
- * ```
23400
- *
23401
- * Mark all messages as read and stop reading message inside channel
23402
- *
23403
- * @param messageFeedId - The sub channel ID to stop reading.
23404
- * @return A success boolean if reading of the sub channel had begun.
23405
- *
23406
- * @category Channel API
23407
- * @async
23408
- * @private
23409
- */
23410
- const stopReadingAPI = async (messageFeedId) => {
23411
- const client = getActiveClient();
23412
- client.log('channel/stopReadingAPI', messageFeedId);
23413
- const { data: payload } = await client.http.post(`/api/v1/markers/message-feeds/${messageFeedId}/stop-reading`);
23414
- const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, feedMarkers, userMarkers, } = payload;
23415
- const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
23416
- const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
23417
- const cachedAt = client.cache && Date.now();
23418
- if (client.cache)
23419
- ingestInCache({ userEntityMarkers, userFeedMarkers, feedMarkers, userMarkers }, { cachedAt });
23420
- fireEvent('local.feedMarker.fetched', { feedMarkers });
23421
- fireEvent('local.channelMarker.fetched', { userEntityMarkers });
23422
- fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
23423
- fireEvent('local.userMarker.fetched', { userMarkers });
23424
- return true;
23425
- };
23426
-
23427
23340
  const START_READING_INTERVAL_TIME = 30000;
23428
23341
  let isSyncRunning$1 = false;
23429
- let disposers$2 = [];
23430
23342
  /**
23431
23343
  * map contains subChannelId and isReading flag to determine which subChannel is on reading state
23432
23344
  */
@@ -23470,91 +23382,6 @@ const markReadEngineOnLoginHandler = () => {
23470
23382
  stopIntervalTask();
23471
23383
  };
23472
23384
  };
23473
- const getParentChannelId$1 = async (subChannelId) => {
23474
- const cached = getSubChannel$1.locally(subChannelId);
23475
- if (cached) {
23476
- return cached.data.channelId;
23477
- }
23478
- const { data } = await getSubChannel$1(subChannelId);
23479
- return data.channelId;
23480
- };
23481
- const registerEventListeners$1 = () => {
23482
- if (disposers$2.length > 0) {
23483
- return;
23484
- }
23485
- disposers$2.push(onOnline(() => {
23486
- // Start reading the reading subChannel again when resume from offline state
23487
- startReadingFromReadingList();
23488
- }));
23489
- };
23490
- const registerTopicSubscribers$1 = async (subChannelId) => {
23491
- const channelId = await getParentChannelId$1(subChannelId);
23492
- const markedMessageTopic = getMarkedMessageTopic({ channelId, subChannelId });
23493
- disposers$2.push(subscribeTopic(markedMessageTopic));
23494
- };
23495
- const disposeAll = () => {
23496
- disposers$2.forEach(fn => fn());
23497
- disposers$2 = [];
23498
- };
23499
- /* begin_public_function
23500
- id: subchannel.start_reading
23501
- */
23502
- /**
23503
- * @deprecated Use {@link startMessageReceiptSync} instead.
23504
- * ```js
23505
- * import { startReading } from '@amityco/ts-sdk-react-native'
23506
- * const success = await startReading('foo')
23507
- * ```
23508
- *
23509
- * Set local reading state of channel to `true` and then call mark all
23510
- * messages as read API.
23511
- *
23512
- * @param subChannelId - The sub channel ID to start reading.
23513
- * @return A success boolean if reading of the sub channel had begun.
23514
- *
23515
- * @category Channel API
23516
- * @async
23517
- */
23518
- const startReading = async (subChannelId) => {
23519
- isReadingMap[subChannelId] = true;
23520
- if (disposers$2.length === 0) {
23521
- registerEventListeners$1();
23522
- registerTopicSubscribers$1(subChannelId);
23523
- }
23524
- try {
23525
- return await startReadingAPI(subChannelId);
23526
- }
23527
- catch (e) {
23528
- isReadingMap[subChannelId] = false;
23529
- return false;
23530
- }
23531
- };
23532
- /* end_public_function */
23533
- /* begin_public_function
23534
- id: subchannel.stop_reading
23535
- */
23536
- /**
23537
- * @deprecated Use {@link stopMessageReceiptSync} instead.
23538
- * ```js
23539
- * import { stopReading } from '@amityco/ts-sdk-react-native'
23540
- * const success = await stopReading('foo')
23541
- * ```
23542
- *
23543
- * Set local reading state of channel to `false` and then call mark all
23544
- * messages as unread API.
23545
- *
23546
- * @param subChannelId - The sub channel ID to stop reading.
23547
- * @return A success boolean if reading of the sub channel had begun.
23548
- *
23549
- * @category Channel API
23550
- * @async
23551
- */
23552
- const stopReading = (subChannelId) => {
23553
- isReadingMap[subChannelId] = false;
23554
- disposeAll();
23555
- return stopReadingAPI(subChannelId);
23556
- };
23557
- /* end_public_function */
23558
23385
  setIntervalTask(async () => {
23559
23386
  if (!isSyncRunning$1)
23560
23387
  return;
@@ -23709,7 +23536,7 @@ const initializeMessagePreviewSetting = async () => {
23709
23536
  * 2. channel and subChannel which isDelete = true
23710
23537
  */
23711
23538
  if (channelWithIsDeletedTrue.length !== 0)
23712
- await getChannelByIds(channelWithIsDeletedTrue);
23539
+ await getChannelByIds$1(channelWithIsDeletedTrue);
23713
23540
  if (subChannelWithIsDeletedTrue.length !== 0)
23714
23541
  await getSubChannels$1(subChannelWithIsDeletedTrue);
23715
23542
  }
@@ -24107,6 +23934,35 @@ var readReceiptSyncEngineOnLoginHandler = () => {
24107
23934
  };
24108
23935
  };
24109
23936
 
23937
+ const onOnline = (callback) => {
23938
+ if (typeof window !== 'undefined' && window.addEventListener) {
23939
+ window.addEventListener('online', callback);
23940
+ return () => window.removeEventListener('online', callback);
23941
+ }
23942
+ if (typeof document !== 'undefined' && document.addEventListener) {
23943
+ document.addEventListener('online', callback);
23944
+ return () => document.removeEventListener('online', callback);
23945
+ }
23946
+ // @TODO: Please update code below to follow our coding conventions and our TS rules
23947
+ if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
23948
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
23949
+ let unsubscribeFn = () => { };
23950
+ import('@react-native-community/netinfo').then(NetInfo => {
23951
+ unsubscribeFn = NetInfo.addEventListener(state => {
23952
+ if (!state.isConnected)
23953
+ return;
23954
+ callback();
23955
+ });
23956
+ });
23957
+ return () => {
23958
+ unsubscribeFn();
23959
+ };
23960
+ }
23961
+ // Handle unsupported environment
23962
+ console.error('Unsupported environment');
23963
+ return () => console.error('Unsupported environment');
23964
+ };
23965
+
24110
23966
  const onOffline = (callback) => {
24111
23967
  if (typeof window !== 'undefined' && window.addEventListener) {
24112
23968
  window.addEventListener('offline', callback);
@@ -24136,8 +23992,90 @@ const onOffline = (callback) => {
24136
23992
  return () => console.error('Unsupported environment');
24137
23993
  };
24138
23994
 
23995
+ /**
23996
+ * ```js
23997
+ * import { getChannelByIds } from '@amityco/ts-sdk'
23998
+ * const channels = await getChannelByIds(['foo', 'bar'])
23999
+ * ```
24000
+ *
24001
+ * Fetches a collection of {@link Amity.Channel} objects
24002
+ *
24003
+ * @param channelIds the IDs of the {@link Amity.Channel} to fetch
24004
+ * @returns the associated collection of {@link Amity.Channel} objects
24005
+ *
24006
+ * @category Channel API
24007
+ * @async
24008
+ */
24009
+ const getChannelByIds = async (channelIds) => {
24010
+ const client = getActiveClient();
24011
+ client.log('channel/getChannelByIds', channelIds);
24012
+ const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
24013
+ let payload;
24014
+ try {
24015
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
24016
+ const response = await client.http.get(`/api/v3/channels/list`, {
24017
+ params: { channelIds: encodedChannelIds },
24018
+ });
24019
+ payload = response.data;
24020
+ }
24021
+ catch (error) {
24022
+ channelIds.forEach(channelId => {
24023
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
24024
+ // NOTE: use channelPublicId as tombstone cache key since we cannot get the channelPrivateId that come along with channel data from server
24025
+ pushToTombstone('channel', channelId);
24026
+ }
24027
+ });
24028
+ throw error;
24029
+ }
24030
+ const data = await prepareChannelPayload(payload);
24031
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
24032
+ await prepareUnreadCountInfo(payload);
24033
+ }
24034
+ const cachedAt = client.cache && Date.now();
24035
+ if (client.cache)
24036
+ ingestInCache(data, { cachedAt });
24037
+ fireEvent('local.channel.fetched', data.channels);
24038
+ return {
24039
+ data: data.channels,
24040
+ cachedAt,
24041
+ };
24042
+ };
24043
+ /**
24044
+ * ```js
24045
+ * import { getChannelByIds } from '@amityco/ts-sdk'
24046
+ * const channels = getChannelByIds.locally(['foo', 'bar']) ?? []
24047
+ * ```
24048
+ *
24049
+ * Fetches a collection of {@link Amity.Channel} objects from cache
24050
+ *
24051
+ * @param channelIds the IDs of the {@link Amity.Channel} to fetch
24052
+ * @returns the associated collection of {@link Amity.Channel} objects
24053
+ *
24054
+ * @category Channel API
24055
+ */
24056
+ getChannelByIds.locally = (channelIds) => {
24057
+ var _a, _b;
24058
+ const client = getActiveClient();
24059
+ client.log('channel/getChannelByIds.locally', channelIds);
24060
+ if (!client.cache)
24061
+ return;
24062
+ const cached = (_a = queryCache(['channel', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
24063
+ return channelIds.includes(data.channelPublicId);
24064
+ });
24065
+ if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) < channelIds.length)
24066
+ return;
24067
+ const channels = cached.map(({ data }) => data);
24068
+ const oldest = (_b = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _b === void 0 ? void 0 : _b[0];
24069
+ return {
24070
+ data: channels,
24071
+ cachedAt: oldest.cachedAt,
24072
+ };
24073
+ };
24074
+
24139
24075
  const resolveChannels = async (channelIds) => {
24140
- const { data: channels } = await getChannelByIds(channelIds);
24076
+ var _a, _b, _c;
24077
+ await getChannelByIds(channelIds);
24078
+ const channels = (_c = (_b = (_a = queryCache(['channel', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => data.channelPublicId && channelIds.includes(data.channelPublicId))) === null || _b === void 0 ? void 0 : _b.map(({ data }) => data)) !== null && _c !== void 0 ? _c : [];
24141
24079
  fireEvent('local.channel.resolved', channels);
24142
24080
  };
24143
24081
 
@@ -25265,13 +25203,6 @@ const stopUnreadSync = () => {
25265
25203
  setMarkerSyncEvents([]);
25266
25204
  unRegisterEventListeners();
25267
25205
  };
25268
- /**
25269
- * @deprecated Please use `startUnreadSync` instead
25270
- */
25271
- const stopUnreadSyncing = () => {
25272
- console.warn('`stopUnreadSyncing` has been deprecated, please use `stopUnreadSync` instead');
25273
- return stopUnreadSync();
25274
- };
25275
25206
  setIntervalTask(async () => {
25276
25207
  if (!isSyncRunning)
25277
25208
  return;
@@ -26027,100 +25958,6 @@ const removeFunctionProperties = (obj) => {
26027
25958
  return Object.fromEntries(entries);
26028
25959
  };
26029
25960
 
26030
- /**
26031
- * @deprecated This function is deprecated
26032
- */
26033
- const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
26034
- const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
26035
- const { cache } = getActiveClient();
26036
- if (!cache) {
26037
- console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
26038
- }
26039
- let model;
26040
- let isUnsyncedModel = false; // for messages
26041
- const disposers = [];
26042
- const dispatcher = (data) => {
26043
- const { data: newModel } = data, rest = __rest(data, ["data"]);
26044
- if (!callbackFilter || callbackFilter(newModel, model)) {
26045
- callback(Object.assign({ data: callbackDataSelector(newModel) }, rest));
26046
- }
26047
- // resolve all getter on data model to a static value to avoid comparison problems
26048
- model = convertGetterPropsToStatic(newModel);
26049
- };
26050
- const realtimeRouter = (eventModel, forceDispatch = false) => {
26051
- if (id !== eventModel[key]) {
26052
- return;
26053
- }
26054
- if (model) {
26055
- if (!forceDispatch && isEqual(model, eventModel)) {
26056
- return;
26057
- }
26058
- }
26059
- dispatcher({ loading: false, data: eventModel, origin: 'event' });
26060
- };
26061
- const onFetch = () => {
26062
- // TODO: Ihis `@ts-ignore` is bring back to fix the build and it needs to be removed later
26063
- // @ts-ignore
26064
- const query = createQuery(fetcher, id, true);
26065
- runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
26066
- if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
26067
- dispatcher({
26068
- // @ts-ignore
26069
- data,
26070
- origin,
26071
- loading: false,
26072
- error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
26073
- });
26074
- isUnsyncedModel = true;
26075
- disposers.forEach(fn => fn());
26076
- }
26077
- else if (!isUnsyncedModel) {
26078
- // @ts-ignore
26079
- dispatcher({ loading, data, origin, error });
26080
- }
26081
- if (error) {
26082
- disposers.forEach(fn => fn());
26083
- }
26084
- });
26085
- };
26086
- disposers.push(...eventHandlers.map(fn => fn(eventModel => realtimeRouter(eventModel, forceDispatch))));
26087
- onFetch();
26088
- return () => {
26089
- disposers.forEach(fn => fn());
26090
- };
26091
- };
26092
-
26093
- /**
26094
- * @deprecated Please use unreadCount from `getUserUnread` instead.
26095
- *
26096
- * ```js
26097
- * import { getTotalUnreadCount } from '@amityco/ts-sdk-react-native';
26098
- *
26099
- * const unsubscribe = getTotalUnreadCount(response => {
26100
- * totalUnreadCount = response.data;
26101
- * });
26102
- * ```
26103
- *
26104
- * Observe current user's unread count from {@link Amity.UserMarker}
26105
- *
26106
- * @param callback the function to call when new data are available
26107
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the events
26108
- *
26109
- * @category Message Live Object
26110
- */
26111
- const getTotalUnreadCount = (callback) => {
26112
- const { _id: userId } = getActiveUser();
26113
- if (!userId)
26114
- throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
26115
- const callbackDataSelector = (data) => { var _a; return (_a = data === null || data === void 0 ? void 0 : data.unreadCount) !== null && _a !== void 0 ? _a : 0; };
26116
- return liveObject(userId, callback, 'userId', async () => {
26117
- const { data: userMarker, cachedAt } = await getUserMarker();
26118
- return { data: userMarker, cachedAt };
26119
- }, [onUserMarkerFetchedLegacy], {
26120
- callbackDataSelector,
26121
- });
26122
- };
26123
-
26124
25961
  /**
26125
25962
  *
26126
25963
  * ```js
@@ -26162,7 +25999,7 @@ const getUserUnread = (callback) => {
26162
25999
  model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
26163
26000
  callback({
26164
26001
  data: callbackModel
26165
- ? Object.assign(Object.assign({}, callbackModel), { hasMentioned: callbackModel.isMentioned }) : callbackModel,
26002
+ ? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
26166
26003
  loading: data.loading,
26167
26004
  error: data.error,
26168
26005
  });
@@ -26253,7 +26090,6 @@ var index$l = /*#__PURE__*/Object.freeze({
26253
26090
  onClientBanned: onClientBanned,
26254
26091
  onSessionStateChange: onSessionStateChange,
26255
26092
  onNetworkActivities: onNetworkActivities,
26256
- getTotalUnreadCount: getTotalUnreadCount,
26257
26093
  getUserUnread: getUserUnread,
26258
26094
  getMarkerSyncEvents: getMarkerSyncEvents,
26259
26095
  setMarkerSyncEvents: setMarkerSyncEvents,
@@ -26262,7 +26098,6 @@ var index$l = /*#__PURE__*/Object.freeze({
26262
26098
  startMarkerSync: startMarkerSync,
26263
26099
  startUnreadSync: startUnreadSync,
26264
26100
  stopUnreadSync: stopUnreadSync,
26265
- stopUnreadSyncing: stopUnreadSyncing,
26266
26101
  getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
26267
26102
  });
26268
26103
 
@@ -26347,311 +26182,134 @@ const unBlockUser = async (userId) => {
26347
26182
  };
26348
26183
  /* end_public_function */
26349
26184
 
26350
- class PaginationController {
26351
- constructor(queryParams) {
26352
- const { http } = getActiveClient();
26353
- this.queryParams = queryParams;
26354
- this.http = http;
26355
- }
26356
- loadFirstPage() {
26357
- return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
26358
- }
26359
- loadNextPage() {
26360
- return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
26361
- }
26362
- loadPreviousPage() {
26363
- return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
26364
- }
26365
- async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
26366
- var _a, _b, _c, _d;
26367
- if (direction === 'prev' && !this.previousToken)
26368
- return;
26369
- if (direction === 'next' && !this.nextToken)
26370
- return;
26371
- let token;
26372
- if (direction === 'prev')
26373
- token = this.previousToken;
26374
- if (direction === 'next')
26375
- token = this.nextToken;
26376
- const queryResponse = await this.getRequest(this.queryParams, token);
26377
- if (direction === 'first') {
26378
- this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
26379
- this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
26380
- }
26381
- if (direction === 'prev')
26382
- this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
26383
- if (direction === 'next')
26384
- this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
26385
- return queryResponse;
26386
- }
26387
- getNextToken() {
26388
- return this.nextToken;
26389
- }
26390
- getPrevToken() {
26391
- return this.previousToken;
26392
- }
26393
- }
26394
-
26395
- class BlockedUserPaginationController extends PaginationController {
26396
- async getRequest(queryParams, token) {
26397
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
26398
- const options = token ? { token } : { limit };
26399
- const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
26400
- params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
26401
- });
26402
- return queryResponse;
26403
- }
26404
- }
26405
-
26406
- class QueryStreamController {
26407
- constructor(query, cacheKey) {
26408
- this.query = query;
26409
- this.cacheKey = cacheKey;
26410
- }
26411
- }
26412
-
26413
- var EnumFollowActions;
26414
- (function (EnumFollowActions) {
26415
- EnumFollowActions["OnRequested"] = "onRequested";
26416
- EnumFollowActions["OnAccepted"] = "onAccepted";
26417
- EnumFollowActions["OnDeclined"] = "onDeclined";
26418
- EnumFollowActions["OnCanceled"] = "onCanceled";
26419
- EnumFollowActions["OnFollowed"] = "onFollowed";
26420
- EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
26421
- EnumFollowActions["OnDeleted"] = "onDeleted";
26422
- EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
26423
- })(EnumFollowActions || (EnumFollowActions = {}));
26424
-
26425
- class BlockedUserQueryStreamController extends QueryStreamController {
26426
- constructor(query, cacheKey, notifyChange, preparePayload) {
26427
- super(query, cacheKey);
26428
- this.notifyChange = notifyChange;
26429
- this.preparePayload = preparePayload;
26430
- }
26431
- async saveToMainDB(response) {
26432
- const processedPayload = await this.preparePayload(response);
26433
- const client = getActiveClient();
26434
- const cachedAt = client.cache && Date.now();
26435
- if (client.cache) {
26436
- ingestInCache(processedPayload, { cachedAt });
26437
- }
26438
- }
26439
- appendToQueryStream(response, direction, refresh = false) {
26440
- var _a, _b;
26441
- if (refresh) {
26442
- pushToCache(this.cacheKey, {
26443
- data: response.users.map(getResolver('user')),
26444
- });
26445
- }
26446
- else {
26447
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26448
- const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
26449
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
26450
- }
26451
- }
26452
- reactor(action) {
26453
- return (targetUser) => {
26454
- var _a;
26455
- if (action === EnumFollowActions.OnFollowed) {
26456
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26457
- const updatedCollection = collection === null || collection === void 0 ? void 0 : collection.data.filter(id => id !== targetUser.userId);
26458
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: updatedCollection }));
26459
- }
26460
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
26461
- };
26462
- }
26463
- subscribeRTE(createSubscriber) {
26464
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
26465
- }
26466
- }
26467
-
26468
- class PaginationNoPageController {
26469
- constructor(queryParams) {
26470
- const { http } = getActiveClient();
26471
- this.queryParams = queryParams;
26472
- this.http = http;
26473
- }
26474
- async onFetch() {
26475
- const queryResponse = await this.getRequest(this.queryParams);
26476
- return queryResponse;
26477
- }
26478
- }
26479
-
26480
- class LiveCollectionController {
26481
- constructor(paginationController, queryStreamId, cacheKey, callback) {
26482
- this.paginationController = paginationController;
26483
- this.queryStreamId = queryStreamId;
26484
- this.cacheKey = cacheKey;
26485
- this.callback = callback;
26486
- }
26487
- async refresh() {
26488
- try {
26489
- let result;
26490
- if (this.paginationController instanceof PaginationNoPageController) {
26491
- result = await this.paginationController.onFetch();
26492
- }
26493
- else {
26494
- result = await this.paginationController.loadFirstPage();
26495
- }
26496
- if (!result)
26497
- return;
26498
- await this.persistModel(result);
26499
- this.persistQueryStream({
26500
- response: result,
26501
- direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
26502
- refresh: true,
26503
- });
26504
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
26505
- }
26506
- catch (e) {
26507
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
26508
- }
26509
- }
26510
- loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
26511
- this.setup();
26512
- this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
26513
- if (initial) {
26514
- this.refresh();
26515
- }
26516
- else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
26517
- this.loadPrevPage();
26518
- }
26519
- else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
26520
- this.loadNextPage();
26521
- }
26522
- }
26523
- async loadNextPage() {
26524
- try {
26525
- if (this.paginationController instanceof PaginationNoPageController)
26526
- return;
26527
- const result = await this.paginationController.loadNextPage();
26528
- if (!result)
26529
- return;
26530
- await this.persistModel(result);
26531
- this.persistQueryStream({
26532
- response: result,
26533
- direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
26534
- });
26535
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
26536
- }
26537
- catch (e) {
26538
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
26539
- }
26540
- }
26541
- async loadPrevPage() {
26542
- try {
26543
- if (this.paginationController instanceof PaginationNoPageController)
26544
- return;
26545
- const result = await this.paginationController.loadPreviousPage();
26546
- if (!result)
26547
- return;
26548
- await this.persistModel(result);
26549
- this.persistQueryStream({
26550
- response: result,
26551
- direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
26552
- });
26553
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
26554
- }
26555
- catch (e) {
26556
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
26557
- }
26558
- }
26559
- shouldNotify(data) {
26560
- const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
26561
- if (isEqual(this.snapshot, newData))
26562
- return false;
26563
- this.snapshot = newData;
26564
- return true;
26565
- }
26566
- getCacheKey() {
26567
- return this.cacheKey;
26568
- }
26569
- }
26570
-
26571
- function prepareBlockedUserPayload(response) {
26572
- const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
26573
- return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
26574
- const followUser = users.find(user => user.userId === follow.from);
26575
- return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
26576
- }), users: users.map(convertRawUserToInternalUser) });
26577
- }
26578
-
26185
+ /* begin_public_function
26186
+ id: user.relationship.follow
26187
+ */
26579
26188
  /**
26580
26189
  * ```js
26581
- * import { onUserUpdated } from '@amityco/ts-sdk-react-native'
26582
- * const dispose = onUserUpdated(user => {
26583
- * // ...
26584
- * })
26190
+ * import { follow } from '@amityco/ts-sdk-react-native'
26191
+ * const status = await follow('foobar')
26585
26192
  * ```
26586
26193
  *
26587
- * Fired when a {@link Amity.InternalUser} has been updated
26194
+ * Follow the user
26588
26195
  *
26589
- * @param callback The function to call when the event was fired
26590
- * @returns an {@link Amity.Unsubscriber} function to stop listening
26196
+ * @param userId the ID of the {@link Amity.InternalUser}
26197
+ * @returns the status {@link Amity.FollowStatus}
26591
26198
  *
26592
- * @category User Events
26199
+ * @category Follow API
26200
+ * @async
26593
26201
  */
26594
- const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
26202
+ const follow = async (userId) => {
26203
+ const client = getActiveClient();
26204
+ client.log('follow/follow', userId);
26205
+ const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
26206
+ const cachedAt = client.cache && Date.now();
26207
+ if (client.cache) {
26208
+ ingestInCache(data, { cachedAt });
26209
+ }
26210
+ const payload = prepareFollowStatusPayload(data);
26211
+ if (data.follows[0].status === 'accepted') {
26212
+ fireEvent('local.follow.created', payload);
26213
+ }
26214
+ else {
26215
+ fireEvent('local.follow.requested', payload);
26216
+ }
26217
+ return {
26218
+ data: data.follows[0],
26219
+ cachedAt,
26220
+ };
26221
+ };
26222
+ /* end_public_function */
26595
26223
 
26224
+ /* begin_public_function
26225
+ id: user.relationship.unfollow
26226
+ */
26596
26227
  /**
26597
26228
  * ```js
26598
- * import { onUserFlagged } from '@amityco/ts-sdk-react-native'
26599
- * const dispose = onUserFlagged(user => {
26600
- * // ...
26601
- * })
26229
+ * import { unfollow } from '@amityco/ts-sdk-react-native'
26230
+ * await unfollow('foobar')
26602
26231
  * ```
26603
26232
  *
26604
- * Fired when a {@link Amity.InternalUser} has been flagged
26233
+ * Cancel the follow request or unfollow the user
26605
26234
  *
26606
- * @param callback The function to call when the event was fired
26607
- * @returns an {@link Amity.Unsubscriber} function to stop listening
26235
+ * @param userId the ID of the {@link Amity.InternalUser}
26236
+ * @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
26608
26237
  *
26609
- * @category User Events
26238
+ * @category Follow API
26239
+ * @async
26610
26240
  */
26611
- const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
26241
+ const unfollow = async (userId) => {
26242
+ const client = getActiveClient();
26243
+ client.log('follow/unfollow', userId);
26244
+ const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
26245
+ if (client.cache) {
26246
+ ingestInCache(data);
26247
+ }
26248
+ const payload = prepareFollowStatusPayload(data);
26249
+ fireEvent('local.follow.unfollowed', payload);
26250
+ return true;
26251
+ };
26252
+ /* end_public_function */
26612
26253
 
26254
+ /* begin_public_function
26255
+ id: user.relationship.accept_follow
26256
+ */
26613
26257
  /**
26614
26258
  * ```js
26615
- * import { onUserUnflagged } from '@amityco/ts-sdk-react-native'
26616
- * const dispose = onUserUnflagged(user => {
26617
- * // ...
26618
- * })
26259
+ * import { UserRepository } from '@amityco/ts-sdk-react-native'
26260
+ * await UserRepository.Relationship.acceptMyFollower('foobar')
26619
26261
  * ```
26620
26262
  *
26621
- * Fired when a flag has been removed from a {@link Amity.InternalUser}
26263
+ * Accept the follow request
26622
26264
  *
26623
- * @param callback The function to call when the event was fired
26624
- * @returns an {@link Amity.Unsubscriber} function to stop listening
26265
+ * @param userId the ID of the {@link Amity.InternalUser} follower
26266
+ * @returns A success boolean if the follow request was accepted
26625
26267
  *
26626
- * @category User Events
26268
+ * @category Follow API
26269
+ * @async
26627
26270
  */
26628
- const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
26271
+ const acceptMyFollower = async (userId) => {
26272
+ const client = getActiveClient();
26273
+ client.log('follow/acceptMyFollower', userId);
26274
+ const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
26275
+ if (client.cache) {
26276
+ ingestInCache(data);
26277
+ }
26278
+ const payload = prepareFollowStatusPayload(data);
26279
+ fireEvent('local.follow.accepted', payload);
26280
+ return true;
26281
+ };
26282
+ /* end_public_function */
26629
26283
 
26284
+ /* begin_public_function
26285
+ id: user.relationship.decline_follow
26286
+ */
26630
26287
  /**
26631
26288
  * ```js
26632
- * import { onUserFlagCleared } from '@amityco/ts-sdk-react-native'
26633
- * const dispose = onUserFlagCleared(user => {
26634
- * // ...
26635
- * })
26289
+ * import { UserRepository } from '@amityco/ts-sdk-react-native'
26290
+ * await UserRepository.Relationship.declineMyFollower('foobar')
26636
26291
  * ```
26637
26292
  *
26638
- * Fired when flags have been cleared for a {@link Amity.InternalUser}
26293
+ * Decline the follow request or delete the follower
26639
26294
  *
26640
- * @param callback The function to call when the event was fired
26641
- * @returns an {@link Amity.Unsubscriber} function to stop listening
26295
+ * @param userId the ID of the {@link Amity.InternalUser} follower
26296
+ * @returns A success boolean if the follow request was decline
26642
26297
  *
26643
- * @category User Events
26298
+ * @category Follow API
26299
+ * @async
26644
26300
  */
26645
- const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
26646
-
26647
- var EnumUserActions;
26648
- (function (EnumUserActions) {
26649
- EnumUserActions["OnUserDeleted"] = "onUserDeleted";
26650
- EnumUserActions["OnUserUpdated"] = "onUserUpdated";
26651
- EnumUserActions["OnUserFlagged"] = "onUserFlagged";
26652
- EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
26653
- EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
26654
- })(EnumUserActions || (EnumUserActions = {}));
26301
+ const declineMyFollower = async (userId) => {
26302
+ const client = getActiveClient();
26303
+ client.log('follow/declineMyFollower', userId);
26304
+ const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
26305
+ if (client.cache) {
26306
+ ingestInCache(data);
26307
+ }
26308
+ const payload = prepareFollowStatusPayload(data);
26309
+ fireEvent('local.follow.requestDeclined', payload);
26310
+ return true;
26311
+ };
26312
+ /* end_public_function */
26655
26313
 
26656
26314
  const createFollowEventSubscriber = (event, callback) => {
26657
26315
  const client = getActiveClient();
@@ -26915,446 +26573,50 @@ const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscri
26915
26573
 
26916
26574
  const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
26917
26575
 
26918
- const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
26919
- var _a, _b;
26920
- if (!sourceModel) {
26921
- return sourceModel;
26922
- }
26923
- const client = getActiveClient();
26924
- const { objectSyncMap } = client;
26925
- /*
26926
- * NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
26927
- * If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
26928
- */
26929
- const resolvedId = isLocalId(sourceModel[sourceModelProp])
26930
- ? sourceModel[sourceModelProp]
26931
- : (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
26932
- const model = (_b = pullFromCache([
26933
- destinationDomain,
26934
- 'get',
26935
- `${resolvedId}`,
26936
- ])) === null || _b === void 0 ? void 0 : _b.data;
26937
- if (!model)
26938
- return;
26939
- return callback(model);
26940
- });
26941
-
26942
- class BlockedUserLiveCollectionController extends LiveCollectionController {
26943
- constructor(query, callback) {
26944
- const queryStreamId = hash(query);
26945
- const cacheKey = ['blockedUsers', 'collection', queryStreamId];
26946
- const paginationController = new BlockedUserPaginationController(query);
26947
- super(paginationController, queryStreamId, cacheKey, callback);
26948
- this.query = query;
26949
- this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
26950
- this.callback = callback.bind(this);
26951
- this.loadPage({ initial: true });
26952
- }
26953
- setup() {
26954
- var _a;
26955
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26956
- if (!collection) {
26957
- pushToCache(this.cacheKey, {
26958
- data: [],
26959
- params: {},
26960
- });
26961
- }
26576
+ class PaginationController {
26577
+ constructor(queryParams) {
26578
+ const { http } = getActiveClient();
26579
+ this.queryParams = queryParams;
26580
+ this.http = http;
26962
26581
  }
26963
- async persistModel(queryPayload) {
26964
- await this.queryStreamController.saveToMainDB(queryPayload);
26582
+ loadFirstPage() {
26583
+ return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
26965
26584
  }
26966
- persistQueryStream({ response, direction, refresh, }) {
26967
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
26585
+ loadNextPage() {
26586
+ return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
26968
26587
  }
26969
- startSubscription() {
26970
- return this.queryStreamController.subscribeRTE([
26971
- {
26972
- fn: onUserDeleted$2,
26973
- action: EnumUserActions.OnUserDeleted,
26974
- },
26975
- // In the case of unblocking a user, we need to subscribe to the follow events
26976
- {
26977
- fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
26978
- action: EnumFollowActions.OnFollowed,
26979
- },
26980
- {
26981
- fn: convertEventPayload(onUserFollowed, 'to', 'user'),
26982
- action: EnumFollowActions.OnFollowed,
26983
- },
26984
- ]);
26588
+ loadPreviousPage() {
26589
+ return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
26985
26590
  }
26986
- notifyChange({ origin, loading, error }) {
26987
- var _a, _b;
26988
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26989
- if (!collection)
26591
+ async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
26592
+ var _a, _b, _c, _d;
26593
+ if (direction === 'prev' && !this.previousToken)
26990
26594
  return;
26991
- const data = this.applyFilter((_b = collection.data
26992
- .map(id => pullFromCache(['user', 'get', id]))
26993
- .filter(isNonNullable)
26994
- .map(({ data }) => data)
26995
- .map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
26996
- if (!this.shouldNotify(data) && origin === 'event')
26595
+ if (direction === 'next' && !this.nextToken)
26997
26596
  return;
26998
- this.callback({
26999
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
27000
- data,
27001
- hasNextPage: !!this.paginationController.getNextToken(),
27002
- loading,
27003
- error,
27004
- });
27005
- }
27006
- // eslint-disable-next-line class-methods-use-this
27007
- applyFilter(data) {
27008
- let users = data;
27009
- users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
27010
- return users;
27011
- }
27012
- }
27013
-
27014
- /* begin_public_function
27015
- id: user.get_blocked_users
27016
- */
27017
- /**
27018
- * ```js
27019
- * import { UserRepository } from '@amityco/ts-sdk-react-native'
27020
- * const unblockedUser = await UserRepository.blockUser('userId')
27021
- * ```
27022
- *
27023
- * Blocks a {@link Amity.InternalUser}
27024
- *
27025
- * @param params The params to get blocked {@link Amity.InternalUser}s
27026
- * @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
27027
- * @returns {@link Amity.Unsubscriber} to unsubscribe from collection
27028
- *
27029
- * @category Post API
27030
- * @async
27031
- */
27032
- const getBlockedUsers$1 = (params, callback, config) => {
27033
- const { log, cache } = getActiveClient();
27034
- if (!cache) {
27035
- console.log(ENABLE_CACHE_MESSAGE);
27036
- }
27037
- const timestamp = Date.now();
27038
- log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
27039
- const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
27040
- const disposers = blockedUserLiveCollection.startSubscription();
27041
- const cacheKey = blockedUserLiveCollection.getCacheKey();
27042
- disposers.push(() => dropFromCache(cacheKey));
27043
- return () => {
27044
- log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
27045
- disposers.forEach(fn => fn());
27046
- dropFromCache(cacheKey);
27047
- };
27048
- };
27049
- /* end_public_function */
27050
-
27051
- /* eslint-disable no-use-before-define */
27052
- const getBlockedUsers = (params, callback, config) => {
27053
- console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
27054
- return getBlockedUsers$1(params, callback);
27055
- };
27056
-
27057
- /* begin_public_function
27058
- id: user.relationship.follow
27059
- */
27060
- /**
27061
- * ```js
27062
- * import { follow } from '@amityco/ts-sdk-react-native'
27063
- * const status = await follow('foobar')
27064
- * ```
27065
- *
27066
- * Follow the user
27067
- *
27068
- * @param userId the ID of the {@link Amity.InternalUser}
27069
- * @returns the status {@link Amity.FollowStatus}
27070
- *
27071
- * @category Follow API
27072
- * @async
27073
- */
27074
- const follow = async (userId) => {
27075
- const client = getActiveClient();
27076
- client.log('follow/follow', userId);
27077
- const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
27078
- const cachedAt = client.cache && Date.now();
27079
- if (client.cache) {
27080
- ingestInCache(data, { cachedAt });
27081
- }
27082
- const payload = prepareFollowStatusPayload(data);
27083
- if (data.follows[0].status === 'accepted') {
27084
- fireEvent('local.follow.created', payload);
27085
- }
27086
- else {
27087
- fireEvent('local.follow.requested', payload);
27088
- }
27089
- return {
27090
- data: data.follows[0],
27091
- cachedAt,
27092
- };
27093
- };
27094
- /* end_public_function */
27095
-
27096
- /* begin_public_function
27097
- id: user.relationship.unfollow
27098
- */
27099
- /**
27100
- * ```js
27101
- * import { unfollow } from '@amityco/ts-sdk-react-native'
27102
- * await unfollow('foobar')
27103
- * ```
27104
- *
27105
- * Cancel the follow request or unfollow the user
27106
- *
27107
- * @param userId the ID of the {@link Amity.InternalUser}
27108
- * @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
27109
- *
27110
- * @category Follow API
27111
- * @async
27112
- */
27113
- const unfollow = async (userId) => {
27114
- const client = getActiveClient();
27115
- client.log('follow/unfollow', userId);
27116
- const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
27117
- if (client.cache) {
27118
- ingestInCache(data);
27119
- }
27120
- const payload = prepareFollowStatusPayload(data);
27121
- fireEvent('local.follow.unfollowed', payload);
27122
- return true;
27123
- };
27124
- /* end_public_function */
27125
-
27126
- /**
27127
- * @deprecated This API renamed to `acceptMyFollower`.
27128
- * Please use acceptMyFollower() instead.
27129
- *
27130
- * ```js
27131
- * import { acceptFollower } from '@amityco/ts-sdk-react-native'
27132
- * await acceptFollower('foobar')
27133
- * ```
27134
- *
27135
- * Accept the follow request
27136
- *
27137
- * @param userId the ID of the {@link Amity.InternalUser} follower
27138
- * @returns A success boolean if the follow request was accepted
27139
- *
27140
- * @category Follow API
27141
- * @async
27142
- */
27143
- const acceptFollower = async (userId) => {
27144
- const client = getActiveClient();
27145
- client.log('follow/acceptFollower', userId);
27146
- const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
27147
- if (client.cache) {
27148
- ingestInCache(data);
27149
- }
27150
- const payload = prepareFollowStatusPayload(data);
27151
- fireEvent('local.follow.accepted', payload);
27152
- return true;
27153
- };
27154
-
27155
- /* begin_public_function
27156
- id: user.relationship.accept_follow
27157
- */
27158
- /**
27159
- * ```js
27160
- * import { UserRepository } from '@amityco/ts-sdk-react-native'
27161
- * await UserRepository.Relationship.acceptMyFollower('foobar')
27162
- * ```
27163
- *
27164
- * Accept the follow request
27165
- *
27166
- * @param userId the ID of the {@link Amity.InternalUser} follower
27167
- * @returns A success boolean if the follow request was accepted
27168
- *
27169
- * @category Follow API
27170
- * @async
27171
- */
27172
- const acceptMyFollower = async (userId) => {
27173
- const client = getActiveClient();
27174
- client.log('follow/acceptMyFollower', userId);
27175
- const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
27176
- if (client.cache) {
27177
- ingestInCache(data);
26597
+ let token;
26598
+ if (direction === 'prev')
26599
+ token = this.previousToken;
26600
+ if (direction === 'next')
26601
+ token = this.nextToken;
26602
+ const queryResponse = await this.getRequest(this.queryParams, token);
26603
+ if (direction === 'first') {
26604
+ this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
26605
+ this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
26606
+ }
26607
+ if (direction === 'prev')
26608
+ this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
26609
+ if (direction === 'next')
26610
+ this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
26611
+ return queryResponse;
27178
26612
  }
27179
- const payload = prepareFollowStatusPayload(data);
27180
- fireEvent('local.follow.accepted', payload);
27181
- return true;
27182
- };
27183
- /* end_public_function */
27184
-
27185
- /**
27186
- * @deprecated This API renamed to `declineMyFollower`.
27187
- * Please use declineMyFollower() instead.
27188
- *
27189
- * ```js
27190
- * import { declineFollower } from '@amityco/ts-sdk-react-native'
27191
- * await declineFollower('foobar')
27192
- * ```
27193
- *
27194
- * Decline the follow request or delete the follower
27195
- *
27196
- * @param userId the ID of the {@link Amity.InternalUser} follower
27197
- * @returns A success boolean if the follow request was decline
27198
- *
27199
- * @category Follow API
27200
- * @async
27201
- */
27202
- const declineFollower = async (userId) => {
27203
- const client = getActiveClient();
27204
- client.log('follow/declineFollower', userId);
27205
- const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
27206
- if (client.cache) {
27207
- ingestInCache(data);
26613
+ getNextToken() {
26614
+ return this.nextToken;
27208
26615
  }
27209
- const payload = prepareFollowStatusPayload(data);
27210
- fireEvent('local.follow.requestDeclined', payload);
27211
- return true;
27212
- };
27213
-
27214
- /* begin_public_function
27215
- id: user.relationship.decline_follow
27216
- */
27217
- /**
27218
- * ```js
27219
- * import { UserRepository } from '@amityco/ts-sdk-react-native'
27220
- * await UserRepository.Relationship.declineMyFollower('foobar')
27221
- * ```
27222
- *
27223
- * Decline the follow request or delete the follower
27224
- *
27225
- * @param userId the ID of the {@link Amity.InternalUser} follower
27226
- * @returns A success boolean if the follow request was decline
27227
- *
27228
- * @category Follow API
27229
- * @async
27230
- */
27231
- const declineMyFollower = async (userId) => {
27232
- const client = getActiveClient();
27233
- client.log('follow/declineMyFollower', userId);
27234
- const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
27235
- if (client.cache) {
27236
- ingestInCache(data);
26616
+ getPrevToken() {
26617
+ return this.previousToken;
27237
26618
  }
27238
- const payload = prepareFollowStatusPayload(data);
27239
- fireEvent('local.follow.requestDeclined', payload);
27240
- return true;
27241
- };
27242
- /* end_public_function */
27243
-
27244
- /**
27245
- * ```js
27246
- * import { observeFollowInfo } from '@amityco/ts-sdk-react-native'
27247
- *
27248
- * let followInfo = {}
27249
- * const dispose = observeFollowInfo(userId, updated => followInfo = updated)
27250
- * ```
27251
- *
27252
- * Observe all mutation on a given {@link Amity.FollowInfo}
27253
- *
27254
- * @param userId the ID of the user to observe
27255
- * @param callback the function to call when new data are available
27256
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
27257
- *
27258
- * @category Follow Observer
27259
- */
27260
- const observeFollowInfo = (userId, callback, policy = 'cache_then_server') => {
27261
- const { log } = getActiveClient();
27262
- const timestamp = Date.now();
27263
- log(`observeFollowInfo(tmpid: ${timestamp}) > listen`);
27264
- const router = (result, action) => {
27265
- var _a, _b;
27266
- if (callback instanceof Function)
27267
- return callback(result);
27268
- if (action !== 'onFetch')
27269
- (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
27270
- (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
27271
- };
27272
- const realtimeRouter = (result, action) => {
27273
- var _a;
27274
- if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
27275
- return;
27276
- router(result, action);
27277
- };
27278
- const disposers = [];
27279
- disposers.push(onFollowInfoUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')));
27280
- runQuery(createQuery(getFollowInfo$1, userId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
27281
- return () => {
27282
- log(`observeFollowInfo(tmpid: ${timestamp}) > dispose`);
27283
- disposers.forEach(fn => fn());
27284
- };
27285
- };
27286
-
27287
- /**
27288
- * ```js
27289
- * import { observeFollowers } from '@amityco/ts-sdk-react-native'
27290
- *
27291
- * let followers = []
27292
- * const unsub = observeFollowers('userId', follower => merge(followers, follower))
27293
- * ```
27294
- *
27295
- * Observe all mutations on a list of followers {@link Amity.FollowStatus} for a given user
27296
- *
27297
- * @param userId the ID of the {@link Amity.InternalUser}
27298
- * @param callback the function to call when new data are available
27299
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
27300
- *
27301
- * @category Follow Observer
27302
- */
27303
- const observeFollowers = (userId, callback) => {
27304
- const { log } = getActiveClient();
27305
- const timestamp = Date.now();
27306
- log(`observeFollowers(tmpid: ${timestamp}) > listen`);
27307
- const disposers = [];
27308
- const router = (status, action) => {
27309
- var _a, _b;
27310
- if (callback instanceof Function) {
27311
- return callback(status);
27312
- }
27313
- (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
27314
- (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
27315
- };
27316
- 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')));
27317
- return () => {
27318
- log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
27319
- disposers.forEach(fn => fn());
27320
- };
27321
- };
27322
-
27323
- /**
27324
- * ```js
27325
- * import { observeFollowings } from '@amityco/ts-sdk-react-native'
27326
- *
27327
- * let followings = []
27328
- * const unsub = observeFollowers('userId', follower => merge(followings, following))
27329
- * ```
27330
- *
27331
- * Observe all mutations on a list of followings {@link Amity.FollowStatus} for a given user
27332
- *
27333
- * @param userId the ID of the {@link Amity.InternalUser}
27334
- * @param callback the function to call when new data are available
27335
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
27336
- *
27337
- * @category Follow Observer
27338
- */
27339
- const observeFollowings = (userId, callback) => {
27340
- const { log } = getActiveClient();
27341
- const timestamp = Date.now();
27342
- log(`observeFollowings(tmpid: ${timestamp}) > listen`);
27343
- const disposers = [];
27344
- const router = (status, action) => {
27345
- var _a, _b;
27346
- if (callback instanceof Function) {
27347
- return callback(status);
27348
- }
27349
- (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
27350
- (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
27351
- };
27352
- 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')));
27353
- return () => {
27354
- log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
27355
- disposers.forEach(fn => fn());
27356
- };
27357
- };
26619
+ }
27358
26620
 
27359
26621
  class FollowerPaginationController extends PaginationController {
27360
26622
  async getRequest(queryParams, token) {
@@ -27369,6 +26631,25 @@ class FollowerPaginationController extends PaginationController {
27369
26631
  }
27370
26632
  }
27371
26633
 
26634
+ class QueryStreamController {
26635
+ constructor(query, cacheKey) {
26636
+ this.query = query;
26637
+ this.cacheKey = cacheKey;
26638
+ }
26639
+ }
26640
+
26641
+ var EnumFollowActions;
26642
+ (function (EnumFollowActions) {
26643
+ EnumFollowActions["OnRequested"] = "onRequested";
26644
+ EnumFollowActions["OnAccepted"] = "onAccepted";
26645
+ EnumFollowActions["OnDeclined"] = "onDeclined";
26646
+ EnumFollowActions["OnCanceled"] = "onCanceled";
26647
+ EnumFollowActions["OnFollowed"] = "onFollowed";
26648
+ EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
26649
+ EnumFollowActions["OnDeleted"] = "onDeleted";
26650
+ EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
26651
+ })(EnumFollowActions || (EnumFollowActions = {}));
26652
+
27372
26653
  class FollowerQueryStreamController extends QueryStreamController {
27373
26654
  constructor(query, cacheKey, notifyChange, preparePayload) {
27374
26655
  super(query, cacheKey);
@@ -27424,6 +26705,109 @@ class FollowerQueryStreamController extends QueryStreamController {
27424
26705
  }
27425
26706
  }
27426
26707
 
26708
+ class PaginationNoPageController {
26709
+ constructor(queryParams) {
26710
+ const { http } = getActiveClient();
26711
+ this.queryParams = queryParams;
26712
+ this.http = http;
26713
+ }
26714
+ async onFetch() {
26715
+ const queryResponse = await this.getRequest(this.queryParams);
26716
+ return queryResponse;
26717
+ }
26718
+ }
26719
+
26720
+ class LiveCollectionController {
26721
+ constructor(paginationController, queryStreamId, cacheKey, callback) {
26722
+ this.paginationController = paginationController;
26723
+ this.queryStreamId = queryStreamId;
26724
+ this.cacheKey = cacheKey;
26725
+ this.callback = callback;
26726
+ }
26727
+ async refresh() {
26728
+ try {
26729
+ let result;
26730
+ if (this.paginationController instanceof PaginationNoPageController) {
26731
+ result = await this.paginationController.onFetch();
26732
+ }
26733
+ else {
26734
+ result = await this.paginationController.loadFirstPage();
26735
+ }
26736
+ if (!result)
26737
+ return;
26738
+ await this.persistModel(result);
26739
+ this.persistQueryStream({
26740
+ response: result,
26741
+ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
26742
+ refresh: true,
26743
+ });
26744
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
26745
+ }
26746
+ catch (e) {
26747
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
26748
+ }
26749
+ }
26750
+ loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
26751
+ this.setup();
26752
+ this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
26753
+ if (initial) {
26754
+ this.refresh();
26755
+ }
26756
+ else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
26757
+ this.loadPrevPage();
26758
+ }
26759
+ else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
26760
+ this.loadNextPage();
26761
+ }
26762
+ }
26763
+ async loadNextPage() {
26764
+ try {
26765
+ if (this.paginationController instanceof PaginationNoPageController)
26766
+ return;
26767
+ const result = await this.paginationController.loadNextPage();
26768
+ if (!result)
26769
+ return;
26770
+ await this.persistModel(result);
26771
+ this.persistQueryStream({
26772
+ response: result,
26773
+ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
26774
+ });
26775
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
26776
+ }
26777
+ catch (e) {
26778
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
26779
+ }
26780
+ }
26781
+ async loadPrevPage() {
26782
+ try {
26783
+ if (this.paginationController instanceof PaginationNoPageController)
26784
+ return;
26785
+ const result = await this.paginationController.loadPreviousPage();
26786
+ if (!result)
26787
+ return;
26788
+ await this.persistModel(result);
26789
+ this.persistQueryStream({
26790
+ response: result,
26791
+ direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
26792
+ });
26793
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
26794
+ }
26795
+ catch (e) {
26796
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
26797
+ }
26798
+ }
26799
+ shouldNotify(data) {
26800
+ const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
26801
+ if (isEqual(this.snapshot, newData))
26802
+ return false;
26803
+ this.snapshot = newData;
26804
+ return true;
26805
+ }
26806
+ getCacheKey() {
26807
+ return this.cacheKey;
26808
+ }
26809
+ }
26810
+
27427
26811
  const onFollowerUserDeleted = ({ userId }) => (callback) => {
27428
26812
  const client = getActiveClient();
27429
26813
  const filter = (data) => {
@@ -27768,6 +27152,69 @@ const getFollowings = (params, callback, config) => {
27768
27152
  };
27769
27153
  /* end_public_function */
27770
27154
 
27155
+ /**
27156
+ * @deprecated This function will to be deprecated soon.
27157
+ */
27158
+ const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
27159
+ const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
27160
+ const { cache } = getActiveClient();
27161
+ if (!cache) {
27162
+ console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
27163
+ }
27164
+ let model;
27165
+ let isUnsyncedModel = false; // for messages
27166
+ const disposers = [];
27167
+ const dispatcher = (data) => {
27168
+ const { data: newModel } = data, rest = __rest(data, ["data"]);
27169
+ if (!callbackFilter || callbackFilter(newModel, model)) {
27170
+ callback(Object.assign({ data: callbackDataSelector(newModel) }, rest));
27171
+ }
27172
+ // resolve all getter on data model to a static value to avoid comparison problems
27173
+ model = convertGetterPropsToStatic(newModel);
27174
+ };
27175
+ const realtimeRouter = (eventModel, forceDispatch = false) => {
27176
+ if (id !== eventModel[key]) {
27177
+ return;
27178
+ }
27179
+ if (model) {
27180
+ if (!forceDispatch && isEqual(model, eventModel)) {
27181
+ return;
27182
+ }
27183
+ }
27184
+ dispatcher({ loading: false, data: eventModel, origin: 'event' });
27185
+ };
27186
+ const onFetch = () => {
27187
+ // TODO: Ihis `@ts-ignore` is bring back to fix the build and it needs to be removed later
27188
+ // @ts-ignore
27189
+ const query = createQuery(fetcher, id, true);
27190
+ runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
27191
+ if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
27192
+ dispatcher({
27193
+ // @ts-ignore
27194
+ data,
27195
+ origin,
27196
+ loading: false,
27197
+ error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
27198
+ });
27199
+ isUnsyncedModel = true;
27200
+ disposers.forEach(fn => fn());
27201
+ }
27202
+ else if (!isUnsyncedModel) {
27203
+ // @ts-ignore
27204
+ dispatcher({ loading, data, origin, error });
27205
+ }
27206
+ if (error) {
27207
+ disposers.forEach(fn => fn());
27208
+ }
27209
+ });
27210
+ };
27211
+ disposers.push(...eventHandlers.map(fn => fn(eventModel => realtimeRouter(eventModel, forceDispatch))));
27212
+ onFetch();
27213
+ return () => {
27214
+ disposers.forEach(fn => fn());
27215
+ };
27216
+ };
27217
+
27771
27218
  /* begin_public_function
27772
27219
  id: user.relationship.get_follow_info
27773
27220
  */
@@ -27833,12 +27280,9 @@ var index$k = /*#__PURE__*/Object.freeze({
27833
27280
  __proto__: null,
27834
27281
  blockUser: blockUser,
27835
27282
  unBlockUser: unBlockUser,
27836
- getBlockedUsers: getBlockedUsers,
27837
27283
  follow: follow,
27838
27284
  unfollow: unfollow,
27839
- acceptFollower: acceptFollower,
27840
27285
  acceptMyFollower: acceptMyFollower,
27841
- declineFollower: declineFollower,
27842
27286
  declineMyFollower: declineMyFollower,
27843
27287
  onUserFollowed: onUserFollowed,
27844
27288
  onUserUnfollowed: onUserUnfollowed,
@@ -27853,9 +27297,6 @@ var index$k = /*#__PURE__*/Object.freeze({
27853
27297
  onLocalFollowerRequested: onLocalFollowerRequested,
27854
27298
  onLocalFollowRequestAccepted: onLocalFollowRequestAccepted,
27855
27299
  onLocalFollowRequestDeclined: onLocalFollowRequestDeclined,
27856
- observeFollowInfo: observeFollowInfo,
27857
- observeFollowers: observeFollowers,
27858
- observeFollowings: observeFollowings,
27859
27300
  getFollowers: getFollowers,
27860
27301
  getFollowings: getFollowings,
27861
27302
  getFollowInfo: getFollowInfo,
@@ -28043,6 +27484,74 @@ const isUserFlaggedByMe = async (userId) => {
28043
27484
  };
28044
27485
  /* end_public_function */
28045
27486
 
27487
+ /**
27488
+ * ```js
27489
+ * import { onUserUpdated } from '@amityco/ts-sdk-react-native'
27490
+ * const dispose = onUserUpdated(user => {
27491
+ * // ...
27492
+ * })
27493
+ * ```
27494
+ *
27495
+ * Fired when a {@link Amity.InternalUser} has been updated
27496
+ *
27497
+ * @param callback The function to call when the event was fired
27498
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27499
+ *
27500
+ * @category User Events
27501
+ */
27502
+ const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
27503
+
27504
+ /**
27505
+ * ```js
27506
+ * import { onUserFlagged } from '@amityco/ts-sdk-react-native'
27507
+ * const dispose = onUserFlagged(user => {
27508
+ * // ...
27509
+ * })
27510
+ * ```
27511
+ *
27512
+ * Fired when a {@link Amity.InternalUser} has been flagged
27513
+ *
27514
+ * @param callback The function to call when the event was fired
27515
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27516
+ *
27517
+ * @category User Events
27518
+ */
27519
+ const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
27520
+
27521
+ /**
27522
+ * ```js
27523
+ * import { onUserUnflagged } from '@amityco/ts-sdk-react-native'
27524
+ * const dispose = onUserUnflagged(user => {
27525
+ * // ...
27526
+ * })
27527
+ * ```
27528
+ *
27529
+ * Fired when a flag has been removed from a {@link Amity.InternalUser}
27530
+ *
27531
+ * @param callback The function to call when the event was fired
27532
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27533
+ *
27534
+ * @category User Events
27535
+ */
27536
+ const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
27537
+
27538
+ /**
27539
+ * ```js
27540
+ * import { onUserFlagCleared } from '@amityco/ts-sdk-react-native'
27541
+ * const dispose = onUserFlagCleared(user => {
27542
+ * // ...
27543
+ * })
27544
+ * ```
27545
+ *
27546
+ * Fired when flags have been cleared for a {@link Amity.InternalUser}
27547
+ *
27548
+ * @param callback The function to call when the event was fired
27549
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27550
+ *
27551
+ * @category User Events
27552
+ */
27553
+ const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
27554
+
28046
27555
  /**
28047
27556
  * ```js
28048
27557
  * import { onUserFetched } from '@amityco/ts-sdk-react-native'
@@ -28074,7 +27583,7 @@ const onUserFetched = (callback) => createUserEventSubscriber('user.fetched', ca
28074
27583
  * @category Private
28075
27584
  * @async
28076
27585
  */
28077
- const getUser$2 = async (userId) => {
27586
+ const getUser$1 = async (userId) => {
28078
27587
  const client = getActiveClient();
28079
27588
  client.log('user/getUser', userId);
28080
27589
  isInTombstone('user', userId);
@@ -28110,7 +27619,7 @@ const getUser$2 = async (userId) => {
28110
27619
  *
28111
27620
  * @category User API
28112
27621
  */
28113
- getUser$2.locally = (userId) => {
27622
+ getUser$1.locally = (userId) => {
28114
27623
  const client = getActiveClient();
28115
27624
  client.log('user/getUser.locally', userId);
28116
27625
  if (!client.cache)
@@ -28146,11 +27655,11 @@ getUser$2.locally = (userId) => {
28146
27655
  *
28147
27656
  * @category Message Live Object
28148
27657
  */
28149
- const getUser$1 = (userId, callback) => {
27658
+ const getUser = (userId, callback) => {
28150
27659
  const reactor = (response) => {
28151
27660
  return callback(Object.assign(Object.assign({}, response), { data: response.data ? LinkedObject.user(response.data) : response.data }));
28152
27661
  };
28153
- return liveObject(userId, reactor, 'userId', getUser$2, [
27662
+ return liveObject(userId, reactor, 'userId', getUser$1, [
28154
27663
  onUserFetched,
28155
27664
  onUserUpdated,
28156
27665
  onUserDeleted$2,
@@ -28163,10 +27672,10 @@ const getUser$1 = (userId, callback) => {
28163
27672
 
28164
27673
  class UserPaginationController extends PaginationController {
28165
27674
  async getRequest(queryParams, token) {
28166
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
27675
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
28167
27676
  const options = token ? { token } : { limit };
28168
27677
  const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
28169
- params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
27678
+ params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
28170
27679
  });
28171
27680
  return queryResponse;
28172
27681
  }
@@ -28218,6 +27727,15 @@ class UserQueryStreamController extends QueryStreamController {
28218
27727
  }
28219
27728
  }
28220
27729
 
27730
+ var EnumUserActions;
27731
+ (function (EnumUserActions) {
27732
+ EnumUserActions["OnUserDeleted"] = "onUserDeleted";
27733
+ EnumUserActions["OnUserUpdated"] = "onUserUpdated";
27734
+ EnumUserActions["OnUserFlagged"] = "onUserFlagged";
27735
+ EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
27736
+ EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
27737
+ })(EnumUserActions || (EnumUserActions = {}));
27738
+
28221
27739
  class UserLiveCollectionController extends LiveCollectionController {
28222
27740
  constructor(query, callback) {
28223
27741
  const queryStreamId = hash(query);
@@ -28276,21 +27794,17 @@ class UserLiveCollectionController extends LiveCollectionController {
28276
27794
  }
28277
27795
  applyFilter(data) {
28278
27796
  let users = data;
28279
- if (!this.query.displayName) {
28280
- const sortFn = (() => {
28281
- switch (this.query.sortBy) {
28282
- case 'firstCreated':
28283
- return sortByFirstCreated;
28284
- case 'lastCreated':
28285
- return sortByLastCreated;
28286
- case 'displayName':
28287
- return sortByDisplayName;
28288
- default:
28289
- return sortByLastCreated;
28290
- }
28291
- })();
28292
- users = users.sort(sortFn);
28293
- }
27797
+ const sortFn = (() => {
27798
+ switch (this.query.sortBy) {
27799
+ case 'firstCreated':
27800
+ return sortByFirstCreated;
27801
+ case 'lastCreated':
27802
+ return sortByLastCreated;
27803
+ default:
27804
+ return sortByLastCreated;
27805
+ }
27806
+ })();
27807
+ users = users.sort(sortFn);
28294
27808
  if (this.query.filter === 'flagged') {
28295
27809
  users = users.filter(user => !!user.hashFlag);
28296
27810
  }
@@ -28337,90 +27851,200 @@ const getUsers = (params, callback, config) => {
28337
27851
  };
28338
27852
  /* end_public_function */
28339
27853
 
28340
- /**
28341
- * ```js
28342
- * import { getUser } from '~/user/api'
28343
- * const { data: user } = await getUser('foobar')
28344
- * ```
28345
- *
28346
- * Fetches a {@link Amity.User} object
28347
- *
28348
- * @param userId the ID of the {@link Amity.User} to fetch
28349
- * @returns the associated {@link Amity.User} object
28350
- *
28351
- * @category Private
28352
- * @async
28353
- */
28354
- const getUser = async (userId) => {
28355
- const { data, cachedAt } = await getUser$2(userId);
28356
- return {
28357
- data: LinkedObject.user(data),
28358
- cachedAt,
28359
- };
28360
- };
28361
- /**
28362
- * ```js
28363
- * import { getUser } from '@amityco/ts-sdk-react-native'
28364
- * const { data: user } = getUser.locally('foobar')
28365
- * ```
28366
- *
28367
- * Fetches a {@link Amity.User} object from cache
28368
- *
28369
- * @param userId the ID of the {@link Amity.User} to fetch
28370
- * @returns the associated {@link Amity.User} object
28371
- *
28372
- * @category User API
28373
- */
28374
- getUser.locally = (userId) => {
28375
- const cached = getUser$2.locally(userId);
28376
- if (!cached)
27854
+ class BlockedUserPaginationController extends PaginationController {
27855
+ async getRequest(queryParams, token) {
27856
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
27857
+ const options = token ? { token } : { limit };
27858
+ const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
27859
+ params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
27860
+ });
27861
+ return queryResponse;
27862
+ }
27863
+ }
27864
+
27865
+ class BlockedUserQueryStreamController extends QueryStreamController {
27866
+ constructor(query, cacheKey, notifyChange, preparePayload) {
27867
+ super(query, cacheKey);
27868
+ this.notifyChange = notifyChange;
27869
+ this.preparePayload = preparePayload;
27870
+ }
27871
+ async saveToMainDB(response) {
27872
+ const processedPayload = await this.preparePayload(response);
27873
+ const client = getActiveClient();
27874
+ const cachedAt = client.cache && Date.now();
27875
+ if (client.cache) {
27876
+ ingestInCache(processedPayload, { cachedAt });
27877
+ }
27878
+ }
27879
+ appendToQueryStream(response, direction, refresh = false) {
27880
+ var _a, _b;
27881
+ if (refresh) {
27882
+ pushToCache(this.cacheKey, {
27883
+ data: response.users.map(getResolver('user')),
27884
+ });
27885
+ }
27886
+ else {
27887
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
27888
+ const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
27889
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
27890
+ }
27891
+ }
27892
+ reactor(action) {
27893
+ return (targetUser) => {
27894
+ var _a;
27895
+ if (action === EnumFollowActions.OnFollowed) {
27896
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
27897
+ const updatedCollection = collection === null || collection === void 0 ? void 0 : collection.data.filter(id => id !== targetUser.userId);
27898
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: updatedCollection }));
27899
+ }
27900
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
27901
+ };
27902
+ }
27903
+ subscribeRTE(createSubscriber) {
27904
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
27905
+ }
27906
+ }
27907
+
27908
+ function prepareBlockedUserPayload(response) {
27909
+ const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
27910
+ return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
27911
+ const followUser = users.find(user => user.userId === follow.from);
27912
+ return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
27913
+ }), users: users.map(convertRawUserToInternalUser) });
27914
+ }
27915
+
27916
+ const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
27917
+ var _a, _b;
27918
+ if (!sourceModel) {
27919
+ return sourceModel;
27920
+ }
27921
+ const client = getActiveClient();
27922
+ const { objectSyncMap } = client;
27923
+ /*
27924
+ * NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
27925
+ * If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
27926
+ */
27927
+ const resolvedId = isLocalId(sourceModel[sourceModelProp])
27928
+ ? sourceModel[sourceModelProp]
27929
+ : (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
27930
+ const model = (_b = pullFromCache([
27931
+ destinationDomain,
27932
+ 'get',
27933
+ `${resolvedId}`,
27934
+ ])) === null || _b === void 0 ? void 0 : _b.data;
27935
+ if (!model)
28377
27936
  return;
28378
- return {
28379
- data: LinkedObject.user(cached.data),
28380
- cachedAt: cached.cachedAt,
28381
- };
28382
- };
27937
+ return callback(model);
27938
+ });
28383
27939
 
27940
+ class BlockedUserLiveCollectionController extends LiveCollectionController {
27941
+ constructor(query, callback) {
27942
+ const queryStreamId = hash(query);
27943
+ const cacheKey = ['blockedUsers', 'collection', queryStreamId];
27944
+ const paginationController = new BlockedUserPaginationController(query);
27945
+ super(paginationController, queryStreamId, cacheKey, callback);
27946
+ this.query = query;
27947
+ this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
27948
+ this.callback = callback.bind(this);
27949
+ this.loadPage({ initial: true });
27950
+ }
27951
+ setup() {
27952
+ var _a;
27953
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
27954
+ if (!collection) {
27955
+ pushToCache(this.cacheKey, {
27956
+ data: [],
27957
+ params: {},
27958
+ });
27959
+ }
27960
+ }
27961
+ async persistModel(queryPayload) {
27962
+ await this.queryStreamController.saveToMainDB(queryPayload);
27963
+ }
27964
+ persistQueryStream({ response, direction, refresh, }) {
27965
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
27966
+ }
27967
+ startSubscription() {
27968
+ return this.queryStreamController.subscribeRTE([
27969
+ {
27970
+ fn: onUserDeleted$2,
27971
+ action: EnumUserActions.OnUserDeleted,
27972
+ },
27973
+ // In the case of unblocking a user, we need to subscribe to the follow events
27974
+ {
27975
+ fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
27976
+ action: EnumFollowActions.OnFollowed,
27977
+ },
27978
+ {
27979
+ fn: convertEventPayload(onUserFollowed, 'to', 'user'),
27980
+ action: EnumFollowActions.OnFollowed,
27981
+ },
27982
+ ]);
27983
+ }
27984
+ notifyChange({ origin, loading, error }) {
27985
+ var _a, _b;
27986
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
27987
+ if (!collection)
27988
+ return;
27989
+ const data = this.applyFilter((_b = collection.data
27990
+ .map(id => pullFromCache(['user', 'get', id]))
27991
+ .filter(isNonNullable)
27992
+ .map(({ data }) => data)
27993
+ .map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
27994
+ if (!this.shouldNotify(data) && origin === 'event')
27995
+ return;
27996
+ this.callback({
27997
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
27998
+ data,
27999
+ hasNextPage: !!this.paginationController.getNextToken(),
28000
+ loading,
28001
+ error,
28002
+ });
28003
+ }
28004
+ // eslint-disable-next-line class-methods-use-this
28005
+ applyFilter(data) {
28006
+ let users = data;
28007
+ users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
28008
+ return users;
28009
+ }
28010
+ }
28011
+
28012
+ /* begin_public_function
28013
+ id: user.get_blocked_users
28014
+ */
28384
28015
  /**
28385
28016
  * ```js
28386
- * import { observeUser } from '@amityco/ts-sdk-react-native'
28387
- *
28388
- * let user = {}
28389
- * const dispose = observeUser(userId, updated => user = updated)
28017
+ * import { UserRepository } from '@amityco/ts-sdk-react-native'
28018
+ * const unblockedUser = await UserRepository.blockUser('userId')
28390
28019
  * ```
28391
28020
  *
28392
- * @param userId the ID of the user to observe
28393
- * @param callback the function to call when new data are available
28394
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the user
28021
+ * Blocks a {@link Amity.InternalUser}
28022
+ *
28023
+ * @param params The params to get blocked {@link Amity.InternalUser}s
28024
+ * @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
28025
+ * @returns {@link Amity.Unsubscriber} to unsubscribe from collection
28395
28026
  *
28396
- * Observe all mutation on a given {@link Amity.InternalUser}
28397
- * @category User Observer
28027
+ * @category Post API
28028
+ * @async
28398
28029
  */
28399
- const observeUser = (userId, callback) => {
28400
- const { log } = getActiveClient();
28030
+ const getBlockedUsers = (params, callback, config) => {
28031
+ const { log, cache } = getActiveClient();
28032
+ if (!cache) {
28033
+ console.log(ENABLE_CACHE_MESSAGE);
28034
+ }
28401
28035
  const timestamp = Date.now();
28402
- log(`observeUser(tmpid: ${timestamp}) > listen`);
28403
- // wrapper function to make sure
28404
- const router = (result, action) => {
28405
- var _a, _b, _c;
28406
- // filter function
28407
- if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
28408
- return;
28409
- const newResult = Object.assign(Object.assign({}, result), { data: LinkedObject.user(result.data) });
28410
- if (callback instanceof Function)
28411
- return callback(newResult);
28412
- if (action !== 'onFetch')
28413
- (_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, newResult);
28414
- (_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, newResult);
28415
- };
28416
- const disposers = [];
28417
- 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')));
28418
- runQuery(createQuery(getUser, userId), result => result.data && router(result, 'onFetch'));
28036
+ log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
28037
+ const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
28038
+ const disposers = blockedUserLiveCollection.startSubscription();
28039
+ const cacheKey = blockedUserLiveCollection.getCacheKey();
28040
+ disposers.push(() => dropFromCache(cacheKey));
28419
28041
  return () => {
28420
- log(`observeUser(tmpid: ${timestamp}) > dispose`);
28042
+ log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
28421
28043
  disposers.forEach(fn => fn());
28044
+ dropFromCache(cacheKey);
28422
28045
  };
28423
- };
28046
+ };
28047
+ /* end_public_function */
28424
28048
 
28425
28049
  class SearchUserPaginationController extends PaginationController {
28426
28050
  async getRequest(queryParams, token) {
@@ -28605,74 +28229,6 @@ const queryReachUser = async ({ viewId, viewedType, limit, token, }) => {
28605
28229
  return response.data;
28606
28230
  };
28607
28231
 
28608
- /**
28609
- * @deprecated: Please use {@link UserRepository.getReachUsers} instead
28610
- * @param params
28611
- * @param callback
28612
- */
28613
- const getViewedUsers = (params, callback) => {
28614
- const { log, cache } = getActiveClient();
28615
- const cacheKey = ['postViewedUsers', 'collection', { postId: params.postId }];
28616
- if (!cache) {
28617
- console.log(ENABLE_CACHE_MESSAGE);
28618
- }
28619
- const timestamp = Date.now();
28620
- log(`getViewedUsers(tmpid: ${timestamp}) > listen`);
28621
- const { limit: queryLimit, postId } = params;
28622
- const responder = (snapshot) => {
28623
- var _a, _b;
28624
- let users = [];
28625
- if (snapshot === null || snapshot === void 0 ? void 0 : snapshot.data) {
28626
- users =
28627
- snapshot.data
28628
- .map((userId) => pullFromCache(['user', 'get', userId]))
28629
- .filter(Boolean)
28630
- .map(data => data === null || data === void 0 ? void 0 : data.data) || [];
28631
- }
28632
- callback({
28633
- // eslint-disable-next-line no-use-before-define
28634
- onNextPage: onFetch,
28635
- data: users,
28636
- hasNextPage: !!((_b = (_a = snapshot.params) === null || _a === void 0 ? void 0 : _a.page) === null || _b === void 0 ? void 0 : _b.next),
28637
- loading: snapshot.loading || false,
28638
- });
28639
- };
28640
- const onFetch = (initial = false) => {
28641
- var _a, _b, _c;
28642
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28643
- const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
28644
- if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
28645
- return;
28646
- const query = createQuery(queryReachUser, {
28647
- viewId: postId,
28648
- viewedType: "post" /* Amity.AnalyticEventContentType.Post */,
28649
- limit: queryLimit || 10,
28650
- token: !initial ? (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) === null || _c === void 0 ? void 0 : _c.next : undefined,
28651
- });
28652
- runQuery(query, result => {
28653
- var _a, _b, _c, _d, _e;
28654
- let userIds = (_c = (_b = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : [];
28655
- if ((_d = result.data) === null || _d === void 0 ? void 0 : _d.users) {
28656
- userIds = [
28657
- ...new Set([...userIds, ...result.data.users.map(({ userId }) => userId)]),
28658
- ];
28659
- }
28660
- const saveToCache = {
28661
- loading: result.loading,
28662
- params: { page: (_e = result.data) === null || _e === void 0 ? void 0 : _e.paging },
28663
- data: userIds || [],
28664
- };
28665
- pushToCache(cacheKey, saveToCache);
28666
- responder(saveToCache);
28667
- }, queryOptions(COLLECTION_DEFAULT_CACHING_POLICY, CACHE_SHORTEN_LIFESPAN));
28668
- };
28669
- onFetch(true);
28670
- return () => {
28671
- log(`getViewedUsers(tmpid: ${timestamp}) > dispose`);
28672
- dropFromCache(cacheKey);
28673
- };
28674
- };
28675
-
28676
28232
  const getReachedUsers = (params, callback) => {
28677
28233
  // Pre-defined function to avoid undefined function call
28678
28234
  let onFetch = (initial = false) => undefined;
@@ -28760,12 +28316,10 @@ var index$j = /*#__PURE__*/Object.freeze({
28760
28316
  onUserFlagged: onUserFlagged,
28761
28317
  onUserUnflagged: onUserUnflagged,
28762
28318
  onUserFlagCleared: onUserFlagCleared,
28763
- getUser: getUser$1,
28319
+ getUser: getUser,
28764
28320
  getUsers: getUsers,
28765
- observeUser: observeUser,
28766
- getBlockedUsers: getBlockedUsers$1,
28321
+ getBlockedUsers: getBlockedUsers,
28767
28322
  searchUserByDisplayName: searchUserByDisplayName,
28768
- getViewedUsers: getViewedUsers,
28769
28323
  getReachedUsers: getReachedUsers,
28770
28324
  get AmityUserSearchMatchType () { return AmityUserSearchMatchType; }
28771
28325
  });
@@ -29015,181 +28569,6 @@ const uploadImage = async (formData, onProgress) => {
29015
28569
  };
29016
28570
  /* end_public_function */
29017
28571
 
29018
- /**
29019
- * ```js
29020
- * import { createImage } from '@amityco/ts-sdk-react-native'
29021
- * const created = await createImage(formData)
29022
- * ```
29023
- *
29024
- * Creates an {@link Amity.File<'image'>}
29025
- *
29026
- * @param formData The data necessary to create a new {@link Amity.File<'image'>}
29027
- * @param onProgress The callback to track the upload progress
29028
- * @returns The newly created {@link Amity.File<'image'>}
29029
- *
29030
- * @category File API
29031
- * @async
29032
- */
29033
- const createImage = async (formData, onProgress) => {
29034
- const client = getActiveClient();
29035
- client.log('file/createImage', formData);
29036
- const files = formData.getAll('files');
29037
- if (!files.length)
29038
- throw new Error('The formData object must have a `files` key.');
29039
- const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
29040
- formData.append('accessType', accessType);
29041
- formData.append('preferredFilename', files[0].name);
29042
- const headers = 'getHeaders' in formData
29043
- ? formData.getHeaders()
29044
- : { 'content-type': 'multipart/form-data' };
29045
- const { data } = await client.http.post('/api/v4/images', formData, {
29046
- headers,
29047
- onUploadProgress({ loaded, total = 100 }) {
29048
- onProgress && onProgress(Math.round((loaded * 100) / total));
29049
- },
29050
- });
29051
- // API-FIX: payload should be serialized properly
29052
- // const { files } = data
29053
- const cachedAt = client.cache && Date.now();
29054
- if (client.cache)
29055
- ingestInCache({ files: data }, { cachedAt });
29056
- return {
29057
- data,
29058
- cachedAt,
29059
- };
29060
- };
29061
- /* end_public_function */
29062
-
29063
- /**
29064
- * ```js
29065
- * import { FileRepository } from '@amityco/ts-sdk-react-native'
29066
- * const created = await FileRepository.createFile(formData)
29067
- * ```
29068
- *
29069
- * Creates an {@link Amity.File}
29070
- *
29071
- * @param formData The data necessary to create a new {@link Amity.File}
29072
- * @param onProgress The callback to track the upload progress
29073
- * @returns The newly created {@link Amity.File}
29074
- *
29075
- * @category File API
29076
- * @async
29077
- */
29078
- const createFile = async (formData, onProgress) => {
29079
- const client = getActiveClient();
29080
- client.log('file/createFile', formData);
29081
- const files = formData.getAll('files');
29082
- if (!files.length)
29083
- throw new Error('The formData object must have a `files` key.');
29084
- const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
29085
- formData.append('accessType', accessType);
29086
- formData.append('preferredFilename', files[0].name);
29087
- const headers = 'getHeaders' in formData
29088
- ? formData.getHeaders()
29089
- : { 'content-type': 'multipart/form-data' };
29090
- const { data } = await client.http.post('/api/v4/files', formData, {
29091
- headers,
29092
- onUploadProgress({ loaded, total = 100 }) {
29093
- onProgress && onProgress(Math.round((loaded * 100) / total));
29094
- },
29095
- });
29096
- // API-FIX: payload should be serialized properly
29097
- // const { files } = data
29098
- const cachedAt = client.cache && Date.now();
29099
- if (client.cache)
29100
- ingestInCache({ files: data }, { cachedAt });
29101
- return {
29102
- data,
29103
- cachedAt,
29104
- };
29105
- };
29106
-
29107
- /**
29108
- * ```js
29109
- * import { FileRepository } from '@amityco/ts-sdk-react-native'
29110
- * const created = await FileRepository.createVideo(formData)
29111
- * ```
29112
- *
29113
- * Creates an {@link Amity.File<'video'>}
29114
- *
29115
- * @param formData The data necessary to create a new {@link Amity.File<'video'>}
29116
- * @param feedType The {@link Amity.File<'video'>} feed type
29117
- * @param onProgress The callback to track the upload progress
29118
- * @returns The newly uploaded {@link Amity.File<'video'>}
29119
- *
29120
- * @category File API
29121
- * @async
29122
- */
29123
- const createVideo = async (formData, feedType, onProgress) => {
29124
- const client = getActiveClient();
29125
- client.log('file/createVideo', formData);
29126
- const files = formData.getAll('files');
29127
- if (!files.length)
29128
- throw new Error('The formData object must have a `files` key.');
29129
- const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
29130
- formData.append('accessType', accessType);
29131
- formData.append('preferredFilename', files[0].name);
29132
- if (feedType) {
29133
- formData.append('feedType', feedType);
29134
- }
29135
- const headers = 'getHeaders' in formData
29136
- ? formData.getHeaders()
29137
- : { 'content-type': 'multipart/form-data' };
29138
- const { data } = await client.http.post('/api/v4/videos', formData, {
29139
- headers,
29140
- onUploadProgress({ loaded, total = 100 }) {
29141
- onProgress && onProgress(Math.round((loaded * 100) / total));
29142
- },
29143
- });
29144
- // API-FIX: payload should be serialized properly
29145
- // const { files } = data
29146
- const cachedAt = client.cache && Date.now();
29147
- if (client.cache)
29148
- ingestInCache({ files: data }, { cachedAt });
29149
- return {
29150
- data,
29151
- cachedAt,
29152
- };
29153
- };
29154
-
29155
- /**
29156
- * ```js
29157
- * import { observeFile } from '@amityco/ts-sdk-react-native'
29158
- *
29159
- * let file = {}
29160
- * const dispose = observeFile(fileId, updated => file = updated)
29161
- * ```
29162
- *
29163
- * Observe all mutation on a given {@link Amity.File}
29164
- *
29165
- * @param fileId the ID of the file to observe
29166
- * @param callback the function to call when new data are available
29167
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the file
29168
- *
29169
- * @category File Observer
29170
- */
29171
- const observeFile = (fileId, callback) => {
29172
- const { log } = getActiveClient();
29173
- const timestamp = Date.now();
29174
- log(`observeFile(tmpid: ${timestamp}) > listen`);
29175
- // wrapper function to make sure
29176
- const router = (result, action) => {
29177
- var _a, _b, _c;
29178
- // filter function
29179
- if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.fileId) !== fileId)
29180
- return;
29181
- if (callback instanceof Function)
29182
- return callback(result);
29183
- if (action !== 'onFetch')
29184
- (_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, result);
29185
- (_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
29186
- };
29187
- runQuery(createQuery(getFile, fileId), result => result.data && router(result, 'onFetch'));
29188
- return () => {
29189
- log(`observeFile(tmpid: ${timestamp}) > dispose`);
29190
- };
29191
- };
29192
-
29193
28572
  var index$i = /*#__PURE__*/Object.freeze({
29194
28573
  __proto__: null,
29195
28574
  getFile: getFile,
@@ -29197,11 +28576,7 @@ var index$i = /*#__PURE__*/Object.freeze({
29197
28576
  deleteFile: deleteFile,
29198
28577
  fileUrlWithSize: fileUrlWithSize,
29199
28578
  uploadVideo: uploadVideo,
29200
- uploadImage: uploadImage,
29201
- createImage: createImage,
29202
- createFile: createFile,
29203
- createVideo: createVideo,
29204
- observeFile: observeFile
28579
+ uploadImage: uploadImage
29205
28580
  });
29206
28581
 
29207
28582
  /**
@@ -29222,16 +28597,12 @@ var index$i = /*#__PURE__*/Object.freeze({
29222
28597
  const queryRoles = async (query) => {
29223
28598
  const client = getActiveClient();
29224
28599
  client.log('role/queryRoles', query);
29225
- const _a = query !== null && query !== void 0 ? query : {}, { page, limit = 10, queryToken, displayName, sortBy } = _a, params = __rest(_a, ["page", "limit", "queryToken", "displayName", "sortBy"]);
28600
+ const _a = query !== null && query !== void 0 ? query : {}, { limit = 10, queryToken, displayName, sortBy } = _a, params = __rest(_a, ["limit", "queryToken", "displayName", "sortBy"]);
29226
28601
  const options = (() => {
29227
28602
  if (queryToken)
29228
28603
  return { token: queryToken };
29229
28604
  if (limit)
29230
28605
  return { limit };
29231
- if (page)
29232
- return {
29233
- token: toToken(page, 'skiplimit'),
29234
- };
29235
28606
  return undefined;
29236
28607
  })();
29237
28608
  // API-FIX: parameters should be querystring.
@@ -29359,12 +28730,9 @@ const dispatchReactable = (referenceType, model) => {
29359
28730
  * @category Message API
29360
28731
  * @async
29361
28732
  */
29362
- const getMessage$2 = async (messageId, isLive = false) => {
28733
+ const getMessage$1 = async (messageId, isLive = false) => {
29363
28734
  const client = getActiveClient();
29364
28735
  client.log('message/getMessage', messageId);
29365
- if (!isLive) {
29366
- console.log('getMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
29367
- }
29368
28736
  isInTombstone('message', messageId);
29369
28737
  let data;
29370
28738
  try {
@@ -29401,7 +28769,7 @@ const getMessage$2 = async (messageId, isLive = false) => {
29401
28769
  *
29402
28770
  * @category Message API
29403
28771
  */
29404
- getMessage$2.locally = (messageId) => {
28772
+ getMessage$1.locally = (messageId) => {
29405
28773
  const client = getActiveClient();
29406
28774
  client.log('message/getMessage.locally', messageId);
29407
28775
  if (!client.cache)
@@ -31330,7 +30698,7 @@ const getChannel$1 = async (channelId) => {
31330
30698
  ingestInCache(data, { cachedAt });
31331
30699
  const { channels } = data;
31332
30700
  return {
31333
- data: constructChannelDynamicValue(channels.find(channel => channel.channelId === channelId)),
30701
+ data: channels.find(channel => channel.channelId === channelId),
31334
30702
  cachedAt,
31335
30703
  };
31336
30704
  };
@@ -31360,7 +30728,7 @@ getChannel$1.locally = (channelId) => {
31360
30728
  if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) === 0)
31361
30729
  return;
31362
30730
  return {
31363
- data: constructChannelDynamicValue(cached[0].data),
30731
+ data: cached[0].data,
31364
30732
  cachedAt: cached[0].cachedAt,
31365
30733
  };
31366
30734
  };
@@ -31385,7 +30753,7 @@ const deleteChannel = async (channelId) => {
31385
30753
  await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}`);
31386
30754
  const deleted = await getChannel$1(channelId);
31387
30755
  // no need for event, fired by server
31388
- return deleted.data;
30756
+ return constructChannelDynamicValue(deleted.data);
31389
30757
  };
31390
30758
 
31391
30759
  /* begin_public_function
@@ -31507,81 +30875,6 @@ const unmuteChannel = async (channelId) => {
31507
30875
  };
31508
30876
  /* end_public_function */
31509
30877
 
31510
- /**
31511
- * ```js
31512
- * import { observeChannel } from '@amityco/ts-sdk-react-native'
31513
- *
31514
- * let channel = {}
31515
- * const dispose = observeChannel(channelId, ({ data }) => channel = data)
31516
- * ```
31517
- *
31518
- * Observe all mutation on a given {@link Amity.Channel}
31519
- *
31520
- * @param channelId the ID of the channel to observe
31521
- * @param callback the function to call when new data are available
31522
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channel
31523
- *
31524
- * @category Channel Observer
31525
- */
31526
- const observeChannel = (channelId, callback) => {
31527
- const { log } = getActiveClient();
31528
- const timestamp = Date.now();
31529
- log(`observeChannel(tmpid: ${timestamp}) > listen`);
31530
- // wrapper function to make sure
31531
- const router = (result, action) => {
31532
- var _a, _b, _c;
31533
- // filter function
31534
- if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.channelId) !== channelId)
31535
- return;
31536
- if (callback instanceof Function)
31537
- return callback(Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
31538
- if (action !== 'onFetch')
31539
- (_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
31540
- (_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
31541
- };
31542
- const disposers = [];
31543
- disposers.push(onChannelUpdated(data => router({ data, loading: false, origin: 'event' }, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)), onChannelDeleted(data => router({ data, loading: false, origin: 'event' }, "onDelete" /* Amity.ChannelActionType.OnDelete */)), onChannelJoined(data => router({ data, loading: false, origin: 'event' }, "onJoin" /* Amity.ChannelActionType.OnJoin */)), onChannelLeft(data => router({ data, loading: false, origin: 'event' }, "onLeft" /* Amity.ChannelActionType.OnLeft */)), onChannelMuted(data => router({ data, loading: false, origin: 'event' }, "onMute" /* Amity.ChannelActionType.OnMute */)), onChannelMemberAdded(data => router({ data, loading: false, origin: 'event' }, "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */)), onChannelMemberRemoved(data => router({ data, loading: false, origin: 'event' }, "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */)), convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel')(data => router({ data, loading: false, origin: 'event' }, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)));
31544
- runQuery(createQuery(getChannel$1, channelId), result => result.data && router(result, "onFetch" /* Amity.ChannelActionType.OnFetch */));
31545
- return () => {
31546
- log(`observeChannel(tmpid: ${timestamp}) > dispose`);
31547
- disposers.forEach(fn => fn());
31548
- };
31549
- };
31550
-
31551
- /**
31552
- * ```js
31553
- * import { observeChannels } from '@amityco/ts-sdk-react-native'
31554
- *
31555
- * let channels = []
31556
- * const unsub = observeChannels(channel => merge(channels, channel))
31557
- * ```
31558
- *
31559
- * Observe all mutations on a list of {@link Amity.Channel} for a current user
31560
- *
31561
- * @param callback the function to call when new data are available
31562
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
31563
- *
31564
- * @category Channel Observer
31565
- */
31566
- const observeChannels = (callback) => {
31567
- const { log } = getActiveClient();
31568
- const timestamp = Date.now();
31569
- log(`observeChannels(tmpid: ${timestamp}) > listen`);
31570
- const disposers = [];
31571
- const router = (channel, action) => {
31572
- var _a, _b;
31573
- if (callback instanceof Function)
31574
- return callback(LinkedObject.channel(constructChannelDynamicValue(channel)));
31575
- (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, LinkedObject.channel(constructChannelDynamicValue(channel)));
31576
- (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, LinkedObject.channel(constructChannelDynamicValue(channel)));
31577
- };
31578
- disposers.push(onChannelCreated(data => router(data, "onCreate" /* Amity.ChannelActionType.OnCreate */)), onChannelUpdated(data => router(data, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)), onChannelDeleted(data => router(data, "onDelete" /* Amity.ChannelActionType.OnDelete */)), onChannelJoined(data => router(data, "onJoin" /* Amity.ChannelActionType.OnJoin */)), onChannelLeft(data => router(data, "onLeft" /* Amity.ChannelActionType.OnLeft */)), onChannelMuted(data => router(data, "onMute" /* Amity.ChannelActionType.OnMute */)), onChannelMemberAdded(data => router(data, "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */)), onChannelMemberRemoved(data => router(data, "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */)), convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel')(data => router(data, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)));
31579
- return () => {
31580
- log(`observeChannels(tmpid: ${timestamp}) > dispose`);
31581
- disposers.forEach(fn => fn());
31582
- };
31583
- };
31584
-
31585
30878
  /**
31586
30879
  * ```js
31587
30880
  * import { onMessageUpdated } from '@amityco/ts-sdk-react-native'
@@ -31860,69 +31153,6 @@ const onSubChannelFetched = (callback) => {
31860
31153
  return createEventSubscriber(getActiveClient(), 'onSubChannelFetched', 'local.message-feed.fetched', payload => callback(payload.messageFeeds[0]));
31861
31154
  };
31862
31155
 
31863
- /**
31864
- * ```js
31865
- * import { getMessages } from '@amityco/ts-sdk-react-native'
31866
- * const messages = await getMessages(['foo', 'bar'])
31867
- * ```
31868
- *
31869
- * Fetches a collection of {@link Amity.Message} objects
31870
- *
31871
- * @param messageIds the IDs of the {@link Amity.Message} to fetch
31872
- * @returns the associated collection of {@link Amity.Message} objects
31873
- *
31874
- * @category Message API
31875
- * @async
31876
- */
31877
- const getMessages$1 = async (messageIds) => {
31878
- const client = getActiveClient();
31879
- client.log('message/getMessages', messageIds);
31880
- const { data: payload } = await client.http.get(`/api/v5/messages/list`, {
31881
- params: { messageIds: messageIds.map(encodeURIComponent) },
31882
- });
31883
- const data = await prepareMessagePayload(payload);
31884
- const cachedAt = client.cache && Date.now();
31885
- if (client.cache)
31886
- ingestInCache(data, { cachedAt });
31887
- const { messages } = data;
31888
- fireEvent('local.message.fetched', { messages });
31889
- return {
31890
- data: messages.map(message => LinkedObject.message(message)),
31891
- cachedAt,
31892
- };
31893
- };
31894
- /**
31895
- * ```js
31896
- * import { getMessages } from '@amityco/ts-sdk-react-native'
31897
- * const messages = getMessages.locally(['foo', 'bar']) ?? []
31898
- * ```
31899
- *
31900
- * Fetches a collection of {@link Amity.Message} objects from cache
31901
- *
31902
- * @param messageIds the IDs of the {@link Amity.Message} to fetch
31903
- * @returns the associated collection of {@link Amity.Message} objects
31904
- *
31905
- * @category Message API
31906
- */
31907
- getMessages$1.locally = (messageIds) => {
31908
- var _a;
31909
- const client = getActiveClient();
31910
- client.log('message/getMessages.locally', messageIds);
31911
- if (!client.cache)
31912
- return;
31913
- const cached = messageIds
31914
- .map(messageId => pullFromCache(['message', 'get', messageId]))
31915
- .filter(Boolean);
31916
- const messages = cached.map(({ data }) => data);
31917
- const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
31918
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < messageIds.length)
31919
- return;
31920
- return {
31921
- data: messages,
31922
- cachedAt: oldest.cachedAt,
31923
- };
31924
- };
31925
-
31926
31156
  const getLocalId = () => `LOCAL_${uuid()}`;
31927
31157
  // FIXME: temp solution
31928
31158
  let uniqueId;
@@ -31947,7 +31177,11 @@ const createMessageOptimistic = (bundle) => {
31947
31177
  if (subChannel) {
31948
31178
  upsertInCache(['subChannel', 'get', bundle.subChannelId], Object.assign(Object.assign({}, subChannel.data), { messageCount: subChannel.data.messageCount + 1 }));
31949
31179
  if (subChannel.data.channelId === subChannel.data.subChannelId) {
31950
- const channel = pullFromCache(['channel', 'get', subChannel.data.channelId]);
31180
+ const channel = pullFromCache([
31181
+ 'channel',
31182
+ 'get',
31183
+ subChannel.data.channelId,
31184
+ ]);
31951
31185
  if (channel === null || channel === void 0 ? void 0 : channel.data) {
31952
31186
  upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_a = channel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
31953
31187
  }
@@ -32235,7 +31469,7 @@ const softDeleteMessage = async (messageId) => {
32235
31469
  client.log('message/softDeleteMessage', messageId);
32236
31470
  // API-FIX: This endpoint has not been implemented yet.
32237
31471
  await client.http.delete(`/api/v5/messages/${encodeURIComponent(messageId)}`);
32238
- const deleted = await getMessage$2(messageId);
31472
+ const deleted = await getMessage$1(messageId);
32239
31473
  fireEvent('local.message.deleted', { messages: [deleted.data] });
32240
31474
  return LinkedObject.message(deleted.data);
32241
31475
  };
@@ -32709,12 +31943,12 @@ const onMessageFetched = (callback) => {
32709
31943
  *
32710
31944
  * @category Message Live Object
32711
31945
  */
32712
- const getMessage$1 = (messageId, callback) => {
31946
+ const getMessage = (messageId, callback) => {
32713
31947
  const responder = (snapshot) => {
32714
31948
  const { data } = snapshot;
32715
31949
  callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.message(snapshot.data) : data }));
32716
31950
  };
32717
- return liveObject(messageId, responder, 'messageId', getMessage$2, [
31951
+ return liveObject(messageId, responder, 'messageId', getMessage$1, [
32718
31952
  onMessageFetched,
32719
31953
  onMessageUpdated,
32720
31954
  onMessageDeleted,
@@ -32763,7 +31997,7 @@ class MessageQueryStreamController extends QueryStreamController {
32763
31997
  }
32764
31998
  reactor(action) {
32765
31999
  return (payload) => {
32766
- var _a, _b, _c, _d, _e;
32000
+ var _a, _b, _c;
32767
32001
  if (action === 'onCreate') {
32768
32002
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
32769
32003
  const { referenceId } = payload;
@@ -32773,14 +32007,9 @@ class MessageQueryStreamController extends QueryStreamController {
32773
32007
  return;
32774
32008
  if (this.query.type && this.query.type !== payload.dataType)
32775
32009
  return;
32776
- if (this.query.dataType && this.query.dataType !== payload.dataType)
32777
- return;
32778
32010
  if (this.query.excludingTags &&
32779
32011
  ((_b = this.query.excludingTags) === null || _b === void 0 ? void 0 : _b.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
32780
32012
  return;
32781
- if (this.query.excludeTags &&
32782
- ((_c = this.query.excludeTags) === null || _c === void 0 ? void 0 : _c.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
32783
- return;
32784
32013
  if (!!this.query.hasFlags !== !!payload.flagCount)
32785
32014
  return;
32786
32015
  if (this.query.parentId && this.query.parentId !== payload.parentId)
@@ -32790,9 +32019,7 @@ class MessageQueryStreamController extends QueryStreamController {
32790
32019
  payload.isDeleted)
32791
32020
  return;
32792
32021
  if (this.query.includingTags &&
32793
- !((_d = this.query.includingTags) === null || _d === void 0 ? void 0 : _d.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
32794
- return;
32795
- if (this.query.tags && !((_e = this.query.tags) === null || _e === void 0 ? void 0 : _e.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
32022
+ !((_c = this.query.includingTags) === null || _c === void 0 ? void 0 : _c.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
32796
32023
  return;
32797
32024
  if ((!this.query.sortBy || this.query.sortBy === 'segmentDesc') &&
32798
32025
  !this.paginationController.getPrevToken()) {
@@ -32892,26 +32119,6 @@ class MessageLiveCollectionController extends LiveCollectionController {
32892
32119
  }
32893
32120
  applyFilter(data) {
32894
32121
  let messages = data;
32895
- messages = messages.filter(m => {
32896
- if (this.query.tags) {
32897
- return this.query.tags.find(value => {
32898
- if (!m.tags)
32899
- return false;
32900
- return m.tags.includes(value);
32901
- });
32902
- }
32903
- return true;
32904
- });
32905
- messages = messages.filter(m => {
32906
- if (this.query.excludeTags) {
32907
- return (this.query.excludeTags || []).find(value => {
32908
- if (!m.tags)
32909
- return true;
32910
- return !m.tags.includes(value);
32911
- });
32912
- }
32913
- return true;
32914
- });
32915
32122
  /*
32916
32123
  * for cases when message is deleted via RTE, this flag is used to get
32917
32124
  * items from cache that are !deleted
@@ -32948,7 +32155,6 @@ class MessageLiveCollectionController extends LiveCollectionController {
32948
32155
  }
32949
32156
  }
32950
32157
 
32951
- /* eslint-disable no-use-before-define */
32952
32158
  /* begin_public_function
32953
32159
  id: message.query
32954
32160
  */
@@ -32991,164 +32197,8 @@ const getMessages = (params, callback, config) => {
32991
32197
  };
32992
32198
  /* end_public_function */
32993
32199
 
32994
- /**
32995
- * ```js
32996
- * import { getMessage } from '@amityco/ts-sdk-react-native'
32997
- * const message = await getMessage('foobar')
32998
- * ```
32999
- *
33000
- * Fetches a {@link Amity.Message} object
33001
- *
33002
- * @param messageId the ID of the {@link Amity.Message} to fetch
33003
- * @returns the associated {@link Amity.Message} object
33004
- *
33005
- * @category Message API
33006
- * @async
33007
- */
33008
- const getMessage = async (messageId, isLive = false) => {
33009
- const client = getActiveClient();
33010
- client.log('message/getMessage', messageId);
33011
- if (!isLive) {
33012
- console.log('getMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
33013
- }
33014
- isInTombstone('message', messageId);
33015
- let data;
33016
- try {
33017
- // API-FIX: endpoint should not be /list, parameters should be querystring.
33018
- const { data: payload } = await client.http.get(`/api/v5/messages/${encodeURIComponent(messageId)}`);
33019
- data = await prepareMessagePayload(payload);
33020
- }
33021
- catch (error) {
33022
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
33023
- pushToTombstone('message', messageId);
33024
- }
33025
- throw error;
33026
- }
33027
- const cachedAt = client.cache && Date.now();
33028
- if (client.cache)
33029
- ingestInCache(data, { cachedAt });
33030
- const { messages } = data;
33031
- fireEvent('local.message.fetched', { messages });
33032
- return {
33033
- data: LinkedObject.message(messages.find(message => message.messageId === messageId)),
33034
- cachedAt,
33035
- };
33036
- };
33037
- /**
33038
- * ```js
33039
- * import { getMessage } from '@amityco/ts-sdk-react-native'
33040
- * const message = getMessage.locally('foobar')
33041
- * ```
33042
- *
33043
- * Fetches a {@link Amity.Message} object
33044
- *
33045
- * @param messageId the ID of the {@link Amity.Message} to fetch
33046
- * @returns the associated {@link Amity.Message} object
33047
- *
33048
- * @category Message API
33049
- */
33050
- getMessage.locally = (messageId) => {
33051
- const client = getActiveClient();
33052
- client.log('message/getMessage.locally', messageId);
33053
- if (!client.cache)
33054
- return;
33055
- const cached = pullFromCache(['message', 'get', messageId]);
33056
- if (!cached)
33057
- return;
33058
- return {
33059
- data: cached.data,
33060
- cachedAt: cached.cachedAt,
33061
- };
33062
- };
33063
-
33064
- /**
33065
- * ```js
33066
- * import { observeMessage } from '@amityco/ts-sdk-react-native'
33067
- *
33068
- * let message = {}
33069
- *
33070
- * const unsub = observeMessage(messageId, updated => message = updated)
33071
- * ```
33072
- *
33073
- * Observe all mutations on a {@link Amity.Message} given a single messageId
33074
- *
33075
- * @param client the client to observe the message with
33076
- * @param messageId the ID of the message to observe
33077
- * @param callback the function to call when new data are available
33078
- * @param policy a query policy option for this observer
33079
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
33080
- *
33081
- * @category Message Observer
33082
- */
33083
- const observeMessage = (messageId, callback, policy = 'cache_then_server') => {
33084
- const { log } = getActiveClient();
33085
- const timestamp = Date.now();
33086
- log(`observeMessage(tmpid: ${timestamp}) > listen`);
33087
- console.log('observeMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
33088
- // wrapper function to make sure
33089
- const router = (result, action) => {
33090
- var _a, _b, _c;
33091
- // filter function
33092
- if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.messageId) !== messageId)
33093
- return;
33094
- if (callback instanceof Function)
33095
- return callback(result);
33096
- if (action !== 'onFetch')
33097
- (_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, result);
33098
- (_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
33099
- };
33100
- const disposers = [];
33101
- disposers.push(onMessageUpdated(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onUpdate')), onMessageDeleted(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onDelete')), convertEventPayload(onMessageMarkerFetched, 'contentId', 'message')(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onUpdate')), convertEventPayload(onMessageMarked, 'contentId', 'message')(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onUpdate')));
33102
- if (policy !== 'no_fetch') {
33103
- runQuery(createQuery(getMessage, messageId), result => result.data && router(result, 'onFetch'), queryOptions(policy));
33104
- }
33105
- return () => {
33106
- log(`observeMessages(tmpid: ${timestamp}) > dispose`);
33107
- disposers.forEach(fn => fn());
33108
- };
33109
- };
33110
-
33111
- /**
33112
- * ```js
33113
- * import { observeMessages } from '@amityco/ts-sdk-react-native'
33114
- *
33115
- * let messages = []
33116
- *
33117
- * const unsubscribe = observeMessages(channelId, message => merge(messages, message))
33118
- * ```
33119
- *
33120
- * Observe all mutations on a list of {@link Amity.Message} for a given {@link Amity.SubChannel} object
33121
- *
33122
- * @param subChannelId the ID of the channel where to observe the messages
33123
- * @param callback the function to call when new data are available
33124
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
33125
- *
33126
- * @category Message Observer
33127
- */
33128
- const observeMessages = (subChannelId, callback) => {
33129
- const { log } = getActiveClient();
33130
- const timestamp = Date.now();
33131
- log(`observeMessages(tmpid: ${timestamp}) > listen`);
33132
- const disposers = [];
33133
- const router = (message, action) => {
33134
- var _a, _b, _c;
33135
- if (((_a = message.data) === null || _a === void 0 ? void 0 : _a.subChannelId) !== subChannelId)
33136
- return;
33137
- if (callback instanceof Function)
33138
- return callback(message);
33139
- (_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, message);
33140
- (_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, message);
33141
- };
33142
- disposers.push(onMessageCreatedMqtt(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onCreate')), onMessageCreatedLocal(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onCreate')), onMessageUpdated(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onUpdate')), onMessageDeleted(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onDelete')), convertEventPayload(onMessageMarkerFetched, 'contentId', 'message')(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onCreate')), convertEventPayload(onMessageMarked, 'contentId', 'message')(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onCreate')));
33143
- return () => {
33144
- log(`observeMessages(tmpid: ${timestamp}) > dispose`);
33145
- disposers.forEach(fn => fn());
33146
- };
33147
- };
33148
-
33149
32200
  var index$g = /*#__PURE__*/Object.freeze({
33150
32201
  __proto__: null,
33151
- getMessageByIds: getMessages$1,
33152
32202
  createMessage: createMessage,
33153
32203
  updateMessage: updateMessage,
33154
32204
  editMessage: editMessage,
@@ -33170,10 +32220,8 @@ var index$g = /*#__PURE__*/Object.freeze({
33170
32220
  onMessageReactionAdded: onMessageReactionAdded,
33171
32221
  onMessageReactionRemoved: onMessageReactionRemoved,
33172
32222
  onMessageFetched: onMessageFetched,
33173
- getMessage: getMessage$1,
32223
+ getMessage: getMessage,
33174
32224
  getMessages: getMessages,
33175
- observeMessage: observeMessage,
33176
- observeMessages: observeMessages,
33177
32225
  convertFromRaw: convertFromRaw$1,
33178
32226
  prepareMessagePayload: prepareMessagePayload,
33179
32227
  convertParams: convertParams,
@@ -33690,8 +32738,6 @@ var index$f = /*#__PURE__*/Object.freeze({
33690
32738
  getSubChannel: getSubChannel,
33691
32739
  getSubChannels: getSubChannels,
33692
32740
  markReadEngineOnLoginHandler: markReadEngineOnLoginHandler,
33693
- startReading: startReading,
33694
- stopReading: stopReading,
33695
32741
  startMessageReceiptSync: startMessageReceiptSync,
33696
32742
  stopMessageReceiptSync: stopMessageReceiptSync
33697
32743
  });
@@ -33742,7 +32788,7 @@ const getChannel = (channelId, callback) => {
33742
32788
  const reactor = async (response) => {
33743
32789
  if (!response.data)
33744
32790
  return callback(response);
33745
- const data = Object.assign(Object.assign({}, response), { data: LinkedObject.channel(constructChannelDynamicValue(getChannelMessagePreviewWithUser(response.data))) });
32791
+ const data = Object.assign(Object.assign({}, response), { data: constructChannelObject(response.data) });
33746
32792
  const newSnapshot = __rest(data, ["origin"]);
33747
32793
  /**
33748
32794
  * check equality of previous data and current data to avoid redundancy
@@ -33776,7 +32822,11 @@ const getChannel = (channelId, callback) => {
33776
32822
  if (message.channelId !== channelId)
33777
32823
  return;
33778
32824
  // channelId from message is channelInternalId
33779
- const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
32825
+ const channel = (_a = pullFromCache([
32826
+ 'channel',
32827
+ 'get',
32828
+ channelId,
32829
+ ])) === null || _a === void 0 ? void 0 : _a.data;
33780
32830
  if (!channel)
33781
32831
  return;
33782
32832
  updateChannelCache(channel, {
@@ -33799,7 +32849,11 @@ const getChannel = (channelId, callback) => {
33799
32849
  if (message.channelId !== channelId)
33800
32850
  return;
33801
32851
  // channelId from message is channelInternalId
33802
- const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
32852
+ const channel = (_a = pullFromCache([
32853
+ 'channel',
32854
+ 'get',
32855
+ channelId,
32856
+ ])) === null || _a === void 0 ? void 0 : _a.data;
33803
32857
  if (!channel)
33804
32858
  return;
33805
32859
  updateChannelCache(channel, {
@@ -33812,7 +32866,11 @@ const getChannel = (channelId, callback) => {
33812
32866
  convertEventPayload((callback) => {
33813
32867
  const updateMessagePreview = async (message) => {
33814
32868
  var _a;
33815
- const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
32869
+ const channel = (_a = pullFromCache([
32870
+ 'channel',
32871
+ 'get',
32872
+ channelId,
32873
+ ])) === null || _a === void 0 ? void 0 : _a.data;
33816
32874
  if (!channel || channel.messagePreviewId !== message.messageId)
33817
32875
  return;
33818
32876
  const messagePreviewSetting = await client.getMessagePreviewSetting(false);
@@ -33826,7 +32884,11 @@ const getChannel = (channelId, callback) => {
33826
32884
  convertEventPayload((callback) => {
33827
32885
  const updateMessagePreview = async (message) => {
33828
32886
  var _a;
33829
- const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
32887
+ const channel = (_a = pullFromCache([
32888
+ 'channel',
32889
+ 'get',
32890
+ channelId,
32891
+ ])) === null || _a === void 0 ? void 0 : _a.data;
33830
32892
  if (!channel || channel.messagePreviewId !== message.messageId)
33831
32893
  return;
33832
32894
  const messagePreviewSetting = await client.getMessagePreviewSetting(false);
@@ -33859,7 +32921,11 @@ const getChannel = (channelId, callback) => {
33859
32921
  if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
33860
32922
  return;
33861
32923
  await getChannel$1(channelId);
33862
- const channel = (_b = pullFromCache(['channel', 'get', channelId])) === null || _b === void 0 ? void 0 : _b.data;
32924
+ const channel = (_b = pullFromCache([
32925
+ 'channel',
32926
+ 'get',
32927
+ channelId,
32928
+ ])) === null || _b === void 0 ? void 0 : _b.data;
33863
32929
  if (!channel)
33864
32930
  return;
33865
32931
  callback(subChannel);
@@ -33881,7 +32947,11 @@ const getChannel = (channelId, callback) => {
33881
32947
  if (!messagePreviewCache ||
33882
32948
  messagePreviewCache.subChannelId !== subChannel.subChannelId)
33883
32949
  return;
33884
- const channel = (_b = pullFromCache(['channel', 'get', channelId])) === null || _b === void 0 ? void 0 : _b.data;
32950
+ const channel = (_b = pullFromCache([
32951
+ 'channel',
32952
+ 'get',
32953
+ channelId,
32954
+ ])) === null || _b === void 0 ? void 0 : _b.data;
33885
32955
  if (!channel)
33886
32956
  return;
33887
32957
  callback(subChannel);
@@ -34077,9 +33147,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
34077
33147
  .map(channelId => pullFromCache(['channel', 'get', channelId]))
34078
33148
  .filter(Boolean)
34079
33149
  .map(({ data }) => data)
34080
- .map(getChannelMessagePreviewWithUser)
34081
- .map(constructChannelDynamicValue)
34082
- .map(LinkedObject.channel)) !== null && _b !== void 0 ? _b : [];
33150
+ .map(constructChannelObject)) !== null && _b !== void 0 ? _b : [];
34083
33151
  if (this.paginationController instanceof ChannelPaginationController) {
34084
33152
  data = this.applyFilter(data);
34085
33153
  }
@@ -34726,11 +33794,6 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
34726
33794
  return false;
34727
33795
  });
34728
33796
  }
34729
- if (this.query.search) {
34730
- // eslint-disable-next-line no-console
34731
- 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.');
34732
- channelMembers = filterBySearchTerm(channelMembers, this.query.search);
34733
- }
34734
33797
  if (this.query.includeDeleted === false) {
34735
33798
  channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted) !== true; });
34736
33799
  }
@@ -34764,11 +33827,6 @@ const applyFilter$1 = (data, params) => {
34764
33827
  return params.memberships.includes(member.membership);
34765
33828
  });
34766
33829
  }
34767
- if (params.search) {
34768
- // eslint-disable-next-line no-console
34769
- 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.');
34770
- channelMembers = filterBySearchTerm(channelMembers, params.search);
34771
- }
34772
33830
  // sort, 'lastCreated' is the default sort order
34773
33831
  const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
34774
33832
  channelMembers = channelMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
@@ -35060,7 +34118,7 @@ var index$c = /*#__PURE__*/Object.freeze({
35060
34118
  __proto__: null,
35061
34119
  Membership: index$e,
35062
34120
  Moderation: index$d,
35063
- getChannelByIds: getChannelByIds,
34121
+ getChannelByIds: getChannelByIds$1,
35064
34122
  createChannel: createChannel,
35065
34123
  updateChannel: updateChannel,
35066
34124
  deleteChannel: deleteChannel,
@@ -35068,7 +34126,6 @@ var index$c = /*#__PURE__*/Object.freeze({
35068
34126
  leaveChannel: leaveChannel,
35069
34127
  muteChannel: muteChannel,
35070
34128
  unmuteChannel: unmuteChannel,
35071
- markAsRead: markAsRead,
35072
34129
  onChannelCreated: onChannelCreated,
35073
34130
  onChannelUpdated: onChannelUpdated,
35074
34131
  onChannelDeleted: onChannelDeleted,
@@ -35081,8 +34138,6 @@ var index$c = /*#__PURE__*/Object.freeze({
35081
34138
  onChannelMemberUnbanned: onChannelMemberUnbanned,
35082
34139
  onChannelMemberRoleAdded: onChannelMemberRoleAdded,
35083
34140
  onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
35084
- observeChannel: observeChannel,
35085
- observeChannels: observeChannels,
35086
34141
  getChannel: getChannel,
35087
34142
  getChannels: getChannels,
35088
34143
  MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
@@ -35393,77 +34448,6 @@ const leaveCommunity = async (communityId) => {
35393
34448
  };
35394
34449
  /* end_public_function */
35395
34450
 
35396
- /* begin_public_function
35397
- id: community.query.trending_communities
35398
- */
35399
- /**
35400
- * @deprecated This API renamed to `getTrendingCommunities()`.
35401
- * Please use getTrendingCommunities() instead.
35402
- *
35403
- * ```js
35404
- * import { CommunityRepository } from '@amityco/ts-sdk-react-native'
35405
- * const trendingCommunities = await CommunityRepository.getTrendingCommunities()
35406
- * ```
35407
- *
35408
- * Gets a list of top trending {@link Amity.Community} objects
35409
- *
35410
- * @param query The query parameters
35411
- * @returns A list of {@link Amity.Community} objects
35412
- *
35413
- * @category Community API
35414
- * @async
35415
- */
35416
- const getTopTrendingCommunities = async (query) => {
35417
- const client = getActiveClient();
35418
- client.log('channel/getTopTrendingCommunities', query);
35419
- const { limit = 5 } = query !== null && query !== void 0 ? query : {};
35420
- // API-FIX: backend doesnt answer Amity.Response
35421
- // const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
35422
- const { data: payload } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
35423
- const data = prepareCommunityPayload(payload);
35424
- const { communities } = data;
35425
- const cachedAt = client.cache && Date.now();
35426
- if (client.cache) {
35427
- ingestInCache(data, { cachedAt });
35428
- const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
35429
- pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
35430
- }
35431
- return { data: communities, cachedAt };
35432
- };
35433
- /* end_public_function */
35434
- /**
35435
- * ```js
35436
- * import { getTopTrendingCommunities } from '@amityco/ts-sdk-react-native'
35437
- * const communities = getTopTrendingCommunities.locally()
35438
- * ```
35439
- *
35440
- * Gets a list of top trending {@link Amity.Community} objects from cache
35441
- *
35442
- * @param query The query parameters
35443
- * @returns communities
35444
- *
35445
- * @category Community API
35446
- */
35447
- getTopTrendingCommunities.locally = (query) => {
35448
- var _a, _b;
35449
- const client = getActiveClient();
35450
- client.log('community/getTopTrendingCommunities.locally', query);
35451
- if (!client.cache)
35452
- return;
35453
- const { limit = 5 } = query !== null && query !== void 0 ? query : {};
35454
- const queryKey = ['community', 'top-trending', { params: { options: { limit } } }];
35455
- const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
35456
- if (!(data === null || data === void 0 ? void 0 : data.communities.length))
35457
- return;
35458
- const communities = data.communities
35459
- .map(communityId => pullFromCache(['community', 'get', communityId]))
35460
- .filter(Boolean)
35461
- .map(({ data }) => data);
35462
- return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
35463
- ? { data: communities, cachedAt }
35464
- : undefined;
35465
- };
35466
-
35467
34451
  const createCommunityEventSubscriber = (event, callback) => {
35468
34452
  const client = getActiveClient();
35469
34453
  const filter = (payload) => {
@@ -35534,7 +34518,224 @@ const onCommunityUpdated = (callback) => createCommunityEventSubscriber('communi
35534
34518
  *
35535
34519
  * @category Community Events
35536
34520
  */
35537
- const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
34521
+ const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
34522
+
34523
+ /**
34524
+ * TODO: handle cache receive cache option, and cache policy
34525
+ * TODO: check if querybyIds is supported
34526
+ */
34527
+ class CommunitiesPaginationController$1 extends PaginationController {
34528
+ async getRequest(queryParams, token) {
34529
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
34530
+ const options = token ? { token } : { limit };
34531
+ const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
34532
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
34533
+ });
34534
+ return queryResponse;
34535
+ }
34536
+ }
34537
+
34538
+ class CommunitiesQueryStreamController$1 extends QueryStreamController {
34539
+ constructor(query, cacheKey, notifyChange, preparePayload) {
34540
+ super(query, cacheKey);
34541
+ this.notifyChange = notifyChange;
34542
+ this.preparePayload = preparePayload;
34543
+ }
34544
+ async saveToMainDB(response) {
34545
+ const processedPayload = await this.preparePayload(response);
34546
+ const client = getActiveClient();
34547
+ const cachedAt = client.cache && Date.now();
34548
+ if (client.cache) {
34549
+ ingestInCache(processedPayload, { cachedAt });
34550
+ }
34551
+ }
34552
+ appendToQueryStream(response, direction, refresh = false) {
34553
+ var _a, _b;
34554
+ if (refresh) {
34555
+ pushToCache(this.cacheKey, {
34556
+ data: response.communities.map(getResolver('community')),
34557
+ });
34558
+ }
34559
+ else {
34560
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
34561
+ const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
34562
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
34563
+ }
34564
+ }
34565
+ reactor(action) {
34566
+ return (community) => {
34567
+ var _a;
34568
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
34569
+ if (!collection)
34570
+ return;
34571
+ pushToCache(this.cacheKey, collection);
34572
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
34573
+ };
34574
+ }
34575
+ subscribeRTE(createSubscriber) {
34576
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
34577
+ }
34578
+ }
34579
+
34580
+ var EnumCommunityActions$4;
34581
+ (function (EnumCommunityActions) {
34582
+ EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
34583
+ EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
34584
+ EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
34585
+ })(EnumCommunityActions$4 || (EnumCommunityActions$4 = {}));
34586
+
34587
+ var EnumCommunityMemberActions$1;
34588
+ (function (EnumCommunityMemberActions) {
34589
+ EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
34590
+ EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
34591
+ EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
34592
+ EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
34593
+ EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
34594
+ EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
34595
+ EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
34596
+ EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
34597
+ EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
34598
+ EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
34599
+ EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
34600
+ })(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
34601
+
34602
+ /* begin_public_function
34603
+ id: community.membership.add_members
34604
+ */
34605
+ /**
34606
+ * ```js
34607
+ * import { CommunityRepository } from '@amityco/ts-sdk-react-native'
34608
+ * const updated = await CommunityRepository.moderation.addMembers(communityId, ['foo', 'bar'])
34609
+ * ```
34610
+ *
34611
+ * Adds a list of {@link Amity.InternalUser} to a {@link Amity.Community} to add users to
34612
+ *
34613
+ * @param communityId The ID of the {@link Amity.Community} to perform
34614
+ * @param userIds The list of IDs {@link Amity.InternalUser} to add
34615
+ * @returns A success boolean if the {@link Amity.InternalUser} were added to the {@link Amity.Community}
34616
+ *
34617
+ * @category Community API
34618
+ * @async
34619
+ */
34620
+ const addMembers = async (communityId, userIds) => {
34621
+ const client = getActiveClient();
34622
+ client.log('community/moderation/addMembers', communityId, userIds);
34623
+ const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
34624
+ fireEvent('local.community.userAdded', payload);
34625
+ const data = prepareMembershipPayload(payload, 'communityUsers');
34626
+ if (client.cache)
34627
+ ingestInCache(data);
34628
+ const { communityUsers } = data;
34629
+ return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
34630
+ };
34631
+ /* end_public_function */
34632
+
34633
+ /* begin_public_function
34634
+ id: community.membership.remove_member
34635
+ */
34636
+ /**
34637
+ * ```js
34638
+ * import { CommunityRepository } from '@amityco/ts-sdk-react-native'
34639
+ * const updated = await CommunityRepository.moderation.removeMembers(communityId, ['foo', 'bar'])
34640
+ * ```
34641
+ *
34642
+ * Removes a list of {@link Amity.InternalUser} from a {@link Amity.Community}
34643
+ *
34644
+ * @param communityId The ID of the {@link Amity.Community} to edit
34645
+ * @param userIds The list of IDs {@link Amity.InternalUser} to remove
34646
+ * @returns A success boolean if the list of {@link Amity.InternalUser} were removed from the {@link Amity.Community}
34647
+ *
34648
+ * @category Community API
34649
+ * @async
34650
+ */
34651
+ const removeMembers = async (communityId, userIds) => {
34652
+ const client = getActiveClient();
34653
+ client.log('community/moderation/removeMembers', communityId, userIds);
34654
+ const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
34655
+ fireEvent('local.community.userRemoved', payload);
34656
+ const data = prepareMembershipPayload(payload, 'communityUsers');
34657
+ if (client.cache)
34658
+ ingestInCache(data);
34659
+ const { communityUsers } = data;
34660
+ return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
34661
+ };
34662
+ /* end_public_function */
34663
+
34664
+ /**
34665
+ * TODO: handle cache receive cache option, and cache policy
34666
+ * TODO: check if querybyIds is supported
34667
+ */
34668
+ class CommunityMembersPaginationController extends PaginationController {
34669
+ async getRequest(queryParams, token) {
34670
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
34671
+ const options = token ? { token } : { limit };
34672
+ const isDeleted = includeDeleted === false ? false : undefined;
34673
+ const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
34674
+ params: Object.assign(Object.assign({}, params), { options,
34675
+ isDeleted }),
34676
+ });
34677
+ return queryResponse;
34678
+ }
34679
+ }
34680
+
34681
+ class CommunityMembersQueryStreamController extends QueryStreamController {
34682
+ constructor(query, cacheKey, notifyChange, preparePayload) {
34683
+ super(query, cacheKey);
34684
+ this.notifyChange = notifyChange;
34685
+ this.preparePayload = preparePayload;
34686
+ }
34687
+ async saveToMainDB(response) {
34688
+ const processedPayload = await this.preparePayload(response);
34689
+ const client = getActiveClient();
34690
+ const cachedAt = client.cache && Date.now();
34691
+ if (client.cache) {
34692
+ ingestInCache(processedPayload, { cachedAt });
34693
+ }
34694
+ }
34695
+ appendToQueryStream(response, direction, refresh = false) {
34696
+ var _a, _b;
34697
+ if (refresh) {
34698
+ pushToCache(this.cacheKey, {
34699
+ data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
34700
+ });
34701
+ }
34702
+ else {
34703
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
34704
+ const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
34705
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
34706
+ ...new Set([
34707
+ ...communityUsers,
34708
+ ...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
34709
+ ]),
34710
+ ] }));
34711
+ }
34712
+ }
34713
+ reactor(action) {
34714
+ return (community, communityMembers) => {
34715
+ var _a;
34716
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
34717
+ if (!collection)
34718
+ return;
34719
+ communityMembers.forEach(communityMember => {
34720
+ const communityMemberCacheId = getResolver('communityUsers')({
34721
+ communityId: this.query.communityId,
34722
+ userId: communityMember.userId,
34723
+ });
34724
+ if (communityMember.communityMembership === 'none') {
34725
+ collection.data = collection.data.filter(m => m !== communityMemberCacheId);
34726
+ }
34727
+ else if (!collection.data.includes(communityMemberCacheId)) {
34728
+ collection.data = [communityMemberCacheId, ...collection.data];
34729
+ }
34730
+ });
34731
+ pushToCache(this.cacheKey, collection);
34732
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
34733
+ };
34734
+ }
34735
+ subscribeRTE(createSubscriber) {
34736
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
34737
+ }
34738
+ }
35538
34739
 
35539
34740
  function hasPermission(member, payload, permission) {
35540
34741
  if (member.permissions.some(x => x === permission)) {
@@ -35828,271 +35029,6 @@ const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubs
35828
35029
 
35829
35030
  const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
35830
35031
 
35831
- /**
35832
- * ```js
35833
- * import { observeCommunity } from '@amityco/ts-sdk-react-native'
35834
- *
35835
- * let community = {}
35836
- * const dispose = observeCommunity(communityId, updated => community = updated)
35837
- * ```
35838
- *
35839
- * Observe all mutation on a given {@link Amity.Community}
35840
- *
35841
- * @param communityId the ID of the community to observe
35842
- * @param callback the function to call when new data are available
35843
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community
35844
- *
35845
- * @category Community Observer
35846
- */
35847
- const observeCommunity = (communityId, callback) => {
35848
- const { log } = getActiveClient();
35849
- const timestamp = Date.now();
35850
- log(`observeCommunity(tmpid: ${timestamp}) > listen`);
35851
- // wrapper function to make sure
35852
- const router = (result, action) => {
35853
- var _a, _b;
35854
- if (callback instanceof Function)
35855
- return callback(result);
35856
- if (action !== 'onFetch')
35857
- (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
35858
- (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
35859
- };
35860
- const realtimeRouter = (result, action) => {
35861
- var _a;
35862
- if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.communityId) !== communityId)
35863
- return;
35864
- router(result, action);
35865
- };
35866
- const disposers = [];
35867
- disposers.push(onCommunityUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onCommunityDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')), onCommunityJoined(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onJoin')), onCommunityLeft(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onLeft')), onCommunityUserAdded(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUserAdded')), onCommunityUserRemoved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUserRemoved')), onCommunityUserBanned(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUserBanned')), onCommunityUserUnbanned(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUserUnbanned')));
35868
- runQuery(createQuery(getCommunity$1, communityId), result => (result.data || result.error) && router(result, 'onFetch'));
35869
- return () => {
35870
- log(`observeCommunity(tmpid: ${timestamp}) > dispose`);
35871
- disposers.forEach(fn => fn());
35872
- };
35873
- };
35874
-
35875
- /**
35876
- * TODO: handle cache receive cache option, and cache policy
35877
- * TODO: check if querybyIds is supported
35878
- */
35879
- class CommunitiesPaginationController$1 extends PaginationController {
35880
- async getRequest(queryParams, token) {
35881
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
35882
- const options = token ? { token } : { limit };
35883
- const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
35884
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
35885
- });
35886
- return queryResponse;
35887
- }
35888
- }
35889
-
35890
- class CommunitiesQueryStreamController$1 extends QueryStreamController {
35891
- constructor(query, cacheKey, notifyChange, preparePayload) {
35892
- super(query, cacheKey);
35893
- this.notifyChange = notifyChange;
35894
- this.preparePayload = preparePayload;
35895
- }
35896
- async saveToMainDB(response) {
35897
- const processedPayload = await this.preparePayload(response);
35898
- const client = getActiveClient();
35899
- const cachedAt = client.cache && Date.now();
35900
- if (client.cache) {
35901
- ingestInCache(processedPayload, { cachedAt });
35902
- }
35903
- }
35904
- appendToQueryStream(response, direction, refresh = false) {
35905
- var _a, _b;
35906
- if (refresh) {
35907
- pushToCache(this.cacheKey, {
35908
- data: response.communities.map(getResolver('community')),
35909
- });
35910
- }
35911
- else {
35912
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
35913
- const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
35914
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
35915
- }
35916
- }
35917
- reactor(action) {
35918
- return (community) => {
35919
- var _a;
35920
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
35921
- if (!collection)
35922
- return;
35923
- pushToCache(this.cacheKey, collection);
35924
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
35925
- };
35926
- }
35927
- subscribeRTE(createSubscriber) {
35928
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
35929
- }
35930
- }
35931
-
35932
- var EnumCommunityActions$4;
35933
- (function (EnumCommunityActions) {
35934
- EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
35935
- EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
35936
- EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
35937
- })(EnumCommunityActions$4 || (EnumCommunityActions$4 = {}));
35938
-
35939
- var EnumCommunityMemberActions$1;
35940
- (function (EnumCommunityMemberActions) {
35941
- EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
35942
- EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
35943
- EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
35944
- EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
35945
- EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
35946
- EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
35947
- EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
35948
- EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
35949
- EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
35950
- EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
35951
- EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
35952
- })(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
35953
-
35954
- /* begin_public_function
35955
- id: community.membership.add_members
35956
- */
35957
- /**
35958
- * ```js
35959
- * import { CommunityRepository } from '@amityco/ts-sdk-react-native'
35960
- * const updated = await CommunityRepository.moderation.addMembers(communityId, ['foo', 'bar'])
35961
- * ```
35962
- *
35963
- * Adds a list of {@link Amity.InternalUser} to a {@link Amity.Community} to add users to
35964
- *
35965
- * @param communityId The ID of the {@link Amity.Community} to perform
35966
- * @param userIds The list of IDs {@link Amity.InternalUser} to add
35967
- * @returns A success boolean if the {@link Amity.InternalUser} were added to the {@link Amity.Community}
35968
- *
35969
- * @category Community API
35970
- * @async
35971
- */
35972
- const addMembers = async (communityId, userIds) => {
35973
- const client = getActiveClient();
35974
- client.log('community/moderation/addMembers', communityId, userIds);
35975
- const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
35976
- fireEvent('local.community.userAdded', payload);
35977
- const data = prepareMembershipPayload(payload, 'communityUsers');
35978
- if (client.cache)
35979
- ingestInCache(data);
35980
- const { communityUsers } = data;
35981
- return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
35982
- };
35983
- /* end_public_function */
35984
-
35985
- /* begin_public_function
35986
- id: community.membership.remove_member
35987
- */
35988
- /**
35989
- * ```js
35990
- * import { CommunityRepository } from '@amityco/ts-sdk-react-native'
35991
- * const updated = await CommunityRepository.moderation.removeMembers(communityId, ['foo', 'bar'])
35992
- * ```
35993
- *
35994
- * Removes a list of {@link Amity.InternalUser} from a {@link Amity.Community}
35995
- *
35996
- * @param communityId The ID of the {@link Amity.Community} to edit
35997
- * @param userIds The list of IDs {@link Amity.InternalUser} to remove
35998
- * @returns A success boolean if the list of {@link Amity.InternalUser} were removed from the {@link Amity.Community}
35999
- *
36000
- * @category Community API
36001
- * @async
36002
- */
36003
- const removeMembers = async (communityId, userIds) => {
36004
- const client = getActiveClient();
36005
- client.log('community/moderation/removeMembers', communityId, userIds);
36006
- const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
36007
- fireEvent('local.community.userRemoved', payload);
36008
- const data = prepareMembershipPayload(payload, 'communityUsers');
36009
- if (client.cache)
36010
- ingestInCache(data);
36011
- const { communityUsers } = data;
36012
- return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
36013
- };
36014
- /* end_public_function */
36015
-
36016
- /**
36017
- * TODO: handle cache receive cache option, and cache policy
36018
- * TODO: check if querybyIds is supported
36019
- */
36020
- class CommunityMembersPaginationController extends PaginationController {
36021
- async getRequest(queryParams, token) {
36022
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
36023
- const options = token ? { token } : { limit };
36024
- const isDeleted = includeDeleted === false ? false : undefined;
36025
- const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
36026
- params: Object.assign(Object.assign({}, params), { options,
36027
- isDeleted }),
36028
- });
36029
- return queryResponse;
36030
- }
36031
- }
36032
-
36033
- class CommunityMembersQueryStreamController extends QueryStreamController {
36034
- constructor(query, cacheKey, notifyChange, preparePayload) {
36035
- super(query, cacheKey);
36036
- this.notifyChange = notifyChange;
36037
- this.preparePayload = preparePayload;
36038
- }
36039
- async saveToMainDB(response) {
36040
- const processedPayload = await this.preparePayload(response);
36041
- const client = getActiveClient();
36042
- const cachedAt = client.cache && Date.now();
36043
- if (client.cache) {
36044
- ingestInCache(processedPayload, { cachedAt });
36045
- }
36046
- }
36047
- appendToQueryStream(response, direction, refresh = false) {
36048
- var _a, _b;
36049
- if (refresh) {
36050
- pushToCache(this.cacheKey, {
36051
- data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
36052
- });
36053
- }
36054
- else {
36055
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
36056
- const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
36057
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
36058
- ...new Set([
36059
- ...communityUsers,
36060
- ...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
36061
- ]),
36062
- ] }));
36063
- }
36064
- }
36065
- reactor(action) {
36066
- return (community, communityMembers) => {
36067
- var _a;
36068
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
36069
- if (!collection)
36070
- return;
36071
- if (action === EnumCommunityMemberActions$1.OnCommunityUserRoleAdded &&
36072
- this.query.sortBy === 'displayName') {
36073
- return;
36074
- }
36075
- communityMembers.forEach(communityMember => {
36076
- const communityMemberCacheId = getResolver('communityUsers')({
36077
- communityId: this.query.communityId,
36078
- userId: communityMember.userId,
36079
- });
36080
- if (communityMember.communityMembership === 'none') {
36081
- collection.data = collection.data.filter(m => m !== communityMemberCacheId);
36082
- }
36083
- else if (!collection.data.includes(communityMemberCacheId)) {
36084
- collection.data = [communityMemberCacheId, ...collection.data];
36085
- }
36086
- });
36087
- pushToCache(this.cacheKey, collection);
36088
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
36089
- };
36090
- }
36091
- subscribeRTE(createSubscriber) {
36092
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
36093
- }
36094
- }
36095
-
36096
35032
  /**
36097
35033
  * ```js
36098
35034
  * import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk-react-native'
@@ -36270,9 +35206,6 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
36270
35206
  return memberships.includes(communityMembership);
36271
35207
  });
36272
35208
  }
36273
- if (this.query.search) {
36274
- communityMembers = filterBySearchTerm(communityMembers, this.query.search);
36275
- }
36276
35209
  if (this.query.includeDeleted === false) {
36277
35210
  communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
36278
35211
  }
@@ -36280,15 +35213,6 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
36280
35213
  case 'firstCreated':
36281
35214
  communityMembers = communityMembers.sort(sortByFirstCreated);
36282
35215
  break;
36283
- case 'displayName':
36284
- communityMembers = communityMembers.sort((a, b) => {
36285
- var _a, _b, _c, _d;
36286
- if (((_a = a === null || a === void 0 ? void 0 : a.user) === null || _a === void 0 ? void 0 : _a.displayName) && ((_b = b === null || b === void 0 ? void 0 : b.user) === null || _b === void 0 ? void 0 : _b.displayName)) {
36287
- return (_c = a === null || a === void 0 ? void 0 : a.user) === null || _c === void 0 ? void 0 : _c.displayName.localeCompare((_d = b === null || b === void 0 ? void 0 : b.user) === null || _d === void 0 ? void 0 : _d.displayName);
36288
- }
36289
- return 0;
36290
- });
36291
- break;
36292
35216
  case 'lastCreated':
36293
35217
  default:
36294
35218
  communityMembers = communityMembers.sort(sortByLastCreated);
@@ -36310,9 +35234,6 @@ const applyFilter = (data, params) => {
36310
35234
  return membership.includes(communityMembership);
36311
35235
  });
36312
35236
  }
36313
- if (params.search) {
36314
- communityMembers = filterBySearchTerm(communityMembers, params.search);
36315
- }
36316
35237
  const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
36317
35238
  communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
36318
35239
  return communityMembers;
@@ -36669,209 +35590,202 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
36669
35590
  if (this.query.membership && userId) {
36670
35591
  communities = filterByCommunityMembership(communities, this.query.membership, userId);
36671
35592
  }
36672
- return communities;
36673
- }
36674
- }
36675
-
36676
- /* begin_public_function
36677
- id: community.query
36678
- */
36679
- /**
36680
- * ```js
36681
- * import { CommunityRepository } from '@amityco/ts-sdk-react-native'
36682
- *
36683
- * let communities = []
36684
- * const unsub = CommunityRepository.searchCommunities({
36685
- * displayName: Amity.Community['displayName'],
36686
- * }, response => merge(communities, response.data))
36687
- * ```
36688
- *
36689
- * Observe all mutations on a list of {@link Amity.Community}s
36690
- *
36691
- * @param params for querying communities
36692
- * @param callback the function to call when new data are available
36693
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
36694
- *
36695
- * @category Community Live Collection
36696
- */
36697
- const searchCommunities = (params, callback, config) => {
36698
- const { log, cache } = getActiveClient();
36699
- if (!cache) {
36700
- console.log(ENABLE_CACHE_MESSAGE);
36701
- }
36702
- const timestamp = Date.now();
36703
- log(`searchCommunities(tmpid: ${timestamp}) > listen`);
36704
- const searchCommunitiesLiveCollection = new SearchCommunityLiveCollectionController(params, callback);
36705
- const disposers = searchCommunitiesLiveCollection.startSubscription();
36706
- const cacheKey = searchCommunitiesLiveCollection.getCacheKey();
36707
- disposers.push(() => dropFromCache(cacheKey));
36708
- return () => {
36709
- log(`searchCommunities(tmpid: ${timestamp}) > dispose`);
36710
- disposers.forEach(fn => fn());
36711
- };
36712
- };
36713
- /* end_public_function */
36714
-
36715
- /**
36716
- * TODO: handle cache receive cache option, and cache policy
36717
- * TODO: check if querybyIds is supported
36718
- */
36719
- class CommunitiesPaginationController extends PaginationController {
36720
- async getRequest(queryParams, token) {
36721
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
36722
- const options = token ? { token } : { limit };
36723
- const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
36724
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
36725
- });
36726
- return queryResponse;
36727
- }
36728
- }
36729
-
36730
- var EnumCommunityActions$3;
36731
- (function (EnumCommunityActions) {
36732
- EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
36733
- EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
36734
- EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
36735
- })(EnumCommunityActions$3 || (EnumCommunityActions$3 = {}));
36736
-
36737
- class CommunitiesQueryStreamController extends QueryStreamController {
36738
- constructor(query, cacheKey, notifyChange, preparePayload) {
36739
- super(query, cacheKey);
36740
- this.notifyChange = notifyChange;
36741
- this.preparePayload = preparePayload;
36742
- }
36743
- async saveToMainDB(response) {
36744
- const processedPayload = await this.preparePayload(response);
36745
- const client = getActiveClient();
36746
- const cachedAt = client.cache && Date.now();
36747
- if (client.cache) {
36748
- ingestInCache(processedPayload, { cachedAt });
36749
- saveCommunityUsers(response.communities, response.communityUsers);
36750
- }
36751
- }
36752
- appendToQueryStream(response, direction, refresh = false) {
36753
- var _a, _b;
36754
- if (refresh) {
36755
- pushToCache(this.cacheKey, {
36756
- data: response.communities.map(getResolver('community')),
36757
- });
36758
- }
36759
- else {
36760
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
36761
- const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
36762
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
36763
- }
36764
- }
36765
- reactor(action) {
36766
- return (community) => {
36767
- var _a;
36768
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
36769
- if (!collection)
36770
- return;
36771
- if (this.query.displayName && action === EnumCommunityActions$3.OnCommunityCreated) {
36772
- return;
36773
- }
36774
- /*
36775
- * Simply update a collection and let responder decide what to do with data
36776
- */
36777
- collection.data = [...new Set([community.communityId, ...collection.data])];
36778
- pushToCache(this.cacheKey, collection);
36779
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
36780
- };
36781
- }
36782
- subscribeRTE(createSubscriber) {
36783
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
36784
- }
36785
- }
36786
-
36787
- class CommunityLiveCollectionController extends LiveCollectionController {
36788
- constructor(query, callback) {
36789
- const queryStreamId = hash(query);
36790
- const cacheKey = ['community', 'collection', queryStreamId];
36791
- const paginationController = new CommunitiesPaginationController(query);
36792
- super(paginationController, queryStreamId, cacheKey, callback);
36793
- this.query = query;
36794
- this.queryStreamController = new CommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
36795
- this.callback = callback.bind(this);
36796
- this.loadPage({ initial: true });
36797
- }
36798
- setup() {
36799
- var _a;
36800
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
36801
- if (!collection) {
36802
- pushToCache(this.cacheKey, {
36803
- data: [],
36804
- params: {},
36805
- });
36806
- }
36807
- }
36808
- async persistModel(queryPayload) {
36809
- await this.queryStreamController.saveToMainDB(queryPayload);
36810
- }
36811
- persistQueryStream({ response, direction, refresh, }) {
36812
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
36813
- }
36814
- startSubscription() {
36815
- return this.queryStreamController.subscribeRTE([
36816
- { fn: onCommunityCreated, action: EnumCommunityActions$3.OnCommunityCreated },
36817
- { fn: onCommunityDeleted, action: EnumCommunityActions$3.OnCommunityDeleted },
36818
- { fn: onCommunityUpdated, action: EnumCommunityActions$3.OnCommunityUpdated },
36819
- { fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
36820
- { fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
36821
- { fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
36822
- { fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
36823
- { fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
36824
- ]);
36825
- }
36826
- notifyChange({ origin, loading, error }) {
36827
- var _a, _b;
36828
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
36829
- if (!collection)
36830
- return;
36831
- const data = this.applyFilter((_b = collection.data
36832
- .map(id => pullFromCache(['community', 'get', id]))
36833
- .filter(isNonNullable)
36834
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
36835
- if (!this.shouldNotify(data) && origin === 'event')
36836
- return;
36837
- this.callback({
36838
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
36839
- data,
36840
- hasNextPage: !!this.paginationController.getNextToken(),
36841
- loading,
36842
- error,
36843
- });
36844
- }
36845
- applyFilter(data) {
36846
- const { userId } = getActiveClient();
36847
- let communities = data;
36848
- if (!this.query.includeDeleted) {
36849
- communities = filterByPropEquality(communities, 'isDeleted', false);
36850
- }
36851
- if (this.query.categoryId) {
36852
- communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
36853
- }
36854
- if (this.query.tags) {
36855
- communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
36856
- }
36857
- if (this.query.membership && userId) {
36858
- communities = filterByCommunityMembership(communities, this.query.membership, userId);
36859
- }
36860
- if (!this.query.displayName) {
36861
- const sortFn = (() => {
36862
- switch (this.query.sortBy) {
36863
- case 'firstCreated':
36864
- return sortByFirstCreated;
36865
- case 'lastCreated':
36866
- return sortByLastCreated;
36867
- case 'displayName':
36868
- return sortByDisplayName;
36869
- default:
36870
- return sortByLastCreated;
36871
- }
36872
- })();
36873
- communities = communities.sort(sortFn);
35593
+ return communities;
35594
+ }
35595
+ }
35596
+
35597
+ /* begin_public_function
35598
+ id: community.query
35599
+ */
35600
+ /**
35601
+ * ```js
35602
+ * import { CommunityRepository } from '@amityco/ts-sdk-react-native'
35603
+ *
35604
+ * let communities = []
35605
+ * const unsub = CommunityRepository.searchCommunities({
35606
+ * displayName: Amity.Community['displayName'],
35607
+ * }, response => merge(communities, response.data))
35608
+ * ```
35609
+ *
35610
+ * Observe all mutations on a list of {@link Amity.Community}s
35611
+ *
35612
+ * @param params for querying communities
35613
+ * @param callback the function to call when new data are available
35614
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
35615
+ *
35616
+ * @category Community Live Collection
35617
+ */
35618
+ const searchCommunities = (params, callback, config) => {
35619
+ const { log, cache } = getActiveClient();
35620
+ if (!cache) {
35621
+ console.log(ENABLE_CACHE_MESSAGE);
35622
+ }
35623
+ const timestamp = Date.now();
35624
+ log(`searchCommunities(tmpid: ${timestamp}) > listen`);
35625
+ const searchCommunitiesLiveCollection = new SearchCommunityLiveCollectionController(params, callback);
35626
+ const disposers = searchCommunitiesLiveCollection.startSubscription();
35627
+ const cacheKey = searchCommunitiesLiveCollection.getCacheKey();
35628
+ disposers.push(() => dropFromCache(cacheKey));
35629
+ return () => {
35630
+ log(`searchCommunities(tmpid: ${timestamp}) > dispose`);
35631
+ disposers.forEach(fn => fn());
35632
+ };
35633
+ };
35634
+ /* end_public_function */
35635
+
35636
+ /**
35637
+ * TODO: handle cache receive cache option, and cache policy
35638
+ * TODO: check if querybyIds is supported
35639
+ */
35640
+ class CommunitiesPaginationController extends PaginationController {
35641
+ async getRequest(queryParams, token) {
35642
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
35643
+ const options = token ? { token } : { limit };
35644
+ const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
35645
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), filter: params.membership, options }),
35646
+ });
35647
+ return queryResponse;
35648
+ }
35649
+ }
35650
+
35651
+ class CommunitiesQueryStreamController extends QueryStreamController {
35652
+ constructor(query, cacheKey, notifyChange, preparePayload) {
35653
+ super(query, cacheKey);
35654
+ this.notifyChange = notifyChange;
35655
+ this.preparePayload = preparePayload;
35656
+ }
35657
+ async saveToMainDB(response) {
35658
+ const processedPayload = await this.preparePayload(response);
35659
+ const client = getActiveClient();
35660
+ const cachedAt = client.cache && Date.now();
35661
+ if (client.cache) {
35662
+ ingestInCache(processedPayload, { cachedAt });
35663
+ saveCommunityUsers(response.communities, response.communityUsers);
36874
35664
  }
35665
+ }
35666
+ appendToQueryStream(response, direction, refresh = false) {
35667
+ var _a, _b;
35668
+ if (refresh) {
35669
+ pushToCache(this.cacheKey, {
35670
+ data: response.communities.map(getResolver('community')),
35671
+ });
35672
+ }
35673
+ else {
35674
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
35675
+ const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
35676
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
35677
+ }
35678
+ }
35679
+ reactor(action) {
35680
+ return (community) => {
35681
+ var _a;
35682
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
35683
+ if (!collection)
35684
+ return;
35685
+ /*
35686
+ * Simply update a collection and let responder decide what to do with data
35687
+ */
35688
+ collection.data = [...new Set([community.communityId, ...collection.data])];
35689
+ pushToCache(this.cacheKey, collection);
35690
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
35691
+ };
35692
+ }
35693
+ subscribeRTE(createSubscriber) {
35694
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
35695
+ }
35696
+ }
35697
+
35698
+ var EnumCommunityActions$3;
35699
+ (function (EnumCommunityActions) {
35700
+ EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
35701
+ EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
35702
+ EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
35703
+ })(EnumCommunityActions$3 || (EnumCommunityActions$3 = {}));
35704
+
35705
+ class CommunityLiveCollectionController extends LiveCollectionController {
35706
+ constructor(query, callback) {
35707
+ const queryStreamId = hash(query);
35708
+ const cacheKey = ['community', 'collection', queryStreamId];
35709
+ const paginationController = new CommunitiesPaginationController(query);
35710
+ super(paginationController, queryStreamId, cacheKey, callback);
35711
+ this.query = query;
35712
+ this.queryStreamController = new CommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
35713
+ this.callback = callback.bind(this);
35714
+ this.loadPage({ initial: true });
35715
+ }
35716
+ setup() {
35717
+ var _a;
35718
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
35719
+ if (!collection) {
35720
+ pushToCache(this.cacheKey, {
35721
+ data: [],
35722
+ params: {},
35723
+ });
35724
+ }
35725
+ }
35726
+ async persistModel(queryPayload) {
35727
+ await this.queryStreamController.saveToMainDB(queryPayload);
35728
+ }
35729
+ persistQueryStream({ response, direction, refresh, }) {
35730
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
35731
+ }
35732
+ startSubscription() {
35733
+ return this.queryStreamController.subscribeRTE([
35734
+ { fn: onCommunityCreated, action: EnumCommunityActions$3.OnCommunityCreated },
35735
+ { fn: onCommunityDeleted, action: EnumCommunityActions$3.OnCommunityDeleted },
35736
+ { fn: onCommunityUpdated, action: EnumCommunityActions$3.OnCommunityUpdated },
35737
+ { fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
35738
+ { fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
35739
+ { fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
35740
+ { fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
35741
+ { fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
35742
+ ]);
35743
+ }
35744
+ notifyChange({ origin, loading, error }) {
35745
+ var _a, _b;
35746
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
35747
+ if (!collection)
35748
+ return;
35749
+ const data = this.applyFilter((_b = collection.data
35750
+ .map(id => pullFromCache(['community', 'get', id]))
35751
+ .filter(isNonNullable)
35752
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
35753
+ if (!this.shouldNotify(data) && origin === 'event')
35754
+ return;
35755
+ this.callback({
35756
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
35757
+ data,
35758
+ hasNextPage: !!this.paginationController.getNextToken(),
35759
+ loading,
35760
+ error,
35761
+ });
35762
+ }
35763
+ applyFilter(data) {
35764
+ const { userId } = getActiveClient();
35765
+ let communities = data;
35766
+ if (!this.query.includeDeleted) {
35767
+ communities = filterByPropEquality(communities, 'isDeleted', false);
35768
+ }
35769
+ if (this.query.categoryId) {
35770
+ communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
35771
+ }
35772
+ if (this.query.tags) {
35773
+ communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
35774
+ }
35775
+ if (this.query.membership && userId) {
35776
+ communities = filterByCommunityMembership(communities, this.query.membership, userId);
35777
+ }
35778
+ const sortFn = (() => {
35779
+ switch (this.query.sortBy) {
35780
+ case 'firstCreated':
35781
+ return sortByFirstCreated;
35782
+ case 'lastCreated':
35783
+ return sortByLastCreated;
35784
+ default:
35785
+ return sortByLastCreated;
35786
+ }
35787
+ })();
35788
+ communities = communities.sort(sortFn);
36875
35789
  return communities;
36876
35790
  }
36877
35791
  }
@@ -37625,11 +36539,9 @@ var index$9 = /*#__PURE__*/Object.freeze({
37625
36539
  deleteCommunity: deleteCommunity,
37626
36540
  joinCommunity: joinCommunity,
37627
36541
  leaveCommunity: leaveCommunity,
37628
- getTopTrendingCommunities: getTopTrendingCommunities,
37629
36542
  onCommunityCreated: onCommunityCreated,
37630
36543
  onCommunityUpdated: onCommunityUpdated,
37631
36544
  onCommunityDeleted: onCommunityDeleted,
37632
- observeCommunity: observeCommunity,
37633
36545
  searchCommunities: searchCommunities,
37634
36546
  getCommunities: getCommunities,
37635
36547
  getCommunity: getCommunity,
@@ -37879,21 +36791,10 @@ var index$8 = /*#__PURE__*/Object.freeze({
37879
36791
  const queryGlobalFeed = async (query) => {
37880
36792
  const client = getActiveClient();
37881
36793
  client.log('feed/queryGlobalFeed', query);
37882
- const _a = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page, queryToken } = _a, params = __rest(_a, ["useCustomRanking", "page", "queryToken"]);
37883
- /*
37884
- * TODO: Remove useCustomRanking key from query
37885
- */
37886
- if (useCustomRanking)
37887
- console.warn('The param "useCustomRanking" has been deprecated. To get custom ranking feed use FeedRepository.getCustomRankingGlobalFeed instead');
37888
- if (page)
37889
- console.warn('The param "page" has been deprecated. Please use "queryToken" instead.');
36794
+ const _a = query !== null && query !== void 0 ? query : {}, { queryToken } = _a, params = __rest(_a, ["queryToken"]);
37890
36795
  const options = (() => {
37891
36796
  if (queryToken)
37892
36797
  return { token: queryToken };
37893
- if (page)
37894
- return {
37895
- token: toToken(page, 'skiplimit'),
37896
- };
37897
36798
  return undefined;
37898
36799
  })();
37899
36800
  const { data: queryPayload } = await client.http.get(`/api/v4/me/global-feeds`, {
@@ -37906,20 +36807,12 @@ const queryGlobalFeed = async (query) => {
37906
36807
  const cachedAt = client.cache && Date.now();
37907
36808
  if (client.cache) {
37908
36809
  ingestInCache(Object.assign(Object.assign({}, data), { communitis: processedCommunity }));
37909
- const cacheKey = [
37910
- 'globalFeed',
37911
- 'query',
37912
- Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
37913
- ];
36810
+ const cacheKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
37914
36811
  pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
37915
36812
  }
37916
- const nextPage = toPage(paging.next);
37917
- const prevPage = toPage(paging.previous);
37918
36813
  return {
37919
36814
  data: posts.map(LinkedObject.post),
37920
36815
  cachedAt,
37921
- prevPage,
37922
- nextPage,
37923
36816
  paging,
37924
36817
  };
37925
36818
  };
@@ -37944,12 +36837,8 @@ queryGlobalFeed.locally = (query) => {
37944
36837
  client.log('post/queryGlobalFeed.locally', query);
37945
36838
  if (!client.cache)
37946
36839
  return;
37947
- const _c = query !== null && query !== void 0 ? query : {}, { page } = _c, params = __rest(_c, ["page"]);
37948
- const queryKey = [
37949
- 'globalFeed',
37950
- 'query',
37951
- Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
37952
- ];
36840
+ const params = __rest(query !== null && query !== void 0 ? query : {}, []);
36841
+ const queryKey = ['globalFeed', 'query', Object.assign({}, params)];
37953
36842
  const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
37954
36843
  if (!(data === null || data === void 0 ? void 0 : data.posts.length))
37955
36844
  return;
@@ -37959,14 +36848,10 @@ queryGlobalFeed.locally = (query) => {
37959
36848
  .map(({ data }) => data)
37960
36849
  .map(LinkedObject.post);
37961
36850
  const { paging } = data;
37962
- const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
37963
- const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
37964
36851
  return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
37965
36852
  ? {
37966
36853
  data: posts,
37967
36854
  cachedAt,
37968
- prevPage,
37969
- nextPage,
37970
36855
  paging,
37971
36856
  }
37972
36857
  : undefined;
@@ -37992,14 +36877,10 @@ queryGlobalFeed.locally = (query) => {
37992
36877
  const getCustomRankingGlobalFeed = async (query) => {
37993
36878
  const client = getActiveClient();
37994
36879
  client.log('feed/getCustomRankingGlobalFeed', query);
37995
- const _a = query !== null && query !== void 0 ? query : {}, { page, queryToken, limit } = _a, params = __rest(_a, ["page", "queryToken", "limit"]);
36880
+ const _a = query !== null && query !== void 0 ? query : {}, { queryToken, limit } = _a, params = __rest(_a, ["queryToken", "limit"]);
37996
36881
  const options = (() => {
37997
36882
  if (queryToken)
37998
36883
  return { token: queryToken };
37999
- if (page)
38000
- return {
38001
- token: toToken(page, 'skiplimit'),
38002
- };
38003
36884
  return undefined;
38004
36885
  })();
38005
36886
  const { data: queryPayload } = await client.http.get(`/api/v5/me/global-feeds`, {
@@ -38011,16 +36892,10 @@ const getCustomRankingGlobalFeed = async (query) => {
38011
36892
  const cachedAt = client.cache && Date.now();
38012
36893
  if (client.cache) {
38013
36894
  ingestInCache(data);
38014
- const cacheKey = [
38015
- 'customGlobalFeed',
38016
- 'query',
38017
- Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
38018
- ];
36895
+ const cacheKey = ['customGlobalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
38019
36896
  pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
38020
36897
  }
38021
- const nextPage = toPage(paging.next);
38022
- const prevPage = toPage(paging.previous);
38023
- return { data: posts.map(LinkedObject.post), cachedAt, prevPage, nextPage, paging };
36898
+ return { data: posts.map(LinkedObject.post), cachedAt, paging };
38024
36899
  };
38025
36900
  /* end_public_function */
38026
36901
  /**
@@ -38043,12 +36918,8 @@ getCustomRankingGlobalFeed.locally = (query) => {
38043
36918
  client.log('post/getCustomRankingGlobalFeed.locally', query);
38044
36919
  if (!client.cache)
38045
36920
  return;
38046
- const _c = query !== null && query !== void 0 ? query : {}, { page } = _c, params = __rest(_c, ["page"]);
38047
- const queryKey = [
38048
- 'customGlobalFeed',
38049
- 'query',
38050
- Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
38051
- ];
36921
+ const params = __rest(query !== null && query !== void 0 ? query : {}, []);
36922
+ const queryKey = ['customGlobalFeed', 'query', Object.assign({}, params)];
38052
36923
  const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
38053
36924
  if (!(data === null || data === void 0 ? void 0 : data.posts.length))
38054
36925
  return;
@@ -38056,11 +36927,9 @@ getCustomRankingGlobalFeed.locally = (query) => {
38056
36927
  .map(postId => pullFromCache(['post', 'get', postId]))
38057
36928
  .filter(Boolean)
38058
36929
  .map(({ data }) => data);
38059
- const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
38060
- const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
38061
36930
  const { paging } = data;
38062
36931
  return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
38063
- ? { data: posts.map(LinkedObject.post), cachedAt, prevPage, nextPage, paging }
36932
+ ? { data: posts.map(LinkedObject.post), cachedAt, paging }
38064
36933
  : undefined;
38065
36934
  };
38066
36935
 
@@ -38191,44 +37060,6 @@ const createPost = async (bundle) => {
38191
37060
  };
38192
37061
  /* end_public_function */
38193
37062
 
38194
- /* begin_public_function
38195
- id: post.edit
38196
- */
38197
- /**
38198
- * ```js
38199
- * import { updatePost } from '@amityco/ts-sdk-react-native'
38200
- * const updated = await updatePost(postId, {
38201
- * data: { text: 'hello world' }
38202
- * })
38203
- * ```
38204
- *
38205
- * Updates an {@link Amity.Post}
38206
- *
38207
- * @param postId The ID of the {@link Amity.Post} to edit
38208
- * @param patch The patch data to apply
38209
- * @returns the updated {@link Amity.Post} object
38210
- *
38211
- * @category Post API
38212
- * @async
38213
- */
38214
- const updatePost = async (postId, patch) => {
38215
- const client = getActiveClient();
38216
- client.log('user/updatePost', patch);
38217
- console.warn('Deprecation: updatePost has been renamed to editPost. Update post API will be deprecated soon.');
38218
- const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
38219
- const data = prepareMembershipPayload(payload, 'communityUsers');
38220
- const cachedAt = client.cache && Date.now();
38221
- if (client.cache)
38222
- ingestInCache(data, { cachedAt });
38223
- fireEvent('local.post.updated', payload);
38224
- const { posts } = data;
38225
- return {
38226
- data: LinkedObject.post(posts.find(post => post.postId === postId)),
38227
- cachedAt,
38228
- };
38229
- };
38230
- /* end_public_function */
38231
-
38232
37063
  /* begin_public_function
38233
37064
  id: post.edit, post.edit.custom_post
38234
37065
  */
@@ -38546,91 +37377,6 @@ const isPostFlaggedByMe = async (postId) => {
38546
37377
  };
38547
37378
  /* end_public_function */
38548
37379
 
38549
- /**
38550
- * ```js
38551
- * import { PostRepository } from '@amityco/ts-sdk-react-native'
38552
- *
38553
- * let posts = []
38554
- * const unsub = PostRepository.observePosts({
38555
- * targetType: Amity.PostTargetType,
38556
- * targetId: Amity.InternalPost['targetId'],
38557
- * }, post => merge(posts, post))
38558
- * ```
38559
- *
38560
- * Observe all mutations on a list of {@link Amity.Post} for a given target object
38561
- *
38562
- * @param params
38563
- * @param callback the function to call when new data are available
38564
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
38565
- *
38566
- * @category Post Observer
38567
- */
38568
- const observePosts = (params, callback) => {
38569
- const { log } = getActiveClient();
38570
- const timestamp = Date.now();
38571
- log(`observePosts(tmpid: ${timestamp}) > listen`);
38572
- const disposers = [];
38573
- const router = (post, action) => {
38574
- var _a, _b;
38575
- if (params.targetId !== post.targetId || params.targetType !== post.targetType)
38576
- return;
38577
- if (callback instanceof Function)
38578
- return callback(LinkedObject.post(post));
38579
- (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, LinkedObject.post(post));
38580
- (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, LinkedObject.post(post));
38581
- };
38582
- disposers.push(onPostCreated(post => router(post, 'onCreate')), onPostUpdated(post => router(post, 'onUpdate')), onPostDeleted(post => router(post, 'onDelete')), onPostApproved(post => router(post, 'onApproved')), onPostDeclined(post => router(post, 'onDeclined')), onPostFlagged(post => router(post, 'onFlagged')), onPostUnflagged(post => router(post, 'onUnflagged')), onPostReactionAdded(post => router(post, 'onReactionAdded')), onPostReactionRemoved(post => router(post, 'onReactionRemoved')));
38583
- return () => {
38584
- log(`observePosts(tmpid: ${timestamp}) > dispose`);
38585
- disposers.forEach(fn => fn());
38586
- };
38587
- };
38588
-
38589
- /**
38590
- * ```js
38591
- * import { observePost } from '@amityco/ts-sdk-react-native'
38592
- *
38593
- * let post = {}
38594
- * const dispose = observePost(postId, updated => post = updated)
38595
- * ```
38596
- *
38597
- * Observe all mutations on a given {@link Amity.Post}
38598
- *
38599
- * @param postId the ID of the post to observe
38600
- * @param callback the function to call when new data are available
38601
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
38602
- *
38603
- * @category Post Observer
38604
- */
38605
- const observePost = (postId, callback, policy = 'cache_then_server') => {
38606
- const { log } = getActiveClient();
38607
- const timestamp = Date.now();
38608
- log(`observePost(tmpid: ${timestamp}) > listen`);
38609
- // wrapper function to make sure
38610
- const router = (result, action) => {
38611
- var _a, _b;
38612
- if (callback instanceof Function)
38613
- return callback(result);
38614
- if (action !== 'onFetch')
38615
- (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
38616
- (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
38617
- };
38618
- const realtimeRouter = (result, action) => {
38619
- var _a;
38620
- if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.postId) !== postId)
38621
- return;
38622
- router(Object.assign(Object.assign({}, result), { data: result.data && LinkedObject.post(result.data) }), action);
38623
- };
38624
- const disposers = [];
38625
- disposers.push(onPostUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPostDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')), onPostApproved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onApproved')), onPostDeclined(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDeclined')), onPostFlagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onFlagged')), onPostUnflagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUnflagged')), onPostReactionAdded(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionAdded')), onPostReactionRemoved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionRemoved')));
38626
- runQuery(createQuery(getPost$2, postId), result => (result.data || result.error) &&
38627
- router(Object.assign(Object.assign({}, result), { data: result.data && LinkedObject.post(result.data) }), 'onFetch'), queryOptions(policy));
38628
- return () => {
38629
- log(`observePosts(tmpid: ${timestamp}) > dispose`);
38630
- disposers.forEach(fn => fn());
38631
- };
38632
- };
38633
-
38634
37380
  /* begin_public_function
38635
37381
  id: comment.get_by_ids
38636
37382
  */
@@ -39106,43 +37852,6 @@ const isCommentFlaggedByMe = async (commentId) => {
39106
37852
  };
39107
37853
  /* end_public_function */
39108
37854
 
39109
- /**
39110
- * ```js
39111
- * import { observeComments } from '@amityco/ts-sdk-react-native'
39112
- *
39113
- * let comments = []
39114
- * const unsub = observeComments(postId, comment => merge(comments, comment))
39115
- * ```
39116
- *
39117
- * Observe all mutations on a list of {@link Amity.InternalComment} for a given {@link Amity.Post} object
39118
- *
39119
- * @param postId the ID of the post where to observe the comments
39120
- * @param callback the function to call when new data are available
39121
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comments
39122
- *
39123
- * @category InternalComment Observer
39124
- */
39125
- const observeComments = (postId, callback) => {
39126
- const { log } = getActiveClient();
39127
- const timestamp = Date.now();
39128
- log(`observeComments(tmpid: ${timestamp}) > listen`);
39129
- const disposers = [];
39130
- const router = (comment, action) => {
39131
- var _a, _b;
39132
- if (comment.referenceId !== postId)
39133
- return;
39134
- if (callback instanceof Function)
39135
- return callback(comment);
39136
- (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, comment);
39137
- (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, comment);
39138
- };
39139
- disposers.push(onCommentCreated(comment => router(comment, 'onCreate')), onCommentUpdated(comment => router(comment, 'onUpdate')), onCommentDeleted(comment => router(comment, 'onDelete')), onCommentFlagged(comment => router(comment, 'onFlagged')), onCommentUnflagged(comment => router(comment, 'onUnflagged')), onCommentReactionAdded(comment => router(comment, 'onReactionAdded')), onCommentReactionRemoved(comment => router(comment, 'onReactionRemoved')));
39140
- return () => {
39141
- log(`observeComments(tmpid: ${timestamp}) > dispose`);
39142
- disposers.forEach(fn => fn());
39143
- };
39144
- };
39145
-
39146
37855
  const getComment$1 = async (commentId) => {
39147
37856
  const client = getActiveClient();
39148
37857
  client.log('comment/getComment', commentId);
@@ -39182,50 +37891,6 @@ getComment$1.locally = (commentId) => {
39182
37891
  };
39183
37892
  };
39184
37893
 
39185
- /**
39186
- * ```js
39187
- * import { observeComment } from '@amityco/ts-sdk-react-native'
39188
- *
39189
- * let comment = {}
39190
- * const dispose = observeComment(commentId, ({ data }) => comment = data)
39191
- * ```
39192
- *
39193
- * Observe all mutation on a given {@link Amity.InternalComment}
39194
- *
39195
- * @param commentId the ID of the comment to observe
39196
- * @param callback the function to call when new data are available
39197
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
39198
- *
39199
- * @category InternalComment Observer
39200
- */
39201
- const observeComment = (commentId, callback, policy = 'cache_then_server') => {
39202
- const { log } = getActiveClient();
39203
- const timestamp = Date.now();
39204
- log(`observeComment(tmpid: ${timestamp}) > listen`);
39205
- // wrapper function to make sure
39206
- const router = (result, action) => {
39207
- var _a, _b;
39208
- if (callback instanceof Function)
39209
- return callback(result);
39210
- if (action !== 'onFetch')
39211
- (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
39212
- (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
39213
- };
39214
- const realtimeRouter = (result, action) => {
39215
- var _a;
39216
- if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.commentId) !== commentId)
39217
- return;
39218
- router(result, action);
39219
- };
39220
- const disposers = [];
39221
- disposers.push(onCommentUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onCommentDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')), onCommentFlagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onFlagged')), onCommentUnflagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUnflagged')), onCommentReactionAdded(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionAdded')), onCommentReactionRemoved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionRemoved')));
39222
- runQuery(createQuery(getComment$1, commentId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
39223
- return () => {
39224
- log(`observeComment(tmpid: ${timestamp}) > dispose`);
39225
- disposers.forEach(fn => fn());
39226
- };
39227
- };
39228
-
39229
37894
  /**
39230
37895
  * ```js
39231
37896
  * import { onCommentDeleteLocal } from '@amityco/ts-sdk-react-native'
@@ -39601,8 +38266,6 @@ var index$6 = /*#__PURE__*/Object.freeze({
39601
38266
  onCommentUnflagged: onCommentUnflagged,
39602
38267
  onCommentReactionAdded: onCommentReactionAdded,
39603
38268
  onCommentReactionRemoved: onCommentReactionRemoved,
39604
- observeComments: observeComments,
39605
- observeComment: observeComment,
39606
38269
  getComment: getComment,
39607
38270
  getComments: getComments
39608
38271
  });
@@ -40596,7 +39259,6 @@ var index$5 = /*#__PURE__*/Object.freeze({
40596
39259
  __proto__: null,
40597
39260
  getPostByIds: getPostByIds,
40598
39261
  createPost: createPost,
40599
- updatePost: updatePost,
40600
39262
  editPost: editPost,
40601
39263
  deletePost: deletePost,
40602
39264
  softDeletePost: softDeletePost,
@@ -40615,8 +39277,6 @@ var index$5 = /*#__PURE__*/Object.freeze({
40615
39277
  onPostUnflagged: onPostUnflagged,
40616
39278
  onPostReactionAdded: onPostReactionAdded,
40617
39279
  onPostReactionRemoved: onPostReactionRemoved,
40618
- observePosts: observePosts,
40619
- observePost: observePost,
40620
39280
  getPost: getPost$1,
40621
39281
  getPosts: getPosts,
40622
39282
  getPinnedPosts: getPinnedPosts,
@@ -40809,47 +39469,6 @@ const disposeStream = async (streamId) => {
40809
39469
  };
40810
39470
  /* end_public_function */
40811
39471
 
40812
- /* begin_public_function
40813
- id: stream.query
40814
- */
40815
- /**
40816
- * @deprecated This API renamed to `getStreams`.
40817
- * Please use getStreams() instead.
40818
- * ```js
40819
- * import { getStreams } from '@amityco/ts-sdk-react-native'
40820
- * const streams = await getStreams()
40821
- * ```
40822
- *
40823
- * Queries a paginable list of {@link Amity.InternalStream} objects
40824
- *
40825
- * @param query The query parameters
40826
- * @returns A page of {@link Amity.InternalStream} objects
40827
- *
40828
- * @category Stream API
40829
- * @async
40830
- */
40831
- const queryStreams$1 = async (query) => {
40832
- const client = getActiveClient();
40833
- client.log('stream/queryStreams', query);
40834
- const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
40835
- const { data } = await client.http.get(`/api/v3/video-streaming`, {
40836
- params: Object.assign(Object.assign({}, params), { options: {
40837
- token: toToken(page, 'skiplimit'),
40838
- } }),
40839
- });
40840
- // API-FIX: backend to response Amity.Response: const { paging, videoStreamings } = unwrapPayload(data)
40841
- // API-FIX: seems returned data has a results identifier on top of data, like no other apis, and this is beautiful
40842
- const { paging, results: payload } = data;
40843
- const { videoStreamings } = payload;
40844
- const cachedAt = client.cache && Date.now();
40845
- if (client.cache)
40846
- ingestInCache(payload, { cachedAt });
40847
- const nextPage = toPage(paging.next);
40848
- const prevPage = toPage(paging.previous);
40849
- return { data: videoStreamings, cachedAt, prevPage, nextPage };
40850
- };
40851
- /* end_public_function */
40852
-
40853
39472
  /**
40854
39473
  * ```js
40855
39474
  * import { onStreamStarted } from '@amityco/ts-sdk-react-native'
@@ -40871,7 +39490,7 @@ const onStreamStarted = (callback) => {
40871
39490
  ingestInCache(payload);
40872
39491
  callback(payload.videoStreamings[0]);
40873
39492
  };
40874
- return createEventSubscriber(client, 'stream/onStreamStarted', 'v3.video-streaming.didStart', filter);
39493
+ return createEventSubscriber(client, 'stream/onStreamStarted', 'video-streaming.didStart', filter);
40875
39494
  };
40876
39495
 
40877
39496
  /**
@@ -40895,7 +39514,7 @@ const onStreamStopped = (callback) => {
40895
39514
  ingestInCache(payload);
40896
39515
  callback(payload.videoStreamings[0]);
40897
39516
  };
40898
- return createEventSubscriber(client, 'stream/onStreamStropped', 'v3.video-streaming.didStop', filter);
39517
+ return createEventSubscriber(client, 'stream/onStreamStropped', 'video-streaming.didStop', filter);
40899
39518
  };
40900
39519
 
40901
39520
  /**
@@ -40919,7 +39538,7 @@ const onStreamRecorded = (callback) => {
40919
39538
  ingestInCache(payload);
40920
39539
  callback(payload.videoStreamings[0]);
40921
39540
  };
40922
- return createEventSubscriber(client, 'stream/onStreamRecorded', 'v3.video-streaming.didRecord', filter);
39541
+ return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
40923
39542
  };
40924
39543
 
40925
39544
  /**
@@ -40943,7 +39562,7 @@ const onStreamFlagged = (callback) => {
40943
39562
  ingestInCache(payload);
40944
39563
  callback(payload.videoStreamings[0]);
40945
39564
  };
40946
- return createEventSubscriber(client, 'stream/onStreamFlagged', 'v3.video-streaming.didFlag', filter);
39565
+ return createEventSubscriber(client, 'stream/onStreamFlagged', 'video-streaming.didFlag', filter);
40947
39566
  };
40948
39567
 
40949
39568
  /**
@@ -40967,7 +39586,7 @@ const onStreamTerminated = (callback) => {
40967
39586
  ingestInCache(payload);
40968
39587
  callback(payload.videoStreamings[0]);
40969
39588
  };
40970
- return createEventSubscriber(client, 'stream/onStreamTerminated', 'v3.video-streaming.didTerminate', filter);
39589
+ return createEventSubscriber(client, 'stream/onStreamTerminated', 'video-streaming.didTerminate', filter);
40971
39590
  };
40972
39591
 
40973
39592
  /* eslint-disable no-use-before-define */
@@ -41171,8 +39790,6 @@ var index$4 = /*#__PURE__*/Object.freeze({
41171
39790
  updateStream: updateStream,
41172
39791
  deleteStream: deleteStream,
41173
39792
  disposeStream: disposeStream,
41174
- queryStreams: queryStreams$1,
41175
- getStream: getStream,
41176
39793
  onStreamStarted: onStreamStarted,
41177
39794
  onStreamStopped: onStreamStopped,
41178
39795
  onStreamRecorded: onStreamRecorded,
@@ -41427,50 +40044,6 @@ const onPollDeleted = (callback) => {
41427
40044
  return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
41428
40045
  };
41429
40046
 
41430
- /**
41431
- * ```js
41432
- * import { observePoll } from '@amityco/ts-sdk-react-native'
41433
- *
41434
- * let poll = {}
41435
- * const dispose = observePoll(pollId, updated => poll = updated)
41436
- * ```
41437
- *
41438
- * Observe all mutation on a given {@link Amity.Poll}
41439
- *
41440
- * @param pollId the ID of the poll to observe
41441
- * @param callback the function to call when new data are available
41442
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
41443
- *
41444
- * @category Poll Observer
41445
- */
41446
- const observePoll = (pollId, callback, policy = 'cache_then_server') => {
41447
- const { log } = getActiveClient();
41448
- const timestamp = Date.now();
41449
- log(`observePoll(tmpid: ${timestamp}) > listen`);
41450
- // wrapper function to make sure
41451
- const router = (result, action) => {
41452
- var _a, _b;
41453
- if (callback instanceof Function)
41454
- return callback(result);
41455
- if (action !== 'onFetch')
41456
- (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
41457
- (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
41458
- };
41459
- const realtimeRouter = (result, action) => {
41460
- var _a;
41461
- if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.pollId) !== pollId)
41462
- return;
41463
- router(result, action);
41464
- };
41465
- const disposers = [];
41466
- disposers.push(onPollUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPollDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')));
41467
- runQuery(createQuery(getPoll$1, pollId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
41468
- return () => {
41469
- log(`observePoll(tmpid: ${timestamp}) > dispose`);
41470
- disposers.forEach(fn => fn());
41471
- };
41472
- };
41473
-
41474
40047
  /* begin_public_function
41475
40048
  id: poll.get
41476
40049
  */
@@ -41506,7 +40079,6 @@ var index$3 = /*#__PURE__*/Object.freeze({
41506
40079
  votePoll: votePoll,
41507
40080
  onPollUpdated: onPollUpdated,
41508
40081
  onPollDeleted: onPollDeleted,
41509
- observePoll: observePoll,
41510
40082
  getPoll: getPoll
41511
40083
  });
41512
40084
 
@@ -41963,7 +40535,7 @@ const createOptimisticTarget = async ({ targetId, targetType, }) => {
41963
40535
  optimisticTarget = Object.assign(Object.assign({}, optimisticTarget), { targetPublicId: community.data.communityId, targetUpdatedAt: (_a = community.data.updatedAt) !== null && _a !== void 0 ? _a : new Date().toISOString() });
41964
40536
  }
41965
40537
  if (targetType === 'user') {
41966
- const user = await getUser$2(targetId);
40538
+ const user = await getUser$1(targetId);
41967
40539
  optimisticTarget = Object.assign(Object.assign({}, optimisticTarget), { targetPublicId: user.data.userPublicId, targetUpdatedAt: (_b = user.data.updatedAt) !== null && _b !== void 0 ? _b : new Date().toISOString() });
41968
40540
  }
41969
40541
  pushToCache(["storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */, 'get', targetId], optimisticTarget);
@@ -43106,4 +41678,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
43106
41678
  return { accessToken: data.accessToken };
43107
41679
  };
43108
41680
 
43109
- export { API_REGIONS, index as AdRepository, index$8 as CategoryRepository, index$c as ChannelRepository, index$l as Client, index$6 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$9 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$7 as FeedRepository, FileAccessTypeEnum, index$i as FileRepository, FileType, index$2 as LiveStreamPlayer, MessageContentType, index$g as MessageRepository, index$3 as PollRepository, PostContentType, index$5 as PostRepository, index$h as ReactionRepository, index$1 as StoryRepository, index$4 as StreamRepository, index$f as SubChannelRepository, SubscriptionLevels, index$j as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
41681
+ export { API_REGIONS, index as AdRepository, index$8 as CategoryRepository, index$c as ChannelRepository, index$l as Client, index$6 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$9 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$7 as FeedRepository, FileAccessTypeEnum, index$i as FileRepository, FileType, index$2 as LiveStreamPlayer, MessageContentType, index$g as MessageRepository, index$3 as PollRepository, PostContentType, index$5 as PostRepository, index$h as ReactionRepository, index$1 as StoryRepository, index$4 as StreamRepository, index$f as SubChannelRepository, SubscriptionLevels, index$j as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };