@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.cjs.js
CHANGED
|
@@ -10,8 +10,6 @@ var HttpAgent = require('agentkeepalive');
|
|
|
10
10
|
var io = require('socket.io-client');
|
|
11
11
|
var AsyncStorage = require('@react-native-async-storage/async-storage');
|
|
12
12
|
var uuid$1 = require('react-native-uuid');
|
|
13
|
-
var reactNative = require('react-native');
|
|
14
|
-
var mime = require('mime');
|
|
15
13
|
var hash = require('object-hash');
|
|
16
14
|
var Hls = require('hls.js');
|
|
17
15
|
|
|
@@ -42,7 +40,6 @@ var HttpAgent__default = /*#__PURE__*/_interopDefaultLegacy(HttpAgent);
|
|
|
42
40
|
var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
|
|
43
41
|
var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
|
|
44
42
|
var uuid__default = /*#__PURE__*/_interopDefaultLegacy(uuid$1);
|
|
45
|
-
var mime__default = /*#__PURE__*/_interopDefaultLegacy(mime);
|
|
46
43
|
var hash__default = /*#__PURE__*/_interopDefaultLegacy(hash);
|
|
47
44
|
var Hls__default = /*#__PURE__*/_interopDefaultLegacy(Hls);
|
|
48
45
|
|
|
@@ -125,8 +122,8 @@ const PostContentType = Object.freeze({
|
|
|
125
122
|
|
|
126
123
|
function getVersion() {
|
|
127
124
|
try {
|
|
128
|
-
// the string ''v6.
|
|
129
|
-
return 'v6.
|
|
125
|
+
// the string ''v6.30.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
126
|
+
return 'v6.30.0-cjs';
|
|
130
127
|
}
|
|
131
128
|
catch (error) {
|
|
132
129
|
return '__dev__';
|
|
@@ -563,6 +560,8 @@ const idResolvers = {
|
|
|
563
560
|
storyTarget: ({ targetId }) => targetId,
|
|
564
561
|
ad: ({ adId }) => adId,
|
|
565
562
|
advertiser: ({ advertiserId }) => advertiserId,
|
|
563
|
+
pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
|
|
564
|
+
pinTarget: ({ targetId }) => targetId,
|
|
566
565
|
};
|
|
567
566
|
/**
|
|
568
567
|
* Retrieve the id resolver matching a domain name
|
|
@@ -612,6 +611,8 @@ const PAYLOAD2MODEL = {
|
|
|
612
611
|
feeds: 'feed',
|
|
613
612
|
ads: 'ad',
|
|
614
613
|
advertisers: 'advertiser',
|
|
614
|
+
pinTargets: 'pinTarget',
|
|
615
|
+
pins: 'pin',
|
|
615
616
|
};
|
|
616
617
|
/** hidden */
|
|
617
618
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -687,18 +688,6 @@ class ASCConnectionError extends ASCError {
|
|
|
687
688
|
: 800210 /* Amity.ClientError.CONNECTION_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
688
689
|
this.event = event;
|
|
689
690
|
}
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* Input sanitization related error
|
|
693
|
-
* @category Errors
|
|
694
|
-
*/
|
|
695
|
-
class ASCInvalidParameterError extends ASCError {
|
|
696
|
-
/**
|
|
697
|
-
* @param message A custom error message
|
|
698
|
-
*/
|
|
699
|
-
constructor(message) {
|
|
700
|
-
super(message, 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
701
|
-
}
|
|
702
691
|
}
|
|
703
692
|
|
|
704
693
|
let activeClient = null;
|
|
@@ -4758,6 +4747,31 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
|
4758
4747
|
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
4759
4748
|
}
|
|
4760
4749
|
|
|
4750
|
+
/**
|
|
4751
|
+
* Attach user object to membership model
|
|
4752
|
+
* - If cache is not enabled, set user to undefined ({..., user: undefined})
|
|
4753
|
+
* - If user object is not found in cache, set user to undefined
|
|
4754
|
+
* ({..., user: undefined})
|
|
4755
|
+
* - If a user is found in the cache, it attaches the user from the cache
|
|
4756
|
+
* ({..., user: { userId, displayName,... }})
|
|
4757
|
+
*
|
|
4758
|
+
* @param member The membership model object
|
|
4759
|
+
* @returns The membership model object that is already mapped to user
|
|
4760
|
+
* @hidden
|
|
4761
|
+
*/
|
|
4762
|
+
const convertRawMembershipToMembership = (member) => {
|
|
4763
|
+
return Object.assign(Object.assign({}, member), { get user() {
|
|
4764
|
+
var _a;
|
|
4765
|
+
const client = getActiveClient();
|
|
4766
|
+
if (!client.cache)
|
|
4767
|
+
return undefined;
|
|
4768
|
+
const userCache = (_a = pullFromCache(['user', 'get', member.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
4769
|
+
if (!userCache) {
|
|
4770
|
+
return undefined;
|
|
4771
|
+
}
|
|
4772
|
+
return userCache;
|
|
4773
|
+
} });
|
|
4774
|
+
};
|
|
4761
4775
|
/**
|
|
4762
4776
|
* Attach user object to membership model
|
|
4763
4777
|
* - If cache is not enabled, set user to undefined ({..., user: undefined})
|
|
@@ -5404,6 +5418,80 @@ const categoryLinkedObject = (category) => {
|
|
|
5404
5418
|
} });
|
|
5405
5419
|
};
|
|
5406
5420
|
|
|
5421
|
+
/**
|
|
5422
|
+
* ```js
|
|
5423
|
+
* import { isEqual } from '~/utils/isEqual'
|
|
5424
|
+
* const isEqual = isEqual(post1, post2)
|
|
5425
|
+
* ```
|
|
5426
|
+
*
|
|
5427
|
+
* Compares two Amity.Model
|
|
5428
|
+
*
|
|
5429
|
+
* @param x the Amity.Model to compare
|
|
5430
|
+
* @param y the Amity.Model to compare wit x
|
|
5431
|
+
* @returns a boolean based on equality
|
|
5432
|
+
*
|
|
5433
|
+
* @category utility
|
|
5434
|
+
* @private
|
|
5435
|
+
*/
|
|
5436
|
+
function isEqual(x, y) {
|
|
5437
|
+
if (x === null || x === undefined || y === null || y === undefined) {
|
|
5438
|
+
return x === y;
|
|
5439
|
+
}
|
|
5440
|
+
// after this just checking type of one would be enough
|
|
5441
|
+
if (x.constructor !== y.constructor) {
|
|
5442
|
+
return false;
|
|
5443
|
+
}
|
|
5444
|
+
// if they are functions, they should exactly refer to same one (because of closures)
|
|
5445
|
+
if (x instanceof Function) {
|
|
5446
|
+
return x === y;
|
|
5447
|
+
}
|
|
5448
|
+
// if they are regexps, they should exactly refer to same one
|
|
5449
|
+
if (x instanceof RegExp) {
|
|
5450
|
+
return x === y;
|
|
5451
|
+
}
|
|
5452
|
+
if (x === y || x.valueOf() === y.valueOf()) {
|
|
5453
|
+
return true;
|
|
5454
|
+
}
|
|
5455
|
+
if (Array.isArray(x) && x.length !== y.length) {
|
|
5456
|
+
return false;
|
|
5457
|
+
}
|
|
5458
|
+
// check each element of the array for equality
|
|
5459
|
+
if (Array.isArray(x) && Array.isArray(y)) {
|
|
5460
|
+
if (x.length !== y.length)
|
|
5461
|
+
return false;
|
|
5462
|
+
for (let i = 0; i < x.length; i += 1) {
|
|
5463
|
+
if (!isEqual(x[i], y[i]))
|
|
5464
|
+
return false;
|
|
5465
|
+
}
|
|
5466
|
+
// if all elements are equal, the arrays are equal
|
|
5467
|
+
return true;
|
|
5468
|
+
}
|
|
5469
|
+
// if they are dates, they must had equal valueOf
|
|
5470
|
+
if (x instanceof Date) {
|
|
5471
|
+
return false;
|
|
5472
|
+
}
|
|
5473
|
+
// if they are strictly equal, they both need to be object at least
|
|
5474
|
+
if (!(x instanceof Object)) {
|
|
5475
|
+
return false;
|
|
5476
|
+
}
|
|
5477
|
+
if (!(y instanceof Object)) {
|
|
5478
|
+
return false;
|
|
5479
|
+
}
|
|
5480
|
+
// recursive object equality check
|
|
5481
|
+
const p = Object.keys(x);
|
|
5482
|
+
return (Object.keys(y).every(i => {
|
|
5483
|
+
// @ts-ignore
|
|
5484
|
+
return p.indexOf(i) !== -1;
|
|
5485
|
+
}) &&
|
|
5486
|
+
p.every(i => {
|
|
5487
|
+
return isEqual(x[i], y[i]);
|
|
5488
|
+
}));
|
|
5489
|
+
}
|
|
5490
|
+
|
|
5491
|
+
function isNonNullable(value) {
|
|
5492
|
+
return value != null;
|
|
5493
|
+
}
|
|
5494
|
+
|
|
5407
5495
|
const commentLinkedObject = (comment) => {
|
|
5408
5496
|
return Object.assign(Object.assign({}, comment), { get target() {
|
|
5409
5497
|
const commentTypes = {
|
|
@@ -5434,7 +5522,7 @@ const commentLinkedObject = (comment) => {
|
|
|
5434
5522
|
return undefined;
|
|
5435
5523
|
},
|
|
5436
5524
|
get childrenComment() {
|
|
5437
|
-
return
|
|
5525
|
+
return comment.children
|
|
5438
5526
|
.map(childCommentId => {
|
|
5439
5527
|
const commentCache = pullFromCache([
|
|
5440
5528
|
'comment',
|
|
@@ -5445,10 +5533,8 @@ const commentLinkedObject = (comment) => {
|
|
|
5445
5533
|
return;
|
|
5446
5534
|
return commentCache === null || commentCache === void 0 ? void 0 : commentCache.data;
|
|
5447
5535
|
})
|
|
5448
|
-
.filter(
|
|
5449
|
-
|
|
5450
|
-
// TS always alert returned value is possibly undefined
|
|
5451
|
-
.map(item => commentLinkedObject(item)));
|
|
5536
|
+
.filter(isNonNullable)
|
|
5537
|
+
.map(item => commentLinkedObject(item));
|
|
5452
5538
|
} });
|
|
5453
5539
|
};
|
|
5454
5540
|
|
|
@@ -5871,6 +5957,31 @@ const adLinkedObject = (ad) => {
|
|
|
5871
5957
|
} });
|
|
5872
5958
|
};
|
|
5873
5959
|
|
|
5960
|
+
const pinnedPostLinkedObject = (pinnedPost) => {
|
|
5961
|
+
var _a;
|
|
5962
|
+
const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
|
|
5963
|
+
const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
|
|
5964
|
+
var _a;
|
|
5965
|
+
return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
|
|
5966
|
+
})) === null || _a === void 0 ? void 0 : _a.data;
|
|
5967
|
+
return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
|
|
5968
|
+
get post() {
|
|
5969
|
+
if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
|
|
5970
|
+
return;
|
|
5971
|
+
return postLinkedObject(postCached.data);
|
|
5972
|
+
},
|
|
5973
|
+
get target() {
|
|
5974
|
+
const pinTarget = pullFromCache([
|
|
5975
|
+
'pinTarget',
|
|
5976
|
+
'get',
|
|
5977
|
+
postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
|
|
5978
|
+
]);
|
|
5979
|
+
if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
|
|
5980
|
+
return;
|
|
5981
|
+
return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
|
|
5982
|
+
} });
|
|
5983
|
+
};
|
|
5984
|
+
|
|
5874
5985
|
const LinkedObject = {
|
|
5875
5986
|
ad: adLinkedObject,
|
|
5876
5987
|
comment: commentLinkedObject,
|
|
@@ -5883,6 +5994,7 @@ const LinkedObject = {
|
|
|
5883
5994
|
message: messageLinkedObject,
|
|
5884
5995
|
reactor: reactorLinkedObject,
|
|
5885
5996
|
channel: channelLinkedObject,
|
|
5997
|
+
pinnedPost: pinnedPostLinkedObject,
|
|
5886
5998
|
};
|
|
5887
5999
|
|
|
5888
6000
|
const getChannelMessagePreviewWithUser = (channel) => {
|
|
@@ -6251,6 +6363,10 @@ const getChannelIsMentioned = (channel, marker) => {
|
|
|
6251
6363
|
: (_d = (_c = getCachedMarker(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
|
|
6252
6364
|
};
|
|
6253
6365
|
|
|
6366
|
+
function convertRawUserToInternalUser(rawUser) {
|
|
6367
|
+
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
6368
|
+
}
|
|
6369
|
+
|
|
6254
6370
|
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
6255
6371
|
const isUnreadCountSupport$2 = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
6256
6372
|
function convertFromRaw$2(channel, options = { isMessagePreviewUpdated: true }) {
|
|
@@ -6308,9 +6424,13 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
|
|
|
6308
6424
|
// attach marker to channel
|
|
6309
6425
|
const channels = rawPayload.channels.map(payload => convertFromRaw$2(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
6310
6426
|
// user marker to channel users
|
|
6311
|
-
const channelUsers =
|
|
6427
|
+
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
6428
|
+
return convertRawMembershipToMembership(channelUser);
|
|
6429
|
+
});
|
|
6430
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
6312
6431
|
const restRawPayload = __rest(rawPayload, ["messageFeedsInfo", "messagePreviews"]);
|
|
6313
|
-
return Object.assign(Object.assign({}, restRawPayload), {
|
|
6432
|
+
return Object.assign(Object.assign({}, restRawPayload), { users,
|
|
6433
|
+
channels,
|
|
6314
6434
|
channelUsers });
|
|
6315
6435
|
};
|
|
6316
6436
|
|
|
@@ -7747,9 +7867,17 @@ const onChannelMemberBanned = (callback) => {
|
|
|
7747
7867
|
return createEventSubscriber(client, 'onChannelMemberBanned', 'channel.banned', filter);
|
|
7748
7868
|
};
|
|
7749
7869
|
|
|
7870
|
+
function prepareUserPayload(response) {
|
|
7871
|
+
return {
|
|
7872
|
+
users: response.users.map(convertRawUserToInternalUser),
|
|
7873
|
+
files: response.files,
|
|
7874
|
+
};
|
|
7875
|
+
}
|
|
7876
|
+
|
|
7750
7877
|
const createUserEventSubscriber = (event, callback) => {
|
|
7751
7878
|
const client = getActiveClient();
|
|
7752
|
-
const filter = (
|
|
7879
|
+
const filter = (data) => {
|
|
7880
|
+
const payload = prepareUserPayload(data);
|
|
7753
7881
|
if (client.cache) {
|
|
7754
7882
|
ingestInCache(payload);
|
|
7755
7883
|
}
|
|
@@ -7773,7 +7901,7 @@ const createUserEventSubscriber = (event, callback) => {
|
|
|
7773
7901
|
*
|
|
7774
7902
|
* @category User Events
|
|
7775
7903
|
*/
|
|
7776
|
-
const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
7904
|
+
const onUserDeleted$2 = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
7777
7905
|
|
|
7778
7906
|
var analyticsEngineOnLoginHandler = () => {
|
|
7779
7907
|
const analyticsEngine = AnalyticsEngine$1.getInstance();
|
|
@@ -9050,7 +9178,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
9050
9178
|
terminateClient();
|
|
9051
9179
|
subscriptions.forEach(fn => fn());
|
|
9052
9180
|
unsubWatcher();
|
|
9053
|
-
}), onUserDeleted((user) => {
|
|
9181
|
+
}), onUserDeleted$2((user) => {
|
|
9054
9182
|
if (user.userId === client.userId) {
|
|
9055
9183
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
9056
9184
|
subscriptions.forEach(fn => fn());
|
|
@@ -9332,43 +9460,6 @@ const isConnected = () => {
|
|
|
9332
9460
|
client.ws.connected);
|
|
9333
9461
|
};
|
|
9334
9462
|
|
|
9335
|
-
const registerPushNotification = async (deviceToken) => {
|
|
9336
|
-
const client = getActiveClient();
|
|
9337
|
-
let platform;
|
|
9338
|
-
if (reactNative.Platform.OS === 'ios' || reactNative.Platform.OS === 'android') {
|
|
9339
|
-
platform = reactNative.Platform.OS;
|
|
9340
|
-
}
|
|
9341
|
-
else {
|
|
9342
|
-
throw new ASCInvalidParameterError('Unsupported platform');
|
|
9343
|
-
}
|
|
9344
|
-
const deviceId = await getDeviceId();
|
|
9345
|
-
const { data: { status, error }, } = await client.http.post('/v1/notification', {
|
|
9346
|
-
userId: client.userId,
|
|
9347
|
-
deviceId,
|
|
9348
|
-
platform,
|
|
9349
|
-
token: deviceToken,
|
|
9350
|
-
}, { headers: { 'X-API-Key': client.apiKey } });
|
|
9351
|
-
if (error) {
|
|
9352
|
-
throw new ASCApiError(error, 500000 /* Amity.ServerError.BUSINESS_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
9353
|
-
}
|
|
9354
|
-
return status === 'success';
|
|
9355
|
-
};
|
|
9356
|
-
|
|
9357
|
-
const unregisterPushNotification = async () => {
|
|
9358
|
-
const client = getActiveClient();
|
|
9359
|
-
const deviceId = getDeviceId();
|
|
9360
|
-
const { data: { status, error }, } = await client.http.delete('/v1/notification', {
|
|
9361
|
-
data: {
|
|
9362
|
-
deviceId,
|
|
9363
|
-
},
|
|
9364
|
-
headers: { 'X-API-Key': client.apiKey },
|
|
9365
|
-
});
|
|
9366
|
-
if (error) {
|
|
9367
|
-
throw new ASCApiError(error, 500000 /* Amity.ServerError.BUSINESS_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
9368
|
-
}
|
|
9369
|
-
return status === 'success';
|
|
9370
|
-
};
|
|
9371
|
-
|
|
9372
9463
|
var _GlobalFileAccessType_fileAccessType;
|
|
9373
9464
|
class GlobalFileAccessType {
|
|
9374
9465
|
constructor() {
|
|
@@ -9639,76 +9730,6 @@ const removeFunctionProperties = (obj) => {
|
|
|
9639
9730
|
return Object.fromEntries(entries);
|
|
9640
9731
|
};
|
|
9641
9732
|
|
|
9642
|
-
/**
|
|
9643
|
-
* ```js
|
|
9644
|
-
* import { isEqual } from '~/utils/isEqual'
|
|
9645
|
-
* const isEqual = isEqual(post1, post2)
|
|
9646
|
-
* ```
|
|
9647
|
-
*
|
|
9648
|
-
* Compares two Amity.Model
|
|
9649
|
-
*
|
|
9650
|
-
* @param x the Amity.Model to compare
|
|
9651
|
-
* @param y the Amity.Model to compare wit x
|
|
9652
|
-
* @returns a boolean based on equality
|
|
9653
|
-
*
|
|
9654
|
-
* @category utility
|
|
9655
|
-
* @private
|
|
9656
|
-
*/
|
|
9657
|
-
function isEqual(x, y) {
|
|
9658
|
-
if (x === null || x === undefined || y === null || y === undefined) {
|
|
9659
|
-
return x === y;
|
|
9660
|
-
}
|
|
9661
|
-
// after this just checking type of one would be enough
|
|
9662
|
-
if (x.constructor !== y.constructor) {
|
|
9663
|
-
return false;
|
|
9664
|
-
}
|
|
9665
|
-
// if they are functions, they should exactly refer to same one (because of closures)
|
|
9666
|
-
if (x instanceof Function) {
|
|
9667
|
-
return x === y;
|
|
9668
|
-
}
|
|
9669
|
-
// if they are regexps, they should exactly refer to same one
|
|
9670
|
-
if (x instanceof RegExp) {
|
|
9671
|
-
return x === y;
|
|
9672
|
-
}
|
|
9673
|
-
if (x === y || x.valueOf() === y.valueOf()) {
|
|
9674
|
-
return true;
|
|
9675
|
-
}
|
|
9676
|
-
if (Array.isArray(x) && x.length !== y.length) {
|
|
9677
|
-
return false;
|
|
9678
|
-
}
|
|
9679
|
-
// check each element of the array for equality
|
|
9680
|
-
if (Array.isArray(x) && Array.isArray(y)) {
|
|
9681
|
-
if (x.length !== y.length)
|
|
9682
|
-
return false;
|
|
9683
|
-
for (let i = 0; i < x.length; i += 1) {
|
|
9684
|
-
if (!isEqual(x[i], y[i]))
|
|
9685
|
-
return false;
|
|
9686
|
-
}
|
|
9687
|
-
// if all elements are equal, the arrays are equal
|
|
9688
|
-
return true;
|
|
9689
|
-
}
|
|
9690
|
-
// if they are dates, they must had equal valueOf
|
|
9691
|
-
if (x instanceof Date) {
|
|
9692
|
-
return false;
|
|
9693
|
-
}
|
|
9694
|
-
// if they are strictly equal, they both need to be object at least
|
|
9695
|
-
if (!(x instanceof Object)) {
|
|
9696
|
-
return false;
|
|
9697
|
-
}
|
|
9698
|
-
if (!(y instanceof Object)) {
|
|
9699
|
-
return false;
|
|
9700
|
-
}
|
|
9701
|
-
// recursive object equality check
|
|
9702
|
-
const p = Object.keys(x);
|
|
9703
|
-
return (Object.keys(y).every(i => {
|
|
9704
|
-
// @ts-ignore
|
|
9705
|
-
return p.indexOf(i) !== -1;
|
|
9706
|
-
}) &&
|
|
9707
|
-
p.every(i => {
|
|
9708
|
-
return isEqual(x[i], y[i]);
|
|
9709
|
-
}));
|
|
9710
|
-
}
|
|
9711
|
-
|
|
9712
9733
|
/**
|
|
9713
9734
|
* @deprecated This function is deprecated
|
|
9714
9735
|
*/
|
|
@@ -9926,8 +9947,6 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
9926
9947
|
renewal: renewal,
|
|
9927
9948
|
markerSync: markerSync,
|
|
9928
9949
|
enableUnreadCount: enableUnreadCount,
|
|
9929
|
-
registerPushNotification: registerPushNotification,
|
|
9930
|
-
unregisterPushNotification: unregisterPushNotification,
|
|
9931
9950
|
setUploadedFileAccessType: setUploadedFileAccessType,
|
|
9932
9951
|
onConnectionError: onConnectionError,
|
|
9933
9952
|
onClientDisconnected: onClientDisconnected,
|
|
@@ -9947,6 +9966,19 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
9947
9966
|
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
|
|
9948
9967
|
});
|
|
9949
9968
|
|
|
9969
|
+
function prepareFollowersPayload(response) {
|
|
9970
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
9971
|
+
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
9972
|
+
}
|
|
9973
|
+
function prepareFollowingsPayload(response) {
|
|
9974
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
9975
|
+
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
9976
|
+
}
|
|
9977
|
+
function prepareFollowStatusPayload(response) {
|
|
9978
|
+
const { follows } = response, rest = __rest(response, ["follows"]);
|
|
9979
|
+
return Object.assign(Object.assign({}, rest), { follows });
|
|
9980
|
+
}
|
|
9981
|
+
|
|
9950
9982
|
/* begin_public_function
|
|
9951
9983
|
id: user.relationship.block
|
|
9952
9984
|
*/
|
|
@@ -9975,7 +10007,8 @@ const blockUser = async (userId) => {
|
|
|
9975
10007
|
ingestInCache(followStatus, { cachedAt });
|
|
9976
10008
|
upsertInCache(['followInfo', 'get', userId], followCounts[0], { cachedAt });
|
|
9977
10009
|
}
|
|
9978
|
-
|
|
10010
|
+
const payload = prepareFollowStatusPayload(followStatus);
|
|
10011
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
9979
10012
|
return data;
|
|
9980
10013
|
};
|
|
9981
10014
|
/* end_public_function */
|
|
@@ -10008,89 +10041,366 @@ const unBlockUser = async (userId) => {
|
|
|
10008
10041
|
ingestInCache(followStatus, { cachedAt });
|
|
10009
10042
|
upsertInCache(['followInfo', 'get', userId], followCounts[0], { cachedAt });
|
|
10010
10043
|
}
|
|
10011
|
-
|
|
10044
|
+
const payload = prepareFollowStatusPayload(followStatus);
|
|
10045
|
+
fireEvent('local.follow.created', payload);
|
|
10012
10046
|
return data;
|
|
10013
10047
|
};
|
|
10014
10048
|
/* end_public_function */
|
|
10015
10049
|
|
|
10016
|
-
|
|
10017
|
-
|
|
10018
|
-
|
|
10019
|
-
|
|
10020
|
-
|
|
10021
|
-
*
|
|
10022
|
-
* @param query The query parameters
|
|
10023
|
-
* @returns A page of {@link Amity.User} objects
|
|
10024
|
-
*
|
|
10025
|
-
* @category Block API
|
|
10026
|
-
* @async
|
|
10027
|
-
*/
|
|
10028
|
-
const queryBlockedUsers = async (query) => {
|
|
10029
|
-
const client = getActiveClient();
|
|
10030
|
-
let params = {};
|
|
10031
|
-
if (query) {
|
|
10032
|
-
const { token, limit } = query;
|
|
10033
|
-
params = {
|
|
10034
|
-
limit,
|
|
10035
|
-
token,
|
|
10036
|
-
};
|
|
10050
|
+
class PaginationController {
|
|
10051
|
+
constructor(queryParams) {
|
|
10052
|
+
const { http } = getActiveClient();
|
|
10053
|
+
this.queryParams = queryParams;
|
|
10054
|
+
this.http = http;
|
|
10037
10055
|
}
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
params,
|
|
10041
|
-
});
|
|
10042
|
-
const { paging } = data, blockedUsers = __rest(data, ["paging"]);
|
|
10043
|
-
const { users } = blockedUsers;
|
|
10044
|
-
const cachedAt = client.cache && Date.now();
|
|
10045
|
-
if (client.cache) {
|
|
10046
|
-
ingestInCache(blockedUsers, { cachedAt });
|
|
10047
|
-
const cacheKey = ['blockedUsers', 'query', params];
|
|
10048
|
-
pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
|
|
10056
|
+
loadFirstPage() {
|
|
10057
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
10049
10058
|
}
|
|
10050
|
-
|
|
10051
|
-
|
|
10052
|
-
const prevPage = toPageRaw(previous);
|
|
10053
|
-
return { data: users, prevPage, nextPage, total, cachedAt };
|
|
10054
|
-
};
|
|
10055
|
-
/**
|
|
10056
|
-
* ```js
|
|
10057
|
-
* import { queryBlockedUsers } from '@amityco/ts-sdk-react-native'
|
|
10058
|
-
* const { data: users } = queryBlockedUsers.locally({ page: 'page_token' })
|
|
10059
|
-
* ```
|
|
10060
|
-
*
|
|
10061
|
-
* Queries a paginable list of {@link Amity.User} objects from cache
|
|
10062
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
10063
|
-
*
|
|
10064
|
-
* @param query The query parameters
|
|
10065
|
-
* @returns A page of {@link Amity.User} objects
|
|
10066
|
-
*
|
|
10067
|
-
* @category Block API
|
|
10068
|
-
*/
|
|
10069
|
-
queryBlockedUsers.locally = (query = {}) => {
|
|
10070
|
-
var _a, _b, _c;
|
|
10071
|
-
const client = getActiveClient();
|
|
10072
|
-
client.log('user/queryBlockedUsers.locally');
|
|
10073
|
-
if (!client.cache)
|
|
10074
|
-
return;
|
|
10075
|
-
let params = {};
|
|
10076
|
-
if (query) {
|
|
10077
|
-
const { token, limit } = query;
|
|
10078
|
-
params = {
|
|
10079
|
-
token,
|
|
10080
|
-
limit,
|
|
10081
|
-
};
|
|
10059
|
+
loadNextPage() {
|
|
10060
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
10082
10061
|
}
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10062
|
+
loadPreviousPage() {
|
|
10063
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
10064
|
+
}
|
|
10065
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
10066
|
+
var _a, _b, _c, _d;
|
|
10067
|
+
if (direction === 'prev' && !this.previousToken)
|
|
10068
|
+
return;
|
|
10069
|
+
if (direction === 'next' && !this.nextToken)
|
|
10070
|
+
return;
|
|
10071
|
+
let token;
|
|
10072
|
+
if (direction === 'prev')
|
|
10073
|
+
token = this.previousToken;
|
|
10074
|
+
if (direction === 'next')
|
|
10075
|
+
token = this.nextToken;
|
|
10076
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
10077
|
+
if (direction === 'first') {
|
|
10078
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
10079
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
10080
|
+
}
|
|
10081
|
+
if (direction === 'prev')
|
|
10082
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
10083
|
+
if (direction === 'next')
|
|
10084
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
10085
|
+
return queryResponse;
|
|
10086
|
+
}
|
|
10087
|
+
getNextToken() {
|
|
10088
|
+
return this.nextToken;
|
|
10089
|
+
}
|
|
10090
|
+
getPrevToken() {
|
|
10091
|
+
return this.previousToken;
|
|
10092
|
+
}
|
|
10093
|
+
}
|
|
10094
|
+
|
|
10095
|
+
class BlockedUserPaginationController extends PaginationController {
|
|
10096
|
+
async getRequest(queryParams, token) {
|
|
10097
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
10098
|
+
const options = token ? { token } : { limit };
|
|
10099
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
10100
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
10101
|
+
});
|
|
10102
|
+
return queryResponse;
|
|
10103
|
+
}
|
|
10104
|
+
}
|
|
10105
|
+
|
|
10106
|
+
class QueryStreamController {
|
|
10107
|
+
constructor(query, cacheKey) {
|
|
10108
|
+
this.query = query;
|
|
10109
|
+
this.cacheKey = cacheKey;
|
|
10110
|
+
}
|
|
10111
|
+
}
|
|
10112
|
+
|
|
10113
|
+
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
10114
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
10115
|
+
super(query, cacheKey);
|
|
10116
|
+
this.notifyChange = notifyChange;
|
|
10117
|
+
this.preparePayload = preparePayload;
|
|
10118
|
+
}
|
|
10119
|
+
async saveToMainDB(response) {
|
|
10120
|
+
const processedPayload = await this.preparePayload(response);
|
|
10121
|
+
const client = getActiveClient();
|
|
10122
|
+
const cachedAt = client.cache && Date.now();
|
|
10123
|
+
if (client.cache) {
|
|
10124
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
10125
|
+
}
|
|
10126
|
+
}
|
|
10127
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
10128
|
+
var _a, _b;
|
|
10129
|
+
if (refresh) {
|
|
10130
|
+
pushToCache(this.cacheKey, {
|
|
10131
|
+
data: response.users.map(getResolver('user')),
|
|
10132
|
+
});
|
|
10133
|
+
}
|
|
10134
|
+
else {
|
|
10135
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10136
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
10137
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
10138
|
+
}
|
|
10139
|
+
}
|
|
10140
|
+
reactor(action) {
|
|
10141
|
+
return (followStatus) => {
|
|
10142
|
+
var _a;
|
|
10143
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10144
|
+
pushToCache(this.cacheKey, collection);
|
|
10145
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
10146
|
+
};
|
|
10147
|
+
}
|
|
10148
|
+
subscribeRTE(createSubscriber) {
|
|
10149
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
10150
|
+
}
|
|
10151
|
+
}
|
|
10152
|
+
|
|
10153
|
+
class PaginationNoPageController {
|
|
10154
|
+
constructor(queryParams) {
|
|
10155
|
+
const { http } = getActiveClient();
|
|
10156
|
+
this.queryParams = queryParams;
|
|
10157
|
+
this.http = http;
|
|
10158
|
+
}
|
|
10159
|
+
async onFetch() {
|
|
10160
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
10161
|
+
return queryResponse;
|
|
10162
|
+
}
|
|
10163
|
+
}
|
|
10164
|
+
|
|
10165
|
+
class LiveCollectionController {
|
|
10166
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
10167
|
+
this.paginationController = paginationController;
|
|
10168
|
+
this.queryStreamId = queryStreamId;
|
|
10169
|
+
this.cacheKey = cacheKey;
|
|
10170
|
+
this.callback = callback;
|
|
10171
|
+
}
|
|
10172
|
+
async refresh() {
|
|
10173
|
+
try {
|
|
10174
|
+
let result;
|
|
10175
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
10176
|
+
result = await this.paginationController.onFetch();
|
|
10177
|
+
}
|
|
10178
|
+
else {
|
|
10179
|
+
result = await this.paginationController.loadFirstPage();
|
|
10180
|
+
}
|
|
10181
|
+
if (!result)
|
|
10182
|
+
return;
|
|
10183
|
+
await this.persistModel(result);
|
|
10184
|
+
this.persistQueryStream({
|
|
10185
|
+
response: result,
|
|
10186
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
10187
|
+
refresh: true,
|
|
10188
|
+
});
|
|
10189
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
10190
|
+
}
|
|
10191
|
+
catch (e) {
|
|
10192
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
10193
|
+
}
|
|
10194
|
+
}
|
|
10195
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
10196
|
+
this.setup();
|
|
10197
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
10198
|
+
if (initial) {
|
|
10199
|
+
this.refresh();
|
|
10200
|
+
}
|
|
10201
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
10202
|
+
this.loadPrevPage();
|
|
10203
|
+
}
|
|
10204
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
10205
|
+
this.loadNextPage();
|
|
10206
|
+
}
|
|
10207
|
+
}
|
|
10208
|
+
async loadNextPage() {
|
|
10209
|
+
try {
|
|
10210
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
10211
|
+
return;
|
|
10212
|
+
const result = await this.paginationController.loadNextPage();
|
|
10213
|
+
if (!result)
|
|
10214
|
+
return;
|
|
10215
|
+
await this.persistModel(result);
|
|
10216
|
+
this.persistQueryStream({
|
|
10217
|
+
response: result,
|
|
10218
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
10219
|
+
});
|
|
10220
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
10221
|
+
}
|
|
10222
|
+
catch (e) {
|
|
10223
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
10224
|
+
}
|
|
10225
|
+
}
|
|
10226
|
+
async loadPrevPage() {
|
|
10227
|
+
try {
|
|
10228
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
10229
|
+
return;
|
|
10230
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
10231
|
+
if (!result)
|
|
10232
|
+
return;
|
|
10233
|
+
await this.persistModel(result);
|
|
10234
|
+
this.persistQueryStream({
|
|
10235
|
+
response: result,
|
|
10236
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
10237
|
+
});
|
|
10238
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
10239
|
+
}
|
|
10240
|
+
catch (e) {
|
|
10241
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
10242
|
+
}
|
|
10243
|
+
}
|
|
10244
|
+
shouldNotify(data) {
|
|
10245
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
10246
|
+
if (isEqual(this.snapshot, newData))
|
|
10247
|
+
return false;
|
|
10248
|
+
this.snapshot = newData;
|
|
10249
|
+
return true;
|
|
10250
|
+
}
|
|
10251
|
+
getCacheKey() {
|
|
10252
|
+
return this.cacheKey;
|
|
10253
|
+
}
|
|
10254
|
+
}
|
|
10255
|
+
|
|
10256
|
+
function prepareBlockedUserPayload(response) {
|
|
10257
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
10258
|
+
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
10259
|
+
const followUser = users.find(user => user.userId === follow.from);
|
|
10260
|
+
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
10261
|
+
}), users: users.map(convertRawUserToInternalUser) });
|
|
10262
|
+
}
|
|
10263
|
+
|
|
10264
|
+
/**
|
|
10265
|
+
* ```js
|
|
10266
|
+
* import { onUserUpdated } from '@amityco/ts-sdk-react-native'
|
|
10267
|
+
* const dispose = onUserUpdated(user => {
|
|
10268
|
+
* // ...
|
|
10269
|
+
* })
|
|
10270
|
+
* ```
|
|
10271
|
+
*
|
|
10272
|
+
* Fired when a {@link Amity.InternalUser} has been updated
|
|
10273
|
+
*
|
|
10274
|
+
* @param callback The function to call when the event was fired
|
|
10275
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10276
|
+
*
|
|
10277
|
+
* @category User Events
|
|
10278
|
+
*/
|
|
10279
|
+
const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
|
|
10280
|
+
|
|
10281
|
+
/**
|
|
10282
|
+
* ```js
|
|
10283
|
+
* import { onUserFlagged } from '@amityco/ts-sdk-react-native'
|
|
10284
|
+
* const dispose = onUserFlagged(user => {
|
|
10285
|
+
* // ...
|
|
10286
|
+
* })
|
|
10287
|
+
* ```
|
|
10288
|
+
*
|
|
10289
|
+
* Fired when a {@link Amity.InternalUser} has been flagged
|
|
10290
|
+
*
|
|
10291
|
+
* @param callback The function to call when the event was fired
|
|
10292
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10293
|
+
*
|
|
10294
|
+
* @category User Events
|
|
10295
|
+
*/
|
|
10296
|
+
const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
|
|
10297
|
+
|
|
10298
|
+
/**
|
|
10299
|
+
* ```js
|
|
10300
|
+
* import { onUserUnflagged } from '@amityco/ts-sdk-react-native'
|
|
10301
|
+
* const dispose = onUserUnflagged(user => {
|
|
10302
|
+
* // ...
|
|
10303
|
+
* })
|
|
10304
|
+
* ```
|
|
10305
|
+
*
|
|
10306
|
+
* Fired when a flag has been removed from a {@link Amity.InternalUser}
|
|
10307
|
+
*
|
|
10308
|
+
* @param callback The function to call when the event was fired
|
|
10309
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10310
|
+
*
|
|
10311
|
+
* @category User Events
|
|
10312
|
+
*/
|
|
10313
|
+
const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
|
|
10314
|
+
|
|
10315
|
+
/**
|
|
10316
|
+
* ```js
|
|
10317
|
+
* import { onUserFlagCleared } from '@amityco/ts-sdk-react-native'
|
|
10318
|
+
* const dispose = onUserFlagCleared(user => {
|
|
10319
|
+
* // ...
|
|
10320
|
+
* })
|
|
10321
|
+
* ```
|
|
10322
|
+
*
|
|
10323
|
+
* Fired when flags have been cleared for a {@link Amity.InternalUser}
|
|
10324
|
+
*
|
|
10325
|
+
* @param callback The function to call when the event was fired
|
|
10326
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10327
|
+
*
|
|
10328
|
+
* @category User Events
|
|
10329
|
+
*/
|
|
10330
|
+
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
10331
|
+
|
|
10332
|
+
var EnumUserActions;
|
|
10333
|
+
(function (EnumUserActions) {
|
|
10334
|
+
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
10335
|
+
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
10336
|
+
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
10337
|
+
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
10338
|
+
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
10339
|
+
})(EnumUserActions || (EnumUserActions = {}));
|
|
10340
|
+
|
|
10341
|
+
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
10342
|
+
constructor(query, callback) {
|
|
10343
|
+
const queryStreamId = hash__default["default"](query);
|
|
10344
|
+
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
10345
|
+
const paginationController = new BlockedUserPaginationController(query);
|
|
10346
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
10347
|
+
this.query = query;
|
|
10348
|
+
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
10349
|
+
this.callback = callback.bind(this);
|
|
10350
|
+
this.loadPage({ initial: true });
|
|
10351
|
+
}
|
|
10352
|
+
setup() {
|
|
10353
|
+
var _a;
|
|
10354
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10355
|
+
if (!collection) {
|
|
10356
|
+
pushToCache(this.cacheKey, {
|
|
10357
|
+
data: [],
|
|
10358
|
+
params: {},
|
|
10359
|
+
});
|
|
10360
|
+
}
|
|
10361
|
+
}
|
|
10362
|
+
async persistModel(queryPayload) {
|
|
10363
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
10364
|
+
}
|
|
10365
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
10366
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
10367
|
+
}
|
|
10368
|
+
startSubscription() {
|
|
10369
|
+
return this.queryStreamController.subscribeRTE([
|
|
10370
|
+
{
|
|
10371
|
+
fn: onUserDeleted$2,
|
|
10372
|
+
action: EnumUserActions.OnUserDeleted,
|
|
10373
|
+
},
|
|
10374
|
+
]);
|
|
10375
|
+
}
|
|
10376
|
+
notifyChange({ origin, loading, error }) {
|
|
10377
|
+
var _a, _b;
|
|
10378
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10379
|
+
if (!collection)
|
|
10380
|
+
return;
|
|
10381
|
+
const data = this.applyFilter((_b = collection.data
|
|
10382
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
10383
|
+
.filter(isNonNullable)
|
|
10384
|
+
.map(({ data }) => data)
|
|
10385
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
10386
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
10387
|
+
return;
|
|
10388
|
+
this.callback({
|
|
10389
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
10390
|
+
data,
|
|
10391
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
10392
|
+
loading,
|
|
10393
|
+
error,
|
|
10394
|
+
});
|
|
10395
|
+
}
|
|
10396
|
+
// eslint-disable-next-line class-methods-use-this
|
|
10397
|
+
applyFilter(data) {
|
|
10398
|
+
let users = data;
|
|
10399
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
10400
|
+
return users;
|
|
10401
|
+
}
|
|
10402
|
+
}
|
|
10092
10403
|
|
|
10093
|
-
/* eslint-disable no-use-before-define */
|
|
10094
10404
|
/* begin_public_function
|
|
10095
10405
|
id: user.get_blocked_users
|
|
10096
10406
|
*/
|
|
@@ -10116,63 +10426,12 @@ const getBlockedUsers$1 = (params, callback, config) => {
|
|
|
10116
10426
|
}
|
|
10117
10427
|
const timestamp = Date.now();
|
|
10118
10428
|
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
10119
|
-
const
|
|
10120
|
-
const
|
|
10121
|
-
const
|
|
10122
|
-
|
|
10123
|
-
const cacheKey = ['blockedUsers', 'collection', {}];
|
|
10124
|
-
const responder = (data) => {
|
|
10125
|
-
var _a, _b;
|
|
10126
|
-
const users = (_a = data.data
|
|
10127
|
-
.map(userId => pullFromCache(['user', 'get', userId]))
|
|
10128
|
-
.filter(Boolean)
|
|
10129
|
-
.map(({ data }) => LinkedObject.user(data))) !== null && _a !== void 0 ? _a : [];
|
|
10130
|
-
callback({
|
|
10131
|
-
onNextPage: onFetch,
|
|
10132
|
-
data: users,
|
|
10133
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
10134
|
-
loading: data.loading,
|
|
10135
|
-
error: data.error,
|
|
10136
|
-
});
|
|
10137
|
-
};
|
|
10138
|
-
/*
|
|
10139
|
-
* const realtimeRouter = () => {
|
|
10140
|
-
* @TODO: At the time of creating this api blocked user do not have any
|
|
10141
|
-
* observers
|
|
10142
|
-
*};
|
|
10143
|
-
*/
|
|
10144
|
-
const onFetch = (initial = false) => {
|
|
10145
|
-
var _a, _b;
|
|
10146
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10147
|
-
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
10148
|
-
if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
10149
|
-
return;
|
|
10150
|
-
const query = createQuery(queryBlockedUsers, {
|
|
10151
|
-
limit,
|
|
10152
|
-
token: toToken(!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined, 'afterbeforeraw'),
|
|
10153
|
-
});
|
|
10154
|
-
runQuery(query,
|
|
10155
|
-
// @ts-ignore
|
|
10156
|
-
({ data: result, loading, error, nextPage: page, total }) => {
|
|
10157
|
-
const data = {
|
|
10158
|
-
loading,
|
|
10159
|
-
error,
|
|
10160
|
-
params: { page, total },
|
|
10161
|
-
data: users,
|
|
10162
|
-
};
|
|
10163
|
-
if (result) {
|
|
10164
|
-
data.data = [...new Set([...users, ...result.map(getResolver('user'))])];
|
|
10165
|
-
}
|
|
10166
|
-
pushToCache(cacheKey, data);
|
|
10167
|
-
responder(data);
|
|
10168
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
10169
|
-
};
|
|
10170
|
-
disposers.push(() => {
|
|
10171
|
-
// @TODO -> update once observers added
|
|
10172
|
-
});
|
|
10173
|
-
onFetch(true);
|
|
10429
|
+
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
10430
|
+
const disposers = blockedUserLiveCollection.startSubscription();
|
|
10431
|
+
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
10432
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
10174
10433
|
return () => {
|
|
10175
|
-
log(`
|
|
10434
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
10176
10435
|
disposers.forEach(fn => fn());
|
|
10177
10436
|
dropFromCache(cacheKey);
|
|
10178
10437
|
};
|
|
@@ -10182,7 +10441,7 @@ const getBlockedUsers$1 = (params, callback, config) => {
|
|
|
10182
10441
|
/* eslint-disable no-use-before-define */
|
|
10183
10442
|
const getBlockedUsers = (params, callback, config) => {
|
|
10184
10443
|
console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
|
|
10185
|
-
return getBlockedUsers$1(params, callback
|
|
10444
|
+
return getBlockedUsers$1(params, callback);
|
|
10186
10445
|
};
|
|
10187
10446
|
|
|
10188
10447
|
/* begin_public_function
|
|
@@ -10210,7 +10469,13 @@ const follow = async (userId) => {
|
|
|
10210
10469
|
if (client.cache) {
|
|
10211
10470
|
ingestInCache(data, { cachedAt });
|
|
10212
10471
|
}
|
|
10213
|
-
|
|
10472
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10473
|
+
if (data.follows[0].status === 'accepted') {
|
|
10474
|
+
fireEvent('local.follow.created', payload);
|
|
10475
|
+
}
|
|
10476
|
+
else {
|
|
10477
|
+
fireEvent('local.follow.requested', payload);
|
|
10478
|
+
}
|
|
10214
10479
|
return {
|
|
10215
10480
|
data: data.follows[0],
|
|
10216
10481
|
cachedAt,
|
|
@@ -10242,7 +10507,8 @@ const unfollow = async (userId) => {
|
|
|
10242
10507
|
if (client.cache) {
|
|
10243
10508
|
ingestInCache(data);
|
|
10244
10509
|
}
|
|
10245
|
-
|
|
10510
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10511
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
10246
10512
|
return true;
|
|
10247
10513
|
};
|
|
10248
10514
|
/* end_public_function */
|
|
@@ -10271,7 +10537,8 @@ const acceptFollower = async (userId) => {
|
|
|
10271
10537
|
if (client.cache) {
|
|
10272
10538
|
ingestInCache(data);
|
|
10273
10539
|
}
|
|
10274
|
-
|
|
10540
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10541
|
+
fireEvent('local.follow.accepted', payload);
|
|
10275
10542
|
return true;
|
|
10276
10543
|
};
|
|
10277
10544
|
|
|
@@ -10299,7 +10566,8 @@ const acceptMyFollower = async (userId) => {
|
|
|
10299
10566
|
if (client.cache) {
|
|
10300
10567
|
ingestInCache(data);
|
|
10301
10568
|
}
|
|
10302
|
-
|
|
10569
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10570
|
+
fireEvent('local.follow.accepted', payload);
|
|
10303
10571
|
return true;
|
|
10304
10572
|
};
|
|
10305
10573
|
/* end_public_function */
|
|
@@ -10328,7 +10596,8 @@ const declineFollower = async (userId) => {
|
|
|
10328
10596
|
if (client.cache) {
|
|
10329
10597
|
ingestInCache(data);
|
|
10330
10598
|
}
|
|
10331
|
-
|
|
10599
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10600
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
10332
10601
|
return true;
|
|
10333
10602
|
};
|
|
10334
10603
|
|
|
@@ -10356,29 +10625,35 @@ const declineMyFollower = async (userId) => {
|
|
|
10356
10625
|
if (client.cache) {
|
|
10357
10626
|
ingestInCache(data);
|
|
10358
10627
|
}
|
|
10359
|
-
|
|
10628
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10629
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
10360
10630
|
return true;
|
|
10361
10631
|
};
|
|
10362
10632
|
/* end_public_function */
|
|
10363
10633
|
|
|
10364
10634
|
const createFollowEventSubscriber = (event, callback) => {
|
|
10365
10635
|
const client = getActiveClient();
|
|
10366
|
-
const filter = (
|
|
10367
|
-
|
|
10636
|
+
const filter = (data) => {
|
|
10637
|
+
const payload = prepareFollowersPayload(data);
|
|
10638
|
+
if (!client.cache) {
|
|
10639
|
+
callback(payload.follows[0]);
|
|
10640
|
+
}
|
|
10641
|
+
else {
|
|
10642
|
+
ingestInCache(payload);
|
|
10643
|
+
callback(payload.follows[0]);
|
|
10644
|
+
}
|
|
10645
|
+
};
|
|
10646
|
+
return createEventSubscriber(client, event, event, filter);
|
|
10647
|
+
};
|
|
10648
|
+
const createLocalFollowEventSubscriber = (event, callback) => {
|
|
10649
|
+
const client = getActiveClient();
|
|
10650
|
+
const filter = (data) => {
|
|
10651
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10368
10652
|
if (!client.cache) {
|
|
10369
10653
|
callback(payload.follows[0]);
|
|
10370
10654
|
}
|
|
10371
10655
|
else {
|
|
10372
10656
|
ingestInCache(payload);
|
|
10373
|
-
const queries = [
|
|
10374
|
-
...((_a = queryCache(['followers', 'query'])) !== null && _a !== void 0 ? _a : []),
|
|
10375
|
-
...((_b = queryCache(['followings', 'query'])) !== null && _b !== void 0 ? _b : []),
|
|
10376
|
-
];
|
|
10377
|
-
queries
|
|
10378
|
-
.filter(({ key }) =>
|
|
10379
|
-
// @ts-ignore
|
|
10380
|
-
key[2].userId === payload.follows[0].from || key[2].userId === payload.follows[0].to)
|
|
10381
|
-
.forEach(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
10382
10657
|
callback(payload.follows[0]);
|
|
10383
10658
|
}
|
|
10384
10659
|
};
|
|
@@ -10597,12 +10872,27 @@ const onFollowInfoUpdated = (callback) => {
|
|
|
10597
10872
|
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
10598
10873
|
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
10599
10874
|
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
10875
|
+
createLocalFollowEventSubscriber('local.follow.created', handler),
|
|
10876
|
+
createLocalFollowEventSubscriber('local.follow.requested', handler),
|
|
10877
|
+
createLocalFollowEventSubscriber('local.follow.accepted', handler),
|
|
10878
|
+
createLocalFollowEventSubscriber('local.follow.unfollowed', handler),
|
|
10879
|
+
createLocalFollowEventSubscriber('local.follow.requestDeclined', handler),
|
|
10600
10880
|
];
|
|
10601
10881
|
return () => {
|
|
10602
10882
|
disposers.forEach(fn => fn());
|
|
10603
10883
|
};
|
|
10604
10884
|
};
|
|
10605
10885
|
|
|
10886
|
+
const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
|
|
10887
|
+
|
|
10888
|
+
const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
|
|
10889
|
+
|
|
10890
|
+
const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
|
|
10891
|
+
|
|
10892
|
+
const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
|
|
10893
|
+
|
|
10894
|
+
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
10895
|
+
|
|
10606
10896
|
/**
|
|
10607
10897
|
* ```js
|
|
10608
10898
|
* import { observeFollowInfo } from '@amityco/ts-sdk-react-native'
|
|
@@ -10675,7 +10965,7 @@ const observeFollowers = (userId, callback) => {
|
|
|
10675
10965
|
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
10676
10966
|
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
10677
10967
|
};
|
|
10678
|
-
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')));
|
|
10968
|
+
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')));
|
|
10679
10969
|
return () => {
|
|
10680
10970
|
log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
|
|
10681
10971
|
disposers.forEach(fn => fn());
|
|
@@ -10711,92 +11001,190 @@ const observeFollowings = (userId, callback) => {
|
|
|
10711
11001
|
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
10712
11002
|
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
10713
11003
|
};
|
|
10714
|
-
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')));
|
|
11004
|
+
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')));
|
|
10715
11005
|
return () => {
|
|
10716
11006
|
log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
|
|
10717
11007
|
disposers.forEach(fn => fn());
|
|
10718
11008
|
};
|
|
10719
11009
|
};
|
|
10720
11010
|
|
|
10721
|
-
|
|
10722
|
-
|
|
10723
|
-
|
|
10724
|
-
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
|
|
10729
|
-
|
|
10730
|
-
|
|
10731
|
-
if (client.cache) {
|
|
10732
|
-
ingestInCache(payload, { cachedAt });
|
|
10733
|
-
const cacheKey = [
|
|
10734
|
-
'follow',
|
|
10735
|
-
'query',
|
|
10736
|
-
Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page), type: key }),
|
|
10737
|
-
];
|
|
10738
|
-
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
11011
|
+
class FollowerPaginationController extends PaginationController {
|
|
11012
|
+
async getRequest(queryParams, token) {
|
|
11013
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
11014
|
+
const options = token ? { token } : { limit };
|
|
11015
|
+
const client = getActiveClient();
|
|
11016
|
+
const path = client.userId === userId ? `/api/v4/me/followers` : `/api/v4/users/${userId}/followers`;
|
|
11017
|
+
const { data: queryResponse } = await this.http.get(path, {
|
|
11018
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
11019
|
+
});
|
|
11020
|
+
return queryResponse;
|
|
10739
11021
|
}
|
|
10740
|
-
|
|
10741
|
-
|
|
10742
|
-
|
|
10743
|
-
|
|
10744
|
-
|
|
10745
|
-
|
|
10746
|
-
|
|
10747
|
-
|
|
10748
|
-
|
|
10749
|
-
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
|
|
10757
|
-
|
|
10758
|
-
|
|
11022
|
+
}
|
|
11023
|
+
|
|
11024
|
+
var EnumFollowActions;
|
|
11025
|
+
(function (EnumFollowActions) {
|
|
11026
|
+
EnumFollowActions["OnRequested"] = "onRequested";
|
|
11027
|
+
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
11028
|
+
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
11029
|
+
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
11030
|
+
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
11031
|
+
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
11032
|
+
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
11033
|
+
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
11034
|
+
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
11035
|
+
|
|
11036
|
+
class FollowerQueryStreamController extends QueryStreamController {
|
|
11037
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
11038
|
+
super(query, cacheKey);
|
|
11039
|
+
this.notifyChange = notifyChange;
|
|
11040
|
+
this.preparePayload = preparePayload;
|
|
10759
11041
|
}
|
|
10760
|
-
|
|
10761
|
-
|
|
10762
|
-
|
|
10763
|
-
|
|
10764
|
-
|
|
10765
|
-
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
|
|
11042
|
+
async saveToMainDB(response) {
|
|
11043
|
+
const processedPayload = await this.preparePayload(response);
|
|
11044
|
+
const client = getActiveClient();
|
|
11045
|
+
const cachedAt = client.cache && Date.now();
|
|
11046
|
+
if (client.cache) {
|
|
11047
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
11048
|
+
}
|
|
11049
|
+
}
|
|
11050
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
11051
|
+
var _a, _b;
|
|
11052
|
+
if (refresh) {
|
|
11053
|
+
pushToCache(this.cacheKey, {
|
|
11054
|
+
data: response.follows.map(getResolver('follow')),
|
|
11055
|
+
});
|
|
11056
|
+
}
|
|
11057
|
+
else {
|
|
11058
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11059
|
+
const follows = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
11060
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...follows, ...response.follows.map(getResolver('follow'))])] }));
|
|
11061
|
+
}
|
|
11062
|
+
}
|
|
11063
|
+
reactor(action) {
|
|
11064
|
+
return (followStatus) => {
|
|
11065
|
+
var _a;
|
|
11066
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11067
|
+
if (this.query.userId !== followStatus.to || !collection)
|
|
11068
|
+
return;
|
|
11069
|
+
switch (action) {
|
|
11070
|
+
case EnumFollowActions.OnDeclined:
|
|
11071
|
+
case EnumFollowActions.OnCanceled:
|
|
11072
|
+
case EnumFollowActions.OnUnfollowed:
|
|
11073
|
+
case EnumFollowActions.OnDeleted:
|
|
11074
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
11075
|
+
break;
|
|
11076
|
+
case EnumFollowActions.OnRequested:
|
|
11077
|
+
case EnumFollowActions.OnAccepted:
|
|
11078
|
+
case EnumFollowActions.OnFollowed:
|
|
11079
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
11080
|
+
break;
|
|
11081
|
+
}
|
|
11082
|
+
pushToCache(this.cacheKey, collection);
|
|
11083
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
11084
|
+
};
|
|
11085
|
+
}
|
|
11086
|
+
subscribeRTE(createSubscriber) {
|
|
11087
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
11088
|
+
}
|
|
11089
|
+
}
|
|
11090
|
+
|
|
11091
|
+
const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
11092
|
+
const client = getActiveClient();
|
|
11093
|
+
const filter = (data) => {
|
|
11094
|
+
const userPayload = prepareUserPayload(data);
|
|
11095
|
+
ingestInCache(userPayload);
|
|
11096
|
+
const cacheData = pullFromCache([
|
|
11097
|
+
'follow',
|
|
11098
|
+
'get',
|
|
11099
|
+
getResolver('follow')({
|
|
11100
|
+
from: userPayload.users[0].userId,
|
|
11101
|
+
to: userId,
|
|
11102
|
+
}),
|
|
11103
|
+
]);
|
|
11104
|
+
if (!cacheData)
|
|
11105
|
+
return;
|
|
11106
|
+
callback(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data);
|
|
11107
|
+
};
|
|
11108
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
10769
11109
|
};
|
|
10770
11110
|
|
|
10771
|
-
|
|
10772
|
-
|
|
10773
|
-
|
|
10774
|
-
|
|
10775
|
-
|
|
10776
|
-
|
|
10777
|
-
|
|
10778
|
-
|
|
10779
|
-
|
|
10780
|
-
|
|
10781
|
-
|
|
10782
|
-
|
|
10783
|
-
|
|
10784
|
-
|
|
10785
|
-
|
|
10786
|
-
|
|
10787
|
-
|
|
10788
|
-
|
|
10789
|
-
|
|
10790
|
-
|
|
10791
|
-
|
|
10792
|
-
|
|
10793
|
-
|
|
10794
|
-
|
|
10795
|
-
|
|
10796
|
-
|
|
10797
|
-
|
|
10798
|
-
|
|
10799
|
-
|
|
11111
|
+
class FollowerLiveCollectionController extends LiveCollectionController {
|
|
11112
|
+
constructor(query, callback) {
|
|
11113
|
+
const queryStreamId = hash__default["default"](query);
|
|
11114
|
+
const cacheKey = ['follow', 'collection', queryStreamId];
|
|
11115
|
+
const paginationController = new FollowerPaginationController(query);
|
|
11116
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
11117
|
+
this.query = query;
|
|
11118
|
+
this.queryStreamController = new FollowerQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareFollowersPayload);
|
|
11119
|
+
this.callback = callback.bind(this);
|
|
11120
|
+
this.loadPage({ initial: true });
|
|
11121
|
+
}
|
|
11122
|
+
setup() {
|
|
11123
|
+
var _a;
|
|
11124
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11125
|
+
if (!collection) {
|
|
11126
|
+
pushToCache(this.cacheKey, {
|
|
11127
|
+
data: [],
|
|
11128
|
+
params: {},
|
|
11129
|
+
});
|
|
11130
|
+
}
|
|
11131
|
+
}
|
|
11132
|
+
async persistModel(queryPayload) {
|
|
11133
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
11134
|
+
}
|
|
11135
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
11136
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
11137
|
+
}
|
|
11138
|
+
startSubscription() {
|
|
11139
|
+
return this.queryStreamController.subscribeRTE([
|
|
11140
|
+
{ fn: onUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
11141
|
+
{ fn: onUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
11142
|
+
{ fn: onFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
11143
|
+
{ fn: onFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
11144
|
+
{ fn: onFollowRequestCanceled, action: EnumFollowActions.OnCanceled },
|
|
11145
|
+
{ fn: onFollowerDeleted, action: EnumFollowActions.OnDeleted },
|
|
11146
|
+
{ fn: onLocalFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
11147
|
+
{ fn: onLocalFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
11148
|
+
{ fn: onLocalUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
11149
|
+
{ fn: onLocalUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
11150
|
+
{
|
|
11151
|
+
fn: onFollowerUserDeleted({ userId: this.query.userId }),
|
|
11152
|
+
action: EnumFollowActions.OnUserDeleted,
|
|
11153
|
+
},
|
|
11154
|
+
]);
|
|
11155
|
+
}
|
|
11156
|
+
notifyChange({ origin, loading, error }) {
|
|
11157
|
+
var _a, _b;
|
|
11158
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11159
|
+
if (!collection)
|
|
11160
|
+
return;
|
|
11161
|
+
const data = this.applyFilter((_b = collection.data
|
|
11162
|
+
.map(id => pullFromCache(['follow', 'get', id]))
|
|
11163
|
+
.filter(isNonNullable)
|
|
11164
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
11165
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
11166
|
+
return;
|
|
11167
|
+
this.callback({
|
|
11168
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
11169
|
+
data,
|
|
11170
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
11171
|
+
loading,
|
|
11172
|
+
error,
|
|
11173
|
+
});
|
|
11174
|
+
}
|
|
11175
|
+
applyFilter(data) {
|
|
11176
|
+
let followers = data;
|
|
11177
|
+
if (this.query.status && this.query.status !== "all" /* Amity.FollowStatusTypeEnum.All */) {
|
|
11178
|
+
followers = followers.filter(follower => follower.status === this.query.status);
|
|
11179
|
+
}
|
|
11180
|
+
followers = followers.filter(follower => {
|
|
11181
|
+
var _a;
|
|
11182
|
+
const fromUser = (_a = pullFromCache(['user', 'get', follower.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
11183
|
+
return (fromUser === null || fromUser === void 0 ? void 0 : fromUser.isDeleted) == null || (fromUser === null || fromUser === void 0 ? void 0 : fromUser.isDeleted) === false;
|
|
11184
|
+
});
|
|
11185
|
+
return followers;
|
|
11186
|
+
}
|
|
11187
|
+
}
|
|
10800
11188
|
|
|
10801
11189
|
/* begin_public_function
|
|
10802
11190
|
id: user.relationship.query_my_followers, user.relationship.query_followers
|
|
@@ -10822,105 +11210,188 @@ queryFollowers.locally = (query) => queryFollows.locally('followers', query);
|
|
|
10822
11210
|
const getFollowers = (params, callback, config) => {
|
|
10823
11211
|
const { log, cache } = getActiveClient();
|
|
10824
11212
|
if (!cache) {
|
|
10825
|
-
console.log(
|
|
11213
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
10826
11214
|
}
|
|
10827
11215
|
const timestamp = Date.now();
|
|
10828
11216
|
log(`getFollowers(tmpid: ${timestamp}) > listen`);
|
|
10829
|
-
const
|
|
10830
|
-
const
|
|
10831
|
-
const
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
11217
|
+
const followerLiveCollection = new FollowerLiveCollectionController(params, callback);
|
|
11218
|
+
const disposers = followerLiveCollection.startSubscription();
|
|
11219
|
+
const cacheKey = followerLiveCollection.getCacheKey();
|
|
11220
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
11221
|
+
return () => {
|
|
11222
|
+
log(`getFollowers(tmpid: ${timestamp}) > dispose`);
|
|
11223
|
+
disposers.forEach(fn => fn());
|
|
11224
|
+
};
|
|
11225
|
+
};
|
|
11226
|
+
/* end_public_function */
|
|
11227
|
+
|
|
11228
|
+
class FollowingPaginationController extends PaginationController {
|
|
11229
|
+
async getRequest(queryParams, token) {
|
|
11230
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
11231
|
+
const options = token ? { token } : { limit };
|
|
11232
|
+
const client = getActiveClient();
|
|
11233
|
+
const path = client.userId === userId ? `/api/v4/me/following` : `/api/v4/users/${userId}/following`;
|
|
11234
|
+
const { data: queryResponse } = await this.http.get(path, {
|
|
11235
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
11236
|
+
});
|
|
11237
|
+
return queryResponse;
|
|
11238
|
+
}
|
|
11239
|
+
}
|
|
11240
|
+
|
|
11241
|
+
class FollowingQueryStreamController extends QueryStreamController {
|
|
11242
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
11243
|
+
super(query, cacheKey);
|
|
11244
|
+
this.notifyChange = notifyChange;
|
|
11245
|
+
this.preparePayload = preparePayload;
|
|
11246
|
+
}
|
|
11247
|
+
async saveToMainDB(response) {
|
|
11248
|
+
const processedPayload = await this.preparePayload(response);
|
|
11249
|
+
const client = getActiveClient();
|
|
11250
|
+
const cachedAt = client.cache && Date.now();
|
|
11251
|
+
if (client.cache) {
|
|
11252
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
11253
|
+
}
|
|
11254
|
+
}
|
|
11255
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
10835
11256
|
var _a, _b;
|
|
10836
|
-
|
|
10837
|
-
.
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
if (params.status && params.status !== 'all') {
|
|
10841
|
-
followers = filterByPropEquality(followers, 'status', params.status);
|
|
11257
|
+
if (refresh) {
|
|
11258
|
+
pushToCache(this.cacheKey, {
|
|
11259
|
+
data: response.follows.map(getResolver('follow')),
|
|
11260
|
+
});
|
|
10842
11261
|
}
|
|
10843
|
-
|
|
10844
|
-
|
|
10845
|
-
data:
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
11262
|
+
else {
|
|
11263
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11264
|
+
const follows = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
11265
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...follows, ...response.follows.map(getResolver('follow'))])] }));
|
|
11266
|
+
}
|
|
11267
|
+
}
|
|
11268
|
+
reactor(action) {
|
|
11269
|
+
return (followStatus) => {
|
|
11270
|
+
var _a;
|
|
11271
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11272
|
+
if (this.query.userId !== followStatus.from || !collection)
|
|
11273
|
+
return;
|
|
11274
|
+
switch (action) {
|
|
11275
|
+
case EnumFollowActions.OnDeclined:
|
|
11276
|
+
case EnumFollowActions.OnCanceled:
|
|
11277
|
+
case EnumFollowActions.OnUnfollowed:
|
|
11278
|
+
case EnumFollowActions.OnDeleted:
|
|
11279
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
11280
|
+
break;
|
|
11281
|
+
case EnumFollowActions.OnRequested:
|
|
11282
|
+
case EnumFollowActions.OnAccepted:
|
|
11283
|
+
case EnumFollowActions.OnFollowed:
|
|
11284
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
11285
|
+
break;
|
|
11286
|
+
}
|
|
11287
|
+
pushToCache(this.cacheKey, collection);
|
|
11288
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
11289
|
+
};
|
|
11290
|
+
}
|
|
11291
|
+
subscribeRTE(createSubscriber) {
|
|
11292
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
11293
|
+
}
|
|
11294
|
+
}
|
|
11295
|
+
|
|
11296
|
+
const onFollowingUserDeleted = ({ userId }) => (callback) => {
|
|
11297
|
+
const client = getActiveClient();
|
|
11298
|
+
const filter = (data) => {
|
|
11299
|
+
const userPayload = prepareUserPayload(data);
|
|
11300
|
+
ingestInCache(userPayload);
|
|
11301
|
+
const cacheData = pullFromCache([
|
|
11302
|
+
'follow',
|
|
11303
|
+
'get',
|
|
11304
|
+
getResolver('follow')({
|
|
11305
|
+
from: userId,
|
|
11306
|
+
to: userPayload.users[0].userId,
|
|
11307
|
+
}),
|
|
11308
|
+
]);
|
|
11309
|
+
if (!cacheData)
|
|
11310
|
+
return;
|
|
11311
|
+
callback(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data);
|
|
10850
11312
|
};
|
|
10851
|
-
|
|
11313
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
11314
|
+
};
|
|
11315
|
+
|
|
11316
|
+
class FollowingLiveCollectionController extends LiveCollectionController {
|
|
11317
|
+
constructor(query, callback) {
|
|
11318
|
+
const queryStreamId = hash__default["default"](query);
|
|
11319
|
+
const cacheKey = ['follow', 'collection', queryStreamId];
|
|
11320
|
+
const paginationController = new FollowingPaginationController(query);
|
|
11321
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
11322
|
+
this.query = query;
|
|
11323
|
+
this.queryStreamController = new FollowingQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareFollowingsPayload);
|
|
11324
|
+
this.callback = callback.bind(this);
|
|
11325
|
+
this.loadPage({ initial: true });
|
|
11326
|
+
}
|
|
11327
|
+
setup() {
|
|
10852
11328
|
var _a;
|
|
10853
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10854
|
-
if (
|
|
11329
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11330
|
+
if (!collection) {
|
|
11331
|
+
pushToCache(this.cacheKey, {
|
|
11332
|
+
data: [],
|
|
11333
|
+
params: {},
|
|
11334
|
+
});
|
|
11335
|
+
}
|
|
11336
|
+
}
|
|
11337
|
+
async persistModel(queryPayload) {
|
|
11338
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
11339
|
+
}
|
|
11340
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
11341
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
11342
|
+
}
|
|
11343
|
+
startSubscription() {
|
|
11344
|
+
return this.queryStreamController.subscribeRTE([
|
|
11345
|
+
{ fn: onFollowerRequested, action: EnumFollowActions.OnRequested },
|
|
11346
|
+
{ fn: onFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
11347
|
+
{ fn: onFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
11348
|
+
{ fn: onFollowRequestCanceled, action: EnumFollowActions.OnCanceled },
|
|
11349
|
+
{ fn: onUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
11350
|
+
{ fn: onUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
11351
|
+
{ fn: onFollowerDeleted, action: EnumFollowActions.OnDeleted },
|
|
11352
|
+
{ fn: onLocalFollowerRequested, action: EnumFollowActions.OnRequested },
|
|
11353
|
+
{ fn: onLocalFollowRequestAccepted, action: EnumFollowActions.OnAccepted },
|
|
11354
|
+
{ fn: onLocalFollowRequestDeclined, action: EnumFollowActions.OnDeclined },
|
|
11355
|
+
{ fn: onLocalUserFollowed, action: EnumFollowActions.OnFollowed },
|
|
11356
|
+
{ fn: onLocalUserUnfollowed, action: EnumFollowActions.OnUnfollowed },
|
|
11357
|
+
{
|
|
11358
|
+
fn: onFollowingUserDeleted({ userId: this.query.userId }),
|
|
11359
|
+
action: EnumFollowActions.OnUserDeleted,
|
|
11360
|
+
},
|
|
11361
|
+
]);
|
|
11362
|
+
}
|
|
11363
|
+
notifyChange({ origin, loading, error }) {
|
|
11364
|
+
var _a, _b;
|
|
11365
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11366
|
+
if (!collection)
|
|
10855
11367
|
return;
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
|
|
10859
|
-
|
|
10860
|
-
|
|
10861
|
-
}
|
|
10862
|
-
pushToCache(cacheKey, collection);
|
|
10863
|
-
responder(collection);
|
|
10864
|
-
};
|
|
10865
|
-
const onFetch = (initial = false) => {
|
|
10866
|
-
var _a, _b, _c, _d;
|
|
10867
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10868
|
-
const followers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
10869
|
-
if (!initial && followers.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
11368
|
+
const data = this.applyFilter((_b = collection.data
|
|
11369
|
+
.map(id => pullFromCache(['follow', 'get', id]))
|
|
11370
|
+
.filter(isNonNullable)
|
|
11371
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
11372
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
10870
11373
|
return;
|
|
10871
|
-
|
|
10872
|
-
|
|
10873
|
-
|
|
10874
|
-
|
|
10875
|
-
|
|
10876
|
-
|
|
10877
|
-
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
|
|
10881
|
-
|
|
10882
|
-
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
|
|
10887
|
-
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
|
|
10891
|
-
|
|
10892
|
-
};
|
|
10893
|
-
/* end_public_function */
|
|
10894
|
-
|
|
10895
|
-
/**
|
|
10896
|
-
* ```js
|
|
10897
|
-
* import { queryFollowings } from '@amityco/ts-sdk-react-native'
|
|
10898
|
-
* const { data: followings, prevPage, nextPage } = await queryFollowings({ userId })
|
|
10899
|
-
* ```
|
|
10900
|
-
*
|
|
10901
|
-
* Queries a paginable list of {@link Amity.FollowStatus}
|
|
10902
|
-
*
|
|
10903
|
-
* @param query The query parameters
|
|
10904
|
-
* @returns followings
|
|
10905
|
-
*
|
|
10906
|
-
* @category Follow API
|
|
10907
|
-
* @async
|
|
10908
|
-
*/
|
|
10909
|
-
const queryFollowings = async (query) => queryFollows('following', query);
|
|
10910
|
-
/**
|
|
10911
|
-
* ```js
|
|
10912
|
-
* import { queryFollowings } from '@amityco/ts-sdk-react-native'
|
|
10913
|
-
* const { data: followings, prevPage, nextPage } = queryFollowings.locally({ userId })
|
|
10914
|
-
* ```
|
|
10915
|
-
*
|
|
10916
|
-
* Queries a paginable list of {@link Amity.FollowStatus} objects from cache
|
|
10917
|
-
*
|
|
10918
|
-
* @param query The query parameters
|
|
10919
|
-
* @returns followings
|
|
10920
|
-
*
|
|
10921
|
-
* @category Post API
|
|
10922
|
-
*/
|
|
10923
|
-
queryFollowings.locally = (query) => queryFollows.locally('following', query);
|
|
11374
|
+
this.callback({
|
|
11375
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
11376
|
+
data,
|
|
11377
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
11378
|
+
loading,
|
|
11379
|
+
error,
|
|
11380
|
+
});
|
|
11381
|
+
}
|
|
11382
|
+
applyFilter(data) {
|
|
11383
|
+
let followings = data;
|
|
11384
|
+
if (this.query.status && this.query.status !== "all" /* Amity.FollowStatusTypeEnum.All */) {
|
|
11385
|
+
followings = followings.filter(following => following.status === this.query.status);
|
|
11386
|
+
}
|
|
11387
|
+
followings = followings.filter(following => {
|
|
11388
|
+
var _a;
|
|
11389
|
+
const toUser = (_a = pullFromCache(['user', 'get', following.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
11390
|
+
return (toUser === null || toUser === void 0 ? void 0 : toUser.isDeleted) == null || (toUser === null || toUser === void 0 ? void 0 : toUser.isDeleted) === false;
|
|
11391
|
+
});
|
|
11392
|
+
return followings;
|
|
11393
|
+
}
|
|
11394
|
+
}
|
|
10924
11395
|
|
|
10925
11396
|
/* begin_public_function
|
|
10926
11397
|
id: user.relationship.query_my_followings, user.relationship.query_followings
|
|
@@ -10950,65 +11421,10 @@ const getFollowings = (params, callback, config) => {
|
|
|
10950
11421
|
}
|
|
10951
11422
|
const timestamp = Date.now();
|
|
10952
11423
|
log(`getFollowings(tmpid: ${timestamp}) > listen`);
|
|
10953
|
-
const
|
|
10954
|
-
const
|
|
10955
|
-
const
|
|
10956
|
-
|
|
10957
|
-
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'following' }];
|
|
10958
|
-
const responder = (data) => {
|
|
10959
|
-
var _a, _b;
|
|
10960
|
-
let followings = (_a = data.data
|
|
10961
|
-
.map(key => pullFromCache(['follow', 'get', key]))
|
|
10962
|
-
.filter(Boolean)
|
|
10963
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
10964
|
-
if (params.status && params.status !== 'all') {
|
|
10965
|
-
followings = filterByPropEquality(followings, 'status', params.status);
|
|
10966
|
-
}
|
|
10967
|
-
callback({
|
|
10968
|
-
onNextPage: onFetch,
|
|
10969
|
-
data: followings,
|
|
10970
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
10971
|
-
loading: data.loading,
|
|
10972
|
-
error: data.error,
|
|
10973
|
-
});
|
|
10974
|
-
};
|
|
10975
|
-
const realtimeRouter = (action) => (followStatus) => {
|
|
10976
|
-
var _a;
|
|
10977
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10978
|
-
if (params.userId !== followStatus.from || !collection)
|
|
10979
|
-
return;
|
|
10980
|
-
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
10981
|
-
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
10982
|
-
}
|
|
10983
|
-
else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
10984
|
-
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
10985
|
-
}
|
|
10986
|
-
pushToCache(cacheKey, collection);
|
|
10987
|
-
responder(collection);
|
|
10988
|
-
};
|
|
10989
|
-
const onFetch = (initial = false) => {
|
|
10990
|
-
var _a, _b, _c, _d;
|
|
10991
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10992
|
-
const followings = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
10993
|
-
if (!initial && followings.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
10994
|
-
return;
|
|
10995
|
-
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 } }));
|
|
10996
|
-
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
10997
|
-
const data = {
|
|
10998
|
-
loading,
|
|
10999
|
-
error,
|
|
11000
|
-
params: { page },
|
|
11001
|
-
data: followings,
|
|
11002
|
-
};
|
|
11003
|
-
if (result) {
|
|
11004
|
-
data.data = [...new Set([...followings, ...result.map(getResolver('follow'))])];
|
|
11005
|
-
}
|
|
11006
|
-
pushToCache(cacheKey, data);
|
|
11007
|
-
responder(data);
|
|
11008
|
-
}, queryOptions(policy));
|
|
11009
|
-
};
|
|
11010
|
-
disposers.push(onFollowerRequested(realtimeRouter('onRequested')), onFollowRequestAccepted(realtimeRouter('onAccepted')), onFollowRequestDeclined(realtimeRouter('onDeclined')), onFollowRequestCanceled(realtimeRouter('onCanceled')), onUserFollowed(realtimeRouter('onFollowed')), onUserUnfollowed(realtimeRouter('onUnfollowed')), onFollowerDeleted(realtimeRouter('onDeleted')));
|
|
11011
|
-
onFetch(true);
|
|
11424
|
+
const followingLiveCollection = new FollowingLiveCollectionController(params, callback);
|
|
11425
|
+
const disposers = followingLiveCollection.startSubscription();
|
|
11426
|
+
const cacheKey = followingLiveCollection.getCacheKey();
|
|
11427
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
11012
11428
|
return () => {
|
|
11013
11429
|
log(`getFollowings(tmpid: ${timestamp}) > dispose`);
|
|
11014
11430
|
disposers.forEach(fn => fn());
|
|
@@ -11096,6 +11512,11 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
11096
11512
|
onFollowRequestAccepted: onFollowRequestAccepted,
|
|
11097
11513
|
onFollowRequestDeclined: onFollowRequestDeclined,
|
|
11098
11514
|
onFollowInfoUpdated: onFollowInfoUpdated,
|
|
11515
|
+
onLocalUserFollowed: onLocalUserFollowed,
|
|
11516
|
+
onLocalUserUnfollowed: onLocalUserUnfollowed,
|
|
11517
|
+
onLocalFollowerRequested: onLocalFollowerRequested,
|
|
11518
|
+
onLocalFollowRequestAccepted: onLocalFollowRequestAccepted,
|
|
11519
|
+
onLocalFollowRequestDeclined: onLocalFollowRequestDeclined,
|
|
11099
11520
|
observeFollowInfo: observeFollowInfo,
|
|
11100
11521
|
observeFollowers: observeFollowers,
|
|
11101
11522
|
observeFollowings: observeFollowings,
|
|
@@ -11130,12 +11551,13 @@ const getUserByIds = async (userIds) => {
|
|
|
11130
11551
|
const { data } = await client.http.get(`/api/v3/users/list`, {
|
|
11131
11552
|
params: { userIds: encodedUserIds },
|
|
11132
11553
|
});
|
|
11554
|
+
const payload = prepareUserPayload(data);
|
|
11133
11555
|
const cachedAt = client.cache && Date.now();
|
|
11134
11556
|
if (client.cache)
|
|
11135
|
-
ingestInCache(
|
|
11557
|
+
ingestInCache(payload, { cachedAt });
|
|
11136
11558
|
fireEvent('user.fetched', data);
|
|
11137
11559
|
return {
|
|
11138
|
-
data:
|
|
11560
|
+
data: payload.users.map(user => LinkedObject.user(user)),
|
|
11139
11561
|
cachedAt,
|
|
11140
11562
|
};
|
|
11141
11563
|
};
|
|
@@ -11193,20 +11615,14 @@ getUserByIds.locally = (userIds) => {
|
|
|
11193
11615
|
const updateUser = async (userId, patch) => {
|
|
11194
11616
|
const client = getActiveClient();
|
|
11195
11617
|
client.log('user/updateUser', userId, patch);
|
|
11196
|
-
// API-FIX: Endpoint is malformed, userId should be a url param.
|
|
11197
|
-
/*
|
|
11198
|
-
const { data } = await client.http.put<Amity.Response<UserPayload>>(
|
|
11199
|
-
`/api/v3/users/${userId}`, patch,
|
|
11200
|
-
)
|
|
11201
|
-
*/
|
|
11202
11618
|
const { data } = await client.http.put(`/api/v3/users/`, Object.assign(Object.assign({ userId }, patch), { createNewUserWhenNotFound: false }));
|
|
11619
|
+
const payload = prepareUserPayload(data);
|
|
11203
11620
|
const cachedAt = client.cache && Date.now();
|
|
11204
11621
|
if (client.cache)
|
|
11205
|
-
ingestInCache(
|
|
11206
|
-
const { users } = data;
|
|
11622
|
+
ingestInCache(payload, { cachedAt });
|
|
11207
11623
|
fireEvent('user.updated', data);
|
|
11208
11624
|
return {
|
|
11209
|
-
data: users.find(user => user.userId === userId),
|
|
11625
|
+
data: payload.users.find(user => user.userId === userId),
|
|
11210
11626
|
cachedAt,
|
|
11211
11627
|
};
|
|
11212
11628
|
};
|
|
@@ -11230,11 +11646,12 @@ const updateUser = async (userId, patch) => {
|
|
|
11230
11646
|
const flagUser = async (userId) => {
|
|
11231
11647
|
const client = getActiveClient();
|
|
11232
11648
|
client.log('user/flagUser', userId);
|
|
11233
|
-
const { data
|
|
11649
|
+
const { data } = await client.http.post(`api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
11650
|
+
const payload = prepareUserPayload(data);
|
|
11234
11651
|
if (client.cache) {
|
|
11235
11652
|
ingestInCache(payload);
|
|
11236
11653
|
}
|
|
11237
|
-
fireEvent('user.flagged',
|
|
11654
|
+
fireEvent('user.flagged', data);
|
|
11238
11655
|
return !!payload;
|
|
11239
11656
|
};
|
|
11240
11657
|
/* end_public_function */
|
|
@@ -11257,11 +11674,12 @@ const flagUser = async (userId) => {
|
|
|
11257
11674
|
const unflagUser = async (userId) => {
|
|
11258
11675
|
const client = getActiveClient();
|
|
11259
11676
|
client.log('user/unflag', userId);
|
|
11260
|
-
const { data
|
|
11677
|
+
const { data } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
11678
|
+
const payload = prepareUserPayload(data);
|
|
11261
11679
|
if (client.cache) {
|
|
11262
11680
|
ingestInCache(payload);
|
|
11263
11681
|
}
|
|
11264
|
-
fireEvent('user.unflagged',
|
|
11682
|
+
fireEvent('user.unflagged', data);
|
|
11265
11683
|
return !!payload;
|
|
11266
11684
|
};
|
|
11267
11685
|
/* end_public_function */
|
|
@@ -11289,74 +11707,6 @@ const isUserFlaggedByMe = async (userId) => {
|
|
|
11289
11707
|
};
|
|
11290
11708
|
/* end_public_function */
|
|
11291
11709
|
|
|
11292
|
-
/**
|
|
11293
|
-
* ```js
|
|
11294
|
-
* import { onUserUpdated } from '@amityco/ts-sdk-react-native'
|
|
11295
|
-
* const dispose = onUserUpdated(user => {
|
|
11296
|
-
* // ...
|
|
11297
|
-
* })
|
|
11298
|
-
* ```
|
|
11299
|
-
*
|
|
11300
|
-
* Fired when a {@link Amity.InternalUser} has been updated
|
|
11301
|
-
*
|
|
11302
|
-
* @param callback The function to call when the event was fired
|
|
11303
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11304
|
-
*
|
|
11305
|
-
* @category User Events
|
|
11306
|
-
*/
|
|
11307
|
-
const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
|
|
11308
|
-
|
|
11309
|
-
/**
|
|
11310
|
-
* ```js
|
|
11311
|
-
* import { onUserFlagged } from '@amityco/ts-sdk-react-native'
|
|
11312
|
-
* const dispose = onUserFlagged(user => {
|
|
11313
|
-
* // ...
|
|
11314
|
-
* })
|
|
11315
|
-
* ```
|
|
11316
|
-
*
|
|
11317
|
-
* Fired when a {@link Amity.InternalUser} has been flagged
|
|
11318
|
-
*
|
|
11319
|
-
* @param callback The function to call when the event was fired
|
|
11320
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11321
|
-
*
|
|
11322
|
-
* @category User Events
|
|
11323
|
-
*/
|
|
11324
|
-
const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
|
|
11325
|
-
|
|
11326
|
-
/**
|
|
11327
|
-
* ```js
|
|
11328
|
-
* import { onUserUnflagged } from '@amityco/ts-sdk-react-native'
|
|
11329
|
-
* const dispose = onUserUnflagged(user => {
|
|
11330
|
-
* // ...
|
|
11331
|
-
* })
|
|
11332
|
-
* ```
|
|
11333
|
-
*
|
|
11334
|
-
* Fired when a flag has been removed from a {@link Amity.InternalUser}
|
|
11335
|
-
*
|
|
11336
|
-
* @param callback The function to call when the event was fired
|
|
11337
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11338
|
-
*
|
|
11339
|
-
* @category User Events
|
|
11340
|
-
*/
|
|
11341
|
-
const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
|
|
11342
|
-
|
|
11343
|
-
/**
|
|
11344
|
-
* ```js
|
|
11345
|
-
* import { onUserFlagCleared } from '@amityco/ts-sdk-react-native'
|
|
11346
|
-
* const dispose = onUserFlagCleared(user => {
|
|
11347
|
-
* // ...
|
|
11348
|
-
* })
|
|
11349
|
-
* ```
|
|
11350
|
-
*
|
|
11351
|
-
* Fired when flags have been cleared for a {@link Amity.InternalUser}
|
|
11352
|
-
*
|
|
11353
|
-
* @param callback The function to call when the event was fired
|
|
11354
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11355
|
-
*
|
|
11356
|
-
* @category User Events
|
|
11357
|
-
*/
|
|
11358
|
-
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
11359
|
-
|
|
11360
11710
|
/**
|
|
11361
11711
|
* ```js
|
|
11362
11712
|
* import { onUserFetched } from '@amityco/ts-sdk-react-native'
|
|
@@ -11392,10 +11742,17 @@ const getUser$2 = async (userId) => {
|
|
|
11392
11742
|
const client = getActiveClient();
|
|
11393
11743
|
client.log('user/getUser', userId);
|
|
11394
11744
|
isInTombstone('user', userId);
|
|
11395
|
-
let data;
|
|
11396
11745
|
try {
|
|
11397
|
-
const
|
|
11398
|
-
|
|
11746
|
+
const { data } = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
|
|
11747
|
+
const cachedAt = client.cache && Date.now();
|
|
11748
|
+
const payload = prepareUserPayload(data);
|
|
11749
|
+
if (client.cache)
|
|
11750
|
+
ingestInCache(payload, { cachedAt });
|
|
11751
|
+
fireEvent('user.fetched', data);
|
|
11752
|
+
return {
|
|
11753
|
+
data: payload.users.find(user => user.userId === userId),
|
|
11754
|
+
cachedAt,
|
|
11755
|
+
};
|
|
11399
11756
|
}
|
|
11400
11757
|
catch (error) {
|
|
11401
11758
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
@@ -11403,15 +11760,6 @@ const getUser$2 = async (userId) => {
|
|
|
11403
11760
|
}
|
|
11404
11761
|
throw error;
|
|
11405
11762
|
}
|
|
11406
|
-
const cachedAt = client.cache && Date.now();
|
|
11407
|
-
if (client.cache)
|
|
11408
|
-
ingestInCache(data, { cachedAt });
|
|
11409
|
-
const { users } = data;
|
|
11410
|
-
fireEvent('user.fetched', data);
|
|
11411
|
-
return {
|
|
11412
|
-
data: users.find(user => user.userId === userId),
|
|
11413
|
-
cachedAt,
|
|
11414
|
-
};
|
|
11415
11763
|
};
|
|
11416
11764
|
/**
|
|
11417
11765
|
* ```js
|
|
@@ -11469,7 +11817,7 @@ const getUser$1 = (userId, callback) => {
|
|
|
11469
11817
|
return liveObject(userId, reactor, 'userId', getUser$2, [
|
|
11470
11818
|
onUserFetched,
|
|
11471
11819
|
onUserUpdated,
|
|
11472
|
-
onUserDeleted,
|
|
11820
|
+
onUserDeleted$2,
|
|
11473
11821
|
onUserFlagged,
|
|
11474
11822
|
onUserUnflagged,
|
|
11475
11823
|
onUserFlagCleared,
|
|
@@ -11477,114 +11825,144 @@ const getUser$1 = (userId, callback) => {
|
|
|
11477
11825
|
};
|
|
11478
11826
|
/* end_public_function */
|
|
11479
11827
|
|
|
11480
|
-
|
|
11481
|
-
|
|
11482
|
-
|
|
11483
|
-
|
|
11484
|
-
|
|
11485
|
-
|
|
11486
|
-
|
|
11487
|
-
|
|
11488
|
-
|
|
11489
|
-
|
|
11490
|
-
|
|
11491
|
-
|
|
11492
|
-
|
|
11493
|
-
|
|
11494
|
-
|
|
11495
|
-
|
|
11496
|
-
|
|
11497
|
-
|
|
11498
|
-
|
|
11499
|
-
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
// unpacking
|
|
11504
|
-
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
11505
|
-
const { users } = payload;
|
|
11506
|
-
const cachedAt = client.cache && Date.now();
|
|
11507
|
-
if (client.cache) {
|
|
11508
|
-
ingestInCache(payload, { cachedAt });
|
|
11509
|
-
/*
|
|
11510
|
-
* using a query as a cache key over params because if the keyword, filter, sort
|
|
11511
|
-
* change the API will NOT cache results, when it should
|
|
11512
|
-
*/
|
|
11513
|
-
const cacheKey = [
|
|
11514
|
-
'user',
|
|
11515
|
-
'query',
|
|
11516
|
-
Object.assign(Object.assign({}, query), { options: { limit, token: page } }),
|
|
11517
|
-
];
|
|
11518
|
-
pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
|
|
11519
|
-
}
|
|
11520
|
-
fireEvent('user.fetched', data);
|
|
11521
|
-
return {
|
|
11522
|
-
data: users,
|
|
11523
|
-
cachedAt,
|
|
11524
|
-
paging,
|
|
11525
|
-
};
|
|
11526
|
-
};
|
|
11527
|
-
/**
|
|
11528
|
-
* ```js
|
|
11529
|
-
* import { queryUsers } from '@amityco/ts-sdk-react-native'
|
|
11530
|
-
* const { data: users } = queryUsers.locally({ keyword: 'foo' })
|
|
11531
|
-
* ```
|
|
11532
|
-
*
|
|
11533
|
-
* Queries a paginable list of {@link Amity.InternalUser} objects from cache
|
|
11534
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
11535
|
-
*
|
|
11536
|
-
* @param query The query parameters
|
|
11537
|
-
* @returns A page of {@link Amity.InternalUser} objects
|
|
11538
|
-
*
|
|
11539
|
-
* @category User API
|
|
11540
|
-
*/
|
|
11541
|
-
queryUsers.locally = (query = {}) => {
|
|
11542
|
-
var _a, _b, _c;
|
|
11543
|
-
const client = getActiveClient();
|
|
11544
|
-
client.log('user/queryUsers.locally', query);
|
|
11545
|
-
if (!client.cache)
|
|
11546
|
-
return;
|
|
11547
|
-
const { limit = 10, page } = query !== null && query !== void 0 ? query : {};
|
|
11548
|
-
const cacheKey = [
|
|
11549
|
-
'user',
|
|
11550
|
-
'query',
|
|
11551
|
-
Object.assign(Object.assign({}, query), { options: {
|
|
11552
|
-
limit,
|
|
11553
|
-
token: page,
|
|
11554
|
-
} }),
|
|
11555
|
-
];
|
|
11556
|
-
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
11557
|
-
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 : [];
|
|
11558
|
-
return users.length > 0 && users.length === ((_c = data === null || data === void 0 ? void 0 : data.users) === null || _c === void 0 ? void 0 : _c.length)
|
|
11559
|
-
? {
|
|
11560
|
-
data: users,
|
|
11561
|
-
cachedAt,
|
|
11562
|
-
paging: data === null || data === void 0 ? void 0 : data.paging,
|
|
11828
|
+
class UserPaginationController extends PaginationController {
|
|
11829
|
+
async getRequest(queryParams, token) {
|
|
11830
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
11831
|
+
const options = token ? { token } : { limit };
|
|
11832
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
11833
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
11834
|
+
});
|
|
11835
|
+
return queryResponse;
|
|
11836
|
+
}
|
|
11837
|
+
}
|
|
11838
|
+
|
|
11839
|
+
class UserQueryStreamController extends QueryStreamController {
|
|
11840
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
11841
|
+
super(query, cacheKey);
|
|
11842
|
+
this.notifyChange = notifyChange;
|
|
11843
|
+
this.preparePayload = preparePayload;
|
|
11844
|
+
}
|
|
11845
|
+
async saveToMainDB(response) {
|
|
11846
|
+
const processedPayload = await this.preparePayload(response);
|
|
11847
|
+
const client = getActiveClient();
|
|
11848
|
+
const cachedAt = client.cache && Date.now();
|
|
11849
|
+
if (client.cache) {
|
|
11850
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
11563
11851
|
}
|
|
11564
|
-
|
|
11565
|
-
|
|
11852
|
+
}
|
|
11853
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
11854
|
+
var _a, _b;
|
|
11855
|
+
if (refresh) {
|
|
11856
|
+
pushToCache(this.cacheKey, {
|
|
11857
|
+
data: response.users.map(getResolver('user')),
|
|
11858
|
+
});
|
|
11859
|
+
}
|
|
11860
|
+
else {
|
|
11861
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11862
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
11863
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
11864
|
+
}
|
|
11865
|
+
}
|
|
11866
|
+
reactor(action) {
|
|
11867
|
+
return (user) => {
|
|
11868
|
+
var _a;
|
|
11869
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11870
|
+
if (!collection)
|
|
11871
|
+
return;
|
|
11872
|
+
/*
|
|
11873
|
+
* Simply update a collection and let responder decide what to do with data
|
|
11874
|
+
*/
|
|
11875
|
+
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
11876
|
+
pushToCache(this.cacheKey, collection);
|
|
11877
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
11878
|
+
};
|
|
11879
|
+
}
|
|
11880
|
+
subscribeRTE(createSubscriber) {
|
|
11881
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
11882
|
+
}
|
|
11883
|
+
}
|
|
11566
11884
|
|
|
11567
|
-
|
|
11568
|
-
|
|
11569
|
-
|
|
11570
|
-
|
|
11571
|
-
const
|
|
11572
|
-
|
|
11573
|
-
|
|
11574
|
-
|
|
11575
|
-
|
|
11576
|
-
|
|
11577
|
-
case 'lastCreated':
|
|
11578
|
-
users = users.sort(sortByLastCreated);
|
|
11579
|
-
break;
|
|
11580
|
-
default:
|
|
11581
|
-
users = users
|
|
11582
|
-
// this needs to be aligned with the backend data type
|
|
11583
|
-
.map(u => (u.displayName ? u : Object.assign(Object.assign({}, u), { displayName: '' })))
|
|
11584
|
-
.sort(sortByDisplayName);
|
|
11885
|
+
class UserLiveCollectionController extends LiveCollectionController {
|
|
11886
|
+
constructor(query, callback) {
|
|
11887
|
+
const queryStreamId = hash__default["default"](query);
|
|
11888
|
+
const cacheKey = ['user', 'collection', queryStreamId];
|
|
11889
|
+
const paginationController = new UserPaginationController(query);
|
|
11890
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
11891
|
+
this.query = query;
|
|
11892
|
+
this.queryStreamController = new UserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareUserPayload);
|
|
11893
|
+
this.callback = callback.bind(this);
|
|
11894
|
+
this.loadPage({ initial: true });
|
|
11585
11895
|
}
|
|
11586
|
-
|
|
11587
|
-
|
|
11896
|
+
setup() {
|
|
11897
|
+
var _a;
|
|
11898
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11899
|
+
if (!collection) {
|
|
11900
|
+
pushToCache(this.cacheKey, {
|
|
11901
|
+
data: [],
|
|
11902
|
+
params: {},
|
|
11903
|
+
});
|
|
11904
|
+
}
|
|
11905
|
+
}
|
|
11906
|
+
async persistModel(queryPayload) {
|
|
11907
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
11908
|
+
}
|
|
11909
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
11910
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
11911
|
+
}
|
|
11912
|
+
startSubscription() {
|
|
11913
|
+
return this.queryStreamController.subscribeRTE([
|
|
11914
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
11915
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
11916
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
11917
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
11918
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
11919
|
+
]);
|
|
11920
|
+
}
|
|
11921
|
+
notifyChange({ origin, loading, error }) {
|
|
11922
|
+
var _a, _b;
|
|
11923
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11924
|
+
if (!collection)
|
|
11925
|
+
return;
|
|
11926
|
+
const data = this.applyFilter((_b = collection.data
|
|
11927
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
11928
|
+
.filter(isNonNullable)
|
|
11929
|
+
.map(({ data }) => data)
|
|
11930
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
11931
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
11932
|
+
return;
|
|
11933
|
+
this.callback({
|
|
11934
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
11935
|
+
data,
|
|
11936
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
11937
|
+
loading,
|
|
11938
|
+
error,
|
|
11939
|
+
});
|
|
11940
|
+
}
|
|
11941
|
+
applyFilter(data) {
|
|
11942
|
+
let users = data;
|
|
11943
|
+
if (!this.query.displayName) {
|
|
11944
|
+
const sortFn = (() => {
|
|
11945
|
+
switch (this.query.sortBy) {
|
|
11946
|
+
case 'firstCreated':
|
|
11947
|
+
return sortByFirstCreated;
|
|
11948
|
+
case 'lastCreated':
|
|
11949
|
+
return sortByLastCreated;
|
|
11950
|
+
case 'displayName':
|
|
11951
|
+
return sortByDisplayName;
|
|
11952
|
+
default:
|
|
11953
|
+
return sortByLastCreated;
|
|
11954
|
+
}
|
|
11955
|
+
})();
|
|
11956
|
+
users = users.sort(sortFn);
|
|
11957
|
+
}
|
|
11958
|
+
if (this.query.filter === 'flagged') {
|
|
11959
|
+
users = users.filter(user => !!user.hashFlag);
|
|
11960
|
+
}
|
|
11961
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
11962
|
+
return users;
|
|
11963
|
+
}
|
|
11964
|
+
}
|
|
11965
|
+
|
|
11588
11966
|
/* begin_public_function
|
|
11589
11967
|
id: user.query
|
|
11590
11968
|
*/
|
|
@@ -11612,63 +11990,10 @@ const getUsers = (params, callback, config) => {
|
|
|
11612
11990
|
}
|
|
11613
11991
|
const timestamp = Date.now();
|
|
11614
11992
|
log(`liveUsers(tmpid: ${timestamp}) > listen`);
|
|
11615
|
-
const
|
|
11616
|
-
const
|
|
11617
|
-
const
|
|
11618
|
-
|
|
11619
|
-
const cacheKey = ['user', 'collection', uuid()];
|
|
11620
|
-
const responder = (data, isEventModel = false) => {
|
|
11621
|
-
var _a, _b;
|
|
11622
|
-
const users = (_a = data.data
|
|
11623
|
-
.map(userId => pullFromCache(['user', 'get', userId]))
|
|
11624
|
-
.filter(Boolean)
|
|
11625
|
-
.map(({ data }) => LinkedObject.user(data))) !== null && _a !== void 0 ? _a : [];
|
|
11626
|
-
callback({
|
|
11627
|
-
onNextPage: onFetch,
|
|
11628
|
-
/*
|
|
11629
|
-
* Only apply filter to RTE Model
|
|
11630
|
-
*/
|
|
11631
|
-
data: isEventModel ? applyFilter$2(users, params) : users,
|
|
11632
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
11633
|
-
loading: data.loading,
|
|
11634
|
-
error: data.error,
|
|
11635
|
-
});
|
|
11636
|
-
};
|
|
11637
|
-
const realtimeRouter = (_) => (user) => {
|
|
11638
|
-
var _a;
|
|
11639
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11640
|
-
if (!collection)
|
|
11641
|
-
return;
|
|
11642
|
-
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
11643
|
-
pushToCache(cacheKey, collection);
|
|
11644
|
-
responder(collection, true);
|
|
11645
|
-
};
|
|
11646
|
-
const onFetch = (initial = false) => {
|
|
11647
|
-
var _a, _b;
|
|
11648
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11649
|
-
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
11650
|
-
if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
11651
|
-
return;
|
|
11652
|
-
const pagingCondition = initial ? { limit } : { page: collection === null || collection === void 0 ? void 0 : collection.params.page };
|
|
11653
|
-
const query = createQuery(queryUsers, Object.assign(Object.assign({}, queryParams), pagingCondition));
|
|
11654
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
11655
|
-
const data = {
|
|
11656
|
-
loading,
|
|
11657
|
-
error,
|
|
11658
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
11659
|
-
data: users,
|
|
11660
|
-
};
|
|
11661
|
-
if (result) {
|
|
11662
|
-
data.data = initial
|
|
11663
|
-
? result.map(getResolver('user'))
|
|
11664
|
-
: [...new Set([...users, ...result.map(getResolver('user'))])];
|
|
11665
|
-
}
|
|
11666
|
-
pushToCache(cacheKey, data);
|
|
11667
|
-
responder(data);
|
|
11668
|
-
}, queryOptions(policy));
|
|
11669
|
-
};
|
|
11670
|
-
disposers.push(onUserUpdated(realtimeRouter()), onUserDeleted(realtimeRouter()), onUserFlagged(realtimeRouter()), onUserUnflagged(realtimeRouter()), onUserFlagCleared(realtimeRouter()));
|
|
11671
|
-
onFetch(true);
|
|
11993
|
+
const usersLiveCollection = new UserLiveCollectionController(params, callback);
|
|
11994
|
+
const disposers = usersLiveCollection.startSubscription();
|
|
11995
|
+
const cacheKey = usersLiveCollection.getCacheKey();
|
|
11996
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
11672
11997
|
return () => {
|
|
11673
11998
|
log(`liveUsers(tmpid: ${timestamp}) > dispose`);
|
|
11674
11999
|
disposers.forEach(fn => fn());
|
|
@@ -11691,27 +12016,9 @@ const getUsers = (params, callback, config) => {
|
|
|
11691
12016
|
* @async
|
|
11692
12017
|
*/
|
|
11693
12018
|
const getUser = async (userId) => {
|
|
11694
|
-
const
|
|
11695
|
-
client.log('user/getUser', userId);
|
|
11696
|
-
isInTombstone('user', userId);
|
|
11697
|
-
let data;
|
|
11698
|
-
try {
|
|
11699
|
-
const response = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
|
|
11700
|
-
data = response.data;
|
|
11701
|
-
}
|
|
11702
|
-
catch (error) {
|
|
11703
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
11704
|
-
pushToTombstone('user', userId);
|
|
11705
|
-
}
|
|
11706
|
-
throw error;
|
|
11707
|
-
}
|
|
11708
|
-
const cachedAt = client.cache && Date.now();
|
|
11709
|
-
if (client.cache)
|
|
11710
|
-
ingestInCache(data, { cachedAt });
|
|
11711
|
-
const { users } = data;
|
|
11712
|
-
fireEvent('user.fetched', data);
|
|
12019
|
+
const { data, cachedAt } = await getUser$2(userId);
|
|
11713
12020
|
return {
|
|
11714
|
-
data: LinkedObject.user(
|
|
12021
|
+
data: LinkedObject.user(data),
|
|
11715
12022
|
cachedAt,
|
|
11716
12023
|
};
|
|
11717
12024
|
};
|
|
@@ -11729,11 +12036,7 @@ const getUser = async (userId) => {
|
|
|
11729
12036
|
* @category User API
|
|
11730
12037
|
*/
|
|
11731
12038
|
getUser.locally = (userId) => {
|
|
11732
|
-
const
|
|
11733
|
-
client.log('user/getUser.locally', userId);
|
|
11734
|
-
if (!client.cache)
|
|
11735
|
-
return;
|
|
11736
|
-
const cached = pullFromCache(['user', 'get', userId]);
|
|
12039
|
+
const cached = getUser$2.locally(userId);
|
|
11737
12040
|
if (!cached)
|
|
11738
12041
|
return;
|
|
11739
12042
|
return {
|
|
@@ -11767,21 +12070,145 @@ const observeUser = (userId, callback) => {
|
|
|
11767
12070
|
// filter function
|
|
11768
12071
|
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
|
|
11769
12072
|
return;
|
|
11770
|
-
const newResult = Object.assign(Object.assign({}, result), { data: LinkedObject.user(result.data) });
|
|
11771
|
-
if (callback instanceof Function)
|
|
11772
|
-
return callback(newResult);
|
|
11773
|
-
if (action !== 'onFetch')
|
|
11774
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, newResult);
|
|
11775
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, newResult);
|
|
11776
|
-
};
|
|
11777
|
-
const disposers = [];
|
|
11778
|
-
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')));
|
|
11779
|
-
runQuery(createQuery(getUser, userId), result => result.data && router(result, 'onFetch'));
|
|
11780
|
-
return () => {
|
|
11781
|
-
log(`observeUser(tmpid: ${timestamp}) > dispose`);
|
|
11782
|
-
disposers.forEach(fn => fn());
|
|
11783
|
-
};
|
|
11784
|
-
};
|
|
12073
|
+
const newResult = Object.assign(Object.assign({}, result), { data: LinkedObject.user(result.data) });
|
|
12074
|
+
if (callback instanceof Function)
|
|
12075
|
+
return callback(newResult);
|
|
12076
|
+
if (action !== 'onFetch')
|
|
12077
|
+
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, newResult);
|
|
12078
|
+
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, newResult);
|
|
12079
|
+
};
|
|
12080
|
+
const disposers = [];
|
|
12081
|
+
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')));
|
|
12082
|
+
runQuery(createQuery(getUser, userId), result => result.data && router(result, 'onFetch'));
|
|
12083
|
+
return () => {
|
|
12084
|
+
log(`observeUser(tmpid: ${timestamp}) > dispose`);
|
|
12085
|
+
disposers.forEach(fn => fn());
|
|
12086
|
+
};
|
|
12087
|
+
};
|
|
12088
|
+
|
|
12089
|
+
class SearchUserPaginationController extends PaginationController {
|
|
12090
|
+
async getRequest(queryParams, token) {
|
|
12091
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
12092
|
+
const options = token ? { token } : { limit };
|
|
12093
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
12094
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
12095
|
+
});
|
|
12096
|
+
return queryResponse;
|
|
12097
|
+
}
|
|
12098
|
+
}
|
|
12099
|
+
|
|
12100
|
+
class SearchUserQueryStreamController extends QueryStreamController {
|
|
12101
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
12102
|
+
super(query, cacheKey);
|
|
12103
|
+
this.notifyChange = notifyChange;
|
|
12104
|
+
this.preparePayload = preparePayload;
|
|
12105
|
+
}
|
|
12106
|
+
async saveToMainDB(response) {
|
|
12107
|
+
const processedPayload = await this.preparePayload(response);
|
|
12108
|
+
const client = getActiveClient();
|
|
12109
|
+
const cachedAt = client.cache && Date.now();
|
|
12110
|
+
if (client.cache) {
|
|
12111
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
12112
|
+
}
|
|
12113
|
+
}
|
|
12114
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
12115
|
+
var _a, _b;
|
|
12116
|
+
if (refresh) {
|
|
12117
|
+
pushToCache(this.cacheKey, {
|
|
12118
|
+
data: response.users.map(getResolver('user')),
|
|
12119
|
+
});
|
|
12120
|
+
}
|
|
12121
|
+
else {
|
|
12122
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
12123
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
12124
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
12125
|
+
}
|
|
12126
|
+
}
|
|
12127
|
+
reactor(action) {
|
|
12128
|
+
return (user) => {
|
|
12129
|
+
var _a;
|
|
12130
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
12131
|
+
if (!collection)
|
|
12132
|
+
return;
|
|
12133
|
+
/*
|
|
12134
|
+
* Simply update a collection and let responder decide what to do with data
|
|
12135
|
+
*/
|
|
12136
|
+
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
12137
|
+
pushToCache(this.cacheKey, collection);
|
|
12138
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
12139
|
+
};
|
|
12140
|
+
}
|
|
12141
|
+
subscribeRTE(createSubscriber) {
|
|
12142
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
12143
|
+
}
|
|
12144
|
+
}
|
|
12145
|
+
|
|
12146
|
+
class SearchUserLiveCollectionController extends LiveCollectionController {
|
|
12147
|
+
constructor(query, callback) {
|
|
12148
|
+
var _a;
|
|
12149
|
+
const queryStreamId = hash__default["default"](query);
|
|
12150
|
+
const cacheKey = ['user', 'collection', queryStreamId];
|
|
12151
|
+
const paginationController = new SearchUserPaginationController(query);
|
|
12152
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
12153
|
+
this.query = Object.assign(Object.assign({}, query), { filter: (_a = query.filter) !== null && _a !== void 0 ? _a : 'all' });
|
|
12154
|
+
this.queryStreamController = new SearchUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareUserPayload);
|
|
12155
|
+
this.callback = callback.bind(this);
|
|
12156
|
+
this.loadPage({ initial: true });
|
|
12157
|
+
}
|
|
12158
|
+
setup() {
|
|
12159
|
+
var _a;
|
|
12160
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
12161
|
+
if (!collection) {
|
|
12162
|
+
pushToCache(this.cacheKey, {
|
|
12163
|
+
data: [],
|
|
12164
|
+
params: {},
|
|
12165
|
+
});
|
|
12166
|
+
}
|
|
12167
|
+
}
|
|
12168
|
+
async persistModel(queryPayload) {
|
|
12169
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
12170
|
+
}
|
|
12171
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
12172
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
12173
|
+
}
|
|
12174
|
+
startSubscription() {
|
|
12175
|
+
return this.queryStreamController.subscribeRTE([
|
|
12176
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
12177
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
12178
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
12179
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
12180
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
12181
|
+
]);
|
|
12182
|
+
}
|
|
12183
|
+
notifyChange({ origin, loading, error }) {
|
|
12184
|
+
var _a, _b;
|
|
12185
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
12186
|
+
if (!collection)
|
|
12187
|
+
return;
|
|
12188
|
+
const data = this.applyFilter((_b = collection.data
|
|
12189
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
12190
|
+
.filter(isNonNullable)
|
|
12191
|
+
.map(({ data }) => data)
|
|
12192
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
12193
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
12194
|
+
return;
|
|
12195
|
+
this.callback({
|
|
12196
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
12197
|
+
data,
|
|
12198
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
12199
|
+
loading,
|
|
12200
|
+
error,
|
|
12201
|
+
});
|
|
12202
|
+
}
|
|
12203
|
+
applyFilter(data) {
|
|
12204
|
+
let users = data;
|
|
12205
|
+
if (this.query.filter === 'flagged') {
|
|
12206
|
+
users = users.filter(user => !!user.hashFlag);
|
|
12207
|
+
}
|
|
12208
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
12209
|
+
return users;
|
|
12210
|
+
}
|
|
12211
|
+
}
|
|
11785
12212
|
|
|
11786
12213
|
/* begin_public_function
|
|
11787
12214
|
id: user.search
|
|
@@ -11804,7 +12231,21 @@ const observeUser = (userId, callback) => {
|
|
|
11804
12231
|
* @category Category Live Collection
|
|
11805
12232
|
*/
|
|
11806
12233
|
const searchUserByDisplayName = (params, callback, config) => {
|
|
11807
|
-
|
|
12234
|
+
const { log, cache } = getActiveClient();
|
|
12235
|
+
if (!cache) {
|
|
12236
|
+
// eslint-disable-next-line no-console
|
|
12237
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
12238
|
+
}
|
|
12239
|
+
const timestamp = Date.now();
|
|
12240
|
+
log(`liveSearchUsers(tmpid: ${timestamp}) > listen`);
|
|
12241
|
+
const searchUsersLiveCollection = new SearchUserLiveCollectionController(params, callback);
|
|
12242
|
+
const disposers = searchUsersLiveCollection.startSubscription();
|
|
12243
|
+
const cacheKey = searchUsersLiveCollection.getCacheKey();
|
|
12244
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
12245
|
+
return () => {
|
|
12246
|
+
log(`liveSearchUsers(tmpid: ${timestamp}) > dispose`);
|
|
12247
|
+
disposers.forEach(fn => fn());
|
|
12248
|
+
};
|
|
11808
12249
|
};
|
|
11809
12250
|
/* end_public_function */
|
|
11810
12251
|
|
|
@@ -11973,7 +12414,7 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
11973
12414
|
unflagUser: unflagUser,
|
|
11974
12415
|
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
11975
12416
|
onUserUpdated: onUserUpdated,
|
|
11976
|
-
onUserDeleted: onUserDeleted,
|
|
12417
|
+
onUserDeleted: onUserDeleted$2,
|
|
11977
12418
|
onUserFlagged: onUserFlagged,
|
|
11978
12419
|
onUserUnflagged: onUserUnflagged,
|
|
11979
12420
|
onUserFlagCleared: onUserFlagCleared,
|
|
@@ -12045,19 +12486,6 @@ getFile.locally = (fileId) => {
|
|
|
12045
12486
|
};
|
|
12046
12487
|
};
|
|
12047
12488
|
|
|
12048
|
-
const rebuildFormDataWithMimeType = (formData) => {
|
|
12049
|
-
const files = formData.getAll('files') || [];
|
|
12050
|
-
if (!files.length)
|
|
12051
|
-
return formData;
|
|
12052
|
-
const newFormData = new FormData();
|
|
12053
|
-
const imageFile = files[0];
|
|
12054
|
-
// In ReactNative Android, we need to define a file type for all upload items; otherwise backend will reject a request
|
|
12055
|
-
// @ts-ignore - we need to modify `type` because in android this value will not set by default (https://github.com/axios/axios/issues/4823)
|
|
12056
|
-
imageFile.type = mime__default["default"].getType(imageFile.uri);
|
|
12057
|
-
newFormData.append('files', imageFile);
|
|
12058
|
-
return newFormData;
|
|
12059
|
-
};
|
|
12060
|
-
|
|
12061
12489
|
/* begin_public_function
|
|
12062
12490
|
id: file.upload.file
|
|
12063
12491
|
*/
|
|
@@ -12088,7 +12516,7 @@ const uploadFile = async (formData, onProgress) => {
|
|
|
12088
12516
|
const headers = 'getHeaders' in formData
|
|
12089
12517
|
? formData.getHeaders()
|
|
12090
12518
|
: { 'content-type': 'multipart/form-data' };
|
|
12091
|
-
const { data } = await client.http.post('/api/v4/files',
|
|
12519
|
+
const { data } = await client.http.post('/api/v4/files', formData, {
|
|
12092
12520
|
headers,
|
|
12093
12521
|
onUploadProgress({ loaded, total = 100 }) {
|
|
12094
12522
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -12169,17 +12597,16 @@ const uploadVideo = async (formData, feedType, onProgress) => {
|
|
|
12169
12597
|
const files = formData.getAll('files');
|
|
12170
12598
|
if (!files.length)
|
|
12171
12599
|
throw new Error('The formData object must have a `files` key.');
|
|
12172
|
-
const newFormDataWithMimeType = rebuildFormDataWithMimeType(formData);
|
|
12173
12600
|
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
12174
|
-
|
|
12175
|
-
|
|
12601
|
+
formData.append('accessType', accessType);
|
|
12602
|
+
formData.append('preferredFilename', files[0].name);
|
|
12176
12603
|
if (feedType) {
|
|
12177
|
-
|
|
12604
|
+
formData.append('feedType', feedType);
|
|
12178
12605
|
}
|
|
12179
|
-
const headers = 'getHeaders' in
|
|
12180
|
-
?
|
|
12606
|
+
const headers = 'getHeaders' in formData
|
|
12607
|
+
? formData.getHeaders()
|
|
12181
12608
|
: { 'content-type': 'multipart/form-data' };
|
|
12182
|
-
const { data } = await client.http.post('/api/v4/videos',
|
|
12609
|
+
const { data } = await client.http.post('/api/v4/videos', formData, {
|
|
12183
12610
|
headers,
|
|
12184
12611
|
onUploadProgress({ loaded, total = 100 }) {
|
|
12185
12612
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -12221,14 +12648,13 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
12221
12648
|
const files = formData.getAll('files');
|
|
12222
12649
|
if (!files.length)
|
|
12223
12650
|
throw new Error('The formData object must have a `files` key.');
|
|
12224
|
-
const newFormDataWithMimeType = rebuildFormDataWithMimeType(formData);
|
|
12225
12651
|
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
12226
|
-
|
|
12227
|
-
|
|
12228
|
-
const headers = 'getHeaders' in
|
|
12229
|
-
?
|
|
12652
|
+
formData.append('accessType', accessType);
|
|
12653
|
+
formData.append('preferredFilename', files[0].name);
|
|
12654
|
+
const headers = 'getHeaders' in formData
|
|
12655
|
+
? formData.getHeaders()
|
|
12230
12656
|
: { 'content-type': 'multipart/form-data' };
|
|
12231
|
-
const { data } = await client.http.post('/api/v4/images',
|
|
12657
|
+
const { data } = await client.http.post('/api/v4/images', formData, {
|
|
12232
12658
|
headers,
|
|
12233
12659
|
onUploadProgress({ loaded, total = 100 }) {
|
|
12234
12660
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -12895,6 +13321,7 @@ const prepareCommentFromFlaggedEvent = (payload) => {
|
|
|
12895
13321
|
* @async
|
|
12896
13322
|
* */
|
|
12897
13323
|
const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
13324
|
+
var _a, _b;
|
|
12898
13325
|
const client = getActiveClient();
|
|
12899
13326
|
client.log('reaction/createReaction', {
|
|
12900
13327
|
referenceId,
|
|
@@ -12913,8 +13340,21 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
12913
13340
|
'get',
|
|
12914
13341
|
referenceId,
|
|
12915
13342
|
]);
|
|
12916
|
-
(model
|
|
12917
|
-
|
|
13343
|
+
if (!model)
|
|
13344
|
+
return true;
|
|
13345
|
+
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 }) });
|
|
13346
|
+
if (referenceType === 'comment') {
|
|
13347
|
+
fireEvent('local.comment.addReaction', {
|
|
13348
|
+
comment: updatedModel,
|
|
13349
|
+
});
|
|
13350
|
+
return true;
|
|
13351
|
+
}
|
|
13352
|
+
if (referenceType === 'post') {
|
|
13353
|
+
fireEvent('local.post.addReaction', {
|
|
13354
|
+
post: updatedModel,
|
|
13355
|
+
});
|
|
13356
|
+
return true;
|
|
13357
|
+
}
|
|
12918
13358
|
}
|
|
12919
13359
|
return true;
|
|
12920
13360
|
};
|
|
@@ -12979,6 +13419,7 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
12979
13419
|
* @async
|
|
12980
13420
|
* */
|
|
12981
13421
|
const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
13422
|
+
var _a, _b;
|
|
12982
13423
|
const client = getActiveClient();
|
|
12983
13424
|
client.log('reaction/removeReaction', {
|
|
12984
13425
|
referenceId,
|
|
@@ -12999,8 +13440,21 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
12999
13440
|
'get',
|
|
13000
13441
|
referenceId,
|
|
13001
13442
|
]);
|
|
13002
|
-
(model
|
|
13003
|
-
|
|
13443
|
+
if (!model)
|
|
13444
|
+
return true;
|
|
13445
|
+
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) }) });
|
|
13446
|
+
if (referenceType === 'comment') {
|
|
13447
|
+
fireEvent('local.comment.removeReaction', {
|
|
13448
|
+
comment: updatedModel,
|
|
13449
|
+
});
|
|
13450
|
+
return true;
|
|
13451
|
+
}
|
|
13452
|
+
if (referenceType === 'post') {
|
|
13453
|
+
fireEvent('local.post.removeReaction', {
|
|
13454
|
+
post: updatedModel,
|
|
13455
|
+
});
|
|
13456
|
+
return true;
|
|
13457
|
+
}
|
|
13004
13458
|
}
|
|
13005
13459
|
return true;
|
|
13006
13460
|
};
|
|
@@ -13045,6 +13499,66 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
13045
13499
|
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;
|
|
13046
13500
|
};
|
|
13047
13501
|
|
|
13502
|
+
const getMatchPostSetting = (value) => {
|
|
13503
|
+
var _a;
|
|
13504
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
13505
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
13506
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
13507
|
+
};
|
|
13508
|
+
function addPostSetting({ communities }) {
|
|
13509
|
+
return communities.map((_a) => {
|
|
13510
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
13511
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
13512
|
+
needApprovalOnPostCreation,
|
|
13513
|
+
onlyAdminCanPost,
|
|
13514
|
+
}) }, restCommunityPayload));
|
|
13515
|
+
});
|
|
13516
|
+
}
|
|
13517
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
13518
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
13519
|
+
// map users with community
|
|
13520
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
13521
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
13522
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
13523
|
+
});
|
|
13524
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
13525
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
13526
|
+
};
|
|
13527
|
+
const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
13528
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
13529
|
+
// map users with community
|
|
13530
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
13531
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
13532
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
13533
|
+
});
|
|
13534
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
13535
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
13536
|
+
};
|
|
13537
|
+
const prepareCommunityRequest = (params) => {
|
|
13538
|
+
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
13539
|
+
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
13540
|
+
// Convert story setting to the actual value. (Allow by default)
|
|
13541
|
+
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
13542
|
+
};
|
|
13543
|
+
|
|
13544
|
+
const preparePostPayload = (postPayload) => {
|
|
13545
|
+
// Unpack community payload by mapping payload field to postSetting value.
|
|
13546
|
+
const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
|
|
13547
|
+
// map users with community
|
|
13548
|
+
const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
|
|
13549
|
+
const user = postPayload.users.find(user => user.userId === communityUser.userId);
|
|
13550
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
13551
|
+
});
|
|
13552
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
13553
|
+
// feed type
|
|
13554
|
+
const posts = postPayload.posts.map(post => {
|
|
13555
|
+
var _a;
|
|
13556
|
+
const feedType = (_a = postPayload.feeds.find(feed => feed.feedId === post.feedId)) === null || _a === void 0 ? void 0 : _a.feedType;
|
|
13557
|
+
return Object.assign(Object.assign({}, post), { feedType });
|
|
13558
|
+
});
|
|
13559
|
+
return Object.assign(Object.assign({}, postPayload), { posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
13560
|
+
};
|
|
13561
|
+
|
|
13048
13562
|
const createPostEventSubscriber = (event, callback) => {
|
|
13049
13563
|
const client = getActiveClient();
|
|
13050
13564
|
const filter = (payload) => {
|
|
@@ -13053,8 +13567,8 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
13053
13567
|
callback(payload.posts[0]);
|
|
13054
13568
|
}
|
|
13055
13569
|
else {
|
|
13056
|
-
const
|
|
13057
|
-
const
|
|
13570
|
+
const data = preparePostPayload(payload);
|
|
13571
|
+
const { communities } = data;
|
|
13058
13572
|
ingestInCache(data);
|
|
13059
13573
|
if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['post.updated'].includes(event)) {
|
|
13060
13574
|
fireEvent('community.updated', {
|
|
@@ -13081,7 +13595,7 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
13081
13595
|
// 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
|
|
13082
13596
|
// and will got skip to notify in a previous code block
|
|
13083
13597
|
if (postedUserId !== client.userId) {
|
|
13084
|
-
|
|
13598
|
+
dropFromCache(['post', 'get', postId]);
|
|
13085
13599
|
}
|
|
13086
13600
|
return callback(payload.posts[0]);
|
|
13087
13601
|
}
|
|
@@ -13098,6 +13612,32 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
13098
13612
|
}
|
|
13099
13613
|
};
|
|
13100
13614
|
return createEventSubscriber(client, event, event, filter);
|
|
13615
|
+
};
|
|
13616
|
+
const createLocalPostEventSubscriber = (event, callback) => {
|
|
13617
|
+
const client = getActiveClient();
|
|
13618
|
+
const filter = (payload) => {
|
|
13619
|
+
if (!client.cache) {
|
|
13620
|
+
callback(payload.posts[0]);
|
|
13621
|
+
}
|
|
13622
|
+
else {
|
|
13623
|
+
const data = preparePostPayload(payload);
|
|
13624
|
+
const { communities } = data;
|
|
13625
|
+
ingestInCache(data);
|
|
13626
|
+
if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['local.post.updated'].includes(event)) {
|
|
13627
|
+
fireEvent('community.updated', {
|
|
13628
|
+
communities,
|
|
13629
|
+
categories: [],
|
|
13630
|
+
communityUsers: data.communityUsers,
|
|
13631
|
+
feeds: [],
|
|
13632
|
+
files: [],
|
|
13633
|
+
users: [],
|
|
13634
|
+
});
|
|
13635
|
+
}
|
|
13636
|
+
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
13637
|
+
callback(post.data);
|
|
13638
|
+
}
|
|
13639
|
+
};
|
|
13640
|
+
return createEventSubscriber(client, event, event, filter);
|
|
13101
13641
|
};
|
|
13102
13642
|
|
|
13103
13643
|
/**
|
|
@@ -13304,6 +13844,9 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
13304
13844
|
comments[0].commentId,
|
|
13305
13845
|
]);
|
|
13306
13846
|
if (['comment.created'].includes(event)) {
|
|
13847
|
+
// NOTE: skip adding comment to parent comment children if it's the same user since we use the local event to update instead.
|
|
13848
|
+
if (event === 'comment.created' && comment.data.userId === client.userId)
|
|
13849
|
+
return;
|
|
13307
13850
|
if (comments[0].parentId) {
|
|
13308
13851
|
const parentComment = pullFromCache([
|
|
13309
13852
|
'comment',
|
|
@@ -13325,6 +13868,58 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
13325
13868
|
}
|
|
13326
13869
|
};
|
|
13327
13870
|
return createEventSubscriber(client, event, event, filter);
|
|
13871
|
+
};
|
|
13872
|
+
const createLocalCommentEventSubscriber = (event, callback) => {
|
|
13873
|
+
const client = getActiveClient();
|
|
13874
|
+
const filter = (payload) => {
|
|
13875
|
+
var _a;
|
|
13876
|
+
if (!client.cache) {
|
|
13877
|
+
// TODO: here we are missing specific properties here!
|
|
13878
|
+
callback(LinkedObject.comment(payload.comments[0]));
|
|
13879
|
+
}
|
|
13880
|
+
else {
|
|
13881
|
+
const processed = payload;
|
|
13882
|
+
ingestInCache(processed);
|
|
13883
|
+
const { comments } = processed;
|
|
13884
|
+
if (comments.length > 0) {
|
|
13885
|
+
const comment = pullFromCache([
|
|
13886
|
+
'comment',
|
|
13887
|
+
'get',
|
|
13888
|
+
comments[0].commentId,
|
|
13889
|
+
]);
|
|
13890
|
+
if (['local.comment.created'].includes(event)) {
|
|
13891
|
+
if (comments[0].parentId) {
|
|
13892
|
+
const parentComment = pullFromCache([
|
|
13893
|
+
'comment',
|
|
13894
|
+
'get',
|
|
13895
|
+
comments[0].parentId,
|
|
13896
|
+
]);
|
|
13897
|
+
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
13898
|
+
// Skip to update parent childComment if current comment already exists
|
|
13899
|
+
if (!parentComment.data.children.includes(comments[0].commentId)) {
|
|
13900
|
+
const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber + 1, children: [...new Set([...parentComment.data.children, comments[0].commentId])] });
|
|
13901
|
+
pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
|
|
13902
|
+
setTimeout(() => {
|
|
13903
|
+
// NOTE: This is workaround solution for emitting event not work properly.
|
|
13904
|
+
fireEvent('comment.updated', {
|
|
13905
|
+
comments: [newParentComment],
|
|
13906
|
+
commentChildren: [],
|
|
13907
|
+
files: [],
|
|
13908
|
+
users: [],
|
|
13909
|
+
communityUsers: [],
|
|
13910
|
+
});
|
|
13911
|
+
}, 200);
|
|
13912
|
+
}
|
|
13913
|
+
}
|
|
13914
|
+
}
|
|
13915
|
+
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; });
|
|
13916
|
+
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
13917
|
+
}
|
|
13918
|
+
callback(LinkedObject.comment(comment.data));
|
|
13919
|
+
}
|
|
13920
|
+
}
|
|
13921
|
+
};
|
|
13922
|
+
return createEventSubscriber(client, event, event, filter);
|
|
13328
13923
|
};
|
|
13329
13924
|
|
|
13330
13925
|
/**
|
|
@@ -13884,29 +14479,53 @@ var index$h = /*#__PURE__*/Object.freeze({
|
|
|
13884
14479
|
getReactions: getReactions
|
|
13885
14480
|
});
|
|
13886
14481
|
|
|
13887
|
-
|
|
13888
|
-
|
|
13889
|
-
|
|
13890
|
-
|
|
13891
|
-
|
|
13892
|
-
|
|
13893
|
-
|
|
13894
|
-
|
|
13895
|
-
|
|
13896
|
-
|
|
13897
|
-
},
|
|
13898
|
-
message: {
|
|
13899
|
-
domainName: 'messages',
|
|
13900
|
-
eventName: 'v3/message.isFlaggedByMe',
|
|
13901
|
-
primaryKey: 'messageId',
|
|
13902
|
-
},
|
|
13903
|
-
user: {
|
|
13904
|
-
domainName: 'users',
|
|
13905
|
-
eventName: 'user.isFlagByMe',
|
|
13906
|
-
primaryKey: 'userId',
|
|
13907
|
-
},
|
|
13908
|
-
};
|
|
14482
|
+
function prepareCommentPayload(commentPayload) {
|
|
14483
|
+
const { comments } = commentPayload;
|
|
14484
|
+
return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
|
|
14485
|
+
if (comment.hasOwnProperty('myReactions'))
|
|
14486
|
+
return comment;
|
|
14487
|
+
// Sometimes `myReactions` field will not come with BE response because that field is empty
|
|
14488
|
+
// We need to put it with an empty array manually to make it show up in client side
|
|
14489
|
+
return Object.assign({ myReactions: [] }, comment);
|
|
14490
|
+
}) });
|
|
14491
|
+
}
|
|
13909
14492
|
|
|
14493
|
+
const createMessageReport = async ({ client, referenceId, }) => {
|
|
14494
|
+
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
14495
|
+
if (client.cache) {
|
|
14496
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
14497
|
+
ingestInCache(messagePayload);
|
|
14498
|
+
}
|
|
14499
|
+
fireEvent(`message.flagged`, payload);
|
|
14500
|
+
return !!payload;
|
|
14501
|
+
};
|
|
14502
|
+
const createPostReport = async ({ client, referenceId, }) => {
|
|
14503
|
+
const { data: payload } = await client.http.post(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
|
|
14504
|
+
if (client.cache) {
|
|
14505
|
+
const postPayload = await preparePostPayload(payload);
|
|
14506
|
+
ingestInCache(postPayload);
|
|
14507
|
+
}
|
|
14508
|
+
fireEvent(`post.flagged`, payload);
|
|
14509
|
+
return !!payload;
|
|
14510
|
+
};
|
|
14511
|
+
const createUserReport = async ({ client, referenceId, }) => {
|
|
14512
|
+
const { data: payload } = await client.http.post(`/api/v4/me/flags/${encodeURIComponent(referenceId)}`);
|
|
14513
|
+
if (client.cache) {
|
|
14514
|
+
const userPayload = await prepareUserPayload(payload);
|
|
14515
|
+
ingestInCache(userPayload);
|
|
14516
|
+
}
|
|
14517
|
+
fireEvent(`user.flagged`, payload);
|
|
14518
|
+
return !!payload;
|
|
14519
|
+
};
|
|
14520
|
+
const createCommentReport = async ({ client, referenceId, }) => {
|
|
14521
|
+
const { data: payload } = await client.http.post(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
|
|
14522
|
+
if (client.cache) {
|
|
14523
|
+
const commentPayload = await prepareCommentPayload(payload);
|
|
14524
|
+
ingestInCache(commentPayload);
|
|
14525
|
+
}
|
|
14526
|
+
fireEvent(`comment.flagged`, payload);
|
|
14527
|
+
return !!payload;
|
|
14528
|
+
};
|
|
13910
14529
|
/**
|
|
13911
14530
|
* ```js
|
|
13912
14531
|
* import { createReport } from '@amityco/ts-sdk-react-native'
|
|
@@ -13923,33 +14542,57 @@ var REFERENCE_TYPES = {
|
|
|
13923
14542
|
const createReport = async (referenceType, referenceId) => {
|
|
13924
14543
|
const client = getActiveClient();
|
|
13925
14544
|
client.log('report/createReport', { referenceType, referenceId });
|
|
13926
|
-
|
|
13927
|
-
|
|
13928
|
-
return `/api/v4/me/flags/${encodeURIComponent(referenceId)}`;
|
|
13929
|
-
}
|
|
13930
|
-
if (referenceType === 'message') {
|
|
13931
|
-
return `/api/v5/messages/${encodeURIComponent(referenceId)}/flags`;
|
|
13932
|
-
}
|
|
13933
|
-
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
13934
|
-
return `/api/v3/${domainName}/${encodeURIComponent(referenceId)}/flag`;
|
|
13935
|
-
};
|
|
13936
|
-
const { data: payload } = await client.http.post(getAPIUrl());
|
|
13937
|
-
if (client.cache) {
|
|
13938
|
-
if (referenceType === 'message') {
|
|
13939
|
-
const messagePayload = await prepareMessagePayload(payload);
|
|
13940
|
-
ingestInCache(messagePayload);
|
|
13941
|
-
}
|
|
13942
|
-
else if (referenceType === 'post') {
|
|
13943
|
-
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
13944
|
-
}
|
|
13945
|
-
else {
|
|
13946
|
-
ingestInCache(payload);
|
|
13947
|
-
}
|
|
14545
|
+
if (referenceType === 'user') {
|
|
14546
|
+
return createUserReport({ client, referenceId });
|
|
13948
14547
|
}
|
|
13949
|
-
|
|
13950
|
-
|
|
14548
|
+
if (referenceType === 'message') {
|
|
14549
|
+
return createMessageReport({ client, referenceId });
|
|
14550
|
+
}
|
|
14551
|
+
if (referenceType === 'post') {
|
|
14552
|
+
return createPostReport({ client, referenceId });
|
|
14553
|
+
}
|
|
14554
|
+
if (referenceType === 'comment') {
|
|
14555
|
+
return createCommentReport({ client, referenceId });
|
|
14556
|
+
}
|
|
14557
|
+
return false;
|
|
13951
14558
|
};
|
|
13952
14559
|
|
|
14560
|
+
const deleteMessageReport = async ({ client, referenceId, }) => {
|
|
14561
|
+
const { data: payload } = await client.http.delete(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
14562
|
+
if (client.cache) {
|
|
14563
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
14564
|
+
ingestInCache(messagePayload);
|
|
14565
|
+
}
|
|
14566
|
+
fireEvent(`message.unflagged`, payload);
|
|
14567
|
+
return !!payload;
|
|
14568
|
+
};
|
|
14569
|
+
const deletePostReport = async ({ client, referenceId, }) => {
|
|
14570
|
+
const { data: payload } = await client.http.delete(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
|
|
14571
|
+
if (client.cache) {
|
|
14572
|
+
const postPayload = await preparePostPayload(payload);
|
|
14573
|
+
ingestInCache(postPayload);
|
|
14574
|
+
}
|
|
14575
|
+
fireEvent(`post.unflagged`, payload);
|
|
14576
|
+
return !!payload;
|
|
14577
|
+
};
|
|
14578
|
+
const deleteUserReport = async ({ client, referenceId, }) => {
|
|
14579
|
+
const { data: payload } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(referenceId)}`);
|
|
14580
|
+
if (client.cache) {
|
|
14581
|
+
const userPayload = await prepareUserPayload(payload);
|
|
14582
|
+
ingestInCache(userPayload);
|
|
14583
|
+
}
|
|
14584
|
+
fireEvent(`user.unflagged`, payload);
|
|
14585
|
+
return !!payload;
|
|
14586
|
+
};
|
|
14587
|
+
const deleteCommentReport = async ({ client, referenceId, }) => {
|
|
14588
|
+
const { data: payload } = await client.http.delete(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
|
|
14589
|
+
if (client.cache) {
|
|
14590
|
+
const commentPayload = await prepareCommentPayload(payload);
|
|
14591
|
+
ingestInCache(commentPayload);
|
|
14592
|
+
}
|
|
14593
|
+
fireEvent(`comment.unflagged`, payload);
|
|
14594
|
+
return !!payload;
|
|
14595
|
+
};
|
|
13953
14596
|
/**
|
|
13954
14597
|
* ```js
|
|
13955
14598
|
* import { deleteReport } from '@amityco/ts-sdk-react-native'
|
|
@@ -13966,34 +14609,45 @@ const createReport = async (referenceType, referenceId) => {
|
|
|
13966
14609
|
const deleteReport = async (referenceType, referenceId) => {
|
|
13967
14610
|
const client = getActiveClient();
|
|
13968
14611
|
client.log('report/deleteReport', { referenceType, referenceId });
|
|
13969
|
-
|
|
13970
|
-
|
|
13971
|
-
return `/api/v4/me/flags/${encodeURIComponent(referenceId)}`;
|
|
13972
|
-
}
|
|
13973
|
-
if (referenceType === 'message') {
|
|
13974
|
-
return `/api/v5/messages/${encodeURIComponent(referenceId)}/flags`;
|
|
13975
|
-
}
|
|
13976
|
-
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
13977
|
-
return `/api/v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`;
|
|
13978
|
-
};
|
|
13979
|
-
const { data: payload } = await client.http.delete(getAPIUrl());
|
|
13980
|
-
if (client.cache) {
|
|
13981
|
-
if (referenceType === 'message') {
|
|
13982
|
-
const messagePayload = await prepareMessagePayload(payload);
|
|
13983
|
-
ingestInCache(messagePayload);
|
|
13984
|
-
}
|
|
13985
|
-
else if (referenceType === 'post') {
|
|
13986
|
-
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
13987
|
-
}
|
|
13988
|
-
else {
|
|
13989
|
-
ingestInCache(payload);
|
|
13990
|
-
}
|
|
14612
|
+
if (referenceType === 'user') {
|
|
14613
|
+
return deleteUserReport({ client, referenceId });
|
|
13991
14614
|
}
|
|
13992
|
-
|
|
13993
|
-
|
|
13994
|
-
|
|
14615
|
+
if (referenceType === 'message') {
|
|
14616
|
+
return deleteMessageReport({ client, referenceId });
|
|
14617
|
+
}
|
|
14618
|
+
if (referenceType === 'post') {
|
|
14619
|
+
return deletePostReport({ client, referenceId });
|
|
14620
|
+
}
|
|
14621
|
+
if (referenceType === 'comment') {
|
|
14622
|
+
return deleteCommentReport({ client, referenceId });
|
|
14623
|
+
}
|
|
14624
|
+
return false;
|
|
13995
14625
|
};
|
|
13996
14626
|
|
|
14627
|
+
const getMessageReport = async ({ client, referenceId, }) => {
|
|
14628
|
+
var _a;
|
|
14629
|
+
const { data } = await client.http.get(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
14630
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
14631
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
14632
|
+
};
|
|
14633
|
+
const getPostReport = async ({ client, referenceId, }) => {
|
|
14634
|
+
var _a;
|
|
14635
|
+
const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
|
|
14636
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
14637
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
14638
|
+
};
|
|
14639
|
+
const getUserReport = async ({ client, referenceId, }) => {
|
|
14640
|
+
var _a;
|
|
14641
|
+
const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
|
|
14642
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
14643
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
14644
|
+
};
|
|
14645
|
+
const getCommentReport = async ({ client, referenceId, }) => {
|
|
14646
|
+
var _a;
|
|
14647
|
+
const { data } = await client.http.get(`/api/v3/comment/${referenceId}/isflagbyme`);
|
|
14648
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
14649
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
14650
|
+
};
|
|
13997
14651
|
/**
|
|
13998
14652
|
* ```js
|
|
13999
14653
|
* import { isReportedByMe } from '@amityco/ts-sdk-react-native'
|
|
@@ -14008,17 +14662,21 @@ const deleteReport = async (referenceType, referenceId) => {
|
|
|
14008
14662
|
* @async
|
|
14009
14663
|
* */
|
|
14010
14664
|
const isReportedByMe = async (referenceType, referenceId) => {
|
|
14011
|
-
var _a;
|
|
14012
14665
|
const client = getActiveClient();
|
|
14013
14666
|
client.log('report/isReportedByMe', { referenceType, referenceId });
|
|
14014
|
-
|
|
14667
|
+
if (referenceType === 'user') {
|
|
14668
|
+
return getUserReport({ client, referenceId });
|
|
14669
|
+
}
|
|
14015
14670
|
if (referenceType === 'message') {
|
|
14016
|
-
|
|
14017
|
-
return data.result;
|
|
14671
|
+
return getMessageReport({ client, referenceId });
|
|
14018
14672
|
}
|
|
14019
|
-
|
|
14020
|
-
|
|
14021
|
-
|
|
14673
|
+
if (referenceType === 'post') {
|
|
14674
|
+
return getPostReport({ client, referenceId });
|
|
14675
|
+
}
|
|
14676
|
+
if (referenceType === 'comment') {
|
|
14677
|
+
return getCommentReport({ client, referenceId });
|
|
14678
|
+
}
|
|
14679
|
+
return false;
|
|
14022
14680
|
};
|
|
14023
14681
|
|
|
14024
14682
|
/* begin_public_function
|
|
@@ -15539,116 +16197,6 @@ const getMessage$1 = (messageId, callback) => {
|
|
|
15539
16197
|
};
|
|
15540
16198
|
/* end_public_function */
|
|
15541
16199
|
|
|
15542
|
-
class PaginationNoPageController {
|
|
15543
|
-
constructor(queryParams) {
|
|
15544
|
-
const { http } = getActiveClient();
|
|
15545
|
-
this.queryParams = queryParams;
|
|
15546
|
-
this.http = http;
|
|
15547
|
-
}
|
|
15548
|
-
async onFetch() {
|
|
15549
|
-
const queryResponse = await this.getRequest(this.queryParams);
|
|
15550
|
-
return queryResponse;
|
|
15551
|
-
}
|
|
15552
|
-
}
|
|
15553
|
-
|
|
15554
|
-
class LiveCollectionController {
|
|
15555
|
-
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
15556
|
-
this.paginationController = paginationController;
|
|
15557
|
-
this.queryStreamId = queryStreamId;
|
|
15558
|
-
this.cacheKey = cacheKey;
|
|
15559
|
-
this.callback = callback;
|
|
15560
|
-
}
|
|
15561
|
-
async refresh() {
|
|
15562
|
-
try {
|
|
15563
|
-
let result;
|
|
15564
|
-
if (this.paginationController instanceof PaginationNoPageController) {
|
|
15565
|
-
result = await this.paginationController.onFetch();
|
|
15566
|
-
}
|
|
15567
|
-
else {
|
|
15568
|
-
result = await this.paginationController.loadFirstPage();
|
|
15569
|
-
}
|
|
15570
|
-
if (!result)
|
|
15571
|
-
return;
|
|
15572
|
-
await this.persistModel(result);
|
|
15573
|
-
this.persistQueryStream({
|
|
15574
|
-
response: result,
|
|
15575
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
15576
|
-
refresh: true,
|
|
15577
|
-
});
|
|
15578
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
15579
|
-
}
|
|
15580
|
-
catch (e) {
|
|
15581
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
15582
|
-
}
|
|
15583
|
-
}
|
|
15584
|
-
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
15585
|
-
this.setup();
|
|
15586
|
-
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
15587
|
-
if (initial) {
|
|
15588
|
-
this.refresh();
|
|
15589
|
-
}
|
|
15590
|
-
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
15591
|
-
this.loadPrevPage();
|
|
15592
|
-
}
|
|
15593
|
-
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
15594
|
-
this.loadNextPage();
|
|
15595
|
-
}
|
|
15596
|
-
}
|
|
15597
|
-
async loadNextPage() {
|
|
15598
|
-
try {
|
|
15599
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
15600
|
-
return;
|
|
15601
|
-
const result = await this.paginationController.loadNextPage();
|
|
15602
|
-
if (!result)
|
|
15603
|
-
return;
|
|
15604
|
-
await this.persistModel(result);
|
|
15605
|
-
this.persistQueryStream({
|
|
15606
|
-
response: result,
|
|
15607
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
15608
|
-
});
|
|
15609
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
15610
|
-
}
|
|
15611
|
-
catch (e) {
|
|
15612
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
15613
|
-
}
|
|
15614
|
-
}
|
|
15615
|
-
async loadPrevPage() {
|
|
15616
|
-
try {
|
|
15617
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
15618
|
-
return;
|
|
15619
|
-
const result = await this.paginationController.loadPreviousPage();
|
|
15620
|
-
if (!result)
|
|
15621
|
-
return;
|
|
15622
|
-
await this.persistModel(result);
|
|
15623
|
-
this.persistQueryStream({
|
|
15624
|
-
response: result,
|
|
15625
|
-
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
15626
|
-
});
|
|
15627
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
15628
|
-
}
|
|
15629
|
-
catch (e) {
|
|
15630
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
15631
|
-
}
|
|
15632
|
-
}
|
|
15633
|
-
shouldNotify(data) {
|
|
15634
|
-
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
15635
|
-
if (isEqual(this.snapshot, newData))
|
|
15636
|
-
return false;
|
|
15637
|
-
this.snapshot = newData;
|
|
15638
|
-
return true;
|
|
15639
|
-
}
|
|
15640
|
-
getCacheKey() {
|
|
15641
|
-
return this.cacheKey;
|
|
15642
|
-
}
|
|
15643
|
-
}
|
|
15644
|
-
|
|
15645
|
-
class QueryStreamController {
|
|
15646
|
-
constructor(query, cacheKey) {
|
|
15647
|
-
this.query = query;
|
|
15648
|
-
this.cacheKey = cacheKey;
|
|
15649
|
-
}
|
|
15650
|
-
}
|
|
15651
|
-
|
|
15652
16200
|
/* eslint-disable no-use-before-define */
|
|
15653
16201
|
class MessageQueryStreamController extends QueryStreamController {
|
|
15654
16202
|
constructor(query, cacheKey, notifyChange, preparePayload, paginationController) {
|
|
@@ -15731,51 +16279,6 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
15731
16279
|
}
|
|
15732
16280
|
}
|
|
15733
16281
|
|
|
15734
|
-
class PaginationController {
|
|
15735
|
-
constructor(queryParams) {
|
|
15736
|
-
const { http } = getActiveClient();
|
|
15737
|
-
this.queryParams = queryParams;
|
|
15738
|
-
this.http = http;
|
|
15739
|
-
}
|
|
15740
|
-
loadFirstPage() {
|
|
15741
|
-
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
15742
|
-
}
|
|
15743
|
-
loadNextPage() {
|
|
15744
|
-
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
15745
|
-
}
|
|
15746
|
-
loadPreviousPage() {
|
|
15747
|
-
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
15748
|
-
}
|
|
15749
|
-
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
15750
|
-
var _a, _b, _c, _d;
|
|
15751
|
-
if (direction === 'prev' && !this.previousToken)
|
|
15752
|
-
return;
|
|
15753
|
-
if (direction === 'next' && !this.nextToken)
|
|
15754
|
-
return;
|
|
15755
|
-
let token;
|
|
15756
|
-
if (direction === 'prev')
|
|
15757
|
-
token = this.previousToken;
|
|
15758
|
-
if (direction === 'next')
|
|
15759
|
-
token = this.nextToken;
|
|
15760
|
-
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
15761
|
-
if (direction === 'first') {
|
|
15762
|
-
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
15763
|
-
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
15764
|
-
}
|
|
15765
|
-
if (direction === 'prev')
|
|
15766
|
-
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
15767
|
-
if (direction === 'next')
|
|
15768
|
-
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
15769
|
-
return queryResponse;
|
|
15770
|
-
}
|
|
15771
|
-
getNextToken() {
|
|
15772
|
-
return this.nextToken;
|
|
15773
|
-
}
|
|
15774
|
-
getPrevToken() {
|
|
15775
|
-
return this.previousToken;
|
|
15776
|
-
}
|
|
15777
|
-
}
|
|
15778
|
-
|
|
15779
16282
|
/* eslint-disable no-use-before-define */
|
|
15780
16283
|
/**
|
|
15781
16284
|
* TODO: handle cache receive cache option, and cache policy
|
|
@@ -17567,10 +18070,12 @@ const removeMembers$1 = async (channelId, userIds) => {
|
|
|
17567
18070
|
*/
|
|
17568
18071
|
class ChannelMemberPaginationController extends PaginationController {
|
|
17569
18072
|
async getRequest(queryParams, token) {
|
|
17570
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
18073
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
17571
18074
|
const options = token ? { token } : { limit };
|
|
18075
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
17572
18076
|
const { data: queryResponse } = await this.http.get(`/api/v4/channels/${encodeURIComponent(params.channelId)}/users`, {
|
|
17573
|
-
params: Object.assign(Object.assign({}, params), { options
|
|
18077
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
18078
|
+
isDeleted }),
|
|
17574
18079
|
});
|
|
17575
18080
|
return queryResponse;
|
|
17576
18081
|
}
|
|
@@ -17636,6 +18141,33 @@ class ChannelMemberQueryStreamController extends QueryStreamController {
|
|
|
17636
18141
|
}
|
|
17637
18142
|
}
|
|
17638
18143
|
|
|
18144
|
+
const onUserDeleted$1 = (channelId) => (callback) => {
|
|
18145
|
+
const client = getActiveClient();
|
|
18146
|
+
const filter = (payload) => {
|
|
18147
|
+
var _a, _b;
|
|
18148
|
+
const userPayload = prepareUserPayload(payload);
|
|
18149
|
+
if (userPayload.users.length === 0)
|
|
18150
|
+
return;
|
|
18151
|
+
const user = userPayload.users[0];
|
|
18152
|
+
ingestInCache(userPayload);
|
|
18153
|
+
const channelUserCacheKey = getResolver('channelUsers')({
|
|
18154
|
+
channelId,
|
|
18155
|
+
userId: user.userId,
|
|
18156
|
+
});
|
|
18157
|
+
const cacheData = (_a = pullFromCache([
|
|
18158
|
+
'channelUsers',
|
|
18159
|
+
'get',
|
|
18160
|
+
channelUserCacheKey,
|
|
18161
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
18162
|
+
upsertInCache(['channelUsers', 'get', channelUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
|
|
18163
|
+
const channel = (_b = pullFromCache(['channel', 'get', channelId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
18164
|
+
if (!channel)
|
|
18165
|
+
return;
|
|
18166
|
+
callback(channel, cacheData);
|
|
18167
|
+
};
|
|
18168
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
18169
|
+
};
|
|
18170
|
+
|
|
17639
18171
|
/* eslint-disable no-use-before-define */
|
|
17640
18172
|
class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
17641
18173
|
constructor(query, callback) {
|
|
@@ -17674,6 +18206,7 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
17674
18206
|
{ fn: onChannelMemberUnbanned, action: 'onChannelMemberUnbanned' },
|
|
17675
18207
|
{ fn: onChannelMemberRoleAdded, action: 'onChannelMemberRoleAdded' },
|
|
17676
18208
|
{ fn: onChannelMemberRoleRemoved, action: 'onChannelMemberRoleRemoved' },
|
|
18209
|
+
{ fn: onUserDeleted$1(this.query.channelId), action: 'onChannelMemberChanged' },
|
|
17677
18210
|
]);
|
|
17678
18211
|
}
|
|
17679
18212
|
notifyChange({ origin, loading, error }) {
|
|
@@ -17720,6 +18253,9 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
17720
18253
|
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.');
|
|
17721
18254
|
channelMembers = filterBySearchTerm(channelMembers, this.query.search);
|
|
17722
18255
|
}
|
|
18256
|
+
if (this.query.includeDeleted === false) {
|
|
18257
|
+
channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted) !== true; });
|
|
18258
|
+
}
|
|
17723
18259
|
// sort, 'lastCreated' is the default sort order
|
|
17724
18260
|
const sortBy = this.query.sortBy ? this.query.sortBy : 'lastCreated';
|
|
17725
18261
|
channelMembers = channelMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
@@ -18087,57 +18623,6 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
18087
18623
|
});
|
|
18088
18624
|
};
|
|
18089
18625
|
|
|
18090
|
-
const getMatchPostSetting = (value) => {
|
|
18091
|
-
var _a;
|
|
18092
|
-
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
18093
|
-
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
18094
|
-
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
18095
|
-
};
|
|
18096
|
-
const convertCommunityUsersToUniqueObject = (communityUsers) => {
|
|
18097
|
-
if (!communityUsers)
|
|
18098
|
-
return communityUsers;
|
|
18099
|
-
const result = {};
|
|
18100
|
-
communityUsers.forEach(user => {
|
|
18101
|
-
result[`${user.userId}#${user.communityId}`] = user;
|
|
18102
|
-
});
|
|
18103
|
-
return result;
|
|
18104
|
-
};
|
|
18105
|
-
const convertCommunityPayload = (rawPayload) => {
|
|
18106
|
-
// Unpack community payload by mapping payload field to postSetting value.
|
|
18107
|
-
const communities = rawPayload.communities.map((_a) => {
|
|
18108
|
-
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
18109
|
-
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
18110
|
-
needApprovalOnPostCreation,
|
|
18111
|
-
onlyAdminCanPost,
|
|
18112
|
-
}) }, restCommunityPayload));
|
|
18113
|
-
});
|
|
18114
|
-
const mergeCommunityUsers = communities.reduce((acc, { communityId }) => {
|
|
18115
|
-
var _a;
|
|
18116
|
-
const users = (_a = pullFromCache([
|
|
18117
|
-
'communityUsers',
|
|
18118
|
-
'collection',
|
|
18119
|
-
communityId,
|
|
18120
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
18121
|
-
if (!users)
|
|
18122
|
-
return acc;
|
|
18123
|
-
return Object.assign(Object.assign({}, convertCommunityUsersToUniqueObject(users)), acc);
|
|
18124
|
-
}, convertCommunityUsersToUniqueObject(rawPayload.communityUsers));
|
|
18125
|
-
const communityUsers = withUsers(Object.values(mergeCommunityUsers));
|
|
18126
|
-
const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
|
|
18127
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
|
|
18128
|
-
};
|
|
18129
|
-
const prepareCommunityPayload = (rawPayload) => {
|
|
18130
|
-
const { communities, communityUsers } = convertCommunityPayload(rawPayload);
|
|
18131
|
-
return Object.assign(Object.assign({}, rawPayload), { communities,
|
|
18132
|
-
communityUsers });
|
|
18133
|
-
};
|
|
18134
|
-
const prepareCommunityRequest = (params) => {
|
|
18135
|
-
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
18136
|
-
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
18137
|
-
// Convert story setting to the actual value. (Allow by default)
|
|
18138
|
-
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
18139
|
-
};
|
|
18140
|
-
|
|
18141
18626
|
/**
|
|
18142
18627
|
* ```js
|
|
18143
18628
|
* import { getCommunities } from '@amityco/ts-sdk-react-native'
|
|
@@ -18573,10 +19058,6 @@ const onCommunityUpdated = (callback) => createCommunityEventSubscriber('communi
|
|
|
18573
19058
|
*/
|
|
18574
19059
|
const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
|
|
18575
19060
|
|
|
18576
|
-
function isNonNullable(value) {
|
|
18577
|
-
return value != null;
|
|
18578
|
-
}
|
|
18579
|
-
|
|
18580
19061
|
function hasPermission(member, payload, permission) {
|
|
18581
19062
|
if (member.permissions.some(x => x === permission)) {
|
|
18582
19063
|
return true;
|
|
@@ -18591,7 +19072,7 @@ function getEventRelatedMember(event, payload) {
|
|
|
18591
19072
|
}
|
|
18592
19073
|
// NOTE: backend returns the one who took the action and the one on whom
|
|
18593
19074
|
// the action was taken. We need the 2nd one
|
|
18594
|
-
if (event === 'community.userRemoved') {
|
|
19075
|
+
if (event === 'community.userRemoved' || event === 'local.community.userRemoved') {
|
|
18595
19076
|
return payload.communityUsers.filter(x => x.communityMembership === 'none');
|
|
18596
19077
|
}
|
|
18597
19078
|
if (event === 'community.userBanned') {
|
|
@@ -18639,6 +19120,43 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
|
|
|
18639
19120
|
}
|
|
18640
19121
|
};
|
|
18641
19122
|
return createEventSubscriber(client, event, event, filter);
|
|
19123
|
+
};
|
|
19124
|
+
const createLocalCommunityMemberEventSubscriber = (event, callback) => {
|
|
19125
|
+
const client = getActiveClient();
|
|
19126
|
+
const filter = (payload) => {
|
|
19127
|
+
const preparedPayload = prepareCommunityPayload(payload);
|
|
19128
|
+
const { communities, communityUsers } = preparedPayload;
|
|
19129
|
+
/*
|
|
19130
|
+
* community.isJoined is not part of the communityMembership payload, and needs
|
|
19131
|
+
* to be calculated based on the communityMembership value
|
|
19132
|
+
*/
|
|
19133
|
+
const communitiesWithMembership = updateMembershipStatus(communities, communityUsers);
|
|
19134
|
+
preparedPayload.communities = communitiesWithMembership;
|
|
19135
|
+
if (!client.cache) {
|
|
19136
|
+
// TODO: here we are missing specific properties here!
|
|
19137
|
+
callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
|
|
19138
|
+
}
|
|
19139
|
+
else {
|
|
19140
|
+
ingestInCache(preparedPayload);
|
|
19141
|
+
const community = pullFromCache([
|
|
19142
|
+
'community',
|
|
19143
|
+
'get',
|
|
19144
|
+
preparedPayload.communities[0].communityId,
|
|
19145
|
+
]);
|
|
19146
|
+
const members = getEventRelatedMember(event, preparedPayload)
|
|
19147
|
+
.map(member => {
|
|
19148
|
+
const memberCache = pullFromCache([
|
|
19149
|
+
'communityUsers',
|
|
19150
|
+
'get',
|
|
19151
|
+
getResolver('communityUsers')(member),
|
|
19152
|
+
]);
|
|
19153
|
+
return memberCache === null || memberCache === void 0 ? void 0 : memberCache.data;
|
|
19154
|
+
})
|
|
19155
|
+
.filter(isNonNullable);
|
|
19156
|
+
callback(community.data, members);
|
|
19157
|
+
}
|
|
19158
|
+
};
|
|
19159
|
+
return createEventSubscriber(client, event, event, filter);
|
|
18642
19160
|
};
|
|
18643
19161
|
|
|
18644
19162
|
/**
|
|
@@ -18760,6 +19278,40 @@ const onCommunityUserRoleAdded = (callback) => createCommunityMemberEventSubscri
|
|
|
18760
19278
|
*/
|
|
18761
19279
|
const onCommunityUserRoleRemoved = (callback) => createCommunityMemberEventSubscriber('community.roleRemoved', callback);
|
|
18762
19280
|
|
|
19281
|
+
/**
|
|
19282
|
+
* ```js
|
|
19283
|
+
* import { onLocalCommunityUserAdded } from '@amityco/ts-sdk-react-native'
|
|
19284
|
+
* const dispose = onLocalCommunityUserAdded((community, member) => {
|
|
19285
|
+
* // ...
|
|
19286
|
+
* })
|
|
19287
|
+
* ```
|
|
19288
|
+
*
|
|
19289
|
+
* Fired when a user has been added to a {@link Amity.Community}
|
|
19290
|
+
*
|
|
19291
|
+
* @param callback The function to call when the event was fired
|
|
19292
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19293
|
+
*
|
|
19294
|
+
* @category Community Events
|
|
19295
|
+
*/
|
|
19296
|
+
const onLocalCommunityUserAdded = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userAdded', callback);
|
|
19297
|
+
|
|
19298
|
+
/**
|
|
19299
|
+
* ```js
|
|
19300
|
+
* import { onLocalCommunityUserRemoved } from '@amityco/ts-sdk-react-native'
|
|
19301
|
+
* const dispose = onLocalCommunityUserRemoved((community, member) => {
|
|
19302
|
+
* // ...
|
|
19303
|
+
* })
|
|
19304
|
+
* ```
|
|
19305
|
+
*
|
|
19306
|
+
* Fired when a user has been removed from a {@link Amity.Community}
|
|
19307
|
+
*
|
|
19308
|
+
* @param callback The function to call when the event was fired
|
|
19309
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19310
|
+
*
|
|
19311
|
+
* @category Community Events
|
|
19312
|
+
*/
|
|
19313
|
+
const onLocalCommunityUserRemoved = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userRemoved', callback);
|
|
19314
|
+
|
|
18763
19315
|
/**
|
|
18764
19316
|
* ```js
|
|
18765
19317
|
* import { onCommunityJoined } from '@amityco/ts-sdk-react-native'
|
|
@@ -18912,6 +19464,9 @@ var EnumCommunityMemberActions$1;
|
|
|
18912
19464
|
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
18913
19465
|
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
18914
19466
|
EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
|
|
19467
|
+
EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
|
|
19468
|
+
EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
|
|
19469
|
+
EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
|
|
18915
19470
|
})(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
|
|
18916
19471
|
|
|
18917
19472
|
/* begin_public_function
|
|
@@ -18936,7 +19491,7 @@ const addMembers = async (communityId, userIds) => {
|
|
|
18936
19491
|
const client = getActiveClient();
|
|
18937
19492
|
client.log('community/moderation/addMembers', communityId, userIds);
|
|
18938
19493
|
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
18939
|
-
fireEvent('community.userAdded', payload);
|
|
19494
|
+
fireEvent('local.community.userAdded', payload);
|
|
18940
19495
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
18941
19496
|
if (client.cache)
|
|
18942
19497
|
ingestInCache(data);
|
|
@@ -18967,7 +19522,7 @@ const removeMembers = async (communityId, userIds) => {
|
|
|
18967
19522
|
const client = getActiveClient();
|
|
18968
19523
|
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
18969
19524
|
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
18970
|
-
fireEvent('community.userRemoved', payload);
|
|
19525
|
+
fireEvent('local.community.userRemoved', payload);
|
|
18971
19526
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
18972
19527
|
if (client.cache)
|
|
18973
19528
|
ingestInCache(data);
|
|
@@ -18982,10 +19537,12 @@ const removeMembers = async (communityId, userIds) => {
|
|
|
18982
19537
|
*/
|
|
18983
19538
|
class CommunityMembersPaginationController extends PaginationController {
|
|
18984
19539
|
async getRequest(queryParams, token) {
|
|
18985
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
19540
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
18986
19541
|
const options = token ? { token } : { limit };
|
|
19542
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
18987
19543
|
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
18988
|
-
params: Object.assign(Object.assign({}, params), { options
|
|
19544
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
19545
|
+
isDeleted }),
|
|
18989
19546
|
});
|
|
18990
19547
|
return queryResponse;
|
|
18991
19548
|
}
|
|
@@ -19054,6 +19611,96 @@ class CommunityMembersQueryStreamController extends QueryStreamController {
|
|
|
19054
19611
|
}
|
|
19055
19612
|
}
|
|
19056
19613
|
|
|
19614
|
+
/**
|
|
19615
|
+
* ```js
|
|
19616
|
+
* import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk-react-native'
|
|
19617
|
+
* const dispose = onLocalCommunityRoleRemoved((community, member) => {
|
|
19618
|
+
* // ...
|
|
19619
|
+
* })
|
|
19620
|
+
* ```
|
|
19621
|
+
*
|
|
19622
|
+
* Fired when any {@link Amity.communityUsers} 's role has been added to any {@link Amity.Community}
|
|
19623
|
+
*
|
|
19624
|
+
* @param callback The function to call when the event was fired
|
|
19625
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19626
|
+
*
|
|
19627
|
+
* @category Community Events
|
|
19628
|
+
*/
|
|
19629
|
+
const onLocalCommunityRoleRemoved = (callback) => {
|
|
19630
|
+
const client = getActiveClient();
|
|
19631
|
+
const filter = async (payload) => {
|
|
19632
|
+
const { communities, communityUsers } = payload;
|
|
19633
|
+
callback(communities[0], communityUsers.filter(communityUser => communityUser.communityMembership === 'member'));
|
|
19634
|
+
};
|
|
19635
|
+
return createEventSubscriber(client, 'onLocalCommunityRoleRemoved', 'local.community.roleRemoved', filter);
|
|
19636
|
+
};
|
|
19637
|
+
|
|
19638
|
+
/**
|
|
19639
|
+
* ```js
|
|
19640
|
+
* import { onLocalCommunityRoleAdded } from '@amityco/ts-sdk-react-native'
|
|
19641
|
+
* const dispose = onLocalCommunityRoleAdded((community, member) => {
|
|
19642
|
+
* // ...
|
|
19643
|
+
* })
|
|
19644
|
+
* ```
|
|
19645
|
+
*
|
|
19646
|
+
* Fired when any {@link Amity.communityUsers} 's role has been added to any {@link Amity.Community}
|
|
19647
|
+
*
|
|
19648
|
+
* @param callback The function to call when the event was fired
|
|
19649
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19650
|
+
*
|
|
19651
|
+
* @category Community Events
|
|
19652
|
+
*/
|
|
19653
|
+
const onLocalCommunityRoleAdded = (callback) => {
|
|
19654
|
+
const client = getActiveClient();
|
|
19655
|
+
const filter = async (payload) => {
|
|
19656
|
+
const { communities, communityUsers } = payload;
|
|
19657
|
+
callback(communities[0], communityUsers.filter(communityUser => communityUser.communityMembership === 'member'));
|
|
19658
|
+
};
|
|
19659
|
+
return createEventSubscriber(client, 'onLocalCommunityRoleAdded', 'local.community.roleAdded', filter);
|
|
19660
|
+
};
|
|
19661
|
+
|
|
19662
|
+
/**
|
|
19663
|
+
* ```js
|
|
19664
|
+
* import { onUserDeleted } from '@amityco/ts-sdk-react-native'
|
|
19665
|
+
* const dispose = onUserDeleted((community, member) => {
|
|
19666
|
+
* // ...
|
|
19667
|
+
* })
|
|
19668
|
+
* ```
|
|
19669
|
+
*
|
|
19670
|
+
* Fired when a {@link Amity.Community} has been joined
|
|
19671
|
+
*
|
|
19672
|
+
* @param callback The function to call when the event was fired
|
|
19673
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19674
|
+
*
|
|
19675
|
+
* @category Community Events
|
|
19676
|
+
*/
|
|
19677
|
+
const onUserDeleted = (communityId) => (callback) => {
|
|
19678
|
+
const client = getActiveClient();
|
|
19679
|
+
const filter = (payload) => {
|
|
19680
|
+
var _a, _b;
|
|
19681
|
+
const userPayload = prepareUserPayload(payload);
|
|
19682
|
+
if (userPayload.users.length === 0)
|
|
19683
|
+
return;
|
|
19684
|
+
const user = userPayload.users[0];
|
|
19685
|
+
ingestInCache(userPayload);
|
|
19686
|
+
const communityUserCacheKey = getResolver('communityUsers')({
|
|
19687
|
+
communityId,
|
|
19688
|
+
userId: user.userId,
|
|
19689
|
+
});
|
|
19690
|
+
const cacheData = (_a = pullFromCache([
|
|
19691
|
+
'communityUsers',
|
|
19692
|
+
'get',
|
|
19693
|
+
communityUserCacheKey,
|
|
19694
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
19695
|
+
pushToCache(['communityUsers', 'get', communityUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
|
|
19696
|
+
const community = (_b = pullFromCache(['community', 'get', communityId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
19697
|
+
callback(community, [
|
|
19698
|
+
Object.assign(Object.assign({}, cacheData), { user }),
|
|
19699
|
+
]);
|
|
19700
|
+
};
|
|
19701
|
+
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
19702
|
+
};
|
|
19703
|
+
|
|
19057
19704
|
class CommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
19058
19705
|
constructor(query, callback) {
|
|
19059
19706
|
const queryStreamId = hash__default["default"](query);
|
|
@@ -19092,7 +19739,24 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
19092
19739
|
fn: onCommunityUserRoleRemoved,
|
|
19093
19740
|
action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
|
|
19094
19741
|
},
|
|
19742
|
+
{
|
|
19743
|
+
fn: onLocalCommunityRoleAdded,
|
|
19744
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserRoleAdded,
|
|
19745
|
+
},
|
|
19746
|
+
{
|
|
19747
|
+
fn: onLocalCommunityRoleRemoved,
|
|
19748
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
|
|
19749
|
+
},
|
|
19095
19750
|
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions$1.OnCommunityUserUnbanned },
|
|
19751
|
+
{ fn: onLocalCommunityUserAdded, action: EnumCommunityMemberActions$1.OnCommunityUserAdded },
|
|
19752
|
+
{
|
|
19753
|
+
fn: onLocalCommunityUserRemoved,
|
|
19754
|
+
action: EnumCommunityMemberActions$1.onCommunityUserRemoved,
|
|
19755
|
+
},
|
|
19756
|
+
{
|
|
19757
|
+
fn: onUserDeleted(this.query.communityId),
|
|
19758
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserChanged,
|
|
19759
|
+
},
|
|
19096
19760
|
]);
|
|
19097
19761
|
}
|
|
19098
19762
|
notifyChange({ origin, loading, error }) {
|
|
@@ -19125,6 +19789,9 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
19125
19789
|
if (this.query.search) {
|
|
19126
19790
|
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
19127
19791
|
}
|
|
19792
|
+
if (this.query.includeDeleted === false) {
|
|
19793
|
+
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
|
|
19794
|
+
}
|
|
19128
19795
|
switch (this.query.sortBy) {
|
|
19129
19796
|
case 'firstCreated':
|
|
19130
19797
|
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
@@ -19215,10 +19882,12 @@ const getMembers = (params, callback, config) => {
|
|
|
19215
19882
|
*/
|
|
19216
19883
|
class SearchCommunityMembersPaginationController extends PaginationController {
|
|
19217
19884
|
async getRequest(queryParams, token) {
|
|
19218
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
19885
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
19219
19886
|
const options = token ? { token } : { limit };
|
|
19887
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
19220
19888
|
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
19221
|
-
params: Object.assign(Object.assign({}, params), { options
|
|
19889
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
19890
|
+
isDeleted }),
|
|
19222
19891
|
});
|
|
19223
19892
|
return queryResponse;
|
|
19224
19893
|
}
|
|
@@ -19325,11 +19994,19 @@ class SearchCommunityMembersLiveCollectionController extends LiveCollectionContr
|
|
|
19325
19994
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
19326
19995
|
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
19327
19996
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
19997
|
+
{
|
|
19998
|
+
fn: onLocalCommunityRoleRemoved,
|
|
19999
|
+
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
20000
|
+
},
|
|
19328
20001
|
{
|
|
19329
20002
|
fn: onCommunityUserRoleRemoved,
|
|
19330
20003
|
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
19331
20004
|
},
|
|
19332
20005
|
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
|
|
20006
|
+
{
|
|
20007
|
+
fn: onUserDeleted(this.query.communityId),
|
|
20008
|
+
action: EnumCommunityMemberActions.OnCommunityUserChanged,
|
|
20009
|
+
},
|
|
19333
20010
|
]);
|
|
19334
20011
|
}
|
|
19335
20012
|
notifyChange({ origin, loading, error }) {
|
|
@@ -19362,6 +20039,9 @@ class SearchCommunityMembersLiveCollectionController extends LiveCollectionContr
|
|
|
19362
20039
|
if (this.query.search) {
|
|
19363
20040
|
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
19364
20041
|
}
|
|
20042
|
+
if (this.query.includeDeleted === false) {
|
|
20043
|
+
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
|
|
20044
|
+
}
|
|
19365
20045
|
return communityMembers;
|
|
19366
20046
|
}
|
|
19367
20047
|
}
|
|
@@ -19423,6 +20103,8 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
19423
20103
|
onCommunityUserUnbanned: onCommunityUserUnbanned,
|
|
19424
20104
|
onCommunityUserRoleAdded: onCommunityUserRoleAdded,
|
|
19425
20105
|
onCommunityUserRoleRemoved: onCommunityUserRoleRemoved,
|
|
20106
|
+
onLocalCommunityUserAdded: onLocalCommunityUserAdded,
|
|
20107
|
+
onLocalCommunityUserRemoved: onLocalCommunityUserRemoved,
|
|
19426
20108
|
onCommunityJoined: onCommunityJoined,
|
|
19427
20109
|
onCommunityLeft: onCommunityLeft
|
|
19428
20110
|
});
|
|
@@ -20079,9 +20761,10 @@ const addRoles = async (communityId, roleIds, userIds) => {
|
|
|
20079
20761
|
const client = getActiveClient();
|
|
20080
20762
|
client.log('community/moderation/addRoles', communityId, roleIds, userIds);
|
|
20081
20763
|
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/users/roles`, { communityId, roles: roleIds, userIds });
|
|
20082
|
-
const data =
|
|
20764
|
+
const data = prepareCommunityMembershipPayload(payload);
|
|
20083
20765
|
if (client.cache)
|
|
20084
20766
|
ingestInCache(data);
|
|
20767
|
+
fireEvent('local.community.roleAdded', data);
|
|
20085
20768
|
const { communityUsers } = data;
|
|
20086
20769
|
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
20087
20770
|
roleIds.some(role => communityUser.roles.includes(role)));
|
|
@@ -20111,9 +20794,10 @@ const removeRoles = async (communityId, roleIds, userIds) => {
|
|
|
20111
20794
|
const client = getActiveClient();
|
|
20112
20795
|
client.log('community/moderation/removeRoles', communityId, roleIds, userIds);
|
|
20113
20796
|
const { data: payload } = await client.http.delete(`/api/v4/communities/${communityId}/users/roles`, { data: { communityId, roles: roleIds, userIds } });
|
|
20114
|
-
const data =
|
|
20797
|
+
const data = prepareCommunityMembershipPayload(payload);
|
|
20115
20798
|
if (client.cache)
|
|
20116
20799
|
ingestInCache(data);
|
|
20800
|
+
fireEvent('local.community.roleRemoved', data);
|
|
20117
20801
|
const { communityUsers } = data;
|
|
20118
20802
|
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
20119
20803
|
!roleIds.some(role => communityUser.roles.includes(role)));
|
|
@@ -20800,7 +21484,7 @@ const updatePost = async (postId, patch) => {
|
|
|
20800
21484
|
const cachedAt = client.cache && Date.now();
|
|
20801
21485
|
if (client.cache)
|
|
20802
21486
|
ingestInCache(data, { cachedAt });
|
|
20803
|
-
fireEvent('local.post.updated',
|
|
21487
|
+
fireEvent('local.post.updated', payload);
|
|
20804
21488
|
const { posts } = data;
|
|
20805
21489
|
return {
|
|
20806
21490
|
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
@@ -20900,7 +21584,15 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
20900
21584
|
}
|
|
20901
21585
|
// to support hard deletion
|
|
20902
21586
|
const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
|
|
20903
|
-
|
|
21587
|
+
if (permanent) {
|
|
21588
|
+
setTimeout(() => {
|
|
21589
|
+
pushToTombstone('post', postId);
|
|
21590
|
+
}, 0);
|
|
21591
|
+
}
|
|
21592
|
+
else {
|
|
21593
|
+
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
21594
|
+
}
|
|
21595
|
+
fireEvent('local.post.deleted', {
|
|
20904
21596
|
posts: [deleted],
|
|
20905
21597
|
categories: [],
|
|
20906
21598
|
comments: [],
|
|
@@ -20911,14 +21603,6 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
20911
21603
|
postChildren: [],
|
|
20912
21604
|
users: [],
|
|
20913
21605
|
});
|
|
20914
|
-
if (permanent) {
|
|
20915
|
-
setTimeout(() => {
|
|
20916
|
-
pushToTombstone('post', postId);
|
|
20917
|
-
}, 0);
|
|
20918
|
-
}
|
|
20919
|
-
else {
|
|
20920
|
-
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
20921
|
-
}
|
|
20922
21606
|
return LinkedObject.post(deleted);
|
|
20923
21607
|
};
|
|
20924
21608
|
|
|
@@ -21306,6 +21990,7 @@ getCommentByIds.locally = (commentIds) => {
|
|
|
21306
21990
|
* @async
|
|
21307
21991
|
*/
|
|
21308
21992
|
const createComment = async (bundle) => {
|
|
21993
|
+
var _a;
|
|
21309
21994
|
const client = getActiveClient();
|
|
21310
21995
|
client.log('comment/createComment', bundle);
|
|
21311
21996
|
const { data } = await client.http.post('/api/v3/comments', bundle);
|
|
@@ -21317,18 +22002,21 @@ const createComment = async (bundle) => {
|
|
|
21317
22002
|
if (client.cache)
|
|
21318
22003
|
ingestInCache(data, { cachedAt });
|
|
21319
22004
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
21320
|
-
const post =
|
|
21321
|
-
|
|
21322
|
-
|
|
21323
|
-
|
|
21324
|
-
|
|
21325
|
-
|
|
21326
|
-
|
|
21327
|
-
|
|
21328
|
-
|
|
21329
|
-
|
|
21330
|
-
|
|
21331
|
-
|
|
22005
|
+
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22006
|
+
if (post) {
|
|
22007
|
+
post.commentsCount += 1;
|
|
22008
|
+
fireEvent('local.post.updated', {
|
|
22009
|
+
posts: [post],
|
|
22010
|
+
categories: [],
|
|
22011
|
+
comments: [],
|
|
22012
|
+
communities: [],
|
|
22013
|
+
communityUsers: data.communityUsers,
|
|
22014
|
+
feeds: [],
|
|
22015
|
+
files: data.files,
|
|
22016
|
+
postChildren: [],
|
|
22017
|
+
users: data.users,
|
|
22018
|
+
});
|
|
22019
|
+
}
|
|
21332
22020
|
}
|
|
21333
22021
|
else if (bundle.referenceType === 'story') {
|
|
21334
22022
|
const storyIndex = pullFromCache([
|
|
@@ -21487,6 +22175,7 @@ getStoryByStoryId$1.locally = (storyId) => {
|
|
|
21487
22175
|
* @async
|
|
21488
22176
|
*/
|
|
21489
22177
|
const deleteComment = async (commentId, permanent = false) => {
|
|
22178
|
+
var _a;
|
|
21490
22179
|
const client = getActiveClient();
|
|
21491
22180
|
const comment = await getComment$2(commentId);
|
|
21492
22181
|
// API-FIX: This endpoint has not been implemented yet.
|
|
@@ -21511,18 +22200,28 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
21511
22200
|
});
|
|
21512
22201
|
}
|
|
21513
22202
|
else {
|
|
21514
|
-
const post =
|
|
21515
|
-
|
|
21516
|
-
|
|
21517
|
-
|
|
21518
|
-
|
|
21519
|
-
|
|
21520
|
-
|
|
21521
|
-
|
|
21522
|
-
|
|
21523
|
-
|
|
21524
|
-
|
|
21525
|
-
|
|
22203
|
+
const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22204
|
+
if (post) {
|
|
22205
|
+
let removeCount;
|
|
22206
|
+
if (!deleted.parentId) {
|
|
22207
|
+
// NOTE: delete the parent comment will remove all children comments
|
|
22208
|
+
removeCount = deleted.childrenNumber + 1;
|
|
22209
|
+
}
|
|
22210
|
+
else
|
|
22211
|
+
removeCount = 1;
|
|
22212
|
+
post.commentsCount -= removeCount;
|
|
22213
|
+
fireEvent('local.post.updated', {
|
|
22214
|
+
posts: [post],
|
|
22215
|
+
categories: [],
|
|
22216
|
+
comments: [],
|
|
22217
|
+
communities: [],
|
|
22218
|
+
communityUsers: [],
|
|
22219
|
+
feeds: [],
|
|
22220
|
+
files: [],
|
|
22221
|
+
postChildren: [],
|
|
22222
|
+
users: [],
|
|
22223
|
+
});
|
|
22224
|
+
}
|
|
21526
22225
|
}
|
|
21527
22226
|
fireEvent('local.comment.deleted', {
|
|
21528
22227
|
comments: [deleted],
|
|
@@ -21746,46 +22445,121 @@ getComment$1.locally = (commentId) => {
|
|
|
21746
22445
|
|
|
21747
22446
|
/**
|
|
21748
22447
|
* ```js
|
|
21749
|
-
* import { observeComment } from '@amityco/ts-sdk-react-native'
|
|
21750
|
-
*
|
|
21751
|
-
* let comment = {}
|
|
21752
|
-
* const dispose = observeComment(commentId, ({ data }) => comment = data)
|
|
22448
|
+
* import { observeComment } from '@amityco/ts-sdk-react-native'
|
|
22449
|
+
*
|
|
22450
|
+
* let comment = {}
|
|
22451
|
+
* const dispose = observeComment(commentId, ({ data }) => comment = data)
|
|
22452
|
+
* ```
|
|
22453
|
+
*
|
|
22454
|
+
* Observe all mutation on a given {@link Amity.InternalComment}
|
|
22455
|
+
*
|
|
22456
|
+
* @param commentId the ID of the comment to observe
|
|
22457
|
+
* @param callback the function to call when new data are available
|
|
22458
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
22459
|
+
*
|
|
22460
|
+
* @category InternalComment Observer
|
|
22461
|
+
*/
|
|
22462
|
+
const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
22463
|
+
const { log } = getActiveClient();
|
|
22464
|
+
const timestamp = Date.now();
|
|
22465
|
+
log(`observeComment(tmpid: ${timestamp}) > listen`);
|
|
22466
|
+
// wrapper function to make sure
|
|
22467
|
+
const router = (result, action) => {
|
|
22468
|
+
var _a, _b;
|
|
22469
|
+
if (callback instanceof Function)
|
|
22470
|
+
return callback(result);
|
|
22471
|
+
if (action !== 'onFetch')
|
|
22472
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
22473
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
22474
|
+
};
|
|
22475
|
+
const realtimeRouter = (result, action) => {
|
|
22476
|
+
var _a;
|
|
22477
|
+
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.commentId) !== commentId)
|
|
22478
|
+
return;
|
|
22479
|
+
router(result, action);
|
|
22480
|
+
};
|
|
22481
|
+
const disposers = [];
|
|
22482
|
+
disposers.push(onCommentUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onCommentDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')), onCommentFlagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onFlagged')), onCommentUnflagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUnflagged')), onCommentReactionAdded(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionAdded')), onCommentReactionRemoved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionRemoved')));
|
|
22483
|
+
runQuery(createQuery(getComment$1, commentId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
22484
|
+
return () => {
|
|
22485
|
+
log(`observeComment(tmpid: ${timestamp}) > dispose`);
|
|
22486
|
+
disposers.forEach(fn => fn());
|
|
22487
|
+
};
|
|
22488
|
+
};
|
|
22489
|
+
|
|
22490
|
+
/**
|
|
22491
|
+
* ```js
|
|
22492
|
+
* import { onCommentDeleteLocal } from '@amityco/ts-sdk-react-native'
|
|
22493
|
+
* const dispose = onCommentDeleteLocal(comment => {
|
|
22494
|
+
* // ...
|
|
22495
|
+
* })
|
|
22496
|
+
* ```
|
|
22497
|
+
*
|
|
22498
|
+
* Fired when a {@link Amity.InternalComment} has been deleted
|
|
22499
|
+
*
|
|
22500
|
+
* @param callback The function to call when the event was fired
|
|
22501
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22502
|
+
*
|
|
22503
|
+
* @category Comment Events
|
|
22504
|
+
*/
|
|
22505
|
+
const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
|
|
22506
|
+
|
|
22507
|
+
/**
|
|
22508
|
+
* ```js
|
|
22509
|
+
* import { onLocalCommentReactionAdded } from '@amityco/ts-sdk-react-native'
|
|
22510
|
+
* const dispose = onLocalCommentReactionAdded(comment => {
|
|
22511
|
+
* // ...
|
|
22512
|
+
* })
|
|
22513
|
+
* ```
|
|
22514
|
+
*
|
|
22515
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
22516
|
+
*
|
|
22517
|
+
* @param callback The function to call when the event was fired
|
|
22518
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22519
|
+
*
|
|
22520
|
+
* @category Comment Events
|
|
22521
|
+
*/
|
|
22522
|
+
const onLocalCommentReactionAdded = (callback) => {
|
|
22523
|
+
const client = getActiveClient();
|
|
22524
|
+
const filter = ({ comment }) => {
|
|
22525
|
+
if (!client.cache) {
|
|
22526
|
+
callback(comment);
|
|
22527
|
+
}
|
|
22528
|
+
else {
|
|
22529
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
22530
|
+
callback(commentLinkedObject(comment));
|
|
22531
|
+
}
|
|
22532
|
+
};
|
|
22533
|
+
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
22534
|
+
};
|
|
22535
|
+
|
|
22536
|
+
/**
|
|
22537
|
+
* ```js
|
|
22538
|
+
* import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk-react-native'
|
|
22539
|
+
* const dispose = onLocalCommentReactionRemoved(comment => {
|
|
22540
|
+
* // ...
|
|
22541
|
+
* })
|
|
21753
22542
|
* ```
|
|
21754
22543
|
*
|
|
21755
|
-
*
|
|
22544
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
21756
22545
|
*
|
|
21757
|
-
* @param
|
|
21758
|
-
* @
|
|
21759
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
22546
|
+
* @param callback The function to call when the event was fired
|
|
22547
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21760
22548
|
*
|
|
21761
|
-
* @category
|
|
22549
|
+
* @category Comment Events
|
|
21762
22550
|
*/
|
|
21763
|
-
const
|
|
21764
|
-
const
|
|
21765
|
-
const
|
|
21766
|
-
|
|
21767
|
-
|
|
21768
|
-
|
|
21769
|
-
|
|
21770
|
-
|
|
21771
|
-
|
|
21772
|
-
|
|
21773
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
21774
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
21775
|
-
};
|
|
21776
|
-
const realtimeRouter = (result, action) => {
|
|
21777
|
-
var _a;
|
|
21778
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.commentId) !== commentId)
|
|
21779
|
-
return;
|
|
21780
|
-
router(result, action);
|
|
21781
|
-
};
|
|
21782
|
-
const disposers = [];
|
|
21783
|
-
disposers.push(onCommentUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onCommentDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')), onCommentFlagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onFlagged')), onCommentUnflagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUnflagged')), onCommentReactionAdded(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionAdded')), onCommentReactionRemoved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionRemoved')));
|
|
21784
|
-
runQuery(createQuery(getComment$1, commentId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
21785
|
-
return () => {
|
|
21786
|
-
log(`observeComment(tmpid: ${timestamp}) > dispose`);
|
|
21787
|
-
disposers.forEach(fn => fn());
|
|
22551
|
+
const onLocalCommentReactionRemoved = (callback) => {
|
|
22552
|
+
const client = getActiveClient();
|
|
22553
|
+
const filter = ({ comment }) => {
|
|
22554
|
+
if (!client.cache) {
|
|
22555
|
+
callback(comment);
|
|
22556
|
+
}
|
|
22557
|
+
else {
|
|
22558
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
22559
|
+
callback(commentLinkedObject(comment));
|
|
22560
|
+
}
|
|
21788
22561
|
};
|
|
22562
|
+
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
21789
22563
|
};
|
|
21790
22564
|
|
|
21791
22565
|
/* begin_public_function
|
|
@@ -21812,26 +22586,15 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
|
21812
22586
|
*/
|
|
21813
22587
|
const getComment = (commentId, callback) => {
|
|
21814
22588
|
return liveObject(commentId, callback, 'commentId', getComment$1, [
|
|
22589
|
+
onCommentDeleteLocal,
|
|
21815
22590
|
onCommentDeleted,
|
|
21816
22591
|
onCommentFlagged,
|
|
21817
22592
|
onCommentReactionAdded,
|
|
21818
22593
|
onCommentReactionRemoved,
|
|
21819
22594
|
onCommentUnflagged,
|
|
21820
22595
|
onCommentUpdated,
|
|
21821
|
-
|
|
21822
|
-
|
|
21823
|
-
if (comment.parentId !== commentId)
|
|
21824
|
-
return;
|
|
21825
|
-
const cacheParent = pullFromCache([
|
|
21826
|
-
'comment',
|
|
21827
|
-
'get',
|
|
21828
|
-
comment.parentId,
|
|
21829
|
-
]);
|
|
21830
|
-
if (!(cacheParent === null || cacheParent === void 0 ? void 0 : cacheParent.data))
|
|
21831
|
-
return;
|
|
21832
|
-
callback(Object.assign(Object.assign({}, cacheParent.data), { childrenNumber: cacheParent.data.childrenNumber + 1, children: [...new Set([...cacheParent.data.children, comment.commentId])] }));
|
|
21833
|
-
});
|
|
21834
|
-
},
|
|
22596
|
+
onLocalCommentReactionAdded,
|
|
22597
|
+
onLocalCommentReactionRemoved,
|
|
21835
22598
|
]);
|
|
21836
22599
|
};
|
|
21837
22600
|
/* end_public_function */
|
|
@@ -21915,16 +22678,24 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
21915
22678
|
}
|
|
21916
22679
|
}
|
|
21917
22680
|
|
|
21918
|
-
|
|
21919
|
-
|
|
21920
|
-
|
|
21921
|
-
|
|
21922
|
-
|
|
21923
|
-
|
|
21924
|
-
|
|
21925
|
-
|
|
21926
|
-
|
|
21927
|
-
|
|
22681
|
+
/**
|
|
22682
|
+
* ```js
|
|
22683
|
+
* import { onCommentCreated } from '@amityco/ts-sdk-react-native'
|
|
22684
|
+
* const dispose = onCommentCreated(comment => {
|
|
22685
|
+
* // ...
|
|
22686
|
+
* })
|
|
22687
|
+
* ```
|
|
22688
|
+
*
|
|
22689
|
+
* Fired when a {@link Amity.InternalComment} has been created
|
|
22690
|
+
*
|
|
22691
|
+
* @param callback The function to call when the event was fired
|
|
22692
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22693
|
+
*
|
|
22694
|
+
* @category Comment Events
|
|
22695
|
+
*/
|
|
22696
|
+
const onCommentCreatedLocal = (callback) => {
|
|
22697
|
+
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
22698
|
+
};
|
|
21928
22699
|
|
|
21929
22700
|
class CommentLiveCollectionController extends LiveCollectionController {
|
|
21930
22701
|
constructor(query, callback) {
|
|
@@ -21955,6 +22726,8 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
21955
22726
|
}
|
|
21956
22727
|
startSubscription() {
|
|
21957
22728
|
return this.queryStreamController.subscribeRTE([
|
|
22729
|
+
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
22730
|
+
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
21958
22731
|
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
21959
22732
|
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
21960
22733
|
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
@@ -21962,6 +22735,8 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
21962
22735
|
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
21963
22736
|
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
21964
22737
|
{ fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
22738
|
+
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
22739
|
+
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
21965
22740
|
]);
|
|
21966
22741
|
}
|
|
21967
22742
|
notifyChange({ origin, loading, error }) {
|
|
@@ -22093,6 +22868,98 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
22093
22868
|
getComments: getComments
|
|
22094
22869
|
});
|
|
22095
22870
|
|
|
22871
|
+
/**
|
|
22872
|
+
* ```js
|
|
22873
|
+
* import { onPostUpdatedLocal } from '@amityco/ts-sdk-react-native'
|
|
22874
|
+
* const dispose = onPostUpdatedLocal(post => {
|
|
22875
|
+
* // ...
|
|
22876
|
+
* })
|
|
22877
|
+
* ```
|
|
22878
|
+
*
|
|
22879
|
+
* Fired when a {@link Amity.InternalPost} has been updated
|
|
22880
|
+
*
|
|
22881
|
+
* @param callback The function to call when the event was fired
|
|
22882
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22883
|
+
*
|
|
22884
|
+
* @category Post Events
|
|
22885
|
+
*/
|
|
22886
|
+
const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
|
|
22887
|
+
|
|
22888
|
+
/**
|
|
22889
|
+
* ```js
|
|
22890
|
+
* import { onLocalPostReactionAdded } from '@amityco/ts-sdk-react-native'
|
|
22891
|
+
* const dispose = onPostReactionAdded(post => {
|
|
22892
|
+
* // ...
|
|
22893
|
+
* })
|
|
22894
|
+
* ```
|
|
22895
|
+
*
|
|
22896
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
22897
|
+
*
|
|
22898
|
+
* @param callback The function to call when the event was fired
|
|
22899
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22900
|
+
*
|
|
22901
|
+
* @category Post Events
|
|
22902
|
+
*/
|
|
22903
|
+
const onLocalPostReactionAdded = (callback) => {
|
|
22904
|
+
const client = getActiveClient();
|
|
22905
|
+
const filter = ({ post }) => {
|
|
22906
|
+
if (!client.cache) {
|
|
22907
|
+
callback(post);
|
|
22908
|
+
}
|
|
22909
|
+
else {
|
|
22910
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
22911
|
+
callback(post);
|
|
22912
|
+
}
|
|
22913
|
+
};
|
|
22914
|
+
return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
|
|
22915
|
+
};
|
|
22916
|
+
|
|
22917
|
+
/**
|
|
22918
|
+
* ```js
|
|
22919
|
+
* import { onLocalPostReactionRemoved } from '@amityco/ts-sdk-react-native'
|
|
22920
|
+
* const dispose = onPostReactionRemoved(post => {
|
|
22921
|
+
* // ...
|
|
22922
|
+
* })
|
|
22923
|
+
* ```
|
|
22924
|
+
*
|
|
22925
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
22926
|
+
*
|
|
22927
|
+
* @param callback The function to call when the event was fired
|
|
22928
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22929
|
+
*
|
|
22930
|
+
* @category Post Events
|
|
22931
|
+
*/
|
|
22932
|
+
const onLocalPostReactionRemoved = (callback) => {
|
|
22933
|
+
const client = getActiveClient();
|
|
22934
|
+
const filter = ({ post }) => {
|
|
22935
|
+
if (!client.cache) {
|
|
22936
|
+
callback(post);
|
|
22937
|
+
}
|
|
22938
|
+
else {
|
|
22939
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
22940
|
+
callback(post);
|
|
22941
|
+
}
|
|
22942
|
+
};
|
|
22943
|
+
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
22944
|
+
};
|
|
22945
|
+
|
|
22946
|
+
/**
|
|
22947
|
+
* ```js
|
|
22948
|
+
* import { onLocalPostDeleted } from '@amityco/ts-sdk-react-native'
|
|
22949
|
+
* const dispose = onLocalPostDeleted(post => {
|
|
22950
|
+
* // ...
|
|
22951
|
+
* })
|
|
22952
|
+
* ```
|
|
22953
|
+
*
|
|
22954
|
+
* Fired when a {@link Amity.InternalPost} has been deleted
|
|
22955
|
+
*
|
|
22956
|
+
* @param callback The function to call when the event was fired
|
|
22957
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22958
|
+
*
|
|
22959
|
+
* @category Post Events
|
|
22960
|
+
*/
|
|
22961
|
+
const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
|
|
22962
|
+
|
|
22096
22963
|
/* begin_public_function
|
|
22097
22964
|
id: post.get
|
|
22098
22965
|
*/
|
|
@@ -22123,6 +22990,8 @@ const getPost$1 = (postId, callback) => {
|
|
|
22123
22990
|
return liveObject(postId, responder, 'postId', getPost$2, [
|
|
22124
22991
|
onPostApproved,
|
|
22125
22992
|
onPostDeclined,
|
|
22993
|
+
onLocalPostReactionAdded,
|
|
22994
|
+
onLocalPostReactionRemoved,
|
|
22126
22995
|
(callback) => {
|
|
22127
22996
|
return onPostDeleted((post) => {
|
|
22128
22997
|
var _a;
|
|
@@ -22157,6 +23026,8 @@ const getPost$1 = (postId, callback) => {
|
|
|
22157
23026
|
},
|
|
22158
23027
|
onPostUnflagged,
|
|
22159
23028
|
onPostUpdated,
|
|
23029
|
+
onPostUpdatedLocal,
|
|
23030
|
+
onLocalPostDeleted,
|
|
22160
23031
|
convertEventPayload((callback) => {
|
|
22161
23032
|
return onCommentCreated(async (comment) => {
|
|
22162
23033
|
if (comment.referenceId === postId) {
|
|
@@ -22278,17 +23149,6 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
22278
23149
|
}
|
|
22279
23150
|
}
|
|
22280
23151
|
|
|
22281
|
-
const preparePostPayload = (postPayload) => {
|
|
22282
|
-
const { posts } = postPayload;
|
|
22283
|
-
const { communities, communityUsers } = convertCommunityPayload({
|
|
22284
|
-
communities: postPayload.communities,
|
|
22285
|
-
communityUsers: postPayload.communityUsers,
|
|
22286
|
-
});
|
|
22287
|
-
return Object.assign(Object.assign({}, postPayload), { posts,
|
|
22288
|
-
communities,
|
|
22289
|
-
communityUsers });
|
|
22290
|
-
};
|
|
22291
|
-
|
|
22292
23152
|
const getPost = async (postId) => {
|
|
22293
23153
|
const client = getActiveClient();
|
|
22294
23154
|
client.log('post/getPost', postId);
|
|
@@ -22361,6 +23221,7 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
22361
23221
|
return this.queryStreamController.subscribeRTE([
|
|
22362
23222
|
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
22363
23223
|
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
23224
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
22364
23225
|
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
22365
23226
|
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
22366
23227
|
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
@@ -22368,6 +23229,9 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
22368
23229
|
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
22369
23230
|
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
22370
23231
|
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
23232
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
23233
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
23234
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
22371
23235
|
{
|
|
22372
23236
|
fn: convertEventPayload((callback) => {
|
|
22373
23237
|
return onCommentCreated(async (comment) => {
|
|
@@ -22485,6 +23349,138 @@ const getPosts = (params, callback, config) => {
|
|
|
22485
23349
|
};
|
|
22486
23350
|
/* end_public_function */
|
|
22487
23351
|
|
|
23352
|
+
class PinnedPostPaginationController extends PaginationController {
|
|
23353
|
+
async getRequest(queryParams, token) {
|
|
23354
|
+
const params = __rest(queryParams, ["limit"]);
|
|
23355
|
+
const { communityId, placement } = params;
|
|
23356
|
+
const path = placement
|
|
23357
|
+
? `/api/v1/pinned-posts/communities/${communityId}/${placement}`
|
|
23358
|
+
: `/api/v1/pinned-posts/communities/${communityId}`;
|
|
23359
|
+
const { data: queryResponse } = await this.http.get(path);
|
|
23360
|
+
return queryResponse;
|
|
23361
|
+
}
|
|
23362
|
+
}
|
|
23363
|
+
|
|
23364
|
+
class PinnedPostQueryStreamController extends QueryStreamController {
|
|
23365
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
23366
|
+
super(query, cacheKey);
|
|
23367
|
+
this.notifyChange = notifyChange;
|
|
23368
|
+
this.preparePayload = preparePayload;
|
|
23369
|
+
}
|
|
23370
|
+
// eslint-disable-next-line class-methods-use-this
|
|
23371
|
+
async saveToMainDB(response) {
|
|
23372
|
+
const client = getActiveClient();
|
|
23373
|
+
const cachedAt = client.cache && Date.now();
|
|
23374
|
+
if (client.cache) {
|
|
23375
|
+
ingestInCache(response, { cachedAt });
|
|
23376
|
+
}
|
|
23377
|
+
}
|
|
23378
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23379
|
+
var _a, _b;
|
|
23380
|
+
if (refresh) {
|
|
23381
|
+
pushToCache(this.cacheKey, {
|
|
23382
|
+
data: response.pins.map(getResolver('pin')),
|
|
23383
|
+
});
|
|
23384
|
+
}
|
|
23385
|
+
else {
|
|
23386
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23387
|
+
const pinnedPosts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23388
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...pinnedPosts, ...response.pins.map(getResolver('pin'))])] }));
|
|
23389
|
+
this.notifyChange({
|
|
23390
|
+
origin: "server" /* Amity.LiveDataOrigin.SERVER */,
|
|
23391
|
+
loading: false,
|
|
23392
|
+
});
|
|
23393
|
+
}
|
|
23394
|
+
}
|
|
23395
|
+
}
|
|
23396
|
+
|
|
23397
|
+
class PinnedPostLiveCollectionController extends LiveCollectionController {
|
|
23398
|
+
constructor(query, callback) {
|
|
23399
|
+
const queryStreamId = hash__default["default"](query);
|
|
23400
|
+
const cacheKey = ['pinnedPosts', 'collection', queryStreamId];
|
|
23401
|
+
const paginationController = new PinnedPostPaginationController(query);
|
|
23402
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
23403
|
+
this.query = query;
|
|
23404
|
+
this.queryStreamController = new PinnedPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
|
|
23405
|
+
this.callback = callback.bind(this);
|
|
23406
|
+
this.loadPage({ initial: true });
|
|
23407
|
+
}
|
|
23408
|
+
setup() {
|
|
23409
|
+
var _a;
|
|
23410
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23411
|
+
if (!collection) {
|
|
23412
|
+
pushToCache(this.cacheKey, {
|
|
23413
|
+
data: [],
|
|
23414
|
+
params: {},
|
|
23415
|
+
});
|
|
23416
|
+
}
|
|
23417
|
+
}
|
|
23418
|
+
async persistModel(queryPayload) {
|
|
23419
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
23420
|
+
}
|
|
23421
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
23422
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
23423
|
+
}
|
|
23424
|
+
// eslint-disable-next-line class-methods-use-this
|
|
23425
|
+
startSubscription() {
|
|
23426
|
+
return [];
|
|
23427
|
+
}
|
|
23428
|
+
notifyChange({ origin, loading, error }) {
|
|
23429
|
+
var _a, _b;
|
|
23430
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23431
|
+
if (!collection)
|
|
23432
|
+
return;
|
|
23433
|
+
let data = ((_b = collection.data
|
|
23434
|
+
.map(id => pullFromCache(['pin', 'get', id]))
|
|
23435
|
+
.filter(isNonNullable)
|
|
23436
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.pinnedPost);
|
|
23437
|
+
data = this.applyFilter(data);
|
|
23438
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
23439
|
+
return;
|
|
23440
|
+
this.callback({
|
|
23441
|
+
data,
|
|
23442
|
+
loading,
|
|
23443
|
+
error,
|
|
23444
|
+
});
|
|
23445
|
+
}
|
|
23446
|
+
applyFilter(data) {
|
|
23447
|
+
let pinnedPost = data;
|
|
23448
|
+
switch (this.query.sortBy) {
|
|
23449
|
+
case 'lastCreated':
|
|
23450
|
+
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 }));
|
|
23451
|
+
break;
|
|
23452
|
+
}
|
|
23453
|
+
return pinnedPost;
|
|
23454
|
+
}
|
|
23455
|
+
}
|
|
23456
|
+
|
|
23457
|
+
/**
|
|
23458
|
+
* Get pinned posts for a community
|
|
23459
|
+
*
|
|
23460
|
+
* @param communityId the ID of the community
|
|
23461
|
+
* @param placement the placement of the pinned post ('announcement' or 'default'), or null to fetch all pinned posts
|
|
23462
|
+
* @returns the associated pinned post(s)
|
|
23463
|
+
*
|
|
23464
|
+
* @category Pined Posts Live Collection
|
|
23465
|
+
*
|
|
23466
|
+
*/
|
|
23467
|
+
const getPinnedPosts = (params, callback, config) => {
|
|
23468
|
+
const { log, cache } = getActiveClient();
|
|
23469
|
+
if (!cache) {
|
|
23470
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
23471
|
+
}
|
|
23472
|
+
const timestamp = Date.now();
|
|
23473
|
+
log(`getPinnedPosts(tmpid: ${timestamp}) > listen`);
|
|
23474
|
+
const pinnedPostLiveCollection = new PinnedPostLiveCollectionController(params, callback);
|
|
23475
|
+
const disposers = pinnedPostLiveCollection.startSubscription();
|
|
23476
|
+
const cacheKey = pinnedPostLiveCollection.getCacheKey();
|
|
23477
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
23478
|
+
return () => {
|
|
23479
|
+
log(`getPinnedPosts(tmpid: ${timestamp}) > dispose`);
|
|
23480
|
+
disposers.forEach(fn => fn());
|
|
23481
|
+
};
|
|
23482
|
+
};
|
|
23483
|
+
|
|
22488
23484
|
var index$5 = /*#__PURE__*/Object.freeze({
|
|
22489
23485
|
__proto__: null,
|
|
22490
23486
|
getPostByIds: getPostByIds,
|
|
@@ -22511,7 +23507,8 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
22511
23507
|
observePosts: observePosts,
|
|
22512
23508
|
observePost: observePost,
|
|
22513
23509
|
getPost: getPost$1,
|
|
22514
|
-
getPosts: getPosts
|
|
23510
|
+
getPosts: getPosts,
|
|
23511
|
+
getPinnedPosts: getPinnedPosts
|
|
22515
23512
|
});
|
|
22516
23513
|
|
|
22517
23514
|
/* begin_public_function
|
|
@@ -23400,7 +24397,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
23400
24397
|
getPoll: getPoll
|
|
23401
24398
|
});
|
|
23402
24399
|
|
|
23403
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
24400
|
+
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-----";
|
|
23404
24401
|
/*
|
|
23405
24402
|
* The crypto algorithm used for importing key and signing string
|
|
23406
24403
|
*/
|