@amityco/ts-sdk-react-native 6.29.3-669217e.0 → 6.30.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/.env +26 -26
- 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/fileRepository/api/uploadFile.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadVideo.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 +2247 -1250
- package/dist/index.esm.js +2435 -1437
- 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/fileRepository/api/uploadFile.ts +5 -10
- package/src/fileRepository/api/uploadImage.ts +5 -8
- package/src/fileRepository/api/uploadVideo.ts +7 -9
- 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,8 +6,6 @@ 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';
|
|
12
10
|
import Hls from 'hls.js';
|
|
13
11
|
|
|
@@ -90,8 +88,8 @@ const PostContentType = Object.freeze({
|
|
|
90
88
|
|
|
91
89
|
function getVersion() {
|
|
92
90
|
try {
|
|
93
|
-
// the string ''v6.
|
|
94
|
-
return 'v6.
|
|
91
|
+
// the string ''v6.30.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
92
|
+
return 'v6.30.0-esm';
|
|
95
93
|
}
|
|
96
94
|
catch (error) {
|
|
97
95
|
return '__dev__';
|
|
@@ -528,6 +526,8 @@ const idResolvers = {
|
|
|
528
526
|
storyTarget: ({ targetId }) => targetId,
|
|
529
527
|
ad: ({ adId }) => adId,
|
|
530
528
|
advertiser: ({ advertiserId }) => advertiserId,
|
|
529
|
+
pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
|
|
530
|
+
pinTarget: ({ targetId }) => targetId,
|
|
531
531
|
};
|
|
532
532
|
/**
|
|
533
533
|
* Retrieve the id resolver matching a domain name
|
|
@@ -577,6 +577,8 @@ const PAYLOAD2MODEL = {
|
|
|
577
577
|
feeds: 'feed',
|
|
578
578
|
ads: 'ad',
|
|
579
579
|
advertisers: 'advertiser',
|
|
580
|
+
pinTargets: 'pinTarget',
|
|
581
|
+
pins: 'pin',
|
|
580
582
|
};
|
|
581
583
|
/** hidden */
|
|
582
584
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -652,18 +654,6 @@ class ASCConnectionError extends ASCError {
|
|
|
652
654
|
: 800210 /* Amity.ClientError.CONNECTION_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
653
655
|
this.event = event;
|
|
654
656
|
}
|
|
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
657
|
}
|
|
668
658
|
|
|
669
659
|
let activeClient = null;
|
|
@@ -20830,6 +20820,31 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
|
20830
20820
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
20831
20821
|
}
|
|
20832
20822
|
|
|
20823
|
+
/**
|
|
20824
|
+
* Attach user object to membership model
|
|
20825
|
+
* - If cache is not enabled, set user to undefined ({..., user: undefined})
|
|
20826
|
+
* - If user object is not found in cache, set user to undefined
|
|
20827
|
+
* ({..., user: undefined})
|
|
20828
|
+
* - If a user is found in the cache, it attaches the user from the cache
|
|
20829
|
+
* ({..., user: { userId, displayName,... }})
|
|
20830
|
+
*
|
|
20831
|
+
* @param member The membership model object
|
|
20832
|
+
* @returns The membership model object that is already mapped to user
|
|
20833
|
+
* @hidden
|
|
20834
|
+
*/
|
|
20835
|
+
const convertRawMembershipToMembership = (member) => {
|
|
20836
|
+
return Object.assign(Object.assign({}, member), { get user() {
|
|
20837
|
+
var _a;
|
|
20838
|
+
const client = getActiveClient();
|
|
20839
|
+
if (!client.cache)
|
|
20840
|
+
return undefined;
|
|
20841
|
+
const userCache = (_a = pullFromCache(['user', 'get', member.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
20842
|
+
if (!userCache) {
|
|
20843
|
+
return undefined;
|
|
20844
|
+
}
|
|
20845
|
+
return userCache;
|
|
20846
|
+
} });
|
|
20847
|
+
};
|
|
20833
20848
|
/**
|
|
20834
20849
|
* Attach user object to membership model
|
|
20835
20850
|
* - If cache is not enabled, set user to undefined ({..., user: undefined})
|
|
@@ -21476,6 +21491,80 @@ const categoryLinkedObject = (category) => {
|
|
|
21476
21491
|
} });
|
|
21477
21492
|
};
|
|
21478
21493
|
|
|
21494
|
+
/**
|
|
21495
|
+
* ```js
|
|
21496
|
+
* import { isEqual } from '~/utils/isEqual'
|
|
21497
|
+
* const isEqual = isEqual(post1, post2)
|
|
21498
|
+
* ```
|
|
21499
|
+
*
|
|
21500
|
+
* Compares two Amity.Model
|
|
21501
|
+
*
|
|
21502
|
+
* @param x the Amity.Model to compare
|
|
21503
|
+
* @param y the Amity.Model to compare wit x
|
|
21504
|
+
* @returns a boolean based on equality
|
|
21505
|
+
*
|
|
21506
|
+
* @category utility
|
|
21507
|
+
* @private
|
|
21508
|
+
*/
|
|
21509
|
+
function isEqual(x, y) {
|
|
21510
|
+
if (x === null || x === undefined || y === null || y === undefined) {
|
|
21511
|
+
return x === y;
|
|
21512
|
+
}
|
|
21513
|
+
// after this just checking type of one would be enough
|
|
21514
|
+
if (x.constructor !== y.constructor) {
|
|
21515
|
+
return false;
|
|
21516
|
+
}
|
|
21517
|
+
// if they are functions, they should exactly refer to same one (because of closures)
|
|
21518
|
+
if (x instanceof Function) {
|
|
21519
|
+
return x === y;
|
|
21520
|
+
}
|
|
21521
|
+
// if they are regexps, they should exactly refer to same one
|
|
21522
|
+
if (x instanceof RegExp) {
|
|
21523
|
+
return x === y;
|
|
21524
|
+
}
|
|
21525
|
+
if (x === y || x.valueOf() === y.valueOf()) {
|
|
21526
|
+
return true;
|
|
21527
|
+
}
|
|
21528
|
+
if (Array.isArray(x) && x.length !== y.length) {
|
|
21529
|
+
return false;
|
|
21530
|
+
}
|
|
21531
|
+
// check each element of the array for equality
|
|
21532
|
+
if (Array.isArray(x) && Array.isArray(y)) {
|
|
21533
|
+
if (x.length !== y.length)
|
|
21534
|
+
return false;
|
|
21535
|
+
for (let i = 0; i < x.length; i += 1) {
|
|
21536
|
+
if (!isEqual(x[i], y[i]))
|
|
21537
|
+
return false;
|
|
21538
|
+
}
|
|
21539
|
+
// if all elements are equal, the arrays are equal
|
|
21540
|
+
return true;
|
|
21541
|
+
}
|
|
21542
|
+
// if they are dates, they must had equal valueOf
|
|
21543
|
+
if (x instanceof Date) {
|
|
21544
|
+
return false;
|
|
21545
|
+
}
|
|
21546
|
+
// if they are strictly equal, they both need to be object at least
|
|
21547
|
+
if (!(x instanceof Object)) {
|
|
21548
|
+
return false;
|
|
21549
|
+
}
|
|
21550
|
+
if (!(y instanceof Object)) {
|
|
21551
|
+
return false;
|
|
21552
|
+
}
|
|
21553
|
+
// recursive object equality check
|
|
21554
|
+
const p = Object.keys(x);
|
|
21555
|
+
return (Object.keys(y).every(i => {
|
|
21556
|
+
// @ts-ignore
|
|
21557
|
+
return p.indexOf(i) !== -1;
|
|
21558
|
+
}) &&
|
|
21559
|
+
p.every(i => {
|
|
21560
|
+
return isEqual(x[i], y[i]);
|
|
21561
|
+
}));
|
|
21562
|
+
}
|
|
21563
|
+
|
|
21564
|
+
function isNonNullable(value) {
|
|
21565
|
+
return value != null;
|
|
21566
|
+
}
|
|
21567
|
+
|
|
21479
21568
|
const commentLinkedObject = (comment) => {
|
|
21480
21569
|
return Object.assign(Object.assign({}, comment), { get target() {
|
|
21481
21570
|
const commentTypes = {
|
|
@@ -21506,7 +21595,7 @@ const commentLinkedObject = (comment) => {
|
|
|
21506
21595
|
return undefined;
|
|
21507
21596
|
},
|
|
21508
21597
|
get childrenComment() {
|
|
21509
|
-
return
|
|
21598
|
+
return comment.children
|
|
21510
21599
|
.map(childCommentId => {
|
|
21511
21600
|
const commentCache = pullFromCache([
|
|
21512
21601
|
'comment',
|
|
@@ -21517,10 +21606,8 @@ const commentLinkedObject = (comment) => {
|
|
|
21517
21606
|
return;
|
|
21518
21607
|
return commentCache === null || commentCache === void 0 ? void 0 : commentCache.data;
|
|
21519
21608
|
})
|
|
21520
|
-
.filter(
|
|
21521
|
-
|
|
21522
|
-
// TS always alert returned value is possibly undefined
|
|
21523
|
-
.map(item => commentLinkedObject(item)));
|
|
21609
|
+
.filter(isNonNullable)
|
|
21610
|
+
.map(item => commentLinkedObject(item));
|
|
21524
21611
|
} });
|
|
21525
21612
|
};
|
|
21526
21613
|
|
|
@@ -21943,6 +22030,31 @@ const adLinkedObject = (ad) => {
|
|
|
21943
22030
|
} });
|
|
21944
22031
|
};
|
|
21945
22032
|
|
|
22033
|
+
const pinnedPostLinkedObject = (pinnedPost) => {
|
|
22034
|
+
var _a;
|
|
22035
|
+
const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
|
|
22036
|
+
const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
|
|
22037
|
+
var _a;
|
|
22038
|
+
return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
|
|
22039
|
+
})) === null || _a === void 0 ? void 0 : _a.data;
|
|
22040
|
+
return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
|
|
22041
|
+
get post() {
|
|
22042
|
+
if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
|
|
22043
|
+
return;
|
|
22044
|
+
return postLinkedObject(postCached.data);
|
|
22045
|
+
},
|
|
22046
|
+
get target() {
|
|
22047
|
+
const pinTarget = pullFromCache([
|
|
22048
|
+
'pinTarget',
|
|
22049
|
+
'get',
|
|
22050
|
+
postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
|
|
22051
|
+
]);
|
|
22052
|
+
if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
|
|
22053
|
+
return;
|
|
22054
|
+
return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
|
|
22055
|
+
} });
|
|
22056
|
+
};
|
|
22057
|
+
|
|
21946
22058
|
const LinkedObject = {
|
|
21947
22059
|
ad: adLinkedObject,
|
|
21948
22060
|
comment: commentLinkedObject,
|
|
@@ -21955,6 +22067,7 @@ const LinkedObject = {
|
|
|
21955
22067
|
message: messageLinkedObject,
|
|
21956
22068
|
reactor: reactorLinkedObject,
|
|
21957
22069
|
channel: channelLinkedObject,
|
|
22070
|
+
pinnedPost: pinnedPostLinkedObject,
|
|
21958
22071
|
};
|
|
21959
22072
|
|
|
21960
22073
|
const getChannelMessagePreviewWithUser = (channel) => {
|
|
@@ -22323,6 +22436,10 @@ const getChannelIsMentioned = (channel, marker) => {
|
|
|
22323
22436
|
: (_d = (_c = getCachedMarker(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
|
|
22324
22437
|
};
|
|
22325
22438
|
|
|
22439
|
+
function convertRawUserToInternalUser(rawUser) {
|
|
22440
|
+
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
22441
|
+
}
|
|
22442
|
+
|
|
22326
22443
|
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
22327
22444
|
const isUnreadCountSupport$2 = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
22328
22445
|
function convertFromRaw$2(channel, options = { isMessagePreviewUpdated: true }) {
|
|
@@ -22380,9 +22497,13 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
|
|
|
22380
22497
|
// attach marker to channel
|
|
22381
22498
|
const channels = rawPayload.channels.map(payload => convertFromRaw$2(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
22382
22499
|
// user marker to channel users
|
|
22383
|
-
const channelUsers =
|
|
22500
|
+
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
22501
|
+
return convertRawMembershipToMembership(channelUser);
|
|
22502
|
+
});
|
|
22503
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
22384
22504
|
const restRawPayload = __rest(rawPayload, ["messageFeedsInfo", "messagePreviews"]);
|
|
22385
|
-
return Object.assign(Object.assign({}, restRawPayload), {
|
|
22505
|
+
return Object.assign(Object.assign({}, restRawPayload), { users,
|
|
22506
|
+
channels,
|
|
22386
22507
|
channelUsers });
|
|
22387
22508
|
};
|
|
22388
22509
|
|
|
@@ -23819,9 +23940,17 @@ const onChannelMemberBanned = (callback) => {
|
|
|
23819
23940
|
return createEventSubscriber(client, 'onChannelMemberBanned', 'channel.banned', filter);
|
|
23820
23941
|
};
|
|
23821
23942
|
|
|
23943
|
+
function prepareUserPayload(response) {
|
|
23944
|
+
return {
|
|
23945
|
+
users: response.users.map(convertRawUserToInternalUser),
|
|
23946
|
+
files: response.files,
|
|
23947
|
+
};
|
|
23948
|
+
}
|
|
23949
|
+
|
|
23822
23950
|
const createUserEventSubscriber = (event, callback) => {
|
|
23823
23951
|
const client = getActiveClient();
|
|
23824
|
-
const filter = (
|
|
23952
|
+
const filter = (data) => {
|
|
23953
|
+
const payload = prepareUserPayload(data);
|
|
23825
23954
|
if (client.cache) {
|
|
23826
23955
|
ingestInCache(payload);
|
|
23827
23956
|
}
|
|
@@ -23845,7 +23974,7 @@ const createUserEventSubscriber = (event, callback) => {
|
|
|
23845
23974
|
*
|
|
23846
23975
|
* @category User Events
|
|
23847
23976
|
*/
|
|
23848
|
-
const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
23977
|
+
const onUserDeleted$2 = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
23849
23978
|
|
|
23850
23979
|
var analyticsEngineOnLoginHandler = () => {
|
|
23851
23980
|
const analyticsEngine = AnalyticsEngine$1.getInstance();
|
|
@@ -25122,7 +25251,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
25122
25251
|
terminateClient();
|
|
25123
25252
|
subscriptions.forEach(fn => fn());
|
|
25124
25253
|
unsubWatcher();
|
|
25125
|
-
}), onUserDeleted((user) => {
|
|
25254
|
+
}), onUserDeleted$2((user) => {
|
|
25126
25255
|
if (user.userId === client.userId) {
|
|
25127
25256
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
25128
25257
|
subscriptions.forEach(fn => fn());
|
|
@@ -25404,43 +25533,6 @@ const isConnected = () => {
|
|
|
25404
25533
|
client.ws.connected);
|
|
25405
25534
|
};
|
|
25406
25535
|
|
|
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
25536
|
var _GlobalFileAccessType_fileAccessType;
|
|
25445
25537
|
class GlobalFileAccessType {
|
|
25446
25538
|
constructor() {
|
|
@@ -25711,76 +25803,6 @@ const removeFunctionProperties = (obj) => {
|
|
|
25711
25803
|
return Object.fromEntries(entries);
|
|
25712
25804
|
};
|
|
25713
25805
|
|
|
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
25806
|
/**
|
|
25785
25807
|
* @deprecated This function is deprecated
|
|
25786
25808
|
*/
|
|
@@ -25998,8 +26020,6 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
25998
26020
|
renewal: renewal,
|
|
25999
26021
|
markerSync: markerSync,
|
|
26000
26022
|
enableUnreadCount: enableUnreadCount,
|
|
26001
|
-
registerPushNotification: registerPushNotification,
|
|
26002
|
-
unregisterPushNotification: unregisterPushNotification,
|
|
26003
26023
|
setUploadedFileAccessType: setUploadedFileAccessType,
|
|
26004
26024
|
onConnectionError: onConnectionError,
|
|
26005
26025
|
onClientDisconnected: onClientDisconnected,
|
|
@@ -26019,6 +26039,19 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
26019
26039
|
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
|
|
26020
26040
|
});
|
|
26021
26041
|
|
|
26042
|
+
function prepareFollowersPayload(response) {
|
|
26043
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
26044
|
+
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
26045
|
+
}
|
|
26046
|
+
function prepareFollowingsPayload(response) {
|
|
26047
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
26048
|
+
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
26049
|
+
}
|
|
26050
|
+
function prepareFollowStatusPayload(response) {
|
|
26051
|
+
const { follows } = response, rest = __rest(response, ["follows"]);
|
|
26052
|
+
return Object.assign(Object.assign({}, rest), { follows });
|
|
26053
|
+
}
|
|
26054
|
+
|
|
26022
26055
|
/* begin_public_function
|
|
26023
26056
|
id: user.relationship.block
|
|
26024
26057
|
*/
|
|
@@ -26047,7 +26080,8 @@ const blockUser = async (userId) => {
|
|
|
26047
26080
|
ingestInCache(followStatus, { cachedAt });
|
|
26048
26081
|
upsertInCache(['followInfo', 'get', userId], followCounts[0], { cachedAt });
|
|
26049
26082
|
}
|
|
26050
|
-
|
|
26083
|
+
const payload = prepareFollowStatusPayload(followStatus);
|
|
26084
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
26051
26085
|
return data;
|
|
26052
26086
|
};
|
|
26053
26087
|
/* end_public_function */
|
|
@@ -26080,171 +26114,397 @@ const unBlockUser = async (userId) => {
|
|
|
26080
26114
|
ingestInCache(followStatus, { cachedAt });
|
|
26081
26115
|
upsertInCache(['followInfo', 'get', userId], followCounts[0], { cachedAt });
|
|
26082
26116
|
}
|
|
26083
|
-
|
|
26117
|
+
const payload = prepareFollowStatusPayload(followStatus);
|
|
26118
|
+
fireEvent('local.follow.created', payload);
|
|
26084
26119
|
return data;
|
|
26085
26120
|
};
|
|
26086
26121
|
/* end_public_function */
|
|
26087
26122
|
|
|
26123
|
+
class PaginationController {
|
|
26124
|
+
constructor(queryParams) {
|
|
26125
|
+
const { http } = getActiveClient();
|
|
26126
|
+
this.queryParams = queryParams;
|
|
26127
|
+
this.http = http;
|
|
26128
|
+
}
|
|
26129
|
+
loadFirstPage() {
|
|
26130
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
26131
|
+
}
|
|
26132
|
+
loadNextPage() {
|
|
26133
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
26134
|
+
}
|
|
26135
|
+
loadPreviousPage() {
|
|
26136
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
26137
|
+
}
|
|
26138
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
26139
|
+
var _a, _b, _c, _d;
|
|
26140
|
+
if (direction === 'prev' && !this.previousToken)
|
|
26141
|
+
return;
|
|
26142
|
+
if (direction === 'next' && !this.nextToken)
|
|
26143
|
+
return;
|
|
26144
|
+
let token;
|
|
26145
|
+
if (direction === 'prev')
|
|
26146
|
+
token = this.previousToken;
|
|
26147
|
+
if (direction === 'next')
|
|
26148
|
+
token = this.nextToken;
|
|
26149
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
26150
|
+
if (direction === 'first') {
|
|
26151
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
26152
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
26153
|
+
}
|
|
26154
|
+
if (direction === 'prev')
|
|
26155
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
26156
|
+
if (direction === 'next')
|
|
26157
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
26158
|
+
return queryResponse;
|
|
26159
|
+
}
|
|
26160
|
+
getNextToken() {
|
|
26161
|
+
return this.nextToken;
|
|
26162
|
+
}
|
|
26163
|
+
getPrevToken() {
|
|
26164
|
+
return this.previousToken;
|
|
26165
|
+
}
|
|
26166
|
+
}
|
|
26167
|
+
|
|
26168
|
+
class BlockedUserPaginationController extends PaginationController {
|
|
26169
|
+
async getRequest(queryParams, token) {
|
|
26170
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
26171
|
+
const options = token ? { token } : { limit };
|
|
26172
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
26173
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
26174
|
+
});
|
|
26175
|
+
return queryResponse;
|
|
26176
|
+
}
|
|
26177
|
+
}
|
|
26178
|
+
|
|
26179
|
+
class QueryStreamController {
|
|
26180
|
+
constructor(query, cacheKey) {
|
|
26181
|
+
this.query = query;
|
|
26182
|
+
this.cacheKey = cacheKey;
|
|
26183
|
+
}
|
|
26184
|
+
}
|
|
26185
|
+
|
|
26186
|
+
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
26187
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
26188
|
+
super(query, cacheKey);
|
|
26189
|
+
this.notifyChange = notifyChange;
|
|
26190
|
+
this.preparePayload = preparePayload;
|
|
26191
|
+
}
|
|
26192
|
+
async saveToMainDB(response) {
|
|
26193
|
+
const processedPayload = await this.preparePayload(response);
|
|
26194
|
+
const client = getActiveClient();
|
|
26195
|
+
const cachedAt = client.cache && Date.now();
|
|
26196
|
+
if (client.cache) {
|
|
26197
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
26198
|
+
}
|
|
26199
|
+
}
|
|
26200
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
26201
|
+
var _a, _b;
|
|
26202
|
+
if (refresh) {
|
|
26203
|
+
pushToCache(this.cacheKey, {
|
|
26204
|
+
data: response.users.map(getResolver('user')),
|
|
26205
|
+
});
|
|
26206
|
+
}
|
|
26207
|
+
else {
|
|
26208
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26209
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26210
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
26211
|
+
}
|
|
26212
|
+
}
|
|
26213
|
+
reactor(action) {
|
|
26214
|
+
return (followStatus) => {
|
|
26215
|
+
var _a;
|
|
26216
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26217
|
+
pushToCache(this.cacheKey, collection);
|
|
26218
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
26219
|
+
};
|
|
26220
|
+
}
|
|
26221
|
+
subscribeRTE(createSubscriber) {
|
|
26222
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
26223
|
+
}
|
|
26224
|
+
}
|
|
26225
|
+
|
|
26226
|
+
class PaginationNoPageController {
|
|
26227
|
+
constructor(queryParams) {
|
|
26228
|
+
const { http } = getActiveClient();
|
|
26229
|
+
this.queryParams = queryParams;
|
|
26230
|
+
this.http = http;
|
|
26231
|
+
}
|
|
26232
|
+
async onFetch() {
|
|
26233
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
26234
|
+
return queryResponse;
|
|
26235
|
+
}
|
|
26236
|
+
}
|
|
26237
|
+
|
|
26238
|
+
class LiveCollectionController {
|
|
26239
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
26240
|
+
this.paginationController = paginationController;
|
|
26241
|
+
this.queryStreamId = queryStreamId;
|
|
26242
|
+
this.cacheKey = cacheKey;
|
|
26243
|
+
this.callback = callback;
|
|
26244
|
+
}
|
|
26245
|
+
async refresh() {
|
|
26246
|
+
try {
|
|
26247
|
+
let result;
|
|
26248
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
26249
|
+
result = await this.paginationController.onFetch();
|
|
26250
|
+
}
|
|
26251
|
+
else {
|
|
26252
|
+
result = await this.paginationController.loadFirstPage();
|
|
26253
|
+
}
|
|
26254
|
+
if (!result)
|
|
26255
|
+
return;
|
|
26256
|
+
await this.persistModel(result);
|
|
26257
|
+
this.persistQueryStream({
|
|
26258
|
+
response: result,
|
|
26259
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26260
|
+
refresh: true,
|
|
26261
|
+
});
|
|
26262
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26263
|
+
}
|
|
26264
|
+
catch (e) {
|
|
26265
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26266
|
+
}
|
|
26267
|
+
}
|
|
26268
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
26269
|
+
this.setup();
|
|
26270
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
26271
|
+
if (initial) {
|
|
26272
|
+
this.refresh();
|
|
26273
|
+
}
|
|
26274
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
26275
|
+
this.loadPrevPage();
|
|
26276
|
+
}
|
|
26277
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
26278
|
+
this.loadNextPage();
|
|
26279
|
+
}
|
|
26280
|
+
}
|
|
26281
|
+
async loadNextPage() {
|
|
26282
|
+
try {
|
|
26283
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
26284
|
+
return;
|
|
26285
|
+
const result = await this.paginationController.loadNextPage();
|
|
26286
|
+
if (!result)
|
|
26287
|
+
return;
|
|
26288
|
+
await this.persistModel(result);
|
|
26289
|
+
this.persistQueryStream({
|
|
26290
|
+
response: result,
|
|
26291
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26292
|
+
});
|
|
26293
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26294
|
+
}
|
|
26295
|
+
catch (e) {
|
|
26296
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26297
|
+
}
|
|
26298
|
+
}
|
|
26299
|
+
async loadPrevPage() {
|
|
26300
|
+
try {
|
|
26301
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
26302
|
+
return;
|
|
26303
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
26304
|
+
if (!result)
|
|
26305
|
+
return;
|
|
26306
|
+
await this.persistModel(result);
|
|
26307
|
+
this.persistQueryStream({
|
|
26308
|
+
response: result,
|
|
26309
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
26310
|
+
});
|
|
26311
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26312
|
+
}
|
|
26313
|
+
catch (e) {
|
|
26314
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26315
|
+
}
|
|
26316
|
+
}
|
|
26317
|
+
shouldNotify(data) {
|
|
26318
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
26319
|
+
if (isEqual(this.snapshot, newData))
|
|
26320
|
+
return false;
|
|
26321
|
+
this.snapshot = newData;
|
|
26322
|
+
return true;
|
|
26323
|
+
}
|
|
26324
|
+
getCacheKey() {
|
|
26325
|
+
return this.cacheKey;
|
|
26326
|
+
}
|
|
26327
|
+
}
|
|
26328
|
+
|
|
26329
|
+
function prepareBlockedUserPayload(response) {
|
|
26330
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
26331
|
+
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
26332
|
+
const followUser = users.find(user => user.userId === follow.from);
|
|
26333
|
+
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
26334
|
+
}), users: users.map(convertRawUserToInternalUser) });
|
|
26335
|
+
}
|
|
26336
|
+
|
|
26088
26337
|
/**
|
|
26089
26338
|
* ```js
|
|
26090
|
-
* import {
|
|
26091
|
-
* const
|
|
26339
|
+
* import { onUserUpdated } from '@amityco/ts-sdk-react-native'
|
|
26340
|
+
* const dispose = onUserUpdated(user => {
|
|
26341
|
+
* // ...
|
|
26342
|
+
* })
|
|
26092
26343
|
* ```
|
|
26093
26344
|
*
|
|
26094
|
-
* @
|
|
26095
|
-
* @returns A page of {@link Amity.User} objects
|
|
26345
|
+
* Fired when a {@link Amity.InternalUser} has been updated
|
|
26096
26346
|
*
|
|
26097
|
-
* @
|
|
26098
|
-
* @
|
|
26347
|
+
* @param callback The function to call when the event was fired
|
|
26348
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26349
|
+
*
|
|
26350
|
+
* @category User Events
|
|
26099
26351
|
*/
|
|
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
|
-
};
|
|
26352
|
+
const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
|
|
26353
|
+
|
|
26127
26354
|
/**
|
|
26128
26355
|
* ```js
|
|
26129
|
-
* import {
|
|
26130
|
-
* const
|
|
26356
|
+
* import { onUserFlagged } from '@amityco/ts-sdk-react-native'
|
|
26357
|
+
* const dispose = onUserFlagged(user => {
|
|
26358
|
+
* // ...
|
|
26359
|
+
* })
|
|
26131
26360
|
* ```
|
|
26132
26361
|
*
|
|
26133
|
-
*
|
|
26134
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
26362
|
+
* Fired when a {@link Amity.InternalUser} has been flagged
|
|
26135
26363
|
*
|
|
26136
|
-
* @param
|
|
26137
|
-
* @returns
|
|
26364
|
+
* @param callback The function to call when the event was fired
|
|
26365
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26138
26366
|
*
|
|
26139
|
-
* @category
|
|
26367
|
+
* @category User Events
|
|
26140
26368
|
*/
|
|
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
|
-
};
|
|
26369
|
+
const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
|
|
26164
26370
|
|
|
26165
|
-
/* eslint-disable no-use-before-define */
|
|
26166
|
-
/* begin_public_function
|
|
26167
|
-
id: user.get_blocked_users
|
|
26168
|
-
*/
|
|
26169
26371
|
/**
|
|
26170
26372
|
* ```js
|
|
26171
|
-
* import {
|
|
26172
|
-
* const
|
|
26373
|
+
* import { onUserUnflagged } from '@amityco/ts-sdk-react-native'
|
|
26374
|
+
* const dispose = onUserUnflagged(user => {
|
|
26375
|
+
* // ...
|
|
26376
|
+
* })
|
|
26173
26377
|
* ```
|
|
26174
26378
|
*
|
|
26175
|
-
*
|
|
26379
|
+
* Fired when a flag has been removed from a {@link Amity.InternalUser}
|
|
26176
26380
|
*
|
|
26177
|
-
* @param
|
|
26178
|
-
* @
|
|
26179
|
-
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
26381
|
+
* @param callback The function to call when the event was fired
|
|
26382
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26180
26383
|
*
|
|
26181
|
-
* @category
|
|
26182
|
-
* @async
|
|
26384
|
+
* @category User Events
|
|
26183
26385
|
*/
|
|
26184
|
-
const
|
|
26185
|
-
|
|
26186
|
-
|
|
26187
|
-
|
|
26386
|
+
const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
|
|
26387
|
+
|
|
26388
|
+
/**
|
|
26389
|
+
* ```js
|
|
26390
|
+
* import { onUserFlagCleared } from '@amityco/ts-sdk-react-native'
|
|
26391
|
+
* const dispose = onUserFlagCleared(user => {
|
|
26392
|
+
* // ...
|
|
26393
|
+
* })
|
|
26394
|
+
* ```
|
|
26395
|
+
*
|
|
26396
|
+
* Fired when flags have been cleared for a {@link Amity.InternalUser}
|
|
26397
|
+
*
|
|
26398
|
+
* @param callback The function to call when the event was fired
|
|
26399
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26400
|
+
*
|
|
26401
|
+
* @category User Events
|
|
26402
|
+
*/
|
|
26403
|
+
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
26404
|
+
|
|
26405
|
+
var EnumUserActions;
|
|
26406
|
+
(function (EnumUserActions) {
|
|
26407
|
+
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
26408
|
+
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
26409
|
+
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
26410
|
+
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
26411
|
+
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
26412
|
+
})(EnumUserActions || (EnumUserActions = {}));
|
|
26413
|
+
|
|
26414
|
+
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
26415
|
+
constructor(query, callback) {
|
|
26416
|
+
const queryStreamId = hash(query);
|
|
26417
|
+
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
26418
|
+
const paginationController = new BlockedUserPaginationController(query);
|
|
26419
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
26420
|
+
this.query = query;
|
|
26421
|
+
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
26422
|
+
this.callback = callback.bind(this);
|
|
26423
|
+
this.loadPage({ initial: true });
|
|
26188
26424
|
}
|
|
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) => {
|
|
26425
|
+
setup() {
|
|
26426
|
+
var _a;
|
|
26427
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26428
|
+
if (!collection) {
|
|
26429
|
+
pushToCache(this.cacheKey, {
|
|
26430
|
+
data: [],
|
|
26431
|
+
params: {},
|
|
26432
|
+
});
|
|
26433
|
+
}
|
|
26434
|
+
}
|
|
26435
|
+
async persistModel(queryPayload) {
|
|
26436
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
26437
|
+
}
|
|
26438
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
26439
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
26440
|
+
}
|
|
26441
|
+
startSubscription() {
|
|
26442
|
+
return this.queryStreamController.subscribeRTE([
|
|
26443
|
+
{
|
|
26444
|
+
fn: onUserDeleted$2,
|
|
26445
|
+
action: EnumUserActions.OnUserDeleted,
|
|
26446
|
+
},
|
|
26447
|
+
]);
|
|
26448
|
+
}
|
|
26449
|
+
notifyChange({ origin, loading, error }) {
|
|
26217
26450
|
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))
|
|
26451
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26452
|
+
if (!collection)
|
|
26221
26453
|
return;
|
|
26222
|
-
const
|
|
26223
|
-
|
|
26224
|
-
|
|
26454
|
+
const data = this.applyFilter((_b = collection.data
|
|
26455
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
26456
|
+
.filter(isNonNullable)
|
|
26457
|
+
.map(({ data }) => data)
|
|
26458
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
26459
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
26460
|
+
return;
|
|
26461
|
+
this.callback({
|
|
26462
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
26463
|
+
data,
|
|
26464
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
26465
|
+
loading,
|
|
26466
|
+
error,
|
|
26225
26467
|
});
|
|
26226
|
-
|
|
26227
|
-
|
|
26228
|
-
|
|
26229
|
-
|
|
26230
|
-
|
|
26231
|
-
|
|
26232
|
-
|
|
26233
|
-
|
|
26234
|
-
|
|
26235
|
-
|
|
26236
|
-
|
|
26237
|
-
|
|
26238
|
-
|
|
26239
|
-
|
|
26240
|
-
|
|
26241
|
-
|
|
26242
|
-
|
|
26243
|
-
|
|
26244
|
-
|
|
26245
|
-
|
|
26468
|
+
}
|
|
26469
|
+
// eslint-disable-next-line class-methods-use-this
|
|
26470
|
+
applyFilter(data) {
|
|
26471
|
+
let users = data;
|
|
26472
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
26473
|
+
return users;
|
|
26474
|
+
}
|
|
26475
|
+
}
|
|
26476
|
+
|
|
26477
|
+
/* begin_public_function
|
|
26478
|
+
id: user.get_blocked_users
|
|
26479
|
+
*/
|
|
26480
|
+
/**
|
|
26481
|
+
* ```js
|
|
26482
|
+
* import { UserRepository } from '@amityco/ts-sdk-react-native'
|
|
26483
|
+
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
26484
|
+
* ```
|
|
26485
|
+
*
|
|
26486
|
+
* Blocks a {@link Amity.InternalUser}
|
|
26487
|
+
*
|
|
26488
|
+
* @param params The params to get blocked {@link Amity.InternalUser}s
|
|
26489
|
+
* @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
|
|
26490
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
26491
|
+
*
|
|
26492
|
+
* @category Post API
|
|
26493
|
+
* @async
|
|
26494
|
+
*/
|
|
26495
|
+
const getBlockedUsers$1 = (params, callback, config) => {
|
|
26496
|
+
const { log, cache } = getActiveClient();
|
|
26497
|
+
if (!cache) {
|
|
26498
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
26499
|
+
}
|
|
26500
|
+
const timestamp = Date.now();
|
|
26501
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
26502
|
+
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
26503
|
+
const disposers = blockedUserLiveCollection.startSubscription();
|
|
26504
|
+
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
26505
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
26246
26506
|
return () => {
|
|
26247
|
-
log(`
|
|
26507
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
26248
26508
|
disposers.forEach(fn => fn());
|
|
26249
26509
|
dropFromCache(cacheKey);
|
|
26250
26510
|
};
|
|
@@ -26254,7 +26514,7 @@ const getBlockedUsers$1 = (params, callback, config) => {
|
|
|
26254
26514
|
/* eslint-disable no-use-before-define */
|
|
26255
26515
|
const getBlockedUsers = (params, callback, config) => {
|
|
26256
26516
|
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
|
|
26517
|
+
return getBlockedUsers$1(params, callback);
|
|
26258
26518
|
};
|
|
26259
26519
|
|
|
26260
26520
|
/* begin_public_function
|
|
@@ -26282,7 +26542,13 @@ const follow = async (userId) => {
|
|
|
26282
26542
|
if (client.cache) {
|
|
26283
26543
|
ingestInCache(data, { cachedAt });
|
|
26284
26544
|
}
|
|
26285
|
-
|
|
26545
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26546
|
+
if (data.follows[0].status === 'accepted') {
|
|
26547
|
+
fireEvent('local.follow.created', payload);
|
|
26548
|
+
}
|
|
26549
|
+
else {
|
|
26550
|
+
fireEvent('local.follow.requested', payload);
|
|
26551
|
+
}
|
|
26286
26552
|
return {
|
|
26287
26553
|
data: data.follows[0],
|
|
26288
26554
|
cachedAt,
|
|
@@ -26314,7 +26580,8 @@ const unfollow = async (userId) => {
|
|
|
26314
26580
|
if (client.cache) {
|
|
26315
26581
|
ingestInCache(data);
|
|
26316
26582
|
}
|
|
26317
|
-
|
|
26583
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26584
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
26318
26585
|
return true;
|
|
26319
26586
|
};
|
|
26320
26587
|
/* end_public_function */
|
|
@@ -26343,7 +26610,8 @@ const acceptFollower = async (userId) => {
|
|
|
26343
26610
|
if (client.cache) {
|
|
26344
26611
|
ingestInCache(data);
|
|
26345
26612
|
}
|
|
26346
|
-
|
|
26613
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26614
|
+
fireEvent('local.follow.accepted', payload);
|
|
26347
26615
|
return true;
|
|
26348
26616
|
};
|
|
26349
26617
|
|
|
@@ -26371,7 +26639,8 @@ const acceptMyFollower = async (userId) => {
|
|
|
26371
26639
|
if (client.cache) {
|
|
26372
26640
|
ingestInCache(data);
|
|
26373
26641
|
}
|
|
26374
|
-
|
|
26642
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26643
|
+
fireEvent('local.follow.accepted', payload);
|
|
26375
26644
|
return true;
|
|
26376
26645
|
};
|
|
26377
26646
|
/* end_public_function */
|
|
@@ -26400,7 +26669,8 @@ const declineFollower = async (userId) => {
|
|
|
26400
26669
|
if (client.cache) {
|
|
26401
26670
|
ingestInCache(data);
|
|
26402
26671
|
}
|
|
26403
|
-
|
|
26672
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26673
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
26404
26674
|
return true;
|
|
26405
26675
|
};
|
|
26406
26676
|
|
|
@@ -26428,29 +26698,35 @@ const declineMyFollower = async (userId) => {
|
|
|
26428
26698
|
if (client.cache) {
|
|
26429
26699
|
ingestInCache(data);
|
|
26430
26700
|
}
|
|
26431
|
-
|
|
26701
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26702
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
26432
26703
|
return true;
|
|
26433
26704
|
};
|
|
26434
26705
|
/* end_public_function */
|
|
26435
26706
|
|
|
26436
26707
|
const createFollowEventSubscriber = (event, callback) => {
|
|
26437
26708
|
const client = getActiveClient();
|
|
26438
|
-
const filter = (
|
|
26439
|
-
|
|
26709
|
+
const filter = (data) => {
|
|
26710
|
+
const payload = prepareFollowersPayload(data);
|
|
26711
|
+
if (!client.cache) {
|
|
26712
|
+
callback(payload.follows[0]);
|
|
26713
|
+
}
|
|
26714
|
+
else {
|
|
26715
|
+
ingestInCache(payload);
|
|
26716
|
+
callback(payload.follows[0]);
|
|
26717
|
+
}
|
|
26718
|
+
};
|
|
26719
|
+
return createEventSubscriber(client, event, event, filter);
|
|
26720
|
+
};
|
|
26721
|
+
const createLocalFollowEventSubscriber = (event, callback) => {
|
|
26722
|
+
const client = getActiveClient();
|
|
26723
|
+
const filter = (data) => {
|
|
26724
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26440
26725
|
if (!client.cache) {
|
|
26441
26726
|
callback(payload.follows[0]);
|
|
26442
26727
|
}
|
|
26443
26728
|
else {
|
|
26444
26729
|
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
26730
|
callback(payload.follows[0]);
|
|
26455
26731
|
}
|
|
26456
26732
|
};
|
|
@@ -26669,12 +26945,27 @@ const onFollowInfoUpdated = (callback) => {
|
|
|
26669
26945
|
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
26670
26946
|
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
26671
26947
|
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
26948
|
+
createLocalFollowEventSubscriber('local.follow.created', handler),
|
|
26949
|
+
createLocalFollowEventSubscriber('local.follow.requested', handler),
|
|
26950
|
+
createLocalFollowEventSubscriber('local.follow.accepted', handler),
|
|
26951
|
+
createLocalFollowEventSubscriber('local.follow.unfollowed', handler),
|
|
26952
|
+
createLocalFollowEventSubscriber('local.follow.requestDeclined', handler),
|
|
26672
26953
|
];
|
|
26673
26954
|
return () => {
|
|
26674
26955
|
disposers.forEach(fn => fn());
|
|
26675
26956
|
};
|
|
26676
26957
|
};
|
|
26677
26958
|
|
|
26959
|
+
const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
|
|
26960
|
+
|
|
26961
|
+
const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
|
|
26962
|
+
|
|
26963
|
+
const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
|
|
26964
|
+
|
|
26965
|
+
const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
|
|
26966
|
+
|
|
26967
|
+
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
26968
|
+
|
|
26678
26969
|
/**
|
|
26679
26970
|
* ```js
|
|
26680
26971
|
* import { observeFollowInfo } from '@amityco/ts-sdk-react-native'
|
|
@@ -26747,7 +27038,7 @@ const observeFollowers = (userId, callback) => {
|
|
|
26747
27038
|
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
26748
27039
|
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
26749
27040
|
};
|
|
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')));
|
|
27041
|
+
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
27042
|
return () => {
|
|
26752
27043
|
log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
|
|
26753
27044
|
disposers.forEach(fn => fn());
|
|
@@ -26783,92 +27074,190 @@ const observeFollowings = (userId, callback) => {
|
|
|
26783
27074
|
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
26784
27075
|
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
26785
27076
|
};
|
|
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')));
|
|
27077
|
+
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
27078
|
return () => {
|
|
26788
27079
|
log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
|
|
26789
27080
|
disposers.forEach(fn => fn());
|
|
26790
27081
|
};
|
|
26791
27082
|
};
|
|
26792
27083
|
|
|
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 });
|
|
27084
|
+
class FollowerPaginationController extends PaginationController {
|
|
27085
|
+
async getRequest(queryParams, token) {
|
|
27086
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
27087
|
+
const options = token ? { token } : { limit };
|
|
27088
|
+
const client = getActiveClient();
|
|
27089
|
+
const path = client.userId === userId ? `/api/v4/me/followers` : `/api/v4/users/${userId}/followers`;
|
|
27090
|
+
const { data: queryResponse } = await this.http.get(path, {
|
|
27091
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
27092
|
+
});
|
|
27093
|
+
return queryResponse;
|
|
26811
27094
|
}
|
|
26812
|
-
|
|
26813
|
-
|
|
26814
|
-
|
|
26815
|
-
|
|
26816
|
-
|
|
26817
|
-
|
|
26818
|
-
|
|
26819
|
-
|
|
26820
|
-
|
|
26821
|
-
|
|
26822
|
-
|
|
26823
|
-
|
|
26824
|
-
|
|
26825
|
-
|
|
26826
|
-
|
|
26827
|
-
|
|
26828
|
-
|
|
26829
|
-
|
|
26830
|
-
|
|
27095
|
+
}
|
|
27096
|
+
|
|
27097
|
+
var EnumFollowActions;
|
|
27098
|
+
(function (EnumFollowActions) {
|
|
27099
|
+
EnumFollowActions["OnRequested"] = "onRequested";
|
|
27100
|
+
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
27101
|
+
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
27102
|
+
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
27103
|
+
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
27104
|
+
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
27105
|
+
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
27106
|
+
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
27107
|
+
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
27108
|
+
|
|
27109
|
+
class FollowerQueryStreamController extends QueryStreamController {
|
|
27110
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27111
|
+
super(query, cacheKey);
|
|
27112
|
+
this.notifyChange = notifyChange;
|
|
27113
|
+
this.preparePayload = preparePayload;
|
|
26831
27114
|
}
|
|
26832
|
-
|
|
26833
|
-
|
|
26834
|
-
|
|
26835
|
-
|
|
26836
|
-
|
|
26837
|
-
|
|
26838
|
-
|
|
26839
|
-
|
|
26840
|
-
|
|
27115
|
+
async saveToMainDB(response) {
|
|
27116
|
+
const processedPayload = await this.preparePayload(response);
|
|
27117
|
+
const client = getActiveClient();
|
|
27118
|
+
const cachedAt = client.cache && Date.now();
|
|
27119
|
+
if (client.cache) {
|
|
27120
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27121
|
+
}
|
|
27122
|
+
}
|
|
27123
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27124
|
+
var _a, _b;
|
|
27125
|
+
if (refresh) {
|
|
27126
|
+
pushToCache(this.cacheKey, {
|
|
27127
|
+
data: response.follows.map(getResolver('follow')),
|
|
27128
|
+
});
|
|
27129
|
+
}
|
|
27130
|
+
else {
|
|
27131
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27132
|
+
const follows = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27133
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...follows, ...response.follows.map(getResolver('follow'))])] }));
|
|
27134
|
+
}
|
|
27135
|
+
}
|
|
27136
|
+
reactor(action) {
|
|
27137
|
+
return (followStatus) => {
|
|
27138
|
+
var _a;
|
|
27139
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27140
|
+
if (this.query.userId !== followStatus.to || !collection)
|
|
27141
|
+
return;
|
|
27142
|
+
switch (action) {
|
|
27143
|
+
case EnumFollowActions.OnDeclined:
|
|
27144
|
+
case EnumFollowActions.OnCanceled:
|
|
27145
|
+
case EnumFollowActions.OnUnfollowed:
|
|
27146
|
+
case EnumFollowActions.OnDeleted:
|
|
27147
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
27148
|
+
break;
|
|
27149
|
+
case EnumFollowActions.OnRequested:
|
|
27150
|
+
case EnumFollowActions.OnAccepted:
|
|
27151
|
+
case EnumFollowActions.OnFollowed:
|
|
27152
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
27153
|
+
break;
|
|
27154
|
+
}
|
|
27155
|
+
pushToCache(this.cacheKey, collection);
|
|
27156
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27157
|
+
};
|
|
27158
|
+
}
|
|
27159
|
+
subscribeRTE(createSubscriber) {
|
|
27160
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27161
|
+
}
|
|
27162
|
+
}
|
|
27163
|
+
|
|
27164
|
+
const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
27165
|
+
const client = getActiveClient();
|
|
27166
|
+
const filter = (data) => {
|
|
27167
|
+
const userPayload = prepareUserPayload(data);
|
|
27168
|
+
ingestInCache(userPayload);
|
|
27169
|
+
const cacheData = pullFromCache([
|
|
27170
|
+
'follow',
|
|
27171
|
+
'get',
|
|
27172
|
+
getResolver('follow')({
|
|
27173
|
+
from: userPayload.users[0].userId,
|
|
27174
|
+
to: userId,
|
|
27175
|
+
}),
|
|
27176
|
+
]);
|
|
27177
|
+
if (!cacheData)
|
|
27178
|
+
return;
|
|
27179
|
+
callback(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data);
|
|
27180
|
+
};
|
|
27181
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
26841
27182
|
};
|
|
26842
27183
|
|
|
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
|
-
|
|
27184
|
+
class FollowerLiveCollectionController extends LiveCollectionController {
|
|
27185
|
+
constructor(query, callback) {
|
|
27186
|
+
const queryStreamId = hash(query);
|
|
27187
|
+
const cacheKey = ['follow', 'collection', queryStreamId];
|
|
27188
|
+
const paginationController = new FollowerPaginationController(query);
|
|
27189
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27190
|
+
this.query = query;
|
|
27191
|
+
this.queryStreamController = new FollowerQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareFollowersPayload);
|
|
27192
|
+
this.callback = callback.bind(this);
|
|
27193
|
+
this.loadPage({ initial: true });
|
|
27194
|
+
}
|
|
27195
|
+
setup() {
|
|
27196
|
+
var _a;
|
|
27197
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27198
|
+
if (!collection) {
|
|
27199
|
+
pushToCache(this.cacheKey, {
|
|
27200
|
+
data: [],
|
|
27201
|
+
params: {},
|
|
27202
|
+
});
|
|
27203
|
+
}
|
|
27204
|
+
}
|
|
27205
|
+
async persistModel(queryPayload) {
|
|
27206
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27207
|
+
}
|
|
27208
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27209
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27210
|
+
}
|
|
27211
|
+
startSubscription() {
|
|
27212
|
+
return this.queryStreamController.subscribeRTE([
|
|
27213
|
+
{ fn: onUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
27214
|
+
{ fn: onUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
27215
|
+
{ fn: onFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
27216
|
+
{ fn: onFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
27217
|
+
{ fn: onFollowRequestCanceled, action: EnumFollowActions.OnCanceled },
|
|
27218
|
+
{ fn: onFollowerDeleted, action: EnumFollowActions.OnDeleted },
|
|
27219
|
+
{ fn: onLocalFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
27220
|
+
{ fn: onLocalFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
27221
|
+
{ fn: onLocalUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
27222
|
+
{ fn: onLocalUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
27223
|
+
{
|
|
27224
|
+
fn: onFollowerUserDeleted({ userId: this.query.userId }),
|
|
27225
|
+
action: EnumFollowActions.OnUserDeleted,
|
|
27226
|
+
},
|
|
27227
|
+
]);
|
|
27228
|
+
}
|
|
27229
|
+
notifyChange({ origin, loading, error }) {
|
|
27230
|
+
var _a, _b;
|
|
27231
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27232
|
+
if (!collection)
|
|
27233
|
+
return;
|
|
27234
|
+
const data = this.applyFilter((_b = collection.data
|
|
27235
|
+
.map(id => pullFromCache(['follow', 'get', id]))
|
|
27236
|
+
.filter(isNonNullable)
|
|
27237
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
27238
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
27239
|
+
return;
|
|
27240
|
+
this.callback({
|
|
27241
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
27242
|
+
data,
|
|
27243
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
27244
|
+
loading,
|
|
27245
|
+
error,
|
|
27246
|
+
});
|
|
27247
|
+
}
|
|
27248
|
+
applyFilter(data) {
|
|
27249
|
+
let followers = data;
|
|
27250
|
+
if (this.query.status && this.query.status !== "all" /* Amity.FollowStatusTypeEnum.All */) {
|
|
27251
|
+
followers = followers.filter(follower => follower.status === this.query.status);
|
|
27252
|
+
}
|
|
27253
|
+
followers = followers.filter(follower => {
|
|
27254
|
+
var _a;
|
|
27255
|
+
const fromUser = (_a = pullFromCache(['user', 'get', follower.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
27256
|
+
return (fromUser === null || fromUser === void 0 ? void 0 : fromUser.isDeleted) == null || (fromUser === null || fromUser === void 0 ? void 0 : fromUser.isDeleted) === false;
|
|
27257
|
+
});
|
|
27258
|
+
return followers;
|
|
27259
|
+
}
|
|
27260
|
+
}
|
|
26872
27261
|
|
|
26873
27262
|
/* begin_public_function
|
|
26874
27263
|
id: user.relationship.query_my_followers, user.relationship.query_followers
|
|
@@ -26894,69 +27283,14 @@ queryFollowers.locally = (query) => queryFollows.locally('followers', query);
|
|
|
26894
27283
|
const getFollowers = (params, callback, config) => {
|
|
26895
27284
|
const { log, cache } = getActiveClient();
|
|
26896
27285
|
if (!cache) {
|
|
26897
|
-
console.log(
|
|
27286
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
26898
27287
|
}
|
|
26899
27288
|
const timestamp = Date.now();
|
|
26900
27289
|
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);
|
|
27290
|
+
const followerLiveCollection = new FollowerLiveCollectionController(params, callback);
|
|
27291
|
+
const disposers = followerLiveCollection.startSubscription();
|
|
27292
|
+
const cacheKey = followerLiveCollection.getCacheKey();
|
|
27293
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
26960
27294
|
return () => {
|
|
26961
27295
|
log(`getFollowers(tmpid: ${timestamp}) > dispose`);
|
|
26962
27296
|
disposers.forEach(fn => fn());
|
|
@@ -26964,35 +27298,173 @@ const getFollowers = (params, callback, config) => {
|
|
|
26964
27298
|
};
|
|
26965
27299
|
/* end_public_function */
|
|
26966
27300
|
|
|
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
|
-
|
|
27301
|
+
class FollowingPaginationController extends PaginationController {
|
|
27302
|
+
async getRequest(queryParams, token) {
|
|
27303
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
27304
|
+
const options = token ? { token } : { limit };
|
|
27305
|
+
const client = getActiveClient();
|
|
27306
|
+
const path = client.userId === userId ? `/api/v4/me/following` : `/api/v4/users/${userId}/following`;
|
|
27307
|
+
const { data: queryResponse } = await this.http.get(path, {
|
|
27308
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
27309
|
+
});
|
|
27310
|
+
return queryResponse;
|
|
27311
|
+
}
|
|
27312
|
+
}
|
|
27313
|
+
|
|
27314
|
+
class FollowingQueryStreamController extends QueryStreamController {
|
|
27315
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27316
|
+
super(query, cacheKey);
|
|
27317
|
+
this.notifyChange = notifyChange;
|
|
27318
|
+
this.preparePayload = preparePayload;
|
|
27319
|
+
}
|
|
27320
|
+
async saveToMainDB(response) {
|
|
27321
|
+
const processedPayload = await this.preparePayload(response);
|
|
27322
|
+
const client = getActiveClient();
|
|
27323
|
+
const cachedAt = client.cache && Date.now();
|
|
27324
|
+
if (client.cache) {
|
|
27325
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27326
|
+
}
|
|
27327
|
+
}
|
|
27328
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27329
|
+
var _a, _b;
|
|
27330
|
+
if (refresh) {
|
|
27331
|
+
pushToCache(this.cacheKey, {
|
|
27332
|
+
data: response.follows.map(getResolver('follow')),
|
|
27333
|
+
});
|
|
27334
|
+
}
|
|
27335
|
+
else {
|
|
27336
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27337
|
+
const follows = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27338
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...follows, ...response.follows.map(getResolver('follow'))])] }));
|
|
27339
|
+
}
|
|
27340
|
+
}
|
|
27341
|
+
reactor(action) {
|
|
27342
|
+
return (followStatus) => {
|
|
27343
|
+
var _a;
|
|
27344
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27345
|
+
if (this.query.userId !== followStatus.from || !collection)
|
|
27346
|
+
return;
|
|
27347
|
+
switch (action) {
|
|
27348
|
+
case EnumFollowActions.OnDeclined:
|
|
27349
|
+
case EnumFollowActions.OnCanceled:
|
|
27350
|
+
case EnumFollowActions.OnUnfollowed:
|
|
27351
|
+
case EnumFollowActions.OnDeleted:
|
|
27352
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
27353
|
+
break;
|
|
27354
|
+
case EnumFollowActions.OnRequested:
|
|
27355
|
+
case EnumFollowActions.OnAccepted:
|
|
27356
|
+
case EnumFollowActions.OnFollowed:
|
|
27357
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
27358
|
+
break;
|
|
27359
|
+
}
|
|
27360
|
+
pushToCache(this.cacheKey, collection);
|
|
27361
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27362
|
+
};
|
|
27363
|
+
}
|
|
27364
|
+
subscribeRTE(createSubscriber) {
|
|
27365
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27366
|
+
}
|
|
27367
|
+
}
|
|
27368
|
+
|
|
27369
|
+
const onFollowingUserDeleted = ({ userId }) => (callback) => {
|
|
27370
|
+
const client = getActiveClient();
|
|
27371
|
+
const filter = (data) => {
|
|
27372
|
+
const userPayload = prepareUserPayload(data);
|
|
27373
|
+
ingestInCache(userPayload);
|
|
27374
|
+
const cacheData = pullFromCache([
|
|
27375
|
+
'follow',
|
|
27376
|
+
'get',
|
|
27377
|
+
getResolver('follow')({
|
|
27378
|
+
from: userId,
|
|
27379
|
+
to: userPayload.users[0].userId,
|
|
27380
|
+
}),
|
|
27381
|
+
]);
|
|
27382
|
+
if (!cacheData)
|
|
27383
|
+
return;
|
|
27384
|
+
callback(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data);
|
|
27385
|
+
};
|
|
27386
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
27387
|
+
};
|
|
27388
|
+
|
|
27389
|
+
class FollowingLiveCollectionController extends LiveCollectionController {
|
|
27390
|
+
constructor(query, callback) {
|
|
27391
|
+
const queryStreamId = hash(query);
|
|
27392
|
+
const cacheKey = ['follow', 'collection', queryStreamId];
|
|
27393
|
+
const paginationController = new FollowingPaginationController(query);
|
|
27394
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27395
|
+
this.query = query;
|
|
27396
|
+
this.queryStreamController = new FollowingQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareFollowingsPayload);
|
|
27397
|
+
this.callback = callback.bind(this);
|
|
27398
|
+
this.loadPage({ initial: true });
|
|
27399
|
+
}
|
|
27400
|
+
setup() {
|
|
27401
|
+
var _a;
|
|
27402
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27403
|
+
if (!collection) {
|
|
27404
|
+
pushToCache(this.cacheKey, {
|
|
27405
|
+
data: [],
|
|
27406
|
+
params: {},
|
|
27407
|
+
});
|
|
27408
|
+
}
|
|
27409
|
+
}
|
|
27410
|
+
async persistModel(queryPayload) {
|
|
27411
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27412
|
+
}
|
|
27413
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27414
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27415
|
+
}
|
|
27416
|
+
startSubscription() {
|
|
27417
|
+
return this.queryStreamController.subscribeRTE([
|
|
27418
|
+
{ fn: onFollowerRequested, action: EnumFollowActions.OnRequested },
|
|
27419
|
+
{ fn: onFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
27420
|
+
{ fn: onFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
27421
|
+
{ fn: onFollowRequestCanceled, action: EnumFollowActions.OnCanceled },
|
|
27422
|
+
{ fn: onUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
27423
|
+
{ fn: onUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
27424
|
+
{ fn: onFollowerDeleted, action: EnumFollowActions.OnDeleted },
|
|
27425
|
+
{ fn: onLocalFollowerRequested, action: EnumFollowActions.OnRequested },
|
|
27426
|
+
{ fn: onLocalFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
27427
|
+
{ fn: onLocalFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
27428
|
+
{ fn: onLocalUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
27429
|
+
{ fn: onLocalUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
27430
|
+
{
|
|
27431
|
+
fn: onFollowingUserDeleted({ userId: this.query.userId }),
|
|
27432
|
+
action: EnumFollowActions.OnUserDeleted,
|
|
27433
|
+
},
|
|
27434
|
+
]);
|
|
27435
|
+
}
|
|
27436
|
+
notifyChange({ origin, loading, error }) {
|
|
27437
|
+
var _a, _b;
|
|
27438
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27439
|
+
if (!collection)
|
|
27440
|
+
return;
|
|
27441
|
+
const data = this.applyFilter((_b = collection.data
|
|
27442
|
+
.map(id => pullFromCache(['follow', 'get', id]))
|
|
27443
|
+
.filter(isNonNullable)
|
|
27444
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
27445
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
27446
|
+
return;
|
|
27447
|
+
this.callback({
|
|
27448
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
27449
|
+
data,
|
|
27450
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
27451
|
+
loading,
|
|
27452
|
+
error,
|
|
27453
|
+
});
|
|
27454
|
+
}
|
|
27455
|
+
applyFilter(data) {
|
|
27456
|
+
let followings = data;
|
|
27457
|
+
if (this.query.status && this.query.status !== "all" /* Amity.FollowStatusTypeEnum.All */) {
|
|
27458
|
+
followings = followings.filter(following => following.status === this.query.status);
|
|
27459
|
+
}
|
|
27460
|
+
followings = followings.filter(following => {
|
|
27461
|
+
var _a;
|
|
27462
|
+
const toUser = (_a = pullFromCache(['user', 'get', following.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
27463
|
+
return (toUser === null || toUser === void 0 ? void 0 : toUser.isDeleted) == null || (toUser === null || toUser === void 0 ? void 0 : toUser.isDeleted) === false;
|
|
27464
|
+
});
|
|
27465
|
+
return followings;
|
|
27466
|
+
}
|
|
27467
|
+
}
|
|
26996
27468
|
|
|
26997
27469
|
/* begin_public_function
|
|
26998
27470
|
id: user.relationship.query_my_followings, user.relationship.query_followings
|
|
@@ -27022,65 +27494,10 @@ const getFollowings = (params, callback, config) => {
|
|
|
27022
27494
|
}
|
|
27023
27495
|
const timestamp = Date.now();
|
|
27024
27496
|
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);
|
|
27497
|
+
const followingLiveCollection = new FollowingLiveCollectionController(params, callback);
|
|
27498
|
+
const disposers = followingLiveCollection.startSubscription();
|
|
27499
|
+
const cacheKey = followingLiveCollection.getCacheKey();
|
|
27500
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
27084
27501
|
return () => {
|
|
27085
27502
|
log(`getFollowings(tmpid: ${timestamp}) > dispose`);
|
|
27086
27503
|
disposers.forEach(fn => fn());
|
|
@@ -27168,6 +27585,11 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
27168
27585
|
onFollowRequestAccepted: onFollowRequestAccepted,
|
|
27169
27586
|
onFollowRequestDeclined: onFollowRequestDeclined,
|
|
27170
27587
|
onFollowInfoUpdated: onFollowInfoUpdated,
|
|
27588
|
+
onLocalUserFollowed: onLocalUserFollowed,
|
|
27589
|
+
onLocalUserUnfollowed: onLocalUserUnfollowed,
|
|
27590
|
+
onLocalFollowerRequested: onLocalFollowerRequested,
|
|
27591
|
+
onLocalFollowRequestAccepted: onLocalFollowRequestAccepted,
|
|
27592
|
+
onLocalFollowRequestDeclined: onLocalFollowRequestDeclined,
|
|
27171
27593
|
observeFollowInfo: observeFollowInfo,
|
|
27172
27594
|
observeFollowers: observeFollowers,
|
|
27173
27595
|
observeFollowings: observeFollowings,
|
|
@@ -27202,12 +27624,13 @@ const getUserByIds = async (userIds) => {
|
|
|
27202
27624
|
const { data } = await client.http.get(`/api/v3/users/list`, {
|
|
27203
27625
|
params: { userIds: encodedUserIds },
|
|
27204
27626
|
});
|
|
27627
|
+
const payload = prepareUserPayload(data);
|
|
27205
27628
|
const cachedAt = client.cache && Date.now();
|
|
27206
27629
|
if (client.cache)
|
|
27207
|
-
ingestInCache(
|
|
27630
|
+
ingestInCache(payload, { cachedAt });
|
|
27208
27631
|
fireEvent('user.fetched', data);
|
|
27209
27632
|
return {
|
|
27210
|
-
data:
|
|
27633
|
+
data: payload.users.map(user => LinkedObject.user(user)),
|
|
27211
27634
|
cachedAt,
|
|
27212
27635
|
};
|
|
27213
27636
|
};
|
|
@@ -27265,20 +27688,14 @@ getUserByIds.locally = (userIds) => {
|
|
|
27265
27688
|
const updateUser = async (userId, patch) => {
|
|
27266
27689
|
const client = getActiveClient();
|
|
27267
27690
|
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
27691
|
const { data } = await client.http.put(`/api/v3/users/`, Object.assign(Object.assign({ userId }, patch), { createNewUserWhenNotFound: false }));
|
|
27692
|
+
const payload = prepareUserPayload(data);
|
|
27275
27693
|
const cachedAt = client.cache && Date.now();
|
|
27276
27694
|
if (client.cache)
|
|
27277
|
-
ingestInCache(
|
|
27278
|
-
const { users } = data;
|
|
27695
|
+
ingestInCache(payload, { cachedAt });
|
|
27279
27696
|
fireEvent('user.updated', data);
|
|
27280
27697
|
return {
|
|
27281
|
-
data: users.find(user => user.userId === userId),
|
|
27698
|
+
data: payload.users.find(user => user.userId === userId),
|
|
27282
27699
|
cachedAt,
|
|
27283
27700
|
};
|
|
27284
27701
|
};
|
|
@@ -27302,11 +27719,12 @@ const updateUser = async (userId, patch) => {
|
|
|
27302
27719
|
const flagUser = async (userId) => {
|
|
27303
27720
|
const client = getActiveClient();
|
|
27304
27721
|
client.log('user/flagUser', userId);
|
|
27305
|
-
const { data
|
|
27722
|
+
const { data } = await client.http.post(`api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
27723
|
+
const payload = prepareUserPayload(data);
|
|
27306
27724
|
if (client.cache) {
|
|
27307
27725
|
ingestInCache(payload);
|
|
27308
27726
|
}
|
|
27309
|
-
fireEvent('user.flagged',
|
|
27727
|
+
fireEvent('user.flagged', data);
|
|
27310
27728
|
return !!payload;
|
|
27311
27729
|
};
|
|
27312
27730
|
/* end_public_function */
|
|
@@ -27329,11 +27747,12 @@ const flagUser = async (userId) => {
|
|
|
27329
27747
|
const unflagUser = async (userId) => {
|
|
27330
27748
|
const client = getActiveClient();
|
|
27331
27749
|
client.log('user/unflag', userId);
|
|
27332
|
-
const { data
|
|
27750
|
+
const { data } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
27751
|
+
const payload = prepareUserPayload(data);
|
|
27333
27752
|
if (client.cache) {
|
|
27334
27753
|
ingestInCache(payload);
|
|
27335
27754
|
}
|
|
27336
|
-
fireEvent('user.unflagged',
|
|
27755
|
+
fireEvent('user.unflagged', data);
|
|
27337
27756
|
return !!payload;
|
|
27338
27757
|
};
|
|
27339
27758
|
/* end_public_function */
|
|
@@ -27361,74 +27780,6 @@ const isUserFlaggedByMe = async (userId) => {
|
|
|
27361
27780
|
};
|
|
27362
27781
|
/* end_public_function */
|
|
27363
27782
|
|
|
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
27783
|
/**
|
|
27433
27784
|
* ```js
|
|
27434
27785
|
* import { onUserFetched } from '@amityco/ts-sdk-react-native'
|
|
@@ -27464,10 +27815,17 @@ const getUser$2 = async (userId) => {
|
|
|
27464
27815
|
const client = getActiveClient();
|
|
27465
27816
|
client.log('user/getUser', userId);
|
|
27466
27817
|
isInTombstone('user', userId);
|
|
27467
|
-
let data;
|
|
27468
27818
|
try {
|
|
27469
|
-
const
|
|
27470
|
-
|
|
27819
|
+
const { data } = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
|
|
27820
|
+
const cachedAt = client.cache && Date.now();
|
|
27821
|
+
const payload = prepareUserPayload(data);
|
|
27822
|
+
if (client.cache)
|
|
27823
|
+
ingestInCache(payload, { cachedAt });
|
|
27824
|
+
fireEvent('user.fetched', data);
|
|
27825
|
+
return {
|
|
27826
|
+
data: payload.users.find(user => user.userId === userId),
|
|
27827
|
+
cachedAt,
|
|
27828
|
+
};
|
|
27471
27829
|
}
|
|
27472
27830
|
catch (error) {
|
|
27473
27831
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
@@ -27475,15 +27833,6 @@ const getUser$2 = async (userId) => {
|
|
|
27475
27833
|
}
|
|
27476
27834
|
throw error;
|
|
27477
27835
|
}
|
|
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
27836
|
};
|
|
27488
27837
|
/**
|
|
27489
27838
|
* ```js
|
|
@@ -27541,7 +27890,7 @@ const getUser$1 = (userId, callback) => {
|
|
|
27541
27890
|
return liveObject(userId, reactor, 'userId', getUser$2, [
|
|
27542
27891
|
onUserFetched,
|
|
27543
27892
|
onUserUpdated,
|
|
27544
|
-
onUserDeleted,
|
|
27893
|
+
onUserDeleted$2,
|
|
27545
27894
|
onUserFlagged,
|
|
27546
27895
|
onUserUnflagged,
|
|
27547
27896
|
onUserFlagCleared,
|
|
@@ -27549,114 +27898,144 @@ const getUser$1 = (userId, callback) => {
|
|
|
27549
27898
|
};
|
|
27550
27899
|
/* end_public_function */
|
|
27551
27900
|
|
|
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 });
|
|
27901
|
+
class UserPaginationController extends PaginationController {
|
|
27902
|
+
async getRequest(queryParams, token) {
|
|
27903
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
27904
|
+
const options = token ? { token } : { limit };
|
|
27905
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
27906
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
27907
|
+
});
|
|
27908
|
+
return queryResponse;
|
|
27591
27909
|
}
|
|
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,
|
|
27910
|
+
}
|
|
27911
|
+
|
|
27912
|
+
class UserQueryStreamController extends QueryStreamController {
|
|
27913
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27914
|
+
super(query, cacheKey);
|
|
27915
|
+
this.notifyChange = notifyChange;
|
|
27916
|
+
this.preparePayload = preparePayload;
|
|
27917
|
+
}
|
|
27918
|
+
async saveToMainDB(response) {
|
|
27919
|
+
const processedPayload = await this.preparePayload(response);
|
|
27920
|
+
const client = getActiveClient();
|
|
27921
|
+
const cachedAt = client.cache && Date.now();
|
|
27922
|
+
if (client.cache) {
|
|
27923
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27635
27924
|
}
|
|
27636
|
-
|
|
27637
|
-
|
|
27925
|
+
}
|
|
27926
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27927
|
+
var _a, _b;
|
|
27928
|
+
if (refresh) {
|
|
27929
|
+
pushToCache(this.cacheKey, {
|
|
27930
|
+
data: response.users.map(getResolver('user')),
|
|
27931
|
+
});
|
|
27932
|
+
}
|
|
27933
|
+
else {
|
|
27934
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27935
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27936
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
27937
|
+
}
|
|
27938
|
+
}
|
|
27939
|
+
reactor(action) {
|
|
27940
|
+
return (user) => {
|
|
27941
|
+
var _a;
|
|
27942
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27943
|
+
if (!collection)
|
|
27944
|
+
return;
|
|
27945
|
+
/*
|
|
27946
|
+
* Simply update a collection and let responder decide what to do with data
|
|
27947
|
+
*/
|
|
27948
|
+
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
27949
|
+
pushToCache(this.cacheKey, collection);
|
|
27950
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27951
|
+
};
|
|
27952
|
+
}
|
|
27953
|
+
subscribeRTE(createSubscriber) {
|
|
27954
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27955
|
+
}
|
|
27956
|
+
}
|
|
27638
27957
|
|
|
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);
|
|
27958
|
+
class UserLiveCollectionController extends LiveCollectionController {
|
|
27959
|
+
constructor(query, callback) {
|
|
27960
|
+
const queryStreamId = hash(query);
|
|
27961
|
+
const cacheKey = ['user', 'collection', queryStreamId];
|
|
27962
|
+
const paginationController = new UserPaginationController(query);
|
|
27963
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27964
|
+
this.query = query;
|
|
27965
|
+
this.queryStreamController = new UserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareUserPayload);
|
|
27966
|
+
this.callback = callback.bind(this);
|
|
27967
|
+
this.loadPage({ initial: true });
|
|
27657
27968
|
}
|
|
27658
|
-
|
|
27659
|
-
|
|
27969
|
+
setup() {
|
|
27970
|
+
var _a;
|
|
27971
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27972
|
+
if (!collection) {
|
|
27973
|
+
pushToCache(this.cacheKey, {
|
|
27974
|
+
data: [],
|
|
27975
|
+
params: {},
|
|
27976
|
+
});
|
|
27977
|
+
}
|
|
27978
|
+
}
|
|
27979
|
+
async persistModel(queryPayload) {
|
|
27980
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27981
|
+
}
|
|
27982
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27983
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27984
|
+
}
|
|
27985
|
+
startSubscription() {
|
|
27986
|
+
return this.queryStreamController.subscribeRTE([
|
|
27987
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
27988
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
27989
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
27990
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
27991
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
27992
|
+
]);
|
|
27993
|
+
}
|
|
27994
|
+
notifyChange({ origin, loading, error }) {
|
|
27995
|
+
var _a, _b;
|
|
27996
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27997
|
+
if (!collection)
|
|
27998
|
+
return;
|
|
27999
|
+
const data = this.applyFilter((_b = collection.data
|
|
28000
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
28001
|
+
.filter(isNonNullable)
|
|
28002
|
+
.map(({ data }) => data)
|
|
28003
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
28004
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
28005
|
+
return;
|
|
28006
|
+
this.callback({
|
|
28007
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
28008
|
+
data,
|
|
28009
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
28010
|
+
loading,
|
|
28011
|
+
error,
|
|
28012
|
+
});
|
|
28013
|
+
}
|
|
28014
|
+
applyFilter(data) {
|
|
28015
|
+
let users = data;
|
|
28016
|
+
if (!this.query.displayName) {
|
|
28017
|
+
const sortFn = (() => {
|
|
28018
|
+
switch (this.query.sortBy) {
|
|
28019
|
+
case 'firstCreated':
|
|
28020
|
+
return sortByFirstCreated;
|
|
28021
|
+
case 'lastCreated':
|
|
28022
|
+
return sortByLastCreated;
|
|
28023
|
+
case 'displayName':
|
|
28024
|
+
return sortByDisplayName;
|
|
28025
|
+
default:
|
|
28026
|
+
return sortByLastCreated;
|
|
28027
|
+
}
|
|
28028
|
+
})();
|
|
28029
|
+
users = users.sort(sortFn);
|
|
28030
|
+
}
|
|
28031
|
+
if (this.query.filter === 'flagged') {
|
|
28032
|
+
users = users.filter(user => !!user.hashFlag);
|
|
28033
|
+
}
|
|
28034
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
28035
|
+
return users;
|
|
28036
|
+
}
|
|
28037
|
+
}
|
|
28038
|
+
|
|
27660
28039
|
/* begin_public_function
|
|
27661
28040
|
id: user.query
|
|
27662
28041
|
*/
|
|
@@ -27684,63 +28063,10 @@ const getUsers = (params, callback, config) => {
|
|
|
27684
28063
|
}
|
|
27685
28064
|
const timestamp = Date.now();
|
|
27686
28065
|
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);
|
|
28066
|
+
const usersLiveCollection = new UserLiveCollectionController(params, callback);
|
|
28067
|
+
const disposers = usersLiveCollection.startSubscription();
|
|
28068
|
+
const cacheKey = usersLiveCollection.getCacheKey();
|
|
28069
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
27744
28070
|
return () => {
|
|
27745
28071
|
log(`liveUsers(tmpid: ${timestamp}) > dispose`);
|
|
27746
28072
|
disposers.forEach(fn => fn());
|
|
@@ -27763,27 +28089,9 @@ const getUsers = (params, callback, config) => {
|
|
|
27763
28089
|
* @async
|
|
27764
28090
|
*/
|
|
27765
28091
|
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);
|
|
28092
|
+
const { data, cachedAt } = await getUser$2(userId);
|
|
27785
28093
|
return {
|
|
27786
|
-
data: LinkedObject.user(
|
|
28094
|
+
data: LinkedObject.user(data),
|
|
27787
28095
|
cachedAt,
|
|
27788
28096
|
};
|
|
27789
28097
|
};
|
|
@@ -27801,11 +28109,7 @@ const getUser = async (userId) => {
|
|
|
27801
28109
|
* @category User API
|
|
27802
28110
|
*/
|
|
27803
28111
|
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]);
|
|
28112
|
+
const cached = getUser$2.locally(userId);
|
|
27809
28113
|
if (!cached)
|
|
27810
28114
|
return;
|
|
27811
28115
|
return {
|
|
@@ -27847,7 +28151,7 @@ const observeUser = (userId, callback) => {
|
|
|
27847
28151
|
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, newResult);
|
|
27848
28152
|
};
|
|
27849
28153
|
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')));
|
|
28154
|
+
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
28155
|
runQuery(createQuery(getUser, userId), result => result.data && router(result, 'onFetch'));
|
|
27852
28156
|
return () => {
|
|
27853
28157
|
log(`observeUser(tmpid: ${timestamp}) > dispose`);
|
|
@@ -27855,6 +28159,130 @@ const observeUser = (userId, callback) => {
|
|
|
27855
28159
|
};
|
|
27856
28160
|
};
|
|
27857
28161
|
|
|
28162
|
+
class SearchUserPaginationController extends PaginationController {
|
|
28163
|
+
async getRequest(queryParams, token) {
|
|
28164
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
28165
|
+
const options = token ? { token } : { limit };
|
|
28166
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
28167
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
28168
|
+
});
|
|
28169
|
+
return queryResponse;
|
|
28170
|
+
}
|
|
28171
|
+
}
|
|
28172
|
+
|
|
28173
|
+
class SearchUserQueryStreamController extends QueryStreamController {
|
|
28174
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
28175
|
+
super(query, cacheKey);
|
|
28176
|
+
this.notifyChange = notifyChange;
|
|
28177
|
+
this.preparePayload = preparePayload;
|
|
28178
|
+
}
|
|
28179
|
+
async saveToMainDB(response) {
|
|
28180
|
+
const processedPayload = await this.preparePayload(response);
|
|
28181
|
+
const client = getActiveClient();
|
|
28182
|
+
const cachedAt = client.cache && Date.now();
|
|
28183
|
+
if (client.cache) {
|
|
28184
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
28185
|
+
}
|
|
28186
|
+
}
|
|
28187
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
28188
|
+
var _a, _b;
|
|
28189
|
+
if (refresh) {
|
|
28190
|
+
pushToCache(this.cacheKey, {
|
|
28191
|
+
data: response.users.map(getResolver('user')),
|
|
28192
|
+
});
|
|
28193
|
+
}
|
|
28194
|
+
else {
|
|
28195
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28196
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
28197
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
28198
|
+
}
|
|
28199
|
+
}
|
|
28200
|
+
reactor(action) {
|
|
28201
|
+
return (user) => {
|
|
28202
|
+
var _a;
|
|
28203
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28204
|
+
if (!collection)
|
|
28205
|
+
return;
|
|
28206
|
+
/*
|
|
28207
|
+
* Simply update a collection and let responder decide what to do with data
|
|
28208
|
+
*/
|
|
28209
|
+
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
28210
|
+
pushToCache(this.cacheKey, collection);
|
|
28211
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
28212
|
+
};
|
|
28213
|
+
}
|
|
28214
|
+
subscribeRTE(createSubscriber) {
|
|
28215
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
28216
|
+
}
|
|
28217
|
+
}
|
|
28218
|
+
|
|
28219
|
+
class SearchUserLiveCollectionController extends LiveCollectionController {
|
|
28220
|
+
constructor(query, callback) {
|
|
28221
|
+
var _a;
|
|
28222
|
+
const queryStreamId = hash(query);
|
|
28223
|
+
const cacheKey = ['user', 'collection', queryStreamId];
|
|
28224
|
+
const paginationController = new SearchUserPaginationController(query);
|
|
28225
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
28226
|
+
this.query = Object.assign(Object.assign({}, query), { filter: (_a = query.filter) !== null && _a !== void 0 ? _a : 'all' });
|
|
28227
|
+
this.queryStreamController = new SearchUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareUserPayload);
|
|
28228
|
+
this.callback = callback.bind(this);
|
|
28229
|
+
this.loadPage({ initial: true });
|
|
28230
|
+
}
|
|
28231
|
+
setup() {
|
|
28232
|
+
var _a;
|
|
28233
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28234
|
+
if (!collection) {
|
|
28235
|
+
pushToCache(this.cacheKey, {
|
|
28236
|
+
data: [],
|
|
28237
|
+
params: {},
|
|
28238
|
+
});
|
|
28239
|
+
}
|
|
28240
|
+
}
|
|
28241
|
+
async persistModel(queryPayload) {
|
|
28242
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
28243
|
+
}
|
|
28244
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
28245
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
28246
|
+
}
|
|
28247
|
+
startSubscription() {
|
|
28248
|
+
return this.queryStreamController.subscribeRTE([
|
|
28249
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
28250
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
28251
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
28252
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
28253
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
28254
|
+
]);
|
|
28255
|
+
}
|
|
28256
|
+
notifyChange({ origin, loading, error }) {
|
|
28257
|
+
var _a, _b;
|
|
28258
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28259
|
+
if (!collection)
|
|
28260
|
+
return;
|
|
28261
|
+
const data = this.applyFilter((_b = collection.data
|
|
28262
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
28263
|
+
.filter(isNonNullable)
|
|
28264
|
+
.map(({ data }) => data)
|
|
28265
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
28266
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
28267
|
+
return;
|
|
28268
|
+
this.callback({
|
|
28269
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
28270
|
+
data,
|
|
28271
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
28272
|
+
loading,
|
|
28273
|
+
error,
|
|
28274
|
+
});
|
|
28275
|
+
}
|
|
28276
|
+
applyFilter(data) {
|
|
28277
|
+
let users = data;
|
|
28278
|
+
if (this.query.filter === 'flagged') {
|
|
28279
|
+
users = users.filter(user => !!user.hashFlag);
|
|
28280
|
+
}
|
|
28281
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
28282
|
+
return users;
|
|
28283
|
+
}
|
|
28284
|
+
}
|
|
28285
|
+
|
|
27858
28286
|
/* begin_public_function
|
|
27859
28287
|
id: user.search
|
|
27860
28288
|
*/
|
|
@@ -27876,7 +28304,21 @@ const observeUser = (userId, callback) => {
|
|
|
27876
28304
|
* @category Category Live Collection
|
|
27877
28305
|
*/
|
|
27878
28306
|
const searchUserByDisplayName = (params, callback, config) => {
|
|
27879
|
-
|
|
28307
|
+
const { log, cache } = getActiveClient();
|
|
28308
|
+
if (!cache) {
|
|
28309
|
+
// eslint-disable-next-line no-console
|
|
28310
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
28311
|
+
}
|
|
28312
|
+
const timestamp = Date.now();
|
|
28313
|
+
log(`liveSearchUsers(tmpid: ${timestamp}) > listen`);
|
|
28314
|
+
const searchUsersLiveCollection = new SearchUserLiveCollectionController(params, callback);
|
|
28315
|
+
const disposers = searchUsersLiveCollection.startSubscription();
|
|
28316
|
+
const cacheKey = searchUsersLiveCollection.getCacheKey();
|
|
28317
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
28318
|
+
return () => {
|
|
28319
|
+
log(`liveSearchUsers(tmpid: ${timestamp}) > dispose`);
|
|
28320
|
+
disposers.forEach(fn => fn());
|
|
28321
|
+
};
|
|
27880
28322
|
};
|
|
27881
28323
|
/* end_public_function */
|
|
27882
28324
|
|
|
@@ -28045,7 +28487,7 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
28045
28487
|
unflagUser: unflagUser,
|
|
28046
28488
|
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
28047
28489
|
onUserUpdated: onUserUpdated,
|
|
28048
|
-
onUserDeleted: onUserDeleted,
|
|
28490
|
+
onUserDeleted: onUserDeleted$2,
|
|
28049
28491
|
onUserFlagged: onUserFlagged,
|
|
28050
28492
|
onUserUnflagged: onUserUnflagged,
|
|
28051
28493
|
onUserFlagCleared: onUserFlagCleared,
|
|
@@ -28117,19 +28559,6 @@ getFile.locally = (fileId) => {
|
|
|
28117
28559
|
};
|
|
28118
28560
|
};
|
|
28119
28561
|
|
|
28120
|
-
const rebuildFormDataWithMimeType = (formData) => {
|
|
28121
|
-
const files = formData.getAll('files') || [];
|
|
28122
|
-
if (!files.length)
|
|
28123
|
-
return formData;
|
|
28124
|
-
const newFormData = new FormData();
|
|
28125
|
-
const imageFile = files[0];
|
|
28126
|
-
// In ReactNative Android, we need to define a file type for all upload items; otherwise backend will reject a request
|
|
28127
|
-
// @ts-ignore - we need to modify `type` because in android this value will not set by default (https://github.com/axios/axios/issues/4823)
|
|
28128
|
-
imageFile.type = mime.getType(imageFile.uri);
|
|
28129
|
-
newFormData.append('files', imageFile);
|
|
28130
|
-
return newFormData;
|
|
28131
|
-
};
|
|
28132
|
-
|
|
28133
28562
|
/* begin_public_function
|
|
28134
28563
|
id: file.upload.file
|
|
28135
28564
|
*/
|
|
@@ -28160,7 +28589,7 @@ const uploadFile = async (formData, onProgress) => {
|
|
|
28160
28589
|
const headers = 'getHeaders' in formData
|
|
28161
28590
|
? formData.getHeaders()
|
|
28162
28591
|
: { 'content-type': 'multipart/form-data' };
|
|
28163
|
-
const { data } = await client.http.post('/api/v4/files',
|
|
28592
|
+
const { data } = await client.http.post('/api/v4/files', formData, {
|
|
28164
28593
|
headers,
|
|
28165
28594
|
onUploadProgress({ loaded, total = 100 }) {
|
|
28166
28595
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -28241,17 +28670,16 @@ const uploadVideo = async (formData, feedType, onProgress) => {
|
|
|
28241
28670
|
const files = formData.getAll('files');
|
|
28242
28671
|
if (!files.length)
|
|
28243
28672
|
throw new Error('The formData object must have a `files` key.');
|
|
28244
|
-
const newFormDataWithMimeType = rebuildFormDataWithMimeType(formData);
|
|
28245
28673
|
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
28246
|
-
|
|
28247
|
-
|
|
28674
|
+
formData.append('accessType', accessType);
|
|
28675
|
+
formData.append('preferredFilename', files[0].name);
|
|
28248
28676
|
if (feedType) {
|
|
28249
|
-
|
|
28677
|
+
formData.append('feedType', feedType);
|
|
28250
28678
|
}
|
|
28251
|
-
const headers = 'getHeaders' in
|
|
28252
|
-
?
|
|
28679
|
+
const headers = 'getHeaders' in formData
|
|
28680
|
+
? formData.getHeaders()
|
|
28253
28681
|
: { 'content-type': 'multipart/form-data' };
|
|
28254
|
-
const { data } = await client.http.post('/api/v4/videos',
|
|
28682
|
+
const { data } = await client.http.post('/api/v4/videos', formData, {
|
|
28255
28683
|
headers,
|
|
28256
28684
|
onUploadProgress({ loaded, total = 100 }) {
|
|
28257
28685
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -28293,14 +28721,13 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
28293
28721
|
const files = formData.getAll('files');
|
|
28294
28722
|
if (!files.length)
|
|
28295
28723
|
throw new Error('The formData object must have a `files` key.');
|
|
28296
|
-
const newFormDataWithMimeType = rebuildFormDataWithMimeType(formData);
|
|
28297
28724
|
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
28298
|
-
|
|
28299
|
-
|
|
28300
|
-
const headers = 'getHeaders' in
|
|
28301
|
-
?
|
|
28725
|
+
formData.append('accessType', accessType);
|
|
28726
|
+
formData.append('preferredFilename', files[0].name);
|
|
28727
|
+
const headers = 'getHeaders' in formData
|
|
28728
|
+
? formData.getHeaders()
|
|
28302
28729
|
: { 'content-type': 'multipart/form-data' };
|
|
28303
|
-
const { data } = await client.http.post('/api/v4/images',
|
|
28730
|
+
const { data } = await client.http.post('/api/v4/images', formData, {
|
|
28304
28731
|
headers,
|
|
28305
28732
|
onUploadProgress({ loaded, total = 100 }) {
|
|
28306
28733
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -28967,6 +29394,7 @@ const prepareCommentFromFlaggedEvent = (payload) => {
|
|
|
28967
29394
|
* @async
|
|
28968
29395
|
* */
|
|
28969
29396
|
const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
29397
|
+
var _a, _b;
|
|
28970
29398
|
const client = getActiveClient();
|
|
28971
29399
|
client.log('reaction/createReaction', {
|
|
28972
29400
|
referenceId,
|
|
@@ -28985,8 +29413,21 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
28985
29413
|
'get',
|
|
28986
29414
|
referenceId,
|
|
28987
29415
|
]);
|
|
28988
|
-
(model
|
|
28989
|
-
|
|
29416
|
+
if (!model)
|
|
29417
|
+
return true;
|
|
29418
|
+
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 }) });
|
|
29419
|
+
if (referenceType === 'comment') {
|
|
29420
|
+
fireEvent('local.comment.addReaction', {
|
|
29421
|
+
comment: updatedModel,
|
|
29422
|
+
});
|
|
29423
|
+
return true;
|
|
29424
|
+
}
|
|
29425
|
+
if (referenceType === 'post') {
|
|
29426
|
+
fireEvent('local.post.addReaction', {
|
|
29427
|
+
post: updatedModel,
|
|
29428
|
+
});
|
|
29429
|
+
return true;
|
|
29430
|
+
}
|
|
28990
29431
|
}
|
|
28991
29432
|
return true;
|
|
28992
29433
|
};
|
|
@@ -29051,6 +29492,7 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
29051
29492
|
* @async
|
|
29052
29493
|
* */
|
|
29053
29494
|
const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
29495
|
+
var _a, _b;
|
|
29054
29496
|
const client = getActiveClient();
|
|
29055
29497
|
client.log('reaction/removeReaction', {
|
|
29056
29498
|
referenceId,
|
|
@@ -29071,8 +29513,21 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
29071
29513
|
'get',
|
|
29072
29514
|
referenceId,
|
|
29073
29515
|
]);
|
|
29074
|
-
(model
|
|
29075
|
-
|
|
29516
|
+
if (!model)
|
|
29517
|
+
return true;
|
|
29518
|
+
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) }) });
|
|
29519
|
+
if (referenceType === 'comment') {
|
|
29520
|
+
fireEvent('local.comment.removeReaction', {
|
|
29521
|
+
comment: updatedModel,
|
|
29522
|
+
});
|
|
29523
|
+
return true;
|
|
29524
|
+
}
|
|
29525
|
+
if (referenceType === 'post') {
|
|
29526
|
+
fireEvent('local.post.removeReaction', {
|
|
29527
|
+
post: updatedModel,
|
|
29528
|
+
});
|
|
29529
|
+
return true;
|
|
29530
|
+
}
|
|
29076
29531
|
}
|
|
29077
29532
|
return true;
|
|
29078
29533
|
};
|
|
@@ -29117,6 +29572,66 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
29117
29572
|
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
29573
|
};
|
|
29119
29574
|
|
|
29575
|
+
const getMatchPostSetting = (value) => {
|
|
29576
|
+
var _a;
|
|
29577
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
29578
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
29579
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
29580
|
+
};
|
|
29581
|
+
function addPostSetting({ communities }) {
|
|
29582
|
+
return communities.map((_a) => {
|
|
29583
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
29584
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
29585
|
+
needApprovalOnPostCreation,
|
|
29586
|
+
onlyAdminCanPost,
|
|
29587
|
+
}) }, restCommunityPayload));
|
|
29588
|
+
});
|
|
29589
|
+
}
|
|
29590
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
29591
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
29592
|
+
// map users with community
|
|
29593
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
29594
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
29595
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
29596
|
+
});
|
|
29597
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
29598
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
29599
|
+
};
|
|
29600
|
+
const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
29601
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
29602
|
+
// map users with community
|
|
29603
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
29604
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
29605
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
29606
|
+
});
|
|
29607
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
29608
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
29609
|
+
};
|
|
29610
|
+
const prepareCommunityRequest = (params) => {
|
|
29611
|
+
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
29612
|
+
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
29613
|
+
// Convert story setting to the actual value. (Allow by default)
|
|
29614
|
+
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
29615
|
+
};
|
|
29616
|
+
|
|
29617
|
+
const preparePostPayload = (postPayload) => {
|
|
29618
|
+
// Unpack community payload by mapping payload field to postSetting value.
|
|
29619
|
+
const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
|
|
29620
|
+
// map users with community
|
|
29621
|
+
const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
|
|
29622
|
+
const user = postPayload.users.find(user => user.userId === communityUser.userId);
|
|
29623
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
29624
|
+
});
|
|
29625
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
29626
|
+
// feed type
|
|
29627
|
+
const posts = postPayload.posts.map(post => {
|
|
29628
|
+
var _a;
|
|
29629
|
+
const feedType = (_a = postPayload.feeds.find(feed => feed.feedId === post.feedId)) === null || _a === void 0 ? void 0 : _a.feedType;
|
|
29630
|
+
return Object.assign(Object.assign({}, post), { feedType });
|
|
29631
|
+
});
|
|
29632
|
+
return Object.assign(Object.assign({}, postPayload), { posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
29633
|
+
};
|
|
29634
|
+
|
|
29120
29635
|
const createPostEventSubscriber = (event, callback) => {
|
|
29121
29636
|
const client = getActiveClient();
|
|
29122
29637
|
const filter = (payload) => {
|
|
@@ -29125,8 +29640,8 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
29125
29640
|
callback(payload.posts[0]);
|
|
29126
29641
|
}
|
|
29127
29642
|
else {
|
|
29128
|
-
const
|
|
29129
|
-
const
|
|
29643
|
+
const data = preparePostPayload(payload);
|
|
29644
|
+
const { communities } = data;
|
|
29130
29645
|
ingestInCache(data);
|
|
29131
29646
|
if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['post.updated'].includes(event)) {
|
|
29132
29647
|
fireEvent('community.updated', {
|
|
@@ -29153,7 +29668,7 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
29153
29668
|
// 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
29669
|
// and will got skip to notify in a previous code block
|
|
29155
29670
|
if (postedUserId !== client.userId) {
|
|
29156
|
-
|
|
29671
|
+
dropFromCache(['post', 'get', postId]);
|
|
29157
29672
|
}
|
|
29158
29673
|
return callback(payload.posts[0]);
|
|
29159
29674
|
}
|
|
@@ -29170,6 +29685,32 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
29170
29685
|
}
|
|
29171
29686
|
};
|
|
29172
29687
|
return createEventSubscriber(client, event, event, filter);
|
|
29688
|
+
};
|
|
29689
|
+
const createLocalPostEventSubscriber = (event, callback) => {
|
|
29690
|
+
const client = getActiveClient();
|
|
29691
|
+
const filter = (payload) => {
|
|
29692
|
+
if (!client.cache) {
|
|
29693
|
+
callback(payload.posts[0]);
|
|
29694
|
+
}
|
|
29695
|
+
else {
|
|
29696
|
+
const data = preparePostPayload(payload);
|
|
29697
|
+
const { communities } = data;
|
|
29698
|
+
ingestInCache(data);
|
|
29699
|
+
if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['local.post.updated'].includes(event)) {
|
|
29700
|
+
fireEvent('community.updated', {
|
|
29701
|
+
communities,
|
|
29702
|
+
categories: [],
|
|
29703
|
+
communityUsers: data.communityUsers,
|
|
29704
|
+
feeds: [],
|
|
29705
|
+
files: [],
|
|
29706
|
+
users: [],
|
|
29707
|
+
});
|
|
29708
|
+
}
|
|
29709
|
+
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
29710
|
+
callback(post.data);
|
|
29711
|
+
}
|
|
29712
|
+
};
|
|
29713
|
+
return createEventSubscriber(client, event, event, filter);
|
|
29173
29714
|
};
|
|
29174
29715
|
|
|
29175
29716
|
/**
|
|
@@ -29376,6 +29917,9 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
29376
29917
|
comments[0].commentId,
|
|
29377
29918
|
]);
|
|
29378
29919
|
if (['comment.created'].includes(event)) {
|
|
29920
|
+
// NOTE: skip adding comment to parent comment children if it's the same user since we use the local event to update instead.
|
|
29921
|
+
if (event === 'comment.created' && comment.data.userId === client.userId)
|
|
29922
|
+
return;
|
|
29379
29923
|
if (comments[0].parentId) {
|
|
29380
29924
|
const parentComment = pullFromCache([
|
|
29381
29925
|
'comment',
|
|
@@ -29397,6 +29941,58 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
29397
29941
|
}
|
|
29398
29942
|
};
|
|
29399
29943
|
return createEventSubscriber(client, event, event, filter);
|
|
29944
|
+
};
|
|
29945
|
+
const createLocalCommentEventSubscriber = (event, callback) => {
|
|
29946
|
+
const client = getActiveClient();
|
|
29947
|
+
const filter = (payload) => {
|
|
29948
|
+
var _a;
|
|
29949
|
+
if (!client.cache) {
|
|
29950
|
+
// TODO: here we are missing specific properties here!
|
|
29951
|
+
callback(LinkedObject.comment(payload.comments[0]));
|
|
29952
|
+
}
|
|
29953
|
+
else {
|
|
29954
|
+
const processed = payload;
|
|
29955
|
+
ingestInCache(processed);
|
|
29956
|
+
const { comments } = processed;
|
|
29957
|
+
if (comments.length > 0) {
|
|
29958
|
+
const comment = pullFromCache([
|
|
29959
|
+
'comment',
|
|
29960
|
+
'get',
|
|
29961
|
+
comments[0].commentId,
|
|
29962
|
+
]);
|
|
29963
|
+
if (['local.comment.created'].includes(event)) {
|
|
29964
|
+
if (comments[0].parentId) {
|
|
29965
|
+
const parentComment = pullFromCache([
|
|
29966
|
+
'comment',
|
|
29967
|
+
'get',
|
|
29968
|
+
comments[0].parentId,
|
|
29969
|
+
]);
|
|
29970
|
+
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
29971
|
+
// Skip to update parent childComment if current comment already exists
|
|
29972
|
+
if (!parentComment.data.children.includes(comments[0].commentId)) {
|
|
29973
|
+
const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber + 1, children: [...new Set([...parentComment.data.children, comments[0].commentId])] });
|
|
29974
|
+
pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
|
|
29975
|
+
setTimeout(() => {
|
|
29976
|
+
// NOTE: This is workaround solution for emitting event not work properly.
|
|
29977
|
+
fireEvent('comment.updated', {
|
|
29978
|
+
comments: [newParentComment],
|
|
29979
|
+
commentChildren: [],
|
|
29980
|
+
files: [],
|
|
29981
|
+
users: [],
|
|
29982
|
+
communityUsers: [],
|
|
29983
|
+
});
|
|
29984
|
+
}, 200);
|
|
29985
|
+
}
|
|
29986
|
+
}
|
|
29987
|
+
}
|
|
29988
|
+
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; });
|
|
29989
|
+
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
29990
|
+
}
|
|
29991
|
+
callback(LinkedObject.comment(comment.data));
|
|
29992
|
+
}
|
|
29993
|
+
}
|
|
29994
|
+
};
|
|
29995
|
+
return createEventSubscriber(client, event, event, filter);
|
|
29400
29996
|
};
|
|
29401
29997
|
|
|
29402
29998
|
/**
|
|
@@ -29956,29 +30552,53 @@ var index$h = /*#__PURE__*/Object.freeze({
|
|
|
29956
30552
|
getReactions: getReactions
|
|
29957
30553
|
});
|
|
29958
30554
|
|
|
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
|
-
};
|
|
30555
|
+
function prepareCommentPayload(commentPayload) {
|
|
30556
|
+
const { comments } = commentPayload;
|
|
30557
|
+
return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
|
|
30558
|
+
if (comment.hasOwnProperty('myReactions'))
|
|
30559
|
+
return comment;
|
|
30560
|
+
// Sometimes `myReactions` field will not come with BE response because that field is empty
|
|
30561
|
+
// We need to put it with an empty array manually to make it show up in client side
|
|
30562
|
+
return Object.assign({ myReactions: [] }, comment);
|
|
30563
|
+
}) });
|
|
30564
|
+
}
|
|
29981
30565
|
|
|
30566
|
+
const createMessageReport = async ({ client, referenceId, }) => {
|
|
30567
|
+
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
30568
|
+
if (client.cache) {
|
|
30569
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
30570
|
+
ingestInCache(messagePayload);
|
|
30571
|
+
}
|
|
30572
|
+
fireEvent(`message.flagged`, payload);
|
|
30573
|
+
return !!payload;
|
|
30574
|
+
};
|
|
30575
|
+
const createPostReport = async ({ client, referenceId, }) => {
|
|
30576
|
+
const { data: payload } = await client.http.post(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
|
|
30577
|
+
if (client.cache) {
|
|
30578
|
+
const postPayload = await preparePostPayload(payload);
|
|
30579
|
+
ingestInCache(postPayload);
|
|
30580
|
+
}
|
|
30581
|
+
fireEvent(`post.flagged`, payload);
|
|
30582
|
+
return !!payload;
|
|
30583
|
+
};
|
|
30584
|
+
const createUserReport = async ({ client, referenceId, }) => {
|
|
30585
|
+
const { data: payload } = await client.http.post(`/api/v4/me/flags/${encodeURIComponent(referenceId)}`);
|
|
30586
|
+
if (client.cache) {
|
|
30587
|
+
const userPayload = await prepareUserPayload(payload);
|
|
30588
|
+
ingestInCache(userPayload);
|
|
30589
|
+
}
|
|
30590
|
+
fireEvent(`user.flagged`, payload);
|
|
30591
|
+
return !!payload;
|
|
30592
|
+
};
|
|
30593
|
+
const createCommentReport = async ({ client, referenceId, }) => {
|
|
30594
|
+
const { data: payload } = await client.http.post(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
|
|
30595
|
+
if (client.cache) {
|
|
30596
|
+
const commentPayload = await prepareCommentPayload(payload);
|
|
30597
|
+
ingestInCache(commentPayload);
|
|
30598
|
+
}
|
|
30599
|
+
fireEvent(`comment.flagged`, payload);
|
|
30600
|
+
return !!payload;
|
|
30601
|
+
};
|
|
29982
30602
|
/**
|
|
29983
30603
|
* ```js
|
|
29984
30604
|
* import { createReport } from '@amityco/ts-sdk-react-native'
|
|
@@ -29995,33 +30615,57 @@ var REFERENCE_TYPES = {
|
|
|
29995
30615
|
const createReport = async (referenceType, referenceId) => {
|
|
29996
30616
|
const client = getActiveClient();
|
|
29997
30617
|
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
|
-
}
|
|
30618
|
+
if (referenceType === 'user') {
|
|
30619
|
+
return createUserReport({ client, referenceId });
|
|
30020
30620
|
}
|
|
30021
|
-
|
|
30022
|
-
|
|
30621
|
+
if (referenceType === 'message') {
|
|
30622
|
+
return createMessageReport({ client, referenceId });
|
|
30623
|
+
}
|
|
30624
|
+
if (referenceType === 'post') {
|
|
30625
|
+
return createPostReport({ client, referenceId });
|
|
30626
|
+
}
|
|
30627
|
+
if (referenceType === 'comment') {
|
|
30628
|
+
return createCommentReport({ client, referenceId });
|
|
30629
|
+
}
|
|
30630
|
+
return false;
|
|
30023
30631
|
};
|
|
30024
30632
|
|
|
30633
|
+
const deleteMessageReport = async ({ client, referenceId, }) => {
|
|
30634
|
+
const { data: payload } = await client.http.delete(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
30635
|
+
if (client.cache) {
|
|
30636
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
30637
|
+
ingestInCache(messagePayload);
|
|
30638
|
+
}
|
|
30639
|
+
fireEvent(`message.unflagged`, payload);
|
|
30640
|
+
return !!payload;
|
|
30641
|
+
};
|
|
30642
|
+
const deletePostReport = async ({ client, referenceId, }) => {
|
|
30643
|
+
const { data: payload } = await client.http.delete(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
|
|
30644
|
+
if (client.cache) {
|
|
30645
|
+
const postPayload = await preparePostPayload(payload);
|
|
30646
|
+
ingestInCache(postPayload);
|
|
30647
|
+
}
|
|
30648
|
+
fireEvent(`post.unflagged`, payload);
|
|
30649
|
+
return !!payload;
|
|
30650
|
+
};
|
|
30651
|
+
const deleteUserReport = async ({ client, referenceId, }) => {
|
|
30652
|
+
const { data: payload } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(referenceId)}`);
|
|
30653
|
+
if (client.cache) {
|
|
30654
|
+
const userPayload = await prepareUserPayload(payload);
|
|
30655
|
+
ingestInCache(userPayload);
|
|
30656
|
+
}
|
|
30657
|
+
fireEvent(`user.unflagged`, payload);
|
|
30658
|
+
return !!payload;
|
|
30659
|
+
};
|
|
30660
|
+
const deleteCommentReport = async ({ client, referenceId, }) => {
|
|
30661
|
+
const { data: payload } = await client.http.delete(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
|
|
30662
|
+
if (client.cache) {
|
|
30663
|
+
const commentPayload = await prepareCommentPayload(payload);
|
|
30664
|
+
ingestInCache(commentPayload);
|
|
30665
|
+
}
|
|
30666
|
+
fireEvent(`comment.unflagged`, payload);
|
|
30667
|
+
return !!payload;
|
|
30668
|
+
};
|
|
30025
30669
|
/**
|
|
30026
30670
|
* ```js
|
|
30027
30671
|
* import { deleteReport } from '@amityco/ts-sdk-react-native'
|
|
@@ -30038,34 +30682,45 @@ const createReport = async (referenceType, referenceId) => {
|
|
|
30038
30682
|
const deleteReport = async (referenceType, referenceId) => {
|
|
30039
30683
|
const client = getActiveClient();
|
|
30040
30684
|
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
|
-
}
|
|
30685
|
+
if (referenceType === 'user') {
|
|
30686
|
+
return deleteUserReport({ client, referenceId });
|
|
30063
30687
|
}
|
|
30064
|
-
|
|
30065
|
-
|
|
30066
|
-
|
|
30688
|
+
if (referenceType === 'message') {
|
|
30689
|
+
return deleteMessageReport({ client, referenceId });
|
|
30690
|
+
}
|
|
30691
|
+
if (referenceType === 'post') {
|
|
30692
|
+
return deletePostReport({ client, referenceId });
|
|
30693
|
+
}
|
|
30694
|
+
if (referenceType === 'comment') {
|
|
30695
|
+
return deleteCommentReport({ client, referenceId });
|
|
30696
|
+
}
|
|
30697
|
+
return false;
|
|
30067
30698
|
};
|
|
30068
30699
|
|
|
30700
|
+
const getMessageReport = async ({ client, referenceId, }) => {
|
|
30701
|
+
var _a;
|
|
30702
|
+
const { data } = await client.http.get(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
30703
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
30704
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
30705
|
+
};
|
|
30706
|
+
const getPostReport = async ({ client, referenceId, }) => {
|
|
30707
|
+
var _a;
|
|
30708
|
+
const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
|
|
30709
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
30710
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
30711
|
+
};
|
|
30712
|
+
const getUserReport = async ({ client, referenceId, }) => {
|
|
30713
|
+
var _a;
|
|
30714
|
+
const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
|
|
30715
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
30716
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
30717
|
+
};
|
|
30718
|
+
const getCommentReport = async ({ client, referenceId, }) => {
|
|
30719
|
+
var _a;
|
|
30720
|
+
const { data } = await client.http.get(`/api/v3/comment/${referenceId}/isflagbyme`);
|
|
30721
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
30722
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
30723
|
+
};
|
|
30069
30724
|
/**
|
|
30070
30725
|
* ```js
|
|
30071
30726
|
* import { isReportedByMe } from '@amityco/ts-sdk-react-native'
|
|
@@ -30080,17 +30735,21 @@ const deleteReport = async (referenceType, referenceId) => {
|
|
|
30080
30735
|
* @async
|
|
30081
30736
|
* */
|
|
30082
30737
|
const isReportedByMe = async (referenceType, referenceId) => {
|
|
30083
|
-
var _a;
|
|
30084
30738
|
const client = getActiveClient();
|
|
30085
30739
|
client.log('report/isReportedByMe', { referenceType, referenceId });
|
|
30086
|
-
|
|
30740
|
+
if (referenceType === 'user') {
|
|
30741
|
+
return getUserReport({ client, referenceId });
|
|
30742
|
+
}
|
|
30087
30743
|
if (referenceType === 'message') {
|
|
30088
|
-
|
|
30089
|
-
return data.result;
|
|
30744
|
+
return getMessageReport({ client, referenceId });
|
|
30090
30745
|
}
|
|
30091
|
-
|
|
30092
|
-
|
|
30093
|
-
|
|
30746
|
+
if (referenceType === 'post') {
|
|
30747
|
+
return getPostReport({ client, referenceId });
|
|
30748
|
+
}
|
|
30749
|
+
if (referenceType === 'comment') {
|
|
30750
|
+
return getCommentReport({ client, referenceId });
|
|
30751
|
+
}
|
|
30752
|
+
return false;
|
|
30094
30753
|
};
|
|
30095
30754
|
|
|
30096
30755
|
/* begin_public_function
|
|
@@ -31611,116 +32270,6 @@ const getMessage$1 = (messageId, callback) => {
|
|
|
31611
32270
|
};
|
|
31612
32271
|
/* end_public_function */
|
|
31613
32272
|
|
|
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
32273
|
/* eslint-disable no-use-before-define */
|
|
31725
32274
|
class MessageQueryStreamController extends QueryStreamController {
|
|
31726
32275
|
constructor(query, cacheKey, notifyChange, preparePayload, paginationController) {
|
|
@@ -31803,51 +32352,6 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
31803
32352
|
}
|
|
31804
32353
|
}
|
|
31805
32354
|
|
|
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
32355
|
/* eslint-disable no-use-before-define */
|
|
31852
32356
|
/**
|
|
31853
32357
|
* TODO: handle cache receive cache option, and cache policy
|
|
@@ -33639,10 +34143,12 @@ const removeMembers$1 = async (channelId, userIds) => {
|
|
|
33639
34143
|
*/
|
|
33640
34144
|
class ChannelMemberPaginationController extends PaginationController {
|
|
33641
34145
|
async getRequest(queryParams, token) {
|
|
33642
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
34146
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
33643
34147
|
const options = token ? { token } : { limit };
|
|
34148
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
33644
34149
|
const { data: queryResponse } = await this.http.get(`/api/v4/channels/${encodeURIComponent(params.channelId)}/users`, {
|
|
33645
|
-
params: Object.assign(Object.assign({}, params), { options
|
|
34150
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
34151
|
+
isDeleted }),
|
|
33646
34152
|
});
|
|
33647
34153
|
return queryResponse;
|
|
33648
34154
|
}
|
|
@@ -33708,6 +34214,33 @@ class ChannelMemberQueryStreamController extends QueryStreamController {
|
|
|
33708
34214
|
}
|
|
33709
34215
|
}
|
|
33710
34216
|
|
|
34217
|
+
const onUserDeleted$1 = (channelId) => (callback) => {
|
|
34218
|
+
const client = getActiveClient();
|
|
34219
|
+
const filter = (payload) => {
|
|
34220
|
+
var _a, _b;
|
|
34221
|
+
const userPayload = prepareUserPayload(payload);
|
|
34222
|
+
if (userPayload.users.length === 0)
|
|
34223
|
+
return;
|
|
34224
|
+
const user = userPayload.users[0];
|
|
34225
|
+
ingestInCache(userPayload);
|
|
34226
|
+
const channelUserCacheKey = getResolver('channelUsers')({
|
|
34227
|
+
channelId,
|
|
34228
|
+
userId: user.userId,
|
|
34229
|
+
});
|
|
34230
|
+
const cacheData = (_a = pullFromCache([
|
|
34231
|
+
'channelUsers',
|
|
34232
|
+
'get',
|
|
34233
|
+
channelUserCacheKey,
|
|
34234
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
34235
|
+
upsertInCache(['channelUsers', 'get', channelUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
|
|
34236
|
+
const channel = (_b = pullFromCache(['channel', 'get', channelId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
34237
|
+
if (!channel)
|
|
34238
|
+
return;
|
|
34239
|
+
callback(channel, cacheData);
|
|
34240
|
+
};
|
|
34241
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
34242
|
+
};
|
|
34243
|
+
|
|
33711
34244
|
/* eslint-disable no-use-before-define */
|
|
33712
34245
|
class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
33713
34246
|
constructor(query, callback) {
|
|
@@ -33746,6 +34279,7 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
33746
34279
|
{ fn: onChannelMemberUnbanned, action: 'onChannelMemberUnbanned' },
|
|
33747
34280
|
{ fn: onChannelMemberRoleAdded, action: 'onChannelMemberRoleAdded' },
|
|
33748
34281
|
{ fn: onChannelMemberRoleRemoved, action: 'onChannelMemberRoleRemoved' },
|
|
34282
|
+
{ fn: onUserDeleted$1(this.query.channelId), action: 'onChannelMemberChanged' },
|
|
33749
34283
|
]);
|
|
33750
34284
|
}
|
|
33751
34285
|
notifyChange({ origin, loading, error }) {
|
|
@@ -33792,6 +34326,9 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
33792
34326
|
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
34327
|
channelMembers = filterBySearchTerm(channelMembers, this.query.search);
|
|
33794
34328
|
}
|
|
34329
|
+
if (this.query.includeDeleted === false) {
|
|
34330
|
+
channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted) !== true; });
|
|
34331
|
+
}
|
|
33795
34332
|
// sort, 'lastCreated' is the default sort order
|
|
33796
34333
|
const sortBy = this.query.sortBy ? this.query.sortBy : 'lastCreated';
|
|
33797
34334
|
channelMembers = channelMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
@@ -34159,57 +34696,6 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
34159
34696
|
});
|
|
34160
34697
|
};
|
|
34161
34698
|
|
|
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
34699
|
/**
|
|
34214
34700
|
* ```js
|
|
34215
34701
|
* import { getCommunities } from '@amityco/ts-sdk-react-native'
|
|
@@ -34645,10 +35131,6 @@ const onCommunityUpdated = (callback) => createCommunityEventSubscriber('communi
|
|
|
34645
35131
|
*/
|
|
34646
35132
|
const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
|
|
34647
35133
|
|
|
34648
|
-
function isNonNullable(value) {
|
|
34649
|
-
return value != null;
|
|
34650
|
-
}
|
|
34651
|
-
|
|
34652
35134
|
function hasPermission(member, payload, permission) {
|
|
34653
35135
|
if (member.permissions.some(x => x === permission)) {
|
|
34654
35136
|
return true;
|
|
@@ -34663,7 +35145,7 @@ function getEventRelatedMember(event, payload) {
|
|
|
34663
35145
|
}
|
|
34664
35146
|
// NOTE: backend returns the one who took the action and the one on whom
|
|
34665
35147
|
// the action was taken. We need the 2nd one
|
|
34666
|
-
if (event === 'community.userRemoved') {
|
|
35148
|
+
if (event === 'community.userRemoved' || event === 'local.community.userRemoved') {
|
|
34667
35149
|
return payload.communityUsers.filter(x => x.communityMembership === 'none');
|
|
34668
35150
|
}
|
|
34669
35151
|
if (event === 'community.userBanned') {
|
|
@@ -34711,6 +35193,43 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
|
|
|
34711
35193
|
}
|
|
34712
35194
|
};
|
|
34713
35195
|
return createEventSubscriber(client, event, event, filter);
|
|
35196
|
+
};
|
|
35197
|
+
const createLocalCommunityMemberEventSubscriber = (event, callback) => {
|
|
35198
|
+
const client = getActiveClient();
|
|
35199
|
+
const filter = (payload) => {
|
|
35200
|
+
const preparedPayload = prepareCommunityPayload(payload);
|
|
35201
|
+
const { communities, communityUsers } = preparedPayload;
|
|
35202
|
+
/*
|
|
35203
|
+
* community.isJoined is not part of the communityMembership payload, and needs
|
|
35204
|
+
* to be calculated based on the communityMembership value
|
|
35205
|
+
*/
|
|
35206
|
+
const communitiesWithMembership = updateMembershipStatus(communities, communityUsers);
|
|
35207
|
+
preparedPayload.communities = communitiesWithMembership;
|
|
35208
|
+
if (!client.cache) {
|
|
35209
|
+
// TODO: here we are missing specific properties here!
|
|
35210
|
+
callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
|
|
35211
|
+
}
|
|
35212
|
+
else {
|
|
35213
|
+
ingestInCache(preparedPayload);
|
|
35214
|
+
const community = pullFromCache([
|
|
35215
|
+
'community',
|
|
35216
|
+
'get',
|
|
35217
|
+
preparedPayload.communities[0].communityId,
|
|
35218
|
+
]);
|
|
35219
|
+
const members = getEventRelatedMember(event, preparedPayload)
|
|
35220
|
+
.map(member => {
|
|
35221
|
+
const memberCache = pullFromCache([
|
|
35222
|
+
'communityUsers',
|
|
35223
|
+
'get',
|
|
35224
|
+
getResolver('communityUsers')(member),
|
|
35225
|
+
]);
|
|
35226
|
+
return memberCache === null || memberCache === void 0 ? void 0 : memberCache.data;
|
|
35227
|
+
})
|
|
35228
|
+
.filter(isNonNullable);
|
|
35229
|
+
callback(community.data, members);
|
|
35230
|
+
}
|
|
35231
|
+
};
|
|
35232
|
+
return createEventSubscriber(client, event, event, filter);
|
|
34714
35233
|
};
|
|
34715
35234
|
|
|
34716
35235
|
/**
|
|
@@ -34832,6 +35351,40 @@ const onCommunityUserRoleAdded = (callback) => createCommunityMemberEventSubscri
|
|
|
34832
35351
|
*/
|
|
34833
35352
|
const onCommunityUserRoleRemoved = (callback) => createCommunityMemberEventSubscriber('community.roleRemoved', callback);
|
|
34834
35353
|
|
|
35354
|
+
/**
|
|
35355
|
+
* ```js
|
|
35356
|
+
* import { onLocalCommunityUserAdded } from '@amityco/ts-sdk-react-native'
|
|
35357
|
+
* const dispose = onLocalCommunityUserAdded((community, member) => {
|
|
35358
|
+
* // ...
|
|
35359
|
+
* })
|
|
35360
|
+
* ```
|
|
35361
|
+
*
|
|
35362
|
+
* Fired when a user has been added to a {@link Amity.Community}
|
|
35363
|
+
*
|
|
35364
|
+
* @param callback The function to call when the event was fired
|
|
35365
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35366
|
+
*
|
|
35367
|
+
* @category Community Events
|
|
35368
|
+
*/
|
|
35369
|
+
const onLocalCommunityUserAdded = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userAdded', callback);
|
|
35370
|
+
|
|
35371
|
+
/**
|
|
35372
|
+
* ```js
|
|
35373
|
+
* import { onLocalCommunityUserRemoved } from '@amityco/ts-sdk-react-native'
|
|
35374
|
+
* const dispose = onLocalCommunityUserRemoved((community, member) => {
|
|
35375
|
+
* // ...
|
|
35376
|
+
* })
|
|
35377
|
+
* ```
|
|
35378
|
+
*
|
|
35379
|
+
* Fired when a user has been removed from a {@link Amity.Community}
|
|
35380
|
+
*
|
|
35381
|
+
* @param callback The function to call when the event was fired
|
|
35382
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35383
|
+
*
|
|
35384
|
+
* @category Community Events
|
|
35385
|
+
*/
|
|
35386
|
+
const onLocalCommunityUserRemoved = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userRemoved', callback);
|
|
35387
|
+
|
|
34835
35388
|
/**
|
|
34836
35389
|
* ```js
|
|
34837
35390
|
* import { onCommunityJoined } from '@amityco/ts-sdk-react-native'
|
|
@@ -34984,6 +35537,9 @@ var EnumCommunityMemberActions$1;
|
|
|
34984
35537
|
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
34985
35538
|
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
34986
35539
|
EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
|
|
35540
|
+
EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
|
|
35541
|
+
EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
|
|
35542
|
+
EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
|
|
34987
35543
|
})(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
|
|
34988
35544
|
|
|
34989
35545
|
/* begin_public_function
|
|
@@ -35008,7 +35564,7 @@ const addMembers = async (communityId, userIds) => {
|
|
|
35008
35564
|
const client = getActiveClient();
|
|
35009
35565
|
client.log('community/moderation/addMembers', communityId, userIds);
|
|
35010
35566
|
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
35011
|
-
fireEvent('community.userAdded', payload);
|
|
35567
|
+
fireEvent('local.community.userAdded', payload);
|
|
35012
35568
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
35013
35569
|
if (client.cache)
|
|
35014
35570
|
ingestInCache(data);
|
|
@@ -35039,7 +35595,7 @@ const removeMembers = async (communityId, userIds) => {
|
|
|
35039
35595
|
const client = getActiveClient();
|
|
35040
35596
|
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
35041
35597
|
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
35042
|
-
fireEvent('community.userRemoved', payload);
|
|
35598
|
+
fireEvent('local.community.userRemoved', payload);
|
|
35043
35599
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
35044
35600
|
if (client.cache)
|
|
35045
35601
|
ingestInCache(data);
|
|
@@ -35054,10 +35610,12 @@ const removeMembers = async (communityId, userIds) => {
|
|
|
35054
35610
|
*/
|
|
35055
35611
|
class CommunityMembersPaginationController extends PaginationController {
|
|
35056
35612
|
async getRequest(queryParams, token) {
|
|
35057
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35613
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
35058
35614
|
const options = token ? { token } : { limit };
|
|
35615
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
35059
35616
|
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
35060
|
-
params: Object.assign(Object.assign({}, params), { options
|
|
35617
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
35618
|
+
isDeleted }),
|
|
35061
35619
|
});
|
|
35062
35620
|
return queryResponse;
|
|
35063
35621
|
}
|
|
@@ -35126,6 +35684,96 @@ class CommunityMembersQueryStreamController extends QueryStreamController {
|
|
|
35126
35684
|
}
|
|
35127
35685
|
}
|
|
35128
35686
|
|
|
35687
|
+
/**
|
|
35688
|
+
* ```js
|
|
35689
|
+
* import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk-react-native'
|
|
35690
|
+
* const dispose = onLocalCommunityRoleRemoved((community, member) => {
|
|
35691
|
+
* // ...
|
|
35692
|
+
* })
|
|
35693
|
+
* ```
|
|
35694
|
+
*
|
|
35695
|
+
* Fired when any {@link Amity.communityUsers} 's role has been added to any {@link Amity.Community}
|
|
35696
|
+
*
|
|
35697
|
+
* @param callback The function to call when the event was fired
|
|
35698
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35699
|
+
*
|
|
35700
|
+
* @category Community Events
|
|
35701
|
+
*/
|
|
35702
|
+
const onLocalCommunityRoleRemoved = (callback) => {
|
|
35703
|
+
const client = getActiveClient();
|
|
35704
|
+
const filter = async (payload) => {
|
|
35705
|
+
const { communities, communityUsers } = payload;
|
|
35706
|
+
callback(communities[0], communityUsers.filter(communityUser => communityUser.communityMembership === 'member'));
|
|
35707
|
+
};
|
|
35708
|
+
return createEventSubscriber(client, 'onLocalCommunityRoleRemoved', 'local.community.roleRemoved', filter);
|
|
35709
|
+
};
|
|
35710
|
+
|
|
35711
|
+
/**
|
|
35712
|
+
* ```js
|
|
35713
|
+
* import { onLocalCommunityRoleAdded } from '@amityco/ts-sdk-react-native'
|
|
35714
|
+
* const dispose = onLocalCommunityRoleAdded((community, member) => {
|
|
35715
|
+
* // ...
|
|
35716
|
+
* })
|
|
35717
|
+
* ```
|
|
35718
|
+
*
|
|
35719
|
+
* Fired when any {@link Amity.communityUsers} 's role has been added to any {@link Amity.Community}
|
|
35720
|
+
*
|
|
35721
|
+
* @param callback The function to call when the event was fired
|
|
35722
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35723
|
+
*
|
|
35724
|
+
* @category Community Events
|
|
35725
|
+
*/
|
|
35726
|
+
const onLocalCommunityRoleAdded = (callback) => {
|
|
35727
|
+
const client = getActiveClient();
|
|
35728
|
+
const filter = async (payload) => {
|
|
35729
|
+
const { communities, communityUsers } = payload;
|
|
35730
|
+
callback(communities[0], communityUsers.filter(communityUser => communityUser.communityMembership === 'member'));
|
|
35731
|
+
};
|
|
35732
|
+
return createEventSubscriber(client, 'onLocalCommunityRoleAdded', 'local.community.roleAdded', filter);
|
|
35733
|
+
};
|
|
35734
|
+
|
|
35735
|
+
/**
|
|
35736
|
+
* ```js
|
|
35737
|
+
* import { onUserDeleted } from '@amityco/ts-sdk-react-native'
|
|
35738
|
+
* const dispose = onUserDeleted((community, member) => {
|
|
35739
|
+
* // ...
|
|
35740
|
+
* })
|
|
35741
|
+
* ```
|
|
35742
|
+
*
|
|
35743
|
+
* Fired when a {@link Amity.Community} has been joined
|
|
35744
|
+
*
|
|
35745
|
+
* @param callback The function to call when the event was fired
|
|
35746
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
35747
|
+
*
|
|
35748
|
+
* @category Community Events
|
|
35749
|
+
*/
|
|
35750
|
+
const onUserDeleted = (communityId) => (callback) => {
|
|
35751
|
+
const client = getActiveClient();
|
|
35752
|
+
const filter = (payload) => {
|
|
35753
|
+
var _a, _b;
|
|
35754
|
+
const userPayload = prepareUserPayload(payload);
|
|
35755
|
+
if (userPayload.users.length === 0)
|
|
35756
|
+
return;
|
|
35757
|
+
const user = userPayload.users[0];
|
|
35758
|
+
ingestInCache(userPayload);
|
|
35759
|
+
const communityUserCacheKey = getResolver('communityUsers')({
|
|
35760
|
+
communityId,
|
|
35761
|
+
userId: user.userId,
|
|
35762
|
+
});
|
|
35763
|
+
const cacheData = (_a = pullFromCache([
|
|
35764
|
+
'communityUsers',
|
|
35765
|
+
'get',
|
|
35766
|
+
communityUserCacheKey,
|
|
35767
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
35768
|
+
pushToCache(['communityUsers', 'get', communityUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
|
|
35769
|
+
const community = (_b = pullFromCache(['community', 'get', communityId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
35770
|
+
callback(community, [
|
|
35771
|
+
Object.assign(Object.assign({}, cacheData), { user }),
|
|
35772
|
+
]);
|
|
35773
|
+
};
|
|
35774
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
35775
|
+
};
|
|
35776
|
+
|
|
35129
35777
|
class CommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
35130
35778
|
constructor(query, callback) {
|
|
35131
35779
|
const queryStreamId = hash(query);
|
|
@@ -35164,7 +35812,274 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
35164
35812
|
fn: onCommunityUserRoleRemoved,
|
|
35165
35813
|
action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
|
|
35166
35814
|
},
|
|
35815
|
+
{
|
|
35816
|
+
fn: onLocalCommunityRoleAdded,
|
|
35817
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserRoleAdded,
|
|
35818
|
+
},
|
|
35819
|
+
{
|
|
35820
|
+
fn: onLocalCommunityRoleRemoved,
|
|
35821
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
|
|
35822
|
+
},
|
|
35167
35823
|
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions$1.OnCommunityUserUnbanned },
|
|
35824
|
+
{ fn: onLocalCommunityUserAdded, action: EnumCommunityMemberActions$1.OnCommunityUserAdded },
|
|
35825
|
+
{
|
|
35826
|
+
fn: onLocalCommunityUserRemoved,
|
|
35827
|
+
action: EnumCommunityMemberActions$1.onCommunityUserRemoved,
|
|
35828
|
+
},
|
|
35829
|
+
{
|
|
35830
|
+
fn: onUserDeleted(this.query.communityId),
|
|
35831
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserChanged,
|
|
35832
|
+
},
|
|
35833
|
+
]);
|
|
35834
|
+
}
|
|
35835
|
+
notifyChange({ origin, loading, error }) {
|
|
35836
|
+
var _a, _b;
|
|
35837
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35838
|
+
if (!collection)
|
|
35839
|
+
return;
|
|
35840
|
+
const data = this.applyFilter((_b = collection.data
|
|
35841
|
+
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
35842
|
+
.filter(isNonNullable)
|
|
35843
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
35844
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
35845
|
+
return;
|
|
35846
|
+
this.callback({
|
|
35847
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
35848
|
+
data,
|
|
35849
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
35850
|
+
loading,
|
|
35851
|
+
error,
|
|
35852
|
+
});
|
|
35853
|
+
}
|
|
35854
|
+
applyFilter(data) {
|
|
35855
|
+
let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
|
|
35856
|
+
if (this.query.memberships) {
|
|
35857
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
35858
|
+
const memberships = this.query.memberships || [];
|
|
35859
|
+
return memberships.includes(communityMembership);
|
|
35860
|
+
});
|
|
35861
|
+
}
|
|
35862
|
+
if (this.query.search) {
|
|
35863
|
+
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
35864
|
+
}
|
|
35865
|
+
if (this.query.includeDeleted === false) {
|
|
35866
|
+
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
|
|
35867
|
+
}
|
|
35868
|
+
switch (this.query.sortBy) {
|
|
35869
|
+
case 'firstCreated':
|
|
35870
|
+
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
35871
|
+
break;
|
|
35872
|
+
case 'displayName':
|
|
35873
|
+
communityMembers = communityMembers.sort((a, b) => {
|
|
35874
|
+
var _a, _b, _c, _d;
|
|
35875
|
+
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)) {
|
|
35876
|
+
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);
|
|
35877
|
+
}
|
|
35878
|
+
return 0;
|
|
35879
|
+
});
|
|
35880
|
+
break;
|
|
35881
|
+
case 'lastCreated':
|
|
35882
|
+
default:
|
|
35883
|
+
communityMembers = communityMembers.sort(sortByLastCreated);
|
|
35884
|
+
break;
|
|
35885
|
+
}
|
|
35886
|
+
return communityMembers;
|
|
35887
|
+
}
|
|
35888
|
+
}
|
|
35889
|
+
|
|
35890
|
+
/*
|
|
35891
|
+
* Exported for testing
|
|
35892
|
+
* @hidden
|
|
35893
|
+
*/
|
|
35894
|
+
const applyFilter = (data, params) => {
|
|
35895
|
+
let communityMembers = filterByPropIntersection(data, 'roles', params.roles);
|
|
35896
|
+
if (params.memberships) {
|
|
35897
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
35898
|
+
const membership = params.memberships;
|
|
35899
|
+
return membership.includes(communityMembership);
|
|
35900
|
+
});
|
|
35901
|
+
}
|
|
35902
|
+
if (params.search) {
|
|
35903
|
+
communityMembers = filterBySearchTerm(communityMembers, params.search);
|
|
35904
|
+
}
|
|
35905
|
+
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
35906
|
+
communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
35907
|
+
return communityMembers;
|
|
35908
|
+
};
|
|
35909
|
+
/* begin_public_function
|
|
35910
|
+
id: community.membership.query
|
|
35911
|
+
*/
|
|
35912
|
+
/**
|
|
35913
|
+
* ```js
|
|
35914
|
+
* import { getMembers } from '@amityco/ts-sdk-react-native'
|
|
35915
|
+
*
|
|
35916
|
+
* let communityMembers = []
|
|
35917
|
+
* const unsub = getMembers({
|
|
35918
|
+
* communityId: Amity.Community['communityId'],
|
|
35919
|
+
* }, response => merge(communityMembers, response.data))
|
|
35920
|
+
* ```
|
|
35921
|
+
*
|
|
35922
|
+
* Observe all mutations on a list of {@link Amity.CommunityUser}s
|
|
35923
|
+
*
|
|
35924
|
+
* @param params for querying community users
|
|
35925
|
+
* @param callback the function to call when new data are available
|
|
35926
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community users
|
|
35927
|
+
*
|
|
35928
|
+
* @category Community Live Collection
|
|
35929
|
+
*/
|
|
35930
|
+
const getMembers = (params, callback, config) => {
|
|
35931
|
+
const { log, cache } = getActiveClient();
|
|
35932
|
+
if (!cache) {
|
|
35933
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
35934
|
+
}
|
|
35935
|
+
const timestamp = Date.now();
|
|
35936
|
+
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
35937
|
+
const communityMemberLiveCollection = new CommunityMembersLiveCollectionController(params, resp => {
|
|
35938
|
+
callback(resp);
|
|
35939
|
+
});
|
|
35940
|
+
const disposers = communityMemberLiveCollection.startSubscription();
|
|
35941
|
+
const cacheKey = communityMemberLiveCollection.getCacheKey();
|
|
35942
|
+
disposers.push(() => {
|
|
35943
|
+
dropFromCache(cacheKey);
|
|
35944
|
+
});
|
|
35945
|
+
return () => {
|
|
35946
|
+
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
35947
|
+
disposers.forEach(fn => fn());
|
|
35948
|
+
};
|
|
35949
|
+
};
|
|
35950
|
+
/* end_public_function */
|
|
35951
|
+
|
|
35952
|
+
/**
|
|
35953
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
35954
|
+
* TODO: check if querybyIds is supported
|
|
35955
|
+
*/
|
|
35956
|
+
class SearchCommunityMembersPaginationController extends PaginationController {
|
|
35957
|
+
async getRequest(queryParams, token) {
|
|
35958
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
35959
|
+
const options = token ? { token } : { limit };
|
|
35960
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
35961
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
35962
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
35963
|
+
isDeleted }),
|
|
35964
|
+
});
|
|
35965
|
+
return queryResponse;
|
|
35966
|
+
}
|
|
35967
|
+
}
|
|
35968
|
+
|
|
35969
|
+
class SearchCommunityMembersQueryStreamController extends QueryStreamController {
|
|
35970
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
35971
|
+
super(query, cacheKey);
|
|
35972
|
+
this.notifyChange = notifyChange;
|
|
35973
|
+
this.preparePayload = preparePayload;
|
|
35974
|
+
}
|
|
35975
|
+
async saveToMainDB(response) {
|
|
35976
|
+
const processedPayload = await this.preparePayload(response);
|
|
35977
|
+
const client = getActiveClient();
|
|
35978
|
+
const cachedAt = client.cache && Date.now();
|
|
35979
|
+
if (client.cache) {
|
|
35980
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
35981
|
+
}
|
|
35982
|
+
}
|
|
35983
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
35984
|
+
var _a, _b;
|
|
35985
|
+
if (refresh) {
|
|
35986
|
+
pushToCache(this.cacheKey, {
|
|
35987
|
+
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
35988
|
+
});
|
|
35989
|
+
}
|
|
35990
|
+
else {
|
|
35991
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35992
|
+
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
35993
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
35994
|
+
...new Set([
|
|
35995
|
+
...communityUsers,
|
|
35996
|
+
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
35997
|
+
]),
|
|
35998
|
+
] }));
|
|
35999
|
+
}
|
|
36000
|
+
}
|
|
36001
|
+
reactor(action) {
|
|
36002
|
+
return (community, communityMembers) => {
|
|
36003
|
+
var _a;
|
|
36004
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36005
|
+
if (!collection)
|
|
36006
|
+
return;
|
|
36007
|
+
communityMembers.forEach(communityMember => {
|
|
36008
|
+
const communityMemberCacheId = getResolver('communityUsers')({
|
|
36009
|
+
communityId: this.query.communityId,
|
|
36010
|
+
userId: communityMember.userId,
|
|
36011
|
+
});
|
|
36012
|
+
if (communityMember.communityMembership === 'none') {
|
|
36013
|
+
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
36014
|
+
}
|
|
36015
|
+
});
|
|
36016
|
+
pushToCache(this.cacheKey, collection);
|
|
36017
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
36018
|
+
};
|
|
36019
|
+
}
|
|
36020
|
+
subscribeRTE(createSubscriber) {
|
|
36021
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
36022
|
+
}
|
|
36023
|
+
}
|
|
36024
|
+
|
|
36025
|
+
var EnumCommunityMemberActions;
|
|
36026
|
+
(function (EnumCommunityMemberActions) {
|
|
36027
|
+
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
36028
|
+
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
36029
|
+
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
36030
|
+
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
36031
|
+
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
36032
|
+
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
36033
|
+
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
36034
|
+
})(EnumCommunityMemberActions || (EnumCommunityMemberActions = {}));
|
|
36035
|
+
|
|
36036
|
+
/* eslint-disable no-use-before-define */
|
|
36037
|
+
class SearchCommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
36038
|
+
constructor(query, callback) {
|
|
36039
|
+
const queryStreamId = hash(query);
|
|
36040
|
+
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
36041
|
+
const paginationController = new SearchCommunityMembersPaginationController(query);
|
|
36042
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
36043
|
+
this.query = query;
|
|
36044
|
+
this.queryStreamController = new SearchCommunityMembersQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
36045
|
+
this.callback = callback.bind(this);
|
|
36046
|
+
this.loadPage({ initial: true });
|
|
36047
|
+
}
|
|
36048
|
+
setup() {
|
|
36049
|
+
var _a;
|
|
36050
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36051
|
+
if (!collection) {
|
|
36052
|
+
pushToCache(this.cacheKey, {
|
|
36053
|
+
data: [],
|
|
36054
|
+
params: {},
|
|
36055
|
+
});
|
|
36056
|
+
}
|
|
36057
|
+
}
|
|
36058
|
+
async persistModel(queryPayload) {
|
|
36059
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
36060
|
+
}
|
|
36061
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
36062
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
36063
|
+
}
|
|
36064
|
+
startSubscription() {
|
|
36065
|
+
return this.queryStreamController.subscribeRTE([
|
|
36066
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
36067
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
36068
|
+
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
36069
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
36070
|
+
{
|
|
36071
|
+
fn: onLocalCommunityRoleRemoved,
|
|
36072
|
+
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
36073
|
+
},
|
|
36074
|
+
{
|
|
36075
|
+
fn: onCommunityUserRoleRemoved,
|
|
36076
|
+
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
36077
|
+
},
|
|
36078
|
+
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
|
|
36079
|
+
{
|
|
36080
|
+
fn: onUserDeleted(this.query.communityId),
|
|
36081
|
+
action: EnumCommunityMemberActions.OnCommunityUserChanged,
|
|
36082
|
+
},
|
|
35168
36083
|
]);
|
|
35169
36084
|
}
|
|
35170
36085
|
notifyChange({ origin, loading, error }) {
|
|
@@ -35197,242 +36112,8 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
35197
36112
|
if (this.query.search) {
|
|
35198
36113
|
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
35199
36114
|
}
|
|
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);
|
|
36115
|
+
if (this.query.includeDeleted === false) {
|
|
36116
|
+
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
|
|
35436
36117
|
}
|
|
35437
36118
|
return communityMembers;
|
|
35438
36119
|
}
|
|
@@ -35495,6 +36176,8 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
35495
36176
|
onCommunityUserUnbanned: onCommunityUserUnbanned,
|
|
35496
36177
|
onCommunityUserRoleAdded: onCommunityUserRoleAdded,
|
|
35497
36178
|
onCommunityUserRoleRemoved: onCommunityUserRoleRemoved,
|
|
36179
|
+
onLocalCommunityUserAdded: onLocalCommunityUserAdded,
|
|
36180
|
+
onLocalCommunityUserRemoved: onLocalCommunityUserRemoved,
|
|
35498
36181
|
onCommunityJoined: onCommunityJoined,
|
|
35499
36182
|
onCommunityLeft: onCommunityLeft
|
|
35500
36183
|
});
|
|
@@ -36151,9 +36834,10 @@ const addRoles = async (communityId, roleIds, userIds) => {
|
|
|
36151
36834
|
const client = getActiveClient();
|
|
36152
36835
|
client.log('community/moderation/addRoles', communityId, roleIds, userIds);
|
|
36153
36836
|
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/users/roles`, { communityId, roles: roleIds, userIds });
|
|
36154
|
-
const data =
|
|
36837
|
+
const data = prepareCommunityMembershipPayload(payload);
|
|
36155
36838
|
if (client.cache)
|
|
36156
36839
|
ingestInCache(data);
|
|
36840
|
+
fireEvent('local.community.roleAdded', data);
|
|
36157
36841
|
const { communityUsers } = data;
|
|
36158
36842
|
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
36159
36843
|
roleIds.some(role => communityUser.roles.includes(role)));
|
|
@@ -36183,9 +36867,10 @@ const removeRoles = async (communityId, roleIds, userIds) => {
|
|
|
36183
36867
|
const client = getActiveClient();
|
|
36184
36868
|
client.log('community/moderation/removeRoles', communityId, roleIds, userIds);
|
|
36185
36869
|
const { data: payload } = await client.http.delete(`/api/v4/communities/${communityId}/users/roles`, { data: { communityId, roles: roleIds, userIds } });
|
|
36186
|
-
const data =
|
|
36870
|
+
const data = prepareCommunityMembershipPayload(payload);
|
|
36187
36871
|
if (client.cache)
|
|
36188
36872
|
ingestInCache(data);
|
|
36873
|
+
fireEvent('local.community.roleRemoved', data);
|
|
36189
36874
|
const { communityUsers } = data;
|
|
36190
36875
|
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
36191
36876
|
!roleIds.some(role => communityUser.roles.includes(role)));
|
|
@@ -36872,7 +37557,7 @@ const updatePost = async (postId, patch) => {
|
|
|
36872
37557
|
const cachedAt = client.cache && Date.now();
|
|
36873
37558
|
if (client.cache)
|
|
36874
37559
|
ingestInCache(data, { cachedAt });
|
|
36875
|
-
fireEvent('local.post.updated',
|
|
37560
|
+
fireEvent('local.post.updated', payload);
|
|
36876
37561
|
const { posts } = data;
|
|
36877
37562
|
return {
|
|
36878
37563
|
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
@@ -36972,7 +37657,15 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
36972
37657
|
}
|
|
36973
37658
|
// to support hard deletion
|
|
36974
37659
|
const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
|
|
36975
|
-
|
|
37660
|
+
if (permanent) {
|
|
37661
|
+
setTimeout(() => {
|
|
37662
|
+
pushToTombstone('post', postId);
|
|
37663
|
+
}, 0);
|
|
37664
|
+
}
|
|
37665
|
+
else {
|
|
37666
|
+
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
37667
|
+
}
|
|
37668
|
+
fireEvent('local.post.deleted', {
|
|
36976
37669
|
posts: [deleted],
|
|
36977
37670
|
categories: [],
|
|
36978
37671
|
comments: [],
|
|
@@ -36983,14 +37676,6 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
36983
37676
|
postChildren: [],
|
|
36984
37677
|
users: [],
|
|
36985
37678
|
});
|
|
36986
|
-
if (permanent) {
|
|
36987
|
-
setTimeout(() => {
|
|
36988
|
-
pushToTombstone('post', postId);
|
|
36989
|
-
}, 0);
|
|
36990
|
-
}
|
|
36991
|
-
else {
|
|
36992
|
-
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
36993
|
-
}
|
|
36994
37679
|
return LinkedObject.post(deleted);
|
|
36995
37680
|
};
|
|
36996
37681
|
|
|
@@ -37378,6 +38063,7 @@ getCommentByIds.locally = (commentIds) => {
|
|
|
37378
38063
|
* @async
|
|
37379
38064
|
*/
|
|
37380
38065
|
const createComment = async (bundle) => {
|
|
38066
|
+
var _a;
|
|
37381
38067
|
const client = getActiveClient();
|
|
37382
38068
|
client.log('comment/createComment', bundle);
|
|
37383
38069
|
const { data } = await client.http.post('/api/v3/comments', bundle);
|
|
@@ -37389,18 +38075,21 @@ const createComment = async (bundle) => {
|
|
|
37389
38075
|
if (client.cache)
|
|
37390
38076
|
ingestInCache(data, { cachedAt });
|
|
37391
38077
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
37392
|
-
const post =
|
|
37393
|
-
|
|
37394
|
-
|
|
37395
|
-
|
|
37396
|
-
|
|
37397
|
-
|
|
37398
|
-
|
|
37399
|
-
|
|
37400
|
-
|
|
37401
|
-
|
|
37402
|
-
|
|
37403
|
-
|
|
38078
|
+
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
38079
|
+
if (post) {
|
|
38080
|
+
post.commentsCount += 1;
|
|
38081
|
+
fireEvent('local.post.updated', {
|
|
38082
|
+
posts: [post],
|
|
38083
|
+
categories: [],
|
|
38084
|
+
comments: [],
|
|
38085
|
+
communities: [],
|
|
38086
|
+
communityUsers: data.communityUsers,
|
|
38087
|
+
feeds: [],
|
|
38088
|
+
files: data.files,
|
|
38089
|
+
postChildren: [],
|
|
38090
|
+
users: data.users,
|
|
38091
|
+
});
|
|
38092
|
+
}
|
|
37404
38093
|
}
|
|
37405
38094
|
else if (bundle.referenceType === 'story') {
|
|
37406
38095
|
const storyIndex = pullFromCache([
|
|
@@ -37559,6 +38248,7 @@ getStoryByStoryId$1.locally = (storyId) => {
|
|
|
37559
38248
|
* @async
|
|
37560
38249
|
*/
|
|
37561
38250
|
const deleteComment = async (commentId, permanent = false) => {
|
|
38251
|
+
var _a;
|
|
37562
38252
|
const client = getActiveClient();
|
|
37563
38253
|
const comment = await getComment$2(commentId);
|
|
37564
38254
|
// API-FIX: This endpoint has not been implemented yet.
|
|
@@ -37583,18 +38273,28 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
37583
38273
|
});
|
|
37584
38274
|
}
|
|
37585
38275
|
else {
|
|
37586
|
-
const post =
|
|
37587
|
-
|
|
37588
|
-
|
|
37589
|
-
|
|
37590
|
-
|
|
37591
|
-
|
|
37592
|
-
|
|
37593
|
-
|
|
37594
|
-
|
|
37595
|
-
|
|
37596
|
-
|
|
37597
|
-
|
|
38276
|
+
const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
38277
|
+
if (post) {
|
|
38278
|
+
let removeCount;
|
|
38279
|
+
if (!deleted.parentId) {
|
|
38280
|
+
// NOTE: delete the parent comment will remove all children comments
|
|
38281
|
+
removeCount = deleted.childrenNumber + 1;
|
|
38282
|
+
}
|
|
38283
|
+
else
|
|
38284
|
+
removeCount = 1;
|
|
38285
|
+
post.commentsCount -= removeCount;
|
|
38286
|
+
fireEvent('local.post.updated', {
|
|
38287
|
+
posts: [post],
|
|
38288
|
+
categories: [],
|
|
38289
|
+
comments: [],
|
|
38290
|
+
communities: [],
|
|
38291
|
+
communityUsers: [],
|
|
38292
|
+
feeds: [],
|
|
38293
|
+
files: [],
|
|
38294
|
+
postChildren: [],
|
|
38295
|
+
users: [],
|
|
38296
|
+
});
|
|
38297
|
+
}
|
|
37598
38298
|
}
|
|
37599
38299
|
fireEvent('local.comment.deleted', {
|
|
37600
38300
|
comments: [deleted],
|
|
@@ -37860,6 +38560,81 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
|
37860
38560
|
};
|
|
37861
38561
|
};
|
|
37862
38562
|
|
|
38563
|
+
/**
|
|
38564
|
+
* ```js
|
|
38565
|
+
* import { onCommentDeleteLocal } from '@amityco/ts-sdk-react-native'
|
|
38566
|
+
* const dispose = onCommentDeleteLocal(comment => {
|
|
38567
|
+
* // ...
|
|
38568
|
+
* })
|
|
38569
|
+
* ```
|
|
38570
|
+
*
|
|
38571
|
+
* Fired when a {@link Amity.InternalComment} has been deleted
|
|
38572
|
+
*
|
|
38573
|
+
* @param callback The function to call when the event was fired
|
|
38574
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38575
|
+
*
|
|
38576
|
+
* @category Comment Events
|
|
38577
|
+
*/
|
|
38578
|
+
const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
|
|
38579
|
+
|
|
38580
|
+
/**
|
|
38581
|
+
* ```js
|
|
38582
|
+
* import { onLocalCommentReactionAdded } from '@amityco/ts-sdk-react-native'
|
|
38583
|
+
* const dispose = onLocalCommentReactionAdded(comment => {
|
|
38584
|
+
* // ...
|
|
38585
|
+
* })
|
|
38586
|
+
* ```
|
|
38587
|
+
*
|
|
38588
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
38589
|
+
*
|
|
38590
|
+
* @param callback The function to call when the event was fired
|
|
38591
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38592
|
+
*
|
|
38593
|
+
* @category Comment Events
|
|
38594
|
+
*/
|
|
38595
|
+
const onLocalCommentReactionAdded = (callback) => {
|
|
38596
|
+
const client = getActiveClient();
|
|
38597
|
+
const filter = ({ comment }) => {
|
|
38598
|
+
if (!client.cache) {
|
|
38599
|
+
callback(comment);
|
|
38600
|
+
}
|
|
38601
|
+
else {
|
|
38602
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
38603
|
+
callback(commentLinkedObject(comment));
|
|
38604
|
+
}
|
|
38605
|
+
};
|
|
38606
|
+
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
38607
|
+
};
|
|
38608
|
+
|
|
38609
|
+
/**
|
|
38610
|
+
* ```js
|
|
38611
|
+
* import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk-react-native'
|
|
38612
|
+
* const dispose = onLocalCommentReactionRemoved(comment => {
|
|
38613
|
+
* // ...
|
|
38614
|
+
* })
|
|
38615
|
+
* ```
|
|
38616
|
+
*
|
|
38617
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
38618
|
+
*
|
|
38619
|
+
* @param callback The function to call when the event was fired
|
|
38620
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38621
|
+
*
|
|
38622
|
+
* @category Comment Events
|
|
38623
|
+
*/
|
|
38624
|
+
const onLocalCommentReactionRemoved = (callback) => {
|
|
38625
|
+
const client = getActiveClient();
|
|
38626
|
+
const filter = ({ comment }) => {
|
|
38627
|
+
if (!client.cache) {
|
|
38628
|
+
callback(comment);
|
|
38629
|
+
}
|
|
38630
|
+
else {
|
|
38631
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
38632
|
+
callback(commentLinkedObject(comment));
|
|
38633
|
+
}
|
|
38634
|
+
};
|
|
38635
|
+
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
38636
|
+
};
|
|
38637
|
+
|
|
37863
38638
|
/* begin_public_function
|
|
37864
38639
|
id: comment.get
|
|
37865
38640
|
*/
|
|
@@ -37884,26 +38659,15 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
|
37884
38659
|
*/
|
|
37885
38660
|
const getComment = (commentId, callback) => {
|
|
37886
38661
|
return liveObject(commentId, callback, 'commentId', getComment$1, [
|
|
38662
|
+
onCommentDeleteLocal,
|
|
37887
38663
|
onCommentDeleted,
|
|
37888
38664
|
onCommentFlagged,
|
|
37889
38665
|
onCommentReactionAdded,
|
|
37890
38666
|
onCommentReactionRemoved,
|
|
37891
38667
|
onCommentUnflagged,
|
|
37892
38668
|
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
|
-
},
|
|
38669
|
+
onLocalCommentReactionAdded,
|
|
38670
|
+
onLocalCommentReactionRemoved,
|
|
37907
38671
|
]);
|
|
37908
38672
|
};
|
|
37909
38673
|
/* end_public_function */
|
|
@@ -37987,16 +38751,24 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
37987
38751
|
}
|
|
37988
38752
|
}
|
|
37989
38753
|
|
|
37990
|
-
|
|
37991
|
-
|
|
37992
|
-
|
|
37993
|
-
|
|
37994
|
-
|
|
37995
|
-
|
|
37996
|
-
|
|
37997
|
-
|
|
37998
|
-
|
|
37999
|
-
|
|
38754
|
+
/**
|
|
38755
|
+
* ```js
|
|
38756
|
+
* import { onCommentCreated } from '@amityco/ts-sdk-react-native'
|
|
38757
|
+
* const dispose = onCommentCreated(comment => {
|
|
38758
|
+
* // ...
|
|
38759
|
+
* })
|
|
38760
|
+
* ```
|
|
38761
|
+
*
|
|
38762
|
+
* Fired when a {@link Amity.InternalComment} has been created
|
|
38763
|
+
*
|
|
38764
|
+
* @param callback The function to call when the event was fired
|
|
38765
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38766
|
+
*
|
|
38767
|
+
* @category Comment Events
|
|
38768
|
+
*/
|
|
38769
|
+
const onCommentCreatedLocal = (callback) => {
|
|
38770
|
+
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
38771
|
+
};
|
|
38000
38772
|
|
|
38001
38773
|
class CommentLiveCollectionController extends LiveCollectionController {
|
|
38002
38774
|
constructor(query, callback) {
|
|
@@ -38027,6 +38799,8 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
38027
38799
|
}
|
|
38028
38800
|
startSubscription() {
|
|
38029
38801
|
return this.queryStreamController.subscribeRTE([
|
|
38802
|
+
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
38803
|
+
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
38030
38804
|
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
38031
38805
|
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
38032
38806
|
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
@@ -38034,6 +38808,8 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
38034
38808
|
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
38035
38809
|
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
38036
38810
|
{ fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
38811
|
+
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
38812
|
+
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
38037
38813
|
]);
|
|
38038
38814
|
}
|
|
38039
38815
|
notifyChange({ origin, loading, error }) {
|
|
@@ -38165,6 +38941,98 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
38165
38941
|
getComments: getComments
|
|
38166
38942
|
});
|
|
38167
38943
|
|
|
38944
|
+
/**
|
|
38945
|
+
* ```js
|
|
38946
|
+
* import { onPostUpdatedLocal } from '@amityco/ts-sdk-react-native'
|
|
38947
|
+
* const dispose = onPostUpdatedLocal(post => {
|
|
38948
|
+
* // ...
|
|
38949
|
+
* })
|
|
38950
|
+
* ```
|
|
38951
|
+
*
|
|
38952
|
+
* Fired when a {@link Amity.InternalPost} has been updated
|
|
38953
|
+
*
|
|
38954
|
+
* @param callback The function to call when the event was fired
|
|
38955
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38956
|
+
*
|
|
38957
|
+
* @category Post Events
|
|
38958
|
+
*/
|
|
38959
|
+
const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
|
|
38960
|
+
|
|
38961
|
+
/**
|
|
38962
|
+
* ```js
|
|
38963
|
+
* import { onLocalPostReactionAdded } from '@amityco/ts-sdk-react-native'
|
|
38964
|
+
* const dispose = onPostReactionAdded(post => {
|
|
38965
|
+
* // ...
|
|
38966
|
+
* })
|
|
38967
|
+
* ```
|
|
38968
|
+
*
|
|
38969
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
38970
|
+
*
|
|
38971
|
+
* @param callback The function to call when the event was fired
|
|
38972
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
38973
|
+
*
|
|
38974
|
+
* @category Post Events
|
|
38975
|
+
*/
|
|
38976
|
+
const onLocalPostReactionAdded = (callback) => {
|
|
38977
|
+
const client = getActiveClient();
|
|
38978
|
+
const filter = ({ post }) => {
|
|
38979
|
+
if (!client.cache) {
|
|
38980
|
+
callback(post);
|
|
38981
|
+
}
|
|
38982
|
+
else {
|
|
38983
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
38984
|
+
callback(post);
|
|
38985
|
+
}
|
|
38986
|
+
};
|
|
38987
|
+
return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
|
|
38988
|
+
};
|
|
38989
|
+
|
|
38990
|
+
/**
|
|
38991
|
+
* ```js
|
|
38992
|
+
* import { onLocalPostReactionRemoved } from '@amityco/ts-sdk-react-native'
|
|
38993
|
+
* const dispose = onPostReactionRemoved(post => {
|
|
38994
|
+
* // ...
|
|
38995
|
+
* })
|
|
38996
|
+
* ```
|
|
38997
|
+
*
|
|
38998
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
38999
|
+
*
|
|
39000
|
+
* @param callback The function to call when the event was fired
|
|
39001
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
39002
|
+
*
|
|
39003
|
+
* @category Post Events
|
|
39004
|
+
*/
|
|
39005
|
+
const onLocalPostReactionRemoved = (callback) => {
|
|
39006
|
+
const client = getActiveClient();
|
|
39007
|
+
const filter = ({ post }) => {
|
|
39008
|
+
if (!client.cache) {
|
|
39009
|
+
callback(post);
|
|
39010
|
+
}
|
|
39011
|
+
else {
|
|
39012
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
39013
|
+
callback(post);
|
|
39014
|
+
}
|
|
39015
|
+
};
|
|
39016
|
+
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
39017
|
+
};
|
|
39018
|
+
|
|
39019
|
+
/**
|
|
39020
|
+
* ```js
|
|
39021
|
+
* import { onLocalPostDeleted } from '@amityco/ts-sdk-react-native'
|
|
39022
|
+
* const dispose = onLocalPostDeleted(post => {
|
|
39023
|
+
* // ...
|
|
39024
|
+
* })
|
|
39025
|
+
* ```
|
|
39026
|
+
*
|
|
39027
|
+
* Fired when a {@link Amity.InternalPost} has been deleted
|
|
39028
|
+
*
|
|
39029
|
+
* @param callback The function to call when the event was fired
|
|
39030
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
39031
|
+
*
|
|
39032
|
+
* @category Post Events
|
|
39033
|
+
*/
|
|
39034
|
+
const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
|
|
39035
|
+
|
|
38168
39036
|
/* begin_public_function
|
|
38169
39037
|
id: post.get
|
|
38170
39038
|
*/
|
|
@@ -38195,6 +39063,8 @@ const getPost$1 = (postId, callback) => {
|
|
|
38195
39063
|
return liveObject(postId, responder, 'postId', getPost$2, [
|
|
38196
39064
|
onPostApproved,
|
|
38197
39065
|
onPostDeclined,
|
|
39066
|
+
onLocalPostReactionAdded,
|
|
39067
|
+
onLocalPostReactionRemoved,
|
|
38198
39068
|
(callback) => {
|
|
38199
39069
|
return onPostDeleted((post) => {
|
|
38200
39070
|
var _a;
|
|
@@ -38229,6 +39099,8 @@ const getPost$1 = (postId, callback) => {
|
|
|
38229
39099
|
},
|
|
38230
39100
|
onPostUnflagged,
|
|
38231
39101
|
onPostUpdated,
|
|
39102
|
+
onPostUpdatedLocal,
|
|
39103
|
+
onLocalPostDeleted,
|
|
38232
39104
|
convertEventPayload((callback) => {
|
|
38233
39105
|
return onCommentCreated(async (comment) => {
|
|
38234
39106
|
if (comment.referenceId === postId) {
|
|
@@ -38350,17 +39222,6 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
38350
39222
|
}
|
|
38351
39223
|
}
|
|
38352
39224
|
|
|
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
39225
|
const getPost = async (postId) => {
|
|
38365
39226
|
const client = getActiveClient();
|
|
38366
39227
|
client.log('post/getPost', postId);
|
|
@@ -38433,6 +39294,7 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
38433
39294
|
return this.queryStreamController.subscribeRTE([
|
|
38434
39295
|
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
38435
39296
|
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
39297
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
38436
39298
|
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
38437
39299
|
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
38438
39300
|
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
@@ -38440,6 +39302,9 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
38440
39302
|
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
38441
39303
|
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
38442
39304
|
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
39305
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
39306
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
39307
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
38443
39308
|
{
|
|
38444
39309
|
fn: convertEventPayload((callback) => {
|
|
38445
39310
|
return onCommentCreated(async (comment) => {
|
|
@@ -38557,6 +39422,138 @@ const getPosts = (params, callback, config) => {
|
|
|
38557
39422
|
};
|
|
38558
39423
|
/* end_public_function */
|
|
38559
39424
|
|
|
39425
|
+
class PinnedPostPaginationController extends PaginationController {
|
|
39426
|
+
async getRequest(queryParams, token) {
|
|
39427
|
+
const params = __rest(queryParams, ["limit"]);
|
|
39428
|
+
const { communityId, placement } = params;
|
|
39429
|
+
const path = placement
|
|
39430
|
+
? `/api/v1/pinned-posts/communities/${communityId}/${placement}`
|
|
39431
|
+
: `/api/v1/pinned-posts/communities/${communityId}`;
|
|
39432
|
+
const { data: queryResponse } = await this.http.get(path);
|
|
39433
|
+
return queryResponse;
|
|
39434
|
+
}
|
|
39435
|
+
}
|
|
39436
|
+
|
|
39437
|
+
class PinnedPostQueryStreamController extends QueryStreamController {
|
|
39438
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
39439
|
+
super(query, cacheKey);
|
|
39440
|
+
this.notifyChange = notifyChange;
|
|
39441
|
+
this.preparePayload = preparePayload;
|
|
39442
|
+
}
|
|
39443
|
+
// eslint-disable-next-line class-methods-use-this
|
|
39444
|
+
async saveToMainDB(response) {
|
|
39445
|
+
const client = getActiveClient();
|
|
39446
|
+
const cachedAt = client.cache && Date.now();
|
|
39447
|
+
if (client.cache) {
|
|
39448
|
+
ingestInCache(response, { cachedAt });
|
|
39449
|
+
}
|
|
39450
|
+
}
|
|
39451
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
39452
|
+
var _a, _b;
|
|
39453
|
+
if (refresh) {
|
|
39454
|
+
pushToCache(this.cacheKey, {
|
|
39455
|
+
data: response.pins.map(getResolver('pin')),
|
|
39456
|
+
});
|
|
39457
|
+
}
|
|
39458
|
+
else {
|
|
39459
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39460
|
+
const pinnedPosts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
39461
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...pinnedPosts, ...response.pins.map(getResolver('pin'))])] }));
|
|
39462
|
+
this.notifyChange({
|
|
39463
|
+
origin: "server" /* Amity.LiveDataOrigin.SERVER */,
|
|
39464
|
+
loading: false,
|
|
39465
|
+
});
|
|
39466
|
+
}
|
|
39467
|
+
}
|
|
39468
|
+
}
|
|
39469
|
+
|
|
39470
|
+
class PinnedPostLiveCollectionController extends LiveCollectionController {
|
|
39471
|
+
constructor(query, callback) {
|
|
39472
|
+
const queryStreamId = hash(query);
|
|
39473
|
+
const cacheKey = ['pinnedPosts', 'collection', queryStreamId];
|
|
39474
|
+
const paginationController = new PinnedPostPaginationController(query);
|
|
39475
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
39476
|
+
this.query = query;
|
|
39477
|
+
this.queryStreamController = new PinnedPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
|
|
39478
|
+
this.callback = callback.bind(this);
|
|
39479
|
+
this.loadPage({ initial: true });
|
|
39480
|
+
}
|
|
39481
|
+
setup() {
|
|
39482
|
+
var _a;
|
|
39483
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39484
|
+
if (!collection) {
|
|
39485
|
+
pushToCache(this.cacheKey, {
|
|
39486
|
+
data: [],
|
|
39487
|
+
params: {},
|
|
39488
|
+
});
|
|
39489
|
+
}
|
|
39490
|
+
}
|
|
39491
|
+
async persistModel(queryPayload) {
|
|
39492
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
39493
|
+
}
|
|
39494
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
39495
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
39496
|
+
}
|
|
39497
|
+
// eslint-disable-next-line class-methods-use-this
|
|
39498
|
+
startSubscription() {
|
|
39499
|
+
return [];
|
|
39500
|
+
}
|
|
39501
|
+
notifyChange({ origin, loading, error }) {
|
|
39502
|
+
var _a, _b;
|
|
39503
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39504
|
+
if (!collection)
|
|
39505
|
+
return;
|
|
39506
|
+
let data = ((_b = collection.data
|
|
39507
|
+
.map(id => pullFromCache(['pin', 'get', id]))
|
|
39508
|
+
.filter(isNonNullable)
|
|
39509
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.pinnedPost);
|
|
39510
|
+
data = this.applyFilter(data);
|
|
39511
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
39512
|
+
return;
|
|
39513
|
+
this.callback({
|
|
39514
|
+
data,
|
|
39515
|
+
loading,
|
|
39516
|
+
error,
|
|
39517
|
+
});
|
|
39518
|
+
}
|
|
39519
|
+
applyFilter(data) {
|
|
39520
|
+
let pinnedPost = data;
|
|
39521
|
+
switch (this.query.sortBy) {
|
|
39522
|
+
case 'lastCreated':
|
|
39523
|
+
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 }));
|
|
39524
|
+
break;
|
|
39525
|
+
}
|
|
39526
|
+
return pinnedPost;
|
|
39527
|
+
}
|
|
39528
|
+
}
|
|
39529
|
+
|
|
39530
|
+
/**
|
|
39531
|
+
* Get pinned posts for a community
|
|
39532
|
+
*
|
|
39533
|
+
* @param communityId the ID of the community
|
|
39534
|
+
* @param placement the placement of the pinned post ('announcement' or 'default'), or null to fetch all pinned posts
|
|
39535
|
+
* @returns the associated pinned post(s)
|
|
39536
|
+
*
|
|
39537
|
+
* @category Pined Posts Live Collection
|
|
39538
|
+
*
|
|
39539
|
+
*/
|
|
39540
|
+
const getPinnedPosts = (params, callback, config) => {
|
|
39541
|
+
const { log, cache } = getActiveClient();
|
|
39542
|
+
if (!cache) {
|
|
39543
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
39544
|
+
}
|
|
39545
|
+
const timestamp = Date.now();
|
|
39546
|
+
log(`getPinnedPosts(tmpid: ${timestamp}) > listen`);
|
|
39547
|
+
const pinnedPostLiveCollection = new PinnedPostLiveCollectionController(params, callback);
|
|
39548
|
+
const disposers = pinnedPostLiveCollection.startSubscription();
|
|
39549
|
+
const cacheKey = pinnedPostLiveCollection.getCacheKey();
|
|
39550
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
39551
|
+
return () => {
|
|
39552
|
+
log(`getPinnedPosts(tmpid: ${timestamp}) > dispose`);
|
|
39553
|
+
disposers.forEach(fn => fn());
|
|
39554
|
+
};
|
|
39555
|
+
};
|
|
39556
|
+
|
|
38560
39557
|
var index$5 = /*#__PURE__*/Object.freeze({
|
|
38561
39558
|
__proto__: null,
|
|
38562
39559
|
getPostByIds: getPostByIds,
|
|
@@ -38583,7 +39580,8 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
38583
39580
|
observePosts: observePosts,
|
|
38584
39581
|
observePost: observePost,
|
|
38585
39582
|
getPost: getPost$1,
|
|
38586
|
-
getPosts: getPosts
|
|
39583
|
+
getPosts: getPosts,
|
|
39584
|
+
getPinnedPosts: getPinnedPosts
|
|
38587
39585
|
});
|
|
38588
39586
|
|
|
38589
39587
|
/* begin_public_function
|
|
@@ -39472,7 +40470,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
39472
40470
|
getPoll: getPoll
|
|
39473
40471
|
});
|
|
39474
40472
|
|
|
39475
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
40473
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
|
|
39476
40474
|
/*
|
|
39477
40475
|
* The crypto algorithm used for importing key and signing string
|
|
39478
40476
|
*/
|