@amityco/ts-sdk-react-native 6.36.1-938a6a9.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +26 -26
- package/dist/@types/core/events.d.ts +6 -6
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/domains/analytics.d.ts +0 -3
- package/dist/@types/domains/analytics.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +9 -33
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +0 -4
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +2 -10
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +0 -11
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +0 -12
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/subChannel.d.ts +0 -4
- package/dist/@types/domains/subChannel.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +1 -5
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/channelRepository/api/deleteChannel.d.ts.map +1 -1
- package/dist/channelRepository/api/index.d.ts +0 -1
- package/dist/channelRepository/api/index.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/getMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/searchMembers.d.ts.map +1 -1
- package/dist/channelRepository/{api → internalApi}/getChannel.d.ts +2 -2
- package/dist/channelRepository/internalApi/getChannel.d.ts.map +1 -0
- package/dist/channelRepository/internalApi/getChannelByIds.d.ts +32 -0
- package/dist/channelRepository/internalApi/getChannelByIds.d.ts.map +1 -0
- package/dist/channelRepository/{api → internalApi}/markAsRead.d.ts +0 -3
- package/dist/channelRepository/internalApi/markAsRead.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/index.d.ts +0 -2
- package/dist/channelRepository/observers/index.d.ts.map +1 -1
- package/dist/channelRepository/utils/constructChannelDynamicValue.d.ts.map +1 -1
- package/dist/channelRepository/utils/constructChannelObject.d.ts +2 -0
- package/dist/channelRepository/utils/constructChannelObject.d.ts.map +1 -0
- package/dist/channelRepository/utils/getChannelIsMentioned.d.ts +1 -1
- package/dist/channelRepository/utils/getChannelIsMentioned.d.ts.map +1 -1
- package/dist/channelRepository/utils/getSubChannelsUnreadCount.d.ts +1 -1
- package/dist/channelRepository/utils/getSubChannelsUnreadCount.d.ts.map +1 -1
- package/dist/channelRepository/utils/resolveChannels.d.ts.map +1 -1
- package/dist/channelRepository/utils/updateChannelCache.d.ts +1 -1
- package/dist/channelRepository/utils/updateChannelCache.d.ts.map +1 -1
- package/dist/client/observers/index.d.ts +0 -1
- package/dist/client/observers/index.d.ts.map +1 -1
- package/dist/client/utils/endpoints.d.ts +1 -1
- package/dist/client/utils/markerSyncEngine.d.ts +0 -4
- package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
- package/dist/client/utils/subscribeGlobalTopic.d.ts.map +1 -1
- package/dist/commentRepository/observers/index.d.ts +0 -2
- package/dist/commentRepository/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/api/index.d.ts +0 -1
- package/dist/communityRepository/api/index.d.ts.map +1 -1
- package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities/CommunitiesPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/index.d.ts +0 -1
- package/dist/communityRepository/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities.d.ts +1 -1
- package/dist/communityRepository/observers/searchCommunities.d.ts.map +1 -1
- package/dist/communityRepository/utils/communityQueryFilter.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/subscription.d.ts +1 -0
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +2 -35
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +1 -1
- package/dist/feedRepository/api/queryGlobalFeed.d.ts +2 -24
- package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/fileRepository/api/index.d.ts +0 -3
- package/dist/fileRepository/api/index.d.ts.map +1 -1
- package/dist/fileRepository/index.d.ts +0 -1
- package/dist/fileRepository/index.d.ts.map +1 -1
- package/dist/index.cjs.js +1262 -2689
- package/dist/index.esm.js +1226 -2654
- package/dist/index.umd.js +3 -3
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -5
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +0 -1
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
- package/dist/messageRepository/api/index.d.ts +0 -1
- package/dist/messageRepository/api/index.d.ts.map +1 -1
- package/dist/messageRepository/internalApi/getMessage.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/getMessages.d.ts +0 -1
- package/dist/messageRepository/observers/getMessages/getMessages.d.ts.map +1 -1
- package/dist/messageRepository/observers/index.d.ts +0 -2
- package/dist/messageRepository/observers/index.d.ts.map +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
- package/dist/pollRepository/observers/index.d.ts +0 -1
- package/dist/pollRepository/observers/index.d.ts.map +1 -1
- package/dist/postRepository/api/index.d.ts +0 -1
- package/dist/postRepository/api/index.d.ts.map +1 -1
- package/dist/postRepository/observers/index.d.ts +0 -2
- package/dist/postRepository/observers/index.d.ts.map +1 -1
- package/dist/role/api/queryRoles.d.ts +0 -7
- package/dist/role/api/queryRoles.d.ts.map +1 -1
- package/dist/streamRepository/api/index.d.ts +0 -2
- package/dist/streamRepository/api/index.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamFlagged.d.ts.map +1 -1
- package/dist/streamRepository/internalApi/getStream.d.ts.map +1 -0
- package/dist/subChannelRepository/utils/markReadEngine.d.ts +0 -34
- package/dist/subChannelRepository/utils/markReadEngine.d.ts.map +1 -1
- package/dist/userRepository/internalApi/queryUsers.d.ts.map +1 -1
- package/dist/userRepository/observers/getUsers/UserLiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/observers/getUsers/UserPaginationController.d.ts.map +1 -1
- package/dist/userRepository/observers/index.d.ts +0 -2
- package/dist/userRepository/observers/index.d.ts.map +1 -1
- package/dist/userRepository/relationship/block/index.d.ts +0 -1
- package/dist/userRepository/relationship/block/index.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/index.d.ts +0 -2
- package/dist/userRepository/relationship/follow/api/index.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/index.d.ts +0 -3
- package/dist/userRepository/relationship/follow/observers/index.d.ts.map +1 -1
- package/dist/utils/liveObject.d.ts +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +8 -9
- package/src/@types/domains/analytics.ts +0 -7
- package/src/@types/domains/channel.ts +15 -46
- package/src/@types/domains/client.ts +0 -4
- package/src/@types/domains/community.ts +0 -8
- package/src/@types/domains/feed.ts +0 -11
- package/src/@types/domains/message.ts +0 -12
- package/src/@types/domains/subChannel.ts +0 -4
- package/src/@types/domains/user.ts +0 -4
- package/src/channelRepository/api/deleteChannel.ts +3 -2
- package/src/channelRepository/api/getChannelByIds.ts +5 -5
- package/src/channelRepository/api/index.ts +0 -2
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +0 -8
- package/src/channelRepository/channelMembership/observers/getMembers/getMembers.ts +0 -8
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.ts +0 -8
- package/src/channelRepository/channelMembership/observers/searchMembers/searchMembers.ts +0 -8
- package/src/channelRepository/{api → internalApi}/getChannel.ts +4 -4
- package/src/channelRepository/internalApi/getChannelByIds.ts +105 -0
- package/src/channelRepository/{api → internalApi}/markAsRead.ts +0 -3
- package/src/channelRepository/observers/getChannel.ts +36 -15
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +11 -12
- package/src/channelRepository/observers/index.ts +0 -2
- package/src/channelRepository/utils/constructChannelDynamicValue.ts +4 -9
- package/src/channelRepository/utils/constructChannelObject.ts +16 -0
- package/src/channelRepository/utils/getChannelIsMentioned.ts +4 -1
- package/src/channelRepository/utils/getSubChannelsUnreadCount.ts +1 -1
- package/src/channelRepository/utils/resolveChannels.ts +7 -2
- package/src/channelRepository/utils/updateChannelCache.ts +4 -1
- package/src/client/observers/getUserUnread.ts +1 -1
- package/src/client/observers/index.ts +0 -1
- package/src/client/utils/endpoints.ts +1 -1
- package/src/client/utils/markerSyncEngine.ts +0 -9
- package/src/client/utils/subscribeGlobalTopic.ts +3 -0
- package/src/commentRepository/observers/index.ts +0 -2
- package/src/communityRepository/api/index.ts +0 -3
- package/src/communityRepository/api/queryCommunities.ts +1 -2
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +0 -12
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +0 -7
- package/src/communityRepository/communityMembership/observers/getMembers.ts +0 -4
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +1 -1
- package/src/communityRepository/communityMembership/observers/tests/getMembers.test.ts +0 -1
- package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +12 -16
- package/src/communityRepository/observers/getCommunities/CommunitiesPaginationController.ts +0 -1
- package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +0 -4
- package/src/communityRepository/observers/index.ts +0 -2
- package/src/communityRepository/observers/searchCommunities.ts +1 -1
- package/src/communityRepository/observers/tests/getCommunities.test.ts +0 -1
- package/src/communityRepository/utils/communityQueryFilter.ts +1 -8
- package/src/core/events.ts +7 -5
- package/src/core/subscription.ts +6 -0
- package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +8 -55
- package/src/feedRepository/api/queryGlobalFeed.ts +6 -58
- package/src/feedRepository/api/test/getCustomRankingGlobalFeed.test.ts +1 -1
- package/src/feedRepository/api/test/queryGlobalFeed.test.ts +1 -1
- package/src/fileRepository/api/index.ts +0 -5
- package/src/fileRepository/index.ts +0 -1
- package/src/liveStreamPlayer/api/getPlayer.ts +1 -1
- package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +2 -2
- package/src/messageRepository/api/createMessage.ts +5 -1
- package/src/messageRepository/api/index.ts +0 -2
- package/src/messageRepository/api/tests/createMessage.test.ts +6 -1
- package/src/messageRepository/api/tests/deleteMessage.test.ts +5 -1
- package/src/messageRepository/internalApi/getMessage.ts +0 -6
- package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +0 -20
- package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +0 -10
- package/src/messageRepository/observers/getMessages/getMessages.ts +0 -54
- package/src/messageRepository/observers/index.ts +0 -3
- package/src/messageRepository/utils/prepareMessagePayload.ts +1 -7
- package/src/pollRepository/observers/index.ts +0 -1
- package/src/postRepository/api/index.ts +0 -1
- package/src/postRepository/observers/index.ts +0 -2
- package/src/role/api/queryRoles.ts +1 -13
- package/src/streamRepository/api/deleteStream.ts +1 -1
- package/src/streamRepository/api/index.ts +0 -4
- package/src/streamRepository/api/tests/getStream.test.ts +1 -1
- package/src/streamRepository/events/onStreamFlagged.ts +1 -6
- package/src/streamRepository/events/onStreamRecorded.ts +1 -1
- package/src/streamRepository/events/onStreamStarted.ts +1 -1
- package/src/streamRepository/events/onStreamStopped.ts +1 -1
- package/src/streamRepository/events/onStreamTerminated.ts +1 -1
- package/src/streamRepository/observers/getStreamById.ts +1 -1
- package/src/subChannelRepository/utils/markReadEngine.ts +0 -106
- package/src/userRepository/internalApi/queryUsers.ts +1 -9
- package/src/userRepository/observers/getUsers/UserLiveCollectionController.ts +12 -16
- package/src/userRepository/observers/getUsers/UserPaginationController.ts +1 -2
- package/src/userRepository/observers/index.ts +0 -2
- package/src/userRepository/observers/tests/getUsers.test.ts +1 -43
- package/src/userRepository/relationship/block/index.ts +0 -1
- package/src/userRepository/relationship/follow/api/index.ts +0 -4
- package/src/userRepository/relationship/follow/observers/index.ts +0 -4
- package/src/utils/linkedObject/channelLinkedObject.ts +1 -1
- package/src/utils/liveObject.ts +2 -2
- package/dist/channelRepository/api/getChannel.d.ts.map +0 -1
- package/dist/channelRepository/api/markAsRead.d.ts.map +0 -1
- package/dist/channelRepository/observers/observeChannel.d.ts +0 -18
- package/dist/channelRepository/observers/observeChannel.d.ts.map +0 -1
- package/dist/channelRepository/observers/observeChannels.d.ts +0 -17
- package/dist/channelRepository/observers/observeChannels.d.ts.map +0 -1
- package/dist/client/observers/getTotalUnreadCount.d.ts +0 -20
- package/dist/client/observers/getTotalUnreadCount.d.ts.map +0 -1
- package/dist/client/observers/tests/getTotalUnreadCount.test.d.ts +0 -2
- package/dist/client/observers/tests/getTotalUnreadCount.test.d.ts.map +0 -1
- package/dist/commentRepository/observers/observeComment.d.ts +0 -18
- package/dist/commentRepository/observers/observeComment.d.ts.map +0 -1
- package/dist/commentRepository/observers/observeComments.d.ts +0 -26
- package/dist/commentRepository/observers/observeComments.d.ts.map +0 -1
- package/dist/communityRepository/api/getTopTrendingCommunities.d.ts +0 -35
- package/dist/communityRepository/api/getTopTrendingCommunities.d.ts.map +0 -1
- package/dist/communityRepository/api/test/getTopTrendingCommunities.test.d.ts +0 -2
- package/dist/communityRepository/api/test/getTopTrendingCommunities.test.d.ts.map +0 -1
- package/dist/communityRepository/observers/observeCommunity.d.ts +0 -18
- package/dist/communityRepository/observers/observeCommunity.d.ts.map +0 -1
- package/dist/feedRepository/internalApi/getCustomRankingGlobalFeed.d.ts +0 -8
- package/dist/feedRepository/internalApi/getCustomRankingGlobalFeed.d.ts.map +0 -1
- package/dist/feedRepository/internalApi/index.d.ts +0 -3
- package/dist/feedRepository/internalApi/index.d.ts.map +0 -1
- package/dist/feedRepository/internalApi/queryGlobalFeed.d.ts +0 -9
- package/dist/feedRepository/internalApi/queryGlobalFeed.d.ts.map +0 -1
- package/dist/feedRepository/internalApi/test/getCustomRankingGlobalFeed.test.d.ts +0 -2
- package/dist/feedRepository/internalApi/test/getCustomRankingGlobalFeed.test.d.ts.map +0 -1
- package/dist/feedRepository/internalApi/test/queryGlobalFeed.test.d.ts +0 -2
- package/dist/feedRepository/internalApi/test/queryGlobalFeed.test.d.ts.map +0 -1
- package/dist/fileRepository/api/createFile.d.ts +0 -17
- package/dist/fileRepository/api/createFile.d.ts.map +0 -1
- package/dist/fileRepository/api/createImage.d.ts +0 -17
- package/dist/fileRepository/api/createImage.d.ts.map +0 -1
- package/dist/fileRepository/api/createVideo.d.ts +0 -18
- package/dist/fileRepository/api/createVideo.d.ts.map +0 -1
- package/dist/fileRepository/observers/index.d.ts +0 -2
- package/dist/fileRepository/observers/index.d.ts.map +0 -1
- package/dist/fileRepository/observers/observeFile.d.ts +0 -18
- package/dist/fileRepository/observers/observeFile.d.ts.map +0 -1
- package/dist/messageRepository/api/getMessage.d.ts +0 -32
- package/dist/messageRepository/api/getMessage.d.ts.map +0 -1
- package/dist/messageRepository/api/getMessages.d.ts +0 -32
- package/dist/messageRepository/api/getMessages.d.ts.map +0 -1
- package/dist/messageRepository/observers/observeMessage.d.ts +0 -21
- package/dist/messageRepository/observers/observeMessage.d.ts.map +0 -1
- package/dist/messageRepository/observers/observeMessages.d.ts +0 -23
- package/dist/messageRepository/observers/observeMessages.d.ts.map +0 -1
- package/dist/pollRepository/observers/observePoll.d.ts +0 -18
- package/dist/pollRepository/observers/observePoll.d.ts.map +0 -1
- package/dist/postRepository/api/updatePost.d.ts +0 -24
- package/dist/postRepository/api/updatePost.d.ts.map +0 -1
- package/dist/postRepository/observers/observePost.d.ts +0 -18
- package/dist/postRepository/observers/observePost.d.ts.map +0 -1
- package/dist/postRepository/observers/observePosts.d.ts +0 -34
- package/dist/postRepository/observers/observePosts.d.ts.map +0 -1
- package/dist/streamRepository/api/getStream.d.ts.map +0 -1
- package/dist/streamRepository/api/queryStreams.d.ts +0 -25
- package/dist/streamRepository/api/queryStreams.d.ts.map +0 -1
- package/dist/userRepository/observers/getViewedUsers.d.ts +0 -7
- package/dist/userRepository/observers/getViewedUsers.d.ts.map +0 -1
- package/dist/userRepository/observers/observeUser.d.ts +0 -17
- package/dist/userRepository/observers/observeUser.d.ts.map +0 -1
- package/dist/userRepository/observers/tests/getViewedUsers.test.d.ts +0 -2
- package/dist/userRepository/observers/tests/getViewedUsers.test.d.ts.map +0 -1
- package/dist/userRepository/relationship/block/observers/getBlockedUsers.d.ts +0 -2
- package/dist/userRepository/relationship/block/observers/getBlockedUsers.d.ts.map +0 -1
- package/dist/userRepository/relationship/block/observers/index.d.ts +0 -2
- package/dist/userRepository/relationship/block/observers/index.d.ts.map +0 -1
- package/dist/userRepository/relationship/follow/api/acceptFollower.d.ts +0 -19
- package/dist/userRepository/relationship/follow/api/acceptFollower.d.ts.map +0 -1
- package/dist/userRepository/relationship/follow/api/declineFollower.d.ts +0 -19
- package/dist/userRepository/relationship/follow/api/declineFollower.d.ts.map +0 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowInfo.d.ts +0 -18
- package/dist/userRepository/relationship/follow/observers/observeFollowInfo.d.ts.map +0 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts +0 -18
- package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts.map +0 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts +0 -18
- package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts.map +0 -1
- package/src/channelRepository/observers/observeChannel.ts +0 -109
- package/src/channelRepository/observers/observeChannels.ts +0 -74
- package/src/client/observers/getTotalUnreadCount.ts +0 -53
- package/src/client/observers/tests/getTotalUnreadCount.test.ts +0 -101
- package/src/commentRepository/observers/observeComment.ts +0 -102
- package/src/commentRepository/observers/observeComments.ts +0 -77
- package/src/communityRepository/api/getTopTrendingCommunities.ts +0 -97
- package/src/communityRepository/api/test/getTopTrendingCommunities.test.ts +0 -102
- package/src/communityRepository/observers/observeCommunity.ts +0 -103
- package/src/feedRepository/internalApi/getCustomRankingGlobalFeed.ts +0 -87
- package/src/feedRepository/internalApi/index.ts +0 -2
- package/src/feedRepository/internalApi/queryGlobalFeed.ts +0 -95
- package/src/feedRepository/internalApi/test/getCustomRankingGlobalFeed.test.ts +0 -138
- package/src/feedRepository/internalApi/test/queryGlobalFeed.test.ts +0 -130
- package/src/fileRepository/api/createFile.ts +0 -59
- package/src/fileRepository/api/createImage.ts +0 -59
- package/src/fileRepository/api/createVideo.ts +0 -69
- package/src/fileRepository/observers/index.ts +0 -1
- package/src/fileRepository/observers/observeFile.ts +0 -49
- package/src/messageRepository/api/getMessage.ts +0 -102
- package/src/messageRepository/api/getMessages.ts +0 -83
- package/src/messageRepository/observers/observeMessage.ts +0 -94
- package/src/messageRepository/observers/observeMessages.ts +0 -89
- package/src/pollRepository/observers/observePoll.ts +0 -67
- package/src/postRepository/api/updatePost.ts +0 -63
- package/src/postRepository/observers/observePost.ts +0 -115
- package/src/postRepository/observers/observePosts.ts +0 -86
- package/src/streamRepository/api/queryStreams.ts +0 -63
- package/src/userRepository/observers/getViewedUsers.ts +0 -99
- package/src/userRepository/observers/observeUser.ts +0 -71
- package/src/userRepository/observers/tests/getViewedUsers.test.ts +0 -39
- package/src/userRepository/relationship/block/observers/getBlockedUsers.ts +0 -13
- package/src/userRepository/relationship/block/observers/index.ts +0 -1
- package/src/userRepository/relationship/follow/api/acceptFollower.ts +0 -40
- package/src/userRepository/relationship/follow/api/declineFollower.ts +0 -40
- package/src/userRepository/relationship/follow/observers/observeFollowInfo.ts +0 -64
- package/src/userRepository/relationship/follow/observers/observeFollowers.ts +0 -74
- package/src/userRepository/relationship/follow/observers/observeFollowings.ts +0 -74
- /package/dist/streamRepository/{api → internalApi}/getStream.d.ts +0 -0
- /package/src/streamRepository/{api → internalApi}/getStream.ts +0 -0
package/dist/index.cjs.js
CHANGED
|
@@ -123,8 +123,8 @@ const PostContentType = Object.freeze({
|
|
|
123
123
|
|
|
124
124
|
function getVersion() {
|
|
125
125
|
try {
|
|
126
|
-
// the string ''
|
|
127
|
-
return '
|
|
126
|
+
// the string ''v7.0.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
127
|
+
return 'v7.0.0-cjs';
|
|
128
128
|
}
|
|
129
129
|
catch (error) {
|
|
130
130
|
return '__dev__';
|
|
@@ -1352,9 +1352,6 @@ const WS_EVENTS = [
|
|
|
1352
1352
|
'sessionStateChange',
|
|
1353
1353
|
// for internal use by accessTokenExpiryWatcher
|
|
1354
1354
|
'tokenExpired',
|
|
1355
|
-
'v3.video-streaming.didRecord',
|
|
1356
|
-
'v3.video-streaming.didStart',
|
|
1357
|
-
'v3.video-streaming.didStop',
|
|
1358
1355
|
];
|
|
1359
1356
|
const MQTT_EVENTS = [
|
|
1360
1357
|
'connect',
|
|
@@ -1364,7 +1361,12 @@ const MQTT_EVENTS = [
|
|
|
1364
1361
|
'close',
|
|
1365
1362
|
'end',
|
|
1366
1363
|
'reconnect',
|
|
1367
|
-
'
|
|
1364
|
+
'video-streaming.didStart',
|
|
1365
|
+
'video-streaming.didRecord',
|
|
1366
|
+
'video-streaming.didStop',
|
|
1367
|
+
'video-streaming.didFlag',
|
|
1368
|
+
'video-streaming.didTerminate',
|
|
1369
|
+
// 'user.didGlobalBan' remove due to message event,
|
|
1368
1370
|
];
|
|
1369
1371
|
/** @hidden */
|
|
1370
1372
|
const createEventEmitter = () => {
|
|
@@ -1563,7 +1565,11 @@ function subscribeTopic(topic, callback) {
|
|
|
1563
1565
|
return () => null;
|
|
1564
1566
|
modifyMqttConnection();
|
|
1565
1567
|
return mqtt.subscribe(topic, callback);
|
|
1566
|
-
}
|
|
1568
|
+
}
|
|
1569
|
+
const getLiveStreamTopic = () => {
|
|
1570
|
+
const user = getActiveUser();
|
|
1571
|
+
return `${getNetworkId(user)}/videostreaming`;
|
|
1572
|
+
};
|
|
1567
1573
|
|
|
1568
1574
|
var _a;
|
|
1569
1575
|
/* eslint-disable no-undef */
|
|
@@ -1599,7 +1605,7 @@ const API_REGIONS = {
|
|
|
1599
1605
|
US: 'us',
|
|
1600
1606
|
};
|
|
1601
1607
|
const URLS = {
|
|
1602
|
-
http: 'https://
|
|
1608
|
+
http: 'https://apix.{region}.amity.co',
|
|
1603
1609
|
mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
|
|
1604
1610
|
};
|
|
1605
1611
|
function computeUrl(type, region) {
|
|
@@ -4417,6 +4423,7 @@ const subscribeGlobalTopic = () => {
|
|
|
4417
4423
|
// subscribing to user topic is necessary to handle ban event
|
|
4418
4424
|
subscribeTopic(getUserTopic(getActiveUser())),
|
|
4419
4425
|
subscribeTopic(getMarkerUserFeedTopic()),
|
|
4426
|
+
subscribeTopic(getLiveStreamTopic()),
|
|
4420
4427
|
];
|
|
4421
4428
|
return () => disposers.forEach(fn => fn());
|
|
4422
4429
|
};
|
|
@@ -5956,9 +5963,6 @@ const reactorLinkedObject = (reactor) => {
|
|
|
5956
5963
|
* import { ChannelRepository } from '@amityco/ts-sdk-react-native'
|
|
5957
5964
|
* const success = await ChannelRepository.markAsRead('channelId')
|
|
5958
5965
|
* ```
|
|
5959
|
-
*
|
|
5960
|
-
* @deprecated Please use the {@link Amity.Channel.markAsRead} method instead
|
|
5961
|
-
*
|
|
5962
5966
|
* Updating all {@link Amity.SubChannel} in specify {@link Amity.Channel} as read
|
|
5963
5967
|
*
|
|
5964
5968
|
* @param channelId the ID of to specify {@link Amity.Channel}
|
|
@@ -6571,7 +6575,7 @@ const prepareMessagePayload = async (payload, event) => {
|
|
|
6571
6575
|
var _a, _b;
|
|
6572
6576
|
const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
6573
6577
|
// exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
|
|
6574
|
-
const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "
|
|
6578
|
+
const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "isMentioned"]);
|
|
6575
6579
|
updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
|
|
6576
6580
|
});
|
|
6577
6581
|
}
|
|
@@ -6585,15 +6589,12 @@ function convertParams(_a) {
|
|
|
6585
6589
|
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
|
|
6586
6590
|
}
|
|
6587
6591
|
function convertQueryParams$1(_a) {
|
|
6588
|
-
var { sortBy, subChannelId,
|
|
6592
|
+
var { sortBy, subChannelId, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
|
|
6589
6593
|
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: inferIsDeleted(includeDeleted), options: {
|
|
6590
6594
|
sortBy,
|
|
6591
6595
|
limit: limit || COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
6592
6596
|
around: aroundMessageId,
|
|
6593
6597
|
} });
|
|
6594
|
-
if (tags) {
|
|
6595
|
-
out.includeTags = tags;
|
|
6596
|
-
}
|
|
6597
6598
|
if (includingTags) {
|
|
6598
6599
|
out.includeTags = includingTags;
|
|
6599
6600
|
}
|
|
@@ -7077,22 +7078,27 @@ const getSubChannelsUnreadCount = (channel, marker) => {
|
|
|
7077
7078
|
};
|
|
7078
7079
|
|
|
7079
7080
|
const constructChannelDynamicValue = (channel) => {
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
return getSubChannelsUnreadCount(channel);
|
|
7083
|
-
},
|
|
7084
|
-
get hasMentioned() {
|
|
7085
|
-
return getChannelIsMentioned(channel);
|
|
7086
|
-
},
|
|
7081
|
+
const rest = __rest(channel, ["messageCount"]);
|
|
7082
|
+
return shallowClone(rest, {
|
|
7087
7083
|
get isMentioned() {
|
|
7088
|
-
return getChannelIsMentioned(
|
|
7084
|
+
return getChannelIsMentioned(rest);
|
|
7089
7085
|
},
|
|
7090
7086
|
get subChannelsUnreadCount() {
|
|
7091
|
-
return getSubChannelsUnreadCount(
|
|
7087
|
+
return getSubChannelsUnreadCount(rest);
|
|
7092
7088
|
},
|
|
7093
7089
|
});
|
|
7094
7090
|
};
|
|
7095
7091
|
|
|
7092
|
+
const constructChannelObject = (channel) => {
|
|
7093
|
+
/**
|
|
7094
|
+
* convert internal cache data to be public channel data
|
|
7095
|
+
* 1. [getChannelMessagePreviewWithUser] add messagePreview >> Amity.InternalChannel -> Amity.InternalChannel
|
|
7096
|
+
* 2. [constructChannelDynamicValue] construct getter value >> Amity.StaticInternalChannel -> Amity.Channel
|
|
7097
|
+
* 3. [LinkedObject.channel] add markAsRead >> Amity.InternalChannel -> Amity.Channel
|
|
7098
|
+
*/
|
|
7099
|
+
return LinkedObject.channel(constructChannelDynamicValue(getChannelMessagePreviewWithUser(channel)));
|
|
7100
|
+
};
|
|
7101
|
+
|
|
7096
7102
|
/**
|
|
7097
7103
|
* ```js
|
|
7098
7104
|
* import { getChannelByIds } from '@amityco/ts-sdk-react-native'
|
|
@@ -7107,7 +7113,7 @@ const constructChannelDynamicValue = (channel) => {
|
|
|
7107
7113
|
* @category Channel API
|
|
7108
7114
|
* @async
|
|
7109
7115
|
*/
|
|
7110
|
-
const getChannelByIds = async (channelIds) => {
|
|
7116
|
+
const getChannelByIds$1 = async (channelIds) => {
|
|
7111
7117
|
const client = getActiveClient();
|
|
7112
7118
|
client.log('channel/getChannelByIds', channelIds);
|
|
7113
7119
|
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
@@ -7137,7 +7143,7 @@ const getChannelByIds = async (channelIds) => {
|
|
|
7137
7143
|
ingestInCache(data, { cachedAt });
|
|
7138
7144
|
fireEvent('local.channel.fetched', data.channels);
|
|
7139
7145
|
return {
|
|
7140
|
-
data: data.channels.map(channel =>
|
|
7146
|
+
data: data.channels.map(channel => constructChannelObject(channel)),
|
|
7141
7147
|
cachedAt,
|
|
7142
7148
|
};
|
|
7143
7149
|
};
|
|
@@ -7154,7 +7160,7 @@ const getChannelByIds = async (channelIds) => {
|
|
|
7154
7160
|
*
|
|
7155
7161
|
* @category Channel API
|
|
7156
7162
|
*/
|
|
7157
|
-
getChannelByIds.locally = (channelIds) => {
|
|
7163
|
+
getChannelByIds$1.locally = (channelIds) => {
|
|
7158
7164
|
var _a, _b;
|
|
7159
7165
|
const client = getActiveClient();
|
|
7160
7166
|
client.log('channel/getChannelByIds.locally', channelIds);
|
|
@@ -7168,7 +7174,7 @@ getChannelByIds.locally = (channelIds) => {
|
|
|
7168
7174
|
const channels = cached.map(({ data }) => data);
|
|
7169
7175
|
const oldest = (_b = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _b === void 0 ? void 0 : _b[0];
|
|
7170
7176
|
return {
|
|
7171
|
-
data: channels.map(channel =>
|
|
7177
|
+
data: channels.map(channel => constructChannelObject(channel)),
|
|
7172
7178
|
cachedAt: oldest.cachedAt,
|
|
7173
7179
|
};
|
|
7174
7180
|
};
|
|
@@ -7226,35 +7232,6 @@ const setIntervalTask = (handler, timeout) => {
|
|
|
7226
7232
|
return () => clearInterval(timer);
|
|
7227
7233
|
};
|
|
7228
7234
|
|
|
7229
|
-
const onOnline = (callback) => {
|
|
7230
|
-
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
7231
|
-
window.addEventListener('online', callback);
|
|
7232
|
-
return () => window.removeEventListener('online', callback);
|
|
7233
|
-
}
|
|
7234
|
-
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
7235
|
-
document.addEventListener('online', callback);
|
|
7236
|
-
return () => document.removeEventListener('online', callback);
|
|
7237
|
-
}
|
|
7238
|
-
// @TODO: Please update code below to follow our coding conventions and our TS rules
|
|
7239
|
-
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
7240
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
7241
|
-
let unsubscribeFn = () => { };
|
|
7242
|
-
Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@react-native-community/netinfo')); }).then(NetInfo => {
|
|
7243
|
-
unsubscribeFn = NetInfo.addEventListener(state => {
|
|
7244
|
-
if (!state.isConnected)
|
|
7245
|
-
return;
|
|
7246
|
-
callback();
|
|
7247
|
-
});
|
|
7248
|
-
});
|
|
7249
|
-
return () => {
|
|
7250
|
-
unsubscribeFn();
|
|
7251
|
-
};
|
|
7252
|
-
}
|
|
7253
|
-
// Handle unsupported environment
|
|
7254
|
-
console.error('Unsupported environment');
|
|
7255
|
-
return () => console.error('Unsupported environment');
|
|
7256
|
-
};
|
|
7257
|
-
|
|
7258
7235
|
/**
|
|
7259
7236
|
* ```js
|
|
7260
7237
|
* import { SubChannel } from '@amityco/ts-sdk-react-native'
|
|
@@ -7287,73 +7264,8 @@ const readingAPI = async (messageFeedIds) => {
|
|
|
7287
7264
|
return true;
|
|
7288
7265
|
};
|
|
7289
7266
|
|
|
7290
|
-
/**
|
|
7291
|
-
* ```js
|
|
7292
|
-
* import { SubChannel } from '@amityco/ts-sdk-react-native'
|
|
7293
|
-
* const success = await SubChannel('foo')
|
|
7294
|
-
* ```
|
|
7295
|
-
*
|
|
7296
|
-
* Mark all messages as read and start reading message inside channel
|
|
7297
|
-
*
|
|
7298
|
-
* @param messageFeedId - Sub channel ID to start reading.
|
|
7299
|
-
* @return A success boolean if reading of the sub channel had begun.
|
|
7300
|
-
*
|
|
7301
|
-
* @category Channel API
|
|
7302
|
-
* @async
|
|
7303
|
-
* @private
|
|
7304
|
-
*/
|
|
7305
|
-
const startReadingAPI = async (messageFeedId) => {
|
|
7306
|
-
const client = getActiveClient();
|
|
7307
|
-
client.log('subChannel/startReadingAPI', messageFeedId);
|
|
7308
|
-
const { data: payload } = await client.http.post(`/api/v1/markers/message-feeds/${messageFeedId}/start-reading`);
|
|
7309
|
-
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, feedMarkers, userMarkers, } = payload;
|
|
7310
|
-
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
7311
|
-
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
7312
|
-
const cachedAt = client.cache && Date.now();
|
|
7313
|
-
if (client.cache)
|
|
7314
|
-
ingestInCache({ userEntityMarkers, userFeedMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
7315
|
-
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
7316
|
-
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
7317
|
-
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
7318
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
7319
|
-
return true;
|
|
7320
|
-
};
|
|
7321
|
-
|
|
7322
|
-
/**
|
|
7323
|
-
* ```js
|
|
7324
|
-
* import { stopReading } from '@amityco/ts-sdk-react-native'
|
|
7325
|
-
* const success = await stopReading('foo')
|
|
7326
|
-
* ```
|
|
7327
|
-
*
|
|
7328
|
-
* Mark all messages as read and stop reading message inside channel
|
|
7329
|
-
*
|
|
7330
|
-
* @param messageFeedId - The sub channel ID to stop reading.
|
|
7331
|
-
* @return A success boolean if reading of the sub channel had begun.
|
|
7332
|
-
*
|
|
7333
|
-
* @category Channel API
|
|
7334
|
-
* @async
|
|
7335
|
-
* @private
|
|
7336
|
-
*/
|
|
7337
|
-
const stopReadingAPI = async (messageFeedId) => {
|
|
7338
|
-
const client = getActiveClient();
|
|
7339
|
-
client.log('channel/stopReadingAPI', messageFeedId);
|
|
7340
|
-
const { data: payload } = await client.http.post(`/api/v1/markers/message-feeds/${messageFeedId}/stop-reading`);
|
|
7341
|
-
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, feedMarkers, userMarkers, } = payload;
|
|
7342
|
-
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
7343
|
-
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
7344
|
-
const cachedAt = client.cache && Date.now();
|
|
7345
|
-
if (client.cache)
|
|
7346
|
-
ingestInCache({ userEntityMarkers, userFeedMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
7347
|
-
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
7348
|
-
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
7349
|
-
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
7350
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
7351
|
-
return true;
|
|
7352
|
-
};
|
|
7353
|
-
|
|
7354
7267
|
const START_READING_INTERVAL_TIME = 30000;
|
|
7355
7268
|
let isSyncRunning$1 = false;
|
|
7356
|
-
let disposers$2 = [];
|
|
7357
7269
|
/**
|
|
7358
7270
|
* map contains subChannelId and isReading flag to determine which subChannel is on reading state
|
|
7359
7271
|
*/
|
|
@@ -7397,91 +7309,6 @@ const markReadEngineOnLoginHandler = () => {
|
|
|
7397
7309
|
stopIntervalTask();
|
|
7398
7310
|
};
|
|
7399
7311
|
};
|
|
7400
|
-
const getParentChannelId$1 = async (subChannelId) => {
|
|
7401
|
-
const cached = getSubChannel$1.locally(subChannelId);
|
|
7402
|
-
if (cached) {
|
|
7403
|
-
return cached.data.channelId;
|
|
7404
|
-
}
|
|
7405
|
-
const { data } = await getSubChannel$1(subChannelId);
|
|
7406
|
-
return data.channelId;
|
|
7407
|
-
};
|
|
7408
|
-
const registerEventListeners$1 = () => {
|
|
7409
|
-
if (disposers$2.length > 0) {
|
|
7410
|
-
return;
|
|
7411
|
-
}
|
|
7412
|
-
disposers$2.push(onOnline(() => {
|
|
7413
|
-
// Start reading the reading subChannel again when resume from offline state
|
|
7414
|
-
startReadingFromReadingList();
|
|
7415
|
-
}));
|
|
7416
|
-
};
|
|
7417
|
-
const registerTopicSubscribers$1 = async (subChannelId) => {
|
|
7418
|
-
const channelId = await getParentChannelId$1(subChannelId);
|
|
7419
|
-
const markedMessageTopic = getMarkedMessageTopic({ channelId, subChannelId });
|
|
7420
|
-
disposers$2.push(subscribeTopic(markedMessageTopic));
|
|
7421
|
-
};
|
|
7422
|
-
const disposeAll = () => {
|
|
7423
|
-
disposers$2.forEach(fn => fn());
|
|
7424
|
-
disposers$2 = [];
|
|
7425
|
-
};
|
|
7426
|
-
/* begin_public_function
|
|
7427
|
-
id: subchannel.start_reading
|
|
7428
|
-
*/
|
|
7429
|
-
/**
|
|
7430
|
-
* @deprecated Use {@link startMessageReceiptSync} instead.
|
|
7431
|
-
* ```js
|
|
7432
|
-
* import { startReading } from '@amityco/ts-sdk-react-native'
|
|
7433
|
-
* const success = await startReading('foo')
|
|
7434
|
-
* ```
|
|
7435
|
-
*
|
|
7436
|
-
* Set local reading state of channel to `true` and then call mark all
|
|
7437
|
-
* messages as read API.
|
|
7438
|
-
*
|
|
7439
|
-
* @param subChannelId - The sub channel ID to start reading.
|
|
7440
|
-
* @return A success boolean if reading of the sub channel had begun.
|
|
7441
|
-
*
|
|
7442
|
-
* @category Channel API
|
|
7443
|
-
* @async
|
|
7444
|
-
*/
|
|
7445
|
-
const startReading = async (subChannelId) => {
|
|
7446
|
-
isReadingMap[subChannelId] = true;
|
|
7447
|
-
if (disposers$2.length === 0) {
|
|
7448
|
-
registerEventListeners$1();
|
|
7449
|
-
registerTopicSubscribers$1(subChannelId);
|
|
7450
|
-
}
|
|
7451
|
-
try {
|
|
7452
|
-
return await startReadingAPI(subChannelId);
|
|
7453
|
-
}
|
|
7454
|
-
catch (e) {
|
|
7455
|
-
isReadingMap[subChannelId] = false;
|
|
7456
|
-
return false;
|
|
7457
|
-
}
|
|
7458
|
-
};
|
|
7459
|
-
/* end_public_function */
|
|
7460
|
-
/* begin_public_function
|
|
7461
|
-
id: subchannel.stop_reading
|
|
7462
|
-
*/
|
|
7463
|
-
/**
|
|
7464
|
-
* @deprecated Use {@link stopMessageReceiptSync} instead.
|
|
7465
|
-
* ```js
|
|
7466
|
-
* import { stopReading } from '@amityco/ts-sdk-react-native'
|
|
7467
|
-
* const success = await stopReading('foo')
|
|
7468
|
-
* ```
|
|
7469
|
-
*
|
|
7470
|
-
* Set local reading state of channel to `false` and then call mark all
|
|
7471
|
-
* messages as unread API.
|
|
7472
|
-
*
|
|
7473
|
-
* @param subChannelId - The sub channel ID to stop reading.
|
|
7474
|
-
* @return A success boolean if reading of the sub channel had begun.
|
|
7475
|
-
*
|
|
7476
|
-
* @category Channel API
|
|
7477
|
-
* @async
|
|
7478
|
-
*/
|
|
7479
|
-
const stopReading = (subChannelId) => {
|
|
7480
|
-
isReadingMap[subChannelId] = false;
|
|
7481
|
-
disposeAll();
|
|
7482
|
-
return stopReadingAPI(subChannelId);
|
|
7483
|
-
};
|
|
7484
|
-
/* end_public_function */
|
|
7485
7312
|
setIntervalTask(async () => {
|
|
7486
7313
|
if (!isSyncRunning$1)
|
|
7487
7314
|
return;
|
|
@@ -7636,7 +7463,7 @@ const initializeMessagePreviewSetting = async () => {
|
|
|
7636
7463
|
* 2. channel and subChannel which isDelete = true
|
|
7637
7464
|
*/
|
|
7638
7465
|
if (channelWithIsDeletedTrue.length !== 0)
|
|
7639
|
-
await getChannelByIds(channelWithIsDeletedTrue);
|
|
7466
|
+
await getChannelByIds$1(channelWithIsDeletedTrue);
|
|
7640
7467
|
if (subChannelWithIsDeletedTrue.length !== 0)
|
|
7641
7468
|
await getSubChannels$1(subChannelWithIsDeletedTrue);
|
|
7642
7469
|
}
|
|
@@ -8034,6 +7861,35 @@ var readReceiptSyncEngineOnLoginHandler = () => {
|
|
|
8034
7861
|
};
|
|
8035
7862
|
};
|
|
8036
7863
|
|
|
7864
|
+
const onOnline = (callback) => {
|
|
7865
|
+
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
7866
|
+
window.addEventListener('online', callback);
|
|
7867
|
+
return () => window.removeEventListener('online', callback);
|
|
7868
|
+
}
|
|
7869
|
+
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
7870
|
+
document.addEventListener('online', callback);
|
|
7871
|
+
return () => document.removeEventListener('online', callback);
|
|
7872
|
+
}
|
|
7873
|
+
// @TODO: Please update code below to follow our coding conventions and our TS rules
|
|
7874
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
7875
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
7876
|
+
let unsubscribeFn = () => { };
|
|
7877
|
+
Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@react-native-community/netinfo')); }).then(NetInfo => {
|
|
7878
|
+
unsubscribeFn = NetInfo.addEventListener(state => {
|
|
7879
|
+
if (!state.isConnected)
|
|
7880
|
+
return;
|
|
7881
|
+
callback();
|
|
7882
|
+
});
|
|
7883
|
+
});
|
|
7884
|
+
return () => {
|
|
7885
|
+
unsubscribeFn();
|
|
7886
|
+
};
|
|
7887
|
+
}
|
|
7888
|
+
// Handle unsupported environment
|
|
7889
|
+
console.error('Unsupported environment');
|
|
7890
|
+
return () => console.error('Unsupported environment');
|
|
7891
|
+
};
|
|
7892
|
+
|
|
8037
7893
|
const onOffline = (callback) => {
|
|
8038
7894
|
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
8039
7895
|
window.addEventListener('offline', callback);
|
|
@@ -8063,8 +7919,90 @@ const onOffline = (callback) => {
|
|
|
8063
7919
|
return () => console.error('Unsupported environment');
|
|
8064
7920
|
};
|
|
8065
7921
|
|
|
7922
|
+
/**
|
|
7923
|
+
* ```js
|
|
7924
|
+
* import { getChannelByIds } from '@amityco/ts-sdk'
|
|
7925
|
+
* const channels = await getChannelByIds(['foo', 'bar'])
|
|
7926
|
+
* ```
|
|
7927
|
+
*
|
|
7928
|
+
* Fetches a collection of {@link Amity.Channel} objects
|
|
7929
|
+
*
|
|
7930
|
+
* @param channelIds the IDs of the {@link Amity.Channel} to fetch
|
|
7931
|
+
* @returns the associated collection of {@link Amity.Channel} objects
|
|
7932
|
+
*
|
|
7933
|
+
* @category Channel API
|
|
7934
|
+
* @async
|
|
7935
|
+
*/
|
|
7936
|
+
const getChannelByIds = async (channelIds) => {
|
|
7937
|
+
const client = getActiveClient();
|
|
7938
|
+
client.log('channel/getChannelByIds', channelIds);
|
|
7939
|
+
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
7940
|
+
let payload;
|
|
7941
|
+
try {
|
|
7942
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
7943
|
+
const response = await client.http.get(`/api/v3/channels/list`, {
|
|
7944
|
+
params: { channelIds: encodedChannelIds },
|
|
7945
|
+
});
|
|
7946
|
+
payload = response.data;
|
|
7947
|
+
}
|
|
7948
|
+
catch (error) {
|
|
7949
|
+
channelIds.forEach(channelId => {
|
|
7950
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
7951
|
+
// NOTE: use channelPublicId as tombstone cache key since we cannot get the channelPrivateId that come along with channel data from server
|
|
7952
|
+
pushToTombstone('channel', channelId);
|
|
7953
|
+
}
|
|
7954
|
+
});
|
|
7955
|
+
throw error;
|
|
7956
|
+
}
|
|
7957
|
+
const data = await prepareChannelPayload(payload);
|
|
7958
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
7959
|
+
await prepareUnreadCountInfo(payload);
|
|
7960
|
+
}
|
|
7961
|
+
const cachedAt = client.cache && Date.now();
|
|
7962
|
+
if (client.cache)
|
|
7963
|
+
ingestInCache(data, { cachedAt });
|
|
7964
|
+
fireEvent('local.channel.fetched', data.channels);
|
|
7965
|
+
return {
|
|
7966
|
+
data: data.channels,
|
|
7967
|
+
cachedAt,
|
|
7968
|
+
};
|
|
7969
|
+
};
|
|
7970
|
+
/**
|
|
7971
|
+
* ```js
|
|
7972
|
+
* import { getChannelByIds } from '@amityco/ts-sdk'
|
|
7973
|
+
* const channels = getChannelByIds.locally(['foo', 'bar']) ?? []
|
|
7974
|
+
* ```
|
|
7975
|
+
*
|
|
7976
|
+
* Fetches a collection of {@link Amity.Channel} objects from cache
|
|
7977
|
+
*
|
|
7978
|
+
* @param channelIds the IDs of the {@link Amity.Channel} to fetch
|
|
7979
|
+
* @returns the associated collection of {@link Amity.Channel} objects
|
|
7980
|
+
*
|
|
7981
|
+
* @category Channel API
|
|
7982
|
+
*/
|
|
7983
|
+
getChannelByIds.locally = (channelIds) => {
|
|
7984
|
+
var _a, _b;
|
|
7985
|
+
const client = getActiveClient();
|
|
7986
|
+
client.log('channel/getChannelByIds.locally', channelIds);
|
|
7987
|
+
if (!client.cache)
|
|
7988
|
+
return;
|
|
7989
|
+
const cached = (_a = queryCache(['channel', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
7990
|
+
return channelIds.includes(data.channelPublicId);
|
|
7991
|
+
});
|
|
7992
|
+
if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) < channelIds.length)
|
|
7993
|
+
return;
|
|
7994
|
+
const channels = cached.map(({ data }) => data);
|
|
7995
|
+
const oldest = (_b = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _b === void 0 ? void 0 : _b[0];
|
|
7996
|
+
return {
|
|
7997
|
+
data: channels,
|
|
7998
|
+
cachedAt: oldest.cachedAt,
|
|
7999
|
+
};
|
|
8000
|
+
};
|
|
8001
|
+
|
|
8066
8002
|
const resolveChannels = async (channelIds) => {
|
|
8067
|
-
|
|
8003
|
+
var _a, _b, _c;
|
|
8004
|
+
await getChannelByIds(channelIds);
|
|
8005
|
+
const channels = (_c = (_b = (_a = queryCache(['channel', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => data.channelPublicId && channelIds.includes(data.channelPublicId))) === null || _b === void 0 ? void 0 : _b.map(({ data }) => data)) !== null && _c !== void 0 ? _c : [];
|
|
8068
8006
|
fireEvent('local.channel.resolved', channels);
|
|
8069
8007
|
};
|
|
8070
8008
|
|
|
@@ -9192,13 +9130,6 @@ const stopUnreadSync = () => {
|
|
|
9192
9130
|
setMarkerSyncEvents([]);
|
|
9193
9131
|
unRegisterEventListeners();
|
|
9194
9132
|
};
|
|
9195
|
-
/**
|
|
9196
|
-
* @deprecated Please use `startUnreadSync` instead
|
|
9197
|
-
*/
|
|
9198
|
-
const stopUnreadSyncing = () => {
|
|
9199
|
-
console.warn('`stopUnreadSyncing` has been deprecated, please use `stopUnreadSync` instead');
|
|
9200
|
-
return stopUnreadSync();
|
|
9201
|
-
};
|
|
9202
9133
|
setIntervalTask(async () => {
|
|
9203
9134
|
if (!isSyncRunning)
|
|
9204
9135
|
return;
|
|
@@ -9954,100 +9885,6 @@ const removeFunctionProperties = (obj) => {
|
|
|
9954
9885
|
return Object.fromEntries(entries);
|
|
9955
9886
|
};
|
|
9956
9887
|
|
|
9957
|
-
/**
|
|
9958
|
-
* @deprecated This function is deprecated
|
|
9959
|
-
*/
|
|
9960
|
-
const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
|
|
9961
|
-
const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
|
|
9962
|
-
const { cache } = getActiveClient();
|
|
9963
|
-
if (!cache) {
|
|
9964
|
-
console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
|
|
9965
|
-
}
|
|
9966
|
-
let model;
|
|
9967
|
-
let isUnsyncedModel = false; // for messages
|
|
9968
|
-
const disposers = [];
|
|
9969
|
-
const dispatcher = (data) => {
|
|
9970
|
-
const { data: newModel } = data, rest = __rest(data, ["data"]);
|
|
9971
|
-
if (!callbackFilter || callbackFilter(newModel, model)) {
|
|
9972
|
-
callback(Object.assign({ data: callbackDataSelector(newModel) }, rest));
|
|
9973
|
-
}
|
|
9974
|
-
// resolve all getter on data model to a static value to avoid comparison problems
|
|
9975
|
-
model = convertGetterPropsToStatic(newModel);
|
|
9976
|
-
};
|
|
9977
|
-
const realtimeRouter = (eventModel, forceDispatch = false) => {
|
|
9978
|
-
if (id !== eventModel[key]) {
|
|
9979
|
-
return;
|
|
9980
|
-
}
|
|
9981
|
-
if (model) {
|
|
9982
|
-
if (!forceDispatch && isEqual(model, eventModel)) {
|
|
9983
|
-
return;
|
|
9984
|
-
}
|
|
9985
|
-
}
|
|
9986
|
-
dispatcher({ loading: false, data: eventModel, origin: 'event' });
|
|
9987
|
-
};
|
|
9988
|
-
const onFetch = () => {
|
|
9989
|
-
// TODO: Ihis `@ts-ignore` is bring back to fix the build and it needs to be removed later
|
|
9990
|
-
// @ts-ignore
|
|
9991
|
-
const query = createQuery(fetcher, id, true);
|
|
9992
|
-
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
9993
|
-
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
9994
|
-
dispatcher({
|
|
9995
|
-
// @ts-ignore
|
|
9996
|
-
data,
|
|
9997
|
-
origin,
|
|
9998
|
-
loading: false,
|
|
9999
|
-
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
10000
|
-
});
|
|
10001
|
-
isUnsyncedModel = true;
|
|
10002
|
-
disposers.forEach(fn => fn());
|
|
10003
|
-
}
|
|
10004
|
-
else if (!isUnsyncedModel) {
|
|
10005
|
-
// @ts-ignore
|
|
10006
|
-
dispatcher({ loading, data, origin, error });
|
|
10007
|
-
}
|
|
10008
|
-
if (error) {
|
|
10009
|
-
disposers.forEach(fn => fn());
|
|
10010
|
-
}
|
|
10011
|
-
});
|
|
10012
|
-
};
|
|
10013
|
-
disposers.push(...eventHandlers.map(fn => fn(eventModel => realtimeRouter(eventModel, forceDispatch))));
|
|
10014
|
-
onFetch();
|
|
10015
|
-
return () => {
|
|
10016
|
-
disposers.forEach(fn => fn());
|
|
10017
|
-
};
|
|
10018
|
-
};
|
|
10019
|
-
|
|
10020
|
-
/**
|
|
10021
|
-
* @deprecated Please use unreadCount from `getUserUnread` instead.
|
|
10022
|
-
*
|
|
10023
|
-
* ```js
|
|
10024
|
-
* import { getTotalUnreadCount } from '@amityco/ts-sdk-react-native';
|
|
10025
|
-
*
|
|
10026
|
-
* const unsubscribe = getTotalUnreadCount(response => {
|
|
10027
|
-
* totalUnreadCount = response.data;
|
|
10028
|
-
* });
|
|
10029
|
-
* ```
|
|
10030
|
-
*
|
|
10031
|
-
* Observe current user's unread count from {@link Amity.UserMarker}
|
|
10032
|
-
*
|
|
10033
|
-
* @param callback the function to call when new data are available
|
|
10034
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the events
|
|
10035
|
-
*
|
|
10036
|
-
* @category Message Live Object
|
|
10037
|
-
*/
|
|
10038
|
-
const getTotalUnreadCount = (callback) => {
|
|
10039
|
-
const { _id: userId } = getActiveUser();
|
|
10040
|
-
if (!userId)
|
|
10041
|
-
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
10042
|
-
const callbackDataSelector = (data) => { var _a; return (_a = data === null || data === void 0 ? void 0 : data.unreadCount) !== null && _a !== void 0 ? _a : 0; };
|
|
10043
|
-
return liveObject(userId, callback, 'userId', async () => {
|
|
10044
|
-
const { data: userMarker, cachedAt } = await getUserMarker();
|
|
10045
|
-
return { data: userMarker, cachedAt };
|
|
10046
|
-
}, [onUserMarkerFetchedLegacy], {
|
|
10047
|
-
callbackDataSelector,
|
|
10048
|
-
});
|
|
10049
|
-
};
|
|
10050
|
-
|
|
10051
9888
|
/**
|
|
10052
9889
|
*
|
|
10053
9890
|
* ```js
|
|
@@ -10089,7 +9926,7 @@ const getUserUnread = (callback) => {
|
|
|
10089
9926
|
model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
|
|
10090
9927
|
callback({
|
|
10091
9928
|
data: callbackModel
|
|
10092
|
-
? Object.assign(Object.assign({}, callbackModel), {
|
|
9929
|
+
? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
|
|
10093
9930
|
loading: data.loading,
|
|
10094
9931
|
error: data.error,
|
|
10095
9932
|
});
|
|
@@ -10180,7 +10017,6 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
10180
10017
|
onClientBanned: onClientBanned,
|
|
10181
10018
|
onSessionStateChange: onSessionStateChange,
|
|
10182
10019
|
onNetworkActivities: onNetworkActivities,
|
|
10183
|
-
getTotalUnreadCount: getTotalUnreadCount,
|
|
10184
10020
|
getUserUnread: getUserUnread,
|
|
10185
10021
|
getMarkerSyncEvents: getMarkerSyncEvents,
|
|
10186
10022
|
setMarkerSyncEvents: setMarkerSyncEvents,
|
|
@@ -10189,7 +10025,6 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
10189
10025
|
startMarkerSync: startMarkerSync,
|
|
10190
10026
|
startUnreadSync: startUnreadSync,
|
|
10191
10027
|
stopUnreadSync: stopUnreadSync,
|
|
10192
|
-
stopUnreadSyncing: stopUnreadSyncing,
|
|
10193
10028
|
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
|
|
10194
10029
|
});
|
|
10195
10030
|
|
|
@@ -10274,311 +10109,134 @@ const unBlockUser = async (userId) => {
|
|
|
10274
10109
|
};
|
|
10275
10110
|
/* end_public_function */
|
|
10276
10111
|
|
|
10277
|
-
|
|
10278
|
-
|
|
10279
|
-
|
|
10280
|
-
|
|
10281
|
-
|
|
10282
|
-
|
|
10283
|
-
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
|
|
10289
|
-
|
|
10290
|
-
|
|
10112
|
+
/* begin_public_function
|
|
10113
|
+
id: user.relationship.follow
|
|
10114
|
+
*/
|
|
10115
|
+
/**
|
|
10116
|
+
* ```js
|
|
10117
|
+
* import { follow } from '@amityco/ts-sdk-react-native'
|
|
10118
|
+
* const status = await follow('foobar')
|
|
10119
|
+
* ```
|
|
10120
|
+
*
|
|
10121
|
+
* Follow the user
|
|
10122
|
+
*
|
|
10123
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
10124
|
+
* @returns the status {@link Amity.FollowStatus}
|
|
10125
|
+
*
|
|
10126
|
+
* @category Follow API
|
|
10127
|
+
* @async
|
|
10128
|
+
*/
|
|
10129
|
+
const follow = async (userId) => {
|
|
10130
|
+
const client = getActiveClient();
|
|
10131
|
+
client.log('follow/follow', userId);
|
|
10132
|
+
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
10133
|
+
const cachedAt = client.cache && Date.now();
|
|
10134
|
+
if (client.cache) {
|
|
10135
|
+
ingestInCache(data, { cachedAt });
|
|
10291
10136
|
}
|
|
10292
|
-
|
|
10293
|
-
|
|
10294
|
-
|
|
10295
|
-
return;
|
|
10296
|
-
if (direction === 'next' && !this.nextToken)
|
|
10297
|
-
return;
|
|
10298
|
-
let token;
|
|
10299
|
-
if (direction === 'prev')
|
|
10300
|
-
token = this.previousToken;
|
|
10301
|
-
if (direction === 'next')
|
|
10302
|
-
token = this.nextToken;
|
|
10303
|
-
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
10304
|
-
if (direction === 'first') {
|
|
10305
|
-
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
10306
|
-
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
10307
|
-
}
|
|
10308
|
-
if (direction === 'prev')
|
|
10309
|
-
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
10310
|
-
if (direction === 'next')
|
|
10311
|
-
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
10312
|
-
return queryResponse;
|
|
10137
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10138
|
+
if (data.follows[0].status === 'accepted') {
|
|
10139
|
+
fireEvent('local.follow.created', payload);
|
|
10313
10140
|
}
|
|
10314
|
-
|
|
10315
|
-
|
|
10141
|
+
else {
|
|
10142
|
+
fireEvent('local.follow.requested', payload);
|
|
10316
10143
|
}
|
|
10317
|
-
|
|
10318
|
-
|
|
10144
|
+
return {
|
|
10145
|
+
data: data.follows[0],
|
|
10146
|
+
cachedAt,
|
|
10147
|
+
};
|
|
10148
|
+
};
|
|
10149
|
+
/* end_public_function */
|
|
10150
|
+
|
|
10151
|
+
/* begin_public_function
|
|
10152
|
+
id: user.relationship.unfollow
|
|
10153
|
+
*/
|
|
10154
|
+
/**
|
|
10155
|
+
* ```js
|
|
10156
|
+
* import { unfollow } from '@amityco/ts-sdk-react-native'
|
|
10157
|
+
* await unfollow('foobar')
|
|
10158
|
+
* ```
|
|
10159
|
+
*
|
|
10160
|
+
* Cancel the follow request or unfollow the user
|
|
10161
|
+
*
|
|
10162
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
10163
|
+
* @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
|
|
10164
|
+
*
|
|
10165
|
+
* @category Follow API
|
|
10166
|
+
* @async
|
|
10167
|
+
*/
|
|
10168
|
+
const unfollow = async (userId) => {
|
|
10169
|
+
const client = getActiveClient();
|
|
10170
|
+
client.log('follow/unfollow', userId);
|
|
10171
|
+
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
10172
|
+
if (client.cache) {
|
|
10173
|
+
ingestInCache(data);
|
|
10319
10174
|
}
|
|
10320
|
-
|
|
10175
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10176
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
10177
|
+
return true;
|
|
10178
|
+
};
|
|
10179
|
+
/* end_public_function */
|
|
10321
10180
|
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
|
|
10326
|
-
|
|
10327
|
-
|
|
10328
|
-
|
|
10329
|
-
|
|
10181
|
+
/* begin_public_function
|
|
10182
|
+
id: user.relationship.accept_follow
|
|
10183
|
+
*/
|
|
10184
|
+
/**
|
|
10185
|
+
* ```js
|
|
10186
|
+
* import { UserRepository } from '@amityco/ts-sdk-react-native'
|
|
10187
|
+
* await UserRepository.Relationship.acceptMyFollower('foobar')
|
|
10188
|
+
* ```
|
|
10189
|
+
*
|
|
10190
|
+
* Accept the follow request
|
|
10191
|
+
*
|
|
10192
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
10193
|
+
* @returns A success boolean if the follow request was accepted
|
|
10194
|
+
*
|
|
10195
|
+
* @category Follow API
|
|
10196
|
+
* @async
|
|
10197
|
+
*/
|
|
10198
|
+
const acceptMyFollower = async (userId) => {
|
|
10199
|
+
const client = getActiveClient();
|
|
10200
|
+
client.log('follow/acceptMyFollower', userId);
|
|
10201
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
10202
|
+
if (client.cache) {
|
|
10203
|
+
ingestInCache(data);
|
|
10330
10204
|
}
|
|
10331
|
-
|
|
10205
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10206
|
+
fireEvent('local.follow.accepted', payload);
|
|
10207
|
+
return true;
|
|
10208
|
+
};
|
|
10209
|
+
/* end_public_function */
|
|
10332
10210
|
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10336
|
-
|
|
10211
|
+
/* begin_public_function
|
|
10212
|
+
id: user.relationship.decline_follow
|
|
10213
|
+
*/
|
|
10214
|
+
/**
|
|
10215
|
+
* ```js
|
|
10216
|
+
* import { UserRepository } from '@amityco/ts-sdk-react-native'
|
|
10217
|
+
* await UserRepository.Relationship.declineMyFollower('foobar')
|
|
10218
|
+
* ```
|
|
10219
|
+
*
|
|
10220
|
+
* Decline the follow request or delete the follower
|
|
10221
|
+
*
|
|
10222
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
10223
|
+
* @returns A success boolean if the follow request was decline
|
|
10224
|
+
*
|
|
10225
|
+
* @category Follow API
|
|
10226
|
+
* @async
|
|
10227
|
+
*/
|
|
10228
|
+
const declineMyFollower = async (userId) => {
|
|
10229
|
+
const client = getActiveClient();
|
|
10230
|
+
client.log('follow/declineMyFollower', userId);
|
|
10231
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
10232
|
+
if (client.cache) {
|
|
10233
|
+
ingestInCache(data);
|
|
10337
10234
|
}
|
|
10338
|
-
|
|
10339
|
-
|
|
10340
|
-
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
10344
|
-
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
10345
|
-
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
10346
|
-
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
10347
|
-
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
10348
|
-
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
10349
|
-
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
10350
|
-
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
10351
|
-
|
|
10352
|
-
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
10353
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
10354
|
-
super(query, cacheKey);
|
|
10355
|
-
this.notifyChange = notifyChange;
|
|
10356
|
-
this.preparePayload = preparePayload;
|
|
10357
|
-
}
|
|
10358
|
-
async saveToMainDB(response) {
|
|
10359
|
-
const processedPayload = await this.preparePayload(response);
|
|
10360
|
-
const client = getActiveClient();
|
|
10361
|
-
const cachedAt = client.cache && Date.now();
|
|
10362
|
-
if (client.cache) {
|
|
10363
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
10364
|
-
}
|
|
10365
|
-
}
|
|
10366
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
10367
|
-
var _a, _b;
|
|
10368
|
-
if (refresh) {
|
|
10369
|
-
pushToCache(this.cacheKey, {
|
|
10370
|
-
data: response.users.map(getResolver('user')),
|
|
10371
|
-
});
|
|
10372
|
-
}
|
|
10373
|
-
else {
|
|
10374
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10375
|
-
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
10376
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
10377
|
-
}
|
|
10378
|
-
}
|
|
10379
|
-
reactor(action) {
|
|
10380
|
-
return (targetUser) => {
|
|
10381
|
-
var _a;
|
|
10382
|
-
if (action === EnumFollowActions.OnFollowed) {
|
|
10383
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10384
|
-
const updatedCollection = collection === null || collection === void 0 ? void 0 : collection.data.filter(id => id !== targetUser.userId);
|
|
10385
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: updatedCollection }));
|
|
10386
|
-
}
|
|
10387
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
10388
|
-
};
|
|
10389
|
-
}
|
|
10390
|
-
subscribeRTE(createSubscriber) {
|
|
10391
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
10392
|
-
}
|
|
10393
|
-
}
|
|
10394
|
-
|
|
10395
|
-
class PaginationNoPageController {
|
|
10396
|
-
constructor(queryParams) {
|
|
10397
|
-
const { http } = getActiveClient();
|
|
10398
|
-
this.queryParams = queryParams;
|
|
10399
|
-
this.http = http;
|
|
10400
|
-
}
|
|
10401
|
-
async onFetch() {
|
|
10402
|
-
const queryResponse = await this.getRequest(this.queryParams);
|
|
10403
|
-
return queryResponse;
|
|
10404
|
-
}
|
|
10405
|
-
}
|
|
10406
|
-
|
|
10407
|
-
class LiveCollectionController {
|
|
10408
|
-
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
10409
|
-
this.paginationController = paginationController;
|
|
10410
|
-
this.queryStreamId = queryStreamId;
|
|
10411
|
-
this.cacheKey = cacheKey;
|
|
10412
|
-
this.callback = callback;
|
|
10413
|
-
}
|
|
10414
|
-
async refresh() {
|
|
10415
|
-
try {
|
|
10416
|
-
let result;
|
|
10417
|
-
if (this.paginationController instanceof PaginationNoPageController) {
|
|
10418
|
-
result = await this.paginationController.onFetch();
|
|
10419
|
-
}
|
|
10420
|
-
else {
|
|
10421
|
-
result = await this.paginationController.loadFirstPage();
|
|
10422
|
-
}
|
|
10423
|
-
if (!result)
|
|
10424
|
-
return;
|
|
10425
|
-
await this.persistModel(result);
|
|
10426
|
-
this.persistQueryStream({
|
|
10427
|
-
response: result,
|
|
10428
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
10429
|
-
refresh: true,
|
|
10430
|
-
});
|
|
10431
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
10432
|
-
}
|
|
10433
|
-
catch (e) {
|
|
10434
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
10435
|
-
}
|
|
10436
|
-
}
|
|
10437
|
-
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
10438
|
-
this.setup();
|
|
10439
|
-
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
10440
|
-
if (initial) {
|
|
10441
|
-
this.refresh();
|
|
10442
|
-
}
|
|
10443
|
-
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
10444
|
-
this.loadPrevPage();
|
|
10445
|
-
}
|
|
10446
|
-
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
10447
|
-
this.loadNextPage();
|
|
10448
|
-
}
|
|
10449
|
-
}
|
|
10450
|
-
async loadNextPage() {
|
|
10451
|
-
try {
|
|
10452
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
10453
|
-
return;
|
|
10454
|
-
const result = await this.paginationController.loadNextPage();
|
|
10455
|
-
if (!result)
|
|
10456
|
-
return;
|
|
10457
|
-
await this.persistModel(result);
|
|
10458
|
-
this.persistQueryStream({
|
|
10459
|
-
response: result,
|
|
10460
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
10461
|
-
});
|
|
10462
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
10463
|
-
}
|
|
10464
|
-
catch (e) {
|
|
10465
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
10466
|
-
}
|
|
10467
|
-
}
|
|
10468
|
-
async loadPrevPage() {
|
|
10469
|
-
try {
|
|
10470
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
10471
|
-
return;
|
|
10472
|
-
const result = await this.paginationController.loadPreviousPage();
|
|
10473
|
-
if (!result)
|
|
10474
|
-
return;
|
|
10475
|
-
await this.persistModel(result);
|
|
10476
|
-
this.persistQueryStream({
|
|
10477
|
-
response: result,
|
|
10478
|
-
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
10479
|
-
});
|
|
10480
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
10481
|
-
}
|
|
10482
|
-
catch (e) {
|
|
10483
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
10484
|
-
}
|
|
10485
|
-
}
|
|
10486
|
-
shouldNotify(data) {
|
|
10487
|
-
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
10488
|
-
if (isEqual(this.snapshot, newData))
|
|
10489
|
-
return false;
|
|
10490
|
-
this.snapshot = newData;
|
|
10491
|
-
return true;
|
|
10492
|
-
}
|
|
10493
|
-
getCacheKey() {
|
|
10494
|
-
return this.cacheKey;
|
|
10495
|
-
}
|
|
10496
|
-
}
|
|
10497
|
-
|
|
10498
|
-
function prepareBlockedUserPayload(response) {
|
|
10499
|
-
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
10500
|
-
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
10501
|
-
const followUser = users.find(user => user.userId === follow.from);
|
|
10502
|
-
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
10503
|
-
}), users: users.map(convertRawUserToInternalUser) });
|
|
10504
|
-
}
|
|
10505
|
-
|
|
10506
|
-
/**
|
|
10507
|
-
* ```js
|
|
10508
|
-
* import { onUserUpdated } from '@amityco/ts-sdk-react-native'
|
|
10509
|
-
* const dispose = onUserUpdated(user => {
|
|
10510
|
-
* // ...
|
|
10511
|
-
* })
|
|
10512
|
-
* ```
|
|
10513
|
-
*
|
|
10514
|
-
* Fired when a {@link Amity.InternalUser} has been updated
|
|
10515
|
-
*
|
|
10516
|
-
* @param callback The function to call when the event was fired
|
|
10517
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10518
|
-
*
|
|
10519
|
-
* @category User Events
|
|
10520
|
-
*/
|
|
10521
|
-
const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
|
|
10522
|
-
|
|
10523
|
-
/**
|
|
10524
|
-
* ```js
|
|
10525
|
-
* import { onUserFlagged } from '@amityco/ts-sdk-react-native'
|
|
10526
|
-
* const dispose = onUserFlagged(user => {
|
|
10527
|
-
* // ...
|
|
10528
|
-
* })
|
|
10529
|
-
* ```
|
|
10530
|
-
*
|
|
10531
|
-
* Fired when a {@link Amity.InternalUser} has been flagged
|
|
10532
|
-
*
|
|
10533
|
-
* @param callback The function to call when the event was fired
|
|
10534
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10535
|
-
*
|
|
10536
|
-
* @category User Events
|
|
10537
|
-
*/
|
|
10538
|
-
const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
|
|
10539
|
-
|
|
10540
|
-
/**
|
|
10541
|
-
* ```js
|
|
10542
|
-
* import { onUserUnflagged } from '@amityco/ts-sdk-react-native'
|
|
10543
|
-
* const dispose = onUserUnflagged(user => {
|
|
10544
|
-
* // ...
|
|
10545
|
-
* })
|
|
10546
|
-
* ```
|
|
10547
|
-
*
|
|
10548
|
-
* Fired when a flag has been removed from a {@link Amity.InternalUser}
|
|
10549
|
-
*
|
|
10550
|
-
* @param callback The function to call when the event was fired
|
|
10551
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10552
|
-
*
|
|
10553
|
-
* @category User Events
|
|
10554
|
-
*/
|
|
10555
|
-
const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
|
|
10556
|
-
|
|
10557
|
-
/**
|
|
10558
|
-
* ```js
|
|
10559
|
-
* import { onUserFlagCleared } from '@amityco/ts-sdk-react-native'
|
|
10560
|
-
* const dispose = onUserFlagCleared(user => {
|
|
10561
|
-
* // ...
|
|
10562
|
-
* })
|
|
10563
|
-
* ```
|
|
10564
|
-
*
|
|
10565
|
-
* Fired when flags have been cleared for a {@link Amity.InternalUser}
|
|
10566
|
-
*
|
|
10567
|
-
* @param callback The function to call when the event was fired
|
|
10568
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10569
|
-
*
|
|
10570
|
-
* @category User Events
|
|
10571
|
-
*/
|
|
10572
|
-
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
10573
|
-
|
|
10574
|
-
var EnumUserActions;
|
|
10575
|
-
(function (EnumUserActions) {
|
|
10576
|
-
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
10577
|
-
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
10578
|
-
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
10579
|
-
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
10580
|
-
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
10581
|
-
})(EnumUserActions || (EnumUserActions = {}));
|
|
10235
|
+
const payload = prepareFollowStatusPayload(data);
|
|
10236
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
10237
|
+
return true;
|
|
10238
|
+
};
|
|
10239
|
+
/* end_public_function */
|
|
10582
10240
|
|
|
10583
10241
|
const createFollowEventSubscriber = (event, callback) => {
|
|
10584
10242
|
const client = getActiveClient();
|
|
@@ -10842,446 +10500,50 @@ const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscri
|
|
|
10842
10500
|
|
|
10843
10501
|
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
10844
10502
|
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
|
|
10503
|
+
class PaginationController {
|
|
10504
|
+
constructor(queryParams) {
|
|
10505
|
+
const { http } = getActiveClient();
|
|
10506
|
+
this.queryParams = queryParams;
|
|
10507
|
+
this.http = http;
|
|
10849
10508
|
}
|
|
10850
|
-
|
|
10851
|
-
|
|
10852
|
-
/*
|
|
10853
|
-
* NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
|
|
10854
|
-
* If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
|
|
10855
|
-
*/
|
|
10856
|
-
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
10857
|
-
? sourceModel[sourceModelProp]
|
|
10858
|
-
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
10859
|
-
const model = (_b = pullFromCache([
|
|
10860
|
-
destinationDomain,
|
|
10861
|
-
'get',
|
|
10862
|
-
`${resolvedId}`,
|
|
10863
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
10864
|
-
if (!model)
|
|
10865
|
-
return;
|
|
10866
|
-
return callback(model);
|
|
10867
|
-
});
|
|
10868
|
-
|
|
10869
|
-
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
10870
|
-
constructor(query, callback) {
|
|
10871
|
-
const queryStreamId = hash__default["default"](query);
|
|
10872
|
-
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
10873
|
-
const paginationController = new BlockedUserPaginationController(query);
|
|
10874
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
10875
|
-
this.query = query;
|
|
10876
|
-
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
10877
|
-
this.callback = callback.bind(this);
|
|
10878
|
-
this.loadPage({ initial: true });
|
|
10879
|
-
}
|
|
10880
|
-
setup() {
|
|
10881
|
-
var _a;
|
|
10882
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
10883
|
-
if (!collection) {
|
|
10884
|
-
pushToCache(this.cacheKey, {
|
|
10885
|
-
data: [],
|
|
10886
|
-
params: {},
|
|
10887
|
-
});
|
|
10888
|
-
}
|
|
10889
|
-
}
|
|
10890
|
-
async persistModel(queryPayload) {
|
|
10891
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
10509
|
+
loadFirstPage() {
|
|
10510
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
10892
10511
|
}
|
|
10893
|
-
|
|
10894
|
-
this.
|
|
10512
|
+
loadNextPage() {
|
|
10513
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
10895
10514
|
}
|
|
10896
|
-
|
|
10897
|
-
return this.
|
|
10898
|
-
{
|
|
10899
|
-
fn: onUserDeleted$2,
|
|
10900
|
-
action: EnumUserActions.OnUserDeleted,
|
|
10901
|
-
},
|
|
10902
|
-
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
10903
|
-
{
|
|
10904
|
-
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
10905
|
-
action: EnumFollowActions.OnFollowed,
|
|
10906
|
-
},
|
|
10907
|
-
{
|
|
10908
|
-
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
10909
|
-
action: EnumFollowActions.OnFollowed,
|
|
10910
|
-
},
|
|
10911
|
-
]);
|
|
10515
|
+
loadPreviousPage() {
|
|
10516
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
10912
10517
|
}
|
|
10913
|
-
|
|
10914
|
-
var _a, _b;
|
|
10915
|
-
|
|
10916
|
-
if (!collection)
|
|
10518
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
10519
|
+
var _a, _b, _c, _d;
|
|
10520
|
+
if (direction === 'prev' && !this.previousToken)
|
|
10917
10521
|
return;
|
|
10918
|
-
|
|
10919
|
-
.map(id => pullFromCache(['user', 'get', id]))
|
|
10920
|
-
.filter(isNonNullable)
|
|
10921
|
-
.map(({ data }) => data)
|
|
10922
|
-
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
10923
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
10522
|
+
if (direction === 'next' && !this.nextToken)
|
|
10924
10523
|
return;
|
|
10925
|
-
|
|
10926
|
-
|
|
10927
|
-
|
|
10928
|
-
|
|
10929
|
-
|
|
10930
|
-
|
|
10931
|
-
|
|
10932
|
-
|
|
10933
|
-
|
|
10934
|
-
|
|
10935
|
-
|
|
10936
|
-
|
|
10937
|
-
|
|
10938
|
-
|
|
10939
|
-
|
|
10940
|
-
|
|
10941
|
-
/* begin_public_function
|
|
10942
|
-
id: user.get_blocked_users
|
|
10943
|
-
*/
|
|
10944
|
-
/**
|
|
10945
|
-
* ```js
|
|
10946
|
-
* import { UserRepository } from '@amityco/ts-sdk-react-native'
|
|
10947
|
-
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
10948
|
-
* ```
|
|
10949
|
-
*
|
|
10950
|
-
* Blocks a {@link Amity.InternalUser}
|
|
10951
|
-
*
|
|
10952
|
-
* @param params The params to get blocked {@link Amity.InternalUser}s
|
|
10953
|
-
* @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
|
|
10954
|
-
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
10955
|
-
*
|
|
10956
|
-
* @category Post API
|
|
10957
|
-
* @async
|
|
10958
|
-
*/
|
|
10959
|
-
const getBlockedUsers$1 = (params, callback, config) => {
|
|
10960
|
-
const { log, cache } = getActiveClient();
|
|
10961
|
-
if (!cache) {
|
|
10962
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
10963
|
-
}
|
|
10964
|
-
const timestamp = Date.now();
|
|
10965
|
-
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
10966
|
-
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
10967
|
-
const disposers = blockedUserLiveCollection.startSubscription();
|
|
10968
|
-
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
10969
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
10970
|
-
return () => {
|
|
10971
|
-
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
10972
|
-
disposers.forEach(fn => fn());
|
|
10973
|
-
dropFromCache(cacheKey);
|
|
10974
|
-
};
|
|
10975
|
-
};
|
|
10976
|
-
/* end_public_function */
|
|
10977
|
-
|
|
10978
|
-
/* eslint-disable no-use-before-define */
|
|
10979
|
-
const getBlockedUsers = (params, callback, config) => {
|
|
10980
|
-
console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
|
|
10981
|
-
return getBlockedUsers$1(params, callback);
|
|
10982
|
-
};
|
|
10983
|
-
|
|
10984
|
-
/* begin_public_function
|
|
10985
|
-
id: user.relationship.follow
|
|
10986
|
-
*/
|
|
10987
|
-
/**
|
|
10988
|
-
* ```js
|
|
10989
|
-
* import { follow } from '@amityco/ts-sdk-react-native'
|
|
10990
|
-
* const status = await follow('foobar')
|
|
10991
|
-
* ```
|
|
10992
|
-
*
|
|
10993
|
-
* Follow the user
|
|
10994
|
-
*
|
|
10995
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
10996
|
-
* @returns the status {@link Amity.FollowStatus}
|
|
10997
|
-
*
|
|
10998
|
-
* @category Follow API
|
|
10999
|
-
* @async
|
|
11000
|
-
*/
|
|
11001
|
-
const follow = async (userId) => {
|
|
11002
|
-
const client = getActiveClient();
|
|
11003
|
-
client.log('follow/follow', userId);
|
|
11004
|
-
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
11005
|
-
const cachedAt = client.cache && Date.now();
|
|
11006
|
-
if (client.cache) {
|
|
11007
|
-
ingestInCache(data, { cachedAt });
|
|
11008
|
-
}
|
|
11009
|
-
const payload = prepareFollowStatusPayload(data);
|
|
11010
|
-
if (data.follows[0].status === 'accepted') {
|
|
11011
|
-
fireEvent('local.follow.created', payload);
|
|
11012
|
-
}
|
|
11013
|
-
else {
|
|
11014
|
-
fireEvent('local.follow.requested', payload);
|
|
11015
|
-
}
|
|
11016
|
-
return {
|
|
11017
|
-
data: data.follows[0],
|
|
11018
|
-
cachedAt,
|
|
11019
|
-
};
|
|
11020
|
-
};
|
|
11021
|
-
/* end_public_function */
|
|
11022
|
-
|
|
11023
|
-
/* begin_public_function
|
|
11024
|
-
id: user.relationship.unfollow
|
|
11025
|
-
*/
|
|
11026
|
-
/**
|
|
11027
|
-
* ```js
|
|
11028
|
-
* import { unfollow } from '@amityco/ts-sdk-react-native'
|
|
11029
|
-
* await unfollow('foobar')
|
|
11030
|
-
* ```
|
|
11031
|
-
*
|
|
11032
|
-
* Cancel the follow request or unfollow the user
|
|
11033
|
-
*
|
|
11034
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
11035
|
-
* @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
|
|
11036
|
-
*
|
|
11037
|
-
* @category Follow API
|
|
11038
|
-
* @async
|
|
11039
|
-
*/
|
|
11040
|
-
const unfollow = async (userId) => {
|
|
11041
|
-
const client = getActiveClient();
|
|
11042
|
-
client.log('follow/unfollow', userId);
|
|
11043
|
-
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
11044
|
-
if (client.cache) {
|
|
11045
|
-
ingestInCache(data);
|
|
11046
|
-
}
|
|
11047
|
-
const payload = prepareFollowStatusPayload(data);
|
|
11048
|
-
fireEvent('local.follow.unfollowed', payload);
|
|
11049
|
-
return true;
|
|
11050
|
-
};
|
|
11051
|
-
/* end_public_function */
|
|
11052
|
-
|
|
11053
|
-
/**
|
|
11054
|
-
* @deprecated This API renamed to `acceptMyFollower`.
|
|
11055
|
-
* Please use acceptMyFollower() instead.
|
|
11056
|
-
*
|
|
11057
|
-
* ```js
|
|
11058
|
-
* import { acceptFollower } from '@amityco/ts-sdk-react-native'
|
|
11059
|
-
* await acceptFollower('foobar')
|
|
11060
|
-
* ```
|
|
11061
|
-
*
|
|
11062
|
-
* Accept the follow request
|
|
11063
|
-
*
|
|
11064
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
11065
|
-
* @returns A success boolean if the follow request was accepted
|
|
11066
|
-
*
|
|
11067
|
-
* @category Follow API
|
|
11068
|
-
* @async
|
|
11069
|
-
*/
|
|
11070
|
-
const acceptFollower = async (userId) => {
|
|
11071
|
-
const client = getActiveClient();
|
|
11072
|
-
client.log('follow/acceptFollower', userId);
|
|
11073
|
-
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
11074
|
-
if (client.cache) {
|
|
11075
|
-
ingestInCache(data);
|
|
11076
|
-
}
|
|
11077
|
-
const payload = prepareFollowStatusPayload(data);
|
|
11078
|
-
fireEvent('local.follow.accepted', payload);
|
|
11079
|
-
return true;
|
|
11080
|
-
};
|
|
11081
|
-
|
|
11082
|
-
/* begin_public_function
|
|
11083
|
-
id: user.relationship.accept_follow
|
|
11084
|
-
*/
|
|
11085
|
-
/**
|
|
11086
|
-
* ```js
|
|
11087
|
-
* import { UserRepository } from '@amityco/ts-sdk-react-native'
|
|
11088
|
-
* await UserRepository.Relationship.acceptMyFollower('foobar')
|
|
11089
|
-
* ```
|
|
11090
|
-
*
|
|
11091
|
-
* Accept the follow request
|
|
11092
|
-
*
|
|
11093
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
11094
|
-
* @returns A success boolean if the follow request was accepted
|
|
11095
|
-
*
|
|
11096
|
-
* @category Follow API
|
|
11097
|
-
* @async
|
|
11098
|
-
*/
|
|
11099
|
-
const acceptMyFollower = async (userId) => {
|
|
11100
|
-
const client = getActiveClient();
|
|
11101
|
-
client.log('follow/acceptMyFollower', userId);
|
|
11102
|
-
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
11103
|
-
if (client.cache) {
|
|
11104
|
-
ingestInCache(data);
|
|
10524
|
+
let token;
|
|
10525
|
+
if (direction === 'prev')
|
|
10526
|
+
token = this.previousToken;
|
|
10527
|
+
if (direction === 'next')
|
|
10528
|
+
token = this.nextToken;
|
|
10529
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
10530
|
+
if (direction === 'first') {
|
|
10531
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
10532
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
10533
|
+
}
|
|
10534
|
+
if (direction === 'prev')
|
|
10535
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
10536
|
+
if (direction === 'next')
|
|
10537
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
10538
|
+
return queryResponse;
|
|
11105
10539
|
}
|
|
11106
|
-
|
|
11107
|
-
|
|
11108
|
-
return true;
|
|
11109
|
-
};
|
|
11110
|
-
/* end_public_function */
|
|
11111
|
-
|
|
11112
|
-
/**
|
|
11113
|
-
* @deprecated This API renamed to `declineMyFollower`.
|
|
11114
|
-
* Please use declineMyFollower() instead.
|
|
11115
|
-
*
|
|
11116
|
-
* ```js
|
|
11117
|
-
* import { declineFollower } from '@amityco/ts-sdk-react-native'
|
|
11118
|
-
* await declineFollower('foobar')
|
|
11119
|
-
* ```
|
|
11120
|
-
*
|
|
11121
|
-
* Decline the follow request or delete the follower
|
|
11122
|
-
*
|
|
11123
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
11124
|
-
* @returns A success boolean if the follow request was decline
|
|
11125
|
-
*
|
|
11126
|
-
* @category Follow API
|
|
11127
|
-
* @async
|
|
11128
|
-
*/
|
|
11129
|
-
const declineFollower = async (userId) => {
|
|
11130
|
-
const client = getActiveClient();
|
|
11131
|
-
client.log('follow/declineFollower', userId);
|
|
11132
|
-
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
11133
|
-
if (client.cache) {
|
|
11134
|
-
ingestInCache(data);
|
|
10540
|
+
getNextToken() {
|
|
10541
|
+
return this.nextToken;
|
|
11135
10542
|
}
|
|
11136
|
-
|
|
11137
|
-
|
|
11138
|
-
return true;
|
|
11139
|
-
};
|
|
11140
|
-
|
|
11141
|
-
/* begin_public_function
|
|
11142
|
-
id: user.relationship.decline_follow
|
|
11143
|
-
*/
|
|
11144
|
-
/**
|
|
11145
|
-
* ```js
|
|
11146
|
-
* import { UserRepository } from '@amityco/ts-sdk-react-native'
|
|
11147
|
-
* await UserRepository.Relationship.declineMyFollower('foobar')
|
|
11148
|
-
* ```
|
|
11149
|
-
*
|
|
11150
|
-
* Decline the follow request or delete the follower
|
|
11151
|
-
*
|
|
11152
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
11153
|
-
* @returns A success boolean if the follow request was decline
|
|
11154
|
-
*
|
|
11155
|
-
* @category Follow API
|
|
11156
|
-
* @async
|
|
11157
|
-
*/
|
|
11158
|
-
const declineMyFollower = async (userId) => {
|
|
11159
|
-
const client = getActiveClient();
|
|
11160
|
-
client.log('follow/declineMyFollower', userId);
|
|
11161
|
-
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
11162
|
-
if (client.cache) {
|
|
11163
|
-
ingestInCache(data);
|
|
10543
|
+
getPrevToken() {
|
|
10544
|
+
return this.previousToken;
|
|
11164
10545
|
}
|
|
11165
|
-
|
|
11166
|
-
fireEvent('local.follow.requestDeclined', payload);
|
|
11167
|
-
return true;
|
|
11168
|
-
};
|
|
11169
|
-
/* end_public_function */
|
|
11170
|
-
|
|
11171
|
-
/**
|
|
11172
|
-
* ```js
|
|
11173
|
-
* import { observeFollowInfo } from '@amityco/ts-sdk-react-native'
|
|
11174
|
-
*
|
|
11175
|
-
* let followInfo = {}
|
|
11176
|
-
* const dispose = observeFollowInfo(userId, updated => followInfo = updated)
|
|
11177
|
-
* ```
|
|
11178
|
-
*
|
|
11179
|
-
* Observe all mutation on a given {@link Amity.FollowInfo}
|
|
11180
|
-
*
|
|
11181
|
-
* @param userId the ID of the user to observe
|
|
11182
|
-
* @param callback the function to call when new data are available
|
|
11183
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
|
|
11184
|
-
*
|
|
11185
|
-
* @category Follow Observer
|
|
11186
|
-
*/
|
|
11187
|
-
const observeFollowInfo = (userId, callback, policy = 'cache_then_server') => {
|
|
11188
|
-
const { log } = getActiveClient();
|
|
11189
|
-
const timestamp = Date.now();
|
|
11190
|
-
log(`observeFollowInfo(tmpid: ${timestamp}) > listen`);
|
|
11191
|
-
const router = (result, action) => {
|
|
11192
|
-
var _a, _b;
|
|
11193
|
-
if (callback instanceof Function)
|
|
11194
|
-
return callback(result);
|
|
11195
|
-
if (action !== 'onFetch')
|
|
11196
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
11197
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
11198
|
-
};
|
|
11199
|
-
const realtimeRouter = (result, action) => {
|
|
11200
|
-
var _a;
|
|
11201
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
|
|
11202
|
-
return;
|
|
11203
|
-
router(result, action);
|
|
11204
|
-
};
|
|
11205
|
-
const disposers = [];
|
|
11206
|
-
disposers.push(onFollowInfoUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')));
|
|
11207
|
-
runQuery(createQuery(getFollowInfo$1, userId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
11208
|
-
return () => {
|
|
11209
|
-
log(`observeFollowInfo(tmpid: ${timestamp}) > dispose`);
|
|
11210
|
-
disposers.forEach(fn => fn());
|
|
11211
|
-
};
|
|
11212
|
-
};
|
|
11213
|
-
|
|
11214
|
-
/**
|
|
11215
|
-
* ```js
|
|
11216
|
-
* import { observeFollowers } from '@amityco/ts-sdk-react-native'
|
|
11217
|
-
*
|
|
11218
|
-
* let followers = []
|
|
11219
|
-
* const unsub = observeFollowers('userId', follower => merge(followers, follower))
|
|
11220
|
-
* ```
|
|
11221
|
-
*
|
|
11222
|
-
* Observe all mutations on a list of followers {@link Amity.FollowStatus} for a given user
|
|
11223
|
-
*
|
|
11224
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
11225
|
-
* @param callback the function to call when new data are available
|
|
11226
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
11227
|
-
*
|
|
11228
|
-
* @category Follow Observer
|
|
11229
|
-
*/
|
|
11230
|
-
const observeFollowers = (userId, callback) => {
|
|
11231
|
-
const { log } = getActiveClient();
|
|
11232
|
-
const timestamp = Date.now();
|
|
11233
|
-
log(`observeFollowers(tmpid: ${timestamp}) > listen`);
|
|
11234
|
-
const disposers = [];
|
|
11235
|
-
const router = (status, action) => {
|
|
11236
|
-
var _a, _b;
|
|
11237
|
-
if (callback instanceof Function) {
|
|
11238
|
-
return callback(status);
|
|
11239
|
-
}
|
|
11240
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
11241
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
11242
|
-
};
|
|
11243
|
-
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')));
|
|
11244
|
-
return () => {
|
|
11245
|
-
log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
|
|
11246
|
-
disposers.forEach(fn => fn());
|
|
11247
|
-
};
|
|
11248
|
-
};
|
|
11249
|
-
|
|
11250
|
-
/**
|
|
11251
|
-
* ```js
|
|
11252
|
-
* import { observeFollowings } from '@amityco/ts-sdk-react-native'
|
|
11253
|
-
*
|
|
11254
|
-
* let followings = []
|
|
11255
|
-
* const unsub = observeFollowers('userId', follower => merge(followings, following))
|
|
11256
|
-
* ```
|
|
11257
|
-
*
|
|
11258
|
-
* Observe all mutations on a list of followings {@link Amity.FollowStatus} for a given user
|
|
11259
|
-
*
|
|
11260
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
11261
|
-
* @param callback the function to call when new data are available
|
|
11262
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
11263
|
-
*
|
|
11264
|
-
* @category Follow Observer
|
|
11265
|
-
*/
|
|
11266
|
-
const observeFollowings = (userId, callback) => {
|
|
11267
|
-
const { log } = getActiveClient();
|
|
11268
|
-
const timestamp = Date.now();
|
|
11269
|
-
log(`observeFollowings(tmpid: ${timestamp}) > listen`);
|
|
11270
|
-
const disposers = [];
|
|
11271
|
-
const router = (status, action) => {
|
|
11272
|
-
var _a, _b;
|
|
11273
|
-
if (callback instanceof Function) {
|
|
11274
|
-
return callback(status);
|
|
11275
|
-
}
|
|
11276
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
11277
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
11278
|
-
};
|
|
11279
|
-
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')));
|
|
11280
|
-
return () => {
|
|
11281
|
-
log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
|
|
11282
|
-
disposers.forEach(fn => fn());
|
|
11283
|
-
};
|
|
11284
|
-
};
|
|
10546
|
+
}
|
|
11285
10547
|
|
|
11286
10548
|
class FollowerPaginationController extends PaginationController {
|
|
11287
10549
|
async getRequest(queryParams, token) {
|
|
@@ -11296,6 +10558,25 @@ class FollowerPaginationController extends PaginationController {
|
|
|
11296
10558
|
}
|
|
11297
10559
|
}
|
|
11298
10560
|
|
|
10561
|
+
class QueryStreamController {
|
|
10562
|
+
constructor(query, cacheKey) {
|
|
10563
|
+
this.query = query;
|
|
10564
|
+
this.cacheKey = cacheKey;
|
|
10565
|
+
}
|
|
10566
|
+
}
|
|
10567
|
+
|
|
10568
|
+
var EnumFollowActions;
|
|
10569
|
+
(function (EnumFollowActions) {
|
|
10570
|
+
EnumFollowActions["OnRequested"] = "onRequested";
|
|
10571
|
+
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
10572
|
+
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
10573
|
+
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
10574
|
+
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
10575
|
+
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
10576
|
+
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
10577
|
+
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
10578
|
+
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
10579
|
+
|
|
11299
10580
|
class FollowerQueryStreamController extends QueryStreamController {
|
|
11300
10581
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
11301
10582
|
super(query, cacheKey);
|
|
@@ -11351,6 +10632,109 @@ class FollowerQueryStreamController extends QueryStreamController {
|
|
|
11351
10632
|
}
|
|
11352
10633
|
}
|
|
11353
10634
|
|
|
10635
|
+
class PaginationNoPageController {
|
|
10636
|
+
constructor(queryParams) {
|
|
10637
|
+
const { http } = getActiveClient();
|
|
10638
|
+
this.queryParams = queryParams;
|
|
10639
|
+
this.http = http;
|
|
10640
|
+
}
|
|
10641
|
+
async onFetch() {
|
|
10642
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
10643
|
+
return queryResponse;
|
|
10644
|
+
}
|
|
10645
|
+
}
|
|
10646
|
+
|
|
10647
|
+
class LiveCollectionController {
|
|
10648
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
10649
|
+
this.paginationController = paginationController;
|
|
10650
|
+
this.queryStreamId = queryStreamId;
|
|
10651
|
+
this.cacheKey = cacheKey;
|
|
10652
|
+
this.callback = callback;
|
|
10653
|
+
}
|
|
10654
|
+
async refresh() {
|
|
10655
|
+
try {
|
|
10656
|
+
let result;
|
|
10657
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
10658
|
+
result = await this.paginationController.onFetch();
|
|
10659
|
+
}
|
|
10660
|
+
else {
|
|
10661
|
+
result = await this.paginationController.loadFirstPage();
|
|
10662
|
+
}
|
|
10663
|
+
if (!result)
|
|
10664
|
+
return;
|
|
10665
|
+
await this.persistModel(result);
|
|
10666
|
+
this.persistQueryStream({
|
|
10667
|
+
response: result,
|
|
10668
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
10669
|
+
refresh: true,
|
|
10670
|
+
});
|
|
10671
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
10672
|
+
}
|
|
10673
|
+
catch (e) {
|
|
10674
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
10675
|
+
}
|
|
10676
|
+
}
|
|
10677
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
10678
|
+
this.setup();
|
|
10679
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
10680
|
+
if (initial) {
|
|
10681
|
+
this.refresh();
|
|
10682
|
+
}
|
|
10683
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
10684
|
+
this.loadPrevPage();
|
|
10685
|
+
}
|
|
10686
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
10687
|
+
this.loadNextPage();
|
|
10688
|
+
}
|
|
10689
|
+
}
|
|
10690
|
+
async loadNextPage() {
|
|
10691
|
+
try {
|
|
10692
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
10693
|
+
return;
|
|
10694
|
+
const result = await this.paginationController.loadNextPage();
|
|
10695
|
+
if (!result)
|
|
10696
|
+
return;
|
|
10697
|
+
await this.persistModel(result);
|
|
10698
|
+
this.persistQueryStream({
|
|
10699
|
+
response: result,
|
|
10700
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
10701
|
+
});
|
|
10702
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
10703
|
+
}
|
|
10704
|
+
catch (e) {
|
|
10705
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
10706
|
+
}
|
|
10707
|
+
}
|
|
10708
|
+
async loadPrevPage() {
|
|
10709
|
+
try {
|
|
10710
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
10711
|
+
return;
|
|
10712
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
10713
|
+
if (!result)
|
|
10714
|
+
return;
|
|
10715
|
+
await this.persistModel(result);
|
|
10716
|
+
this.persistQueryStream({
|
|
10717
|
+
response: result,
|
|
10718
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
10719
|
+
});
|
|
10720
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
10721
|
+
}
|
|
10722
|
+
catch (e) {
|
|
10723
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
10724
|
+
}
|
|
10725
|
+
}
|
|
10726
|
+
shouldNotify(data) {
|
|
10727
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
10728
|
+
if (isEqual(this.snapshot, newData))
|
|
10729
|
+
return false;
|
|
10730
|
+
this.snapshot = newData;
|
|
10731
|
+
return true;
|
|
10732
|
+
}
|
|
10733
|
+
getCacheKey() {
|
|
10734
|
+
return this.cacheKey;
|
|
10735
|
+
}
|
|
10736
|
+
}
|
|
10737
|
+
|
|
11354
10738
|
const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
11355
10739
|
const client = getActiveClient();
|
|
11356
10740
|
const filter = (data) => {
|
|
@@ -11695,6 +11079,69 @@ const getFollowings = (params, callback, config) => {
|
|
|
11695
11079
|
};
|
|
11696
11080
|
/* end_public_function */
|
|
11697
11081
|
|
|
11082
|
+
/**
|
|
11083
|
+
* @deprecated This function will to be deprecated soon.
|
|
11084
|
+
*/
|
|
11085
|
+
const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
|
|
11086
|
+
const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
|
|
11087
|
+
const { cache } = getActiveClient();
|
|
11088
|
+
if (!cache) {
|
|
11089
|
+
console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
|
|
11090
|
+
}
|
|
11091
|
+
let model;
|
|
11092
|
+
let isUnsyncedModel = false; // for messages
|
|
11093
|
+
const disposers = [];
|
|
11094
|
+
const dispatcher = (data) => {
|
|
11095
|
+
const { data: newModel } = data, rest = __rest(data, ["data"]);
|
|
11096
|
+
if (!callbackFilter || callbackFilter(newModel, model)) {
|
|
11097
|
+
callback(Object.assign({ data: callbackDataSelector(newModel) }, rest));
|
|
11098
|
+
}
|
|
11099
|
+
// resolve all getter on data model to a static value to avoid comparison problems
|
|
11100
|
+
model = convertGetterPropsToStatic(newModel);
|
|
11101
|
+
};
|
|
11102
|
+
const realtimeRouter = (eventModel, forceDispatch = false) => {
|
|
11103
|
+
if (id !== eventModel[key]) {
|
|
11104
|
+
return;
|
|
11105
|
+
}
|
|
11106
|
+
if (model) {
|
|
11107
|
+
if (!forceDispatch && isEqual(model, eventModel)) {
|
|
11108
|
+
return;
|
|
11109
|
+
}
|
|
11110
|
+
}
|
|
11111
|
+
dispatcher({ loading: false, data: eventModel, origin: 'event' });
|
|
11112
|
+
};
|
|
11113
|
+
const onFetch = () => {
|
|
11114
|
+
// TODO: Ihis `@ts-ignore` is bring back to fix the build and it needs to be removed later
|
|
11115
|
+
// @ts-ignore
|
|
11116
|
+
const query = createQuery(fetcher, id, true);
|
|
11117
|
+
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
11118
|
+
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
11119
|
+
dispatcher({
|
|
11120
|
+
// @ts-ignore
|
|
11121
|
+
data,
|
|
11122
|
+
origin,
|
|
11123
|
+
loading: false,
|
|
11124
|
+
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
11125
|
+
});
|
|
11126
|
+
isUnsyncedModel = true;
|
|
11127
|
+
disposers.forEach(fn => fn());
|
|
11128
|
+
}
|
|
11129
|
+
else if (!isUnsyncedModel) {
|
|
11130
|
+
// @ts-ignore
|
|
11131
|
+
dispatcher({ loading, data, origin, error });
|
|
11132
|
+
}
|
|
11133
|
+
if (error) {
|
|
11134
|
+
disposers.forEach(fn => fn());
|
|
11135
|
+
}
|
|
11136
|
+
});
|
|
11137
|
+
};
|
|
11138
|
+
disposers.push(...eventHandlers.map(fn => fn(eventModel => realtimeRouter(eventModel, forceDispatch))));
|
|
11139
|
+
onFetch();
|
|
11140
|
+
return () => {
|
|
11141
|
+
disposers.forEach(fn => fn());
|
|
11142
|
+
};
|
|
11143
|
+
};
|
|
11144
|
+
|
|
11698
11145
|
/* begin_public_function
|
|
11699
11146
|
id: user.relationship.get_follow_info
|
|
11700
11147
|
*/
|
|
@@ -11760,12 +11207,9 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
11760
11207
|
__proto__: null,
|
|
11761
11208
|
blockUser: blockUser,
|
|
11762
11209
|
unBlockUser: unBlockUser,
|
|
11763
|
-
getBlockedUsers: getBlockedUsers,
|
|
11764
11210
|
follow: follow,
|
|
11765
11211
|
unfollow: unfollow,
|
|
11766
|
-
acceptFollower: acceptFollower,
|
|
11767
11212
|
acceptMyFollower: acceptMyFollower,
|
|
11768
|
-
declineFollower: declineFollower,
|
|
11769
11213
|
declineMyFollower: declineMyFollower,
|
|
11770
11214
|
onUserFollowed: onUserFollowed,
|
|
11771
11215
|
onUserUnfollowed: onUserUnfollowed,
|
|
@@ -11780,9 +11224,6 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
11780
11224
|
onLocalFollowerRequested: onLocalFollowerRequested,
|
|
11781
11225
|
onLocalFollowRequestAccepted: onLocalFollowRequestAccepted,
|
|
11782
11226
|
onLocalFollowRequestDeclined: onLocalFollowRequestDeclined,
|
|
11783
|
-
observeFollowInfo: observeFollowInfo,
|
|
11784
|
-
observeFollowers: observeFollowers,
|
|
11785
|
-
observeFollowings: observeFollowings,
|
|
11786
11227
|
getFollowers: getFollowers,
|
|
11787
11228
|
getFollowings: getFollowings,
|
|
11788
11229
|
getFollowInfo: getFollowInfo,
|
|
@@ -11919,56 +11360,124 @@ const flagUser = async (userId) => {
|
|
|
11919
11360
|
};
|
|
11920
11361
|
/* end_public_function */
|
|
11921
11362
|
|
|
11922
|
-
/* begin_public_function
|
|
11923
|
-
id: user.unflag
|
|
11924
|
-
*/
|
|
11363
|
+
/* begin_public_function
|
|
11364
|
+
id: user.unflag
|
|
11365
|
+
*/
|
|
11366
|
+
/**
|
|
11367
|
+
* ```js
|
|
11368
|
+
* import { UserRepository } from '@amityco/ts-sdk-react-native'
|
|
11369
|
+
* const unflagged = await UserRepository.unflagUser('post', postId)
|
|
11370
|
+
* ```
|
|
11371
|
+
*
|
|
11372
|
+
* @param userId The ID of the user to unflag
|
|
11373
|
+
* @returns the deleted report result
|
|
11374
|
+
*
|
|
11375
|
+
* @category User API
|
|
11376
|
+
* @async
|
|
11377
|
+
* */
|
|
11378
|
+
const unflagUser = async (userId) => {
|
|
11379
|
+
const client = getActiveClient();
|
|
11380
|
+
client.log('user/unflag', userId);
|
|
11381
|
+
const { data } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
11382
|
+
const payload = prepareUserPayload(data);
|
|
11383
|
+
if (client.cache) {
|
|
11384
|
+
ingestInCache(payload);
|
|
11385
|
+
}
|
|
11386
|
+
fireEvent('user.unflagged', data);
|
|
11387
|
+
return !!payload;
|
|
11388
|
+
};
|
|
11389
|
+
/* end_public_function */
|
|
11390
|
+
|
|
11391
|
+
/* begin_public_function
|
|
11392
|
+
id: user.check_flag_by_me
|
|
11393
|
+
*/
|
|
11394
|
+
/**
|
|
11395
|
+
* ```js
|
|
11396
|
+
* import { UserRepository } from '@amityco/ts-sdk-react-native'
|
|
11397
|
+
* const isFlagged = await UserRepository.isUserFlaggedByMe(postId)
|
|
11398
|
+
* ```
|
|
11399
|
+
*
|
|
11400
|
+
* @param userId The ID of the thing to check a report to.
|
|
11401
|
+
* @returns `true` if the report is created by me, `false` if doesn't.
|
|
11402
|
+
*
|
|
11403
|
+
* @category Report API
|
|
11404
|
+
* @async
|
|
11405
|
+
* */
|
|
11406
|
+
const isUserFlaggedByMe = async (userId) => {
|
|
11407
|
+
const client = getActiveClient();
|
|
11408
|
+
client.log('user/isUserFlaggedByMe', userId);
|
|
11409
|
+
const { data: { isFlagByMe }, } = await client.http.get(`/api/v3/users/${userId}/isFlagByMe`);
|
|
11410
|
+
return isFlagByMe;
|
|
11411
|
+
};
|
|
11412
|
+
/* end_public_function */
|
|
11413
|
+
|
|
11414
|
+
/**
|
|
11415
|
+
* ```js
|
|
11416
|
+
* import { onUserUpdated } from '@amityco/ts-sdk-react-native'
|
|
11417
|
+
* const dispose = onUserUpdated(user => {
|
|
11418
|
+
* // ...
|
|
11419
|
+
* })
|
|
11420
|
+
* ```
|
|
11421
|
+
*
|
|
11422
|
+
* Fired when a {@link Amity.InternalUser} has been updated
|
|
11423
|
+
*
|
|
11424
|
+
* @param callback The function to call when the event was fired
|
|
11425
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11426
|
+
*
|
|
11427
|
+
* @category User Events
|
|
11428
|
+
*/
|
|
11429
|
+
const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
|
|
11430
|
+
|
|
11431
|
+
/**
|
|
11432
|
+
* ```js
|
|
11433
|
+
* import { onUserFlagged } from '@amityco/ts-sdk-react-native'
|
|
11434
|
+
* const dispose = onUserFlagged(user => {
|
|
11435
|
+
* // ...
|
|
11436
|
+
* })
|
|
11437
|
+
* ```
|
|
11438
|
+
*
|
|
11439
|
+
* Fired when a {@link Amity.InternalUser} has been flagged
|
|
11440
|
+
*
|
|
11441
|
+
* @param callback The function to call when the event was fired
|
|
11442
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11443
|
+
*
|
|
11444
|
+
* @category User Events
|
|
11445
|
+
*/
|
|
11446
|
+
const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
|
|
11447
|
+
|
|
11925
11448
|
/**
|
|
11926
11449
|
* ```js
|
|
11927
|
-
* import {
|
|
11928
|
-
* const
|
|
11450
|
+
* import { onUserUnflagged } from '@amityco/ts-sdk-react-native'
|
|
11451
|
+
* const dispose = onUserUnflagged(user => {
|
|
11452
|
+
* // ...
|
|
11453
|
+
* })
|
|
11929
11454
|
* ```
|
|
11930
11455
|
*
|
|
11931
|
-
*
|
|
11932
|
-
* @returns the deleted report result
|
|
11456
|
+
* Fired when a flag has been removed from a {@link Amity.InternalUser}
|
|
11933
11457
|
*
|
|
11934
|
-
* @
|
|
11935
|
-
* @
|
|
11936
|
-
*
|
|
11937
|
-
|
|
11938
|
-
|
|
11939
|
-
|
|
11940
|
-
const { data } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
11941
|
-
const payload = prepareUserPayload(data);
|
|
11942
|
-
if (client.cache) {
|
|
11943
|
-
ingestInCache(payload);
|
|
11944
|
-
}
|
|
11945
|
-
fireEvent('user.unflagged', data);
|
|
11946
|
-
return !!payload;
|
|
11947
|
-
};
|
|
11948
|
-
/* end_public_function */
|
|
11458
|
+
* @param callback The function to call when the event was fired
|
|
11459
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11460
|
+
*
|
|
11461
|
+
* @category User Events
|
|
11462
|
+
*/
|
|
11463
|
+
const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
|
|
11949
11464
|
|
|
11950
|
-
/* begin_public_function
|
|
11951
|
-
id: user.check_flag_by_me
|
|
11952
|
-
*/
|
|
11953
11465
|
/**
|
|
11954
11466
|
* ```js
|
|
11955
|
-
* import {
|
|
11956
|
-
* const
|
|
11467
|
+
* import { onUserFlagCleared } from '@amityco/ts-sdk-react-native'
|
|
11468
|
+
* const dispose = onUserFlagCleared(user => {
|
|
11469
|
+
* // ...
|
|
11470
|
+
* })
|
|
11957
11471
|
* ```
|
|
11958
11472
|
*
|
|
11959
|
-
*
|
|
11960
|
-
* @returns `true` if the report is created by me, `false` if doesn't.
|
|
11473
|
+
* Fired when flags have been cleared for a {@link Amity.InternalUser}
|
|
11961
11474
|
*
|
|
11962
|
-
* @
|
|
11963
|
-
* @
|
|
11964
|
-
*
|
|
11965
|
-
|
|
11966
|
-
|
|
11967
|
-
|
|
11968
|
-
const { data: { isFlagByMe }, } = await client.http.get(`/api/v3/users/${userId}/isFlagByMe`);
|
|
11969
|
-
return isFlagByMe;
|
|
11970
|
-
};
|
|
11971
|
-
/* end_public_function */
|
|
11475
|
+
* @param callback The function to call when the event was fired
|
|
11476
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11477
|
+
*
|
|
11478
|
+
* @category User Events
|
|
11479
|
+
*/
|
|
11480
|
+
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
11972
11481
|
|
|
11973
11482
|
/**
|
|
11974
11483
|
* ```js
|
|
@@ -12001,7 +11510,7 @@ const onUserFetched = (callback) => createUserEventSubscriber('user.fetched', ca
|
|
|
12001
11510
|
* @category Private
|
|
12002
11511
|
* @async
|
|
12003
11512
|
*/
|
|
12004
|
-
const getUser$
|
|
11513
|
+
const getUser$1 = async (userId) => {
|
|
12005
11514
|
const client = getActiveClient();
|
|
12006
11515
|
client.log('user/getUser', userId);
|
|
12007
11516
|
isInTombstone('user', userId);
|
|
@@ -12037,7 +11546,7 @@ const getUser$2 = async (userId) => {
|
|
|
12037
11546
|
*
|
|
12038
11547
|
* @category User API
|
|
12039
11548
|
*/
|
|
12040
|
-
getUser$
|
|
11549
|
+
getUser$1.locally = (userId) => {
|
|
12041
11550
|
const client = getActiveClient();
|
|
12042
11551
|
client.log('user/getUser.locally', userId);
|
|
12043
11552
|
if (!client.cache)
|
|
@@ -12073,11 +11582,11 @@ getUser$2.locally = (userId) => {
|
|
|
12073
11582
|
*
|
|
12074
11583
|
* @category Message Live Object
|
|
12075
11584
|
*/
|
|
12076
|
-
const getUser
|
|
11585
|
+
const getUser = (userId, callback) => {
|
|
12077
11586
|
const reactor = (response) => {
|
|
12078
11587
|
return callback(Object.assign(Object.assign({}, response), { data: response.data ? LinkedObject.user(response.data) : response.data }));
|
|
12079
11588
|
};
|
|
12080
|
-
return liveObject(userId, reactor, 'userId', getUser$
|
|
11589
|
+
return liveObject(userId, reactor, 'userId', getUser$1, [
|
|
12081
11590
|
onUserFetched,
|
|
12082
11591
|
onUserUpdated,
|
|
12083
11592
|
onUserDeleted$2,
|
|
@@ -12090,10 +11599,10 @@ const getUser$1 = (userId, callback) => {
|
|
|
12090
11599
|
|
|
12091
11600
|
class UserPaginationController extends PaginationController {
|
|
12092
11601
|
async getRequest(queryParams, token) {
|
|
12093
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT
|
|
11602
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
12094
11603
|
const options = token ? { token } : { limit };
|
|
12095
11604
|
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
12096
|
-
params: Object.assign(Object.assign({}, params), {
|
|
11605
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
12097
11606
|
});
|
|
12098
11607
|
return queryResponse;
|
|
12099
11608
|
}
|
|
@@ -12145,6 +11654,15 @@ class UserQueryStreamController extends QueryStreamController {
|
|
|
12145
11654
|
}
|
|
12146
11655
|
}
|
|
12147
11656
|
|
|
11657
|
+
var EnumUserActions;
|
|
11658
|
+
(function (EnumUserActions) {
|
|
11659
|
+
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
11660
|
+
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
11661
|
+
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
11662
|
+
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
11663
|
+
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
11664
|
+
})(EnumUserActions || (EnumUserActions = {}));
|
|
11665
|
+
|
|
12148
11666
|
class UserLiveCollectionController extends LiveCollectionController {
|
|
12149
11667
|
constructor(query, callback) {
|
|
12150
11668
|
const queryStreamId = hash__default["default"](query);
|
|
@@ -12203,21 +11721,17 @@ class UserLiveCollectionController extends LiveCollectionController {
|
|
|
12203
11721
|
}
|
|
12204
11722
|
applyFilter(data) {
|
|
12205
11723
|
let users = data;
|
|
12206
|
-
|
|
12207
|
-
|
|
12208
|
-
|
|
12209
|
-
|
|
12210
|
-
|
|
12211
|
-
|
|
12212
|
-
|
|
12213
|
-
|
|
12214
|
-
|
|
12215
|
-
|
|
12216
|
-
|
|
12217
|
-
}
|
|
12218
|
-
})();
|
|
12219
|
-
users = users.sort(sortFn);
|
|
12220
|
-
}
|
|
11724
|
+
const sortFn = (() => {
|
|
11725
|
+
switch (this.query.sortBy) {
|
|
11726
|
+
case 'firstCreated':
|
|
11727
|
+
return sortByFirstCreated;
|
|
11728
|
+
case 'lastCreated':
|
|
11729
|
+
return sortByLastCreated;
|
|
11730
|
+
default:
|
|
11731
|
+
return sortByLastCreated;
|
|
11732
|
+
}
|
|
11733
|
+
})();
|
|
11734
|
+
users = users.sort(sortFn);
|
|
12221
11735
|
if (this.query.filter === 'flagged') {
|
|
12222
11736
|
users = users.filter(user => !!user.hashFlag);
|
|
12223
11737
|
}
|
|
@@ -12264,90 +11778,200 @@ const getUsers = (params, callback, config) => {
|
|
|
12264
11778
|
};
|
|
12265
11779
|
/* end_public_function */
|
|
12266
11780
|
|
|
12267
|
-
|
|
12268
|
-
|
|
12269
|
-
|
|
12270
|
-
|
|
12271
|
-
|
|
12272
|
-
|
|
12273
|
-
|
|
12274
|
-
|
|
12275
|
-
|
|
12276
|
-
|
|
12277
|
-
|
|
12278
|
-
|
|
12279
|
-
|
|
12280
|
-
|
|
12281
|
-
|
|
12282
|
-
|
|
12283
|
-
|
|
12284
|
-
|
|
12285
|
-
|
|
12286
|
-
|
|
12287
|
-
|
|
12288
|
-
|
|
12289
|
-
|
|
12290
|
-
|
|
12291
|
-
|
|
12292
|
-
|
|
12293
|
-
|
|
12294
|
-
|
|
12295
|
-
|
|
12296
|
-
|
|
12297
|
-
|
|
12298
|
-
|
|
12299
|
-
|
|
12300
|
-
|
|
12301
|
-
|
|
12302
|
-
|
|
12303
|
-
|
|
11781
|
+
class BlockedUserPaginationController extends PaginationController {
|
|
11782
|
+
async getRequest(queryParams, token) {
|
|
11783
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
11784
|
+
const options = token ? { token } : { limit };
|
|
11785
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
11786
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
11787
|
+
});
|
|
11788
|
+
return queryResponse;
|
|
11789
|
+
}
|
|
11790
|
+
}
|
|
11791
|
+
|
|
11792
|
+
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
11793
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
11794
|
+
super(query, cacheKey);
|
|
11795
|
+
this.notifyChange = notifyChange;
|
|
11796
|
+
this.preparePayload = preparePayload;
|
|
11797
|
+
}
|
|
11798
|
+
async saveToMainDB(response) {
|
|
11799
|
+
const processedPayload = await this.preparePayload(response);
|
|
11800
|
+
const client = getActiveClient();
|
|
11801
|
+
const cachedAt = client.cache && Date.now();
|
|
11802
|
+
if (client.cache) {
|
|
11803
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
11804
|
+
}
|
|
11805
|
+
}
|
|
11806
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
11807
|
+
var _a, _b;
|
|
11808
|
+
if (refresh) {
|
|
11809
|
+
pushToCache(this.cacheKey, {
|
|
11810
|
+
data: response.users.map(getResolver('user')),
|
|
11811
|
+
});
|
|
11812
|
+
}
|
|
11813
|
+
else {
|
|
11814
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11815
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
11816
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
11817
|
+
}
|
|
11818
|
+
}
|
|
11819
|
+
reactor(action) {
|
|
11820
|
+
return (targetUser) => {
|
|
11821
|
+
var _a;
|
|
11822
|
+
if (action === EnumFollowActions.OnFollowed) {
|
|
11823
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11824
|
+
const updatedCollection = collection === null || collection === void 0 ? void 0 : collection.data.filter(id => id !== targetUser.userId);
|
|
11825
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: updatedCollection }));
|
|
11826
|
+
}
|
|
11827
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
11828
|
+
};
|
|
11829
|
+
}
|
|
11830
|
+
subscribeRTE(createSubscriber) {
|
|
11831
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
11832
|
+
}
|
|
11833
|
+
}
|
|
11834
|
+
|
|
11835
|
+
function prepareBlockedUserPayload(response) {
|
|
11836
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
11837
|
+
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
11838
|
+
const followUser = users.find(user => user.userId === follow.from);
|
|
11839
|
+
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
11840
|
+
}), users: users.map(convertRawUserToInternalUser) });
|
|
11841
|
+
}
|
|
11842
|
+
|
|
11843
|
+
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
11844
|
+
var _a, _b;
|
|
11845
|
+
if (!sourceModel) {
|
|
11846
|
+
return sourceModel;
|
|
11847
|
+
}
|
|
11848
|
+
const client = getActiveClient();
|
|
11849
|
+
const { objectSyncMap } = client;
|
|
11850
|
+
/*
|
|
11851
|
+
* NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
|
|
11852
|
+
* If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
|
|
11853
|
+
*/
|
|
11854
|
+
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
11855
|
+
? sourceModel[sourceModelProp]
|
|
11856
|
+
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
11857
|
+
const model = (_b = pullFromCache([
|
|
11858
|
+
destinationDomain,
|
|
11859
|
+
'get',
|
|
11860
|
+
`${resolvedId}`,
|
|
11861
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
11862
|
+
if (!model)
|
|
12304
11863
|
return;
|
|
12305
|
-
return
|
|
12306
|
-
|
|
12307
|
-
|
|
12308
|
-
|
|
12309
|
-
|
|
11864
|
+
return callback(model);
|
|
11865
|
+
});
|
|
11866
|
+
|
|
11867
|
+
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
11868
|
+
constructor(query, callback) {
|
|
11869
|
+
const queryStreamId = hash__default["default"](query);
|
|
11870
|
+
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
11871
|
+
const paginationController = new BlockedUserPaginationController(query);
|
|
11872
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
11873
|
+
this.query = query;
|
|
11874
|
+
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
11875
|
+
this.callback = callback.bind(this);
|
|
11876
|
+
this.loadPage({ initial: true });
|
|
11877
|
+
}
|
|
11878
|
+
setup() {
|
|
11879
|
+
var _a;
|
|
11880
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11881
|
+
if (!collection) {
|
|
11882
|
+
pushToCache(this.cacheKey, {
|
|
11883
|
+
data: [],
|
|
11884
|
+
params: {},
|
|
11885
|
+
});
|
|
11886
|
+
}
|
|
11887
|
+
}
|
|
11888
|
+
async persistModel(queryPayload) {
|
|
11889
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
11890
|
+
}
|
|
11891
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
11892
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
11893
|
+
}
|
|
11894
|
+
startSubscription() {
|
|
11895
|
+
return this.queryStreamController.subscribeRTE([
|
|
11896
|
+
{
|
|
11897
|
+
fn: onUserDeleted$2,
|
|
11898
|
+
action: EnumUserActions.OnUserDeleted,
|
|
11899
|
+
},
|
|
11900
|
+
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
11901
|
+
{
|
|
11902
|
+
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
11903
|
+
action: EnumFollowActions.OnFollowed,
|
|
11904
|
+
},
|
|
11905
|
+
{
|
|
11906
|
+
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
11907
|
+
action: EnumFollowActions.OnFollowed,
|
|
11908
|
+
},
|
|
11909
|
+
]);
|
|
11910
|
+
}
|
|
11911
|
+
notifyChange({ origin, loading, error }) {
|
|
11912
|
+
var _a, _b;
|
|
11913
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11914
|
+
if (!collection)
|
|
11915
|
+
return;
|
|
11916
|
+
const data = this.applyFilter((_b = collection.data
|
|
11917
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
11918
|
+
.filter(isNonNullable)
|
|
11919
|
+
.map(({ data }) => data)
|
|
11920
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
11921
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
11922
|
+
return;
|
|
11923
|
+
this.callback({
|
|
11924
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
11925
|
+
data,
|
|
11926
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
11927
|
+
loading,
|
|
11928
|
+
error,
|
|
11929
|
+
});
|
|
11930
|
+
}
|
|
11931
|
+
// eslint-disable-next-line class-methods-use-this
|
|
11932
|
+
applyFilter(data) {
|
|
11933
|
+
let users = data;
|
|
11934
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
11935
|
+
return users;
|
|
11936
|
+
}
|
|
11937
|
+
}
|
|
12310
11938
|
|
|
11939
|
+
/* begin_public_function
|
|
11940
|
+
id: user.get_blocked_users
|
|
11941
|
+
*/
|
|
12311
11942
|
/**
|
|
12312
11943
|
* ```js
|
|
12313
|
-
* import {
|
|
12314
|
-
*
|
|
12315
|
-
* let user = {}
|
|
12316
|
-
* const dispose = observeUser(userId, updated => user = updated)
|
|
11944
|
+
* import { UserRepository } from '@amityco/ts-sdk-react-native'
|
|
11945
|
+
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
12317
11946
|
* ```
|
|
12318
11947
|
*
|
|
12319
|
-
*
|
|
12320
|
-
*
|
|
12321
|
-
* @
|
|
11948
|
+
* Blocks a {@link Amity.InternalUser}
|
|
11949
|
+
*
|
|
11950
|
+
* @param params The params to get blocked {@link Amity.InternalUser}s
|
|
11951
|
+
* @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
|
|
11952
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
12322
11953
|
*
|
|
12323
|
-
*
|
|
12324
|
-
* @
|
|
11954
|
+
* @category Post API
|
|
11955
|
+
* @async
|
|
12325
11956
|
*/
|
|
12326
|
-
const
|
|
12327
|
-
const { log } = getActiveClient();
|
|
11957
|
+
const getBlockedUsers = (params, callback, config) => {
|
|
11958
|
+
const { log, cache } = getActiveClient();
|
|
11959
|
+
if (!cache) {
|
|
11960
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
11961
|
+
}
|
|
12328
11962
|
const timestamp = Date.now();
|
|
12329
|
-
log(`
|
|
12330
|
-
|
|
12331
|
-
const
|
|
12332
|
-
|
|
12333
|
-
|
|
12334
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
|
|
12335
|
-
return;
|
|
12336
|
-
const newResult = Object.assign(Object.assign({}, result), { data: LinkedObject.user(result.data) });
|
|
12337
|
-
if (callback instanceof Function)
|
|
12338
|
-
return callback(newResult);
|
|
12339
|
-
if (action !== 'onFetch')
|
|
12340
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, newResult);
|
|
12341
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, newResult);
|
|
12342
|
-
};
|
|
12343
|
-
const disposers = [];
|
|
12344
|
-
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')));
|
|
12345
|
-
runQuery(createQuery(getUser, userId), result => result.data && router(result, 'onFetch'));
|
|
11963
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
11964
|
+
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
11965
|
+
const disposers = blockedUserLiveCollection.startSubscription();
|
|
11966
|
+
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
11967
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
12346
11968
|
return () => {
|
|
12347
|
-
log(`
|
|
11969
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
12348
11970
|
disposers.forEach(fn => fn());
|
|
11971
|
+
dropFromCache(cacheKey);
|
|
12349
11972
|
};
|
|
12350
|
-
};
|
|
11973
|
+
};
|
|
11974
|
+
/* end_public_function */
|
|
12351
11975
|
|
|
12352
11976
|
class SearchUserPaginationController extends PaginationController {
|
|
12353
11977
|
async getRequest(queryParams, token) {
|
|
@@ -12532,74 +12156,6 @@ const queryReachUser = async ({ viewId, viewedType, limit, token, }) => {
|
|
|
12532
12156
|
return response.data;
|
|
12533
12157
|
};
|
|
12534
12158
|
|
|
12535
|
-
/**
|
|
12536
|
-
* @deprecated: Please use {@link UserRepository.getReachUsers} instead
|
|
12537
|
-
* @param params
|
|
12538
|
-
* @param callback
|
|
12539
|
-
*/
|
|
12540
|
-
const getViewedUsers = (params, callback) => {
|
|
12541
|
-
const { log, cache } = getActiveClient();
|
|
12542
|
-
const cacheKey = ['postViewedUsers', 'collection', { postId: params.postId }];
|
|
12543
|
-
if (!cache) {
|
|
12544
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
12545
|
-
}
|
|
12546
|
-
const timestamp = Date.now();
|
|
12547
|
-
log(`getViewedUsers(tmpid: ${timestamp}) > listen`);
|
|
12548
|
-
const { limit: queryLimit, postId } = params;
|
|
12549
|
-
const responder = (snapshot) => {
|
|
12550
|
-
var _a, _b;
|
|
12551
|
-
let users = [];
|
|
12552
|
-
if (snapshot === null || snapshot === void 0 ? void 0 : snapshot.data) {
|
|
12553
|
-
users =
|
|
12554
|
-
snapshot.data
|
|
12555
|
-
.map((userId) => pullFromCache(['user', 'get', userId]))
|
|
12556
|
-
.filter(Boolean)
|
|
12557
|
-
.map(data => data === null || data === void 0 ? void 0 : data.data) || [];
|
|
12558
|
-
}
|
|
12559
|
-
callback({
|
|
12560
|
-
// eslint-disable-next-line no-use-before-define
|
|
12561
|
-
onNextPage: onFetch,
|
|
12562
|
-
data: users,
|
|
12563
|
-
hasNextPage: !!((_b = (_a = snapshot.params) === null || _a === void 0 ? void 0 : _a.page) === null || _b === void 0 ? void 0 : _b.next),
|
|
12564
|
-
loading: snapshot.loading || false,
|
|
12565
|
-
});
|
|
12566
|
-
};
|
|
12567
|
-
const onFetch = (initial = false) => {
|
|
12568
|
-
var _a, _b, _c;
|
|
12569
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
12570
|
-
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
12571
|
-
if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
12572
|
-
return;
|
|
12573
|
-
const query = createQuery(queryReachUser, {
|
|
12574
|
-
viewId: postId,
|
|
12575
|
-
viewedType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
12576
|
-
limit: queryLimit || 10,
|
|
12577
|
-
token: !initial ? (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) === null || _c === void 0 ? void 0 : _c.next : undefined,
|
|
12578
|
-
});
|
|
12579
|
-
runQuery(query, result => {
|
|
12580
|
-
var _a, _b, _c, _d, _e;
|
|
12581
|
-
let userIds = (_c = (_b = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : [];
|
|
12582
|
-
if ((_d = result.data) === null || _d === void 0 ? void 0 : _d.users) {
|
|
12583
|
-
userIds = [
|
|
12584
|
-
...new Set([...userIds, ...result.data.users.map(({ userId }) => userId)]),
|
|
12585
|
-
];
|
|
12586
|
-
}
|
|
12587
|
-
const saveToCache = {
|
|
12588
|
-
loading: result.loading,
|
|
12589
|
-
params: { page: (_e = result.data) === null || _e === void 0 ? void 0 : _e.paging },
|
|
12590
|
-
data: userIds || [],
|
|
12591
|
-
};
|
|
12592
|
-
pushToCache(cacheKey, saveToCache);
|
|
12593
|
-
responder(saveToCache);
|
|
12594
|
-
}, queryOptions(COLLECTION_DEFAULT_CACHING_POLICY, CACHE_SHORTEN_LIFESPAN));
|
|
12595
|
-
};
|
|
12596
|
-
onFetch(true);
|
|
12597
|
-
return () => {
|
|
12598
|
-
log(`getViewedUsers(tmpid: ${timestamp}) > dispose`);
|
|
12599
|
-
dropFromCache(cacheKey);
|
|
12600
|
-
};
|
|
12601
|
-
};
|
|
12602
|
-
|
|
12603
12159
|
const getReachedUsers = (params, callback) => {
|
|
12604
12160
|
// Pre-defined function to avoid undefined function call
|
|
12605
12161
|
let onFetch = (initial = false) => undefined;
|
|
@@ -12687,12 +12243,10 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
12687
12243
|
onUserFlagged: onUserFlagged,
|
|
12688
12244
|
onUserUnflagged: onUserUnflagged,
|
|
12689
12245
|
onUserFlagCleared: onUserFlagCleared,
|
|
12690
|
-
getUser: getUser
|
|
12246
|
+
getUser: getUser,
|
|
12691
12247
|
getUsers: getUsers,
|
|
12692
|
-
|
|
12693
|
-
getBlockedUsers: getBlockedUsers$1,
|
|
12248
|
+
getBlockedUsers: getBlockedUsers,
|
|
12694
12249
|
searchUserByDisplayName: searchUserByDisplayName,
|
|
12695
|
-
getViewedUsers: getViewedUsers,
|
|
12696
12250
|
getReachedUsers: getReachedUsers,
|
|
12697
12251
|
get AmityUserSearchMatchType () { return AmityUserSearchMatchType; }
|
|
12698
12252
|
});
|
|
@@ -12937,185 +12491,10 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
12937
12491
|
ingestInCache({ files: data }, { cachedAt });
|
|
12938
12492
|
return {
|
|
12939
12493
|
data,
|
|
12940
|
-
cachedAt,
|
|
12941
|
-
};
|
|
12942
|
-
};
|
|
12943
|
-
/* end_public_function */
|
|
12944
|
-
|
|
12945
|
-
/**
|
|
12946
|
-
* ```js
|
|
12947
|
-
* import { createImage } from '@amityco/ts-sdk-react-native'
|
|
12948
|
-
* const created = await createImage(formData)
|
|
12949
|
-
* ```
|
|
12950
|
-
*
|
|
12951
|
-
* Creates an {@link Amity.File<'image'>}
|
|
12952
|
-
*
|
|
12953
|
-
* @param formData The data necessary to create a new {@link Amity.File<'image'>}
|
|
12954
|
-
* @param onProgress The callback to track the upload progress
|
|
12955
|
-
* @returns The newly created {@link Amity.File<'image'>}
|
|
12956
|
-
*
|
|
12957
|
-
* @category File API
|
|
12958
|
-
* @async
|
|
12959
|
-
*/
|
|
12960
|
-
const createImage = async (formData, onProgress) => {
|
|
12961
|
-
const client = getActiveClient();
|
|
12962
|
-
client.log('file/createImage', formData);
|
|
12963
|
-
const files = formData.getAll('files');
|
|
12964
|
-
if (!files.length)
|
|
12965
|
-
throw new Error('The formData object must have a `files` key.');
|
|
12966
|
-
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
12967
|
-
formData.append('accessType', accessType);
|
|
12968
|
-
formData.append('preferredFilename', files[0].name);
|
|
12969
|
-
const headers = 'getHeaders' in formData
|
|
12970
|
-
? formData.getHeaders()
|
|
12971
|
-
: { 'content-type': 'multipart/form-data' };
|
|
12972
|
-
const { data } = await client.http.post('/api/v4/images', formData, {
|
|
12973
|
-
headers,
|
|
12974
|
-
onUploadProgress({ loaded, total = 100 }) {
|
|
12975
|
-
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
12976
|
-
},
|
|
12977
|
-
});
|
|
12978
|
-
// API-FIX: payload should be serialized properly
|
|
12979
|
-
// const { files } = data
|
|
12980
|
-
const cachedAt = client.cache && Date.now();
|
|
12981
|
-
if (client.cache)
|
|
12982
|
-
ingestInCache({ files: data }, { cachedAt });
|
|
12983
|
-
return {
|
|
12984
|
-
data,
|
|
12985
|
-
cachedAt,
|
|
12986
|
-
};
|
|
12987
|
-
};
|
|
12988
|
-
/* end_public_function */
|
|
12989
|
-
|
|
12990
|
-
/**
|
|
12991
|
-
* ```js
|
|
12992
|
-
* import { FileRepository } from '@amityco/ts-sdk-react-native'
|
|
12993
|
-
* const created = await FileRepository.createFile(formData)
|
|
12994
|
-
* ```
|
|
12995
|
-
*
|
|
12996
|
-
* Creates an {@link Amity.File}
|
|
12997
|
-
*
|
|
12998
|
-
* @param formData The data necessary to create a new {@link Amity.File}
|
|
12999
|
-
* @param onProgress The callback to track the upload progress
|
|
13000
|
-
* @returns The newly created {@link Amity.File}
|
|
13001
|
-
*
|
|
13002
|
-
* @category File API
|
|
13003
|
-
* @async
|
|
13004
|
-
*/
|
|
13005
|
-
const createFile = async (formData, onProgress) => {
|
|
13006
|
-
const client = getActiveClient();
|
|
13007
|
-
client.log('file/createFile', formData);
|
|
13008
|
-
const files = formData.getAll('files');
|
|
13009
|
-
if (!files.length)
|
|
13010
|
-
throw new Error('The formData object must have a `files` key.');
|
|
13011
|
-
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
13012
|
-
formData.append('accessType', accessType);
|
|
13013
|
-
formData.append('preferredFilename', files[0].name);
|
|
13014
|
-
const headers = 'getHeaders' in formData
|
|
13015
|
-
? formData.getHeaders()
|
|
13016
|
-
: { 'content-type': 'multipart/form-data' };
|
|
13017
|
-
const { data } = await client.http.post('/api/v4/files', formData, {
|
|
13018
|
-
headers,
|
|
13019
|
-
onUploadProgress({ loaded, total = 100 }) {
|
|
13020
|
-
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
13021
|
-
},
|
|
13022
|
-
});
|
|
13023
|
-
// API-FIX: payload should be serialized properly
|
|
13024
|
-
// const { files } = data
|
|
13025
|
-
const cachedAt = client.cache && Date.now();
|
|
13026
|
-
if (client.cache)
|
|
13027
|
-
ingestInCache({ files: data }, { cachedAt });
|
|
13028
|
-
return {
|
|
13029
|
-
data,
|
|
13030
|
-
cachedAt,
|
|
13031
|
-
};
|
|
13032
|
-
};
|
|
13033
|
-
|
|
13034
|
-
/**
|
|
13035
|
-
* ```js
|
|
13036
|
-
* import { FileRepository } from '@amityco/ts-sdk-react-native'
|
|
13037
|
-
* const created = await FileRepository.createVideo(formData)
|
|
13038
|
-
* ```
|
|
13039
|
-
*
|
|
13040
|
-
* Creates an {@link Amity.File<'video'>}
|
|
13041
|
-
*
|
|
13042
|
-
* @param formData The data necessary to create a new {@link Amity.File<'video'>}
|
|
13043
|
-
* @param feedType The {@link Amity.File<'video'>} feed type
|
|
13044
|
-
* @param onProgress The callback to track the upload progress
|
|
13045
|
-
* @returns The newly uploaded {@link Amity.File<'video'>}
|
|
13046
|
-
*
|
|
13047
|
-
* @category File API
|
|
13048
|
-
* @async
|
|
13049
|
-
*/
|
|
13050
|
-
const createVideo = async (formData, feedType, onProgress) => {
|
|
13051
|
-
const client = getActiveClient();
|
|
13052
|
-
client.log('file/createVideo', formData);
|
|
13053
|
-
const files = formData.getAll('files');
|
|
13054
|
-
if (!files.length)
|
|
13055
|
-
throw new Error('The formData object must have a `files` key.');
|
|
13056
|
-
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
13057
|
-
formData.append('accessType', accessType);
|
|
13058
|
-
formData.append('preferredFilename', files[0].name);
|
|
13059
|
-
if (feedType) {
|
|
13060
|
-
formData.append('feedType', feedType);
|
|
13061
|
-
}
|
|
13062
|
-
const headers = 'getHeaders' in formData
|
|
13063
|
-
? formData.getHeaders()
|
|
13064
|
-
: { 'content-type': 'multipart/form-data' };
|
|
13065
|
-
const { data } = await client.http.post('/api/v4/videos', formData, {
|
|
13066
|
-
headers,
|
|
13067
|
-
onUploadProgress({ loaded, total = 100 }) {
|
|
13068
|
-
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
13069
|
-
},
|
|
13070
|
-
});
|
|
13071
|
-
// API-FIX: payload should be serialized properly
|
|
13072
|
-
// const { files } = data
|
|
13073
|
-
const cachedAt = client.cache && Date.now();
|
|
13074
|
-
if (client.cache)
|
|
13075
|
-
ingestInCache({ files: data }, { cachedAt });
|
|
13076
|
-
return {
|
|
13077
|
-
data,
|
|
13078
|
-
cachedAt,
|
|
13079
|
-
};
|
|
13080
|
-
};
|
|
13081
|
-
|
|
13082
|
-
/**
|
|
13083
|
-
* ```js
|
|
13084
|
-
* import { observeFile } from '@amityco/ts-sdk-react-native'
|
|
13085
|
-
*
|
|
13086
|
-
* let file = {}
|
|
13087
|
-
* const dispose = observeFile(fileId, updated => file = updated)
|
|
13088
|
-
* ```
|
|
13089
|
-
*
|
|
13090
|
-
* Observe all mutation on a given {@link Amity.File}
|
|
13091
|
-
*
|
|
13092
|
-
* @param fileId the ID of the file to observe
|
|
13093
|
-
* @param callback the function to call when new data are available
|
|
13094
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the file
|
|
13095
|
-
*
|
|
13096
|
-
* @category File Observer
|
|
13097
|
-
*/
|
|
13098
|
-
const observeFile = (fileId, callback) => {
|
|
13099
|
-
const { log } = getActiveClient();
|
|
13100
|
-
const timestamp = Date.now();
|
|
13101
|
-
log(`observeFile(tmpid: ${timestamp}) > listen`);
|
|
13102
|
-
// wrapper function to make sure
|
|
13103
|
-
const router = (result, action) => {
|
|
13104
|
-
var _a, _b, _c;
|
|
13105
|
-
// filter function
|
|
13106
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.fileId) !== fileId)
|
|
13107
|
-
return;
|
|
13108
|
-
if (callback instanceof Function)
|
|
13109
|
-
return callback(result);
|
|
13110
|
-
if (action !== 'onFetch')
|
|
13111
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, result);
|
|
13112
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
|
|
13113
|
-
};
|
|
13114
|
-
runQuery(createQuery(getFile, fileId), result => result.data && router(result, 'onFetch'));
|
|
13115
|
-
return () => {
|
|
13116
|
-
log(`observeFile(tmpid: ${timestamp}) > dispose`);
|
|
12494
|
+
cachedAt,
|
|
13117
12495
|
};
|
|
13118
|
-
};
|
|
12496
|
+
};
|
|
12497
|
+
/* end_public_function */
|
|
13119
12498
|
|
|
13120
12499
|
var index$i = /*#__PURE__*/Object.freeze({
|
|
13121
12500
|
__proto__: null,
|
|
@@ -13124,11 +12503,7 @@ var index$i = /*#__PURE__*/Object.freeze({
|
|
|
13124
12503
|
deleteFile: deleteFile,
|
|
13125
12504
|
fileUrlWithSize: fileUrlWithSize,
|
|
13126
12505
|
uploadVideo: uploadVideo,
|
|
13127
|
-
uploadImage: uploadImage
|
|
13128
|
-
createImage: createImage,
|
|
13129
|
-
createFile: createFile,
|
|
13130
|
-
createVideo: createVideo,
|
|
13131
|
-
observeFile: observeFile
|
|
12506
|
+
uploadImage: uploadImage
|
|
13132
12507
|
});
|
|
13133
12508
|
|
|
13134
12509
|
/**
|
|
@@ -13149,16 +12524,12 @@ var index$i = /*#__PURE__*/Object.freeze({
|
|
|
13149
12524
|
const queryRoles = async (query) => {
|
|
13150
12525
|
const client = getActiveClient();
|
|
13151
12526
|
client.log('role/queryRoles', query);
|
|
13152
|
-
const _a = query !== null && query !== void 0 ? query : {}, {
|
|
12527
|
+
const _a = query !== null && query !== void 0 ? query : {}, { limit = 10, queryToken, displayName, sortBy } = _a, params = __rest(_a, ["limit", "queryToken", "displayName", "sortBy"]);
|
|
13153
12528
|
const options = (() => {
|
|
13154
12529
|
if (queryToken)
|
|
13155
12530
|
return { token: queryToken };
|
|
13156
12531
|
if (limit)
|
|
13157
12532
|
return { limit };
|
|
13158
|
-
if (page)
|
|
13159
|
-
return {
|
|
13160
|
-
token: toToken(page, 'skiplimit'),
|
|
13161
|
-
};
|
|
13162
12533
|
return undefined;
|
|
13163
12534
|
})();
|
|
13164
12535
|
// API-FIX: parameters should be querystring.
|
|
@@ -13286,12 +12657,9 @@ const dispatchReactable = (referenceType, model) => {
|
|
|
13286
12657
|
* @category Message API
|
|
13287
12658
|
* @async
|
|
13288
12659
|
*/
|
|
13289
|
-
const getMessage$
|
|
12660
|
+
const getMessage$1 = async (messageId, isLive = false) => {
|
|
13290
12661
|
const client = getActiveClient();
|
|
13291
12662
|
client.log('message/getMessage', messageId);
|
|
13292
|
-
if (!isLive) {
|
|
13293
|
-
console.log('getMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
|
|
13294
|
-
}
|
|
13295
12663
|
isInTombstone('message', messageId);
|
|
13296
12664
|
let data;
|
|
13297
12665
|
try {
|
|
@@ -13328,7 +12696,7 @@ const getMessage$2 = async (messageId, isLive = false) => {
|
|
|
13328
12696
|
*
|
|
13329
12697
|
* @category Message API
|
|
13330
12698
|
*/
|
|
13331
|
-
getMessage$
|
|
12699
|
+
getMessage$1.locally = (messageId) => {
|
|
13332
12700
|
const client = getActiveClient();
|
|
13333
12701
|
client.log('message/getMessage.locally', messageId);
|
|
13334
12702
|
if (!client.cache)
|
|
@@ -15257,7 +14625,7 @@ const getChannel$1 = async (channelId) => {
|
|
|
15257
14625
|
ingestInCache(data, { cachedAt });
|
|
15258
14626
|
const { channels } = data;
|
|
15259
14627
|
return {
|
|
15260
|
-
data:
|
|
14628
|
+
data: channels.find(channel => channel.channelId === channelId),
|
|
15261
14629
|
cachedAt,
|
|
15262
14630
|
};
|
|
15263
14631
|
};
|
|
@@ -15287,7 +14655,7 @@ getChannel$1.locally = (channelId) => {
|
|
|
15287
14655
|
if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) === 0)
|
|
15288
14656
|
return;
|
|
15289
14657
|
return {
|
|
15290
|
-
data:
|
|
14658
|
+
data: cached[0].data,
|
|
15291
14659
|
cachedAt: cached[0].cachedAt,
|
|
15292
14660
|
};
|
|
15293
14661
|
};
|
|
@@ -15312,7 +14680,7 @@ const deleteChannel = async (channelId) => {
|
|
|
15312
14680
|
await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
15313
14681
|
const deleted = await getChannel$1(channelId);
|
|
15314
14682
|
// no need for event, fired by server
|
|
15315
|
-
return deleted.data;
|
|
14683
|
+
return constructChannelDynamicValue(deleted.data);
|
|
15316
14684
|
};
|
|
15317
14685
|
|
|
15318
14686
|
/* begin_public_function
|
|
@@ -15434,81 +14802,6 @@ const unmuteChannel = async (channelId) => {
|
|
|
15434
14802
|
};
|
|
15435
14803
|
/* end_public_function */
|
|
15436
14804
|
|
|
15437
|
-
/**
|
|
15438
|
-
* ```js
|
|
15439
|
-
* import { observeChannel } from '@amityco/ts-sdk-react-native'
|
|
15440
|
-
*
|
|
15441
|
-
* let channel = {}
|
|
15442
|
-
* const dispose = observeChannel(channelId, ({ data }) => channel = data)
|
|
15443
|
-
* ```
|
|
15444
|
-
*
|
|
15445
|
-
* Observe all mutation on a given {@link Amity.Channel}
|
|
15446
|
-
*
|
|
15447
|
-
* @param channelId the ID of the channel to observe
|
|
15448
|
-
* @param callback the function to call when new data are available
|
|
15449
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channel
|
|
15450
|
-
*
|
|
15451
|
-
* @category Channel Observer
|
|
15452
|
-
*/
|
|
15453
|
-
const observeChannel = (channelId, callback) => {
|
|
15454
|
-
const { log } = getActiveClient();
|
|
15455
|
-
const timestamp = Date.now();
|
|
15456
|
-
log(`observeChannel(tmpid: ${timestamp}) > listen`);
|
|
15457
|
-
// wrapper function to make sure
|
|
15458
|
-
const router = (result, action) => {
|
|
15459
|
-
var _a, _b, _c;
|
|
15460
|
-
// filter function
|
|
15461
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.channelId) !== channelId)
|
|
15462
|
-
return;
|
|
15463
|
-
if (callback instanceof Function)
|
|
15464
|
-
return callback(Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
|
|
15465
|
-
if (action !== 'onFetch')
|
|
15466
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
|
|
15467
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
|
|
15468
|
-
};
|
|
15469
|
-
const disposers = [];
|
|
15470
|
-
disposers.push(onChannelUpdated(data => router({ data, loading: false, origin: 'event' }, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)), onChannelDeleted(data => router({ data, loading: false, origin: 'event' }, "onDelete" /* Amity.ChannelActionType.OnDelete */)), onChannelJoined(data => router({ data, loading: false, origin: 'event' }, "onJoin" /* Amity.ChannelActionType.OnJoin */)), onChannelLeft(data => router({ data, loading: false, origin: 'event' }, "onLeft" /* Amity.ChannelActionType.OnLeft */)), onChannelMuted(data => router({ data, loading: false, origin: 'event' }, "onMute" /* Amity.ChannelActionType.OnMute */)), onChannelMemberAdded(data => router({ data, loading: false, origin: 'event' }, "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */)), onChannelMemberRemoved(data => router({ data, loading: false, origin: 'event' }, "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */)), convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel')(data => router({ data, loading: false, origin: 'event' }, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)));
|
|
15471
|
-
runQuery(createQuery(getChannel$1, channelId), result => result.data && router(result, "onFetch" /* Amity.ChannelActionType.OnFetch */));
|
|
15472
|
-
return () => {
|
|
15473
|
-
log(`observeChannel(tmpid: ${timestamp}) > dispose`);
|
|
15474
|
-
disposers.forEach(fn => fn());
|
|
15475
|
-
};
|
|
15476
|
-
};
|
|
15477
|
-
|
|
15478
|
-
/**
|
|
15479
|
-
* ```js
|
|
15480
|
-
* import { observeChannels } from '@amityco/ts-sdk-react-native'
|
|
15481
|
-
*
|
|
15482
|
-
* let channels = []
|
|
15483
|
-
* const unsub = observeChannels(channel => merge(channels, channel))
|
|
15484
|
-
* ```
|
|
15485
|
-
*
|
|
15486
|
-
* Observe all mutations on a list of {@link Amity.Channel} for a current user
|
|
15487
|
-
*
|
|
15488
|
-
* @param callback the function to call when new data are available
|
|
15489
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
15490
|
-
*
|
|
15491
|
-
* @category Channel Observer
|
|
15492
|
-
*/
|
|
15493
|
-
const observeChannels = (callback) => {
|
|
15494
|
-
const { log } = getActiveClient();
|
|
15495
|
-
const timestamp = Date.now();
|
|
15496
|
-
log(`observeChannels(tmpid: ${timestamp}) > listen`);
|
|
15497
|
-
const disposers = [];
|
|
15498
|
-
const router = (channel, action) => {
|
|
15499
|
-
var _a, _b;
|
|
15500
|
-
if (callback instanceof Function)
|
|
15501
|
-
return callback(LinkedObject.channel(constructChannelDynamicValue(channel)));
|
|
15502
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, LinkedObject.channel(constructChannelDynamicValue(channel)));
|
|
15503
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, LinkedObject.channel(constructChannelDynamicValue(channel)));
|
|
15504
|
-
};
|
|
15505
|
-
disposers.push(onChannelCreated(data => router(data, "onCreate" /* Amity.ChannelActionType.OnCreate */)), onChannelUpdated(data => router(data, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)), onChannelDeleted(data => router(data, "onDelete" /* Amity.ChannelActionType.OnDelete */)), onChannelJoined(data => router(data, "onJoin" /* Amity.ChannelActionType.OnJoin */)), onChannelLeft(data => router(data, "onLeft" /* Amity.ChannelActionType.OnLeft */)), onChannelMuted(data => router(data, "onMute" /* Amity.ChannelActionType.OnMute */)), onChannelMemberAdded(data => router(data, "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */)), onChannelMemberRemoved(data => router(data, "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */)), convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel')(data => router(data, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)));
|
|
15506
|
-
return () => {
|
|
15507
|
-
log(`observeChannels(tmpid: ${timestamp}) > dispose`);
|
|
15508
|
-
disposers.forEach(fn => fn());
|
|
15509
|
-
};
|
|
15510
|
-
};
|
|
15511
|
-
|
|
15512
14805
|
/**
|
|
15513
14806
|
* ```js
|
|
15514
14807
|
* import { onMessageUpdated } from '@amityco/ts-sdk-react-native'
|
|
@@ -15787,69 +15080,6 @@ const onSubChannelFetched = (callback) => {
|
|
|
15787
15080
|
return createEventSubscriber(getActiveClient(), 'onSubChannelFetched', 'local.message-feed.fetched', payload => callback(payload.messageFeeds[0]));
|
|
15788
15081
|
};
|
|
15789
15082
|
|
|
15790
|
-
/**
|
|
15791
|
-
* ```js
|
|
15792
|
-
* import { getMessages } from '@amityco/ts-sdk-react-native'
|
|
15793
|
-
* const messages = await getMessages(['foo', 'bar'])
|
|
15794
|
-
* ```
|
|
15795
|
-
*
|
|
15796
|
-
* Fetches a collection of {@link Amity.Message} objects
|
|
15797
|
-
*
|
|
15798
|
-
* @param messageIds the IDs of the {@link Amity.Message} to fetch
|
|
15799
|
-
* @returns the associated collection of {@link Amity.Message} objects
|
|
15800
|
-
*
|
|
15801
|
-
* @category Message API
|
|
15802
|
-
* @async
|
|
15803
|
-
*/
|
|
15804
|
-
const getMessages$1 = async (messageIds) => {
|
|
15805
|
-
const client = getActiveClient();
|
|
15806
|
-
client.log('message/getMessages', messageIds);
|
|
15807
|
-
const { data: payload } = await client.http.get(`/api/v5/messages/list`, {
|
|
15808
|
-
params: { messageIds: messageIds.map(encodeURIComponent) },
|
|
15809
|
-
});
|
|
15810
|
-
const data = await prepareMessagePayload(payload);
|
|
15811
|
-
const cachedAt = client.cache && Date.now();
|
|
15812
|
-
if (client.cache)
|
|
15813
|
-
ingestInCache(data, { cachedAt });
|
|
15814
|
-
const { messages } = data;
|
|
15815
|
-
fireEvent('local.message.fetched', { messages });
|
|
15816
|
-
return {
|
|
15817
|
-
data: messages.map(message => LinkedObject.message(message)),
|
|
15818
|
-
cachedAt,
|
|
15819
|
-
};
|
|
15820
|
-
};
|
|
15821
|
-
/**
|
|
15822
|
-
* ```js
|
|
15823
|
-
* import { getMessages } from '@amityco/ts-sdk-react-native'
|
|
15824
|
-
* const messages = getMessages.locally(['foo', 'bar']) ?? []
|
|
15825
|
-
* ```
|
|
15826
|
-
*
|
|
15827
|
-
* Fetches a collection of {@link Amity.Message} objects from cache
|
|
15828
|
-
*
|
|
15829
|
-
* @param messageIds the IDs of the {@link Amity.Message} to fetch
|
|
15830
|
-
* @returns the associated collection of {@link Amity.Message} objects
|
|
15831
|
-
*
|
|
15832
|
-
* @category Message API
|
|
15833
|
-
*/
|
|
15834
|
-
getMessages$1.locally = (messageIds) => {
|
|
15835
|
-
var _a;
|
|
15836
|
-
const client = getActiveClient();
|
|
15837
|
-
client.log('message/getMessages.locally', messageIds);
|
|
15838
|
-
if (!client.cache)
|
|
15839
|
-
return;
|
|
15840
|
-
const cached = messageIds
|
|
15841
|
-
.map(messageId => pullFromCache(['message', 'get', messageId]))
|
|
15842
|
-
.filter(Boolean);
|
|
15843
|
-
const messages = cached.map(({ data }) => data);
|
|
15844
|
-
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
15845
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.length) < messageIds.length)
|
|
15846
|
-
return;
|
|
15847
|
-
return {
|
|
15848
|
-
data: messages,
|
|
15849
|
-
cachedAt: oldest.cachedAt,
|
|
15850
|
-
};
|
|
15851
|
-
};
|
|
15852
|
-
|
|
15853
15083
|
const getLocalId = () => `LOCAL_${uuid()}`;
|
|
15854
15084
|
// FIXME: temp solution
|
|
15855
15085
|
let uniqueId;
|
|
@@ -15874,7 +15104,11 @@ const createMessageOptimistic = (bundle) => {
|
|
|
15874
15104
|
if (subChannel) {
|
|
15875
15105
|
upsertInCache(['subChannel', 'get', bundle.subChannelId], Object.assign(Object.assign({}, subChannel.data), { messageCount: subChannel.data.messageCount + 1 }));
|
|
15876
15106
|
if (subChannel.data.channelId === subChannel.data.subChannelId) {
|
|
15877
|
-
const channel = pullFromCache([
|
|
15107
|
+
const channel = pullFromCache([
|
|
15108
|
+
'channel',
|
|
15109
|
+
'get',
|
|
15110
|
+
subChannel.data.channelId,
|
|
15111
|
+
]);
|
|
15878
15112
|
if (channel === null || channel === void 0 ? void 0 : channel.data) {
|
|
15879
15113
|
upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_a = channel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
|
|
15880
15114
|
}
|
|
@@ -16162,7 +15396,7 @@ const softDeleteMessage = async (messageId) => {
|
|
|
16162
15396
|
client.log('message/softDeleteMessage', messageId);
|
|
16163
15397
|
// API-FIX: This endpoint has not been implemented yet.
|
|
16164
15398
|
await client.http.delete(`/api/v5/messages/${encodeURIComponent(messageId)}`);
|
|
16165
|
-
const deleted = await getMessage$
|
|
15399
|
+
const deleted = await getMessage$1(messageId);
|
|
16166
15400
|
fireEvent('local.message.deleted', { messages: [deleted.data] });
|
|
16167
15401
|
return LinkedObject.message(deleted.data);
|
|
16168
15402
|
};
|
|
@@ -16636,12 +15870,12 @@ const onMessageFetched = (callback) => {
|
|
|
16636
15870
|
*
|
|
16637
15871
|
* @category Message Live Object
|
|
16638
15872
|
*/
|
|
16639
|
-
const getMessage
|
|
15873
|
+
const getMessage = (messageId, callback) => {
|
|
16640
15874
|
const responder = (snapshot) => {
|
|
16641
15875
|
const { data } = snapshot;
|
|
16642
15876
|
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.message(snapshot.data) : data }));
|
|
16643
15877
|
};
|
|
16644
|
-
return liveObject(messageId, responder, 'messageId', getMessage$
|
|
15878
|
+
return liveObject(messageId, responder, 'messageId', getMessage$1, [
|
|
16645
15879
|
onMessageFetched,
|
|
16646
15880
|
onMessageUpdated,
|
|
16647
15881
|
onMessageDeleted,
|
|
@@ -16690,7 +15924,7 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
16690
15924
|
}
|
|
16691
15925
|
reactor(action) {
|
|
16692
15926
|
return (payload) => {
|
|
16693
|
-
var _a, _b, _c
|
|
15927
|
+
var _a, _b, _c;
|
|
16694
15928
|
if (action === 'onCreate') {
|
|
16695
15929
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16696
15930
|
const { referenceId } = payload;
|
|
@@ -16700,14 +15934,9 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
16700
15934
|
return;
|
|
16701
15935
|
if (this.query.type && this.query.type !== payload.dataType)
|
|
16702
15936
|
return;
|
|
16703
|
-
if (this.query.dataType && this.query.dataType !== payload.dataType)
|
|
16704
|
-
return;
|
|
16705
15937
|
if (this.query.excludingTags &&
|
|
16706
15938
|
((_b = this.query.excludingTags) === null || _b === void 0 ? void 0 : _b.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
16707
15939
|
return;
|
|
16708
|
-
if (this.query.excludeTags &&
|
|
16709
|
-
((_c = this.query.excludeTags) === null || _c === void 0 ? void 0 : _c.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
16710
|
-
return;
|
|
16711
15940
|
if (!!this.query.hasFlags !== !!payload.flagCount)
|
|
16712
15941
|
return;
|
|
16713
15942
|
if (this.query.parentId && this.query.parentId !== payload.parentId)
|
|
@@ -16717,9 +15946,7 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
16717
15946
|
payload.isDeleted)
|
|
16718
15947
|
return;
|
|
16719
15948
|
if (this.query.includingTags &&
|
|
16720
|
-
!((
|
|
16721
|
-
return;
|
|
16722
|
-
if (this.query.tags && !((_e = this.query.tags) === null || _e === void 0 ? void 0 : _e.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
15949
|
+
!((_c = this.query.includingTags) === null || _c === void 0 ? void 0 : _c.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
16723
15950
|
return;
|
|
16724
15951
|
if ((!this.query.sortBy || this.query.sortBy === 'segmentDesc') &&
|
|
16725
15952
|
!this.paginationController.getPrevToken()) {
|
|
@@ -16819,26 +16046,6 @@ class MessageLiveCollectionController extends LiveCollectionController {
|
|
|
16819
16046
|
}
|
|
16820
16047
|
applyFilter(data) {
|
|
16821
16048
|
let messages = data;
|
|
16822
|
-
messages = messages.filter(m => {
|
|
16823
|
-
if (this.query.tags) {
|
|
16824
|
-
return this.query.tags.find(value => {
|
|
16825
|
-
if (!m.tags)
|
|
16826
|
-
return false;
|
|
16827
|
-
return m.tags.includes(value);
|
|
16828
|
-
});
|
|
16829
|
-
}
|
|
16830
|
-
return true;
|
|
16831
|
-
});
|
|
16832
|
-
messages = messages.filter(m => {
|
|
16833
|
-
if (this.query.excludeTags) {
|
|
16834
|
-
return (this.query.excludeTags || []).find(value => {
|
|
16835
|
-
if (!m.tags)
|
|
16836
|
-
return true;
|
|
16837
|
-
return !m.tags.includes(value);
|
|
16838
|
-
});
|
|
16839
|
-
}
|
|
16840
|
-
return true;
|
|
16841
|
-
});
|
|
16842
16049
|
/*
|
|
16843
16050
|
* for cases when message is deleted via RTE, this flag is used to get
|
|
16844
16051
|
* items from cache that are !deleted
|
|
@@ -16855,227 +16062,70 @@ class MessageLiveCollectionController extends LiveCollectionController {
|
|
|
16855
16062
|
}
|
|
16856
16063
|
return 0;
|
|
16857
16064
|
});
|
|
16858
|
-
return messages;
|
|
16859
|
-
}
|
|
16860
|
-
setup() {
|
|
16861
|
-
var _a;
|
|
16862
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16863
|
-
if (!collection) {
|
|
16864
|
-
pushToCache(this.cacheKey, {
|
|
16865
|
-
data: [],
|
|
16866
|
-
query: this.query,
|
|
16867
|
-
});
|
|
16868
|
-
}
|
|
16869
|
-
}
|
|
16870
|
-
async persistModel(response) {
|
|
16871
|
-
await this.queryStreamController.saveToMainDB(response);
|
|
16872
|
-
}
|
|
16873
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
16874
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
16875
|
-
}
|
|
16876
|
-
}
|
|
16877
|
-
|
|
16878
|
-
/* eslint-disable no-use-before-define */
|
|
16879
|
-
/* begin_public_function
|
|
16880
|
-
id: message.query
|
|
16881
|
-
*/
|
|
16882
|
-
/**
|
|
16883
|
-
* ```js
|
|
16884
|
-
* import { getMessages } from '@amityco/ts-sdk-react-native';
|
|
16885
|
-
*
|
|
16886
|
-
* let messages = [];
|
|
16887
|
-
*
|
|
16888
|
-
* const unsubscribe = getMessages({
|
|
16889
|
-
* subChannelId: Amity.SubChannel['subChannelId'];
|
|
16890
|
-
* }, response => merge(messages, response.data));
|
|
16891
|
-
* ```
|
|
16892
|
-
*
|
|
16893
|
-
* Observe all mutations on a list of {@link Amity.Message} for a given target object
|
|
16894
|
-
*
|
|
16895
|
-
* @param params for querying messages from a sub channel
|
|
16896
|
-
* @param callback the function to call when new data are available
|
|
16897
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
16898
|
-
*
|
|
16899
|
-
* @category Messages Live Collection
|
|
16900
|
-
*/
|
|
16901
|
-
const getMessages = (params, callback, config) => {
|
|
16902
|
-
const { log, cache } = getActiveClient();
|
|
16903
|
-
if (!cache) {
|
|
16904
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
16905
|
-
}
|
|
16906
|
-
const timestamp = Date.now();
|
|
16907
|
-
log(`getMessages(tmpid: ${timestamp}) > listen`);
|
|
16908
|
-
const messagesLiveCollection = new MessageLiveCollectionController(params, callback);
|
|
16909
|
-
const disposers = messagesLiveCollection.startSubscription();
|
|
16910
|
-
const cacheKey = messagesLiveCollection.getCacheKey();
|
|
16911
|
-
disposers.push(() => {
|
|
16912
|
-
dropFromCache(cacheKey);
|
|
16913
|
-
});
|
|
16914
|
-
return () => {
|
|
16915
|
-
log(`getMessages(tmpid: ${timestamp}) > dispose`);
|
|
16916
|
-
disposers.forEach(fn => fn());
|
|
16917
|
-
};
|
|
16918
|
-
};
|
|
16919
|
-
/* end_public_function */
|
|
16920
|
-
|
|
16921
|
-
/**
|
|
16922
|
-
* ```js
|
|
16923
|
-
* import { getMessage } from '@amityco/ts-sdk-react-native'
|
|
16924
|
-
* const message = await getMessage('foobar')
|
|
16925
|
-
* ```
|
|
16926
|
-
*
|
|
16927
|
-
* Fetches a {@link Amity.Message} object
|
|
16928
|
-
*
|
|
16929
|
-
* @param messageId the ID of the {@link Amity.Message} to fetch
|
|
16930
|
-
* @returns the associated {@link Amity.Message} object
|
|
16931
|
-
*
|
|
16932
|
-
* @category Message API
|
|
16933
|
-
* @async
|
|
16934
|
-
*/
|
|
16935
|
-
const getMessage = async (messageId, isLive = false) => {
|
|
16936
|
-
const client = getActiveClient();
|
|
16937
|
-
client.log('message/getMessage', messageId);
|
|
16938
|
-
if (!isLive) {
|
|
16939
|
-
console.log('getMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
|
|
16940
|
-
}
|
|
16941
|
-
isInTombstone('message', messageId);
|
|
16942
|
-
let data;
|
|
16943
|
-
try {
|
|
16944
|
-
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
16945
|
-
const { data: payload } = await client.http.get(`/api/v5/messages/${encodeURIComponent(messageId)}`);
|
|
16946
|
-
data = await prepareMessagePayload(payload);
|
|
16947
|
-
}
|
|
16948
|
-
catch (error) {
|
|
16949
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
16950
|
-
pushToTombstone('message', messageId);
|
|
16951
|
-
}
|
|
16952
|
-
throw error;
|
|
16953
|
-
}
|
|
16954
|
-
const cachedAt = client.cache && Date.now();
|
|
16955
|
-
if (client.cache)
|
|
16956
|
-
ingestInCache(data, { cachedAt });
|
|
16957
|
-
const { messages } = data;
|
|
16958
|
-
fireEvent('local.message.fetched', { messages });
|
|
16959
|
-
return {
|
|
16960
|
-
data: LinkedObject.message(messages.find(message => message.messageId === messageId)),
|
|
16961
|
-
cachedAt,
|
|
16962
|
-
};
|
|
16963
|
-
};
|
|
16964
|
-
/**
|
|
16965
|
-
* ```js
|
|
16966
|
-
* import { getMessage } from '@amityco/ts-sdk-react-native'
|
|
16967
|
-
* const message = getMessage.locally('foobar')
|
|
16968
|
-
* ```
|
|
16969
|
-
*
|
|
16970
|
-
* Fetches a {@link Amity.Message} object
|
|
16971
|
-
*
|
|
16972
|
-
* @param messageId the ID of the {@link Amity.Message} to fetch
|
|
16973
|
-
* @returns the associated {@link Amity.Message} object
|
|
16974
|
-
*
|
|
16975
|
-
* @category Message API
|
|
16976
|
-
*/
|
|
16977
|
-
getMessage.locally = (messageId) => {
|
|
16978
|
-
const client = getActiveClient();
|
|
16979
|
-
client.log('message/getMessage.locally', messageId);
|
|
16980
|
-
if (!client.cache)
|
|
16981
|
-
return;
|
|
16982
|
-
const cached = pullFromCache(['message', 'get', messageId]);
|
|
16983
|
-
if (!cached)
|
|
16984
|
-
return;
|
|
16985
|
-
return {
|
|
16986
|
-
data: cached.data,
|
|
16987
|
-
cachedAt: cached.cachedAt,
|
|
16988
|
-
};
|
|
16989
|
-
};
|
|
16990
|
-
|
|
16991
|
-
/**
|
|
16992
|
-
* ```js
|
|
16993
|
-
* import { observeMessage } from '@amityco/ts-sdk-react-native'
|
|
16994
|
-
*
|
|
16995
|
-
* let message = {}
|
|
16996
|
-
*
|
|
16997
|
-
* const unsub = observeMessage(messageId, updated => message = updated)
|
|
16998
|
-
* ```
|
|
16999
|
-
*
|
|
17000
|
-
* Observe all mutations on a {@link Amity.Message} given a single messageId
|
|
17001
|
-
*
|
|
17002
|
-
* @param client the client to observe the message with
|
|
17003
|
-
* @param messageId the ID of the message to observe
|
|
17004
|
-
* @param callback the function to call when new data are available
|
|
17005
|
-
* @param policy a query policy option for this observer
|
|
17006
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
|
|
17007
|
-
*
|
|
17008
|
-
* @category Message Observer
|
|
17009
|
-
*/
|
|
17010
|
-
const observeMessage = (messageId, callback, policy = 'cache_then_server') => {
|
|
17011
|
-
const { log } = getActiveClient();
|
|
17012
|
-
const timestamp = Date.now();
|
|
17013
|
-
log(`observeMessage(tmpid: ${timestamp}) > listen`);
|
|
17014
|
-
console.log('observeMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
|
|
17015
|
-
// wrapper function to make sure
|
|
17016
|
-
const router = (result, action) => {
|
|
17017
|
-
var _a, _b, _c;
|
|
17018
|
-
// filter function
|
|
17019
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.messageId) !== messageId)
|
|
17020
|
-
return;
|
|
17021
|
-
if (callback instanceof Function)
|
|
17022
|
-
return callback(result);
|
|
17023
|
-
if (action !== 'onFetch')
|
|
17024
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, result);
|
|
17025
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
|
|
17026
|
-
};
|
|
17027
|
-
const disposers = [];
|
|
17028
|
-
disposers.push(onMessageUpdated(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onUpdate')), onMessageDeleted(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onDelete')), convertEventPayload(onMessageMarkerFetched, 'contentId', 'message')(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onUpdate')), convertEventPayload(onMessageMarked, 'contentId', 'message')(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onUpdate')));
|
|
17029
|
-
if (policy !== 'no_fetch') {
|
|
17030
|
-
runQuery(createQuery(getMessage, messageId), result => result.data && router(result, 'onFetch'), queryOptions(policy));
|
|
16065
|
+
return messages;
|
|
17031
16066
|
}
|
|
17032
|
-
|
|
17033
|
-
|
|
17034
|
-
|
|
17035
|
-
|
|
17036
|
-
|
|
16067
|
+
setup() {
|
|
16068
|
+
var _a;
|
|
16069
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16070
|
+
if (!collection) {
|
|
16071
|
+
pushToCache(this.cacheKey, {
|
|
16072
|
+
data: [],
|
|
16073
|
+
query: this.query,
|
|
16074
|
+
});
|
|
16075
|
+
}
|
|
16076
|
+
}
|
|
16077
|
+
async persistModel(response) {
|
|
16078
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
16079
|
+
}
|
|
16080
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
16081
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
16082
|
+
}
|
|
16083
|
+
}
|
|
17037
16084
|
|
|
16085
|
+
/* begin_public_function
|
|
16086
|
+
id: message.query
|
|
16087
|
+
*/
|
|
17038
16088
|
/**
|
|
17039
16089
|
* ```js
|
|
17040
|
-
* import {
|
|
16090
|
+
* import { getMessages } from '@amityco/ts-sdk-react-native';
|
|
17041
16091
|
*
|
|
17042
|
-
* let messages = []
|
|
16092
|
+
* let messages = [];
|
|
17043
16093
|
*
|
|
17044
|
-
* const unsubscribe =
|
|
16094
|
+
* const unsubscribe = getMessages({
|
|
16095
|
+
* subChannelId: Amity.SubChannel['subChannelId'];
|
|
16096
|
+
* }, response => merge(messages, response.data));
|
|
17045
16097
|
* ```
|
|
17046
16098
|
*
|
|
17047
|
-
* Observe all mutations on a list of {@link Amity.Message} for a given
|
|
16099
|
+
* Observe all mutations on a list of {@link Amity.Message} for a given target object
|
|
17048
16100
|
*
|
|
17049
|
-
* @param
|
|
16101
|
+
* @param params for querying messages from a sub channel
|
|
17050
16102
|
* @param callback the function to call when new data are available
|
|
17051
16103
|
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
17052
16104
|
*
|
|
17053
|
-
* @category
|
|
16105
|
+
* @category Messages Live Collection
|
|
17054
16106
|
*/
|
|
17055
|
-
const
|
|
17056
|
-
const { log } = getActiveClient();
|
|
16107
|
+
const getMessages = (params, callback, config) => {
|
|
16108
|
+
const { log, cache } = getActiveClient();
|
|
16109
|
+
if (!cache) {
|
|
16110
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
16111
|
+
}
|
|
17057
16112
|
const timestamp = Date.now();
|
|
17058
|
-
log(`
|
|
17059
|
-
const
|
|
17060
|
-
const
|
|
17061
|
-
|
|
17062
|
-
|
|
17063
|
-
|
|
17064
|
-
|
|
17065
|
-
return callback(message);
|
|
17066
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, message);
|
|
17067
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, message);
|
|
17068
|
-
};
|
|
17069
|
-
disposers.push(onMessageCreatedMqtt(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onCreate')), onMessageCreatedLocal(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onCreate')), onMessageUpdated(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onUpdate')), onMessageDeleted(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onDelete')), convertEventPayload(onMessageMarkerFetched, 'contentId', 'message')(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onCreate')), convertEventPayload(onMessageMarked, 'contentId', 'message')(data => router({ data: LinkedObject.message(data), loading: false, origin: 'event' }, 'onCreate')));
|
|
16113
|
+
log(`getMessages(tmpid: ${timestamp}) > listen`);
|
|
16114
|
+
const messagesLiveCollection = new MessageLiveCollectionController(params, callback);
|
|
16115
|
+
const disposers = messagesLiveCollection.startSubscription();
|
|
16116
|
+
const cacheKey = messagesLiveCollection.getCacheKey();
|
|
16117
|
+
disposers.push(() => {
|
|
16118
|
+
dropFromCache(cacheKey);
|
|
16119
|
+
});
|
|
17070
16120
|
return () => {
|
|
17071
|
-
log(`
|
|
16121
|
+
log(`getMessages(tmpid: ${timestamp}) > dispose`);
|
|
17072
16122
|
disposers.forEach(fn => fn());
|
|
17073
16123
|
};
|
|
17074
|
-
};
|
|
16124
|
+
};
|
|
16125
|
+
/* end_public_function */
|
|
17075
16126
|
|
|
17076
16127
|
var index$g = /*#__PURE__*/Object.freeze({
|
|
17077
16128
|
__proto__: null,
|
|
17078
|
-
getMessageByIds: getMessages$1,
|
|
17079
16129
|
createMessage: createMessage,
|
|
17080
16130
|
updateMessage: updateMessage,
|
|
17081
16131
|
editMessage: editMessage,
|
|
@@ -17097,10 +16147,8 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
17097
16147
|
onMessageReactionAdded: onMessageReactionAdded,
|
|
17098
16148
|
onMessageReactionRemoved: onMessageReactionRemoved,
|
|
17099
16149
|
onMessageFetched: onMessageFetched,
|
|
17100
|
-
getMessage: getMessage
|
|
16150
|
+
getMessage: getMessage,
|
|
17101
16151
|
getMessages: getMessages,
|
|
17102
|
-
observeMessage: observeMessage,
|
|
17103
|
-
observeMessages: observeMessages,
|
|
17104
16152
|
convertFromRaw: convertFromRaw$1,
|
|
17105
16153
|
prepareMessagePayload: prepareMessagePayload,
|
|
17106
16154
|
convertParams: convertParams,
|
|
@@ -17617,8 +16665,6 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
17617
16665
|
getSubChannel: getSubChannel,
|
|
17618
16666
|
getSubChannels: getSubChannels,
|
|
17619
16667
|
markReadEngineOnLoginHandler: markReadEngineOnLoginHandler,
|
|
17620
|
-
startReading: startReading,
|
|
17621
|
-
stopReading: stopReading,
|
|
17622
16668
|
startMessageReceiptSync: startMessageReceiptSync,
|
|
17623
16669
|
stopMessageReceiptSync: stopMessageReceiptSync
|
|
17624
16670
|
});
|
|
@@ -17669,7 +16715,7 @@ const getChannel = (channelId, callback) => {
|
|
|
17669
16715
|
const reactor = async (response) => {
|
|
17670
16716
|
if (!response.data)
|
|
17671
16717
|
return callback(response);
|
|
17672
|
-
const data = Object.assign(Object.assign({}, response), { data:
|
|
16718
|
+
const data = Object.assign(Object.assign({}, response), { data: constructChannelObject(response.data) });
|
|
17673
16719
|
const newSnapshot = __rest(data, ["origin"]);
|
|
17674
16720
|
/**
|
|
17675
16721
|
* check equality of previous data and current data to avoid redundancy
|
|
@@ -17703,7 +16749,11 @@ const getChannel = (channelId, callback) => {
|
|
|
17703
16749
|
if (message.channelId !== channelId)
|
|
17704
16750
|
return;
|
|
17705
16751
|
// channelId from message is channelInternalId
|
|
17706
|
-
const channel = (_a = pullFromCache([
|
|
16752
|
+
const channel = (_a = pullFromCache([
|
|
16753
|
+
'channel',
|
|
16754
|
+
'get',
|
|
16755
|
+
channelId,
|
|
16756
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17707
16757
|
if (!channel)
|
|
17708
16758
|
return;
|
|
17709
16759
|
updateChannelCache(channel, {
|
|
@@ -17726,7 +16776,11 @@ const getChannel = (channelId, callback) => {
|
|
|
17726
16776
|
if (message.channelId !== channelId)
|
|
17727
16777
|
return;
|
|
17728
16778
|
// channelId from message is channelInternalId
|
|
17729
|
-
const channel = (_a = pullFromCache([
|
|
16779
|
+
const channel = (_a = pullFromCache([
|
|
16780
|
+
'channel',
|
|
16781
|
+
'get',
|
|
16782
|
+
channelId,
|
|
16783
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17730
16784
|
if (!channel)
|
|
17731
16785
|
return;
|
|
17732
16786
|
updateChannelCache(channel, {
|
|
@@ -17739,7 +16793,11 @@ const getChannel = (channelId, callback) => {
|
|
|
17739
16793
|
convertEventPayload((callback) => {
|
|
17740
16794
|
const updateMessagePreview = async (message) => {
|
|
17741
16795
|
var _a;
|
|
17742
|
-
const channel = (_a = pullFromCache([
|
|
16796
|
+
const channel = (_a = pullFromCache([
|
|
16797
|
+
'channel',
|
|
16798
|
+
'get',
|
|
16799
|
+
channelId,
|
|
16800
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17743
16801
|
if (!channel || channel.messagePreviewId !== message.messageId)
|
|
17744
16802
|
return;
|
|
17745
16803
|
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
@@ -17753,7 +16811,11 @@ const getChannel = (channelId, callback) => {
|
|
|
17753
16811
|
convertEventPayload((callback) => {
|
|
17754
16812
|
const updateMessagePreview = async (message) => {
|
|
17755
16813
|
var _a;
|
|
17756
|
-
const channel = (_a = pullFromCache([
|
|
16814
|
+
const channel = (_a = pullFromCache([
|
|
16815
|
+
'channel',
|
|
16816
|
+
'get',
|
|
16817
|
+
channelId,
|
|
16818
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17757
16819
|
if (!channel || channel.messagePreviewId !== message.messageId)
|
|
17758
16820
|
return;
|
|
17759
16821
|
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
@@ -17786,7 +16848,11 @@ const getChannel = (channelId, callback) => {
|
|
|
17786
16848
|
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
17787
16849
|
return;
|
|
17788
16850
|
await getChannel$1(channelId);
|
|
17789
|
-
const channel = (_b = pullFromCache([
|
|
16851
|
+
const channel = (_b = pullFromCache([
|
|
16852
|
+
'channel',
|
|
16853
|
+
'get',
|
|
16854
|
+
channelId,
|
|
16855
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
17790
16856
|
if (!channel)
|
|
17791
16857
|
return;
|
|
17792
16858
|
callback(subChannel);
|
|
@@ -17808,7 +16874,11 @@ const getChannel = (channelId, callback) => {
|
|
|
17808
16874
|
if (!messagePreviewCache ||
|
|
17809
16875
|
messagePreviewCache.subChannelId !== subChannel.subChannelId)
|
|
17810
16876
|
return;
|
|
17811
|
-
const channel = (_b = pullFromCache([
|
|
16877
|
+
const channel = (_b = pullFromCache([
|
|
16878
|
+
'channel',
|
|
16879
|
+
'get',
|
|
16880
|
+
channelId,
|
|
16881
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
17812
16882
|
if (!channel)
|
|
17813
16883
|
return;
|
|
17814
16884
|
callback(subChannel);
|
|
@@ -18004,9 +17074,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
18004
17074
|
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
18005
17075
|
.filter(Boolean)
|
|
18006
17076
|
.map(({ data }) => data)
|
|
18007
|
-
.map(
|
|
18008
|
-
.map(constructChannelDynamicValue)
|
|
18009
|
-
.map(LinkedObject.channel)) !== null && _b !== void 0 ? _b : [];
|
|
17077
|
+
.map(constructChannelObject)) !== null && _b !== void 0 ? _b : [];
|
|
18010
17078
|
if (this.paginationController instanceof ChannelPaginationController) {
|
|
18011
17079
|
data = this.applyFilter(data);
|
|
18012
17080
|
}
|
|
@@ -18653,11 +17721,6 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
18653
17721
|
return false;
|
|
18654
17722
|
});
|
|
18655
17723
|
}
|
|
18656
|
-
if (this.query.search) {
|
|
18657
|
-
// eslint-disable-next-line no-console
|
|
18658
|
-
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.');
|
|
18659
|
-
channelMembers = filterBySearchTerm(channelMembers, this.query.search);
|
|
18660
|
-
}
|
|
18661
17724
|
if (this.query.includeDeleted === false) {
|
|
18662
17725
|
channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted) !== true; });
|
|
18663
17726
|
}
|
|
@@ -18691,11 +17754,6 @@ const applyFilter$1 = (data, params) => {
|
|
|
18691
17754
|
return params.memberships.includes(member.membership);
|
|
18692
17755
|
});
|
|
18693
17756
|
}
|
|
18694
|
-
if (params.search) {
|
|
18695
|
-
// eslint-disable-next-line no-console
|
|
18696
|
-
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.');
|
|
18697
|
-
channelMembers = filterBySearchTerm(channelMembers, params.search);
|
|
18698
|
-
}
|
|
18699
17757
|
// sort, 'lastCreated' is the default sort order
|
|
18700
17758
|
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
18701
17759
|
channelMembers = channelMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
@@ -18987,7 +18045,7 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
18987
18045
|
__proto__: null,
|
|
18988
18046
|
Membership: index$e,
|
|
18989
18047
|
Moderation: index$d,
|
|
18990
|
-
getChannelByIds: getChannelByIds,
|
|
18048
|
+
getChannelByIds: getChannelByIds$1,
|
|
18991
18049
|
createChannel: createChannel,
|
|
18992
18050
|
updateChannel: updateChannel,
|
|
18993
18051
|
deleteChannel: deleteChannel,
|
|
@@ -18995,7 +18053,6 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
18995
18053
|
leaveChannel: leaveChannel,
|
|
18996
18054
|
muteChannel: muteChannel,
|
|
18997
18055
|
unmuteChannel: unmuteChannel,
|
|
18998
|
-
markAsRead: markAsRead,
|
|
18999
18056
|
onChannelCreated: onChannelCreated,
|
|
19000
18057
|
onChannelUpdated: onChannelUpdated,
|
|
19001
18058
|
onChannelDeleted: onChannelDeleted,
|
|
@@ -19008,8 +18065,6 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
19008
18065
|
onChannelMemberUnbanned: onChannelMemberUnbanned,
|
|
19009
18066
|
onChannelMemberRoleAdded: onChannelMemberRoleAdded,
|
|
19010
18067
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
19011
|
-
observeChannel: observeChannel,
|
|
19012
|
-
observeChannels: observeChannels,
|
|
19013
18068
|
getChannel: getChannel,
|
|
19014
18069
|
getChannels: getChannels,
|
|
19015
18070
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
@@ -19314,154 +18369,300 @@ const leaveCommunity = async (communityId) => {
|
|
|
19314
18369
|
const data = prepareCommunityPayload(payload);
|
|
19315
18370
|
const cachedAt = client.cache && Date.now();
|
|
19316
18371
|
if (client.cache)
|
|
19317
|
-
ingestInCache(data, { cachedAt });
|
|
18372
|
+
ingestInCache(data, { cachedAt });
|
|
18373
|
+
const { communityUsers } = data;
|
|
18374
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
18375
|
+
};
|
|
18376
|
+
/* end_public_function */
|
|
18377
|
+
|
|
18378
|
+
const createCommunityEventSubscriber = (event, callback) => {
|
|
18379
|
+
const client = getActiveClient();
|
|
18380
|
+
const filter = (payload) => {
|
|
18381
|
+
const unpackedPayload = prepareCommunityPayload(payload);
|
|
18382
|
+
if (!client.cache) {
|
|
18383
|
+
// TODO: here we are missing specific properties here!
|
|
18384
|
+
callback(unpackedPayload.communities[0]);
|
|
18385
|
+
}
|
|
18386
|
+
else {
|
|
18387
|
+
ingestInCache(unpackedPayload);
|
|
18388
|
+
const community = pullFromCache([
|
|
18389
|
+
'community',
|
|
18390
|
+
'get',
|
|
18391
|
+
unpackedPayload.communities[0].communityId,
|
|
18392
|
+
]);
|
|
18393
|
+
callback(community.data);
|
|
18394
|
+
}
|
|
18395
|
+
};
|
|
18396
|
+
return createEventSubscriber(client, event, event, filter);
|
|
18397
|
+
};
|
|
18398
|
+
|
|
18399
|
+
/**
|
|
18400
|
+
* ```js
|
|
18401
|
+
* import { onCommunityCreated } from '@amityco/ts-sdk-react-native'
|
|
18402
|
+
* const dispose = onCommunityCreated(community => {
|
|
18403
|
+
* // ...
|
|
18404
|
+
* })
|
|
18405
|
+
* ```
|
|
18406
|
+
*
|
|
18407
|
+
* Fired when a {@link Amity.Community} have been created
|
|
18408
|
+
*
|
|
18409
|
+
* @param callback The function to call when the event was fired
|
|
18410
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18411
|
+
*
|
|
18412
|
+
* @category Community Events
|
|
18413
|
+
*/
|
|
18414
|
+
const onCommunityCreated = (callback) => createCommunityEventSubscriber('community.created', callback);
|
|
18415
|
+
|
|
18416
|
+
/**
|
|
18417
|
+
* ```js
|
|
18418
|
+
* import { onCommunityUpdated } from '@amityco/ts-sdk-react-native'
|
|
18419
|
+
* const dispose = onCommunityUpdated(community => {
|
|
18420
|
+
* // ...
|
|
18421
|
+
* })
|
|
18422
|
+
* ```
|
|
18423
|
+
*
|
|
18424
|
+
* Fired when a {@link Amity.Community} has been updated
|
|
18425
|
+
*
|
|
18426
|
+
* @param callback The function to call when the event was fired
|
|
18427
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18428
|
+
*
|
|
18429
|
+
* @category Community Events
|
|
18430
|
+
*/
|
|
18431
|
+
const onCommunityUpdated = (callback) => createCommunityEventSubscriber('community.updated', callback);
|
|
18432
|
+
|
|
18433
|
+
/**
|
|
18434
|
+
* ```js
|
|
18435
|
+
* import { onCommunityDeleted } from '@amityco/ts-sdk-react-native'
|
|
18436
|
+
* const dispose = onCommunityDeleted(community => {
|
|
18437
|
+
* // ...
|
|
18438
|
+
* })
|
|
18439
|
+
* ```
|
|
18440
|
+
*
|
|
18441
|
+
* Fired when a {@link Amity.Community} has been deleted
|
|
18442
|
+
*
|
|
18443
|
+
* @param callback The function to call when the event was fired
|
|
18444
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18445
|
+
*
|
|
18446
|
+
* @category Community Events
|
|
18447
|
+
*/
|
|
18448
|
+
const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
|
|
18449
|
+
|
|
18450
|
+
/**
|
|
18451
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
18452
|
+
* TODO: check if querybyIds is supported
|
|
18453
|
+
*/
|
|
18454
|
+
class CommunitiesPaginationController$1 extends PaginationController {
|
|
18455
|
+
async getRequest(queryParams, token) {
|
|
18456
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
18457
|
+
const options = token ? { token } : { limit };
|
|
18458
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
18459
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
18460
|
+
});
|
|
18461
|
+
return queryResponse;
|
|
18462
|
+
}
|
|
18463
|
+
}
|
|
18464
|
+
|
|
18465
|
+
class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
18466
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
18467
|
+
super(query, cacheKey);
|
|
18468
|
+
this.notifyChange = notifyChange;
|
|
18469
|
+
this.preparePayload = preparePayload;
|
|
18470
|
+
}
|
|
18471
|
+
async saveToMainDB(response) {
|
|
18472
|
+
const processedPayload = await this.preparePayload(response);
|
|
18473
|
+
const client = getActiveClient();
|
|
18474
|
+
const cachedAt = client.cache && Date.now();
|
|
18475
|
+
if (client.cache) {
|
|
18476
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
18477
|
+
}
|
|
18478
|
+
}
|
|
18479
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
18480
|
+
var _a, _b;
|
|
18481
|
+
if (refresh) {
|
|
18482
|
+
pushToCache(this.cacheKey, {
|
|
18483
|
+
data: response.communities.map(getResolver('community')),
|
|
18484
|
+
});
|
|
18485
|
+
}
|
|
18486
|
+
else {
|
|
18487
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18488
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
18489
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
18490
|
+
}
|
|
18491
|
+
}
|
|
18492
|
+
reactor(action) {
|
|
18493
|
+
return (community) => {
|
|
18494
|
+
var _a;
|
|
18495
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18496
|
+
if (!collection)
|
|
18497
|
+
return;
|
|
18498
|
+
pushToCache(this.cacheKey, collection);
|
|
18499
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
18500
|
+
};
|
|
18501
|
+
}
|
|
18502
|
+
subscribeRTE(createSubscriber) {
|
|
18503
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
18504
|
+
}
|
|
18505
|
+
}
|
|
18506
|
+
|
|
18507
|
+
var EnumCommunityActions$4;
|
|
18508
|
+
(function (EnumCommunityActions) {
|
|
18509
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
18510
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
18511
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
18512
|
+
})(EnumCommunityActions$4 || (EnumCommunityActions$4 = {}));
|
|
18513
|
+
|
|
18514
|
+
var EnumCommunityMemberActions$1;
|
|
18515
|
+
(function (EnumCommunityMemberActions) {
|
|
18516
|
+
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
18517
|
+
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
18518
|
+
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
18519
|
+
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
18520
|
+
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
18521
|
+
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
18522
|
+
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
18523
|
+
EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
|
|
18524
|
+
EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
|
|
18525
|
+
EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
|
|
18526
|
+
EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
|
|
18527
|
+
})(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
|
|
18528
|
+
|
|
18529
|
+
/* begin_public_function
|
|
18530
|
+
id: community.membership.add_members
|
|
18531
|
+
*/
|
|
18532
|
+
/**
|
|
18533
|
+
* ```js
|
|
18534
|
+
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
18535
|
+
* const updated = await CommunityRepository.moderation.addMembers(communityId, ['foo', 'bar'])
|
|
18536
|
+
* ```
|
|
18537
|
+
*
|
|
18538
|
+
* Adds a list of {@link Amity.InternalUser} to a {@link Amity.Community} to add users to
|
|
18539
|
+
*
|
|
18540
|
+
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
18541
|
+
* @param userIds The list of IDs {@link Amity.InternalUser} to add
|
|
18542
|
+
* @returns A success boolean if the {@link Amity.InternalUser} were added to the {@link Amity.Community}
|
|
18543
|
+
*
|
|
18544
|
+
* @category Community API
|
|
18545
|
+
* @async
|
|
18546
|
+
*/
|
|
18547
|
+
const addMembers = async (communityId, userIds) => {
|
|
18548
|
+
const client = getActiveClient();
|
|
18549
|
+
client.log('community/moderation/addMembers', communityId, userIds);
|
|
18550
|
+
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
18551
|
+
fireEvent('local.community.userAdded', payload);
|
|
18552
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
18553
|
+
if (client.cache)
|
|
18554
|
+
ingestInCache(data);
|
|
19318
18555
|
const { communityUsers } = data;
|
|
19319
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership
|
|
18556
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
19320
18557
|
};
|
|
19321
18558
|
/* end_public_function */
|
|
19322
18559
|
|
|
19323
18560
|
/* begin_public_function
|
|
19324
|
-
id: community.
|
|
18561
|
+
id: community.membership.remove_member
|
|
19325
18562
|
*/
|
|
19326
18563
|
/**
|
|
19327
|
-
* @deprecated This API renamed to `getTrendingCommunities()`.
|
|
19328
|
-
* Please use getTrendingCommunities() instead.
|
|
19329
|
-
*
|
|
19330
18564
|
* ```js
|
|
19331
18565
|
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
19332
|
-
* const
|
|
18566
|
+
* const updated = await CommunityRepository.moderation.removeMembers(communityId, ['foo', 'bar'])
|
|
19333
18567
|
* ```
|
|
19334
18568
|
*
|
|
19335
|
-
*
|
|
18569
|
+
* Removes a list of {@link Amity.InternalUser} from a {@link Amity.Community}
|
|
19336
18570
|
*
|
|
19337
|
-
* @param
|
|
19338
|
-
* @
|
|
18571
|
+
* @param communityId The ID of the {@link Amity.Community} to edit
|
|
18572
|
+
* @param userIds The list of IDs {@link Amity.InternalUser} to remove
|
|
18573
|
+
* @returns A success boolean if the list of {@link Amity.InternalUser} were removed from the {@link Amity.Community}
|
|
19339
18574
|
*
|
|
19340
18575
|
* @category Community API
|
|
19341
18576
|
* @async
|
|
19342
18577
|
*/
|
|
19343
|
-
const
|
|
18578
|
+
const removeMembers = async (communityId, userIds) => {
|
|
19344
18579
|
const client = getActiveClient();
|
|
19345
|
-
client.log('
|
|
19346
|
-
const {
|
|
19347
|
-
|
|
19348
|
-
|
|
19349
|
-
|
|
19350
|
-
|
|
19351
|
-
const {
|
|
19352
|
-
|
|
19353
|
-
if (client.cache) {
|
|
19354
|
-
ingestInCache(data, { cachedAt });
|
|
19355
|
-
const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
19356
|
-
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
19357
|
-
}
|
|
19358
|
-
return { data: communities, cachedAt };
|
|
18580
|
+
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
18581
|
+
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
18582
|
+
fireEvent('local.community.userRemoved', payload);
|
|
18583
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
18584
|
+
if (client.cache)
|
|
18585
|
+
ingestInCache(data);
|
|
18586
|
+
const { communityUsers } = data;
|
|
18587
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
19359
18588
|
};
|
|
19360
|
-
/* end_public_function */
|
|
18589
|
+
/* end_public_function */
|
|
18590
|
+
|
|
19361
18591
|
/**
|
|
19362
|
-
*
|
|
19363
|
-
*
|
|
19364
|
-
* const communities = getTopTrendingCommunities.locally()
|
|
19365
|
-
* ```
|
|
19366
|
-
*
|
|
19367
|
-
* Gets a list of top trending {@link Amity.Community} objects from cache
|
|
19368
|
-
*
|
|
19369
|
-
* @param query The query parameters
|
|
19370
|
-
* @returns communities
|
|
19371
|
-
*
|
|
19372
|
-
* @category Community API
|
|
18592
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
18593
|
+
* TODO: check if querybyIds is supported
|
|
19373
18594
|
*/
|
|
19374
|
-
|
|
19375
|
-
|
|
19376
|
-
|
|
19377
|
-
|
|
19378
|
-
|
|
19379
|
-
|
|
19380
|
-
|
|
19381
|
-
|
|
19382
|
-
|
|
19383
|
-
|
|
19384
|
-
|
|
19385
|
-
|
|
19386
|
-
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
19387
|
-
.filter(Boolean)
|
|
19388
|
-
.map(({ data }) => data);
|
|
19389
|
-
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
19390
|
-
? { data: communities, cachedAt }
|
|
19391
|
-
: undefined;
|
|
19392
|
-
};
|
|
18595
|
+
class CommunityMembersPaginationController extends PaginationController {
|
|
18596
|
+
async getRequest(queryParams, token) {
|
|
18597
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
18598
|
+
const options = token ? { token } : { limit };
|
|
18599
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
18600
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
18601
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
18602
|
+
isDeleted }),
|
|
18603
|
+
});
|
|
18604
|
+
return queryResponse;
|
|
18605
|
+
}
|
|
18606
|
+
}
|
|
19393
18607
|
|
|
19394
|
-
|
|
19395
|
-
|
|
19396
|
-
|
|
19397
|
-
|
|
19398
|
-
|
|
19399
|
-
|
|
19400
|
-
|
|
18608
|
+
class CommunityMembersQueryStreamController extends QueryStreamController {
|
|
18609
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
18610
|
+
super(query, cacheKey);
|
|
18611
|
+
this.notifyChange = notifyChange;
|
|
18612
|
+
this.preparePayload = preparePayload;
|
|
18613
|
+
}
|
|
18614
|
+
async saveToMainDB(response) {
|
|
18615
|
+
const processedPayload = await this.preparePayload(response);
|
|
18616
|
+
const client = getActiveClient();
|
|
18617
|
+
const cachedAt = client.cache && Date.now();
|
|
18618
|
+
if (client.cache) {
|
|
18619
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
18620
|
+
}
|
|
18621
|
+
}
|
|
18622
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
18623
|
+
var _a, _b;
|
|
18624
|
+
if (refresh) {
|
|
18625
|
+
pushToCache(this.cacheKey, {
|
|
18626
|
+
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
18627
|
+
});
|
|
19401
18628
|
}
|
|
19402
18629
|
else {
|
|
19403
|
-
|
|
19404
|
-
const
|
|
19405
|
-
|
|
19406
|
-
|
|
19407
|
-
|
|
19408
|
-
|
|
19409
|
-
|
|
18630
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18631
|
+
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
18632
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
18633
|
+
...new Set([
|
|
18634
|
+
...communityUsers,
|
|
18635
|
+
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
18636
|
+
]),
|
|
18637
|
+
] }));
|
|
19410
18638
|
}
|
|
19411
|
-
}
|
|
19412
|
-
|
|
19413
|
-
|
|
19414
|
-
|
|
19415
|
-
|
|
19416
|
-
|
|
19417
|
-
|
|
19418
|
-
|
|
19419
|
-
|
|
19420
|
-
|
|
19421
|
-
|
|
19422
|
-
|
|
19423
|
-
|
|
19424
|
-
|
|
19425
|
-
|
|
19426
|
-
|
|
19427
|
-
|
|
19428
|
-
|
|
19429
|
-
|
|
19430
|
-
|
|
19431
|
-
|
|
19432
|
-
|
|
19433
|
-
|
|
19434
|
-
|
|
19435
|
-
|
|
19436
|
-
|
|
19437
|
-
|
|
19438
|
-
* ```
|
|
19439
|
-
*
|
|
19440
|
-
* Fired when a {@link Amity.Community} has been updated
|
|
19441
|
-
*
|
|
19442
|
-
* @param callback The function to call when the event was fired
|
|
19443
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19444
|
-
*
|
|
19445
|
-
* @category Community Events
|
|
19446
|
-
*/
|
|
19447
|
-
const onCommunityUpdated = (callback) => createCommunityEventSubscriber('community.updated', callback);
|
|
19448
|
-
|
|
19449
|
-
/**
|
|
19450
|
-
* ```js
|
|
19451
|
-
* import { onCommunityDeleted } from '@amityco/ts-sdk-react-native'
|
|
19452
|
-
* const dispose = onCommunityDeleted(community => {
|
|
19453
|
-
* // ...
|
|
19454
|
-
* })
|
|
19455
|
-
* ```
|
|
19456
|
-
*
|
|
19457
|
-
* Fired when a {@link Amity.Community} has been deleted
|
|
19458
|
-
*
|
|
19459
|
-
* @param callback The function to call when the event was fired
|
|
19460
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19461
|
-
*
|
|
19462
|
-
* @category Community Events
|
|
19463
|
-
*/
|
|
19464
|
-
const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
|
|
18639
|
+
}
|
|
18640
|
+
reactor(action) {
|
|
18641
|
+
return (community, communityMembers) => {
|
|
18642
|
+
var _a;
|
|
18643
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18644
|
+
if (!collection)
|
|
18645
|
+
return;
|
|
18646
|
+
communityMembers.forEach(communityMember => {
|
|
18647
|
+
const communityMemberCacheId = getResolver('communityUsers')({
|
|
18648
|
+
communityId: this.query.communityId,
|
|
18649
|
+
userId: communityMember.userId,
|
|
18650
|
+
});
|
|
18651
|
+
if (communityMember.communityMembership === 'none') {
|
|
18652
|
+
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
18653
|
+
}
|
|
18654
|
+
else if (!collection.data.includes(communityMemberCacheId)) {
|
|
18655
|
+
collection.data = [communityMemberCacheId, ...collection.data];
|
|
18656
|
+
}
|
|
18657
|
+
});
|
|
18658
|
+
pushToCache(this.cacheKey, collection);
|
|
18659
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
18660
|
+
};
|
|
18661
|
+
}
|
|
18662
|
+
subscribeRTE(createSubscriber) {
|
|
18663
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
18664
|
+
}
|
|
18665
|
+
}
|
|
19465
18666
|
|
|
19466
18667
|
function hasPermission(member, payload, permission) {
|
|
19467
18668
|
if (member.permissions.some(x => x === permission)) {
|
|
@@ -19664,361 +18865,96 @@ const onCommunityUserUnbanned = (callback) => createCommunityMemberEventSubscrib
|
|
|
19664
18865
|
*
|
|
19665
18866
|
* @category Community Events
|
|
19666
18867
|
*/
|
|
19667
|
-
const onCommunityUserRoleAdded = (callback) => createCommunityMemberEventSubscriber('community.roleAdded', callback);
|
|
19668
|
-
|
|
19669
|
-
/**
|
|
19670
|
-
* ```js
|
|
19671
|
-
* import { onCommunityUserRoleRemoved } from '@amityco/ts-sdk-react-native'
|
|
19672
|
-
* const dispose = onCommunityUserRoleRemoved((community, member) => {
|
|
19673
|
-
* // ...
|
|
19674
|
-
* })
|
|
19675
|
-
* ```
|
|
19676
|
-
*
|
|
19677
|
-
* Fired when a role has been removed from {@link Amity.CommunityUser}
|
|
19678
|
-
*
|
|
19679
|
-
* @param callback The function to call when the event was fired
|
|
19680
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19681
|
-
*
|
|
19682
|
-
* @category Community Events
|
|
19683
|
-
*/
|
|
19684
|
-
const onCommunityUserRoleRemoved = (callback) => createCommunityMemberEventSubscriber('community.roleRemoved', callback);
|
|
19685
|
-
|
|
19686
|
-
/**
|
|
19687
|
-
* ```js
|
|
19688
|
-
* import { onLocalCommunityUserAdded } from '@amityco/ts-sdk-react-native'
|
|
19689
|
-
* const dispose = onLocalCommunityUserAdded((community, member) => {
|
|
19690
|
-
* // ...
|
|
19691
|
-
* })
|
|
19692
|
-
* ```
|
|
19693
|
-
*
|
|
19694
|
-
* Fired when a user has been added to a {@link Amity.Community}
|
|
19695
|
-
*
|
|
19696
|
-
* @param callback The function to call when the event was fired
|
|
19697
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19698
|
-
*
|
|
19699
|
-
* @category Community Events
|
|
19700
|
-
*/
|
|
19701
|
-
const onLocalCommunityUserAdded = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userAdded', callback);
|
|
19702
|
-
|
|
19703
|
-
/**
|
|
19704
|
-
* ```js
|
|
19705
|
-
* import { onLocalCommunityUserRemoved } from '@amityco/ts-sdk-react-native'
|
|
19706
|
-
* const dispose = onLocalCommunityUserRemoved((community, member) => {
|
|
19707
|
-
* // ...
|
|
19708
|
-
* })
|
|
19709
|
-
* ```
|
|
19710
|
-
*
|
|
19711
|
-
* Fired when a user has been removed from a {@link Amity.Community}
|
|
19712
|
-
*
|
|
19713
|
-
* @param callback The function to call when the event was fired
|
|
19714
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19715
|
-
*
|
|
19716
|
-
* @category Community Events
|
|
19717
|
-
*/
|
|
19718
|
-
const onLocalCommunityUserRemoved = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userRemoved', callback);
|
|
19719
|
-
|
|
19720
|
-
/**
|
|
19721
|
-
* ```js
|
|
19722
|
-
* import { onCommunityJoined } from '@amityco/ts-sdk-react-native'
|
|
19723
|
-
* const dispose = onCommunityJoined((community, member) => {
|
|
19724
|
-
* // ...
|
|
19725
|
-
* })
|
|
19726
|
-
* ```
|
|
19727
|
-
*
|
|
19728
|
-
* Fired when a {@link Amity.Community} has been joined
|
|
19729
|
-
*
|
|
19730
|
-
* @param callback The function to call when the event was fired
|
|
19731
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19732
|
-
*
|
|
19733
|
-
* @category Community Events
|
|
19734
|
-
*/
|
|
19735
|
-
const onCommunityJoined = (callback) => createCommunityMemberEventSubscriber('community.joined', callback);
|
|
18868
|
+
const onCommunityUserRoleAdded = (callback) => createCommunityMemberEventSubscriber('community.roleAdded', callback);
|
|
19736
18869
|
|
|
19737
18870
|
/**
|
|
19738
18871
|
* ```js
|
|
19739
|
-
* import {
|
|
19740
|
-
* const dispose =
|
|
18872
|
+
* import { onCommunityUserRoleRemoved } from '@amityco/ts-sdk-react-native'
|
|
18873
|
+
* const dispose = onCommunityUserRoleRemoved((community, member) => {
|
|
19741
18874
|
* // ...
|
|
19742
18875
|
* })
|
|
19743
18876
|
* ```
|
|
19744
18877
|
*
|
|
19745
|
-
* Fired when a {@link Amity.
|
|
18878
|
+
* Fired when a role has been removed from {@link Amity.CommunityUser}
|
|
19746
18879
|
*
|
|
19747
18880
|
* @param callback The function to call when the event was fired
|
|
19748
18881
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19749
18882
|
*
|
|
19750
18883
|
* @category Community Events
|
|
19751
18884
|
*/
|
|
19752
|
-
const
|
|
19753
|
-
|
|
19754
|
-
const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubscriber('local.community.joined', callback);
|
|
19755
|
-
|
|
19756
|
-
const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
|
|
18885
|
+
const onCommunityUserRoleRemoved = (callback) => createCommunityMemberEventSubscriber('community.roleRemoved', callback);
|
|
19757
18886
|
|
|
19758
18887
|
/**
|
|
19759
18888
|
* ```js
|
|
19760
|
-
* import {
|
|
19761
|
-
*
|
|
19762
|
-
*
|
|
19763
|
-
*
|
|
18889
|
+
* import { onLocalCommunityUserAdded } from '@amityco/ts-sdk-react-native'
|
|
18890
|
+
* const dispose = onLocalCommunityUserAdded((community, member) => {
|
|
18891
|
+
* // ...
|
|
18892
|
+
* })
|
|
19764
18893
|
* ```
|
|
19765
18894
|
*
|
|
19766
|
-
*
|
|
18895
|
+
* Fired when a user has been added to a {@link Amity.Community}
|
|
19767
18896
|
*
|
|
19768
|
-
* @param
|
|
19769
|
-
* @
|
|
19770
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community
|
|
18897
|
+
* @param callback The function to call when the event was fired
|
|
18898
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19771
18899
|
*
|
|
19772
|
-
* @category Community
|
|
19773
|
-
*/
|
|
19774
|
-
const observeCommunity = (communityId, callback) => {
|
|
19775
|
-
const { log } = getActiveClient();
|
|
19776
|
-
const timestamp = Date.now();
|
|
19777
|
-
log(`observeCommunity(tmpid: ${timestamp}) > listen`);
|
|
19778
|
-
// wrapper function to make sure
|
|
19779
|
-
const router = (result, action) => {
|
|
19780
|
-
var _a, _b;
|
|
19781
|
-
if (callback instanceof Function)
|
|
19782
|
-
return callback(result);
|
|
19783
|
-
if (action !== 'onFetch')
|
|
19784
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
19785
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
19786
|
-
};
|
|
19787
|
-
const realtimeRouter = (result, action) => {
|
|
19788
|
-
var _a;
|
|
19789
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.communityId) !== communityId)
|
|
19790
|
-
return;
|
|
19791
|
-
router(result, action);
|
|
19792
|
-
};
|
|
19793
|
-
const disposers = [];
|
|
19794
|
-
disposers.push(onCommunityUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onCommunityDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')), onCommunityJoined(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onJoin')), onCommunityLeft(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onLeft')), onCommunityUserAdded(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUserAdded')), onCommunityUserRemoved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUserRemoved')), onCommunityUserBanned(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUserBanned')), onCommunityUserUnbanned(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUserUnbanned')));
|
|
19795
|
-
runQuery(createQuery(getCommunity$1, communityId), result => (result.data || result.error) && router(result, 'onFetch'));
|
|
19796
|
-
return () => {
|
|
19797
|
-
log(`observeCommunity(tmpid: ${timestamp}) > dispose`);
|
|
19798
|
-
disposers.forEach(fn => fn());
|
|
19799
|
-
};
|
|
19800
|
-
};
|
|
19801
|
-
|
|
19802
|
-
/**
|
|
19803
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
19804
|
-
* TODO: check if querybyIds is supported
|
|
18900
|
+
* @category Community Events
|
|
19805
18901
|
*/
|
|
19806
|
-
|
|
19807
|
-
async getRequest(queryParams, token) {
|
|
19808
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
19809
|
-
const options = token ? { token } : { limit };
|
|
19810
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
19811
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
19812
|
-
});
|
|
19813
|
-
return queryResponse;
|
|
19814
|
-
}
|
|
19815
|
-
}
|
|
19816
|
-
|
|
19817
|
-
class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
19818
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
19819
|
-
super(query, cacheKey);
|
|
19820
|
-
this.notifyChange = notifyChange;
|
|
19821
|
-
this.preparePayload = preparePayload;
|
|
19822
|
-
}
|
|
19823
|
-
async saveToMainDB(response) {
|
|
19824
|
-
const processedPayload = await this.preparePayload(response);
|
|
19825
|
-
const client = getActiveClient();
|
|
19826
|
-
const cachedAt = client.cache && Date.now();
|
|
19827
|
-
if (client.cache) {
|
|
19828
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
19829
|
-
}
|
|
19830
|
-
}
|
|
19831
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
19832
|
-
var _a, _b;
|
|
19833
|
-
if (refresh) {
|
|
19834
|
-
pushToCache(this.cacheKey, {
|
|
19835
|
-
data: response.communities.map(getResolver('community')),
|
|
19836
|
-
});
|
|
19837
|
-
}
|
|
19838
|
-
else {
|
|
19839
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19840
|
-
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
19841
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
19842
|
-
}
|
|
19843
|
-
}
|
|
19844
|
-
reactor(action) {
|
|
19845
|
-
return (community) => {
|
|
19846
|
-
var _a;
|
|
19847
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19848
|
-
if (!collection)
|
|
19849
|
-
return;
|
|
19850
|
-
pushToCache(this.cacheKey, collection);
|
|
19851
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
19852
|
-
};
|
|
19853
|
-
}
|
|
19854
|
-
subscribeRTE(createSubscriber) {
|
|
19855
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
19856
|
-
}
|
|
19857
|
-
}
|
|
19858
|
-
|
|
19859
|
-
var EnumCommunityActions$4;
|
|
19860
|
-
(function (EnumCommunityActions) {
|
|
19861
|
-
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
19862
|
-
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
19863
|
-
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
19864
|
-
})(EnumCommunityActions$4 || (EnumCommunityActions$4 = {}));
|
|
19865
|
-
|
|
19866
|
-
var EnumCommunityMemberActions$1;
|
|
19867
|
-
(function (EnumCommunityMemberActions) {
|
|
19868
|
-
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
19869
|
-
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
19870
|
-
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
19871
|
-
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
19872
|
-
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
19873
|
-
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
19874
|
-
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
19875
|
-
EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
|
|
19876
|
-
EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
|
|
19877
|
-
EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
|
|
19878
|
-
EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
|
|
19879
|
-
})(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
|
|
18902
|
+
const onLocalCommunityUserAdded = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userAdded', callback);
|
|
19880
18903
|
|
|
19881
|
-
/* begin_public_function
|
|
19882
|
-
id: community.membership.add_members
|
|
19883
|
-
*/
|
|
19884
18904
|
/**
|
|
19885
18905
|
* ```js
|
|
19886
|
-
* import {
|
|
19887
|
-
* const
|
|
18906
|
+
* import { onLocalCommunityUserRemoved } from '@amityco/ts-sdk-react-native'
|
|
18907
|
+
* const dispose = onLocalCommunityUserRemoved((community, member) => {
|
|
18908
|
+
* // ...
|
|
18909
|
+
* })
|
|
19888
18910
|
* ```
|
|
19889
18911
|
*
|
|
19890
|
-
*
|
|
18912
|
+
* Fired when a user has been removed from a {@link Amity.Community}
|
|
19891
18913
|
*
|
|
19892
|
-
* @param
|
|
19893
|
-
* @
|
|
19894
|
-
* @returns A success boolean if the {@link Amity.InternalUser} were added to the {@link Amity.Community}
|
|
18914
|
+
* @param callback The function to call when the event was fired
|
|
18915
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19895
18916
|
*
|
|
19896
|
-
* @category Community
|
|
19897
|
-
* @async
|
|
18917
|
+
* @category Community Events
|
|
19898
18918
|
*/
|
|
19899
|
-
const
|
|
19900
|
-
const client = getActiveClient();
|
|
19901
|
-
client.log('community/moderation/addMembers', communityId, userIds);
|
|
19902
|
-
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
19903
|
-
fireEvent('local.community.userAdded', payload);
|
|
19904
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
19905
|
-
if (client.cache)
|
|
19906
|
-
ingestInCache(data);
|
|
19907
|
-
const { communityUsers } = data;
|
|
19908
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
19909
|
-
};
|
|
19910
|
-
/* end_public_function */
|
|
18919
|
+
const onLocalCommunityUserRemoved = (callback) => createLocalCommunityMemberEventSubscriber('local.community.userRemoved', callback);
|
|
19911
18920
|
|
|
19912
|
-
/* begin_public_function
|
|
19913
|
-
id: community.membership.remove_member
|
|
19914
|
-
*/
|
|
19915
18921
|
/**
|
|
19916
18922
|
* ```js
|
|
19917
|
-
* import {
|
|
19918
|
-
* const
|
|
18923
|
+
* import { onCommunityJoined } from '@amityco/ts-sdk-react-native'
|
|
18924
|
+
* const dispose = onCommunityJoined((community, member) => {
|
|
18925
|
+
* // ...
|
|
18926
|
+
* })
|
|
19919
18927
|
* ```
|
|
19920
18928
|
*
|
|
19921
|
-
*
|
|
18929
|
+
* Fired when a {@link Amity.Community} has been joined
|
|
19922
18930
|
*
|
|
19923
|
-
* @param
|
|
19924
|
-
* @
|
|
19925
|
-
* @returns A success boolean if the list of {@link Amity.InternalUser} were removed from the {@link Amity.Community}
|
|
18931
|
+
* @param callback The function to call when the event was fired
|
|
18932
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19926
18933
|
*
|
|
19927
|
-
* @category Community
|
|
19928
|
-
* @async
|
|
18934
|
+
* @category Community Events
|
|
19929
18935
|
*/
|
|
19930
|
-
const
|
|
19931
|
-
const client = getActiveClient();
|
|
19932
|
-
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
19933
|
-
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
19934
|
-
fireEvent('local.community.userRemoved', payload);
|
|
19935
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
19936
|
-
if (client.cache)
|
|
19937
|
-
ingestInCache(data);
|
|
19938
|
-
const { communityUsers } = data;
|
|
19939
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
19940
|
-
};
|
|
19941
|
-
/* end_public_function */
|
|
18936
|
+
const onCommunityJoined = (callback) => createCommunityMemberEventSubscriber('community.joined', callback);
|
|
19942
18937
|
|
|
19943
18938
|
/**
|
|
19944
|
-
*
|
|
19945
|
-
*
|
|
19946
|
-
|
|
19947
|
-
|
|
19948
|
-
|
|
19949
|
-
|
|
19950
|
-
|
|
19951
|
-
|
|
19952
|
-
|
|
19953
|
-
|
|
19954
|
-
|
|
19955
|
-
|
|
19956
|
-
|
|
19957
|
-
|
|
19958
|
-
|
|
19959
|
-
|
|
19960
|
-
|
|
19961
|
-
|
|
19962
|
-
|
|
19963
|
-
this.notifyChange = notifyChange;
|
|
19964
|
-
this.preparePayload = preparePayload;
|
|
19965
|
-
}
|
|
19966
|
-
async saveToMainDB(response) {
|
|
19967
|
-
const processedPayload = await this.preparePayload(response);
|
|
19968
|
-
const client = getActiveClient();
|
|
19969
|
-
const cachedAt = client.cache && Date.now();
|
|
19970
|
-
if (client.cache) {
|
|
19971
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
19972
|
-
}
|
|
19973
|
-
}
|
|
19974
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
19975
|
-
var _a, _b;
|
|
19976
|
-
if (refresh) {
|
|
19977
|
-
pushToCache(this.cacheKey, {
|
|
19978
|
-
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
19979
|
-
});
|
|
19980
|
-
}
|
|
19981
|
-
else {
|
|
19982
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19983
|
-
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
19984
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
19985
|
-
...new Set([
|
|
19986
|
-
...communityUsers,
|
|
19987
|
-
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
19988
|
-
]),
|
|
19989
|
-
] }));
|
|
19990
|
-
}
|
|
19991
|
-
}
|
|
19992
|
-
reactor(action) {
|
|
19993
|
-
return (community, communityMembers) => {
|
|
19994
|
-
var _a;
|
|
19995
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19996
|
-
if (!collection)
|
|
19997
|
-
return;
|
|
19998
|
-
if (action === EnumCommunityMemberActions$1.OnCommunityUserRoleAdded &&
|
|
19999
|
-
this.query.sortBy === 'displayName') {
|
|
20000
|
-
return;
|
|
20001
|
-
}
|
|
20002
|
-
communityMembers.forEach(communityMember => {
|
|
20003
|
-
const communityMemberCacheId = getResolver('communityUsers')({
|
|
20004
|
-
communityId: this.query.communityId,
|
|
20005
|
-
userId: communityMember.userId,
|
|
20006
|
-
});
|
|
20007
|
-
if (communityMember.communityMembership === 'none') {
|
|
20008
|
-
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
20009
|
-
}
|
|
20010
|
-
else if (!collection.data.includes(communityMemberCacheId)) {
|
|
20011
|
-
collection.data = [communityMemberCacheId, ...collection.data];
|
|
20012
|
-
}
|
|
20013
|
-
});
|
|
20014
|
-
pushToCache(this.cacheKey, collection);
|
|
20015
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
20016
|
-
};
|
|
20017
|
-
}
|
|
20018
|
-
subscribeRTE(createSubscriber) {
|
|
20019
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
20020
|
-
}
|
|
20021
|
-
}
|
|
18939
|
+
* ```js
|
|
18940
|
+
* import { onCommunityLeft } from '@amityco/ts-sdk-react-native'
|
|
18941
|
+
* const dispose = onCommunityLeft((community, member) => {
|
|
18942
|
+
* // ...
|
|
18943
|
+
* })
|
|
18944
|
+
* ```
|
|
18945
|
+
*
|
|
18946
|
+
* Fired when a {@link Amity.Community} has been left
|
|
18947
|
+
*
|
|
18948
|
+
* @param callback The function to call when the event was fired
|
|
18949
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18950
|
+
*
|
|
18951
|
+
* @category Community Events
|
|
18952
|
+
*/
|
|
18953
|
+
const onCommunityLeft = (callback) => createCommunityMemberEventSubscriber('community.left', callback);
|
|
18954
|
+
|
|
18955
|
+
const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubscriber('local.community.joined', callback);
|
|
18956
|
+
|
|
18957
|
+
const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
|
|
20022
18958
|
|
|
20023
18959
|
/**
|
|
20024
18960
|
* ```js
|
|
@@ -20197,9 +19133,6 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
20197
19133
|
return memberships.includes(communityMembership);
|
|
20198
19134
|
});
|
|
20199
19135
|
}
|
|
20200
|
-
if (this.query.search) {
|
|
20201
|
-
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
20202
|
-
}
|
|
20203
19136
|
if (this.query.includeDeleted === false) {
|
|
20204
19137
|
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
|
|
20205
19138
|
}
|
|
@@ -20207,15 +19140,6 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
20207
19140
|
case 'firstCreated':
|
|
20208
19141
|
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
20209
19142
|
break;
|
|
20210
|
-
case 'displayName':
|
|
20211
|
-
communityMembers = communityMembers.sort((a, b) => {
|
|
20212
|
-
var _a, _b, _c, _d;
|
|
20213
|
-
if (((_a = a === null || a === void 0 ? void 0 : a.user) === null || _a === void 0 ? void 0 : _a.displayName) && ((_b = b === null || b === void 0 ? void 0 : b.user) === null || _b === void 0 ? void 0 : _b.displayName)) {
|
|
20214
|
-
return (_c = a === null || a === void 0 ? void 0 : a.user) === null || _c === void 0 ? void 0 : _c.displayName.localeCompare((_d = b === null || b === void 0 ? void 0 : b.user) === null || _d === void 0 ? void 0 : _d.displayName);
|
|
20215
|
-
}
|
|
20216
|
-
return 0;
|
|
20217
|
-
});
|
|
20218
|
-
break;
|
|
20219
19143
|
case 'lastCreated':
|
|
20220
19144
|
default:
|
|
20221
19145
|
communityMembers = communityMembers.sort(sortByLastCreated);
|
|
@@ -20237,9 +19161,6 @@ const applyFilter = (data, params) => {
|
|
|
20237
19161
|
return membership.includes(communityMembership);
|
|
20238
19162
|
});
|
|
20239
19163
|
}
|
|
20240
|
-
if (params.search) {
|
|
20241
|
-
communityMembers = filterBySearchTerm(communityMembers, params.search);
|
|
20242
|
-
}
|
|
20243
19164
|
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
20244
19165
|
communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
20245
19166
|
return communityMembers;
|
|
@@ -20648,19 +19569,12 @@ class CommunitiesPaginationController extends PaginationController {
|
|
|
20648
19569
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
20649
19570
|
const options = token ? { token } : { limit };
|
|
20650
19571
|
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
20651
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted),
|
|
19572
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), filter: params.membership, options }),
|
|
20652
19573
|
});
|
|
20653
19574
|
return queryResponse;
|
|
20654
19575
|
}
|
|
20655
19576
|
}
|
|
20656
19577
|
|
|
20657
|
-
var EnumCommunityActions$3;
|
|
20658
|
-
(function (EnumCommunityActions) {
|
|
20659
|
-
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
20660
|
-
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
20661
|
-
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
20662
|
-
})(EnumCommunityActions$3 || (EnumCommunityActions$3 = {}));
|
|
20663
|
-
|
|
20664
19578
|
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
20665
19579
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
20666
19580
|
super(query, cacheKey);
|
|
@@ -20695,9 +19609,6 @@ class CommunitiesQueryStreamController extends QueryStreamController {
|
|
|
20695
19609
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20696
19610
|
if (!collection)
|
|
20697
19611
|
return;
|
|
20698
|
-
if (this.query.displayName && action === EnumCommunityActions$3.OnCommunityCreated) {
|
|
20699
|
-
return;
|
|
20700
|
-
}
|
|
20701
19612
|
/*
|
|
20702
19613
|
* Simply update a collection and let responder decide what to do with data
|
|
20703
19614
|
*/
|
|
@@ -20711,6 +19622,13 @@ class CommunitiesQueryStreamController extends QueryStreamController {
|
|
|
20711
19622
|
}
|
|
20712
19623
|
}
|
|
20713
19624
|
|
|
19625
|
+
var EnumCommunityActions$3;
|
|
19626
|
+
(function (EnumCommunityActions) {
|
|
19627
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
19628
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
19629
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
19630
|
+
})(EnumCommunityActions$3 || (EnumCommunityActions$3 = {}));
|
|
19631
|
+
|
|
20714
19632
|
class CommunityLiveCollectionController extends LiveCollectionController {
|
|
20715
19633
|
constructor(query, callback) {
|
|
20716
19634
|
const queryStreamId = hash__default["default"](query);
|
|
@@ -20784,21 +19702,17 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
20784
19702
|
if (this.query.membership && userId) {
|
|
20785
19703
|
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
20786
19704
|
}
|
|
20787
|
-
|
|
20788
|
-
|
|
20789
|
-
|
|
20790
|
-
|
|
20791
|
-
|
|
20792
|
-
|
|
20793
|
-
|
|
20794
|
-
|
|
20795
|
-
|
|
20796
|
-
|
|
20797
|
-
|
|
20798
|
-
}
|
|
20799
|
-
})();
|
|
20800
|
-
communities = communities.sort(sortFn);
|
|
20801
|
-
}
|
|
19705
|
+
const sortFn = (() => {
|
|
19706
|
+
switch (this.query.sortBy) {
|
|
19707
|
+
case 'firstCreated':
|
|
19708
|
+
return sortByFirstCreated;
|
|
19709
|
+
case 'lastCreated':
|
|
19710
|
+
return sortByLastCreated;
|
|
19711
|
+
default:
|
|
19712
|
+
return sortByLastCreated;
|
|
19713
|
+
}
|
|
19714
|
+
})();
|
|
19715
|
+
communities = communities.sort(sortFn);
|
|
20802
19716
|
return communities;
|
|
20803
19717
|
}
|
|
20804
19718
|
}
|
|
@@ -21552,11 +20466,9 @@ var index$9 = /*#__PURE__*/Object.freeze({
|
|
|
21552
20466
|
deleteCommunity: deleteCommunity,
|
|
21553
20467
|
joinCommunity: joinCommunity,
|
|
21554
20468
|
leaveCommunity: leaveCommunity,
|
|
21555
|
-
getTopTrendingCommunities: getTopTrendingCommunities,
|
|
21556
20469
|
onCommunityCreated: onCommunityCreated,
|
|
21557
20470
|
onCommunityUpdated: onCommunityUpdated,
|
|
21558
20471
|
onCommunityDeleted: onCommunityDeleted,
|
|
21559
|
-
observeCommunity: observeCommunity,
|
|
21560
20472
|
searchCommunities: searchCommunities,
|
|
21561
20473
|
getCommunities: getCommunities,
|
|
21562
20474
|
getCommunity: getCommunity,
|
|
@@ -21806,21 +20718,10 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
21806
20718
|
const queryGlobalFeed = async (query) => {
|
|
21807
20719
|
const client = getActiveClient();
|
|
21808
20720
|
client.log('feed/queryGlobalFeed', query);
|
|
21809
|
-
const _a = query !== null && query !== void 0 ? query : {}, {
|
|
21810
|
-
/*
|
|
21811
|
-
* TODO: Remove useCustomRanking key from query
|
|
21812
|
-
*/
|
|
21813
|
-
if (useCustomRanking)
|
|
21814
|
-
console.warn('The param "useCustomRanking" has been deprecated. To get custom ranking feed use FeedRepository.getCustomRankingGlobalFeed instead');
|
|
21815
|
-
if (page)
|
|
21816
|
-
console.warn('The param "page" has been deprecated. Please use "queryToken" instead.');
|
|
20721
|
+
const _a = query !== null && query !== void 0 ? query : {}, { queryToken } = _a, params = __rest(_a, ["queryToken"]);
|
|
21817
20722
|
const options = (() => {
|
|
21818
20723
|
if (queryToken)
|
|
21819
20724
|
return { token: queryToken };
|
|
21820
|
-
if (page)
|
|
21821
|
-
return {
|
|
21822
|
-
token: toToken(page, 'skiplimit'),
|
|
21823
|
-
};
|
|
21824
20725
|
return undefined;
|
|
21825
20726
|
})();
|
|
21826
20727
|
const { data: queryPayload } = await client.http.get(`/api/v4/me/global-feeds`, {
|
|
@@ -21833,20 +20734,12 @@ const queryGlobalFeed = async (query) => {
|
|
|
21833
20734
|
const cachedAt = client.cache && Date.now();
|
|
21834
20735
|
if (client.cache) {
|
|
21835
20736
|
ingestInCache(Object.assign(Object.assign({}, data), { communitis: processedCommunity }));
|
|
21836
|
-
const cacheKey = [
|
|
21837
|
-
'globalFeed',
|
|
21838
|
-
'query',
|
|
21839
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
21840
|
-
];
|
|
20737
|
+
const cacheKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
21841
20738
|
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
21842
20739
|
}
|
|
21843
|
-
const nextPage = toPage(paging.next);
|
|
21844
|
-
const prevPage = toPage(paging.previous);
|
|
21845
20740
|
return {
|
|
21846
20741
|
data: posts.map(LinkedObject.post),
|
|
21847
20742
|
cachedAt,
|
|
21848
|
-
prevPage,
|
|
21849
|
-
nextPage,
|
|
21850
20743
|
paging,
|
|
21851
20744
|
};
|
|
21852
20745
|
};
|
|
@@ -21871,12 +20764,8 @@ queryGlobalFeed.locally = (query) => {
|
|
|
21871
20764
|
client.log('post/queryGlobalFeed.locally', query);
|
|
21872
20765
|
if (!client.cache)
|
|
21873
20766
|
return;
|
|
21874
|
-
const
|
|
21875
|
-
const queryKey = [
|
|
21876
|
-
'globalFeed',
|
|
21877
|
-
'query',
|
|
21878
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
21879
|
-
];
|
|
20767
|
+
const params = __rest(query !== null && query !== void 0 ? query : {}, []);
|
|
20768
|
+
const queryKey = ['globalFeed', 'query', Object.assign({}, params)];
|
|
21880
20769
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
21881
20770
|
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
21882
20771
|
return;
|
|
@@ -21886,14 +20775,10 @@ queryGlobalFeed.locally = (query) => {
|
|
|
21886
20775
|
.map(({ data }) => data)
|
|
21887
20776
|
.map(LinkedObject.post);
|
|
21888
20777
|
const { paging } = data;
|
|
21889
|
-
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
21890
|
-
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
21891
20778
|
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
21892
20779
|
? {
|
|
21893
20780
|
data: posts,
|
|
21894
20781
|
cachedAt,
|
|
21895
|
-
prevPage,
|
|
21896
|
-
nextPage,
|
|
21897
20782
|
paging,
|
|
21898
20783
|
}
|
|
21899
20784
|
: undefined;
|
|
@@ -21919,14 +20804,10 @@ queryGlobalFeed.locally = (query) => {
|
|
|
21919
20804
|
const getCustomRankingGlobalFeed = async (query) => {
|
|
21920
20805
|
const client = getActiveClient();
|
|
21921
20806
|
client.log('feed/getCustomRankingGlobalFeed', query);
|
|
21922
|
-
const _a = query !== null && query !== void 0 ? query : {}, {
|
|
20807
|
+
const _a = query !== null && query !== void 0 ? query : {}, { queryToken, limit } = _a, params = __rest(_a, ["queryToken", "limit"]);
|
|
21923
20808
|
const options = (() => {
|
|
21924
20809
|
if (queryToken)
|
|
21925
20810
|
return { token: queryToken };
|
|
21926
|
-
if (page)
|
|
21927
|
-
return {
|
|
21928
|
-
token: toToken(page, 'skiplimit'),
|
|
21929
|
-
};
|
|
21930
20811
|
return undefined;
|
|
21931
20812
|
})();
|
|
21932
20813
|
const { data: queryPayload } = await client.http.get(`/api/v5/me/global-feeds`, {
|
|
@@ -21938,16 +20819,10 @@ const getCustomRankingGlobalFeed = async (query) => {
|
|
|
21938
20819
|
const cachedAt = client.cache && Date.now();
|
|
21939
20820
|
if (client.cache) {
|
|
21940
20821
|
ingestInCache(data);
|
|
21941
|
-
const cacheKey = [
|
|
21942
|
-
'customGlobalFeed',
|
|
21943
|
-
'query',
|
|
21944
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
21945
|
-
];
|
|
20822
|
+
const cacheKey = ['customGlobalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
21946
20823
|
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
21947
20824
|
}
|
|
21948
|
-
|
|
21949
|
-
const prevPage = toPage(paging.previous);
|
|
21950
|
-
return { data: posts.map(LinkedObject.post), cachedAt, prevPage, nextPage, paging };
|
|
20825
|
+
return { data: posts.map(LinkedObject.post), cachedAt, paging };
|
|
21951
20826
|
};
|
|
21952
20827
|
/* end_public_function */
|
|
21953
20828
|
/**
|
|
@@ -21970,12 +20845,8 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
21970
20845
|
client.log('post/getCustomRankingGlobalFeed.locally', query);
|
|
21971
20846
|
if (!client.cache)
|
|
21972
20847
|
return;
|
|
21973
|
-
const
|
|
21974
|
-
const queryKey = [
|
|
21975
|
-
'customGlobalFeed',
|
|
21976
|
-
'query',
|
|
21977
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
21978
|
-
];
|
|
20848
|
+
const params = __rest(query !== null && query !== void 0 ? query : {}, []);
|
|
20849
|
+
const queryKey = ['customGlobalFeed', 'query', Object.assign({}, params)];
|
|
21979
20850
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
21980
20851
|
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
21981
20852
|
return;
|
|
@@ -21983,11 +20854,9 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
21983
20854
|
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
21984
20855
|
.filter(Boolean)
|
|
21985
20856
|
.map(({ data }) => data);
|
|
21986
|
-
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
21987
|
-
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
21988
20857
|
const { paging } = data;
|
|
21989
20858
|
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
21990
|
-
? { data: posts.map(LinkedObject.post), cachedAt,
|
|
20859
|
+
? { data: posts.map(LinkedObject.post), cachedAt, paging }
|
|
21991
20860
|
: undefined;
|
|
21992
20861
|
};
|
|
21993
20862
|
|
|
@@ -22118,44 +20987,6 @@ const createPost = async (bundle) => {
|
|
|
22118
20987
|
};
|
|
22119
20988
|
/* end_public_function */
|
|
22120
20989
|
|
|
22121
|
-
/* begin_public_function
|
|
22122
|
-
id: post.edit
|
|
22123
|
-
*/
|
|
22124
|
-
/**
|
|
22125
|
-
* ```js
|
|
22126
|
-
* import { updatePost } from '@amityco/ts-sdk-react-native'
|
|
22127
|
-
* const updated = await updatePost(postId, {
|
|
22128
|
-
* data: { text: 'hello world' }
|
|
22129
|
-
* })
|
|
22130
|
-
* ```
|
|
22131
|
-
*
|
|
22132
|
-
* Updates an {@link Amity.Post}
|
|
22133
|
-
*
|
|
22134
|
-
* @param postId The ID of the {@link Amity.Post} to edit
|
|
22135
|
-
* @param patch The patch data to apply
|
|
22136
|
-
* @returns the updated {@link Amity.Post} object
|
|
22137
|
-
*
|
|
22138
|
-
* @category Post API
|
|
22139
|
-
* @async
|
|
22140
|
-
*/
|
|
22141
|
-
const updatePost = async (postId, patch) => {
|
|
22142
|
-
const client = getActiveClient();
|
|
22143
|
-
client.log('user/updatePost', patch);
|
|
22144
|
-
console.warn('Deprecation: updatePost has been renamed to editPost. Update post API will be deprecated soon.');
|
|
22145
|
-
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
|
|
22146
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
22147
|
-
const cachedAt = client.cache && Date.now();
|
|
22148
|
-
if (client.cache)
|
|
22149
|
-
ingestInCache(data, { cachedAt });
|
|
22150
|
-
fireEvent('local.post.updated', payload);
|
|
22151
|
-
const { posts } = data;
|
|
22152
|
-
return {
|
|
22153
|
-
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
22154
|
-
cachedAt,
|
|
22155
|
-
};
|
|
22156
|
-
};
|
|
22157
|
-
/* end_public_function */
|
|
22158
|
-
|
|
22159
20990
|
/* begin_public_function
|
|
22160
20991
|
id: post.edit, post.edit.custom_post
|
|
22161
20992
|
*/
|
|
@@ -22473,91 +21304,6 @@ const isPostFlaggedByMe = async (postId) => {
|
|
|
22473
21304
|
};
|
|
22474
21305
|
/* end_public_function */
|
|
22475
21306
|
|
|
22476
|
-
/**
|
|
22477
|
-
* ```js
|
|
22478
|
-
* import { PostRepository } from '@amityco/ts-sdk-react-native'
|
|
22479
|
-
*
|
|
22480
|
-
* let posts = []
|
|
22481
|
-
* const unsub = PostRepository.observePosts({
|
|
22482
|
-
* targetType: Amity.PostTargetType,
|
|
22483
|
-
* targetId: Amity.InternalPost['targetId'],
|
|
22484
|
-
* }, post => merge(posts, post))
|
|
22485
|
-
* ```
|
|
22486
|
-
*
|
|
22487
|
-
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
22488
|
-
*
|
|
22489
|
-
* @param params
|
|
22490
|
-
* @param callback the function to call when new data are available
|
|
22491
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
22492
|
-
*
|
|
22493
|
-
* @category Post Observer
|
|
22494
|
-
*/
|
|
22495
|
-
const observePosts = (params, callback) => {
|
|
22496
|
-
const { log } = getActiveClient();
|
|
22497
|
-
const timestamp = Date.now();
|
|
22498
|
-
log(`observePosts(tmpid: ${timestamp}) > listen`);
|
|
22499
|
-
const disposers = [];
|
|
22500
|
-
const router = (post, action) => {
|
|
22501
|
-
var _a, _b;
|
|
22502
|
-
if (params.targetId !== post.targetId || params.targetType !== post.targetType)
|
|
22503
|
-
return;
|
|
22504
|
-
if (callback instanceof Function)
|
|
22505
|
-
return callback(LinkedObject.post(post));
|
|
22506
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, LinkedObject.post(post));
|
|
22507
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, LinkedObject.post(post));
|
|
22508
|
-
};
|
|
22509
|
-
disposers.push(onPostCreated(post => router(post, 'onCreate')), onPostUpdated(post => router(post, 'onUpdate')), onPostDeleted(post => router(post, 'onDelete')), onPostApproved(post => router(post, 'onApproved')), onPostDeclined(post => router(post, 'onDeclined')), onPostFlagged(post => router(post, 'onFlagged')), onPostUnflagged(post => router(post, 'onUnflagged')), onPostReactionAdded(post => router(post, 'onReactionAdded')), onPostReactionRemoved(post => router(post, 'onReactionRemoved')));
|
|
22510
|
-
return () => {
|
|
22511
|
-
log(`observePosts(tmpid: ${timestamp}) > dispose`);
|
|
22512
|
-
disposers.forEach(fn => fn());
|
|
22513
|
-
};
|
|
22514
|
-
};
|
|
22515
|
-
|
|
22516
|
-
/**
|
|
22517
|
-
* ```js
|
|
22518
|
-
* import { observePost } from '@amityco/ts-sdk-react-native'
|
|
22519
|
-
*
|
|
22520
|
-
* let post = {}
|
|
22521
|
-
* const dispose = observePost(postId, updated => post = updated)
|
|
22522
|
-
* ```
|
|
22523
|
-
*
|
|
22524
|
-
* Observe all mutations on a given {@link Amity.Post}
|
|
22525
|
-
*
|
|
22526
|
-
* @param postId the ID of the post to observe
|
|
22527
|
-
* @param callback the function to call when new data are available
|
|
22528
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
|
|
22529
|
-
*
|
|
22530
|
-
* @category Post Observer
|
|
22531
|
-
*/
|
|
22532
|
-
const observePost = (postId, callback, policy = 'cache_then_server') => {
|
|
22533
|
-
const { log } = getActiveClient();
|
|
22534
|
-
const timestamp = Date.now();
|
|
22535
|
-
log(`observePost(tmpid: ${timestamp}) > listen`);
|
|
22536
|
-
// wrapper function to make sure
|
|
22537
|
-
const router = (result, action) => {
|
|
22538
|
-
var _a, _b;
|
|
22539
|
-
if (callback instanceof Function)
|
|
22540
|
-
return callback(result);
|
|
22541
|
-
if (action !== 'onFetch')
|
|
22542
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
22543
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
22544
|
-
};
|
|
22545
|
-
const realtimeRouter = (result, action) => {
|
|
22546
|
-
var _a;
|
|
22547
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.postId) !== postId)
|
|
22548
|
-
return;
|
|
22549
|
-
router(Object.assign(Object.assign({}, result), { data: result.data && LinkedObject.post(result.data) }), action);
|
|
22550
|
-
};
|
|
22551
|
-
const disposers = [];
|
|
22552
|
-
disposers.push(onPostUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPostDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')), onPostApproved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onApproved')), onPostDeclined(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDeclined')), onPostFlagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onFlagged')), onPostUnflagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUnflagged')), onPostReactionAdded(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionAdded')), onPostReactionRemoved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionRemoved')));
|
|
22553
|
-
runQuery(createQuery(getPost$2, postId), result => (result.data || result.error) &&
|
|
22554
|
-
router(Object.assign(Object.assign({}, result), { data: result.data && LinkedObject.post(result.data) }), 'onFetch'), queryOptions(policy));
|
|
22555
|
-
return () => {
|
|
22556
|
-
log(`observePosts(tmpid: ${timestamp}) > dispose`);
|
|
22557
|
-
disposers.forEach(fn => fn());
|
|
22558
|
-
};
|
|
22559
|
-
};
|
|
22560
|
-
|
|
22561
21307
|
/* begin_public_function
|
|
22562
21308
|
id: comment.get_by_ids
|
|
22563
21309
|
*/
|
|
@@ -23033,43 +21779,6 @@ const isCommentFlaggedByMe = async (commentId) => {
|
|
|
23033
21779
|
};
|
|
23034
21780
|
/* end_public_function */
|
|
23035
21781
|
|
|
23036
|
-
/**
|
|
23037
|
-
* ```js
|
|
23038
|
-
* import { observeComments } from '@amityco/ts-sdk-react-native'
|
|
23039
|
-
*
|
|
23040
|
-
* let comments = []
|
|
23041
|
-
* const unsub = observeComments(postId, comment => merge(comments, comment))
|
|
23042
|
-
* ```
|
|
23043
|
-
*
|
|
23044
|
-
* Observe all mutations on a list of {@link Amity.InternalComment} for a given {@link Amity.Post} object
|
|
23045
|
-
*
|
|
23046
|
-
* @param postId the ID of the post where to observe the comments
|
|
23047
|
-
* @param callback the function to call when new data are available
|
|
23048
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comments
|
|
23049
|
-
*
|
|
23050
|
-
* @category InternalComment Observer
|
|
23051
|
-
*/
|
|
23052
|
-
const observeComments = (postId, callback) => {
|
|
23053
|
-
const { log } = getActiveClient();
|
|
23054
|
-
const timestamp = Date.now();
|
|
23055
|
-
log(`observeComments(tmpid: ${timestamp}) > listen`);
|
|
23056
|
-
const disposers = [];
|
|
23057
|
-
const router = (comment, action) => {
|
|
23058
|
-
var _a, _b;
|
|
23059
|
-
if (comment.referenceId !== postId)
|
|
23060
|
-
return;
|
|
23061
|
-
if (callback instanceof Function)
|
|
23062
|
-
return callback(comment);
|
|
23063
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, comment);
|
|
23064
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, comment);
|
|
23065
|
-
};
|
|
23066
|
-
disposers.push(onCommentCreated(comment => router(comment, 'onCreate')), onCommentUpdated(comment => router(comment, 'onUpdate')), onCommentDeleted(comment => router(comment, 'onDelete')), onCommentFlagged(comment => router(comment, 'onFlagged')), onCommentUnflagged(comment => router(comment, 'onUnflagged')), onCommentReactionAdded(comment => router(comment, 'onReactionAdded')), onCommentReactionRemoved(comment => router(comment, 'onReactionRemoved')));
|
|
23067
|
-
return () => {
|
|
23068
|
-
log(`observeComments(tmpid: ${timestamp}) > dispose`);
|
|
23069
|
-
disposers.forEach(fn => fn());
|
|
23070
|
-
};
|
|
23071
|
-
};
|
|
23072
|
-
|
|
23073
21782
|
const getComment$1 = async (commentId) => {
|
|
23074
21783
|
const client = getActiveClient();
|
|
23075
21784
|
client.log('comment/getComment', commentId);
|
|
@@ -23109,50 +21818,6 @@ getComment$1.locally = (commentId) => {
|
|
|
23109
21818
|
};
|
|
23110
21819
|
};
|
|
23111
21820
|
|
|
23112
|
-
/**
|
|
23113
|
-
* ```js
|
|
23114
|
-
* import { observeComment } from '@amityco/ts-sdk-react-native'
|
|
23115
|
-
*
|
|
23116
|
-
* let comment = {}
|
|
23117
|
-
* const dispose = observeComment(commentId, ({ data }) => comment = data)
|
|
23118
|
-
* ```
|
|
23119
|
-
*
|
|
23120
|
-
* Observe all mutation on a given {@link Amity.InternalComment}
|
|
23121
|
-
*
|
|
23122
|
-
* @param commentId the ID of the comment to observe
|
|
23123
|
-
* @param callback the function to call when new data are available
|
|
23124
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
23125
|
-
*
|
|
23126
|
-
* @category InternalComment Observer
|
|
23127
|
-
*/
|
|
23128
|
-
const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
23129
|
-
const { log } = getActiveClient();
|
|
23130
|
-
const timestamp = Date.now();
|
|
23131
|
-
log(`observeComment(tmpid: ${timestamp}) > listen`);
|
|
23132
|
-
// wrapper function to make sure
|
|
23133
|
-
const router = (result, action) => {
|
|
23134
|
-
var _a, _b;
|
|
23135
|
-
if (callback instanceof Function)
|
|
23136
|
-
return callback(result);
|
|
23137
|
-
if (action !== 'onFetch')
|
|
23138
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
23139
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
23140
|
-
};
|
|
23141
|
-
const realtimeRouter = (result, action) => {
|
|
23142
|
-
var _a;
|
|
23143
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.commentId) !== commentId)
|
|
23144
|
-
return;
|
|
23145
|
-
router(result, action);
|
|
23146
|
-
};
|
|
23147
|
-
const disposers = [];
|
|
23148
|
-
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')));
|
|
23149
|
-
runQuery(createQuery(getComment$1, commentId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
23150
|
-
return () => {
|
|
23151
|
-
log(`observeComment(tmpid: ${timestamp}) > dispose`);
|
|
23152
|
-
disposers.forEach(fn => fn());
|
|
23153
|
-
};
|
|
23154
|
-
};
|
|
23155
|
-
|
|
23156
21821
|
/**
|
|
23157
21822
|
* ```js
|
|
23158
21823
|
* import { onCommentDeleteLocal } from '@amityco/ts-sdk-react-native'
|
|
@@ -23528,8 +22193,6 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
23528
22193
|
onCommentUnflagged: onCommentUnflagged,
|
|
23529
22194
|
onCommentReactionAdded: onCommentReactionAdded,
|
|
23530
22195
|
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
23531
|
-
observeComments: observeComments,
|
|
23532
|
-
observeComment: observeComment,
|
|
23533
22196
|
getComment: getComment,
|
|
23534
22197
|
getComments: getComments
|
|
23535
22198
|
});
|
|
@@ -24523,7 +23186,6 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
24523
23186
|
__proto__: null,
|
|
24524
23187
|
getPostByIds: getPostByIds,
|
|
24525
23188
|
createPost: createPost,
|
|
24526
|
-
updatePost: updatePost,
|
|
24527
23189
|
editPost: editPost,
|
|
24528
23190
|
deletePost: deletePost,
|
|
24529
23191
|
softDeletePost: softDeletePost,
|
|
@@ -24542,8 +23204,6 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
24542
23204
|
onPostUnflagged: onPostUnflagged,
|
|
24543
23205
|
onPostReactionAdded: onPostReactionAdded,
|
|
24544
23206
|
onPostReactionRemoved: onPostReactionRemoved,
|
|
24545
|
-
observePosts: observePosts,
|
|
24546
|
-
observePost: observePost,
|
|
24547
23207
|
getPost: getPost$1,
|
|
24548
23208
|
getPosts: getPosts,
|
|
24549
23209
|
getPinnedPosts: getPinnedPosts,
|
|
@@ -24736,47 +23396,6 @@ const disposeStream = async (streamId) => {
|
|
|
24736
23396
|
};
|
|
24737
23397
|
/* end_public_function */
|
|
24738
23398
|
|
|
24739
|
-
/* begin_public_function
|
|
24740
|
-
id: stream.query
|
|
24741
|
-
*/
|
|
24742
|
-
/**
|
|
24743
|
-
* @deprecated This API renamed to `getStreams`.
|
|
24744
|
-
* Please use getStreams() instead.
|
|
24745
|
-
* ```js
|
|
24746
|
-
* import { getStreams } from '@amityco/ts-sdk-react-native'
|
|
24747
|
-
* const streams = await getStreams()
|
|
24748
|
-
* ```
|
|
24749
|
-
*
|
|
24750
|
-
* Queries a paginable list of {@link Amity.InternalStream} objects
|
|
24751
|
-
*
|
|
24752
|
-
* @param query The query parameters
|
|
24753
|
-
* @returns A page of {@link Amity.InternalStream} objects
|
|
24754
|
-
*
|
|
24755
|
-
* @category Stream API
|
|
24756
|
-
* @async
|
|
24757
|
-
*/
|
|
24758
|
-
const queryStreams$1 = async (query) => {
|
|
24759
|
-
const client = getActiveClient();
|
|
24760
|
-
client.log('stream/queryStreams', query);
|
|
24761
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
24762
|
-
const { data } = await client.http.get(`/api/v3/video-streaming`, {
|
|
24763
|
-
params: Object.assign(Object.assign({}, params), { options: {
|
|
24764
|
-
token: toToken(page, 'skiplimit'),
|
|
24765
|
-
} }),
|
|
24766
|
-
});
|
|
24767
|
-
// API-FIX: backend to response Amity.Response: const { paging, videoStreamings } = unwrapPayload(data)
|
|
24768
|
-
// API-FIX: seems returned data has a results identifier on top of data, like no other apis, and this is beautiful
|
|
24769
|
-
const { paging, results: payload } = data;
|
|
24770
|
-
const { videoStreamings } = payload;
|
|
24771
|
-
const cachedAt = client.cache && Date.now();
|
|
24772
|
-
if (client.cache)
|
|
24773
|
-
ingestInCache(payload, { cachedAt });
|
|
24774
|
-
const nextPage = toPage(paging.next);
|
|
24775
|
-
const prevPage = toPage(paging.previous);
|
|
24776
|
-
return { data: videoStreamings, cachedAt, prevPage, nextPage };
|
|
24777
|
-
};
|
|
24778
|
-
/* end_public_function */
|
|
24779
|
-
|
|
24780
23399
|
/**
|
|
24781
23400
|
* ```js
|
|
24782
23401
|
* import { onStreamStarted } from '@amityco/ts-sdk-react-native'
|
|
@@ -24798,7 +23417,7 @@ const onStreamStarted = (callback) => {
|
|
|
24798
23417
|
ingestInCache(payload);
|
|
24799
23418
|
callback(payload.videoStreamings[0]);
|
|
24800
23419
|
};
|
|
24801
|
-
return createEventSubscriber(client, 'stream/onStreamStarted', '
|
|
23420
|
+
return createEventSubscriber(client, 'stream/onStreamStarted', 'video-streaming.didStart', filter);
|
|
24802
23421
|
};
|
|
24803
23422
|
|
|
24804
23423
|
/**
|
|
@@ -24822,7 +23441,7 @@ const onStreamStopped = (callback) => {
|
|
|
24822
23441
|
ingestInCache(payload);
|
|
24823
23442
|
callback(payload.videoStreamings[0]);
|
|
24824
23443
|
};
|
|
24825
|
-
return createEventSubscriber(client, 'stream/onStreamStropped', '
|
|
23444
|
+
return createEventSubscriber(client, 'stream/onStreamStropped', 'video-streaming.didStop', filter);
|
|
24826
23445
|
};
|
|
24827
23446
|
|
|
24828
23447
|
/**
|
|
@@ -24846,7 +23465,7 @@ const onStreamRecorded = (callback) => {
|
|
|
24846
23465
|
ingestInCache(payload);
|
|
24847
23466
|
callback(payload.videoStreamings[0]);
|
|
24848
23467
|
};
|
|
24849
|
-
return createEventSubscriber(client, 'stream/onStreamRecorded', '
|
|
23468
|
+
return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
|
|
24850
23469
|
};
|
|
24851
23470
|
|
|
24852
23471
|
/**
|
|
@@ -24870,7 +23489,7 @@ const onStreamFlagged = (callback) => {
|
|
|
24870
23489
|
ingestInCache(payload);
|
|
24871
23490
|
callback(payload.videoStreamings[0]);
|
|
24872
23491
|
};
|
|
24873
|
-
return createEventSubscriber(client, 'stream/onStreamFlagged', '
|
|
23492
|
+
return createEventSubscriber(client, 'stream/onStreamFlagged', 'video-streaming.didFlag', filter);
|
|
24874
23493
|
};
|
|
24875
23494
|
|
|
24876
23495
|
/**
|
|
@@ -24894,7 +23513,7 @@ const onStreamTerminated = (callback) => {
|
|
|
24894
23513
|
ingestInCache(payload);
|
|
24895
23514
|
callback(payload.videoStreamings[0]);
|
|
24896
23515
|
};
|
|
24897
|
-
return createEventSubscriber(client, 'stream/onStreamTerminated', '
|
|
23516
|
+
return createEventSubscriber(client, 'stream/onStreamTerminated', 'video-streaming.didTerminate', filter);
|
|
24898
23517
|
};
|
|
24899
23518
|
|
|
24900
23519
|
/* eslint-disable no-use-before-define */
|
|
@@ -25098,8 +23717,6 @@ var index$4 = /*#__PURE__*/Object.freeze({
|
|
|
25098
23717
|
updateStream: updateStream,
|
|
25099
23718
|
deleteStream: deleteStream,
|
|
25100
23719
|
disposeStream: disposeStream,
|
|
25101
|
-
queryStreams: queryStreams$1,
|
|
25102
|
-
getStream: getStream,
|
|
25103
23720
|
onStreamStarted: onStreamStarted,
|
|
25104
23721
|
onStreamStopped: onStreamStopped,
|
|
25105
23722
|
onStreamRecorded: onStreamRecorded,
|
|
@@ -25354,50 +23971,6 @@ const onPollDeleted = (callback) => {
|
|
|
25354
23971
|
return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
|
|
25355
23972
|
};
|
|
25356
23973
|
|
|
25357
|
-
/**
|
|
25358
|
-
* ```js
|
|
25359
|
-
* import { observePoll } from '@amityco/ts-sdk-react-native'
|
|
25360
|
-
*
|
|
25361
|
-
* let poll = {}
|
|
25362
|
-
* const dispose = observePoll(pollId, updated => poll = updated)
|
|
25363
|
-
* ```
|
|
25364
|
-
*
|
|
25365
|
-
* Observe all mutation on a given {@link Amity.Poll}
|
|
25366
|
-
*
|
|
25367
|
-
* @param pollId the ID of the poll to observe
|
|
25368
|
-
* @param callback the function to call when new data are available
|
|
25369
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
|
|
25370
|
-
*
|
|
25371
|
-
* @category Poll Observer
|
|
25372
|
-
*/
|
|
25373
|
-
const observePoll = (pollId, callback, policy = 'cache_then_server') => {
|
|
25374
|
-
const { log } = getActiveClient();
|
|
25375
|
-
const timestamp = Date.now();
|
|
25376
|
-
log(`observePoll(tmpid: ${timestamp}) > listen`);
|
|
25377
|
-
// wrapper function to make sure
|
|
25378
|
-
const router = (result, action) => {
|
|
25379
|
-
var _a, _b;
|
|
25380
|
-
if (callback instanceof Function)
|
|
25381
|
-
return callback(result);
|
|
25382
|
-
if (action !== 'onFetch')
|
|
25383
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
25384
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
25385
|
-
};
|
|
25386
|
-
const realtimeRouter = (result, action) => {
|
|
25387
|
-
var _a;
|
|
25388
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.pollId) !== pollId)
|
|
25389
|
-
return;
|
|
25390
|
-
router(result, action);
|
|
25391
|
-
};
|
|
25392
|
-
const disposers = [];
|
|
25393
|
-
disposers.push(onPollUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPollDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')));
|
|
25394
|
-
runQuery(createQuery(getPoll$1, pollId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
25395
|
-
return () => {
|
|
25396
|
-
log(`observePoll(tmpid: ${timestamp}) > dispose`);
|
|
25397
|
-
disposers.forEach(fn => fn());
|
|
25398
|
-
};
|
|
25399
|
-
};
|
|
25400
|
-
|
|
25401
23974
|
/* begin_public_function
|
|
25402
23975
|
id: poll.get
|
|
25403
23976
|
*/
|
|
@@ -25433,11 +24006,10 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
25433
24006
|
votePoll: votePoll,
|
|
25434
24007
|
onPollUpdated: onPollUpdated,
|
|
25435
24008
|
onPollDeleted: onPollDeleted,
|
|
25436
|
-
observePoll: observePoll,
|
|
25437
24009
|
getPoll: getPoll
|
|
25438
24010
|
});
|
|
25439
24011
|
|
|
25440
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
24012
|
+
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-----";
|
|
25441
24013
|
/*
|
|
25442
24014
|
* The crypto algorithm used for importing key and signing string
|
|
25443
24015
|
*/
|
|
@@ -25890,7 +24462,7 @@ const createOptimisticTarget = async ({ targetId, targetType, }) => {
|
|
|
25890
24462
|
optimisticTarget = Object.assign(Object.assign({}, optimisticTarget), { targetPublicId: community.data.communityId, targetUpdatedAt: (_a = community.data.updatedAt) !== null && _a !== void 0 ? _a : new Date().toISOString() });
|
|
25891
24463
|
}
|
|
25892
24464
|
if (targetType === 'user') {
|
|
25893
|
-
const user = await getUser$
|
|
24465
|
+
const user = await getUser$1(targetId);
|
|
25894
24466
|
optimisticTarget = Object.assign(Object.assign({}, optimisticTarget), { targetPublicId: user.data.userPublicId, targetUpdatedAt: (_b = user.data.updatedAt) !== null && _b !== void 0 ? _b : new Date().toISOString() });
|
|
25895
24467
|
}
|
|
25896
24468
|
pushToCache(["storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */, 'get', targetId], optimisticTarget);
|
|
@@ -27083,6 +25655,7 @@ exports.getChannelTopic = getChannelTopic;
|
|
|
27083
25655
|
exports.getCommentTopic = getCommentTopic;
|
|
27084
25656
|
exports.getCommunityStoriesTopic = getCommunityStoriesTopic;
|
|
27085
25657
|
exports.getCommunityTopic = getCommunityTopic;
|
|
25658
|
+
exports.getLiveStreamTopic = getLiveStreamTopic;
|
|
27086
25659
|
exports.getMarkedMessageTopic = getMarkedMessageTopic;
|
|
27087
25660
|
exports.getMarkerUserFeedTopic = getMarkerUserFeedTopic;
|
|
27088
25661
|
exports.getMessageTopic = getMessageTopic;
|