@amityco/ts-sdk-react-native 6.29.3-669217e.0 → 6.29.3-fe4e045.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.
- package/dist/@types/core/events.d.ts +41 -11
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +4 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +32 -7
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/permissions.d.ts +4 -4
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +8 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +5 -4
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +32 -8
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/follow.d.ts +21 -3
- package/dist/@types/domains/follow.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +13 -7
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/@types/domains/pin.d.ts +22 -0
- package/dist/@types/domains/pin.d.ts.map +1 -0
- package/dist/@types/domains/pinnedPost.d.ts +28 -0
- package/dist/@types/domains/pinnedPost.d.ts.map +1 -0
- package/dist/@types/domains/poll.d.ts +3 -1
- package/dist/@types/domains/poll.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +8 -5
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/stream.d.ts +2 -1
- package/dist/@types/domains/stream.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +34 -6
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberPaginationController.d.ts +3 -2
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberPaginationController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts +14 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts.map +1 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberPaginationController.d.ts +14 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberPaginationController.d.ts.map +1 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts +14 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts.map +1 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/index.d.ts +2 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/index.d.ts.map +1 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/searchMembers.d.ts +21 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/searchMembers.d.ts.map +1 -0
- package/dist/channelRepository/events/onUserDeleted.d.ts +2 -0
- package/dist/channelRepository/events/onUserDeleted.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannels/ChannelPaginationController.d.ts +3 -3
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/channelRepository/utils/tests/prepareChannelPayload.test.d.ts +1 -1
- package/dist/channelRepository/utils/tests/prepareChannelPayload.test.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +0 -2
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/commentRepository/api/createComment.d.ts.map +1 -1
- package/dist/commentRepository/api/deleteComment.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentCreatedLocal.d.ts +17 -0
- package/dist/commentRepository/events/onCommentCreatedLocal.d.ts.map +1 -0
- package/dist/commentRepository/events/onCommentDeletedLocal.d.ts +17 -0
- package/dist/commentRepository/events/onCommentDeletedLocal.d.ts.map +1 -0
- package/dist/commentRepository/events/onLocalCommentReactionAdded.d.ts +17 -0
- package/dist/commentRepository/events/onLocalCommentReactionAdded.d.ts.map +1 -0
- package/dist/commentRepository/events/onLocalCommentReactionRemoved.d.ts +17 -0
- package/dist/commentRepository/events/onLocalCommentReactionRemoved.d.ts.map +1 -0
- package/dist/commentRepository/events/utils.d.ts +1 -0
- package/dist/commentRepository/events/utils.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComment.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComments/CommentLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/index.d.ts +2 -0
- package/dist/communityRepository/communityMembership/events/index.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts +17 -0
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts +17 -0
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts +17 -0
- package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/events/utils.d.ts +1 -0
- package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts +4 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/api/addRoles.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/api/removeRoles.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts +17 -0
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts.map +1 -0
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts +17 -0
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts.map +1 -0
- package/dist/communityRepository/utils/payload.d.ts +3 -6
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/group/utils/withUser.d.ts +13 -0
- package/dist/group/utils/withUser.d.ts.map +1 -1
- package/dist/index.cjs.js +2241 -1227
- package/dist/index.esm.js +2421 -1407
- package/dist/index.umd.js +3 -3
- package/dist/pollRepository/observers/observePoll.d.ts +1 -1
- package/dist/pollRepository/observers/observePoll.d.ts.map +1 -1
- package/dist/postRepository/events/onLocalPostDeleted.d.ts +17 -0
- package/dist/postRepository/events/onLocalPostDeleted.d.ts.map +1 -0
- package/dist/postRepository/events/onLocalPostReactionAdded.d.ts +17 -0
- package/dist/postRepository/events/onLocalPostReactionAdded.d.ts.map +1 -0
- package/dist/postRepository/events/onLocalPostReactionRemoved.d.ts +17 -0
- package/dist/postRepository/events/onLocalPostReactionRemoved.d.ts.map +1 -0
- package/dist/postRepository/events/onPostUpdatedLocal.d.ts +17 -0
- package/dist/postRepository/events/onPostUpdatedLocal.d.ts.map +1 -0
- package/dist/postRepository/events/utils.d.ts +1 -0
- package/dist/postRepository/events/utils.d.ts.map +1 -1
- package/dist/postRepository/internalApi/index.d.ts +1 -12
- package/dist/postRepository/internalApi/index.d.ts.map +1 -1
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts +14 -0
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostPaginationController.d.ts +13 -0
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostPaginationController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts +9 -0
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPinnedPosts.d.ts +12 -0
- package/dist/postRepository/observers/getPinnedPosts.d.ts.map +1 -0
- package/dist/postRepository/observers/getPost.d.ts.map +1 -1
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
- package/dist/postRepository/observers/index.d.ts +1 -0
- package/dist/postRepository/observers/index.d.ts.map +1 -1
- package/dist/postRepository/utils/payload.d.ts.map +1 -1
- package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
- package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
- package/dist/report/api/createReport.d.ts +1 -2
- package/dist/report/api/createReport.d.ts.map +1 -1
- package/dist/report/api/deleteReport.d.ts +1 -2
- package/dist/report/api/deleteReport.d.ts.map +1 -1
- package/dist/report/api/isReportedByMe.d.ts +1 -2
- package/dist/report/api/isReportedByMe.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts +1 -1
- package/dist/userRepository/api/flagUser.d.ts.map +1 -1
- package/dist/userRepository/api/getUser.d.ts.map +1 -1
- package/dist/userRepository/api/getUserByIds.d.ts.map +1 -1
- package/dist/userRepository/api/queryBlockedUsers.d.ts.map +1 -1
- package/dist/userRepository/api/queryUsers.d.ts.map +1 -1
- package/dist/userRepository/api/unflagUser.d.ts.map +1 -1
- package/dist/userRepository/api/updateUser.d.ts.map +1 -1
- package/dist/userRepository/events/utils.d.ts.map +1 -1
- package/dist/userRepository/internalApi/getUser.d.ts.map +1 -1
- package/dist/userRepository/internalApi/queryUsers.d.ts.map +1 -1
- package/dist/userRepository/observers/enums.d.ts +8 -0
- package/dist/userRepository/observers/enums.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts +14 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserPaginationController.d.ts +5 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserPaginationController.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts +15 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockedUsers.d.ts.map +1 -1
- package/dist/userRepository/observers/getUsers/UserLiveCollectionController.d.ts +14 -0
- package/dist/userRepository/observers/getUsers/UserLiveCollectionController.d.ts.map +1 -0
- package/dist/userRepository/observers/getUsers/UserPaginationController.d.ts +5 -0
- package/dist/userRepository/observers/getUsers/UserPaginationController.d.ts.map +1 -0
- package/dist/userRepository/observers/getUsers/UserQueryStreamController.d.ts +15 -0
- package/dist/userRepository/observers/getUsers/UserQueryStreamController.d.ts.map +1 -0
- package/dist/userRepository/observers/getUsers.d.ts +0 -1
- package/dist/userRepository/observers/getUsers.d.ts.map +1 -1
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.d.ts +14 -0
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.d.ts.map +1 -0
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserPaginationController.d.ts +5 -0
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserPaginationController.d.ts.map +1 -0
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserQueryStreamController.d.ts +15 -0
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserQueryStreamController.d.ts.map +1 -0
- package/dist/userRepository/observers/searchUserByDisplayName.d.ts.map +1 -1
- package/dist/userRepository/relationship/block/api/blockUser.d.ts.map +1 -1
- package/dist/userRepository/relationship/block/api/unBlockUser.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/acceptFollower.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/acceptMyFollower.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/declineFollower.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/declineMyFollower.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/follow.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/unfollow.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/utils.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/enums.d.ts +11 -0
- package/dist/userRepository/relationship/follow/enums.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/index.d.ts +5 -0
- package/dist/userRepository/relationship/follow/events/index.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/events/onFollowInfoUpdated.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/events/onFollowerUserDeleted.d.ts +4 -0
- package/dist/userRepository/relationship/follow/events/onFollowerUserDeleted.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/onFollowingUserDeleted.d.ts +4 -0
- package/dist/userRepository/relationship/follow/events/onFollowingUserDeleted.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/onLocalFollowRequestAccepted.d.ts +2 -0
- package/dist/userRepository/relationship/follow/events/onLocalFollowRequestAccepted.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/onLocalFollowRequestDeclined.d.ts +2 -0
- package/dist/userRepository/relationship/follow/events/onLocalFollowRequestDeclined.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/onLocalFollowerRequested.d.ts +2 -0
- package/dist/userRepository/relationship/follow/events/onLocalFollowerRequested.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/onLocalUserFollowed.d.ts +2 -0
- package/dist/userRepository/relationship/follow/events/onLocalUserFollowed.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/onLocalUserUnfollowed.d.ts +2 -0
- package/dist/userRepository/relationship/follow/events/onLocalUserUnfollowed.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/events/utils.d.ts +2 -1
- package/dist/userRepository/relationship/follow/events/utils.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.d.ts +14 -0
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerPaginationController.d.ts +5 -0
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerPaginationController.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerQueryStreamController.d.ts +15 -0
- package/dist/userRepository/relationship/follow/observers/getFollowers/FollowerQueryStreamController.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/observers/getFollowers.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.d.ts +14 -0
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingPaginationController.d.ts +5 -0
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingPaginationController.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingQueryStreamController.d.ts +15 -0
- package/dist/userRepository/relationship/follow/observers/getFollowings/FollowingQueryStreamController.d.ts.map +1 -0
- package/dist/userRepository/relationship/follow/observers/getFollowings.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts +1 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts +1 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/utils.d.ts +4 -0
- package/dist/userRepository/relationship/follow/utils.d.ts.map +1 -0
- package/dist/userRepository/utils/convertRawUserToInternalUser.d.ts +2 -0
- package/dist/userRepository/utils/convertRawUserToInternalUser.d.ts.map +1 -0
- package/dist/userRepository/utils/prepareBlockedUserPayload.d.ts +2 -0
- package/dist/userRepository/utils/prepareBlockedUserPayload.d.ts.map +1 -0
- package/dist/userRepository/utils/prepareUserPayload.d.ts +2 -0
- package/dist/userRepository/utils/prepareUserPayload.d.ts.map +1 -0
- package/dist/utils/linkedObject/commentLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +2 -1
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/pinnedPostLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/pinnedPostLinkedObject.d.ts.map +1 -0
- package/dist/utils/tests/dummy/block.d.ts +2 -2
- package/dist/utils/tests/dummy/channel.d.ts +12 -12
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/dist/utils/tests/dummy/community.d.ts +2 -2
- package/dist/utils/tests/dummy/follow.d.ts +2 -2
- package/dist/utils/tests/dummy/user.d.ts +10 -2
- package/dist/utils/tests/dummy/user.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +40 -13
- package/src/@types/core/model.ts +6 -0
- package/src/@types/core/payload.ts +39 -9
- package/src/@types/core/permissions.ts +4 -4
- package/src/@types/domains/channel.ts +13 -0
- package/src/@types/domains/comment.ts +6 -4
- package/src/@types/domains/community.ts +40 -12
- package/src/@types/domains/follow.ts +26 -12
- package/src/@types/domains/group.ts +14 -6
- package/src/@types/domains/pin.ts +27 -0
- package/src/@types/domains/pinnedPost.ts +35 -0
- package/src/@types/domains/poll.ts +5 -1
- package/src/@types/domains/post.ts +9 -5
- package/src/@types/domains/stream.ts +3 -1
- package/src/@types/domains/user.ts +49 -6
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +6 -0
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberPaginationController.ts +4 -1
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.ts +148 -0
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberPaginationController.ts +31 -0
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.ts +112 -0
- package/src/channelRepository/channelMembership/observers/searchMembers/index.ts +1 -0
- package/src/channelRepository/channelMembership/observers/searchMembers/searchMembers.ts +111 -0
- package/src/channelRepository/events/onUserDeleted.ts +46 -0
- package/src/channelRepository/utils/prepareChannelPayload.ts +8 -4
- package/src/client/api/index.ts +0 -3
- package/src/commentRepository/api/createComment.ts +16 -12
- package/src/commentRepository/api/deleteComment.ts +23 -13
- package/src/commentRepository/events/onCommentCreatedLocal.ts +22 -0
- package/src/commentRepository/events/onCommentDeletedLocal.ts +20 -0
- package/src/commentRepository/events/onLocalCommentReactionAdded.ts +42 -0
- package/src/commentRepository/events/onLocalCommentReactionRemoved.ts +42 -0
- package/src/commentRepository/events/utils.ts +77 -0
- package/src/commentRepository/observers/getComment.ts +6 -19
- package/src/commentRepository/observers/getComments/CommentLiveCollectionController.ts +8 -0
- package/src/communityRepository/communityMembership/api/addMembers.ts +1 -1
- package/src/communityRepository/communityMembership/api/removeMembers.ts +1 -1
- package/src/communityRepository/communityMembership/events/index.ts +2 -0
- package/src/communityRepository/communityMembership/events/onLocalCommunityUserAdded.ts +20 -0
- package/src/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.ts +20 -0
- package/src/communityRepository/communityMembership/events/onUserDeleted.ts +64 -0
- package/src/communityRepository/communityMembership/events/utils.ts +50 -2
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +26 -1
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.ts +4 -1
- package/src/communityRepository/communityMembership/observers/getMembers/enums.ts +3 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +14 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +4 -1
- package/src/communityRepository/communityModeration/api/addRoles.ts +5 -2
- package/src/communityRepository/communityModeration/api/removeRoles.ts +5 -2
- package/src/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.ts +38 -0
- package/src/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.ts +38 -0
- package/src/communityRepository/utils/payload.ts +47 -53
- package/src/core/model/idResolvers.ts +3 -0
- package/src/core/model/index.ts +3 -0
- package/src/group/utils/withUser.ts +33 -0
- package/src/postRepository/api/deletePost.ts +9 -9
- package/src/postRepository/api/updatePost.ts +1 -1
- package/src/postRepository/events/onLocalPostDeleted.ts +20 -0
- package/src/postRepository/events/onLocalPostReactionAdded.ts +38 -0
- package/src/postRepository/events/onLocalPostReactionRemoved.ts +41 -0
- package/src/postRepository/events/onPostUpdatedLocal.ts +20 -0
- package/src/postRepository/events/utils.ts +41 -6
- package/src/postRepository/internalApi/index.ts +1 -16
- package/src/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.ts +104 -0
- package/src/postRepository/observers/getPinnedPosts/PinnedPostPaginationController.ts +23 -0
- package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +61 -0
- package/src/postRepository/observers/getPinnedPosts.ts +41 -0
- package/src/postRepository/observers/getPost.ts +8 -0
- package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +8 -0
- package/src/postRepository/observers/index.ts +1 -0
- package/src/postRepository/utils/payload.ts +31 -7
- package/src/reactionRepository/api/addReaction.ts +27 -2
- package/src/reactionRepository/api/removeReaction.ts +27 -2
- package/src/report/api/createReport.ts +100 -31
- package/src/report/api/deleteReport.ts +100 -31
- package/src/report/api/isReportedByMe.ts +72 -11
- package/src/userRepository/api/flagUser.ts +5 -2
- package/src/userRepository/api/getUser.ts +4 -43
- package/src/userRepository/api/getUserByIds.ts +5 -2
- package/src/userRepository/api/queryBlockedUsers.ts +6 -6
- package/src/userRepository/api/queryUsers.ts +11 -87
- package/src/userRepository/api/unflagUser.ts +5 -2
- package/src/userRepository/api/updateUser.ts +5 -11
- package/src/userRepository/events/utils.ts +4 -1
- package/src/userRepository/internalApi/getUser.ts +12 -16
- package/src/userRepository/internalApi/queryUsers.ts +7 -4
- package/src/userRepository/observers/enums.ts +7 -0
- package/src/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.ts +106 -0
- package/src/userRepository/observers/getBlockedUsers/BlockedUserPaginationController.ts +24 -0
- package/src/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.ts +76 -0
- package/src/userRepository/observers/getBlockedUsers.ts +8 -81
- package/src/userRepository/observers/getUsers/UserLiveCollectionController.ts +131 -0
- package/src/userRepository/observers/getUsers/UserPaginationController.ts +25 -0
- package/src/userRepository/observers/getUsers/UserQueryStreamController.ts +82 -0
- package/src/userRepository/observers/getUsers.ts +7 -137
- package/src/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.ts +116 -0
- package/src/userRepository/observers/searchUserByDisplayName/SearchUserPaginationController.ts +25 -0
- package/src/userRepository/observers/searchUserByDisplayName/SearchUserQueryStreamController.ts +82 -0
- package/src/userRepository/observers/searchUserByDisplayName.ts +25 -1
- package/src/userRepository/relationship/block/api/blockUser.ts +4 -1
- package/src/userRepository/relationship/block/api/unBlockUser.ts +4 -1
- package/src/userRepository/relationship/follow/api/acceptFollower.ts +4 -1
- package/src/userRepository/relationship/follow/api/acceptMyFollower.ts +4 -1
- package/src/userRepository/relationship/follow/api/declineFollower.ts +5 -2
- package/src/userRepository/relationship/follow/api/declineMyFollower.ts +5 -2
- package/src/userRepository/relationship/follow/api/follow.ts +8 -1
- package/src/userRepository/relationship/follow/api/unfollow.ts +4 -1
- package/src/userRepository/relationship/follow/api/utils.ts +6 -2
- package/src/userRepository/relationship/follow/enums.ts +10 -0
- package/src/userRepository/relationship/follow/events/index.ts +6 -0
- package/src/userRepository/relationship/follow/events/onFollowInfoUpdated.ts +6 -1
- package/src/userRepository/relationship/follow/events/onFollowerUserDeleted.ts +33 -0
- package/src/userRepository/relationship/follow/events/onFollowingUserDeleted.ts +33 -0
- package/src/userRepository/relationship/follow/events/onLocalFollowRequestAccepted.ts +5 -0
- package/src/userRepository/relationship/follow/events/onLocalFollowRequestDeclined.ts +5 -0
- package/src/userRepository/relationship/follow/events/onLocalFollowerRequested.ts +5 -0
- package/src/userRepository/relationship/follow/events/onLocalUserFollowed.ts +5 -0
- package/src/userRepository/relationship/follow/events/onLocalUserUnfollowed.ts +5 -0
- package/src/userRepository/relationship/follow/events/utils.ts +25 -14
- package/src/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.ts +132 -0
- package/src/userRepository/relationship/follow/observers/getFollowers/FollowerPaginationController.ts +29 -0
- package/src/userRepository/relationship/follow/observers/getFollowers/FollowerQueryStreamController.ts +95 -0
- package/src/userRepository/relationship/follow/observers/getFollowers.ts +8 -106
- package/src/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.ts +136 -0
- package/src/userRepository/relationship/follow/observers/getFollowings/FollowingPaginationController.ts +29 -0
- package/src/userRepository/relationship/follow/observers/getFollowings/FollowingQueryStreamController.ts +95 -0
- package/src/userRepository/relationship/follow/observers/getFollowings.ts +6 -106
- package/src/userRepository/relationship/follow/observers/observeFollowers.ts +11 -0
- package/src/userRepository/relationship/follow/observers/observeFollowings.ts +11 -0
- package/src/userRepository/relationship/follow/utils.ts +36 -0
- package/src/userRepository/utils/convertRawUserToInternalUser.ts +6 -0
- package/src/userRepository/utils/prepareBlockedUserPayload.ts +19 -0
- package/src/userRepository/utils/prepareUserPayload.ts +8 -0
- package/src/utils/linkedObject/commentLinkedObject.ts +13 -16
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/pinnedPostLinkedObject.ts +28 -0
package/dist/index.esm.js
CHANGED
|
@@ -6,9 +6,8 @@ import HttpAgent, { HttpsAgent } from 'agentkeepalive';
|
|
|
6
6
|
import io from 'socket.io-client';
|
|
7
7
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
8
8
|
import uuid$1 from 'react-native-uuid';
|
|
9
|
-
import { Platform } from 'react-native';
|
|
10
|
-
import mime from 'mime';
|
|
11
9
|
import hash from 'object-hash';
|
|
10
|
+
import mime from 'mime';
|
|
12
11
|
import Hls from 'hls.js';
|
|
13
12
|
|
|
14
13
|
const FileType = Object.freeze({
|
|
@@ -528,6 +527,8 @@ const idResolvers = {
|
|
|
528
527
|
storyTarget: ({ targetId }) => targetId,
|
|
529
528
|
ad: ({ adId }) => adId,
|
|
530
529
|
advertiser: ({ advertiserId }) => advertiserId,
|
|
530
|
+
pin: ({ referenceId }) => referenceId,
|
|
531
|
+
pinTarget: ({ targetId }) => targetId,
|
|
531
532
|
};
|
|
532
533
|
/**
|
|
533
534
|
* Retrieve the id resolver matching a domain name
|
|
@@ -577,6 +578,8 @@ const PAYLOAD2MODEL = {
|
|
|
577
578
|
feeds: 'feed',
|
|
578
579
|
ads: 'ad',
|
|
579
580
|
advertisers: 'advertiser',
|
|
581
|
+
pinTargets: 'pinTarget',
|
|
582
|
+
pins: 'pin',
|
|
580
583
|
};
|
|
581
584
|
/** hidden */
|
|
582
585
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -652,18 +655,6 @@ class ASCConnectionError extends ASCError {
|
|
|
652
655
|
: 800210 /* Amity.ClientError.CONNECTION_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
653
656
|
this.event = event;
|
|
654
657
|
}
|
|
655
|
-
}
|
|
656
|
-
/**
|
|
657
|
-
* Input sanitization related error
|
|
658
|
-
* @category Errors
|
|
659
|
-
*/
|
|
660
|
-
class ASCInvalidParameterError extends ASCError {
|
|
661
|
-
/**
|
|
662
|
-
* @param message A custom error message
|
|
663
|
-
*/
|
|
664
|
-
constructor(message) {
|
|
665
|
-
super(message, 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
666
|
-
}
|
|
667
658
|
}
|
|
668
659
|
|
|
669
660
|
let activeClient = null;
|
|
@@ -20830,6 +20821,31 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
|
20830
20821
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
20831
20822
|
}
|
|
20832
20823
|
|
|
20824
|
+
/**
|
|
20825
|
+
* Attach user object to membership model
|
|
20826
|
+
* - If cache is not enabled, set user to undefined ({..., user: undefined})
|
|
20827
|
+
* - If user object is not found in cache, set user to undefined
|
|
20828
|
+
* ({..., user: undefined})
|
|
20829
|
+
* - If a user is found in the cache, it attaches the user from the cache
|
|
20830
|
+
* ({..., user: { userId, displayName,... }})
|
|
20831
|
+
*
|
|
20832
|
+
* @param member The membership model object
|
|
20833
|
+
* @returns The membership model object that is already mapped to user
|
|
20834
|
+
* @hidden
|
|
20835
|
+
*/
|
|
20836
|
+
const convertRawMembershipToMembership = (member) => {
|
|
20837
|
+
return Object.assign(Object.assign({}, member), { get user() {
|
|
20838
|
+
var _a;
|
|
20839
|
+
const client = getActiveClient();
|
|
20840
|
+
if (!client.cache)
|
|
20841
|
+
return undefined;
|
|
20842
|
+
const userCache = (_a = pullFromCache(['user', 'get', member.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
20843
|
+
if (!userCache) {
|
|
20844
|
+
return undefined;
|
|
20845
|
+
}
|
|
20846
|
+
return userCache;
|
|
20847
|
+
} });
|
|
20848
|
+
};
|
|
20833
20849
|
/**
|
|
20834
20850
|
* Attach user object to membership model
|
|
20835
20851
|
* - If cache is not enabled, set user to undefined ({..., user: undefined})
|
|
@@ -21476,6 +21492,80 @@ const categoryLinkedObject = (category) => {
|
|
|
21476
21492
|
} });
|
|
21477
21493
|
};
|
|
21478
21494
|
|
|
21495
|
+
/**
|
|
21496
|
+
* ```js
|
|
21497
|
+
* import { isEqual } from '~/utils/isEqual'
|
|
21498
|
+
* const isEqual = isEqual(post1, post2)
|
|
21499
|
+
* ```
|
|
21500
|
+
*
|
|
21501
|
+
* Compares two Amity.Model
|
|
21502
|
+
*
|
|
21503
|
+
* @param x the Amity.Model to compare
|
|
21504
|
+
* @param y the Amity.Model to compare wit x
|
|
21505
|
+
* @returns a boolean based on equality
|
|
21506
|
+
*
|
|
21507
|
+
* @category utility
|
|
21508
|
+
* @private
|
|
21509
|
+
*/
|
|
21510
|
+
function isEqual(x, y) {
|
|
21511
|
+
if (x === null || x === undefined || y === null || y === undefined) {
|
|
21512
|
+
return x === y;
|
|
21513
|
+
}
|
|
21514
|
+
// after this just checking type of one would be enough
|
|
21515
|
+
if (x.constructor !== y.constructor) {
|
|
21516
|
+
return false;
|
|
21517
|
+
}
|
|
21518
|
+
// if they are functions, they should exactly refer to same one (because of closures)
|
|
21519
|
+
if (x instanceof Function) {
|
|
21520
|
+
return x === y;
|
|
21521
|
+
}
|
|
21522
|
+
// if they are regexps, they should exactly refer to same one
|
|
21523
|
+
if (x instanceof RegExp) {
|
|
21524
|
+
return x === y;
|
|
21525
|
+
}
|
|
21526
|
+
if (x === y || x.valueOf() === y.valueOf()) {
|
|
21527
|
+
return true;
|
|
21528
|
+
}
|
|
21529
|
+
if (Array.isArray(x) && x.length !== y.length) {
|
|
21530
|
+
return false;
|
|
21531
|
+
}
|
|
21532
|
+
// check each element of the array for equality
|
|
21533
|
+
if (Array.isArray(x) && Array.isArray(y)) {
|
|
21534
|
+
if (x.length !== y.length)
|
|
21535
|
+
return false;
|
|
21536
|
+
for (let i = 0; i < x.length; i += 1) {
|
|
21537
|
+
if (!isEqual(x[i], y[i]))
|
|
21538
|
+
return false;
|
|
21539
|
+
}
|
|
21540
|
+
// if all elements are equal, the arrays are equal
|
|
21541
|
+
return true;
|
|
21542
|
+
}
|
|
21543
|
+
// if they are dates, they must had equal valueOf
|
|
21544
|
+
if (x instanceof Date) {
|
|
21545
|
+
return false;
|
|
21546
|
+
}
|
|
21547
|
+
// if they are strictly equal, they both need to be object at least
|
|
21548
|
+
if (!(x instanceof Object)) {
|
|
21549
|
+
return false;
|
|
21550
|
+
}
|
|
21551
|
+
if (!(y instanceof Object)) {
|
|
21552
|
+
return false;
|
|
21553
|
+
}
|
|
21554
|
+
// recursive object equality check
|
|
21555
|
+
const p = Object.keys(x);
|
|
21556
|
+
return (Object.keys(y).every(i => {
|
|
21557
|
+
// @ts-ignore
|
|
21558
|
+
return p.indexOf(i) !== -1;
|
|
21559
|
+
}) &&
|
|
21560
|
+
p.every(i => {
|
|
21561
|
+
return isEqual(x[i], y[i]);
|
|
21562
|
+
}));
|
|
21563
|
+
}
|
|
21564
|
+
|
|
21565
|
+
function isNonNullable(value) {
|
|
21566
|
+
return value != null;
|
|
21567
|
+
}
|
|
21568
|
+
|
|
21479
21569
|
const commentLinkedObject = (comment) => {
|
|
21480
21570
|
return Object.assign(Object.assign({}, comment), { get target() {
|
|
21481
21571
|
const commentTypes = {
|
|
@@ -21506,7 +21596,7 @@ const commentLinkedObject = (comment) => {
|
|
|
21506
21596
|
return undefined;
|
|
21507
21597
|
},
|
|
21508
21598
|
get childrenComment() {
|
|
21509
|
-
return
|
|
21599
|
+
return comment.children
|
|
21510
21600
|
.map(childCommentId => {
|
|
21511
21601
|
const commentCache = pullFromCache([
|
|
21512
21602
|
'comment',
|
|
@@ -21517,10 +21607,8 @@ const commentLinkedObject = (comment) => {
|
|
|
21517
21607
|
return;
|
|
21518
21608
|
return commentCache === null || commentCache === void 0 ? void 0 : commentCache.data;
|
|
21519
21609
|
})
|
|
21520
|
-
.filter(
|
|
21521
|
-
|
|
21522
|
-
// TS always alert returned value is possibly undefined
|
|
21523
|
-
.map(item => commentLinkedObject(item)));
|
|
21610
|
+
.filter(isNonNullable)
|
|
21611
|
+
.map(item => commentLinkedObject(item));
|
|
21524
21612
|
} });
|
|
21525
21613
|
};
|
|
21526
21614
|
|
|
@@ -21943,6 +22031,31 @@ const adLinkedObject = (ad) => {
|
|
|
21943
22031
|
} });
|
|
21944
22032
|
};
|
|
21945
22033
|
|
|
22034
|
+
const pinnedPostLinkedObject = (pinnedPost) => {
|
|
22035
|
+
var _a;
|
|
22036
|
+
const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
|
|
22037
|
+
const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
|
|
22038
|
+
var _a;
|
|
22039
|
+
return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
|
|
22040
|
+
})) === null || _a === void 0 ? void 0 : _a.data;
|
|
22041
|
+
return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
|
|
22042
|
+
get post() {
|
|
22043
|
+
if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
|
|
22044
|
+
return;
|
|
22045
|
+
return postLinkedObject(postCached.data);
|
|
22046
|
+
},
|
|
22047
|
+
get target() {
|
|
22048
|
+
const pinTarget = pullFromCache([
|
|
22049
|
+
'pinTarget',
|
|
22050
|
+
'get',
|
|
22051
|
+
postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
|
|
22052
|
+
]);
|
|
22053
|
+
if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
|
|
22054
|
+
return;
|
|
22055
|
+
return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
|
|
22056
|
+
} });
|
|
22057
|
+
};
|
|
22058
|
+
|
|
21946
22059
|
const LinkedObject = {
|
|
21947
22060
|
ad: adLinkedObject,
|
|
21948
22061
|
comment: commentLinkedObject,
|
|
@@ -21955,6 +22068,7 @@ const LinkedObject = {
|
|
|
21955
22068
|
message: messageLinkedObject,
|
|
21956
22069
|
reactor: reactorLinkedObject,
|
|
21957
22070
|
channel: channelLinkedObject,
|
|
22071
|
+
pinnedPost: pinnedPostLinkedObject,
|
|
21958
22072
|
};
|
|
21959
22073
|
|
|
21960
22074
|
const getChannelMessagePreviewWithUser = (channel) => {
|
|
@@ -22323,6 +22437,10 @@ const getChannelIsMentioned = (channel, marker) => {
|
|
|
22323
22437
|
: (_d = (_c = getCachedMarker(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
|
|
22324
22438
|
};
|
|
22325
22439
|
|
|
22440
|
+
function convertRawUserToInternalUser(rawUser) {
|
|
22441
|
+
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
22442
|
+
}
|
|
22443
|
+
|
|
22326
22444
|
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
22327
22445
|
const isUnreadCountSupport$2 = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
22328
22446
|
function convertFromRaw$2(channel, options = { isMessagePreviewUpdated: true }) {
|
|
@@ -22380,9 +22498,13 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
|
|
|
22380
22498
|
// attach marker to channel
|
|
22381
22499
|
const channels = rawPayload.channels.map(payload => convertFromRaw$2(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
22382
22500
|
// user marker to channel users
|
|
22383
|
-
const channelUsers =
|
|
22501
|
+
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
22502
|
+
return convertRawMembershipToMembership(channelUser);
|
|
22503
|
+
});
|
|
22504
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
22384
22505
|
const restRawPayload = __rest(rawPayload, ["messageFeedsInfo", "messagePreviews"]);
|
|
22385
|
-
return Object.assign(Object.assign({}, restRawPayload), {
|
|
22506
|
+
return Object.assign(Object.assign({}, restRawPayload), { users,
|
|
22507
|
+
channels,
|
|
22386
22508
|
channelUsers });
|
|
22387
22509
|
};
|
|
22388
22510
|
|
|
@@ -23819,9 +23941,17 @@ const onChannelMemberBanned = (callback) => {
|
|
|
23819
23941
|
return createEventSubscriber(client, 'onChannelMemberBanned', 'channel.banned', filter);
|
|
23820
23942
|
};
|
|
23821
23943
|
|
|
23944
|
+
function prepareUserPayload(response) {
|
|
23945
|
+
return {
|
|
23946
|
+
users: response.users.map(convertRawUserToInternalUser),
|
|
23947
|
+
files: response.files,
|
|
23948
|
+
};
|
|
23949
|
+
}
|
|
23950
|
+
|
|
23822
23951
|
const createUserEventSubscriber = (event, callback) => {
|
|
23823
23952
|
const client = getActiveClient();
|
|
23824
|
-
const filter = (
|
|
23953
|
+
const filter = (data) => {
|
|
23954
|
+
const payload = prepareUserPayload(data);
|
|
23825
23955
|
if (client.cache) {
|
|
23826
23956
|
ingestInCache(payload);
|
|
23827
23957
|
}
|
|
@@ -23845,7 +23975,7 @@ const createUserEventSubscriber = (event, callback) => {
|
|
|
23845
23975
|
*
|
|
23846
23976
|
* @category User Events
|
|
23847
23977
|
*/
|
|
23848
|
-
const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
23978
|
+
const onUserDeleted$2 = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
23849
23979
|
|
|
23850
23980
|
var analyticsEngineOnLoginHandler = () => {
|
|
23851
23981
|
const analyticsEngine = AnalyticsEngine$1.getInstance();
|
|
@@ -25122,7 +25252,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
25122
25252
|
terminateClient();
|
|
25123
25253
|
subscriptions.forEach(fn => fn());
|
|
25124
25254
|
unsubWatcher();
|
|
25125
|
-
}), onUserDeleted((user) => {
|
|
25255
|
+
}), onUserDeleted$2((user) => {
|
|
25126
25256
|
if (user.userId === client.userId) {
|
|
25127
25257
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
25128
25258
|
subscriptions.forEach(fn => fn());
|
|
@@ -25404,43 +25534,6 @@ const isConnected = () => {
|
|
|
25404
25534
|
client.ws.connected);
|
|
25405
25535
|
};
|
|
25406
25536
|
|
|
25407
|
-
const registerPushNotification = async (deviceToken) => {
|
|
25408
|
-
const client = getActiveClient();
|
|
25409
|
-
let platform;
|
|
25410
|
-
if (Platform.OS === 'ios' || Platform.OS === 'android') {
|
|
25411
|
-
platform = Platform.OS;
|
|
25412
|
-
}
|
|
25413
|
-
else {
|
|
25414
|
-
throw new ASCInvalidParameterError('Unsupported platform');
|
|
25415
|
-
}
|
|
25416
|
-
const deviceId = await getDeviceId();
|
|
25417
|
-
const { data: { status, error }, } = await client.http.post('/v1/notification', {
|
|
25418
|
-
userId: client.userId,
|
|
25419
|
-
deviceId,
|
|
25420
|
-
platform,
|
|
25421
|
-
token: deviceToken,
|
|
25422
|
-
}, { headers: { 'X-API-Key': client.apiKey } });
|
|
25423
|
-
if (error) {
|
|
25424
|
-
throw new ASCApiError(error, 500000 /* Amity.ServerError.BUSINESS_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25425
|
-
}
|
|
25426
|
-
return status === 'success';
|
|
25427
|
-
};
|
|
25428
|
-
|
|
25429
|
-
const unregisterPushNotification = async () => {
|
|
25430
|
-
const client = getActiveClient();
|
|
25431
|
-
const deviceId = getDeviceId();
|
|
25432
|
-
const { data: { status, error }, } = await client.http.delete('/v1/notification', {
|
|
25433
|
-
data: {
|
|
25434
|
-
deviceId,
|
|
25435
|
-
},
|
|
25436
|
-
headers: { 'X-API-Key': client.apiKey },
|
|
25437
|
-
});
|
|
25438
|
-
if (error) {
|
|
25439
|
-
throw new ASCApiError(error, 500000 /* Amity.ServerError.BUSINESS_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25440
|
-
}
|
|
25441
|
-
return status === 'success';
|
|
25442
|
-
};
|
|
25443
|
-
|
|
25444
25537
|
var _GlobalFileAccessType_fileAccessType;
|
|
25445
25538
|
class GlobalFileAccessType {
|
|
25446
25539
|
constructor() {
|
|
@@ -25711,76 +25804,6 @@ const removeFunctionProperties = (obj) => {
|
|
|
25711
25804
|
return Object.fromEntries(entries);
|
|
25712
25805
|
};
|
|
25713
25806
|
|
|
25714
|
-
/**
|
|
25715
|
-
* ```js
|
|
25716
|
-
* import { isEqual } from '~/utils/isEqual'
|
|
25717
|
-
* const isEqual = isEqual(post1, post2)
|
|
25718
|
-
* ```
|
|
25719
|
-
*
|
|
25720
|
-
* Compares two Amity.Model
|
|
25721
|
-
*
|
|
25722
|
-
* @param x the Amity.Model to compare
|
|
25723
|
-
* @param y the Amity.Model to compare wit x
|
|
25724
|
-
* @returns a boolean based on equality
|
|
25725
|
-
*
|
|
25726
|
-
* @category utility
|
|
25727
|
-
* @private
|
|
25728
|
-
*/
|
|
25729
|
-
function isEqual(x, y) {
|
|
25730
|
-
if (x === null || x === undefined || y === null || y === undefined) {
|
|
25731
|
-
return x === y;
|
|
25732
|
-
}
|
|
25733
|
-
// after this just checking type of one would be enough
|
|
25734
|
-
if (x.constructor !== y.constructor) {
|
|
25735
|
-
return false;
|
|
25736
|
-
}
|
|
25737
|
-
// if they are functions, they should exactly refer to same one (because of closures)
|
|
25738
|
-
if (x instanceof Function) {
|
|
25739
|
-
return x === y;
|
|
25740
|
-
}
|
|
25741
|
-
// if they are regexps, they should exactly refer to same one
|
|
25742
|
-
if (x instanceof RegExp) {
|
|
25743
|
-
return x === y;
|
|
25744
|
-
}
|
|
25745
|
-
if (x === y || x.valueOf() === y.valueOf()) {
|
|
25746
|
-
return true;
|
|
25747
|
-
}
|
|
25748
|
-
if (Array.isArray(x) && x.length !== y.length) {
|
|
25749
|
-
return false;
|
|
25750
|
-
}
|
|
25751
|
-
// check each element of the array for equality
|
|
25752
|
-
if (Array.isArray(x) && Array.isArray(y)) {
|
|
25753
|
-
if (x.length !== y.length)
|
|
25754
|
-
return false;
|
|
25755
|
-
for (let i = 0; i < x.length; i += 1) {
|
|
25756
|
-
if (!isEqual(x[i], y[i]))
|
|
25757
|
-
return false;
|
|
25758
|
-
}
|
|
25759
|
-
// if all elements are equal, the arrays are equal
|
|
25760
|
-
return true;
|
|
25761
|
-
}
|
|
25762
|
-
// if they are dates, they must had equal valueOf
|
|
25763
|
-
if (x instanceof Date) {
|
|
25764
|
-
return false;
|
|
25765
|
-
}
|
|
25766
|
-
// if they are strictly equal, they both need to be object at least
|
|
25767
|
-
if (!(x instanceof Object)) {
|
|
25768
|
-
return false;
|
|
25769
|
-
}
|
|
25770
|
-
if (!(y instanceof Object)) {
|
|
25771
|
-
return false;
|
|
25772
|
-
}
|
|
25773
|
-
// recursive object equality check
|
|
25774
|
-
const p = Object.keys(x);
|
|
25775
|
-
return (Object.keys(y).every(i => {
|
|
25776
|
-
// @ts-ignore
|
|
25777
|
-
return p.indexOf(i) !== -1;
|
|
25778
|
-
}) &&
|
|
25779
|
-
p.every(i => {
|
|
25780
|
-
return isEqual(x[i], y[i]);
|
|
25781
|
-
}));
|
|
25782
|
-
}
|
|
25783
|
-
|
|
25784
25807
|
/**
|
|
25785
25808
|
* @deprecated This function is deprecated
|
|
25786
25809
|
*/
|
|
@@ -25998,8 +26021,6 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
25998
26021
|
renewal: renewal,
|
|
25999
26022
|
markerSync: markerSync,
|
|
26000
26023
|
enableUnreadCount: enableUnreadCount,
|
|
26001
|
-
registerPushNotification: registerPushNotification,
|
|
26002
|
-
unregisterPushNotification: unregisterPushNotification,
|
|
26003
26024
|
setUploadedFileAccessType: setUploadedFileAccessType,
|
|
26004
26025
|
onConnectionError: onConnectionError,
|
|
26005
26026
|
onClientDisconnected: onClientDisconnected,
|
|
@@ -26019,6 +26040,19 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
26019
26040
|
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
|
|
26020
26041
|
});
|
|
26021
26042
|
|
|
26043
|
+
function prepareFollowersPayload(response) {
|
|
26044
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
26045
|
+
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
26046
|
+
}
|
|
26047
|
+
function prepareFollowingsPayload(response) {
|
|
26048
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
26049
|
+
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
26050
|
+
}
|
|
26051
|
+
function prepareFollowStatusPayload(response) {
|
|
26052
|
+
const { follows } = response, rest = __rest(response, ["follows"]);
|
|
26053
|
+
return Object.assign(Object.assign({}, rest), { follows });
|
|
26054
|
+
}
|
|
26055
|
+
|
|
26022
26056
|
/* begin_public_function
|
|
26023
26057
|
id: user.relationship.block
|
|
26024
26058
|
*/
|
|
@@ -26047,7 +26081,8 @@ const blockUser = async (userId) => {
|
|
|
26047
26081
|
ingestInCache(followStatus, { cachedAt });
|
|
26048
26082
|
upsertInCache(['followInfo', 'get', userId], followCounts[0], { cachedAt });
|
|
26049
26083
|
}
|
|
26050
|
-
|
|
26084
|
+
const payload = prepareFollowStatusPayload(followStatus);
|
|
26085
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
26051
26086
|
return data;
|
|
26052
26087
|
};
|
|
26053
26088
|
/* end_public_function */
|
|
@@ -26080,171 +26115,397 @@ const unBlockUser = async (userId) => {
|
|
|
26080
26115
|
ingestInCache(followStatus, { cachedAt });
|
|
26081
26116
|
upsertInCache(['followInfo', 'get', userId], followCounts[0], { cachedAt });
|
|
26082
26117
|
}
|
|
26083
|
-
|
|
26118
|
+
const payload = prepareFollowStatusPayload(followStatus);
|
|
26119
|
+
fireEvent('local.follow.created', payload);
|
|
26084
26120
|
return data;
|
|
26085
26121
|
};
|
|
26086
26122
|
/* end_public_function */
|
|
26087
26123
|
|
|
26124
|
+
class PaginationController {
|
|
26125
|
+
constructor(queryParams) {
|
|
26126
|
+
const { http } = getActiveClient();
|
|
26127
|
+
this.queryParams = queryParams;
|
|
26128
|
+
this.http = http;
|
|
26129
|
+
}
|
|
26130
|
+
loadFirstPage() {
|
|
26131
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
26132
|
+
}
|
|
26133
|
+
loadNextPage() {
|
|
26134
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
26135
|
+
}
|
|
26136
|
+
loadPreviousPage() {
|
|
26137
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
26138
|
+
}
|
|
26139
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
26140
|
+
var _a, _b, _c, _d;
|
|
26141
|
+
if (direction === 'prev' && !this.previousToken)
|
|
26142
|
+
return;
|
|
26143
|
+
if (direction === 'next' && !this.nextToken)
|
|
26144
|
+
return;
|
|
26145
|
+
let token;
|
|
26146
|
+
if (direction === 'prev')
|
|
26147
|
+
token = this.previousToken;
|
|
26148
|
+
if (direction === 'next')
|
|
26149
|
+
token = this.nextToken;
|
|
26150
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
26151
|
+
if (direction === 'first') {
|
|
26152
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
26153
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
26154
|
+
}
|
|
26155
|
+
if (direction === 'prev')
|
|
26156
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
26157
|
+
if (direction === 'next')
|
|
26158
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
26159
|
+
return queryResponse;
|
|
26160
|
+
}
|
|
26161
|
+
getNextToken() {
|
|
26162
|
+
return this.nextToken;
|
|
26163
|
+
}
|
|
26164
|
+
getPrevToken() {
|
|
26165
|
+
return this.previousToken;
|
|
26166
|
+
}
|
|
26167
|
+
}
|
|
26168
|
+
|
|
26169
|
+
class BlockedUserPaginationController extends PaginationController {
|
|
26170
|
+
async getRequest(queryParams, token) {
|
|
26171
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
26172
|
+
const options = token ? { token } : { limit };
|
|
26173
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
26174
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
26175
|
+
});
|
|
26176
|
+
return queryResponse;
|
|
26177
|
+
}
|
|
26178
|
+
}
|
|
26179
|
+
|
|
26180
|
+
class QueryStreamController {
|
|
26181
|
+
constructor(query, cacheKey) {
|
|
26182
|
+
this.query = query;
|
|
26183
|
+
this.cacheKey = cacheKey;
|
|
26184
|
+
}
|
|
26185
|
+
}
|
|
26186
|
+
|
|
26187
|
+
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
26188
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
26189
|
+
super(query, cacheKey);
|
|
26190
|
+
this.notifyChange = notifyChange;
|
|
26191
|
+
this.preparePayload = preparePayload;
|
|
26192
|
+
}
|
|
26193
|
+
async saveToMainDB(response) {
|
|
26194
|
+
const processedPayload = await this.preparePayload(response);
|
|
26195
|
+
const client = getActiveClient();
|
|
26196
|
+
const cachedAt = client.cache && Date.now();
|
|
26197
|
+
if (client.cache) {
|
|
26198
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
26199
|
+
}
|
|
26200
|
+
}
|
|
26201
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
26202
|
+
var _a, _b;
|
|
26203
|
+
if (refresh) {
|
|
26204
|
+
pushToCache(this.cacheKey, {
|
|
26205
|
+
data: response.users.map(getResolver('user')),
|
|
26206
|
+
});
|
|
26207
|
+
}
|
|
26208
|
+
else {
|
|
26209
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26210
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26211
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
26212
|
+
}
|
|
26213
|
+
}
|
|
26214
|
+
reactor(action) {
|
|
26215
|
+
return (followStatus) => {
|
|
26216
|
+
var _a;
|
|
26217
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26218
|
+
pushToCache(this.cacheKey, collection);
|
|
26219
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
26220
|
+
};
|
|
26221
|
+
}
|
|
26222
|
+
subscribeRTE(createSubscriber) {
|
|
26223
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
26224
|
+
}
|
|
26225
|
+
}
|
|
26226
|
+
|
|
26227
|
+
class PaginationNoPageController {
|
|
26228
|
+
constructor(queryParams) {
|
|
26229
|
+
const { http } = getActiveClient();
|
|
26230
|
+
this.queryParams = queryParams;
|
|
26231
|
+
this.http = http;
|
|
26232
|
+
}
|
|
26233
|
+
async onFetch() {
|
|
26234
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
26235
|
+
return queryResponse;
|
|
26236
|
+
}
|
|
26237
|
+
}
|
|
26238
|
+
|
|
26239
|
+
class LiveCollectionController {
|
|
26240
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
26241
|
+
this.paginationController = paginationController;
|
|
26242
|
+
this.queryStreamId = queryStreamId;
|
|
26243
|
+
this.cacheKey = cacheKey;
|
|
26244
|
+
this.callback = callback;
|
|
26245
|
+
}
|
|
26246
|
+
async refresh() {
|
|
26247
|
+
try {
|
|
26248
|
+
let result;
|
|
26249
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
26250
|
+
result = await this.paginationController.onFetch();
|
|
26251
|
+
}
|
|
26252
|
+
else {
|
|
26253
|
+
result = await this.paginationController.loadFirstPage();
|
|
26254
|
+
}
|
|
26255
|
+
if (!result)
|
|
26256
|
+
return;
|
|
26257
|
+
await this.persistModel(result);
|
|
26258
|
+
this.persistQueryStream({
|
|
26259
|
+
response: result,
|
|
26260
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26261
|
+
refresh: true,
|
|
26262
|
+
});
|
|
26263
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26264
|
+
}
|
|
26265
|
+
catch (e) {
|
|
26266
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26267
|
+
}
|
|
26268
|
+
}
|
|
26269
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
26270
|
+
this.setup();
|
|
26271
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
26272
|
+
if (initial) {
|
|
26273
|
+
this.refresh();
|
|
26274
|
+
}
|
|
26275
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
26276
|
+
this.loadPrevPage();
|
|
26277
|
+
}
|
|
26278
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
26279
|
+
this.loadNextPage();
|
|
26280
|
+
}
|
|
26281
|
+
}
|
|
26282
|
+
async loadNextPage() {
|
|
26283
|
+
try {
|
|
26284
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
26285
|
+
return;
|
|
26286
|
+
const result = await this.paginationController.loadNextPage();
|
|
26287
|
+
if (!result)
|
|
26288
|
+
return;
|
|
26289
|
+
await this.persistModel(result);
|
|
26290
|
+
this.persistQueryStream({
|
|
26291
|
+
response: result,
|
|
26292
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26293
|
+
});
|
|
26294
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26295
|
+
}
|
|
26296
|
+
catch (e) {
|
|
26297
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26298
|
+
}
|
|
26299
|
+
}
|
|
26300
|
+
async loadPrevPage() {
|
|
26301
|
+
try {
|
|
26302
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
26303
|
+
return;
|
|
26304
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
26305
|
+
if (!result)
|
|
26306
|
+
return;
|
|
26307
|
+
await this.persistModel(result);
|
|
26308
|
+
this.persistQueryStream({
|
|
26309
|
+
response: result,
|
|
26310
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
26311
|
+
});
|
|
26312
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26313
|
+
}
|
|
26314
|
+
catch (e) {
|
|
26315
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26316
|
+
}
|
|
26317
|
+
}
|
|
26318
|
+
shouldNotify(data) {
|
|
26319
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
26320
|
+
if (isEqual(this.snapshot, newData))
|
|
26321
|
+
return false;
|
|
26322
|
+
this.snapshot = newData;
|
|
26323
|
+
return true;
|
|
26324
|
+
}
|
|
26325
|
+
getCacheKey() {
|
|
26326
|
+
return this.cacheKey;
|
|
26327
|
+
}
|
|
26328
|
+
}
|
|
26329
|
+
|
|
26330
|
+
function prepareBlockedUserPayload(response) {
|
|
26331
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
26332
|
+
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
26333
|
+
const followUser = users.find(user => user.userId === follow.from);
|
|
26334
|
+
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
26335
|
+
}), users: users.map(convertRawUserToInternalUser) });
|
|
26336
|
+
}
|
|
26337
|
+
|
|
26088
26338
|
/**
|
|
26089
26339
|
* ```js
|
|
26090
|
-
* import {
|
|
26091
|
-
* const
|
|
26340
|
+
* import { onUserUpdated } from '@amityco/ts-sdk-react-native'
|
|
26341
|
+
* const dispose = onUserUpdated(user => {
|
|
26342
|
+
* // ...
|
|
26343
|
+
* })
|
|
26092
26344
|
* ```
|
|
26093
26345
|
*
|
|
26094
|
-
* @
|
|
26095
|
-
* @returns A page of {@link Amity.User} objects
|
|
26346
|
+
* Fired when a {@link Amity.InternalUser} has been updated
|
|
26096
26347
|
*
|
|
26097
|
-
* @
|
|
26098
|
-
* @
|
|
26348
|
+
* @param callback The function to call when the event was fired
|
|
26349
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26350
|
+
*
|
|
26351
|
+
* @category User Events
|
|
26099
26352
|
*/
|
|
26100
|
-
const
|
|
26101
|
-
|
|
26102
|
-
let params = {};
|
|
26103
|
-
if (query) {
|
|
26104
|
-
const { token, limit } = query;
|
|
26105
|
-
params = {
|
|
26106
|
-
limit,
|
|
26107
|
-
token,
|
|
26108
|
-
};
|
|
26109
|
-
}
|
|
26110
|
-
client.log('user/queryBlockedUsers');
|
|
26111
|
-
const { data } = await client.http.get('/api/v4/me/user-blocks', {
|
|
26112
|
-
params,
|
|
26113
|
-
});
|
|
26114
|
-
const { paging } = data, blockedUsers = __rest(data, ["paging"]);
|
|
26115
|
-
const { users } = blockedUsers;
|
|
26116
|
-
const cachedAt = client.cache && Date.now();
|
|
26117
|
-
if (client.cache) {
|
|
26118
|
-
ingestInCache(blockedUsers, { cachedAt });
|
|
26119
|
-
const cacheKey = ['blockedUsers', 'query', params];
|
|
26120
|
-
pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
|
|
26121
|
-
}
|
|
26122
|
-
const { next, previous, total } = paging;
|
|
26123
|
-
const nextPage = toPageRaw(next);
|
|
26124
|
-
const prevPage = toPageRaw(previous);
|
|
26125
|
-
return { data: users, prevPage, nextPage, total, cachedAt };
|
|
26126
|
-
};
|
|
26353
|
+
const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
|
|
26354
|
+
|
|
26127
26355
|
/**
|
|
26128
26356
|
* ```js
|
|
26129
|
-
* import {
|
|
26130
|
-
* const
|
|
26357
|
+
* import { onUserFlagged } from '@amityco/ts-sdk-react-native'
|
|
26358
|
+
* const dispose = onUserFlagged(user => {
|
|
26359
|
+
* // ...
|
|
26360
|
+
* })
|
|
26131
26361
|
* ```
|
|
26132
26362
|
*
|
|
26133
|
-
*
|
|
26134
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
26363
|
+
* Fired when a {@link Amity.InternalUser} has been flagged
|
|
26135
26364
|
*
|
|
26136
|
-
* @param
|
|
26137
|
-
* @returns
|
|
26365
|
+
* @param callback The function to call when the event was fired
|
|
26366
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26367
|
+
*
|
|
26368
|
+
* @category User Events
|
|
26369
|
+
*/
|
|
26370
|
+
const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
|
|
26371
|
+
|
|
26372
|
+
/**
|
|
26373
|
+
* ```js
|
|
26374
|
+
* import { onUserUnflagged } from '@amityco/ts-sdk-react-native'
|
|
26375
|
+
* const dispose = onUserUnflagged(user => {
|
|
26376
|
+
* // ...
|
|
26377
|
+
* })
|
|
26378
|
+
* ```
|
|
26379
|
+
*
|
|
26380
|
+
* Fired when a flag has been removed from a {@link Amity.InternalUser}
|
|
26381
|
+
*
|
|
26382
|
+
* @param callback The function to call when the event was fired
|
|
26383
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26138
26384
|
*
|
|
26139
|
-
* @category
|
|
26385
|
+
* @category User Events
|
|
26140
26386
|
*/
|
|
26141
|
-
|
|
26142
|
-
var _a, _b, _c;
|
|
26143
|
-
const client = getActiveClient();
|
|
26144
|
-
client.log('user/queryBlockedUsers.locally');
|
|
26145
|
-
if (!client.cache)
|
|
26146
|
-
return;
|
|
26147
|
-
let params = {};
|
|
26148
|
-
if (query) {
|
|
26149
|
-
const { token, limit } = query;
|
|
26150
|
-
params = {
|
|
26151
|
-
token,
|
|
26152
|
-
limit,
|
|
26153
|
-
};
|
|
26154
|
-
}
|
|
26155
|
-
const cacheKey = ['blockedUsers', 'query', params];
|
|
26156
|
-
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
26157
|
-
const users = (_b = data === null || data === void 0 ? void 0 : data.users.map(userId => pullFromCache(['user', 'get', userId])).filter(Boolean).map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
26158
|
-
const nextPage = toPageRaw(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
26159
|
-
const prevPage = toPageRaw(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
26160
|
-
return users.length > 0 && users.length === ((_c = data === null || data === void 0 ? void 0 : data.users) === null || _c === void 0 ? void 0 : _c.length)
|
|
26161
|
-
? { data: users, nextPage, prevPage, total: data === null || data === void 0 ? void 0 : data.paging.total, cachedAt }
|
|
26162
|
-
: undefined;
|
|
26163
|
-
};
|
|
26387
|
+
const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
|
|
26164
26388
|
|
|
26165
|
-
/* eslint-disable no-use-before-define */
|
|
26166
|
-
/* begin_public_function
|
|
26167
|
-
id: user.get_blocked_users
|
|
26168
|
-
*/
|
|
26169
26389
|
/**
|
|
26170
26390
|
* ```js
|
|
26171
|
-
* import {
|
|
26172
|
-
* const
|
|
26391
|
+
* import { onUserFlagCleared } from '@amityco/ts-sdk-react-native'
|
|
26392
|
+
* const dispose = onUserFlagCleared(user => {
|
|
26393
|
+
* // ...
|
|
26394
|
+
* })
|
|
26173
26395
|
* ```
|
|
26174
26396
|
*
|
|
26175
|
-
*
|
|
26397
|
+
* Fired when flags have been cleared for a {@link Amity.InternalUser}
|
|
26176
26398
|
*
|
|
26177
|
-
* @param
|
|
26178
|
-
* @
|
|
26179
|
-
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
26399
|
+
* @param callback The function to call when the event was fired
|
|
26400
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26180
26401
|
*
|
|
26181
|
-
* @category
|
|
26182
|
-
* @async
|
|
26402
|
+
* @category User Events
|
|
26183
26403
|
*/
|
|
26184
|
-
const
|
|
26185
|
-
|
|
26186
|
-
|
|
26187
|
-
|
|
26404
|
+
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
26405
|
+
|
|
26406
|
+
var EnumUserActions;
|
|
26407
|
+
(function (EnumUserActions) {
|
|
26408
|
+
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
26409
|
+
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
26410
|
+
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
26411
|
+
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
26412
|
+
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
26413
|
+
})(EnumUserActions || (EnumUserActions = {}));
|
|
26414
|
+
|
|
26415
|
+
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
26416
|
+
constructor(query, callback) {
|
|
26417
|
+
const queryStreamId = hash(query);
|
|
26418
|
+
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
26419
|
+
const paginationController = new BlockedUserPaginationController(query);
|
|
26420
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
26421
|
+
this.query = query;
|
|
26422
|
+
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
26423
|
+
this.callback = callback.bind(this);
|
|
26424
|
+
this.loadPage({ initial: true });
|
|
26188
26425
|
}
|
|
26189
|
-
|
|
26190
|
-
|
|
26191
|
-
|
|
26192
|
-
|
|
26193
|
-
|
|
26194
|
-
|
|
26195
|
-
|
|
26196
|
-
|
|
26197
|
-
|
|
26198
|
-
|
|
26199
|
-
|
|
26200
|
-
|
|
26201
|
-
|
|
26202
|
-
|
|
26203
|
-
|
|
26204
|
-
|
|
26205
|
-
|
|
26206
|
-
|
|
26207
|
-
|
|
26208
|
-
|
|
26209
|
-
|
|
26210
|
-
|
|
26211
|
-
|
|
26212
|
-
|
|
26213
|
-
|
|
26214
|
-
*};
|
|
26215
|
-
*/
|
|
26216
|
-
const onFetch = (initial = false) => {
|
|
26426
|
+
setup() {
|
|
26427
|
+
var _a;
|
|
26428
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26429
|
+
if (!collection) {
|
|
26430
|
+
pushToCache(this.cacheKey, {
|
|
26431
|
+
data: [],
|
|
26432
|
+
params: {},
|
|
26433
|
+
});
|
|
26434
|
+
}
|
|
26435
|
+
}
|
|
26436
|
+
async persistModel(queryPayload) {
|
|
26437
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
26438
|
+
}
|
|
26439
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
26440
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
26441
|
+
}
|
|
26442
|
+
startSubscription() {
|
|
26443
|
+
return this.queryStreamController.subscribeRTE([
|
|
26444
|
+
{
|
|
26445
|
+
fn: onUserDeleted$2,
|
|
26446
|
+
action: EnumUserActions.OnUserDeleted,
|
|
26447
|
+
},
|
|
26448
|
+
]);
|
|
26449
|
+
}
|
|
26450
|
+
notifyChange({ origin, loading, error }) {
|
|
26217
26451
|
var _a, _b;
|
|
26218
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26219
|
-
|
|
26220
|
-
if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
26452
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26453
|
+
if (!collection)
|
|
26221
26454
|
return;
|
|
26222
|
-
const
|
|
26223
|
-
|
|
26224
|
-
|
|
26455
|
+
const data = this.applyFilter((_b = collection.data
|
|
26456
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
26457
|
+
.filter(isNonNullable)
|
|
26458
|
+
.map(({ data }) => data)
|
|
26459
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
26460
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
26461
|
+
return;
|
|
26462
|
+
this.callback({
|
|
26463
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
26464
|
+
data,
|
|
26465
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
26466
|
+
loading,
|
|
26467
|
+
error,
|
|
26225
26468
|
});
|
|
26226
|
-
|
|
26227
|
-
|
|
26228
|
-
|
|
26229
|
-
|
|
26230
|
-
|
|
26231
|
-
|
|
26232
|
-
|
|
26233
|
-
|
|
26234
|
-
|
|
26235
|
-
|
|
26236
|
-
|
|
26237
|
-
|
|
26238
|
-
|
|
26239
|
-
|
|
26240
|
-
|
|
26241
|
-
|
|
26242
|
-
|
|
26243
|
-
|
|
26244
|
-
|
|
26245
|
-
|
|
26469
|
+
}
|
|
26470
|
+
// eslint-disable-next-line class-methods-use-this
|
|
26471
|
+
applyFilter(data) {
|
|
26472
|
+
let users = data;
|
|
26473
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
26474
|
+
return users;
|
|
26475
|
+
}
|
|
26476
|
+
}
|
|
26477
|
+
|
|
26478
|
+
/* begin_public_function
|
|
26479
|
+
id: user.get_blocked_users
|
|
26480
|
+
*/
|
|
26481
|
+
/**
|
|
26482
|
+
* ```js
|
|
26483
|
+
* import { UserRepository } from '@amityco/ts-sdk-react-native'
|
|
26484
|
+
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
26485
|
+
* ```
|
|
26486
|
+
*
|
|
26487
|
+
* Blocks a {@link Amity.InternalUser}
|
|
26488
|
+
*
|
|
26489
|
+
* @param params The params to get blocked {@link Amity.InternalUser}s
|
|
26490
|
+
* @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
|
|
26491
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
26492
|
+
*
|
|
26493
|
+
* @category Post API
|
|
26494
|
+
* @async
|
|
26495
|
+
*/
|
|
26496
|
+
const getBlockedUsers$1 = (params, callback, config) => {
|
|
26497
|
+
const { log, cache } = getActiveClient();
|
|
26498
|
+
if (!cache) {
|
|
26499
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
26500
|
+
}
|
|
26501
|
+
const timestamp = Date.now();
|
|
26502
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
26503
|
+
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
26504
|
+
const disposers = blockedUserLiveCollection.startSubscription();
|
|
26505
|
+
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
26506
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
26246
26507
|
return () => {
|
|
26247
|
-
log(`
|
|
26508
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
26248
26509
|
disposers.forEach(fn => fn());
|
|
26249
26510
|
dropFromCache(cacheKey);
|
|
26250
26511
|
};
|
|
@@ -26254,7 +26515,7 @@ const getBlockedUsers$1 = (params, callback, config) => {
|
|
|
26254
26515
|
/* eslint-disable no-use-before-define */
|
|
26255
26516
|
const getBlockedUsers = (params, callback, config) => {
|
|
26256
26517
|
console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
|
|
26257
|
-
return getBlockedUsers$1(params, callback
|
|
26518
|
+
return getBlockedUsers$1(params, callback);
|
|
26258
26519
|
};
|
|
26259
26520
|
|
|
26260
26521
|
/* begin_public_function
|
|
@@ -26282,7 +26543,13 @@ const follow = async (userId) => {
|
|
|
26282
26543
|
if (client.cache) {
|
|
26283
26544
|
ingestInCache(data, { cachedAt });
|
|
26284
26545
|
}
|
|
26285
|
-
|
|
26546
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26547
|
+
if (data.follows[0].status === 'accepted') {
|
|
26548
|
+
fireEvent('local.follow.created', payload);
|
|
26549
|
+
}
|
|
26550
|
+
else {
|
|
26551
|
+
fireEvent('local.follow.requested', payload);
|
|
26552
|
+
}
|
|
26286
26553
|
return {
|
|
26287
26554
|
data: data.follows[0],
|
|
26288
26555
|
cachedAt,
|
|
@@ -26314,7 +26581,8 @@ const unfollow = async (userId) => {
|
|
|
26314
26581
|
if (client.cache) {
|
|
26315
26582
|
ingestInCache(data);
|
|
26316
26583
|
}
|
|
26317
|
-
|
|
26584
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26585
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
26318
26586
|
return true;
|
|
26319
26587
|
};
|
|
26320
26588
|
/* end_public_function */
|
|
@@ -26343,7 +26611,8 @@ const acceptFollower = async (userId) => {
|
|
|
26343
26611
|
if (client.cache) {
|
|
26344
26612
|
ingestInCache(data);
|
|
26345
26613
|
}
|
|
26346
|
-
|
|
26614
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26615
|
+
fireEvent('local.follow.accepted', payload);
|
|
26347
26616
|
return true;
|
|
26348
26617
|
};
|
|
26349
26618
|
|
|
@@ -26371,7 +26640,8 @@ const acceptMyFollower = async (userId) => {
|
|
|
26371
26640
|
if (client.cache) {
|
|
26372
26641
|
ingestInCache(data);
|
|
26373
26642
|
}
|
|
26374
|
-
|
|
26643
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26644
|
+
fireEvent('local.follow.accepted', payload);
|
|
26375
26645
|
return true;
|
|
26376
26646
|
};
|
|
26377
26647
|
/* end_public_function */
|
|
@@ -26400,7 +26670,8 @@ const declineFollower = async (userId) => {
|
|
|
26400
26670
|
if (client.cache) {
|
|
26401
26671
|
ingestInCache(data);
|
|
26402
26672
|
}
|
|
26403
|
-
|
|
26673
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26674
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
26404
26675
|
return true;
|
|
26405
26676
|
};
|
|
26406
26677
|
|
|
@@ -26428,29 +26699,35 @@ const declineMyFollower = async (userId) => {
|
|
|
26428
26699
|
if (client.cache) {
|
|
26429
26700
|
ingestInCache(data);
|
|
26430
26701
|
}
|
|
26431
|
-
|
|
26702
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26703
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
26432
26704
|
return true;
|
|
26433
26705
|
};
|
|
26434
26706
|
/* end_public_function */
|
|
26435
26707
|
|
|
26436
26708
|
const createFollowEventSubscriber = (event, callback) => {
|
|
26437
26709
|
const client = getActiveClient();
|
|
26438
|
-
const filter = (
|
|
26439
|
-
|
|
26710
|
+
const filter = (data) => {
|
|
26711
|
+
const payload = prepareFollowersPayload(data);
|
|
26712
|
+
if (!client.cache) {
|
|
26713
|
+
callback(payload.follows[0]);
|
|
26714
|
+
}
|
|
26715
|
+
else {
|
|
26716
|
+
ingestInCache(payload);
|
|
26717
|
+
callback(payload.follows[0]);
|
|
26718
|
+
}
|
|
26719
|
+
};
|
|
26720
|
+
return createEventSubscriber(client, event, event, filter);
|
|
26721
|
+
};
|
|
26722
|
+
const createLocalFollowEventSubscriber = (event, callback) => {
|
|
26723
|
+
const client = getActiveClient();
|
|
26724
|
+
const filter = (data) => {
|
|
26725
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26440
26726
|
if (!client.cache) {
|
|
26441
26727
|
callback(payload.follows[0]);
|
|
26442
26728
|
}
|
|
26443
26729
|
else {
|
|
26444
26730
|
ingestInCache(payload);
|
|
26445
|
-
const queries = [
|
|
26446
|
-
...((_a = queryCache(['followers', 'query'])) !== null && _a !== void 0 ? _a : []),
|
|
26447
|
-
...((_b = queryCache(['followings', 'query'])) !== null && _b !== void 0 ? _b : []),
|
|
26448
|
-
];
|
|
26449
|
-
queries
|
|
26450
|
-
.filter(({ key }) =>
|
|
26451
|
-
// @ts-ignore
|
|
26452
|
-
key[2].userId === payload.follows[0].from || key[2].userId === payload.follows[0].to)
|
|
26453
|
-
.forEach(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
26454
26731
|
callback(payload.follows[0]);
|
|
26455
26732
|
}
|
|
26456
26733
|
};
|
|
@@ -26669,12 +26946,27 @@ const onFollowInfoUpdated = (callback) => {
|
|
|
26669
26946
|
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
26670
26947
|
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
26671
26948
|
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
26949
|
+
createLocalFollowEventSubscriber('local.follow.created', handler),
|
|
26950
|
+
createLocalFollowEventSubscriber('local.follow.requested', handler),
|
|
26951
|
+
createLocalFollowEventSubscriber('local.follow.accepted', handler),
|
|
26952
|
+
createLocalFollowEventSubscriber('local.follow.unfollowed', handler),
|
|
26953
|
+
createLocalFollowEventSubscriber('local.follow.requestDeclined', handler),
|
|
26672
26954
|
];
|
|
26673
26955
|
return () => {
|
|
26674
26956
|
disposers.forEach(fn => fn());
|
|
26675
26957
|
};
|
|
26676
26958
|
};
|
|
26677
26959
|
|
|
26960
|
+
const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
|
|
26961
|
+
|
|
26962
|
+
const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
|
|
26963
|
+
|
|
26964
|
+
const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
|
|
26965
|
+
|
|
26966
|
+
const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
|
|
26967
|
+
|
|
26968
|
+
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
26969
|
+
|
|
26678
26970
|
/**
|
|
26679
26971
|
* ```js
|
|
26680
26972
|
* import { observeFollowInfo } from '@amityco/ts-sdk-react-native'
|
|
@@ -26747,7 +27039,7 @@ const observeFollowers = (userId, callback) => {
|
|
|
26747
27039
|
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
26748
27040
|
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
26749
27041
|
};
|
|
26750
|
-
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')));
|
|
27042
|
+
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')));
|
|
26751
27043
|
return () => {
|
|
26752
27044
|
log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
|
|
26753
27045
|
disposers.forEach(fn => fn());
|
|
@@ -26783,92 +27075,190 @@ const observeFollowings = (userId, callback) => {
|
|
|
26783
27075
|
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
26784
27076
|
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
26785
27077
|
};
|
|
26786
|
-
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')));
|
|
27078
|
+
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')));
|
|
26787
27079
|
return () => {
|
|
26788
27080
|
log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
|
|
26789
27081
|
disposers.forEach(fn => fn());
|
|
26790
27082
|
};
|
|
26791
27083
|
};
|
|
26792
27084
|
|
|
26793
|
-
|
|
26794
|
-
|
|
26795
|
-
|
|
26796
|
-
|
|
26797
|
-
|
|
26798
|
-
|
|
26799
|
-
|
|
26800
|
-
|
|
26801
|
-
|
|
26802
|
-
|
|
26803
|
-
if (client.cache) {
|
|
26804
|
-
ingestInCache(payload, { cachedAt });
|
|
26805
|
-
const cacheKey = [
|
|
26806
|
-
'follow',
|
|
26807
|
-
'query',
|
|
26808
|
-
Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page), type: key }),
|
|
26809
|
-
];
|
|
26810
|
-
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
27085
|
+
class FollowerPaginationController extends PaginationController {
|
|
27086
|
+
async getRequest(queryParams, token) {
|
|
27087
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
27088
|
+
const options = token ? { token } : { limit };
|
|
27089
|
+
const client = getActiveClient();
|
|
27090
|
+
const path = client.userId === userId ? `/api/v4/me/followers` : `/api/v4/users/${userId}/followers`;
|
|
27091
|
+
const { data: queryResponse } = await this.http.get(path, {
|
|
27092
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
27093
|
+
});
|
|
27094
|
+
return queryResponse;
|
|
26811
27095
|
}
|
|
26812
|
-
|
|
26813
|
-
|
|
26814
|
-
|
|
26815
|
-
|
|
26816
|
-
|
|
26817
|
-
|
|
26818
|
-
|
|
26819
|
-
|
|
26820
|
-
|
|
26821
|
-
|
|
26822
|
-
|
|
26823
|
-
|
|
26824
|
-
|
|
26825
|
-
|
|
26826
|
-
|
|
26827
|
-
|
|
26828
|
-
|
|
26829
|
-
|
|
26830
|
-
|
|
27096
|
+
}
|
|
27097
|
+
|
|
27098
|
+
var EnumFollowActions;
|
|
27099
|
+
(function (EnumFollowActions) {
|
|
27100
|
+
EnumFollowActions["OnRequested"] = "onRequested";
|
|
27101
|
+
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
27102
|
+
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
27103
|
+
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
27104
|
+
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
27105
|
+
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
27106
|
+
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
27107
|
+
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
27108
|
+
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
27109
|
+
|
|
27110
|
+
class FollowerQueryStreamController extends QueryStreamController {
|
|
27111
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27112
|
+
super(query, cacheKey);
|
|
27113
|
+
this.notifyChange = notifyChange;
|
|
27114
|
+
this.preparePayload = preparePayload;
|
|
26831
27115
|
}
|
|
26832
|
-
|
|
26833
|
-
|
|
26834
|
-
|
|
26835
|
-
|
|
26836
|
-
|
|
26837
|
-
|
|
26838
|
-
|
|
26839
|
-
|
|
26840
|
-
|
|
27116
|
+
async saveToMainDB(response) {
|
|
27117
|
+
const processedPayload = await this.preparePayload(response);
|
|
27118
|
+
const client = getActiveClient();
|
|
27119
|
+
const cachedAt = client.cache && Date.now();
|
|
27120
|
+
if (client.cache) {
|
|
27121
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27122
|
+
}
|
|
27123
|
+
}
|
|
27124
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27125
|
+
var _a, _b;
|
|
27126
|
+
if (refresh) {
|
|
27127
|
+
pushToCache(this.cacheKey, {
|
|
27128
|
+
data: response.follows.map(getResolver('follow')),
|
|
27129
|
+
});
|
|
27130
|
+
}
|
|
27131
|
+
else {
|
|
27132
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27133
|
+
const follows = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27134
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...follows, ...response.follows.map(getResolver('follow'))])] }));
|
|
27135
|
+
}
|
|
27136
|
+
}
|
|
27137
|
+
reactor(action) {
|
|
27138
|
+
return (followStatus) => {
|
|
27139
|
+
var _a;
|
|
27140
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27141
|
+
if (this.query.userId !== followStatus.to || !collection)
|
|
27142
|
+
return;
|
|
27143
|
+
switch (action) {
|
|
27144
|
+
case EnumFollowActions.OnDeclined:
|
|
27145
|
+
case EnumFollowActions.OnCanceled:
|
|
27146
|
+
case EnumFollowActions.OnUnfollowed:
|
|
27147
|
+
case EnumFollowActions.OnDeleted:
|
|
27148
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
27149
|
+
break;
|
|
27150
|
+
case EnumFollowActions.OnRequested:
|
|
27151
|
+
case EnumFollowActions.OnAccepted:
|
|
27152
|
+
case EnumFollowActions.OnFollowed:
|
|
27153
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
27154
|
+
break;
|
|
27155
|
+
}
|
|
27156
|
+
pushToCache(this.cacheKey, collection);
|
|
27157
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27158
|
+
};
|
|
27159
|
+
}
|
|
27160
|
+
subscribeRTE(createSubscriber) {
|
|
27161
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27162
|
+
}
|
|
27163
|
+
}
|
|
27164
|
+
|
|
27165
|
+
const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
27166
|
+
const client = getActiveClient();
|
|
27167
|
+
const filter = (data) => {
|
|
27168
|
+
const userPayload = prepareUserPayload(data);
|
|
27169
|
+
ingestInCache(userPayload);
|
|
27170
|
+
const cacheData = pullFromCache([
|
|
27171
|
+
'follow',
|
|
27172
|
+
'get',
|
|
27173
|
+
getResolver('follow')({
|
|
27174
|
+
from: userPayload.users[0].userId,
|
|
27175
|
+
to: userId,
|
|
27176
|
+
}),
|
|
27177
|
+
]);
|
|
27178
|
+
if (!cacheData)
|
|
27179
|
+
return;
|
|
27180
|
+
callback(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data);
|
|
27181
|
+
};
|
|
27182
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
26841
27183
|
};
|
|
26842
27184
|
|
|
26843
|
-
|
|
26844
|
-
|
|
26845
|
-
|
|
26846
|
-
|
|
26847
|
-
|
|
26848
|
-
|
|
26849
|
-
|
|
26850
|
-
|
|
26851
|
-
|
|
26852
|
-
|
|
26853
|
-
|
|
26854
|
-
|
|
26855
|
-
|
|
26856
|
-
|
|
26857
|
-
|
|
26858
|
-
|
|
26859
|
-
|
|
26860
|
-
|
|
26861
|
-
|
|
26862
|
-
|
|
26863
|
-
|
|
26864
|
-
|
|
26865
|
-
|
|
26866
|
-
|
|
26867
|
-
|
|
26868
|
-
|
|
26869
|
-
|
|
26870
|
-
|
|
26871
|
-
|
|
27185
|
+
class FollowerLiveCollectionController extends LiveCollectionController {
|
|
27186
|
+
constructor(query, callback) {
|
|
27187
|
+
const queryStreamId = hash(query);
|
|
27188
|
+
const cacheKey = ['follow', 'collection', queryStreamId];
|
|
27189
|
+
const paginationController = new FollowerPaginationController(query);
|
|
27190
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27191
|
+
this.query = query;
|
|
27192
|
+
this.queryStreamController = new FollowerQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareFollowersPayload);
|
|
27193
|
+
this.callback = callback.bind(this);
|
|
27194
|
+
this.loadPage({ initial: true });
|
|
27195
|
+
}
|
|
27196
|
+
setup() {
|
|
27197
|
+
var _a;
|
|
27198
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27199
|
+
if (!collection) {
|
|
27200
|
+
pushToCache(this.cacheKey, {
|
|
27201
|
+
data: [],
|
|
27202
|
+
params: {},
|
|
27203
|
+
});
|
|
27204
|
+
}
|
|
27205
|
+
}
|
|
27206
|
+
async persistModel(queryPayload) {
|
|
27207
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27208
|
+
}
|
|
27209
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27210
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27211
|
+
}
|
|
27212
|
+
startSubscription() {
|
|
27213
|
+
return this.queryStreamController.subscribeRTE([
|
|
27214
|
+
{ fn: onUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
27215
|
+
{ fn: onUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
27216
|
+
{ fn: onFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
27217
|
+
{ fn: onFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
27218
|
+
{ fn: onFollowRequestCanceled, action: EnumFollowActions.OnCanceled },
|
|
27219
|
+
{ fn: onFollowerDeleted, action: EnumFollowActions.OnDeleted },
|
|
27220
|
+
{ fn: onLocalFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
27221
|
+
{ fn: onLocalFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
27222
|
+
{ fn: onLocalUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
27223
|
+
{ fn: onLocalUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
27224
|
+
{
|
|
27225
|
+
fn: onFollowerUserDeleted({ userId: this.query.userId }),
|
|
27226
|
+
action: EnumFollowActions.OnUserDeleted,
|
|
27227
|
+
},
|
|
27228
|
+
]);
|
|
27229
|
+
}
|
|
27230
|
+
notifyChange({ origin, loading, error }) {
|
|
27231
|
+
var _a, _b;
|
|
27232
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27233
|
+
if (!collection)
|
|
27234
|
+
return;
|
|
27235
|
+
const data = this.applyFilter((_b = collection.data
|
|
27236
|
+
.map(id => pullFromCache(['follow', 'get', id]))
|
|
27237
|
+
.filter(isNonNullable)
|
|
27238
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
27239
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
27240
|
+
return;
|
|
27241
|
+
this.callback({
|
|
27242
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
27243
|
+
data,
|
|
27244
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
27245
|
+
loading,
|
|
27246
|
+
error,
|
|
27247
|
+
});
|
|
27248
|
+
}
|
|
27249
|
+
applyFilter(data) {
|
|
27250
|
+
let followers = data;
|
|
27251
|
+
if (this.query.status && this.query.status !== "all" /* Amity.FollowStatusTypeEnum.All */) {
|
|
27252
|
+
followers = followers.filter(follower => follower.status === this.query.status);
|
|
27253
|
+
}
|
|
27254
|
+
followers = followers.filter(follower => {
|
|
27255
|
+
var _a;
|
|
27256
|
+
const fromUser = (_a = pullFromCache(['user', 'get', follower.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
27257
|
+
return (fromUser === null || fromUser === void 0 ? void 0 : fromUser.isDeleted) == null || (fromUser === null || fromUser === void 0 ? void 0 : fromUser.isDeleted) === false;
|
|
27258
|
+
});
|
|
27259
|
+
return followers;
|
|
27260
|
+
}
|
|
27261
|
+
}
|
|
26872
27262
|
|
|
26873
27263
|
/* begin_public_function
|
|
26874
27264
|
id: user.relationship.query_my_followers, user.relationship.query_followers
|
|
@@ -26894,69 +27284,14 @@ queryFollowers.locally = (query) => queryFollows.locally('followers', query);
|
|
|
26894
27284
|
const getFollowers = (params, callback, config) => {
|
|
26895
27285
|
const { log, cache } = getActiveClient();
|
|
26896
27286
|
if (!cache) {
|
|
26897
|
-
console.log(
|
|
27287
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
26898
27288
|
}
|
|
26899
27289
|
const timestamp = Date.now();
|
|
26900
27290
|
log(`getFollowers(tmpid: ${timestamp}) > listen`);
|
|
26901
|
-
const
|
|
26902
|
-
const
|
|
26903
|
-
const
|
|
26904
|
-
|
|
26905
|
-
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'follower' }];
|
|
26906
|
-
const responder = (data) => {
|
|
26907
|
-
var _a, _b;
|
|
26908
|
-
let followers = (_a = data.data
|
|
26909
|
-
.map(key => pullFromCache(['follow', 'get', key]))
|
|
26910
|
-
.filter(Boolean)
|
|
26911
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
26912
|
-
if (params.status && params.status !== 'all') {
|
|
26913
|
-
followers = filterByPropEquality(followers, 'status', params.status);
|
|
26914
|
-
}
|
|
26915
|
-
callback({
|
|
26916
|
-
onNextPage: onFetch,
|
|
26917
|
-
data: followers,
|
|
26918
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
26919
|
-
loading: data.loading,
|
|
26920
|
-
error: data.error,
|
|
26921
|
-
});
|
|
26922
|
-
};
|
|
26923
|
-
const realtimeRouter = (action) => (followStatus) => {
|
|
26924
|
-
var _a;
|
|
26925
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26926
|
-
if (params.userId !== followStatus.to || !collection)
|
|
26927
|
-
return;
|
|
26928
|
-
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
26929
|
-
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
26930
|
-
}
|
|
26931
|
-
else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
26932
|
-
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
26933
|
-
}
|
|
26934
|
-
pushToCache(cacheKey, collection);
|
|
26935
|
-
responder(collection);
|
|
26936
|
-
};
|
|
26937
|
-
const onFetch = (initial = false) => {
|
|
26938
|
-
var _a, _b, _c, _d;
|
|
26939
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26940
|
-
const followers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26941
|
-
if (!initial && followers.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
26942
|
-
return;
|
|
26943
|
-
const query = createQuery(queryFollowers, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
|
|
26944
|
-
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
26945
|
-
const data = {
|
|
26946
|
-
loading,
|
|
26947
|
-
error,
|
|
26948
|
-
params: { page },
|
|
26949
|
-
data: followers,
|
|
26950
|
-
};
|
|
26951
|
-
if (result) {
|
|
26952
|
-
data.data = [...new Set([...followers, ...result.map(getResolver('follow'))])];
|
|
26953
|
-
}
|
|
26954
|
-
pushToCache(cacheKey, data);
|
|
26955
|
-
responder(data);
|
|
26956
|
-
}, queryOptions(policy));
|
|
26957
|
-
};
|
|
26958
|
-
disposers.push(onFollowerRequested(realtimeRouter('onRequested')), onFollowRequestAccepted(realtimeRouter('onAccepted')), onFollowRequestDeclined(realtimeRouter('onDeclined')), onFollowRequestCanceled(realtimeRouter('onCanceled')), onUserFollowed(realtimeRouter('onFollowed')), onUserUnfollowed(realtimeRouter('onUnfollowed')), onFollowerDeleted(realtimeRouter('onDeleted')));
|
|
26959
|
-
onFetch(true);
|
|
27291
|
+
const followerLiveCollection = new FollowerLiveCollectionController(params, callback);
|
|
27292
|
+
const disposers = followerLiveCollection.startSubscription();
|
|
27293
|
+
const cacheKey = followerLiveCollection.getCacheKey();
|
|
27294
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
26960
27295
|
return () => {
|
|
26961
27296
|
log(`getFollowers(tmpid: ${timestamp}) > dispose`);
|
|
26962
27297
|
disposers.forEach(fn => fn());
|
|
@@ -26964,35 +27299,173 @@ const getFollowers = (params, callback, config) => {
|
|
|
26964
27299
|
};
|
|
26965
27300
|
/* end_public_function */
|
|
26966
27301
|
|
|
26967
|
-
|
|
26968
|
-
|
|
26969
|
-
|
|
26970
|
-
|
|
26971
|
-
|
|
26972
|
-
|
|
26973
|
-
|
|
26974
|
-
|
|
26975
|
-
|
|
26976
|
-
|
|
26977
|
-
|
|
26978
|
-
|
|
26979
|
-
|
|
26980
|
-
|
|
26981
|
-
|
|
26982
|
-
|
|
26983
|
-
|
|
26984
|
-
|
|
26985
|
-
|
|
26986
|
-
|
|
26987
|
-
|
|
26988
|
-
|
|
26989
|
-
|
|
26990
|
-
|
|
26991
|
-
|
|
26992
|
-
|
|
26993
|
-
|
|
26994
|
-
|
|
26995
|
-
|
|
27302
|
+
class FollowingPaginationController extends PaginationController {
|
|
27303
|
+
async getRequest(queryParams, token) {
|
|
27304
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
27305
|
+
const options = token ? { token } : { limit };
|
|
27306
|
+
const client = getActiveClient();
|
|
27307
|
+
const path = client.userId === userId ? `/api/v4/me/following` : `/api/v4/users/${userId}/following`;
|
|
27308
|
+
const { data: queryResponse } = await this.http.get(path, {
|
|
27309
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
27310
|
+
});
|
|
27311
|
+
return queryResponse;
|
|
27312
|
+
}
|
|
27313
|
+
}
|
|
27314
|
+
|
|
27315
|
+
class FollowingQueryStreamController extends QueryStreamController {
|
|
27316
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27317
|
+
super(query, cacheKey);
|
|
27318
|
+
this.notifyChange = notifyChange;
|
|
27319
|
+
this.preparePayload = preparePayload;
|
|
27320
|
+
}
|
|
27321
|
+
async saveToMainDB(response) {
|
|
27322
|
+
const processedPayload = await this.preparePayload(response);
|
|
27323
|
+
const client = getActiveClient();
|
|
27324
|
+
const cachedAt = client.cache && Date.now();
|
|
27325
|
+
if (client.cache) {
|
|
27326
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27327
|
+
}
|
|
27328
|
+
}
|
|
27329
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27330
|
+
var _a, _b;
|
|
27331
|
+
if (refresh) {
|
|
27332
|
+
pushToCache(this.cacheKey, {
|
|
27333
|
+
data: response.follows.map(getResolver('follow')),
|
|
27334
|
+
});
|
|
27335
|
+
}
|
|
27336
|
+
else {
|
|
27337
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27338
|
+
const follows = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27339
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...follows, ...response.follows.map(getResolver('follow'))])] }));
|
|
27340
|
+
}
|
|
27341
|
+
}
|
|
27342
|
+
reactor(action) {
|
|
27343
|
+
return (followStatus) => {
|
|
27344
|
+
var _a;
|
|
27345
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27346
|
+
if (this.query.userId !== followStatus.from || !collection)
|
|
27347
|
+
return;
|
|
27348
|
+
switch (action) {
|
|
27349
|
+
case EnumFollowActions.OnDeclined:
|
|
27350
|
+
case EnumFollowActions.OnCanceled:
|
|
27351
|
+
case EnumFollowActions.OnUnfollowed:
|
|
27352
|
+
case EnumFollowActions.OnDeleted:
|
|
27353
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
27354
|
+
break;
|
|
27355
|
+
case EnumFollowActions.OnRequested:
|
|
27356
|
+
case EnumFollowActions.OnAccepted:
|
|
27357
|
+
case EnumFollowActions.OnFollowed:
|
|
27358
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
27359
|
+
break;
|
|
27360
|
+
}
|
|
27361
|
+
pushToCache(this.cacheKey, collection);
|
|
27362
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27363
|
+
};
|
|
27364
|
+
}
|
|
27365
|
+
subscribeRTE(createSubscriber) {
|
|
27366
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27367
|
+
}
|
|
27368
|
+
}
|
|
27369
|
+
|
|
27370
|
+
const onFollowingUserDeleted = ({ userId }) => (callback) => {
|
|
27371
|
+
const client = getActiveClient();
|
|
27372
|
+
const filter = (data) => {
|
|
27373
|
+
const userPayload = prepareUserPayload(data);
|
|
27374
|
+
ingestInCache(userPayload);
|
|
27375
|
+
const cacheData = pullFromCache([
|
|
27376
|
+
'follow',
|
|
27377
|
+
'get',
|
|
27378
|
+
getResolver('follow')({
|
|
27379
|
+
from: userId,
|
|
27380
|
+
to: userPayload.users[0].userId,
|
|
27381
|
+
}),
|
|
27382
|
+
]);
|
|
27383
|
+
if (!cacheData)
|
|
27384
|
+
return;
|
|
27385
|
+
callback(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data);
|
|
27386
|
+
};
|
|
27387
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
27388
|
+
};
|
|
27389
|
+
|
|
27390
|
+
class FollowingLiveCollectionController extends LiveCollectionController {
|
|
27391
|
+
constructor(query, callback) {
|
|
27392
|
+
const queryStreamId = hash(query);
|
|
27393
|
+
const cacheKey = ['follow', 'collection', queryStreamId];
|
|
27394
|
+
const paginationController = new FollowingPaginationController(query);
|
|
27395
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27396
|
+
this.query = query;
|
|
27397
|
+
this.queryStreamController = new FollowingQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareFollowingsPayload);
|
|
27398
|
+
this.callback = callback.bind(this);
|
|
27399
|
+
this.loadPage({ initial: true });
|
|
27400
|
+
}
|
|
27401
|
+
setup() {
|
|
27402
|
+
var _a;
|
|
27403
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27404
|
+
if (!collection) {
|
|
27405
|
+
pushToCache(this.cacheKey, {
|
|
27406
|
+
data: [],
|
|
27407
|
+
params: {},
|
|
27408
|
+
});
|
|
27409
|
+
}
|
|
27410
|
+
}
|
|
27411
|
+
async persistModel(queryPayload) {
|
|
27412
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27413
|
+
}
|
|
27414
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27415
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27416
|
+
}
|
|
27417
|
+
startSubscription() {
|
|
27418
|
+
return this.queryStreamController.subscribeRTE([
|
|
27419
|
+
{ fn: onFollowerRequested, action: EnumFollowActions.OnRequested },
|
|
27420
|
+
{ fn: onFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
27421
|
+
{ fn: onFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
27422
|
+
{ fn: onFollowRequestCanceled, action: EnumFollowActions.OnCanceled },
|
|
27423
|
+
{ fn: onUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
27424
|
+
{ fn: onUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
27425
|
+
{ fn: onFollowerDeleted, action: EnumFollowActions.OnDeleted },
|
|
27426
|
+
{ fn: onLocalFollowerRequested, action: EnumFollowActions.OnRequested },
|
|
27427
|
+
{ fn: onLocalFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
27428
|
+
{ fn: onLocalFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
27429
|
+
{ fn: onLocalUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
27430
|
+
{ fn: onLocalUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
27431
|
+
{
|
|
27432
|
+
fn: onFollowingUserDeleted({ userId: this.query.userId }),
|
|
27433
|
+
action: EnumFollowActions.OnUserDeleted,
|
|
27434
|
+
},
|
|
27435
|
+
]);
|
|
27436
|
+
}
|
|
27437
|
+
notifyChange({ origin, loading, error }) {
|
|
27438
|
+
var _a, _b;
|
|
27439
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27440
|
+
if (!collection)
|
|
27441
|
+
return;
|
|
27442
|
+
const data = this.applyFilter((_b = collection.data
|
|
27443
|
+
.map(id => pullFromCache(['follow', 'get', id]))
|
|
27444
|
+
.filter(isNonNullable)
|
|
27445
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
27446
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
27447
|
+
return;
|
|
27448
|
+
this.callback({
|
|
27449
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
27450
|
+
data,
|
|
27451
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
27452
|
+
loading,
|
|
27453
|
+
error,
|
|
27454
|
+
});
|
|
27455
|
+
}
|
|
27456
|
+
applyFilter(data) {
|
|
27457
|
+
let followings = data;
|
|
27458
|
+
if (this.query.status && this.query.status !== "all" /* Amity.FollowStatusTypeEnum.All */) {
|
|
27459
|
+
followings = followings.filter(following => following.status === this.query.status);
|
|
27460
|
+
}
|
|
27461
|
+
followings = followings.filter(following => {
|
|
27462
|
+
var _a;
|
|
27463
|
+
const toUser = (_a = pullFromCache(['user', 'get', following.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
27464
|
+
return (toUser === null || toUser === void 0 ? void 0 : toUser.isDeleted) == null || (toUser === null || toUser === void 0 ? void 0 : toUser.isDeleted) === false;
|
|
27465
|
+
});
|
|
27466
|
+
return followings;
|
|
27467
|
+
}
|
|
27468
|
+
}
|
|
26996
27469
|
|
|
26997
27470
|
/* begin_public_function
|
|
26998
27471
|
id: user.relationship.query_my_followings, user.relationship.query_followings
|
|
@@ -27022,65 +27495,10 @@ const getFollowings = (params, callback, config) => {
|
|
|
27022
27495
|
}
|
|
27023
27496
|
const timestamp = Date.now();
|
|
27024
27497
|
log(`getFollowings(tmpid: ${timestamp}) > listen`);
|
|
27025
|
-
const
|
|
27026
|
-
const
|
|
27027
|
-
const
|
|
27028
|
-
|
|
27029
|
-
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'following' }];
|
|
27030
|
-
const responder = (data) => {
|
|
27031
|
-
var _a, _b;
|
|
27032
|
-
let followings = (_a = data.data
|
|
27033
|
-
.map(key => pullFromCache(['follow', 'get', key]))
|
|
27034
|
-
.filter(Boolean)
|
|
27035
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
27036
|
-
if (params.status && params.status !== 'all') {
|
|
27037
|
-
followings = filterByPropEquality(followings, 'status', params.status);
|
|
27038
|
-
}
|
|
27039
|
-
callback({
|
|
27040
|
-
onNextPage: onFetch,
|
|
27041
|
-
data: followings,
|
|
27042
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
27043
|
-
loading: data.loading,
|
|
27044
|
-
error: data.error,
|
|
27045
|
-
});
|
|
27046
|
-
};
|
|
27047
|
-
const realtimeRouter = (action) => (followStatus) => {
|
|
27048
|
-
var _a;
|
|
27049
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27050
|
-
if (params.userId !== followStatus.from || !collection)
|
|
27051
|
-
return;
|
|
27052
|
-
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
27053
|
-
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
27054
|
-
}
|
|
27055
|
-
else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
27056
|
-
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
27057
|
-
}
|
|
27058
|
-
pushToCache(cacheKey, collection);
|
|
27059
|
-
responder(collection);
|
|
27060
|
-
};
|
|
27061
|
-
const onFetch = (initial = false) => {
|
|
27062
|
-
var _a, _b, _c, _d;
|
|
27063
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27064
|
-
const followings = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27065
|
-
if (!initial && followings.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
27066
|
-
return;
|
|
27067
|
-
const query = createQuery(queryFollowings, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
|
|
27068
|
-
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
27069
|
-
const data = {
|
|
27070
|
-
loading,
|
|
27071
|
-
error,
|
|
27072
|
-
params: { page },
|
|
27073
|
-
data: followings,
|
|
27074
|
-
};
|
|
27075
|
-
if (result) {
|
|
27076
|
-
data.data = [...new Set([...followings, ...result.map(getResolver('follow'))])];
|
|
27077
|
-
}
|
|
27078
|
-
pushToCache(cacheKey, data);
|
|
27079
|
-
responder(data);
|
|
27080
|
-
}, queryOptions(policy));
|
|
27081
|
-
};
|
|
27082
|
-
disposers.push(onFollowerRequested(realtimeRouter('onRequested')), onFollowRequestAccepted(realtimeRouter('onAccepted')), onFollowRequestDeclined(realtimeRouter('onDeclined')), onFollowRequestCanceled(realtimeRouter('onCanceled')), onUserFollowed(realtimeRouter('onFollowed')), onUserUnfollowed(realtimeRouter('onUnfollowed')), onFollowerDeleted(realtimeRouter('onDeleted')));
|
|
27083
|
-
onFetch(true);
|
|
27498
|
+
const followingLiveCollection = new FollowingLiveCollectionController(params, callback);
|
|
27499
|
+
const disposers = followingLiveCollection.startSubscription();
|
|
27500
|
+
const cacheKey = followingLiveCollection.getCacheKey();
|
|
27501
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
27084
27502
|
return () => {
|
|
27085
27503
|
log(`getFollowings(tmpid: ${timestamp}) > dispose`);
|
|
27086
27504
|
disposers.forEach(fn => fn());
|
|
@@ -27168,6 +27586,11 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
27168
27586
|
onFollowRequestAccepted: onFollowRequestAccepted,
|
|
27169
27587
|
onFollowRequestDeclined: onFollowRequestDeclined,
|
|
27170
27588
|
onFollowInfoUpdated: onFollowInfoUpdated,
|
|
27589
|
+
onLocalUserFollowed: onLocalUserFollowed,
|
|
27590
|
+
onLocalUserUnfollowed: onLocalUserUnfollowed,
|
|
27591
|
+
onLocalFollowerRequested: onLocalFollowerRequested,
|
|
27592
|
+
onLocalFollowRequestAccepted: onLocalFollowRequestAccepted,
|
|
27593
|
+
onLocalFollowRequestDeclined: onLocalFollowRequestDeclined,
|
|
27171
27594
|
observeFollowInfo: observeFollowInfo,
|
|
27172
27595
|
observeFollowers: observeFollowers,
|
|
27173
27596
|
observeFollowings: observeFollowings,
|
|
@@ -27202,12 +27625,13 @@ const getUserByIds = async (userIds) => {
|
|
|
27202
27625
|
const { data } = await client.http.get(`/api/v3/users/list`, {
|
|
27203
27626
|
params: { userIds: encodedUserIds },
|
|
27204
27627
|
});
|
|
27628
|
+
const payload = prepareUserPayload(data);
|
|
27205
27629
|
const cachedAt = client.cache && Date.now();
|
|
27206
27630
|
if (client.cache)
|
|
27207
|
-
ingestInCache(
|
|
27631
|
+
ingestInCache(payload, { cachedAt });
|
|
27208
27632
|
fireEvent('user.fetched', data);
|
|
27209
27633
|
return {
|
|
27210
|
-
data:
|
|
27634
|
+
data: payload.users.map(user => LinkedObject.user(user)),
|
|
27211
27635
|
cachedAt,
|
|
27212
27636
|
};
|
|
27213
27637
|
};
|
|
@@ -27265,20 +27689,14 @@ getUserByIds.locally = (userIds) => {
|
|
|
27265
27689
|
const updateUser = async (userId, patch) => {
|
|
27266
27690
|
const client = getActiveClient();
|
|
27267
27691
|
client.log('user/updateUser', userId, patch);
|
|
27268
|
-
// API-FIX: Endpoint is malformed, userId should be a url param.
|
|
27269
|
-
/*
|
|
27270
|
-
const { data } = await client.http.put<Amity.Response<UserPayload>>(
|
|
27271
|
-
`/api/v3/users/${userId}`, patch,
|
|
27272
|
-
)
|
|
27273
|
-
*/
|
|
27274
27692
|
const { data } = await client.http.put(`/api/v3/users/`, Object.assign(Object.assign({ userId }, patch), { createNewUserWhenNotFound: false }));
|
|
27693
|
+
const payload = prepareUserPayload(data);
|
|
27275
27694
|
const cachedAt = client.cache && Date.now();
|
|
27276
27695
|
if (client.cache)
|
|
27277
|
-
ingestInCache(
|
|
27278
|
-
const { users } = data;
|
|
27696
|
+
ingestInCache(payload, { cachedAt });
|
|
27279
27697
|
fireEvent('user.updated', data);
|
|
27280
27698
|
return {
|
|
27281
|
-
data: users.find(user => user.userId === userId),
|
|
27699
|
+
data: payload.users.find(user => user.userId === userId),
|
|
27282
27700
|
cachedAt,
|
|
27283
27701
|
};
|
|
27284
27702
|
};
|
|
@@ -27302,11 +27720,12 @@ const updateUser = async (userId, patch) => {
|
|
|
27302
27720
|
const flagUser = async (userId) => {
|
|
27303
27721
|
const client = getActiveClient();
|
|
27304
27722
|
client.log('user/flagUser', userId);
|
|
27305
|
-
const { data
|
|
27723
|
+
const { data } = await client.http.post(`api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
27724
|
+
const payload = prepareUserPayload(data);
|
|
27306
27725
|
if (client.cache) {
|
|
27307
27726
|
ingestInCache(payload);
|
|
27308
27727
|
}
|
|
27309
|
-
fireEvent('user.flagged',
|
|
27728
|
+
fireEvent('user.flagged', data);
|
|
27310
27729
|
return !!payload;
|
|
27311
27730
|
};
|
|
27312
27731
|
/* end_public_function */
|
|
@@ -27329,11 +27748,12 @@ const flagUser = async (userId) => {
|
|
|
27329
27748
|
const unflagUser = async (userId) => {
|
|
27330
27749
|
const client = getActiveClient();
|
|
27331
27750
|
client.log('user/unflag', userId);
|
|
27332
|
-
const { data
|
|
27751
|
+
const { data } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
27752
|
+
const payload = prepareUserPayload(data);
|
|
27333
27753
|
if (client.cache) {
|
|
27334
27754
|
ingestInCache(payload);
|
|
27335
27755
|
}
|
|
27336
|
-
fireEvent('user.unflagged',
|
|
27756
|
+
fireEvent('user.unflagged', data);
|
|
27337
27757
|
return !!payload;
|
|
27338
27758
|
};
|
|
27339
27759
|
/* end_public_function */
|
|
@@ -27361,74 +27781,6 @@ const isUserFlaggedByMe = async (userId) => {
|
|
|
27361
27781
|
};
|
|
27362
27782
|
/* end_public_function */
|
|
27363
27783
|
|
|
27364
|
-
/**
|
|
27365
|
-
* ```js
|
|
27366
|
-
* import { onUserUpdated } from '@amityco/ts-sdk-react-native'
|
|
27367
|
-
* const dispose = onUserUpdated(user => {
|
|
27368
|
-
* // ...
|
|
27369
|
-
* })
|
|
27370
|
-
* ```
|
|
27371
|
-
*
|
|
27372
|
-
* Fired when a {@link Amity.InternalUser} has been updated
|
|
27373
|
-
*
|
|
27374
|
-
* @param callback The function to call when the event was fired
|
|
27375
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27376
|
-
*
|
|
27377
|
-
* @category User Events
|
|
27378
|
-
*/
|
|
27379
|
-
const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
|
|
27380
|
-
|
|
27381
|
-
/**
|
|
27382
|
-
* ```js
|
|
27383
|
-
* import { onUserFlagged } from '@amityco/ts-sdk-react-native'
|
|
27384
|
-
* const dispose = onUserFlagged(user => {
|
|
27385
|
-
* // ...
|
|
27386
|
-
* })
|
|
27387
|
-
* ```
|
|
27388
|
-
*
|
|
27389
|
-
* Fired when a {@link Amity.InternalUser} has been flagged
|
|
27390
|
-
*
|
|
27391
|
-
* @param callback The function to call when the event was fired
|
|
27392
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27393
|
-
*
|
|
27394
|
-
* @category User Events
|
|
27395
|
-
*/
|
|
27396
|
-
const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
|
|
27397
|
-
|
|
27398
|
-
/**
|
|
27399
|
-
* ```js
|
|
27400
|
-
* import { onUserUnflagged } from '@amityco/ts-sdk-react-native'
|
|
27401
|
-
* const dispose = onUserUnflagged(user => {
|
|
27402
|
-
* // ...
|
|
27403
|
-
* })
|
|
27404
|
-
* ```
|
|
27405
|
-
*
|
|
27406
|
-
* Fired when a flag has been removed from a {@link Amity.InternalUser}
|
|
27407
|
-
*
|
|
27408
|
-
* @param callback The function to call when the event was fired
|
|
27409
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27410
|
-
*
|
|
27411
|
-
* @category User Events
|
|
27412
|
-
*/
|
|
27413
|
-
const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
|
|
27414
|
-
|
|
27415
|
-
/**
|
|
27416
|
-
* ```js
|
|
27417
|
-
* import { onUserFlagCleared } from '@amityco/ts-sdk-react-native'
|
|
27418
|
-
* const dispose = onUserFlagCleared(user => {
|
|
27419
|
-
* // ...
|
|
27420
|
-
* })
|
|
27421
|
-
* ```
|
|
27422
|
-
*
|
|
27423
|
-
* Fired when flags have been cleared for a {@link Amity.InternalUser}
|
|
27424
|
-
*
|
|
27425
|
-
* @param callback The function to call when the event was fired
|
|
27426
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27427
|
-
*
|
|
27428
|
-
* @category User Events
|
|
27429
|
-
*/
|
|
27430
|
-
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
27431
|
-
|
|
27432
27784
|
/**
|
|
27433
27785
|
* ```js
|
|
27434
27786
|
* import { onUserFetched } from '@amityco/ts-sdk-react-native'
|
|
@@ -27464,10 +27816,17 @@ const getUser$2 = async (userId) => {
|
|
|
27464
27816
|
const client = getActiveClient();
|
|
27465
27817
|
client.log('user/getUser', userId);
|
|
27466
27818
|
isInTombstone('user', userId);
|
|
27467
|
-
let data;
|
|
27468
27819
|
try {
|
|
27469
|
-
const
|
|
27470
|
-
|
|
27820
|
+
const { data } = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
|
|
27821
|
+
const cachedAt = client.cache && Date.now();
|
|
27822
|
+
const payload = prepareUserPayload(data);
|
|
27823
|
+
if (client.cache)
|
|
27824
|
+
ingestInCache(payload, { cachedAt });
|
|
27825
|
+
fireEvent('user.fetched', data);
|
|
27826
|
+
return {
|
|
27827
|
+
data: payload.users.find(user => user.userId === userId),
|
|
27828
|
+
cachedAt,
|
|
27829
|
+
};
|
|
27471
27830
|
}
|
|
27472
27831
|
catch (error) {
|
|
27473
27832
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
@@ -27475,15 +27834,6 @@ const getUser$2 = async (userId) => {
|
|
|
27475
27834
|
}
|
|
27476
27835
|
throw error;
|
|
27477
27836
|
}
|
|
27478
|
-
const cachedAt = client.cache && Date.now();
|
|
27479
|
-
if (client.cache)
|
|
27480
|
-
ingestInCache(data, { cachedAt });
|
|
27481
|
-
const { users } = data;
|
|
27482
|
-
fireEvent('user.fetched', data);
|
|
27483
|
-
return {
|
|
27484
|
-
data: users.find(user => user.userId === userId),
|
|
27485
|
-
cachedAt,
|
|
27486
|
-
};
|
|
27487
27837
|
};
|
|
27488
27838
|
/**
|
|
27489
27839
|
* ```js
|
|
@@ -27541,7 +27891,7 @@ const getUser$1 = (userId, callback) => {
|
|
|
27541
27891
|
return liveObject(userId, reactor, 'userId', getUser$2, [
|
|
27542
27892
|
onUserFetched,
|
|
27543
27893
|
onUserUpdated,
|
|
27544
|
-
onUserDeleted,
|
|
27894
|
+
onUserDeleted$2,
|
|
27545
27895
|
onUserFlagged,
|
|
27546
27896
|
onUserUnflagged,
|
|
27547
27897
|
onUserFlagCleared,
|
|
@@ -27549,114 +27899,144 @@ const getUser$1 = (userId, callback) => {
|
|
|
27549
27899
|
};
|
|
27550
27900
|
/* end_public_function */
|
|
27551
27901
|
|
|
27552
|
-
|
|
27553
|
-
|
|
27554
|
-
|
|
27555
|
-
|
|
27556
|
-
|
|
27557
|
-
|
|
27558
|
-
|
|
27559
|
-
|
|
27560
|
-
*
|
|
27561
|
-
* @param query The query parameters
|
|
27562
|
-
* @returns A page of {@link Amity.InternalUser} objects
|
|
27563
|
-
*
|
|
27564
|
-
* @category User API
|
|
27565
|
-
* @async
|
|
27566
|
-
*/
|
|
27567
|
-
const queryUsers = async (query = {}) => {
|
|
27568
|
-
const client = getActiveClient();
|
|
27569
|
-
client.log('user/queryUsers', query);
|
|
27570
|
-
const { page, limit = 10, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query, ["page", "limit", "displayName", "filter", "sortBy"]);
|
|
27571
|
-
const { data } = await client.http.get(`/api/v3/users`, {
|
|
27572
|
-
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter,
|
|
27573
|
-
sortBy, options: page ? { token: page } : { limit } }),
|
|
27574
|
-
});
|
|
27575
|
-
// unpacking
|
|
27576
|
-
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
27577
|
-
const { users } = payload;
|
|
27578
|
-
const cachedAt = client.cache && Date.now();
|
|
27579
|
-
if (client.cache) {
|
|
27580
|
-
ingestInCache(payload, { cachedAt });
|
|
27581
|
-
/*
|
|
27582
|
-
* using a query as a cache key over params because if the keyword, filter, sort
|
|
27583
|
-
* change the API will NOT cache results, when it should
|
|
27584
|
-
*/
|
|
27585
|
-
const cacheKey = [
|
|
27586
|
-
'user',
|
|
27587
|
-
'query',
|
|
27588
|
-
Object.assign(Object.assign({}, query), { options: { limit, token: page } }),
|
|
27589
|
-
];
|
|
27590
|
-
pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
|
|
27902
|
+
class UserPaginationController extends PaginationController {
|
|
27903
|
+
async getRequest(queryParams, token) {
|
|
27904
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
27905
|
+
const options = token ? { token } : { limit };
|
|
27906
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
27907
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
27908
|
+
});
|
|
27909
|
+
return queryResponse;
|
|
27591
27910
|
}
|
|
27592
|
-
|
|
27593
|
-
|
|
27594
|
-
|
|
27595
|
-
|
|
27596
|
-
|
|
27597
|
-
|
|
27598
|
-
|
|
27599
|
-
|
|
27600
|
-
|
|
27601
|
-
|
|
27602
|
-
|
|
27603
|
-
|
|
27604
|
-
|
|
27605
|
-
|
|
27606
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
27607
|
-
*
|
|
27608
|
-
* @param query The query parameters
|
|
27609
|
-
* @returns A page of {@link Amity.InternalUser} objects
|
|
27610
|
-
*
|
|
27611
|
-
* @category User API
|
|
27612
|
-
*/
|
|
27613
|
-
queryUsers.locally = (query = {}) => {
|
|
27614
|
-
var _a, _b, _c;
|
|
27615
|
-
const client = getActiveClient();
|
|
27616
|
-
client.log('user/queryUsers.locally', query);
|
|
27617
|
-
if (!client.cache)
|
|
27618
|
-
return;
|
|
27619
|
-
const { limit = 10, page } = query !== null && query !== void 0 ? query : {};
|
|
27620
|
-
const cacheKey = [
|
|
27621
|
-
'user',
|
|
27622
|
-
'query',
|
|
27623
|
-
Object.assign(Object.assign({}, query), { options: {
|
|
27624
|
-
limit,
|
|
27625
|
-
token: page,
|
|
27626
|
-
} }),
|
|
27627
|
-
];
|
|
27628
|
-
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
27629
|
-
const users = (_b = data === null || data === void 0 ? void 0 : data.users.map(userId => pullFromCache(['user', 'get', userId])).filter(Boolean).map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
27630
|
-
return users.length > 0 && users.length === ((_c = data === null || data === void 0 ? void 0 : data.users) === null || _c === void 0 ? void 0 : _c.length)
|
|
27631
|
-
? {
|
|
27632
|
-
data: users,
|
|
27633
|
-
cachedAt,
|
|
27634
|
-
paging: data === null || data === void 0 ? void 0 : data.paging,
|
|
27911
|
+
}
|
|
27912
|
+
|
|
27913
|
+
class UserQueryStreamController extends QueryStreamController {
|
|
27914
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27915
|
+
super(query, cacheKey);
|
|
27916
|
+
this.notifyChange = notifyChange;
|
|
27917
|
+
this.preparePayload = preparePayload;
|
|
27918
|
+
}
|
|
27919
|
+
async saveToMainDB(response) {
|
|
27920
|
+
const processedPayload = await this.preparePayload(response);
|
|
27921
|
+
const client = getActiveClient();
|
|
27922
|
+
const cachedAt = client.cache && Date.now();
|
|
27923
|
+
if (client.cache) {
|
|
27924
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27635
27925
|
}
|
|
27636
|
-
|
|
27637
|
-
|
|
27926
|
+
}
|
|
27927
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27928
|
+
var _a, _b;
|
|
27929
|
+
if (refresh) {
|
|
27930
|
+
pushToCache(this.cacheKey, {
|
|
27931
|
+
data: response.users.map(getResolver('user')),
|
|
27932
|
+
});
|
|
27933
|
+
}
|
|
27934
|
+
else {
|
|
27935
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27936
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27937
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
27938
|
+
}
|
|
27939
|
+
}
|
|
27940
|
+
reactor(action) {
|
|
27941
|
+
return (user) => {
|
|
27942
|
+
var _a;
|
|
27943
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27944
|
+
if (!collection)
|
|
27945
|
+
return;
|
|
27946
|
+
/*
|
|
27947
|
+
* Simply update a collection and let responder decide what to do with data
|
|
27948
|
+
*/
|
|
27949
|
+
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
27950
|
+
pushToCache(this.cacheKey, collection);
|
|
27951
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27952
|
+
};
|
|
27953
|
+
}
|
|
27954
|
+
subscribeRTE(createSubscriber) {
|
|
27955
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27956
|
+
}
|
|
27957
|
+
}
|
|
27638
27958
|
|
|
27639
|
-
|
|
27640
|
-
|
|
27641
|
-
|
|
27642
|
-
|
|
27643
|
-
const
|
|
27644
|
-
|
|
27645
|
-
|
|
27646
|
-
|
|
27647
|
-
|
|
27648
|
-
|
|
27649
|
-
case 'lastCreated':
|
|
27650
|
-
users = users.sort(sortByLastCreated);
|
|
27651
|
-
break;
|
|
27652
|
-
default:
|
|
27653
|
-
users = users
|
|
27654
|
-
// this needs to be aligned with the backend data type
|
|
27655
|
-
.map(u => (u.displayName ? u : Object.assign(Object.assign({}, u), { displayName: '' })))
|
|
27656
|
-
.sort(sortByDisplayName);
|
|
27959
|
+
class UserLiveCollectionController extends LiveCollectionController {
|
|
27960
|
+
constructor(query, callback) {
|
|
27961
|
+
const queryStreamId = hash(query);
|
|
27962
|
+
const cacheKey = ['user', 'collection', queryStreamId];
|
|
27963
|
+
const paginationController = new UserPaginationController(query);
|
|
27964
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27965
|
+
this.query = query;
|
|
27966
|
+
this.queryStreamController = new UserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareUserPayload);
|
|
27967
|
+
this.callback = callback.bind(this);
|
|
27968
|
+
this.loadPage({ initial: true });
|
|
27657
27969
|
}
|
|
27658
|
-
|
|
27659
|
-
|
|
27970
|
+
setup() {
|
|
27971
|
+
var _a;
|
|
27972
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27973
|
+
if (!collection) {
|
|
27974
|
+
pushToCache(this.cacheKey, {
|
|
27975
|
+
data: [],
|
|
27976
|
+
params: {},
|
|
27977
|
+
});
|
|
27978
|
+
}
|
|
27979
|
+
}
|
|
27980
|
+
async persistModel(queryPayload) {
|
|
27981
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27982
|
+
}
|
|
27983
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27984
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27985
|
+
}
|
|
27986
|
+
startSubscription() {
|
|
27987
|
+
return this.queryStreamController.subscribeRTE([
|
|
27988
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
27989
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
27990
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
27991
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
27992
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
27993
|
+
]);
|
|
27994
|
+
}
|
|
27995
|
+
notifyChange({ origin, loading, error }) {
|
|
27996
|
+
var _a, _b;
|
|
27997
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27998
|
+
if (!collection)
|
|
27999
|
+
return;
|
|
28000
|
+
const data = this.applyFilter((_b = collection.data
|
|
28001
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
28002
|
+
.filter(isNonNullable)
|
|
28003
|
+
.map(({ data }) => data)
|
|
28004
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
28005
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
28006
|
+
return;
|
|
28007
|
+
this.callback({
|
|
28008
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
28009
|
+
data,
|
|
28010
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
28011
|
+
loading,
|
|
28012
|
+
error,
|
|
28013
|
+
});
|
|
28014
|
+
}
|
|
28015
|
+
applyFilter(data) {
|
|
28016
|
+
let users = data;
|
|
28017
|
+
if (!this.query.displayName) {
|
|
28018
|
+
const sortFn = (() => {
|
|
28019
|
+
switch (this.query.sortBy) {
|
|
28020
|
+
case 'firstCreated':
|
|
28021
|
+
return sortByFirstCreated;
|
|
28022
|
+
case 'lastCreated':
|
|
28023
|
+
return sortByLastCreated;
|
|
28024
|
+
case 'displayName':
|
|
28025
|
+
return sortByDisplayName;
|
|
28026
|
+
default:
|
|
28027
|
+
return sortByLastCreated;
|
|
28028
|
+
}
|
|
28029
|
+
})();
|
|
28030
|
+
users = users.sort(sortFn);
|
|
28031
|
+
}
|
|
28032
|
+
if (this.query.filter === 'flagged') {
|
|
28033
|
+
users = users.filter(user => !!user.hashFlag);
|
|
28034
|
+
}
|
|
28035
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
28036
|
+
return users;
|
|
28037
|
+
}
|
|
28038
|
+
}
|
|
28039
|
+
|
|
27660
28040
|
/* begin_public_function
|
|
27661
28041
|
id: user.query
|
|
27662
28042
|
*/
|
|
@@ -27684,63 +28064,10 @@ const getUsers = (params, callback, config) => {
|
|
|
27684
28064
|
}
|
|
27685
28065
|
const timestamp = Date.now();
|
|
27686
28066
|
log(`liveUsers(tmpid: ${timestamp}) > listen`);
|
|
27687
|
-
const
|
|
27688
|
-
const
|
|
27689
|
-
const
|
|
27690
|
-
|
|
27691
|
-
const cacheKey = ['user', 'collection', uuid()];
|
|
27692
|
-
const responder = (data, isEventModel = false) => {
|
|
27693
|
-
var _a, _b;
|
|
27694
|
-
const users = (_a = data.data
|
|
27695
|
-
.map(userId => pullFromCache(['user', 'get', userId]))
|
|
27696
|
-
.filter(Boolean)
|
|
27697
|
-
.map(({ data }) => LinkedObject.user(data))) !== null && _a !== void 0 ? _a : [];
|
|
27698
|
-
callback({
|
|
27699
|
-
onNextPage: onFetch,
|
|
27700
|
-
/*
|
|
27701
|
-
* Only apply filter to RTE Model
|
|
27702
|
-
*/
|
|
27703
|
-
data: isEventModel ? applyFilter$2(users, params) : users,
|
|
27704
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
27705
|
-
loading: data.loading,
|
|
27706
|
-
error: data.error,
|
|
27707
|
-
});
|
|
27708
|
-
};
|
|
27709
|
-
const realtimeRouter = (_) => (user) => {
|
|
27710
|
-
var _a;
|
|
27711
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27712
|
-
if (!collection)
|
|
27713
|
-
return;
|
|
27714
|
-
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
27715
|
-
pushToCache(cacheKey, collection);
|
|
27716
|
-
responder(collection, true);
|
|
27717
|
-
};
|
|
27718
|
-
const onFetch = (initial = false) => {
|
|
27719
|
-
var _a, _b;
|
|
27720
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27721
|
-
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27722
|
-
if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
27723
|
-
return;
|
|
27724
|
-
const pagingCondition = initial ? { limit } : { page: collection === null || collection === void 0 ? void 0 : collection.params.page };
|
|
27725
|
-
const query = createQuery(queryUsers, Object.assign(Object.assign({}, queryParams), pagingCondition));
|
|
27726
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
27727
|
-
const data = {
|
|
27728
|
-
loading,
|
|
27729
|
-
error,
|
|
27730
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
27731
|
-
data: users,
|
|
27732
|
-
};
|
|
27733
|
-
if (result) {
|
|
27734
|
-
data.data = initial
|
|
27735
|
-
? result.map(getResolver('user'))
|
|
27736
|
-
: [...new Set([...users, ...result.map(getResolver('user'))])];
|
|
27737
|
-
}
|
|
27738
|
-
pushToCache(cacheKey, data);
|
|
27739
|
-
responder(data);
|
|
27740
|
-
}, queryOptions(policy));
|
|
27741
|
-
};
|
|
27742
|
-
disposers.push(onUserUpdated(realtimeRouter()), onUserDeleted(realtimeRouter()), onUserFlagged(realtimeRouter()), onUserUnflagged(realtimeRouter()), onUserFlagCleared(realtimeRouter()));
|
|
27743
|
-
onFetch(true);
|
|
28067
|
+
const usersLiveCollection = new UserLiveCollectionController(params, callback);
|
|
28068
|
+
const disposers = usersLiveCollection.startSubscription();
|
|
28069
|
+
const cacheKey = usersLiveCollection.getCacheKey();
|
|
28070
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
27744
28071
|
return () => {
|
|
27745
28072
|
log(`liveUsers(tmpid: ${timestamp}) > dispose`);
|
|
27746
28073
|
disposers.forEach(fn => fn());
|
|
@@ -27763,27 +28090,9 @@ const getUsers = (params, callback, config) => {
|
|
|
27763
28090
|
* @async
|
|
27764
28091
|
*/
|
|
27765
28092
|
const getUser = async (userId) => {
|
|
27766
|
-
const
|
|
27767
|
-
client.log('user/getUser', userId);
|
|
27768
|
-
isInTombstone('user', userId);
|
|
27769
|
-
let data;
|
|
27770
|
-
try {
|
|
27771
|
-
const response = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
|
|
27772
|
-
data = response.data;
|
|
27773
|
-
}
|
|
27774
|
-
catch (error) {
|
|
27775
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
27776
|
-
pushToTombstone('user', userId);
|
|
27777
|
-
}
|
|
27778
|
-
throw error;
|
|
27779
|
-
}
|
|
27780
|
-
const cachedAt = client.cache && Date.now();
|
|
27781
|
-
if (client.cache)
|
|
27782
|
-
ingestInCache(data, { cachedAt });
|
|
27783
|
-
const { users } = data;
|
|
27784
|
-
fireEvent('user.fetched', data);
|
|
28093
|
+
const { data, cachedAt } = await getUser$2(userId);
|
|
27785
28094
|
return {
|
|
27786
|
-
data: LinkedObject.user(
|
|
28095
|
+
data: LinkedObject.user(data),
|
|
27787
28096
|
cachedAt,
|
|
27788
28097
|
};
|
|
27789
28098
|
};
|
|
@@ -27801,11 +28110,7 @@ const getUser = async (userId) => {
|
|
|
27801
28110
|
* @category User API
|
|
27802
28111
|
*/
|
|
27803
28112
|
getUser.locally = (userId) => {
|
|
27804
|
-
const
|
|
27805
|
-
client.log('user/getUser.locally', userId);
|
|
27806
|
-
if (!client.cache)
|
|
27807
|
-
return;
|
|
27808
|
-
const cached = pullFromCache(['user', 'get', userId]);
|
|
28113
|
+
const cached = getUser$2.locally(userId);
|
|
27809
28114
|
if (!cached)
|
|
27810
28115
|
return;
|
|
27811
28116
|
return {
|
|
@@ -27847,7 +28152,7 @@ const observeUser = (userId, callback) => {
|
|
|
27847
28152
|
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, newResult);
|
|
27848
28153
|
};
|
|
27849
28154
|
const disposers = [];
|
|
27850
|
-
disposers.push(onUserUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onUserDeleted(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), onUserFlagged(data => router({ data, loading: false, origin: 'event' }, 'onFlagged')), onUserUnflagged(data => router({ data, loading: false, origin: 'event' }, 'onUnflagged')), onUserFlagCleared(data => router({ data, loading: false, origin: 'event' }, 'onFlagCleared')));
|
|
28155
|
+
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')));
|
|
27851
28156
|
runQuery(createQuery(getUser, userId), result => result.data && router(result, 'onFetch'));
|
|
27852
28157
|
return () => {
|
|
27853
28158
|
log(`observeUser(tmpid: ${timestamp}) > dispose`);
|
|
@@ -27855,6 +28160,130 @@ const observeUser = (userId, callback) => {
|
|
|
27855
28160
|
};
|
|
27856
28161
|
};
|
|
27857
28162
|
|
|
28163
|
+
class SearchUserPaginationController extends PaginationController {
|
|
28164
|
+
async getRequest(queryParams, token) {
|
|
28165
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
28166
|
+
const options = token ? { token } : { limit };
|
|
28167
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
28168
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
28169
|
+
});
|
|
28170
|
+
return queryResponse;
|
|
28171
|
+
}
|
|
28172
|
+
}
|
|
28173
|
+
|
|
28174
|
+
class SearchUserQueryStreamController extends QueryStreamController {
|
|
28175
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
28176
|
+
super(query, cacheKey);
|
|
28177
|
+
this.notifyChange = notifyChange;
|
|
28178
|
+
this.preparePayload = preparePayload;
|
|
28179
|
+
}
|
|
28180
|
+
async saveToMainDB(response) {
|
|
28181
|
+
const processedPayload = await this.preparePayload(response);
|
|
28182
|
+
const client = getActiveClient();
|
|
28183
|
+
const cachedAt = client.cache && Date.now();
|
|
28184
|
+
if (client.cache) {
|
|
28185
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
28186
|
+
}
|
|
28187
|
+
}
|
|
28188
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
28189
|
+
var _a, _b;
|
|
28190
|
+
if (refresh) {
|
|
28191
|
+
pushToCache(this.cacheKey, {
|
|
28192
|
+
data: response.users.map(getResolver('user')),
|
|
28193
|
+
});
|
|
28194
|
+
}
|
|
28195
|
+
else {
|
|
28196
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28197
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
28198
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
28199
|
+
}
|
|
28200
|
+
}
|
|
28201
|
+
reactor(action) {
|
|
28202
|
+
return (user) => {
|
|
28203
|
+
var _a;
|
|
28204
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28205
|
+
if (!collection)
|
|
28206
|
+
return;
|
|
28207
|
+
/*
|
|
28208
|
+
* Simply update a collection and let responder decide what to do with data
|
|
28209
|
+
*/
|
|
28210
|
+
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
28211
|
+
pushToCache(this.cacheKey, collection);
|
|
28212
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
28213
|
+
};
|
|
28214
|
+
}
|
|
28215
|
+
subscribeRTE(createSubscriber) {
|
|
28216
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
28217
|
+
}
|
|
28218
|
+
}
|
|
28219
|
+
|
|
28220
|
+
class SearchUserLiveCollectionController extends LiveCollectionController {
|
|
28221
|
+
constructor(query, callback) {
|
|
28222
|
+
var _a;
|
|
28223
|
+
const queryStreamId = hash(query);
|
|
28224
|
+
const cacheKey = ['user', 'collection', queryStreamId];
|
|
28225
|
+
const paginationController = new SearchUserPaginationController(query);
|
|
28226
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
28227
|
+
this.query = Object.assign(Object.assign({}, query), { filter: (_a = query.filter) !== null && _a !== void 0 ? _a : 'all' });
|
|
28228
|
+
this.queryStreamController = new SearchUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareUserPayload);
|
|
28229
|
+
this.callback = callback.bind(this);
|
|
28230
|
+
this.loadPage({ initial: true });
|
|
28231
|
+
}
|
|
28232
|
+
setup() {
|
|
28233
|
+
var _a;
|
|
28234
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28235
|
+
if (!collection) {
|
|
28236
|
+
pushToCache(this.cacheKey, {
|
|
28237
|
+
data: [],
|
|
28238
|
+
params: {},
|
|
28239
|
+
});
|
|
28240
|
+
}
|
|
28241
|
+
}
|
|
28242
|
+
async persistModel(queryPayload) {
|
|
28243
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
28244
|
+
}
|
|
28245
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
28246
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
28247
|
+
}
|
|
28248
|
+
startSubscription() {
|
|
28249
|
+
return this.queryStreamController.subscribeRTE([
|
|
28250
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
28251
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
28252
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
28253
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
28254
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
28255
|
+
]);
|
|
28256
|
+
}
|
|
28257
|
+
notifyChange({ origin, loading, error }) {
|
|
28258
|
+
var _a, _b;
|
|
28259
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28260
|
+
if (!collection)
|
|
28261
|
+
return;
|
|
28262
|
+
const data = this.applyFilter((_b = collection.data
|
|
28263
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
28264
|
+
.filter(isNonNullable)
|
|
28265
|
+
.map(({ data }) => data)
|
|
28266
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
28267
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
28268
|
+
return;
|
|
28269
|
+
this.callback({
|
|
28270
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
28271
|
+
data,
|
|
28272
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
28273
|
+
loading,
|
|
28274
|
+
error,
|
|
28275
|
+
});
|
|
28276
|
+
}
|
|
28277
|
+
applyFilter(data) {
|
|
28278
|
+
let users = data;
|
|
28279
|
+
if (this.query.filter === 'flagged') {
|
|
28280
|
+
users = users.filter(user => !!user.hashFlag);
|
|
28281
|
+
}
|
|
28282
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
28283
|
+
return users;
|
|
28284
|
+
}
|
|
28285
|
+
}
|
|
28286
|
+
|
|
27858
28287
|
/* begin_public_function
|
|
27859
28288
|
id: user.search
|
|
27860
28289
|
*/
|
|
@@ -27876,7 +28305,21 @@ const observeUser = (userId, callback) => {
|
|
|
27876
28305
|
* @category Category Live Collection
|
|
27877
28306
|
*/
|
|
27878
28307
|
const searchUserByDisplayName = (params, callback, config) => {
|
|
27879
|
-
|
|
28308
|
+
const { log, cache } = getActiveClient();
|
|
28309
|
+
if (!cache) {
|
|
28310
|
+
// eslint-disable-next-line no-console
|
|
28311
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
28312
|
+
}
|
|
28313
|
+
const timestamp = Date.now();
|
|
28314
|
+
log(`liveSearchUsers(tmpid: ${timestamp}) > listen`);
|
|
28315
|
+
const searchUsersLiveCollection = new SearchUserLiveCollectionController(params, callback);
|
|
28316
|
+
const disposers = searchUsersLiveCollection.startSubscription();
|
|
28317
|
+
const cacheKey = searchUsersLiveCollection.getCacheKey();
|
|
28318
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
28319
|
+
return () => {
|
|
28320
|
+
log(`liveSearchUsers(tmpid: ${timestamp}) > dispose`);
|
|
28321
|
+
disposers.forEach(fn => fn());
|
|
28322
|
+
};
|
|
27880
28323
|
};
|
|
27881
28324
|
/* end_public_function */
|
|
27882
28325
|
|
|
@@ -28045,7 +28488,7 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
28045
28488
|
unflagUser: unflagUser,
|
|
28046
28489
|
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
28047
28490
|
onUserUpdated: onUserUpdated,
|
|
28048
|
-
onUserDeleted: onUserDeleted,
|
|
28491
|
+
onUserDeleted: onUserDeleted$2,
|
|
28049
28492
|
onUserFlagged: onUserFlagged,
|
|
28050
28493
|
onUserUnflagged: onUserUnflagged,
|
|
28051
28494
|
onUserFlagCleared: onUserFlagCleared,
|
|
@@ -28967,6 +29410,7 @@ const prepareCommentFromFlaggedEvent = (payload) => {
|
|
|
28967
29410
|
* @async
|
|
28968
29411
|
* */
|
|
28969
29412
|
const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
29413
|
+
var _a, _b;
|
|
28970
29414
|
const client = getActiveClient();
|
|
28971
29415
|
client.log('reaction/createReaction', {
|
|
28972
29416
|
referenceId,
|
|
@@ -28985,8 +29429,21 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
28985
29429
|
'get',
|
|
28986
29430
|
referenceId,
|
|
28987
29431
|
]);
|
|
28988
|
-
(model
|
|
28989
|
-
|
|
29432
|
+
if (!model)
|
|
29433
|
+
return true;
|
|
29434
|
+
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) + 1 }) });
|
|
29435
|
+
if (referenceType === 'comment') {
|
|
29436
|
+
fireEvent('local.comment.addReaction', {
|
|
29437
|
+
comment: updatedModel,
|
|
29438
|
+
});
|
|
29439
|
+
return true;
|
|
29440
|
+
}
|
|
29441
|
+
if (referenceType === 'post') {
|
|
29442
|
+
fireEvent('local.post.addReaction', {
|
|
29443
|
+
post: updatedModel,
|
|
29444
|
+
});
|
|
29445
|
+
return true;
|
|
29446
|
+
}
|
|
28990
29447
|
}
|
|
28991
29448
|
return true;
|
|
28992
29449
|
};
|
|
@@ -29051,6 +29508,7 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
29051
29508
|
* @async
|
|
29052
29509
|
* */
|
|
29053
29510
|
const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
29511
|
+
var _a, _b;
|
|
29054
29512
|
const client = getActiveClient();
|
|
29055
29513
|
client.log('reaction/removeReaction', {
|
|
29056
29514
|
referenceId,
|
|
@@ -29071,8 +29529,21 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
29071
29529
|
'get',
|
|
29072
29530
|
referenceId,
|
|
29073
29531
|
]);
|
|
29074
|
-
(model
|
|
29075
|
-
|
|
29532
|
+
if (!model)
|
|
29533
|
+
return true;
|
|
29534
|
+
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }) });
|
|
29535
|
+
if (referenceType === 'comment') {
|
|
29536
|
+
fireEvent('local.comment.removeReaction', {
|
|
29537
|
+
comment: updatedModel,
|
|
29538
|
+
});
|
|
29539
|
+
return true;
|
|
29540
|
+
}
|
|
29541
|
+
if (referenceType === 'post') {
|
|
29542
|
+
fireEvent('local.post.removeReaction', {
|
|
29543
|
+
post: updatedModel,
|
|
29544
|
+
});
|
|
29545
|
+
return true;
|
|
29546
|
+
}
|
|
29076
29547
|
}
|
|
29077
29548
|
return true;
|
|
29078
29549
|
};
|
|
@@ -29117,6 +29588,66 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
29117
29588
|
return (_e = !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName))) !== null && _e !== void 0 ? _e : false;
|
|
29118
29589
|
};
|
|
29119
29590
|
|
|
29591
|
+
const getMatchPostSetting = (value) => {
|
|
29592
|
+
var _a;
|
|
29593
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
29594
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
29595
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
29596
|
+
};
|
|
29597
|
+
function addPostSetting({ communities }) {
|
|
29598
|
+
return communities.map((_a) => {
|
|
29599
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
29600
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
29601
|
+
needApprovalOnPostCreation,
|
|
29602
|
+
onlyAdminCanPost,
|
|
29603
|
+
}) }, restCommunityPayload));
|
|
29604
|
+
});
|
|
29605
|
+
}
|
|
29606
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
29607
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
29608
|
+
// map users with community
|
|
29609
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
29610
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
29611
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
29612
|
+
});
|
|
29613
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
29614
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
29615
|
+
};
|
|
29616
|
+
const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
29617
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
29618
|
+
// map users with community
|
|
29619
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
29620
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
29621
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
29622
|
+
});
|
|
29623
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
29624
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
29625
|
+
};
|
|
29626
|
+
const prepareCommunityRequest = (params) => {
|
|
29627
|
+
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
29628
|
+
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
29629
|
+
// Convert story setting to the actual value. (Allow by default)
|
|
29630
|
+
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
29631
|
+
};
|
|
29632
|
+
|
|
29633
|
+
const preparePostPayload = (postPayload) => {
|
|
29634
|
+
// Unpack community payload by mapping payload field to postSetting value.
|
|
29635
|
+
const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
|
|
29636
|
+
// map users with community
|
|
29637
|
+
const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
|
|
29638
|
+
const user = postPayload.users.find(user => user.userId === communityUser.userId);
|
|
29639
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
29640
|
+
});
|
|
29641
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
29642
|
+
// feed type
|
|
29643
|
+
const posts = postPayload.posts.map(post => {
|
|
29644
|
+
var _a;
|
|
29645
|
+
const feedType = (_a = postPayload.feeds.find(feed => feed.feedId === post.feedId)) === null || _a === void 0 ? void 0 : _a.feedType;
|
|
29646
|
+
return Object.assign(Object.assign({}, post), { feedType });
|
|
29647
|
+
});
|
|
29648
|
+
return Object.assign(Object.assign({}, postPayload), { posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
29649
|
+
};
|
|
29650
|
+
|
|
29120
29651
|
const createPostEventSubscriber = (event, callback) => {
|
|
29121
29652
|
const client = getActiveClient();
|
|
29122
29653
|
const filter = (payload) => {
|
|
@@ -29125,8 +29656,8 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
29125
29656
|
callback(payload.posts[0]);
|
|
29126
29657
|
}
|
|
29127
29658
|
else {
|
|
29128
|
-
const
|
|
29129
|
-
const
|
|
29659
|
+
const data = preparePostPayload(payload);
|
|
29660
|
+
const { communities } = data;
|
|
29130
29661
|
ingestInCache(data);
|
|
29131
29662
|
if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['post.updated'].includes(event)) {
|
|
29132
29663
|
fireEvent('community.updated', {
|
|
@@ -29153,7 +29684,7 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
29153
29684
|
// But if it is hard delete, it will pushed into tombstone before fire an event to BE. it means it will stay in tombstone already
|
|
29154
29685
|
// and will got skip to notify in a previous code block
|
|
29155
29686
|
if (postedUserId !== client.userId) {
|
|
29156
|
-
|
|
29687
|
+
dropFromCache(['post', 'get', postId]);
|
|
29157
29688
|
}
|
|
29158
29689
|
return callback(payload.posts[0]);
|
|
29159
29690
|
}
|
|
@@ -29170,6 +29701,32 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
29170
29701
|
}
|
|
29171
29702
|
};
|
|
29172
29703
|
return createEventSubscriber(client, event, event, filter);
|
|
29704
|
+
};
|
|
29705
|
+
const createLocalPostEventSubscriber = (event, callback) => {
|
|
29706
|
+
const client = getActiveClient();
|
|
29707
|
+
const filter = (payload) => {
|
|
29708
|
+
if (!client.cache) {
|
|
29709
|
+
callback(payload.posts[0]);
|
|
29710
|
+
}
|
|
29711
|
+
else {
|
|
29712
|
+
const data = preparePostPayload(payload);
|
|
29713
|
+
const { communities } = data;
|
|
29714
|
+
ingestInCache(data);
|
|
29715
|
+
if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['local.post.updated'].includes(event)) {
|
|
29716
|
+
fireEvent('community.updated', {
|
|
29717
|
+
communities,
|
|
29718
|
+
categories: [],
|
|
29719
|
+
communityUsers: data.communityUsers,
|
|
29720
|
+
feeds: [],
|
|
29721
|
+
files: [],
|
|
29722
|
+
users: [],
|
|
29723
|
+
});
|
|
29724
|
+
}
|
|
29725
|
+
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
29726
|
+
callback(post.data);
|
|
29727
|
+
}
|
|
29728
|
+
};
|
|
29729
|
+
return createEventSubscriber(client, event, event, filter);
|
|
29173
29730
|
};
|
|
29174
29731
|
|
|
29175
29732
|
/**
|
|
@@ -29376,6 +29933,9 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
29376
29933
|
comments[0].commentId,
|
|
29377
29934
|
]);
|
|
29378
29935
|
if (['comment.created'].includes(event)) {
|
|
29936
|
+
// NOTE: skip adding comment to parent comment children if it's the same user since we use the local event to update instead.
|
|
29937
|
+
if (event === 'comment.created' && comment.data.userId === client.userId)
|
|
29938
|
+
return;
|
|
29379
29939
|
if (comments[0].parentId) {
|
|
29380
29940
|
const parentComment = pullFromCache([
|
|
29381
29941
|
'comment',
|
|
@@ -29397,6 +29957,58 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
29397
29957
|
}
|
|
29398
29958
|
};
|
|
29399
29959
|
return createEventSubscriber(client, event, event, filter);
|
|
29960
|
+
};
|
|
29961
|
+
const createLocalCommentEventSubscriber = (event, callback) => {
|
|
29962
|
+
const client = getActiveClient();
|
|
29963
|
+
const filter = (payload) => {
|
|
29964
|
+
var _a;
|
|
29965
|
+
if (!client.cache) {
|
|
29966
|
+
// TODO: here we are missing specific properties here!
|
|
29967
|
+
callback(LinkedObject.comment(payload.comments[0]));
|
|
29968
|
+
}
|
|
29969
|
+
else {
|
|
29970
|
+
const processed = payload;
|
|
29971
|
+
ingestInCache(processed);
|
|
29972
|
+
const { comments } = processed;
|
|
29973
|
+
if (comments.length > 0) {
|
|
29974
|
+
const comment = pullFromCache([
|
|
29975
|
+
'comment',
|
|
29976
|
+
'get',
|
|
29977
|
+
comments[0].commentId,
|
|
29978
|
+
]);
|
|
29979
|
+
if (['local.comment.created'].includes(event)) {
|
|
29980
|
+
if (comments[0].parentId) {
|
|
29981
|
+
const parentComment = pullFromCache([
|
|
29982
|
+
'comment',
|
|
29983
|
+
'get',
|
|
29984
|
+
comments[0].parentId,
|
|
29985
|
+
]);
|
|
29986
|
+
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
29987
|
+
// Skip to update parent childComment if current comment already exists
|
|
29988
|
+
if (!parentComment.data.children.includes(comments[0].commentId)) {
|
|
29989
|
+
const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber + 1, children: [...new Set([...parentComment.data.children, comments[0].commentId])] });
|
|
29990
|
+
pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
|
|
29991
|
+
setTimeout(() => {
|
|
29992
|
+
// NOTE: This is workaround solution for emitting event not work properly.
|
|
29993
|
+
fireEvent('comment.updated', {
|
|
29994
|
+
comments: [newParentComment],
|
|
29995
|
+
commentChildren: [],
|
|
29996
|
+
files: [],
|
|
29997
|
+
users: [],
|
|
29998
|
+
communityUsers: [],
|
|
29999
|
+
});
|
|
30000
|
+
}, 200);
|
|
30001
|
+
}
|
|
30002
|
+
}
|
|
30003
|
+
}
|
|
30004
|
+
const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
30005
|
+
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
30006
|
+
}
|
|
30007
|
+
callback(LinkedObject.comment(comment.data));
|
|
30008
|
+
}
|
|
30009
|
+
}
|
|
30010
|
+
};
|
|
30011
|
+
return createEventSubscriber(client, event, event, filter);
|
|
29400
30012
|
};
|
|
29401
30013
|
|
|
29402
30014
|
/**
|
|
@@ -29956,29 +30568,53 @@ var index$h = /*#__PURE__*/Object.freeze({
|
|
|
29956
30568
|
getReactions: getReactions
|
|
29957
30569
|
});
|
|
29958
30570
|
|
|
29959
|
-
|
|
29960
|
-
|
|
29961
|
-
|
|
29962
|
-
|
|
29963
|
-
|
|
29964
|
-
|
|
29965
|
-
|
|
29966
|
-
|
|
29967
|
-
|
|
29968
|
-
|
|
29969
|
-
},
|
|
29970
|
-
message: {
|
|
29971
|
-
domainName: 'messages',
|
|
29972
|
-
eventName: 'v3/message.isFlaggedByMe',
|
|
29973
|
-
primaryKey: 'messageId',
|
|
29974
|
-
},
|
|
29975
|
-
user: {
|
|
29976
|
-
domainName: 'users',
|
|
29977
|
-
eventName: 'user.isFlagByMe',
|
|
29978
|
-
primaryKey: 'userId',
|
|
29979
|
-
},
|
|
29980
|
-
};
|
|
30571
|
+
function prepareCommentPayload(commentPayload) {
|
|
30572
|
+
const { comments } = commentPayload;
|
|
30573
|
+
return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
|
|
30574
|
+
if (comment.hasOwnProperty('myReactions'))
|
|
30575
|
+
return comment;
|
|
30576
|
+
// Sometimes `myReactions` field will not come with BE response because that field is empty
|
|
30577
|
+
// We need to put it with an empty array manually to make it show up in client side
|
|
30578
|
+
return Object.assign({ myReactions: [] }, comment);
|
|
30579
|
+
}) });
|
|
30580
|
+
}
|
|
29981
30581
|
|
|
30582
|
+
const createMessageReport = async ({ client, referenceId, }) => {
|
|
30583
|
+
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
30584
|
+
if (client.cache) {
|
|
30585
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
30586
|
+
ingestInCache(messagePayload);
|
|
30587
|
+
}
|
|
30588
|
+
fireEvent(`message.flagged`, payload);
|
|
30589
|
+
return !!payload;
|
|
30590
|
+
};
|
|
30591
|
+
const createPostReport = async ({ client, referenceId, }) => {
|
|
30592
|
+
const { data: payload } = await client.http.post(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
|
|
30593
|
+
if (client.cache) {
|
|
30594
|
+
const postPayload = await preparePostPayload(payload);
|
|
30595
|
+
ingestInCache(postPayload);
|
|
30596
|
+
}
|
|
30597
|
+
fireEvent(`post.flagged`, payload);
|
|
30598
|
+
return !!payload;
|
|
30599
|
+
};
|
|
30600
|
+
const createUserReport = async ({ client, referenceId, }) => {
|
|
30601
|
+
const { data: payload } = await client.http.post(`/api/v4/me/flags/${encodeURIComponent(referenceId)}`);
|
|
30602
|
+
if (client.cache) {
|
|
30603
|
+
const userPayload = await prepareUserPayload(payload);
|
|
30604
|
+
ingestInCache(userPayload);
|
|
30605
|
+
}
|
|
30606
|
+
fireEvent(`user.flagged`, payload);
|
|
30607
|
+
return !!payload;
|
|
30608
|
+
};
|
|
30609
|
+
const createCommentReport = async ({ client, referenceId, }) => {
|
|
30610
|
+
const { data: payload } = await client.http.post(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
|
|
30611
|
+
if (client.cache) {
|
|
30612
|
+
const commentPayload = await prepareCommentPayload(payload);
|
|
30613
|
+
ingestInCache(commentPayload);
|
|
30614
|
+
}
|
|
30615
|
+
fireEvent(`comment.flagged`, payload);
|
|
30616
|
+
return !!payload;
|
|
30617
|
+
};
|
|
29982
30618
|
/**
|
|
29983
30619
|
* ```js
|
|
29984
30620
|
* import { createReport } from '@amityco/ts-sdk-react-native'
|
|
@@ -29995,33 +30631,57 @@ var REFERENCE_TYPES = {
|
|
|
29995
30631
|
const createReport = async (referenceType, referenceId) => {
|
|
29996
30632
|
const client = getActiveClient();
|
|
29997
30633
|
client.log('report/createReport', { referenceType, referenceId });
|
|
29998
|
-
|
|
29999
|
-
|
|
30000
|
-
return `/api/v4/me/flags/${encodeURIComponent(referenceId)}`;
|
|
30001
|
-
}
|
|
30002
|
-
if (referenceType === 'message') {
|
|
30003
|
-
return `/api/v5/messages/${encodeURIComponent(referenceId)}/flags`;
|
|
30004
|
-
}
|
|
30005
|
-
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
30006
|
-
return `/api/v3/${domainName}/${encodeURIComponent(referenceId)}/flag`;
|
|
30007
|
-
};
|
|
30008
|
-
const { data: payload } = await client.http.post(getAPIUrl());
|
|
30009
|
-
if (client.cache) {
|
|
30010
|
-
if (referenceType === 'message') {
|
|
30011
|
-
const messagePayload = await prepareMessagePayload(payload);
|
|
30012
|
-
ingestInCache(messagePayload);
|
|
30013
|
-
}
|
|
30014
|
-
else if (referenceType === 'post') {
|
|
30015
|
-
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
30016
|
-
}
|
|
30017
|
-
else {
|
|
30018
|
-
ingestInCache(payload);
|
|
30019
|
-
}
|
|
30634
|
+
if (referenceType === 'user') {
|
|
30635
|
+
return createUserReport({ client, referenceId });
|
|
30020
30636
|
}
|
|
30021
|
-
|
|
30022
|
-
|
|
30637
|
+
if (referenceType === 'message') {
|
|
30638
|
+
return createMessageReport({ client, referenceId });
|
|
30639
|
+
}
|
|
30640
|
+
if (referenceType === 'post') {
|
|
30641
|
+
return createPostReport({ client, referenceId });
|
|
30642
|
+
}
|
|
30643
|
+
if (referenceType === 'comment') {
|
|
30644
|
+
return createCommentReport({ client, referenceId });
|
|
30645
|
+
}
|
|
30646
|
+
return false;
|
|
30023
30647
|
};
|
|
30024
30648
|
|
|
30649
|
+
const deleteMessageReport = async ({ client, referenceId, }) => {
|
|
30650
|
+
const { data: payload } = await client.http.delete(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
30651
|
+
if (client.cache) {
|
|
30652
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
30653
|
+
ingestInCache(messagePayload);
|
|
30654
|
+
}
|
|
30655
|
+
fireEvent(`message.unflagged`, payload);
|
|
30656
|
+
return !!payload;
|
|
30657
|
+
};
|
|
30658
|
+
const deletePostReport = async ({ client, referenceId, }) => {
|
|
30659
|
+
const { data: payload } = await client.http.delete(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
|
|
30660
|
+
if (client.cache) {
|
|
30661
|
+
const postPayload = await preparePostPayload(payload);
|
|
30662
|
+
ingestInCache(postPayload);
|
|
30663
|
+
}
|
|
30664
|
+
fireEvent(`post.unflagged`, payload);
|
|
30665
|
+
return !!payload;
|
|
30666
|
+
};
|
|
30667
|
+
const deleteUserReport = async ({ client, referenceId, }) => {
|
|
30668
|
+
const { data: payload } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(referenceId)}`);
|
|
30669
|
+
if (client.cache) {
|
|
30670
|
+
const userPayload = await prepareUserPayload(payload);
|
|
30671
|
+
ingestInCache(userPayload);
|
|
30672
|
+
}
|
|
30673
|
+
fireEvent(`user.unflagged`, payload);
|
|
30674
|
+
return !!payload;
|
|
30675
|
+
};
|
|
30676
|
+
const deleteCommentReport = async ({ client, referenceId, }) => {
|
|
30677
|
+
const { data: payload } = await client.http.delete(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
|
|
30678
|
+
if (client.cache) {
|
|
30679
|
+
const commentPayload = await prepareCommentPayload(payload);
|
|
30680
|
+
ingestInCache(commentPayload);
|
|
30681
|
+
}
|
|
30682
|
+
fireEvent(`comment.unflagged`, payload);
|
|
30683
|
+
return !!payload;
|
|
30684
|
+
};
|
|
30025
30685
|
/**
|
|
30026
30686
|
* ```js
|
|
30027
30687
|
* import { deleteReport } from '@amityco/ts-sdk-react-native'
|
|
@@ -30038,34 +30698,45 @@ const createReport = async (referenceType, referenceId) => {
|
|
|
30038
30698
|
const deleteReport = async (referenceType, referenceId) => {
|
|
30039
30699
|
const client = getActiveClient();
|
|
30040
30700
|
client.log('report/deleteReport', { referenceType, referenceId });
|
|
30041
|
-
|
|
30042
|
-
|
|
30043
|
-
return `/api/v4/me/flags/${encodeURIComponent(referenceId)}`;
|
|
30044
|
-
}
|
|
30045
|
-
if (referenceType === 'message') {
|
|
30046
|
-
return `/api/v5/messages/${encodeURIComponent(referenceId)}/flags`;
|
|
30047
|
-
}
|
|
30048
|
-
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
30049
|
-
return `/api/v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`;
|
|
30050
|
-
};
|
|
30051
|
-
const { data: payload } = await client.http.delete(getAPIUrl());
|
|
30052
|
-
if (client.cache) {
|
|
30053
|
-
if (referenceType === 'message') {
|
|
30054
|
-
const messagePayload = await prepareMessagePayload(payload);
|
|
30055
|
-
ingestInCache(messagePayload);
|
|
30056
|
-
}
|
|
30057
|
-
else if (referenceType === 'post') {
|
|
30058
|
-
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
30059
|
-
}
|
|
30060
|
-
else {
|
|
30061
|
-
ingestInCache(payload);
|
|
30062
|
-
}
|
|
30701
|
+
if (referenceType === 'user') {
|
|
30702
|
+
return deleteUserReport({ client, referenceId });
|
|
30063
30703
|
}
|
|
30064
|
-
|
|
30065
|
-
|
|
30066
|
-
|
|
30704
|
+
if (referenceType === 'message') {
|
|
30705
|
+
return deleteMessageReport({ client, referenceId });
|
|
30706
|
+
}
|
|
30707
|
+
if (referenceType === 'post') {
|
|
30708
|
+
return deletePostReport({ client, referenceId });
|
|
30709
|
+
}
|
|
30710
|
+
if (referenceType === 'comment') {
|
|
30711
|
+
return deleteCommentReport({ client, referenceId });
|
|
30712
|
+
}
|
|
30713
|
+
return false;
|
|
30067
30714
|
};
|
|
30068
30715
|
|
|
30716
|
+
const getMessageReport = async ({ client, referenceId, }) => {
|
|
30717
|
+
var _a;
|
|
30718
|
+
const { data } = await client.http.get(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
30719
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
30720
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
30721
|
+
};
|
|
30722
|
+
const getPostReport = async ({ client, referenceId, }) => {
|
|
30723
|
+
var _a;
|
|
30724
|
+
const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
|
|
30725
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
30726
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
30727
|
+
};
|
|
30728
|
+
const getUserReport = async ({ client, referenceId, }) => {
|
|
30729
|
+
var _a;
|
|
30730
|
+
const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
|
|
30731
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
30732
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
30733
|
+
};
|
|
30734
|
+
const getCommentReport = async ({ client, referenceId, }) => {
|
|
30735
|
+
var _a;
|
|
30736
|
+
const { data } = await client.http.get(`/api/v3/comment/${referenceId}/isflagbyme`);
|
|
30737
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
30738
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
30739
|
+
};
|
|
30069
30740
|
/**
|
|
30070
30741
|
* ```js
|
|
30071
30742
|
* import { isReportedByMe } from '@amityco/ts-sdk-react-native'
|
|
@@ -30080,17 +30751,21 @@ const deleteReport = async (referenceType, referenceId) => {
|
|
|
30080
30751
|
* @async
|
|
30081
30752
|
* */
|
|
30082
30753
|
const isReportedByMe = async (referenceType, referenceId) => {
|
|
30083
|
-
var _a;
|
|
30084
30754
|
const client = getActiveClient();
|
|
30085
30755
|
client.log('report/isReportedByMe', { referenceType, referenceId });
|
|
30086
|
-
|
|
30756
|
+
if (referenceType === 'user') {
|
|
30757
|
+
return getUserReport({ client, referenceId });
|
|
30758
|
+
}
|
|
30087
30759
|
if (referenceType === 'message') {
|
|
30088
|
-
|
|
30089
|
-
return data.result;
|
|
30760
|
+
return getMessageReport({ client, referenceId });
|
|
30090
30761
|
}
|
|
30091
|
-
|
|
30092
|
-
|
|
30093
|
-
|
|
30762
|
+
if (referenceType === 'post') {
|
|
30763
|
+
return getPostReport({ client, referenceId });
|
|
30764
|
+
}
|
|
30765
|
+
if (referenceType === 'comment') {
|
|
30766
|
+
return getCommentReport({ client, referenceId });
|
|
30767
|
+
}
|
|
30768
|
+
return false;
|
|
30094
30769
|
};
|
|
30095
30770
|
|
|
30096
30771
|
/* begin_public_function
|
|
@@ -31611,116 +32286,6 @@ const getMessage$1 = (messageId, callback) => {
|
|
|
31611
32286
|
};
|
|
31612
32287
|
/* end_public_function */
|
|
31613
32288
|
|
|
31614
|
-
class PaginationNoPageController {
|
|
31615
|
-
constructor(queryParams) {
|
|
31616
|
-
const { http } = getActiveClient();
|
|
31617
|
-
this.queryParams = queryParams;
|
|
31618
|
-
this.http = http;
|
|
31619
|
-
}
|
|
31620
|
-
async onFetch() {
|
|
31621
|
-
const queryResponse = await this.getRequest(this.queryParams);
|
|
31622
|
-
return queryResponse;
|
|
31623
|
-
}
|
|
31624
|
-
}
|
|
31625
|
-
|
|
31626
|
-
class LiveCollectionController {
|
|
31627
|
-
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
31628
|
-
this.paginationController = paginationController;
|
|
31629
|
-
this.queryStreamId = queryStreamId;
|
|
31630
|
-
this.cacheKey = cacheKey;
|
|
31631
|
-
this.callback = callback;
|
|
31632
|
-
}
|
|
31633
|
-
async refresh() {
|
|
31634
|
-
try {
|
|
31635
|
-
let result;
|
|
31636
|
-
if (this.paginationController instanceof PaginationNoPageController) {
|
|
31637
|
-
result = await this.paginationController.onFetch();
|
|
31638
|
-
}
|
|
31639
|
-
else {
|
|
31640
|
-
result = await this.paginationController.loadFirstPage();
|
|
31641
|
-
}
|
|
31642
|
-
if (!result)
|
|
31643
|
-
return;
|
|
31644
|
-
await this.persistModel(result);
|
|
31645
|
-
this.persistQueryStream({
|
|
31646
|
-
response: result,
|
|
31647
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
31648
|
-
refresh: true,
|
|
31649
|
-
});
|
|
31650
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
31651
|
-
}
|
|
31652
|
-
catch (e) {
|
|
31653
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
31654
|
-
}
|
|
31655
|
-
}
|
|
31656
|
-
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
31657
|
-
this.setup();
|
|
31658
|
-
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
31659
|
-
if (initial) {
|
|
31660
|
-
this.refresh();
|
|
31661
|
-
}
|
|
31662
|
-
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
31663
|
-
this.loadPrevPage();
|
|
31664
|
-
}
|
|
31665
|
-
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
31666
|
-
this.loadNextPage();
|
|
31667
|
-
}
|
|
31668
|
-
}
|
|
31669
|
-
async loadNextPage() {
|
|
31670
|
-
try {
|
|
31671
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
31672
|
-
return;
|
|
31673
|
-
const result = await this.paginationController.loadNextPage();
|
|
31674
|
-
if (!result)
|
|
31675
|
-
return;
|
|
31676
|
-
await this.persistModel(result);
|
|
31677
|
-
this.persistQueryStream({
|
|
31678
|
-
response: result,
|
|
31679
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
31680
|
-
});
|
|
31681
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
31682
|
-
}
|
|
31683
|
-
catch (e) {
|
|
31684
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
31685
|
-
}
|
|
31686
|
-
}
|
|
31687
|
-
async loadPrevPage() {
|
|
31688
|
-
try {
|
|
31689
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
31690
|
-
return;
|
|
31691
|
-
const result = await this.paginationController.loadPreviousPage();
|
|
31692
|
-
if (!result)
|
|
31693
|
-
return;
|
|
31694
|
-
await this.persistModel(result);
|
|
31695
|
-
this.persistQueryStream({
|
|
31696
|
-
response: result,
|
|
31697
|
-
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
31698
|
-
});
|
|
31699
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
31700
|
-
}
|
|
31701
|
-
catch (e) {
|
|
31702
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
31703
|
-
}
|
|
31704
|
-
}
|
|
31705
|
-
shouldNotify(data) {
|
|
31706
|
-
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
31707
|
-
if (isEqual(this.snapshot, newData))
|
|
31708
|
-
return false;
|
|
31709
|
-
this.snapshot = newData;
|
|
31710
|
-
return true;
|
|
31711
|
-
}
|
|
31712
|
-
getCacheKey() {
|
|
31713
|
-
return this.cacheKey;
|
|
31714
|
-
}
|
|
31715
|
-
}
|
|
31716
|
-
|
|
31717
|
-
class QueryStreamController {
|
|
31718
|
-
constructor(query, cacheKey) {
|
|
31719
|
-
this.query = query;
|
|
31720
|
-
this.cacheKey = cacheKey;
|
|
31721
|
-
}
|
|
31722
|
-
}
|
|
31723
|
-
|
|
31724
32289
|
/* eslint-disable no-use-before-define */
|
|
31725
32290
|
class MessageQueryStreamController extends QueryStreamController {
|
|
31726
32291
|
constructor(query, cacheKey, notifyChange, preparePayload, paginationController) {
|
|
@@ -31803,51 +32368,6 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
31803
32368
|
}
|
|
31804
32369
|
}
|
|
31805
32370
|
|
|
31806
|
-
class PaginationController {
|
|
31807
|
-
constructor(queryParams) {
|
|
31808
|
-
const { http } = getActiveClient();
|
|
31809
|
-
this.queryParams = queryParams;
|
|
31810
|
-
this.http = http;
|
|
31811
|
-
}
|
|
31812
|
-
loadFirstPage() {
|
|
31813
|
-
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
31814
|
-
}
|
|
31815
|
-
loadNextPage() {
|
|
31816
|
-
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
31817
|
-
}
|
|
31818
|
-
loadPreviousPage() {
|
|
31819
|
-
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
31820
|
-
}
|
|
31821
|
-
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
31822
|
-
var _a, _b, _c, _d;
|
|
31823
|
-
if (direction === 'prev' && !this.previousToken)
|
|
31824
|
-
return;
|
|
31825
|
-
if (direction === 'next' && !this.nextToken)
|
|
31826
|
-
return;
|
|
31827
|
-
let token;
|
|
31828
|
-
if (direction === 'prev')
|
|
31829
|
-
token = this.previousToken;
|
|
31830
|
-
if (direction === 'next')
|
|
31831
|
-
token = this.nextToken;
|
|
31832
|
-
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
31833
|
-
if (direction === 'first') {
|
|
31834
|
-
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
31835
|
-
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
31836
|
-
}
|
|
31837
|
-
if (direction === 'prev')
|
|
31838
|
-
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
31839
|
-
if (direction === 'next')
|
|
31840
|
-
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
31841
|
-
return queryResponse;
|
|
31842
|
-
}
|
|
31843
|
-
getNextToken() {
|
|
31844
|
-
return this.nextToken;
|
|
31845
|
-
}
|
|
31846
|
-
getPrevToken() {
|
|
31847
|
-
return this.previousToken;
|
|
31848
|
-
}
|
|
31849
|
-
}
|
|
31850
|
-
|
|
31851
32371
|
/* eslint-disable no-use-before-define */
|
|
31852
32372
|
/**
|
|
31853
32373
|
* TODO: handle cache receive cache option, and cache policy
|
|
@@ -33639,10 +34159,12 @@ const removeMembers$1 = async (channelId, userIds) => {
|
|
|
33639
34159
|
*/
|
|
33640
34160
|
class ChannelMemberPaginationController extends PaginationController {
|
|
33641
34161
|
async getRequest(queryParams, token) {
|
|
33642
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
34162
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
33643
34163
|
const options = token ? { token } : { limit };
|
|
34164
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
33644
34165
|
const { data: queryResponse } = await this.http.get(`/api/v4/channels/${encodeURIComponent(params.channelId)}/users`, {
|
|
33645
|
-
params: Object.assign(Object.assign({}, params), { options
|
|
34166
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
34167
|
+
isDeleted }),
|
|
33646
34168
|
});
|
|
33647
34169
|
return queryResponse;
|
|
33648
34170
|
}
|
|
@@ -33708,6 +34230,33 @@ class ChannelMemberQueryStreamController extends QueryStreamController {
|
|
|
33708
34230
|
}
|
|
33709
34231
|
}
|
|
33710
34232
|
|
|
34233
|
+
const onUserDeleted$1 = (channelId) => (callback) => {
|
|
34234
|
+
const client = getActiveClient();
|
|
34235
|
+
const filter = (payload) => {
|
|
34236
|
+
var _a, _b;
|
|
34237
|
+
const userPayload = prepareUserPayload(payload);
|
|
34238
|
+
if (userPayload.users.length === 0)
|
|
34239
|
+
return;
|
|
34240
|
+
const user = userPayload.users[0];
|
|
34241
|
+
ingestInCache(userPayload);
|
|
34242
|
+
const channelUserCacheKey = getResolver('channelUsers')({
|
|
34243
|
+
channelId,
|
|
34244
|
+
userId: user.userId,
|
|
34245
|
+
});
|
|
34246
|
+
const cacheData = (_a = pullFromCache([
|
|
34247
|
+
'channelUsers',
|
|
34248
|
+
'get',
|
|
34249
|
+
channelUserCacheKey,
|
|
34250
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
34251
|
+
upsertInCache(['channelUsers', 'get', channelUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
|
|
34252
|
+
const channel = (_b = pullFromCache(['channel', 'get', channelId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
34253
|
+
if (!channel)
|
|
34254
|
+
return;
|
|
34255
|
+
callback(channel, cacheData);
|
|
34256
|
+
};
|
|
34257
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
34258
|
+
};
|
|
34259
|
+
|
|
33711
34260
|
/* eslint-disable no-use-before-define */
|
|
33712
34261
|
class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
33713
34262
|
constructor(query, callback) {
|
|
@@ -33746,6 +34295,7 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
33746
34295
|
{ fn: onChannelMemberUnbanned, action: 'onChannelMemberUnbanned' },
|
|
33747
34296
|
{ fn: onChannelMemberRoleAdded, action: 'onChannelMemberRoleAdded' },
|
|
33748
34297
|
{ fn: onChannelMemberRoleRemoved, action: 'onChannelMemberRoleRemoved' },
|
|
34298
|
+
{ fn: onUserDeleted$1(this.query.channelId), action: 'onChannelMemberChanged' },
|
|
33749
34299
|
]);
|
|
33750
34300
|
}
|
|
33751
34301
|
notifyChange({ origin, loading, error }) {
|
|
@@ -33792,6 +34342,9 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
33792
34342
|
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.');
|
|
33793
34343
|
channelMembers = filterBySearchTerm(channelMembers, this.query.search);
|
|
33794
34344
|
}
|
|
34345
|
+
if (this.query.includeDeleted === false) {
|
|
34346
|
+
channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted) !== true; });
|
|
34347
|
+
}
|
|
33795
34348
|
// sort, 'lastCreated' is the default sort order
|
|
33796
34349
|
const sortBy = this.query.sortBy ? this.query.sortBy : 'lastCreated';
|
|
33797
34350
|
channelMembers = channelMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
@@ -34159,57 +34712,6 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
34159
34712
|
});
|
|
34160
34713
|
};
|
|
34161
34714
|
|
|
34162
|
-
const getMatchPostSetting = (value) => {
|
|
34163
|
-
var _a;
|
|
34164
|
-
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
34165
|
-
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
34166
|
-
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
34167
|
-
};
|
|
34168
|
-
const convertCommunityUsersToUniqueObject = (communityUsers) => {
|
|
34169
|
-
if (!communityUsers)
|
|
34170
|
-
return communityUsers;
|
|
34171
|
-
const result = {};
|
|
34172
|
-
communityUsers.forEach(user => {
|
|
34173
|
-
result[`${user.userId}#${user.communityId}`] = user;
|
|
34174
|
-
});
|
|
34175
|
-
return result;
|
|
34176
|
-
};
|
|
34177
|
-
const convertCommunityPayload = (rawPayload) => {
|
|
34178
|
-
// Unpack community payload by mapping payload field to postSetting value.
|
|
34179
|
-
const communities = rawPayload.communities.map((_a) => {
|
|
34180
|
-
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
34181
|
-
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
34182
|
-
needApprovalOnPostCreation,
|
|
34183
|
-
onlyAdminCanPost,
|
|
34184
|
-
}) }, restCommunityPayload));
|
|
34185
|
-
});
|
|
34186
|
-
const mergeCommunityUsers = communities.reduce((acc, { communityId }) => {
|
|
34187
|
-
var _a;
|
|
34188
|
-
const users = (_a = pullFromCache([
|
|
34189
|
-
'communityUsers',
|
|
34190
|
-
'collection',
|
|
34191
|
-
communityId,
|
|
34192
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
34193
|
-
if (!users)
|
|
34194
|
-
return acc;
|
|
34195
|
-
return Object.assign(Object.assign({}, convertCommunityUsersToUniqueObject(users)), acc);
|
|
34196
|
-
}, convertCommunityUsersToUniqueObject(rawPayload.communityUsers));
|
|
34197
|
-
const communityUsers = withUsers(Object.values(mergeCommunityUsers));
|
|
34198
|
-
const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
|
|
34199
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
|
|
34200
|
-
};
|
|
34201
|
-
const prepareCommunityPayload = (rawPayload) => {
|
|
34202
|
-
const { communities, communityUsers } = convertCommunityPayload(rawPayload);
|
|
34203
|
-
return Object.assign(Object.assign({}, rawPayload), { communities,
|
|
34204
|
-
communityUsers });
|
|
34205
|
-
};
|
|
34206
|
-
const prepareCommunityRequest = (params) => {
|
|
34207
|
-
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
34208
|
-
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
34209
|
-
// Convert story setting to the actual value. (Allow by default)
|
|
34210
|
-
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
34211
|
-
};
|
|
34212
|
-
|
|
34213
34715
|
/**
|
|
34214
34716
|
* ```js
|
|
34215
34717
|
* import { getCommunities } from '@amityco/ts-sdk-react-native'
|
|
@@ -34645,10 +35147,6 @@ const onCommunityUpdated = (callback) => createCommunityEventSubscriber('communi
|
|
|
34645
35147
|
*/
|
|
34646
35148
|
const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
|
|
34647
35149
|
|
|
34648
|
-
function isNonNullable(value) {
|
|
34649
|
-
return value != null;
|
|
34650
|
-
}
|
|
34651
|
-
|
|
34652
35150
|
function hasPermission(member, payload, permission) {
|
|
34653
35151
|
if (member.permissions.some(x => x === permission)) {
|
|
34654
35152
|
return true;
|
|
@@ -34663,7 +35161,7 @@ function getEventRelatedMember(event, payload) {
|
|
|
34663
35161
|
}
|
|
34664
35162
|
// NOTE: backend returns the one who took the action and the one on whom
|
|
34665
35163
|
// the action was taken. We need the 2nd one
|
|
34666
|
-
if (event === 'community.userRemoved') {
|
|
35164
|
+
if (event === 'community.userRemoved' || event === 'local.community.userRemoved') {
|
|
34667
35165
|
return payload.communityUsers.filter(x => x.communityMembership === 'none');
|
|
34668
35166
|
}
|
|
34669
35167
|
if (event === 'community.userBanned') {
|
|
@@ -34711,6 +35209,43 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
|
|
|
34711
35209
|
}
|
|
34712
35210
|
};
|
|
34713
35211
|
return createEventSubscriber(client, event, event, filter);
|
|
35212
|
+
};
|
|
35213
|
+
const createLocalCommunityMemberEventSubscriber = (event, callback) => {
|
|
35214
|
+
const client = getActiveClient();
|
|
35215
|
+
const filter = (payload) => {
|
|
35216
|
+
const preparedPayload = prepareCommunityPayload(payload);
|
|
35217
|
+
const { communities, communityUsers } = preparedPayload;
|
|
35218
|
+
/*
|
|
35219
|
+
* community.isJoined is not part of the communityMembership payload, and needs
|
|
35220
|
+
* to be calculated based on the communityMembership value
|
|
35221
|
+
*/
|
|
35222
|
+
const communitiesWithMembership = updateMembershipStatus(communities, communityUsers);
|
|
35223
|
+
preparedPayload.communities = communitiesWithMembership;
|
|
35224
|
+
if (!client.cache) {
|
|
35225
|
+
// TODO: here we are missing specific properties here!
|
|
35226
|
+
callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
|
|
35227
|
+
}
|
|
35228
|
+
else {
|
|
35229
|
+
ingestInCache(preparedPayload);
|
|
35230
|
+
const community = pullFromCache([
|
|
35231
|
+
'community',
|
|
35232
|
+
'get',
|
|
35233
|
+
preparedPayload.communities[0].communityId,
|
|
35234
|
+
]);
|
|
35235
|
+
const members = getEventRelatedMember(event, preparedPayload)
|
|
35236
|
+
.map(member => {
|
|
35237
|
+
const memberCache = pullFromCache([
|
|
35238
|
+
'communityUsers',
|
|
35239
|
+
'get',
|
|
35240
|
+
getResolver('communityUsers')(member),
|
|
35241
|
+
]);
|
|
35242
|
+
return memberCache === null || memberCache === void 0 ? void 0 : memberCache.data;
|
|
35243
|
+
})
|
|
35244
|
+
.filter(isNonNullable);
|
|
35245
|
+
callback(community.data, members);
|
|
35246
|
+
}
|
|
35247
|
+
};
|
|
35248
|
+
return createEventSubscriber(client, event, event, filter);
|
|
34714
35249
|
};
|
|
34715
35250
|
|
|
34716
35251
|
/**
|
|
@@ -34832,6 +35367,40 @@ const onCommunityUserRoleAdded = (callback) => createCommunityMemberEventSubscri
|
|
|
34832
35367
|
*/
|
|
34833
35368
|
const onCommunityUserRoleRemoved = (callback) => createCommunityMemberEventSubscriber('community.roleRemoved', callback);
|
|
34834
35369
|
|
|
35370
|
+
/**
|
|
35371
|
+
* ```js
|
|
35372
|
+
* import { onLocalCommunityUserAdded } from '@amityco/ts-sdk-react-native'
|
|
35373
|
+
* const dispose = onLocalCommunityUserAdded((community, member) => {
|
|
35374
|
+
* // ...
|
|
35375
|
+
* })
|
|
35376
|
+
* ```
|
|
35377
|
+
*
|
|
35378
|
+
* Fired when a user has been added to a {@link Amity.Community}
|
|
35379
|
+
*
|
|
35380
|
+
* @param callback The function to call when the event was fired
|
|
35381
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35382
|
+
*
|
|
35383
|
+
* @category Community Events
|
|
35384
|
+
*/
|
|
35385
|
+
const onLocalCommunityUserAdded = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userAdded', callback);
|
|
35386
|
+
|
|
35387
|
+
/**
|
|
35388
|
+
* ```js
|
|
35389
|
+
* import { onLocalCommunityUserRemoved } from '@amityco/ts-sdk-react-native'
|
|
35390
|
+
* const dispose = onLocalCommunityUserRemoved((community, member) => {
|
|
35391
|
+
* // ...
|
|
35392
|
+
* })
|
|
35393
|
+
* ```
|
|
35394
|
+
*
|
|
35395
|
+
* Fired when a user has been removed from a {@link Amity.Community}
|
|
35396
|
+
*
|
|
35397
|
+
* @param callback The function to call when the event was fired
|
|
35398
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35399
|
+
*
|
|
35400
|
+
* @category Community Events
|
|
35401
|
+
*/
|
|
35402
|
+
const onLocalCommunityUserRemoved = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userRemoved', callback);
|
|
35403
|
+
|
|
34835
35404
|
/**
|
|
34836
35405
|
* ```js
|
|
34837
35406
|
* import { onCommunityJoined } from '@amityco/ts-sdk-react-native'
|
|
@@ -34984,6 +35553,9 @@ var EnumCommunityMemberActions$1;
|
|
|
34984
35553
|
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
34985
35554
|
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
34986
35555
|
EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
|
|
35556
|
+
EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
|
|
35557
|
+
EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
|
|
35558
|
+
EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
|
|
34987
35559
|
})(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
|
|
34988
35560
|
|
|
34989
35561
|
/* begin_public_function
|
|
@@ -35008,7 +35580,7 @@ const addMembers = async (communityId, userIds) => {
|
|
|
35008
35580
|
const client = getActiveClient();
|
|
35009
35581
|
client.log('community/moderation/addMembers', communityId, userIds);
|
|
35010
35582
|
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
35011
|
-
fireEvent('community.userAdded', payload);
|
|
35583
|
+
fireEvent('local.community.userAdded', payload);
|
|
35012
35584
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
35013
35585
|
if (client.cache)
|
|
35014
35586
|
ingestInCache(data);
|
|
@@ -35039,7 +35611,7 @@ const removeMembers = async (communityId, userIds) => {
|
|
|
35039
35611
|
const client = getActiveClient();
|
|
35040
35612
|
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
35041
35613
|
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
35042
|
-
fireEvent('community.userRemoved', payload);
|
|
35614
|
+
fireEvent('local.community.userRemoved', payload);
|
|
35043
35615
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
35044
35616
|
if (client.cache)
|
|
35045
35617
|
ingestInCache(data);
|
|
@@ -35054,10 +35626,12 @@ const removeMembers = async (communityId, userIds) => {
|
|
|
35054
35626
|
*/
|
|
35055
35627
|
class CommunityMembersPaginationController extends PaginationController {
|
|
35056
35628
|
async getRequest(queryParams, token) {
|
|
35057
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35629
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
35058
35630
|
const options = token ? { token } : { limit };
|
|
35631
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
35059
35632
|
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
35060
|
-
params: Object.assign(Object.assign({}, params), { options
|
|
35633
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
35634
|
+
isDeleted }),
|
|
35061
35635
|
});
|
|
35062
35636
|
return queryResponse;
|
|
35063
35637
|
}
|
|
@@ -35126,6 +35700,96 @@ class CommunityMembersQueryStreamController extends QueryStreamController {
|
|
|
35126
35700
|
}
|
|
35127
35701
|
}
|
|
35128
35702
|
|
|
35703
|
+
/**
|
|
35704
|
+
* ```js
|
|
35705
|
+
* import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk-react-native'
|
|
35706
|
+
* const dispose = onLocalCommunityRoleRemoved((community, member) => {
|
|
35707
|
+
* // ...
|
|
35708
|
+
* })
|
|
35709
|
+
* ```
|
|
35710
|
+
*
|
|
35711
|
+
* Fired when any {@link Amity.communityUsers} 's role has been added to any {@link Amity.Community}
|
|
35712
|
+
*
|
|
35713
|
+
* @param callback The function to call when the event was fired
|
|
35714
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35715
|
+
*
|
|
35716
|
+
* @category Community Events
|
|
35717
|
+
*/
|
|
35718
|
+
const onLocalCommunityRoleRemoved = (callback) => {
|
|
35719
|
+
const client = getActiveClient();
|
|
35720
|
+
const filter = async (payload) => {
|
|
35721
|
+
const { communities, communityUsers } = payload;
|
|
35722
|
+
callback(communities[0], communityUsers.filter(communityUser => communityUser.communityMembership === 'member'));
|
|
35723
|
+
};
|
|
35724
|
+
return createEventSubscriber(client, 'onLocalCommunityRoleRemoved', 'local.community.roleRemoved', filter);
|
|
35725
|
+
};
|
|
35726
|
+
|
|
35727
|
+
/**
|
|
35728
|
+
* ```js
|
|
35729
|
+
* import { onLocalCommunityRoleAdded } from '@amityco/ts-sdk-react-native'
|
|
35730
|
+
* const dispose = onLocalCommunityRoleAdded((community, member) => {
|
|
35731
|
+
* // ...
|
|
35732
|
+
* })
|
|
35733
|
+
* ```
|
|
35734
|
+
*
|
|
35735
|
+
* Fired when any {@link Amity.communityUsers} 's role has been added to any {@link Amity.Community}
|
|
35736
|
+
*
|
|
35737
|
+
* @param callback The function to call when the event was fired
|
|
35738
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35739
|
+
*
|
|
35740
|
+
* @category Community Events
|
|
35741
|
+
*/
|
|
35742
|
+
const onLocalCommunityRoleAdded = (callback) => {
|
|
35743
|
+
const client = getActiveClient();
|
|
35744
|
+
const filter = async (payload) => {
|
|
35745
|
+
const { communities, communityUsers } = payload;
|
|
35746
|
+
callback(communities[0], communityUsers.filter(communityUser => communityUser.communityMembership === 'member'));
|
|
35747
|
+
};
|
|
35748
|
+
return createEventSubscriber(client, 'onLocalCommunityRoleAdded', 'local.community.roleAdded', filter);
|
|
35749
|
+
};
|
|
35750
|
+
|
|
35751
|
+
/**
|
|
35752
|
+
* ```js
|
|
35753
|
+
* import { onUserDeleted } from '@amityco/ts-sdk'
|
|
35754
|
+
* const dispose = onUserDeleted((community, member) => {
|
|
35755
|
+
* // ...
|
|
35756
|
+
* })
|
|
35757
|
+
* ```
|
|
35758
|
+
*
|
|
35759
|
+
* Fired when a {@link Amity.Community} has been joined
|
|
35760
|
+
*
|
|
35761
|
+
* @param callback The function to call when the event was fired
|
|
35762
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35763
|
+
*
|
|
35764
|
+
* @category Community Events
|
|
35765
|
+
*/
|
|
35766
|
+
const onUserDeleted = (communityId) => (callback) => {
|
|
35767
|
+
const client = getActiveClient();
|
|
35768
|
+
const filter = (payload) => {
|
|
35769
|
+
var _a, _b;
|
|
35770
|
+
const userPayload = prepareUserPayload(payload);
|
|
35771
|
+
if (userPayload.users.length === 0)
|
|
35772
|
+
return;
|
|
35773
|
+
const user = userPayload.users[0];
|
|
35774
|
+
ingestInCache(userPayload);
|
|
35775
|
+
const communityUserCacheKey = getResolver('communityUsers')({
|
|
35776
|
+
communityId,
|
|
35777
|
+
userId: user.userId,
|
|
35778
|
+
});
|
|
35779
|
+
const cacheData = (_a = pullFromCache([
|
|
35780
|
+
'communityUsers',
|
|
35781
|
+
'get',
|
|
35782
|
+
communityUserCacheKey,
|
|
35783
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
35784
|
+
pushToCache(['communityUsers', 'get', communityUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
|
|
35785
|
+
const community = (_b = pullFromCache(['community', 'get', communityId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
35786
|
+
callback(community, [
|
|
35787
|
+
Object.assign(Object.assign({}, cacheData), { user }),
|
|
35788
|
+
]);
|
|
35789
|
+
};
|
|
35790
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
35791
|
+
};
|
|
35792
|
+
|
|
35129
35793
|
class CommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
35130
35794
|
constructor(query, callback) {
|
|
35131
35795
|
const queryStreamId = hash(query);
|
|
@@ -35164,7 +35828,274 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
35164
35828
|
fn: onCommunityUserRoleRemoved,
|
|
35165
35829
|
action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
|
|
35166
35830
|
},
|
|
35831
|
+
{
|
|
35832
|
+
fn: onLocalCommunityRoleAdded,
|
|
35833
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserRoleAdded,
|
|
35834
|
+
},
|
|
35835
|
+
{
|
|
35836
|
+
fn: onLocalCommunityRoleRemoved,
|
|
35837
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
|
|
35838
|
+
},
|
|
35167
35839
|
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions$1.OnCommunityUserUnbanned },
|
|
35840
|
+
{ fn: onLocalCommunityUserAdded, action: EnumCommunityMemberActions$1.OnCommunityUserAdded },
|
|
35841
|
+
{
|
|
35842
|
+
fn: onLocalCommunityUserRemoved,
|
|
35843
|
+
action: EnumCommunityMemberActions$1.onCommunityUserRemoved,
|
|
35844
|
+
},
|
|
35845
|
+
{
|
|
35846
|
+
fn: onUserDeleted(this.query.communityId),
|
|
35847
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserChanged,
|
|
35848
|
+
},
|
|
35849
|
+
]);
|
|
35850
|
+
}
|
|
35851
|
+
notifyChange({ origin, loading, error }) {
|
|
35852
|
+
var _a, _b;
|
|
35853
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35854
|
+
if (!collection)
|
|
35855
|
+
return;
|
|
35856
|
+
const data = this.applyFilter((_b = collection.data
|
|
35857
|
+
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
35858
|
+
.filter(isNonNullable)
|
|
35859
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
35860
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
35861
|
+
return;
|
|
35862
|
+
this.callback({
|
|
35863
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
35864
|
+
data,
|
|
35865
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
35866
|
+
loading,
|
|
35867
|
+
error,
|
|
35868
|
+
});
|
|
35869
|
+
}
|
|
35870
|
+
applyFilter(data) {
|
|
35871
|
+
let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
|
|
35872
|
+
if (this.query.memberships) {
|
|
35873
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
35874
|
+
const memberships = this.query.memberships || [];
|
|
35875
|
+
return memberships.includes(communityMembership);
|
|
35876
|
+
});
|
|
35877
|
+
}
|
|
35878
|
+
if (this.query.search) {
|
|
35879
|
+
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
35880
|
+
}
|
|
35881
|
+
if (this.query.includeDeleted === false) {
|
|
35882
|
+
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
|
|
35883
|
+
}
|
|
35884
|
+
switch (this.query.sortBy) {
|
|
35885
|
+
case 'firstCreated':
|
|
35886
|
+
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
35887
|
+
break;
|
|
35888
|
+
case 'displayName':
|
|
35889
|
+
communityMembers = communityMembers.sort((a, b) => {
|
|
35890
|
+
var _a, _b, _c, _d;
|
|
35891
|
+
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)) {
|
|
35892
|
+
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);
|
|
35893
|
+
}
|
|
35894
|
+
return 0;
|
|
35895
|
+
});
|
|
35896
|
+
break;
|
|
35897
|
+
case 'lastCreated':
|
|
35898
|
+
default:
|
|
35899
|
+
communityMembers = communityMembers.sort(sortByLastCreated);
|
|
35900
|
+
break;
|
|
35901
|
+
}
|
|
35902
|
+
return communityMembers;
|
|
35903
|
+
}
|
|
35904
|
+
}
|
|
35905
|
+
|
|
35906
|
+
/*
|
|
35907
|
+
* Exported for testing
|
|
35908
|
+
* @hidden
|
|
35909
|
+
*/
|
|
35910
|
+
const applyFilter = (data, params) => {
|
|
35911
|
+
let communityMembers = filterByPropIntersection(data, 'roles', params.roles);
|
|
35912
|
+
if (params.memberships) {
|
|
35913
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
35914
|
+
const membership = params.memberships;
|
|
35915
|
+
return membership.includes(communityMembership);
|
|
35916
|
+
});
|
|
35917
|
+
}
|
|
35918
|
+
if (params.search) {
|
|
35919
|
+
communityMembers = filterBySearchTerm(communityMembers, params.search);
|
|
35920
|
+
}
|
|
35921
|
+
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
35922
|
+
communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
35923
|
+
return communityMembers;
|
|
35924
|
+
};
|
|
35925
|
+
/* begin_public_function
|
|
35926
|
+
id: community.membership.query
|
|
35927
|
+
*/
|
|
35928
|
+
/**
|
|
35929
|
+
* ```js
|
|
35930
|
+
* import { getMembers } from '@amityco/ts-sdk-react-native'
|
|
35931
|
+
*
|
|
35932
|
+
* let communityMembers = []
|
|
35933
|
+
* const unsub = getMembers({
|
|
35934
|
+
* communityId: Amity.Community['communityId'],
|
|
35935
|
+
* }, response => merge(communityMembers, response.data))
|
|
35936
|
+
* ```
|
|
35937
|
+
*
|
|
35938
|
+
* Observe all mutations on a list of {@link Amity.CommunityUser}s
|
|
35939
|
+
*
|
|
35940
|
+
* @param params for querying community users
|
|
35941
|
+
* @param callback the function to call when new data are available
|
|
35942
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community users
|
|
35943
|
+
*
|
|
35944
|
+
* @category Community Live Collection
|
|
35945
|
+
*/
|
|
35946
|
+
const getMembers = (params, callback, config) => {
|
|
35947
|
+
const { log, cache } = getActiveClient();
|
|
35948
|
+
if (!cache) {
|
|
35949
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
35950
|
+
}
|
|
35951
|
+
const timestamp = Date.now();
|
|
35952
|
+
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
35953
|
+
const communityMemberLiveCollection = new CommunityMembersLiveCollectionController(params, resp => {
|
|
35954
|
+
callback(resp);
|
|
35955
|
+
});
|
|
35956
|
+
const disposers = communityMemberLiveCollection.startSubscription();
|
|
35957
|
+
const cacheKey = communityMemberLiveCollection.getCacheKey();
|
|
35958
|
+
disposers.push(() => {
|
|
35959
|
+
dropFromCache(cacheKey);
|
|
35960
|
+
});
|
|
35961
|
+
return () => {
|
|
35962
|
+
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
35963
|
+
disposers.forEach(fn => fn());
|
|
35964
|
+
};
|
|
35965
|
+
};
|
|
35966
|
+
/* end_public_function */
|
|
35967
|
+
|
|
35968
|
+
/**
|
|
35969
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
35970
|
+
* TODO: check if querybyIds is supported
|
|
35971
|
+
*/
|
|
35972
|
+
class SearchCommunityMembersPaginationController extends PaginationController {
|
|
35973
|
+
async getRequest(queryParams, token) {
|
|
35974
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
35975
|
+
const options = token ? { token } : { limit };
|
|
35976
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
35977
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
35978
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
35979
|
+
isDeleted }),
|
|
35980
|
+
});
|
|
35981
|
+
return queryResponse;
|
|
35982
|
+
}
|
|
35983
|
+
}
|
|
35984
|
+
|
|
35985
|
+
class SearchCommunityMembersQueryStreamController extends QueryStreamController {
|
|
35986
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
35987
|
+
super(query, cacheKey);
|
|
35988
|
+
this.notifyChange = notifyChange;
|
|
35989
|
+
this.preparePayload = preparePayload;
|
|
35990
|
+
}
|
|
35991
|
+
async saveToMainDB(response) {
|
|
35992
|
+
const processedPayload = await this.preparePayload(response);
|
|
35993
|
+
const client = getActiveClient();
|
|
35994
|
+
const cachedAt = client.cache && Date.now();
|
|
35995
|
+
if (client.cache) {
|
|
35996
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
35997
|
+
}
|
|
35998
|
+
}
|
|
35999
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
36000
|
+
var _a, _b;
|
|
36001
|
+
if (refresh) {
|
|
36002
|
+
pushToCache(this.cacheKey, {
|
|
36003
|
+
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
36004
|
+
});
|
|
36005
|
+
}
|
|
36006
|
+
else {
|
|
36007
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36008
|
+
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
36009
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
36010
|
+
...new Set([
|
|
36011
|
+
...communityUsers,
|
|
36012
|
+
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
36013
|
+
]),
|
|
36014
|
+
] }));
|
|
36015
|
+
}
|
|
36016
|
+
}
|
|
36017
|
+
reactor(action) {
|
|
36018
|
+
return (community, communityMembers) => {
|
|
36019
|
+
var _a;
|
|
36020
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36021
|
+
if (!collection)
|
|
36022
|
+
return;
|
|
36023
|
+
communityMembers.forEach(communityMember => {
|
|
36024
|
+
const communityMemberCacheId = getResolver('communityUsers')({
|
|
36025
|
+
communityId: this.query.communityId,
|
|
36026
|
+
userId: communityMember.userId,
|
|
36027
|
+
});
|
|
36028
|
+
if (communityMember.communityMembership === 'none') {
|
|
36029
|
+
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
36030
|
+
}
|
|
36031
|
+
});
|
|
36032
|
+
pushToCache(this.cacheKey, collection);
|
|
36033
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
36034
|
+
};
|
|
36035
|
+
}
|
|
36036
|
+
subscribeRTE(createSubscriber) {
|
|
36037
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
36038
|
+
}
|
|
36039
|
+
}
|
|
36040
|
+
|
|
36041
|
+
var EnumCommunityMemberActions;
|
|
36042
|
+
(function (EnumCommunityMemberActions) {
|
|
36043
|
+
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
36044
|
+
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
36045
|
+
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
36046
|
+
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
36047
|
+
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
36048
|
+
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
36049
|
+
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
36050
|
+
})(EnumCommunityMemberActions || (EnumCommunityMemberActions = {}));
|
|
36051
|
+
|
|
36052
|
+
/* eslint-disable no-use-before-define */
|
|
36053
|
+
class SearchCommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
36054
|
+
constructor(query, callback) {
|
|
36055
|
+
const queryStreamId = hash(query);
|
|
36056
|
+
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
36057
|
+
const paginationController = new SearchCommunityMembersPaginationController(query);
|
|
36058
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
36059
|
+
this.query = query;
|
|
36060
|
+
this.queryStreamController = new SearchCommunityMembersQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
36061
|
+
this.callback = callback.bind(this);
|
|
36062
|
+
this.loadPage({ initial: true });
|
|
36063
|
+
}
|
|
36064
|
+
setup() {
|
|
36065
|
+
var _a;
|
|
36066
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36067
|
+
if (!collection) {
|
|
36068
|
+
pushToCache(this.cacheKey, {
|
|
36069
|
+
data: [],
|
|
36070
|
+
params: {},
|
|
36071
|
+
});
|
|
36072
|
+
}
|
|
36073
|
+
}
|
|
36074
|
+
async persistModel(queryPayload) {
|
|
36075
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
36076
|
+
}
|
|
36077
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
36078
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
36079
|
+
}
|
|
36080
|
+
startSubscription() {
|
|
36081
|
+
return this.queryStreamController.subscribeRTE([
|
|
36082
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
36083
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
36084
|
+
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
36085
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
36086
|
+
{
|
|
36087
|
+
fn: onLocalCommunityRoleRemoved,
|
|
36088
|
+
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
36089
|
+
},
|
|
36090
|
+
{
|
|
36091
|
+
fn: onCommunityUserRoleRemoved,
|
|
36092
|
+
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
36093
|
+
},
|
|
36094
|
+
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
|
|
36095
|
+
{
|
|
36096
|
+
fn: onUserDeleted(this.query.communityId),
|
|
36097
|
+
action: EnumCommunityMemberActions.OnCommunityUserChanged,
|
|
36098
|
+
},
|
|
35168
36099
|
]);
|
|
35169
36100
|
}
|
|
35170
36101
|
notifyChange({ origin, loading, error }) {
|
|
@@ -35197,242 +36128,8 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
35197
36128
|
if (this.query.search) {
|
|
35198
36129
|
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
35199
36130
|
}
|
|
35200
|
-
|
|
35201
|
-
|
|
35202
|
-
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
35203
|
-
break;
|
|
35204
|
-
case 'displayName':
|
|
35205
|
-
communityMembers = communityMembers.sort((a, b) => {
|
|
35206
|
-
var _a, _b, _c, _d;
|
|
35207
|
-
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)) {
|
|
35208
|
-
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);
|
|
35209
|
-
}
|
|
35210
|
-
return 0;
|
|
35211
|
-
});
|
|
35212
|
-
break;
|
|
35213
|
-
case 'lastCreated':
|
|
35214
|
-
default:
|
|
35215
|
-
communityMembers = communityMembers.sort(sortByLastCreated);
|
|
35216
|
-
break;
|
|
35217
|
-
}
|
|
35218
|
-
return communityMembers;
|
|
35219
|
-
}
|
|
35220
|
-
}
|
|
35221
|
-
|
|
35222
|
-
/*
|
|
35223
|
-
* Exported for testing
|
|
35224
|
-
* @hidden
|
|
35225
|
-
*/
|
|
35226
|
-
const applyFilter = (data, params) => {
|
|
35227
|
-
let communityMembers = filterByPropIntersection(data, 'roles', params.roles);
|
|
35228
|
-
if (params.memberships) {
|
|
35229
|
-
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
35230
|
-
const membership = params.memberships;
|
|
35231
|
-
return membership.includes(communityMembership);
|
|
35232
|
-
});
|
|
35233
|
-
}
|
|
35234
|
-
if (params.search) {
|
|
35235
|
-
communityMembers = filterBySearchTerm(communityMembers, params.search);
|
|
35236
|
-
}
|
|
35237
|
-
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
35238
|
-
communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
35239
|
-
return communityMembers;
|
|
35240
|
-
};
|
|
35241
|
-
/* begin_public_function
|
|
35242
|
-
id: community.membership.query
|
|
35243
|
-
*/
|
|
35244
|
-
/**
|
|
35245
|
-
* ```js
|
|
35246
|
-
* import { getMembers } from '@amityco/ts-sdk-react-native'
|
|
35247
|
-
*
|
|
35248
|
-
* let communityMembers = []
|
|
35249
|
-
* const unsub = getMembers({
|
|
35250
|
-
* communityId: Amity.Community['communityId'],
|
|
35251
|
-
* }, response => merge(communityMembers, response.data))
|
|
35252
|
-
* ```
|
|
35253
|
-
*
|
|
35254
|
-
* Observe all mutations on a list of {@link Amity.CommunityUser}s
|
|
35255
|
-
*
|
|
35256
|
-
* @param params for querying community users
|
|
35257
|
-
* @param callback the function to call when new data are available
|
|
35258
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community users
|
|
35259
|
-
*
|
|
35260
|
-
* @category Community Live Collection
|
|
35261
|
-
*/
|
|
35262
|
-
const getMembers = (params, callback, config) => {
|
|
35263
|
-
const { log, cache } = getActiveClient();
|
|
35264
|
-
if (!cache) {
|
|
35265
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
35266
|
-
}
|
|
35267
|
-
const timestamp = Date.now();
|
|
35268
|
-
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
35269
|
-
const communityMemberLiveCollection = new CommunityMembersLiveCollectionController(params, resp => {
|
|
35270
|
-
callback(resp);
|
|
35271
|
-
});
|
|
35272
|
-
const disposers = communityMemberLiveCollection.startSubscription();
|
|
35273
|
-
const cacheKey = communityMemberLiveCollection.getCacheKey();
|
|
35274
|
-
disposers.push(() => {
|
|
35275
|
-
dropFromCache(cacheKey);
|
|
35276
|
-
});
|
|
35277
|
-
return () => {
|
|
35278
|
-
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
35279
|
-
disposers.forEach(fn => fn());
|
|
35280
|
-
};
|
|
35281
|
-
};
|
|
35282
|
-
/* end_public_function */
|
|
35283
|
-
|
|
35284
|
-
/**
|
|
35285
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
35286
|
-
* TODO: check if querybyIds is supported
|
|
35287
|
-
*/
|
|
35288
|
-
class SearchCommunityMembersPaginationController extends PaginationController {
|
|
35289
|
-
async getRequest(queryParams, token) {
|
|
35290
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35291
|
-
const options = token ? { token } : { limit };
|
|
35292
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
35293
|
-
params: Object.assign(Object.assign({}, params), { options }),
|
|
35294
|
-
});
|
|
35295
|
-
return queryResponse;
|
|
35296
|
-
}
|
|
35297
|
-
}
|
|
35298
|
-
|
|
35299
|
-
class SearchCommunityMembersQueryStreamController extends QueryStreamController {
|
|
35300
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
35301
|
-
super(query, cacheKey);
|
|
35302
|
-
this.notifyChange = notifyChange;
|
|
35303
|
-
this.preparePayload = preparePayload;
|
|
35304
|
-
}
|
|
35305
|
-
async saveToMainDB(response) {
|
|
35306
|
-
const processedPayload = await this.preparePayload(response);
|
|
35307
|
-
const client = getActiveClient();
|
|
35308
|
-
const cachedAt = client.cache && Date.now();
|
|
35309
|
-
if (client.cache) {
|
|
35310
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
35311
|
-
}
|
|
35312
|
-
}
|
|
35313
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
35314
|
-
var _a, _b;
|
|
35315
|
-
if (refresh) {
|
|
35316
|
-
pushToCache(this.cacheKey, {
|
|
35317
|
-
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
35318
|
-
});
|
|
35319
|
-
}
|
|
35320
|
-
else {
|
|
35321
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35322
|
-
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
35323
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
35324
|
-
...new Set([
|
|
35325
|
-
...communityUsers,
|
|
35326
|
-
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
35327
|
-
]),
|
|
35328
|
-
] }));
|
|
35329
|
-
}
|
|
35330
|
-
}
|
|
35331
|
-
reactor(action) {
|
|
35332
|
-
return (community, communityMembers) => {
|
|
35333
|
-
var _a;
|
|
35334
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35335
|
-
if (!collection)
|
|
35336
|
-
return;
|
|
35337
|
-
communityMembers.forEach(communityMember => {
|
|
35338
|
-
const communityMemberCacheId = getResolver('communityUsers')({
|
|
35339
|
-
communityId: this.query.communityId,
|
|
35340
|
-
userId: communityMember.userId,
|
|
35341
|
-
});
|
|
35342
|
-
if (communityMember.communityMembership === 'none') {
|
|
35343
|
-
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
35344
|
-
}
|
|
35345
|
-
});
|
|
35346
|
-
pushToCache(this.cacheKey, collection);
|
|
35347
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
35348
|
-
};
|
|
35349
|
-
}
|
|
35350
|
-
subscribeRTE(createSubscriber) {
|
|
35351
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
35352
|
-
}
|
|
35353
|
-
}
|
|
35354
|
-
|
|
35355
|
-
var EnumCommunityMemberActions;
|
|
35356
|
-
(function (EnumCommunityMemberActions) {
|
|
35357
|
-
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
35358
|
-
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
35359
|
-
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
35360
|
-
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
35361
|
-
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
35362
|
-
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
35363
|
-
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
35364
|
-
})(EnumCommunityMemberActions || (EnumCommunityMemberActions = {}));
|
|
35365
|
-
|
|
35366
|
-
/* eslint-disable no-use-before-define */
|
|
35367
|
-
class SearchCommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
35368
|
-
constructor(query, callback) {
|
|
35369
|
-
const queryStreamId = hash(query);
|
|
35370
|
-
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
35371
|
-
const paginationController = new SearchCommunityMembersPaginationController(query);
|
|
35372
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
35373
|
-
this.query = query;
|
|
35374
|
-
this.queryStreamController = new SearchCommunityMembersQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
35375
|
-
this.callback = callback.bind(this);
|
|
35376
|
-
this.loadPage({ initial: true });
|
|
35377
|
-
}
|
|
35378
|
-
setup() {
|
|
35379
|
-
var _a;
|
|
35380
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35381
|
-
if (!collection) {
|
|
35382
|
-
pushToCache(this.cacheKey, {
|
|
35383
|
-
data: [],
|
|
35384
|
-
params: {},
|
|
35385
|
-
});
|
|
35386
|
-
}
|
|
35387
|
-
}
|
|
35388
|
-
async persistModel(queryPayload) {
|
|
35389
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
35390
|
-
}
|
|
35391
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
35392
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
35393
|
-
}
|
|
35394
|
-
startSubscription() {
|
|
35395
|
-
return this.queryStreamController.subscribeRTE([
|
|
35396
|
-
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
35397
|
-
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
35398
|
-
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
35399
|
-
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
35400
|
-
{
|
|
35401
|
-
fn: onCommunityUserRoleRemoved,
|
|
35402
|
-
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
35403
|
-
},
|
|
35404
|
-
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
|
|
35405
|
-
]);
|
|
35406
|
-
}
|
|
35407
|
-
notifyChange({ origin, loading, error }) {
|
|
35408
|
-
var _a, _b;
|
|
35409
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35410
|
-
if (!collection)
|
|
35411
|
-
return;
|
|
35412
|
-
const data = this.applyFilter((_b = collection.data
|
|
35413
|
-
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
35414
|
-
.filter(isNonNullable)
|
|
35415
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
35416
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
35417
|
-
return;
|
|
35418
|
-
this.callback({
|
|
35419
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
35420
|
-
data,
|
|
35421
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
35422
|
-
loading,
|
|
35423
|
-
error,
|
|
35424
|
-
});
|
|
35425
|
-
}
|
|
35426
|
-
applyFilter(data) {
|
|
35427
|
-
let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
|
|
35428
|
-
if (this.query.memberships) {
|
|
35429
|
-
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
35430
|
-
const memberships = this.query.memberships || [];
|
|
35431
|
-
return memberships.includes(communityMembership);
|
|
35432
|
-
});
|
|
35433
|
-
}
|
|
35434
|
-
if (this.query.search) {
|
|
35435
|
-
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
36131
|
+
if (this.query.includeDeleted === false) {
|
|
36132
|
+
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
|
|
35436
36133
|
}
|
|
35437
36134
|
return communityMembers;
|
|
35438
36135
|
}
|
|
@@ -35495,6 +36192,8 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
35495
36192
|
onCommunityUserUnbanned: onCommunityUserUnbanned,
|
|
35496
36193
|
onCommunityUserRoleAdded: onCommunityUserRoleAdded,
|
|
35497
36194
|
onCommunityUserRoleRemoved: onCommunityUserRoleRemoved,
|
|
36195
|
+
onLocalCommunityUserAdded: onLocalCommunityUserAdded,
|
|
36196
|
+
onLocalCommunityUserRemoved: onLocalCommunityUserRemoved,
|
|
35498
36197
|
onCommunityJoined: onCommunityJoined,
|
|
35499
36198
|
onCommunityLeft: onCommunityLeft
|
|
35500
36199
|
});
|
|
@@ -36151,9 +36850,10 @@ const addRoles = async (communityId, roleIds, userIds) => {
|
|
|
36151
36850
|
const client = getActiveClient();
|
|
36152
36851
|
client.log('community/moderation/addRoles', communityId, roleIds, userIds);
|
|
36153
36852
|
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/users/roles`, { communityId, roles: roleIds, userIds });
|
|
36154
|
-
const data =
|
|
36853
|
+
const data = prepareCommunityMembershipPayload(payload);
|
|
36155
36854
|
if (client.cache)
|
|
36156
36855
|
ingestInCache(data);
|
|
36856
|
+
fireEvent('local.community.roleAdded', data);
|
|
36157
36857
|
const { communityUsers } = data;
|
|
36158
36858
|
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
36159
36859
|
roleIds.some(role => communityUser.roles.includes(role)));
|
|
@@ -36183,9 +36883,10 @@ const removeRoles = async (communityId, roleIds, userIds) => {
|
|
|
36183
36883
|
const client = getActiveClient();
|
|
36184
36884
|
client.log('community/moderation/removeRoles', communityId, roleIds, userIds);
|
|
36185
36885
|
const { data: payload } = await client.http.delete(`/api/v4/communities/${communityId}/users/roles`, { data: { communityId, roles: roleIds, userIds } });
|
|
36186
|
-
const data =
|
|
36886
|
+
const data = prepareCommunityMembershipPayload(payload);
|
|
36187
36887
|
if (client.cache)
|
|
36188
36888
|
ingestInCache(data);
|
|
36889
|
+
fireEvent('local.community.roleRemoved', data);
|
|
36189
36890
|
const { communityUsers } = data;
|
|
36190
36891
|
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
36191
36892
|
!roleIds.some(role => communityUser.roles.includes(role)));
|
|
@@ -36872,7 +37573,7 @@ const updatePost = async (postId, patch) => {
|
|
|
36872
37573
|
const cachedAt = client.cache && Date.now();
|
|
36873
37574
|
if (client.cache)
|
|
36874
37575
|
ingestInCache(data, { cachedAt });
|
|
36875
|
-
fireEvent('local.post.updated',
|
|
37576
|
+
fireEvent('local.post.updated', payload);
|
|
36876
37577
|
const { posts } = data;
|
|
36877
37578
|
return {
|
|
36878
37579
|
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
@@ -36972,7 +37673,15 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
36972
37673
|
}
|
|
36973
37674
|
// to support hard deletion
|
|
36974
37675
|
const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
|
|
36975
|
-
|
|
37676
|
+
if (permanent) {
|
|
37677
|
+
setTimeout(() => {
|
|
37678
|
+
pushToTombstone('post', postId);
|
|
37679
|
+
}, 0);
|
|
37680
|
+
}
|
|
37681
|
+
else {
|
|
37682
|
+
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
37683
|
+
}
|
|
37684
|
+
fireEvent('local.post.deleted', {
|
|
36976
37685
|
posts: [deleted],
|
|
36977
37686
|
categories: [],
|
|
36978
37687
|
comments: [],
|
|
@@ -36983,14 +37692,6 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
36983
37692
|
postChildren: [],
|
|
36984
37693
|
users: [],
|
|
36985
37694
|
});
|
|
36986
|
-
if (permanent) {
|
|
36987
|
-
setTimeout(() => {
|
|
36988
|
-
pushToTombstone('post', postId);
|
|
36989
|
-
}, 0);
|
|
36990
|
-
}
|
|
36991
|
-
else {
|
|
36992
|
-
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
36993
|
-
}
|
|
36994
37695
|
return LinkedObject.post(deleted);
|
|
36995
37696
|
};
|
|
36996
37697
|
|
|
@@ -37378,6 +38079,7 @@ getCommentByIds.locally = (commentIds) => {
|
|
|
37378
38079
|
* @async
|
|
37379
38080
|
*/
|
|
37380
38081
|
const createComment = async (bundle) => {
|
|
38082
|
+
var _a;
|
|
37381
38083
|
const client = getActiveClient();
|
|
37382
38084
|
client.log('comment/createComment', bundle);
|
|
37383
38085
|
const { data } = await client.http.post('/api/v3/comments', bundle);
|
|
@@ -37389,18 +38091,21 @@ const createComment = async (bundle) => {
|
|
|
37389
38091
|
if (client.cache)
|
|
37390
38092
|
ingestInCache(data, { cachedAt });
|
|
37391
38093
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
37392
|
-
const post =
|
|
37393
|
-
|
|
37394
|
-
|
|
37395
|
-
|
|
37396
|
-
|
|
37397
|
-
|
|
37398
|
-
|
|
37399
|
-
|
|
37400
|
-
|
|
37401
|
-
|
|
37402
|
-
|
|
37403
|
-
|
|
38094
|
+
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
38095
|
+
if (post) {
|
|
38096
|
+
post.commentsCount += 1;
|
|
38097
|
+
fireEvent('local.post.updated', {
|
|
38098
|
+
posts: [post],
|
|
38099
|
+
categories: [],
|
|
38100
|
+
comments: [],
|
|
38101
|
+
communities: [],
|
|
38102
|
+
communityUsers: data.communityUsers,
|
|
38103
|
+
feeds: [],
|
|
38104
|
+
files: data.files,
|
|
38105
|
+
postChildren: [],
|
|
38106
|
+
users: data.users,
|
|
38107
|
+
});
|
|
38108
|
+
}
|
|
37404
38109
|
}
|
|
37405
38110
|
else if (bundle.referenceType === 'story') {
|
|
37406
38111
|
const storyIndex = pullFromCache([
|
|
@@ -37559,6 +38264,7 @@ getStoryByStoryId$1.locally = (storyId) => {
|
|
|
37559
38264
|
* @async
|
|
37560
38265
|
*/
|
|
37561
38266
|
const deleteComment = async (commentId, permanent = false) => {
|
|
38267
|
+
var _a;
|
|
37562
38268
|
const client = getActiveClient();
|
|
37563
38269
|
const comment = await getComment$2(commentId);
|
|
37564
38270
|
// API-FIX: This endpoint has not been implemented yet.
|
|
@@ -37583,18 +38289,28 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
37583
38289
|
});
|
|
37584
38290
|
}
|
|
37585
38291
|
else {
|
|
37586
|
-
const post =
|
|
37587
|
-
|
|
37588
|
-
|
|
37589
|
-
|
|
37590
|
-
|
|
37591
|
-
|
|
37592
|
-
|
|
37593
|
-
|
|
37594
|
-
|
|
37595
|
-
|
|
37596
|
-
|
|
37597
|
-
|
|
38292
|
+
const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
38293
|
+
if (post) {
|
|
38294
|
+
let removeCount;
|
|
38295
|
+
if (!deleted.parentId) {
|
|
38296
|
+
// NOTE: delete the parent comment will remove all children comments
|
|
38297
|
+
removeCount = deleted.childrenNumber + 1;
|
|
38298
|
+
}
|
|
38299
|
+
else
|
|
38300
|
+
removeCount = 1;
|
|
38301
|
+
post.commentsCount -= removeCount;
|
|
38302
|
+
fireEvent('local.post.updated', {
|
|
38303
|
+
posts: [post],
|
|
38304
|
+
categories: [],
|
|
38305
|
+
comments: [],
|
|
38306
|
+
communities: [],
|
|
38307
|
+
communityUsers: [],
|
|
38308
|
+
feeds: [],
|
|
38309
|
+
files: [],
|
|
38310
|
+
postChildren: [],
|
|
38311
|
+
users: [],
|
|
38312
|
+
});
|
|
38313
|
+
}
|
|
37598
38314
|
}
|
|
37599
38315
|
fireEvent('local.comment.deleted', {
|
|
37600
38316
|
comments: [deleted],
|
|
@@ -37860,6 +38576,81 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
|
37860
38576
|
};
|
|
37861
38577
|
};
|
|
37862
38578
|
|
|
38579
|
+
/**
|
|
38580
|
+
* ```js
|
|
38581
|
+
* import { onCommentDeleteLocal } from '@amityco/ts-sdk-react-native'
|
|
38582
|
+
* const dispose = onCommentDeleteLocal(comment => {
|
|
38583
|
+
* // ...
|
|
38584
|
+
* })
|
|
38585
|
+
* ```
|
|
38586
|
+
*
|
|
38587
|
+
* Fired when a {@link Amity.InternalComment} has been deleted
|
|
38588
|
+
*
|
|
38589
|
+
* @param callback The function to call when the event was fired
|
|
38590
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38591
|
+
*
|
|
38592
|
+
* @category Comment Events
|
|
38593
|
+
*/
|
|
38594
|
+
const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
|
|
38595
|
+
|
|
38596
|
+
/**
|
|
38597
|
+
* ```js
|
|
38598
|
+
* import { onLocalCommentReactionAdded } from '@amityco/ts-sdk-react-native'
|
|
38599
|
+
* const dispose = onLocalCommentReactionAdded(comment => {
|
|
38600
|
+
* // ...
|
|
38601
|
+
* })
|
|
38602
|
+
* ```
|
|
38603
|
+
*
|
|
38604
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
38605
|
+
*
|
|
38606
|
+
* @param callback The function to call when the event was fired
|
|
38607
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38608
|
+
*
|
|
38609
|
+
* @category Comment Events
|
|
38610
|
+
*/
|
|
38611
|
+
const onLocalCommentReactionAdded = (callback) => {
|
|
38612
|
+
const client = getActiveClient();
|
|
38613
|
+
const filter = ({ comment }) => {
|
|
38614
|
+
if (!client.cache) {
|
|
38615
|
+
callback(comment);
|
|
38616
|
+
}
|
|
38617
|
+
else {
|
|
38618
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
38619
|
+
callback(commentLinkedObject(comment));
|
|
38620
|
+
}
|
|
38621
|
+
};
|
|
38622
|
+
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
38623
|
+
};
|
|
38624
|
+
|
|
38625
|
+
/**
|
|
38626
|
+
* ```js
|
|
38627
|
+
* import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk-react-native'
|
|
38628
|
+
* const dispose = onLocalCommentReactionRemoved(comment => {
|
|
38629
|
+
* // ...
|
|
38630
|
+
* })
|
|
38631
|
+
* ```
|
|
38632
|
+
*
|
|
38633
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
38634
|
+
*
|
|
38635
|
+
* @param callback The function to call when the event was fired
|
|
38636
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38637
|
+
*
|
|
38638
|
+
* @category Comment Events
|
|
38639
|
+
*/
|
|
38640
|
+
const onLocalCommentReactionRemoved = (callback) => {
|
|
38641
|
+
const client = getActiveClient();
|
|
38642
|
+
const filter = ({ comment }) => {
|
|
38643
|
+
if (!client.cache) {
|
|
38644
|
+
callback(comment);
|
|
38645
|
+
}
|
|
38646
|
+
else {
|
|
38647
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
38648
|
+
callback(commentLinkedObject(comment));
|
|
38649
|
+
}
|
|
38650
|
+
};
|
|
38651
|
+
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
38652
|
+
};
|
|
38653
|
+
|
|
37863
38654
|
/* begin_public_function
|
|
37864
38655
|
id: comment.get
|
|
37865
38656
|
*/
|
|
@@ -37884,26 +38675,15 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
|
37884
38675
|
*/
|
|
37885
38676
|
const getComment = (commentId, callback) => {
|
|
37886
38677
|
return liveObject(commentId, callback, 'commentId', getComment$1, [
|
|
38678
|
+
onCommentDeleteLocal,
|
|
37887
38679
|
onCommentDeleted,
|
|
37888
38680
|
onCommentFlagged,
|
|
37889
38681
|
onCommentReactionAdded,
|
|
37890
38682
|
onCommentReactionRemoved,
|
|
37891
38683
|
onCommentUnflagged,
|
|
37892
38684
|
onCommentUpdated,
|
|
37893
|
-
|
|
37894
|
-
|
|
37895
|
-
if (comment.parentId !== commentId)
|
|
37896
|
-
return;
|
|
37897
|
-
const cacheParent = pullFromCache([
|
|
37898
|
-
'comment',
|
|
37899
|
-
'get',
|
|
37900
|
-
comment.parentId,
|
|
37901
|
-
]);
|
|
37902
|
-
if (!(cacheParent === null || cacheParent === void 0 ? void 0 : cacheParent.data))
|
|
37903
|
-
return;
|
|
37904
|
-
callback(Object.assign(Object.assign({}, cacheParent.data), { childrenNumber: cacheParent.data.childrenNumber + 1, children: [...new Set([...cacheParent.data.children, comment.commentId])] }));
|
|
37905
|
-
});
|
|
37906
|
-
},
|
|
38685
|
+
onLocalCommentReactionAdded,
|
|
38686
|
+
onLocalCommentReactionRemoved,
|
|
37907
38687
|
]);
|
|
37908
38688
|
};
|
|
37909
38689
|
/* end_public_function */
|
|
@@ -37987,16 +38767,24 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
37987
38767
|
}
|
|
37988
38768
|
}
|
|
37989
38769
|
|
|
37990
|
-
|
|
37991
|
-
|
|
37992
|
-
|
|
37993
|
-
|
|
37994
|
-
|
|
37995
|
-
|
|
37996
|
-
|
|
37997
|
-
|
|
37998
|
-
|
|
37999
|
-
|
|
38770
|
+
/**
|
|
38771
|
+
* ```js
|
|
38772
|
+
* import { onCommentCreated } from '@amityco/ts-sdk-react-native'
|
|
38773
|
+
* const dispose = onCommentCreated(comment => {
|
|
38774
|
+
* // ...
|
|
38775
|
+
* })
|
|
38776
|
+
* ```
|
|
38777
|
+
*
|
|
38778
|
+
* Fired when a {@link Amity.InternalComment} has been created
|
|
38779
|
+
*
|
|
38780
|
+
* @param callback The function to call when the event was fired
|
|
38781
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38782
|
+
*
|
|
38783
|
+
* @category Comment Events
|
|
38784
|
+
*/
|
|
38785
|
+
const onCommentCreatedLocal = (callback) => {
|
|
38786
|
+
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
38787
|
+
};
|
|
38000
38788
|
|
|
38001
38789
|
class CommentLiveCollectionController extends LiveCollectionController {
|
|
38002
38790
|
constructor(query, callback) {
|
|
@@ -38027,6 +38815,8 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
38027
38815
|
}
|
|
38028
38816
|
startSubscription() {
|
|
38029
38817
|
return this.queryStreamController.subscribeRTE([
|
|
38818
|
+
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
38819
|
+
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
38030
38820
|
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
38031
38821
|
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
38032
38822
|
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
@@ -38034,6 +38824,8 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
38034
38824
|
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
38035
38825
|
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
38036
38826
|
{ fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
38827
|
+
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
38828
|
+
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
38037
38829
|
]);
|
|
38038
38830
|
}
|
|
38039
38831
|
notifyChange({ origin, loading, error }) {
|
|
@@ -38165,6 +38957,98 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
38165
38957
|
getComments: getComments
|
|
38166
38958
|
});
|
|
38167
38959
|
|
|
38960
|
+
/**
|
|
38961
|
+
* ```js
|
|
38962
|
+
* import { onPostUpdatedLocal } from '@amityco/ts-sdk-react-native'
|
|
38963
|
+
* const dispose = onPostUpdatedLocal(post => {
|
|
38964
|
+
* // ...
|
|
38965
|
+
* })
|
|
38966
|
+
* ```
|
|
38967
|
+
*
|
|
38968
|
+
* Fired when a {@link Amity.InternalPost} has been updated
|
|
38969
|
+
*
|
|
38970
|
+
* @param callback The function to call when the event was fired
|
|
38971
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38972
|
+
*
|
|
38973
|
+
* @category Post Events
|
|
38974
|
+
*/
|
|
38975
|
+
const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
|
|
38976
|
+
|
|
38977
|
+
/**
|
|
38978
|
+
* ```js
|
|
38979
|
+
* import { onLocalPostReactionAdded } from '@amityco/ts-sdk-react-native'
|
|
38980
|
+
* const dispose = onPostReactionAdded(post => {
|
|
38981
|
+
* // ...
|
|
38982
|
+
* })
|
|
38983
|
+
* ```
|
|
38984
|
+
*
|
|
38985
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
38986
|
+
*
|
|
38987
|
+
* @param callback The function to call when the event was fired
|
|
38988
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38989
|
+
*
|
|
38990
|
+
* @category Post Events
|
|
38991
|
+
*/
|
|
38992
|
+
const onLocalPostReactionAdded = (callback) => {
|
|
38993
|
+
const client = getActiveClient();
|
|
38994
|
+
const filter = ({ post }) => {
|
|
38995
|
+
if (!client.cache) {
|
|
38996
|
+
callback(post);
|
|
38997
|
+
}
|
|
38998
|
+
else {
|
|
38999
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
39000
|
+
callback(post);
|
|
39001
|
+
}
|
|
39002
|
+
};
|
|
39003
|
+
return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
|
|
39004
|
+
};
|
|
39005
|
+
|
|
39006
|
+
/**
|
|
39007
|
+
* ```js
|
|
39008
|
+
* import { onLocalPostReactionRemoved } from '@amityco/ts-sdk-react-native'
|
|
39009
|
+
* const dispose = onPostReactionRemoved(post => {
|
|
39010
|
+
* // ...
|
|
39011
|
+
* })
|
|
39012
|
+
* ```
|
|
39013
|
+
*
|
|
39014
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
39015
|
+
*
|
|
39016
|
+
* @param callback The function to call when the event was fired
|
|
39017
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
39018
|
+
*
|
|
39019
|
+
* @category Post Events
|
|
39020
|
+
*/
|
|
39021
|
+
const onLocalPostReactionRemoved = (callback) => {
|
|
39022
|
+
const client = getActiveClient();
|
|
39023
|
+
const filter = ({ post }) => {
|
|
39024
|
+
if (!client.cache) {
|
|
39025
|
+
callback(post);
|
|
39026
|
+
}
|
|
39027
|
+
else {
|
|
39028
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
39029
|
+
callback(post);
|
|
39030
|
+
}
|
|
39031
|
+
};
|
|
39032
|
+
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
39033
|
+
};
|
|
39034
|
+
|
|
39035
|
+
/**
|
|
39036
|
+
* ```js
|
|
39037
|
+
* import { onLocalPostDeleted } from '@amityco/ts-sdk-react-native'
|
|
39038
|
+
* const dispose = onLocalPostDeleted(post => {
|
|
39039
|
+
* // ...
|
|
39040
|
+
* })
|
|
39041
|
+
* ```
|
|
39042
|
+
*
|
|
39043
|
+
* Fired when a {@link Amity.InternalPost} has been deleted
|
|
39044
|
+
*
|
|
39045
|
+
* @param callback The function to call when the event was fired
|
|
39046
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
39047
|
+
*
|
|
39048
|
+
* @category Post Events
|
|
39049
|
+
*/
|
|
39050
|
+
const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
|
|
39051
|
+
|
|
38168
39052
|
/* begin_public_function
|
|
38169
39053
|
id: post.get
|
|
38170
39054
|
*/
|
|
@@ -38195,6 +39079,8 @@ const getPost$1 = (postId, callback) => {
|
|
|
38195
39079
|
return liveObject(postId, responder, 'postId', getPost$2, [
|
|
38196
39080
|
onPostApproved,
|
|
38197
39081
|
onPostDeclined,
|
|
39082
|
+
onLocalPostReactionAdded,
|
|
39083
|
+
onLocalPostReactionRemoved,
|
|
38198
39084
|
(callback) => {
|
|
38199
39085
|
return onPostDeleted((post) => {
|
|
38200
39086
|
var _a;
|
|
@@ -38229,6 +39115,8 @@ const getPost$1 = (postId, callback) => {
|
|
|
38229
39115
|
},
|
|
38230
39116
|
onPostUnflagged,
|
|
38231
39117
|
onPostUpdated,
|
|
39118
|
+
onPostUpdatedLocal,
|
|
39119
|
+
onLocalPostDeleted,
|
|
38232
39120
|
convertEventPayload((callback) => {
|
|
38233
39121
|
return onCommentCreated(async (comment) => {
|
|
38234
39122
|
if (comment.referenceId === postId) {
|
|
@@ -38350,17 +39238,6 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
38350
39238
|
}
|
|
38351
39239
|
}
|
|
38352
39240
|
|
|
38353
|
-
const preparePostPayload = (postPayload) => {
|
|
38354
|
-
const { posts } = postPayload;
|
|
38355
|
-
const { communities, communityUsers } = convertCommunityPayload({
|
|
38356
|
-
communities: postPayload.communities,
|
|
38357
|
-
communityUsers: postPayload.communityUsers,
|
|
38358
|
-
});
|
|
38359
|
-
return Object.assign(Object.assign({}, postPayload), { posts,
|
|
38360
|
-
communities,
|
|
38361
|
-
communityUsers });
|
|
38362
|
-
};
|
|
38363
|
-
|
|
38364
39241
|
const getPost = async (postId) => {
|
|
38365
39242
|
const client = getActiveClient();
|
|
38366
39243
|
client.log('post/getPost', postId);
|
|
@@ -38433,6 +39310,7 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
38433
39310
|
return this.queryStreamController.subscribeRTE([
|
|
38434
39311
|
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
38435
39312
|
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
39313
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
38436
39314
|
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
38437
39315
|
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
38438
39316
|
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
@@ -38440,6 +39318,9 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
38440
39318
|
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
38441
39319
|
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
38442
39320
|
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
39321
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
39322
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
39323
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
38443
39324
|
{
|
|
38444
39325
|
fn: convertEventPayload((callback) => {
|
|
38445
39326
|
return onCommentCreated(async (comment) => {
|
|
@@ -38557,6 +39438,138 @@ const getPosts = (params, callback, config) => {
|
|
|
38557
39438
|
};
|
|
38558
39439
|
/* end_public_function */
|
|
38559
39440
|
|
|
39441
|
+
class PinnedPostPaginationController extends PaginationController {
|
|
39442
|
+
async getRequest(queryParams, token) {
|
|
39443
|
+
const params = __rest(queryParams, ["limit"]);
|
|
39444
|
+
const { communityId, placement } = params;
|
|
39445
|
+
const path = placement
|
|
39446
|
+
? `/api/v1/pinned-posts/communities/${communityId}/${placement}`
|
|
39447
|
+
: `/api/v1/pinned-posts/communities/${communityId}`;
|
|
39448
|
+
const { data: queryResponse } = await this.http.get(path);
|
|
39449
|
+
return queryResponse;
|
|
39450
|
+
}
|
|
39451
|
+
}
|
|
39452
|
+
|
|
39453
|
+
class PinnedPostQueryStreamController extends QueryStreamController {
|
|
39454
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
39455
|
+
super(query, cacheKey);
|
|
39456
|
+
this.notifyChange = notifyChange;
|
|
39457
|
+
this.preparePayload = preparePayload;
|
|
39458
|
+
}
|
|
39459
|
+
// eslint-disable-next-line class-methods-use-this
|
|
39460
|
+
async saveToMainDB(response) {
|
|
39461
|
+
const client = getActiveClient();
|
|
39462
|
+
const cachedAt = client.cache && Date.now();
|
|
39463
|
+
if (client.cache) {
|
|
39464
|
+
ingestInCache(response, { cachedAt });
|
|
39465
|
+
}
|
|
39466
|
+
}
|
|
39467
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
39468
|
+
var _a, _b;
|
|
39469
|
+
if (refresh) {
|
|
39470
|
+
pushToCache(this.cacheKey, {
|
|
39471
|
+
data: response.pins.map(getResolver('pin')),
|
|
39472
|
+
});
|
|
39473
|
+
}
|
|
39474
|
+
else {
|
|
39475
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39476
|
+
const pinnedPosts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
39477
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...pinnedPosts, ...response.pins.map(getResolver('pin'))])] }));
|
|
39478
|
+
this.notifyChange({
|
|
39479
|
+
origin: "server" /* Amity.LiveDataOrigin.SERVER */,
|
|
39480
|
+
loading: false,
|
|
39481
|
+
});
|
|
39482
|
+
}
|
|
39483
|
+
}
|
|
39484
|
+
}
|
|
39485
|
+
|
|
39486
|
+
class PinnedPostLiveCollectionController extends LiveCollectionController {
|
|
39487
|
+
constructor(query, callback) {
|
|
39488
|
+
const queryStreamId = hash(query);
|
|
39489
|
+
const cacheKey = ['pinnedPosts', 'collection', queryStreamId];
|
|
39490
|
+
const paginationController = new PinnedPostPaginationController(query);
|
|
39491
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
39492
|
+
this.query = query;
|
|
39493
|
+
this.queryStreamController = new PinnedPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
|
|
39494
|
+
this.callback = callback.bind(this);
|
|
39495
|
+
this.loadPage({ initial: true });
|
|
39496
|
+
}
|
|
39497
|
+
setup() {
|
|
39498
|
+
var _a;
|
|
39499
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39500
|
+
if (!collection) {
|
|
39501
|
+
pushToCache(this.cacheKey, {
|
|
39502
|
+
data: [],
|
|
39503
|
+
params: {},
|
|
39504
|
+
});
|
|
39505
|
+
}
|
|
39506
|
+
}
|
|
39507
|
+
async persistModel(queryPayload) {
|
|
39508
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
39509
|
+
}
|
|
39510
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
39511
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
39512
|
+
}
|
|
39513
|
+
// eslint-disable-next-line class-methods-use-this
|
|
39514
|
+
startSubscription() {
|
|
39515
|
+
return [];
|
|
39516
|
+
}
|
|
39517
|
+
notifyChange({ origin, loading, error }) {
|
|
39518
|
+
var _a, _b;
|
|
39519
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39520
|
+
if (!collection)
|
|
39521
|
+
return;
|
|
39522
|
+
let data = ((_b = collection.data
|
|
39523
|
+
.map(id => pullFromCache(['pin', 'get', id]))
|
|
39524
|
+
.filter(isNonNullable)
|
|
39525
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.pinnedPost);
|
|
39526
|
+
data = this.applyFilter(data);
|
|
39527
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
39528
|
+
return;
|
|
39529
|
+
this.callback({
|
|
39530
|
+
data,
|
|
39531
|
+
loading,
|
|
39532
|
+
error,
|
|
39533
|
+
});
|
|
39534
|
+
}
|
|
39535
|
+
applyFilter(data) {
|
|
39536
|
+
let pinnedPost = data;
|
|
39537
|
+
switch (this.query.sortBy) {
|
|
39538
|
+
case 'lastCreated':
|
|
39539
|
+
pinnedPost = pinnedPost.sort(({ post: postA }, { post: postB }) => sortByLastCreated({ createdAt: postA === null || postA === void 0 ? void 0 : postA.createdAt }, { createdAt: postB === null || postB === void 0 ? void 0 : postB.createdAt }));
|
|
39540
|
+
break;
|
|
39541
|
+
}
|
|
39542
|
+
return pinnedPost;
|
|
39543
|
+
}
|
|
39544
|
+
}
|
|
39545
|
+
|
|
39546
|
+
/**
|
|
39547
|
+
* Get pinned posts for a community
|
|
39548
|
+
*
|
|
39549
|
+
* @param communityId the ID of the community
|
|
39550
|
+
* @param placement the placement of the pinned post ('announcement' or 'default'), or null to fetch all pinned posts
|
|
39551
|
+
* @returns the associated pinned post(s)
|
|
39552
|
+
*
|
|
39553
|
+
* @category Pined Posts Live Collection
|
|
39554
|
+
*
|
|
39555
|
+
*/
|
|
39556
|
+
const getPinnedPosts = (params, callback, config) => {
|
|
39557
|
+
const { log, cache } = getActiveClient();
|
|
39558
|
+
if (!cache) {
|
|
39559
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
39560
|
+
}
|
|
39561
|
+
const timestamp = Date.now();
|
|
39562
|
+
log(`getPinnedPosts(tmpid: ${timestamp}) > listen`);
|
|
39563
|
+
const pinnedPostLiveCollection = new PinnedPostLiveCollectionController(params, callback);
|
|
39564
|
+
const disposers = pinnedPostLiveCollection.startSubscription();
|
|
39565
|
+
const cacheKey = pinnedPostLiveCollection.getCacheKey();
|
|
39566
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
39567
|
+
return () => {
|
|
39568
|
+
log(`getPinnedPosts(tmpid: ${timestamp}) > dispose`);
|
|
39569
|
+
disposers.forEach(fn => fn());
|
|
39570
|
+
};
|
|
39571
|
+
};
|
|
39572
|
+
|
|
38560
39573
|
var index$5 = /*#__PURE__*/Object.freeze({
|
|
38561
39574
|
__proto__: null,
|
|
38562
39575
|
getPostByIds: getPostByIds,
|
|
@@ -38583,7 +39596,8 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
38583
39596
|
observePosts: observePosts,
|
|
38584
39597
|
observePost: observePost,
|
|
38585
39598
|
getPost: getPost$1,
|
|
38586
|
-
getPosts: getPosts
|
|
39599
|
+
getPosts: getPosts,
|
|
39600
|
+
getPinnedPosts: getPinnedPosts
|
|
38587
39601
|
});
|
|
38588
39602
|
|
|
38589
39603
|
/* begin_public_function
|