@amityco/ts-sdk 6.35.2-cd7f86f.0 → 6.35.3-024c022.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +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/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/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 +1363 -2900
- package/dist/index.esm.js +1083 -2621
- package/dist/index.umd.js +4 -4
- 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/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.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/analytic/api/queryReachUser.ts +1 -1
- package/src/channelRepository/api/deleteChannel.ts +3 -2
- 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 +107 -0
- package/src/channelRepository/{api → internalApi}/markAsRead.ts +0 -3
- package/src/channelRepository/observers/getChannel.ts +4 -3
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +8 -3
- package/src/channelRepository/observers/index.ts +0 -2
- package/src/channelRepository/utils/constructChannelDynamicValue.ts +4 -9
- package/src/channelRepository/utils/constructChannelObject.ts +9 -0
- package/src/channelRepository/utils/getChannelIsMentioned.ts +4 -1
- package/src/channelRepository/utils/getSubChannelsUnreadCount.ts +1 -1
- package/src/channelRepository/utils/resolveChannels.ts +6 -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/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/core/events.ts +6 -4
- 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 +1 -1
- package/src/messageRepository/api/index.ts +0 -2
- package/src/messageRepository/api/tests/createMessage.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 -20
- 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/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.esm.js
CHANGED
|
@@ -87,8 +87,8 @@ const PostContentType = Object.freeze({
|
|
|
87
87
|
|
|
88
88
|
function getVersion() {
|
|
89
89
|
try {
|
|
90
|
-
// the string ''v6.35.
|
|
91
|
-
return 'v6.35.
|
|
90
|
+
// the string ''v6.35.2-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
91
|
+
return 'v6.35.2-esm';
|
|
92
92
|
}
|
|
93
93
|
catch (error) {
|
|
94
94
|
return '__dev__';
|
|
@@ -1304,9 +1304,6 @@ const WS_EVENTS = [
|
|
|
1304
1304
|
'sessionStateChange',
|
|
1305
1305
|
// for internal use by accessTokenExpiryWatcher
|
|
1306
1306
|
'tokenExpired',
|
|
1307
|
-
'v3.video-streaming.didRecord',
|
|
1308
|
-
'v3.video-streaming.didStart',
|
|
1309
|
-
'v3.video-streaming.didStop',
|
|
1310
1307
|
];
|
|
1311
1308
|
const MQTT_EVENTS = [
|
|
1312
1309
|
'connect',
|
|
@@ -1316,6 +1313,11 @@ const MQTT_EVENTS = [
|
|
|
1316
1313
|
'close',
|
|
1317
1314
|
'end',
|
|
1318
1315
|
'reconnect',
|
|
1316
|
+
'video-streaming.didStart',
|
|
1317
|
+
'video-streaming.didRecord',
|
|
1318
|
+
'video-streaming.didStop',
|
|
1319
|
+
'video-streaming.didFlag',
|
|
1320
|
+
'video-streaming.didTerminate',
|
|
1319
1321
|
'user.didGlobalBan',
|
|
1320
1322
|
];
|
|
1321
1323
|
/** @hidden */
|
|
@@ -1515,7 +1517,11 @@ function subscribeTopic(topic, callback) {
|
|
|
1515
1517
|
return () => null;
|
|
1516
1518
|
modifyMqttConnection();
|
|
1517
1519
|
return mqtt.subscribe(topic, callback);
|
|
1518
|
-
}
|
|
1520
|
+
}
|
|
1521
|
+
const getLiveStreamTopic = () => {
|
|
1522
|
+
const user = getActiveUser();
|
|
1523
|
+
return `${getNetworkId(user)}/videostreaming`;
|
|
1524
|
+
};
|
|
1519
1525
|
|
|
1520
1526
|
var _a;
|
|
1521
1527
|
/* eslint-disable no-undef */
|
|
@@ -1551,7 +1557,7 @@ const API_REGIONS = {
|
|
|
1551
1557
|
US: 'us',
|
|
1552
1558
|
};
|
|
1553
1559
|
const URLS = {
|
|
1554
|
-
http: 'https://
|
|
1560
|
+
http: 'https://apix.{region}.amity.co',
|
|
1555
1561
|
mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
|
|
1556
1562
|
};
|
|
1557
1563
|
function computeUrl(type, region) {
|
|
@@ -20460,6 +20466,7 @@ const subscribeGlobalTopic = () => {
|
|
|
20460
20466
|
// subscribing to user topic is necessary to handle ban event
|
|
20461
20467
|
subscribeTopic(getUserTopic(getActiveUser())),
|
|
20462
20468
|
subscribeTopic(getMarkerUserFeedTopic()),
|
|
20469
|
+
subscribeTopic(getLiveStreamTopic()),
|
|
20463
20470
|
];
|
|
20464
20471
|
return () => disposers.forEach(fn => fn());
|
|
20465
20472
|
};
|
|
@@ -21972,9 +21979,6 @@ const reactorLinkedObject = (reactor) => {
|
|
|
21972
21979
|
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
21973
21980
|
* const success = await ChannelRepository.markAsRead('channelId')
|
|
21974
21981
|
* ```
|
|
21975
|
-
*
|
|
21976
|
-
* @deprecated Please use the {@link Amity.Channel.markAsRead} method instead
|
|
21977
|
-
*
|
|
21978
21982
|
* Updating all {@link Amity.SubChannel} in specify {@link Amity.Channel} as read
|
|
21979
21983
|
*
|
|
21980
21984
|
* @param channelId the ID of to specify {@link Amity.Channel}
|
|
@@ -22587,7 +22591,7 @@ const prepareMessagePayload = async (payload, event) => {
|
|
|
22587
22591
|
var _a, _b;
|
|
22588
22592
|
const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
22589
22593
|
// exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
|
|
22590
|
-
const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "
|
|
22594
|
+
const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "isMentioned"]);
|
|
22591
22595
|
updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
|
|
22592
22596
|
});
|
|
22593
22597
|
}
|
|
@@ -22601,15 +22605,12 @@ function convertParams(_a) {
|
|
|
22601
22605
|
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
|
|
22602
22606
|
}
|
|
22603
22607
|
function convertQueryParams$1(_a) {
|
|
22604
|
-
var { sortBy, subChannelId,
|
|
22608
|
+
var { sortBy, subChannelId, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
|
|
22605
22609
|
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: inferIsDeleted(includeDeleted), options: {
|
|
22606
22610
|
sortBy,
|
|
22607
22611
|
limit: limit || COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
22608
22612
|
around: aroundMessageId,
|
|
22609
22613
|
} });
|
|
22610
|
-
if (tags) {
|
|
22611
|
-
out.includeTags = tags;
|
|
22612
|
-
}
|
|
22613
22614
|
if (includingTags) {
|
|
22614
22615
|
out.includeTags = includingTags;
|
|
22615
22616
|
}
|
|
@@ -23093,18 +23094,13 @@ const getSubChannelsUnreadCount = (channel, marker) => {
|
|
|
23093
23094
|
};
|
|
23094
23095
|
|
|
23095
23096
|
const constructChannelDynamicValue = (channel) => {
|
|
23096
|
-
|
|
23097
|
-
|
|
23098
|
-
return getSubChannelsUnreadCount(channel);
|
|
23099
|
-
},
|
|
23100
|
-
get hasMentioned() {
|
|
23101
|
-
return getChannelIsMentioned(channel);
|
|
23102
|
-
},
|
|
23097
|
+
const rest = __rest(channel, ["messageCount"]);
|
|
23098
|
+
return shallowClone(rest, {
|
|
23103
23099
|
get isMentioned() {
|
|
23104
|
-
return getChannelIsMentioned(
|
|
23100
|
+
return getChannelIsMentioned(rest);
|
|
23105
23101
|
},
|
|
23106
23102
|
get subChannelsUnreadCount() {
|
|
23107
|
-
return getSubChannelsUnreadCount(
|
|
23103
|
+
return getSubChannelsUnreadCount(rest);
|
|
23108
23104
|
},
|
|
23109
23105
|
});
|
|
23110
23106
|
};
|
|
@@ -23242,20 +23238,6 @@ const setIntervalTask = (handler, timeout) => {
|
|
|
23242
23238
|
return () => clearInterval(timer);
|
|
23243
23239
|
};
|
|
23244
23240
|
|
|
23245
|
-
const onOnline = (callback) => {
|
|
23246
|
-
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
23247
|
-
window.addEventListener('online', callback);
|
|
23248
|
-
return () => window.removeEventListener('online', callback);
|
|
23249
|
-
}
|
|
23250
|
-
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
23251
|
-
document.addEventListener('online', callback);
|
|
23252
|
-
return () => document.removeEventListener('online', callback);
|
|
23253
|
-
}
|
|
23254
|
-
// Handle unsupported environment
|
|
23255
|
-
console.error('Unsupported environment');
|
|
23256
|
-
return () => console.error('Unsupported environment');
|
|
23257
|
-
};
|
|
23258
|
-
|
|
23259
23241
|
/**
|
|
23260
23242
|
* ```js
|
|
23261
23243
|
* import { SubChannel } from '@amityco/ts-sdk'
|
|
@@ -23288,73 +23270,8 @@ const readingAPI = async (messageFeedIds) => {
|
|
|
23288
23270
|
return true;
|
|
23289
23271
|
};
|
|
23290
23272
|
|
|
23291
|
-
/**
|
|
23292
|
-
* ```js
|
|
23293
|
-
* import { SubChannel } from '@amityco/ts-sdk'
|
|
23294
|
-
* const success = await SubChannel('foo')
|
|
23295
|
-
* ```
|
|
23296
|
-
*
|
|
23297
|
-
* Mark all messages as read and start reading message inside channel
|
|
23298
|
-
*
|
|
23299
|
-
* @param messageFeedId - Sub channel ID to start reading.
|
|
23300
|
-
* @return A success boolean if reading of the sub channel had begun.
|
|
23301
|
-
*
|
|
23302
|
-
* @category Channel API
|
|
23303
|
-
* @async
|
|
23304
|
-
* @private
|
|
23305
|
-
*/
|
|
23306
|
-
const startReadingAPI = async (messageFeedId) => {
|
|
23307
|
-
const client = getActiveClient();
|
|
23308
|
-
client.log('subChannel/startReadingAPI', messageFeedId);
|
|
23309
|
-
const { data: payload } = await client.http.post(`/api/v1/markers/message-feeds/${messageFeedId}/start-reading`);
|
|
23310
|
-
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, feedMarkers, userMarkers, } = payload;
|
|
23311
|
-
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
23312
|
-
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
23313
|
-
const cachedAt = client.cache && Date.now();
|
|
23314
|
-
if (client.cache)
|
|
23315
|
-
ingestInCache({ userEntityMarkers, userFeedMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
23316
|
-
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
23317
|
-
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
23318
|
-
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
23319
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
23320
|
-
return true;
|
|
23321
|
-
};
|
|
23322
|
-
|
|
23323
|
-
/**
|
|
23324
|
-
* ```js
|
|
23325
|
-
* import { stopReading } from '@amityco/ts-sdk'
|
|
23326
|
-
* const success = await stopReading('foo')
|
|
23327
|
-
* ```
|
|
23328
|
-
*
|
|
23329
|
-
* Mark all messages as read and stop reading message inside channel
|
|
23330
|
-
*
|
|
23331
|
-
* @param messageFeedId - The sub channel ID to stop reading.
|
|
23332
|
-
* @return A success boolean if reading of the sub channel had begun.
|
|
23333
|
-
*
|
|
23334
|
-
* @category Channel API
|
|
23335
|
-
* @async
|
|
23336
|
-
* @private
|
|
23337
|
-
*/
|
|
23338
|
-
const stopReadingAPI = async (messageFeedId) => {
|
|
23339
|
-
const client = getActiveClient();
|
|
23340
|
-
client.log('channel/stopReadingAPI', messageFeedId);
|
|
23341
|
-
const { data: payload } = await client.http.post(`/api/v1/markers/message-feeds/${messageFeedId}/stop-reading`);
|
|
23342
|
-
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, feedMarkers, userMarkers, } = payload;
|
|
23343
|
-
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
23344
|
-
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
23345
|
-
const cachedAt = client.cache && Date.now();
|
|
23346
|
-
if (client.cache)
|
|
23347
|
-
ingestInCache({ userEntityMarkers, userFeedMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
23348
|
-
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
23349
|
-
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
23350
|
-
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
23351
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
23352
|
-
return true;
|
|
23353
|
-
};
|
|
23354
|
-
|
|
23355
23273
|
const START_READING_INTERVAL_TIME = 30000;
|
|
23356
23274
|
let isSyncRunning$1 = false;
|
|
23357
|
-
let disposers$2 = [];
|
|
23358
23275
|
/**
|
|
23359
23276
|
* map contains subChannelId and isReading flag to determine which subChannel is on reading state
|
|
23360
23277
|
*/
|
|
@@ -23398,91 +23315,6 @@ const markReadEngineOnLoginHandler = () => {
|
|
|
23398
23315
|
stopIntervalTask();
|
|
23399
23316
|
};
|
|
23400
23317
|
};
|
|
23401
|
-
const getParentChannelId$1 = async (subChannelId) => {
|
|
23402
|
-
const cached = getSubChannel$1.locally(subChannelId);
|
|
23403
|
-
if (cached) {
|
|
23404
|
-
return cached.data.channelId;
|
|
23405
|
-
}
|
|
23406
|
-
const { data } = await getSubChannel$1(subChannelId);
|
|
23407
|
-
return data.channelId;
|
|
23408
|
-
};
|
|
23409
|
-
const registerEventListeners$1 = () => {
|
|
23410
|
-
if (disposers$2.length > 0) {
|
|
23411
|
-
return;
|
|
23412
|
-
}
|
|
23413
|
-
disposers$2.push(onOnline(() => {
|
|
23414
|
-
// Start reading the reading subChannel again when resume from offline state
|
|
23415
|
-
startReadingFromReadingList();
|
|
23416
|
-
}));
|
|
23417
|
-
};
|
|
23418
|
-
const registerTopicSubscribers$1 = async (subChannelId) => {
|
|
23419
|
-
const channelId = await getParentChannelId$1(subChannelId);
|
|
23420
|
-
const markedMessageTopic = getMarkedMessageTopic({ channelId, subChannelId });
|
|
23421
|
-
disposers$2.push(subscribeTopic(markedMessageTopic));
|
|
23422
|
-
};
|
|
23423
|
-
const disposeAll = () => {
|
|
23424
|
-
disposers$2.forEach(fn => fn());
|
|
23425
|
-
disposers$2 = [];
|
|
23426
|
-
};
|
|
23427
|
-
/* begin_public_function
|
|
23428
|
-
id: subchannel.start_reading
|
|
23429
|
-
*/
|
|
23430
|
-
/**
|
|
23431
|
-
* @deprecated Use {@link startMessageReceiptSync} instead.
|
|
23432
|
-
* ```js
|
|
23433
|
-
* import { startReading } from '@amityco/ts-sdk'
|
|
23434
|
-
* const success = await startReading('foo')
|
|
23435
|
-
* ```
|
|
23436
|
-
*
|
|
23437
|
-
* Set local reading state of channel to `true` and then call mark all
|
|
23438
|
-
* messages as read API.
|
|
23439
|
-
*
|
|
23440
|
-
* @param subChannelId - The sub channel ID to start reading.
|
|
23441
|
-
* @return A success boolean if reading of the sub channel had begun.
|
|
23442
|
-
*
|
|
23443
|
-
* @category Channel API
|
|
23444
|
-
* @async
|
|
23445
|
-
*/
|
|
23446
|
-
const startReading = async (subChannelId) => {
|
|
23447
|
-
isReadingMap[subChannelId] = true;
|
|
23448
|
-
if (disposers$2.length === 0) {
|
|
23449
|
-
registerEventListeners$1();
|
|
23450
|
-
registerTopicSubscribers$1(subChannelId);
|
|
23451
|
-
}
|
|
23452
|
-
try {
|
|
23453
|
-
return await startReadingAPI(subChannelId);
|
|
23454
|
-
}
|
|
23455
|
-
catch (e) {
|
|
23456
|
-
isReadingMap[subChannelId] = false;
|
|
23457
|
-
return false;
|
|
23458
|
-
}
|
|
23459
|
-
};
|
|
23460
|
-
/* end_public_function */
|
|
23461
|
-
/* begin_public_function
|
|
23462
|
-
id: subchannel.stop_reading
|
|
23463
|
-
*/
|
|
23464
|
-
/**
|
|
23465
|
-
* @deprecated Use {@link stopMessageReceiptSync} instead.
|
|
23466
|
-
* ```js
|
|
23467
|
-
* import { stopReading } from '@amityco/ts-sdk'
|
|
23468
|
-
* const success = await stopReading('foo')
|
|
23469
|
-
* ```
|
|
23470
|
-
*
|
|
23471
|
-
* Set local reading state of channel to `false` and then call mark all
|
|
23472
|
-
* messages as unread API.
|
|
23473
|
-
*
|
|
23474
|
-
* @param subChannelId - The sub channel ID to stop reading.
|
|
23475
|
-
* @return A success boolean if reading of the sub channel had begun.
|
|
23476
|
-
*
|
|
23477
|
-
* @category Channel API
|
|
23478
|
-
* @async
|
|
23479
|
-
*/
|
|
23480
|
-
const stopReading = (subChannelId) => {
|
|
23481
|
-
isReadingMap[subChannelId] = false;
|
|
23482
|
-
disposeAll();
|
|
23483
|
-
return stopReadingAPI(subChannelId);
|
|
23484
|
-
};
|
|
23485
|
-
/* end_public_function */
|
|
23486
23318
|
setIntervalTask(async () => {
|
|
23487
23319
|
if (!isSyncRunning$1)
|
|
23488
23320
|
return;
|
|
@@ -24035,6 +23867,20 @@ var readReceiptSyncEngineOnLoginHandler = () => {
|
|
|
24035
23867
|
};
|
|
24036
23868
|
};
|
|
24037
23869
|
|
|
23870
|
+
const onOnline = (callback) => {
|
|
23871
|
+
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
23872
|
+
window.addEventListener('online', callback);
|
|
23873
|
+
return () => window.removeEventListener('online', callback);
|
|
23874
|
+
}
|
|
23875
|
+
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
23876
|
+
document.addEventListener('online', callback);
|
|
23877
|
+
return () => document.removeEventListener('online', callback);
|
|
23878
|
+
}
|
|
23879
|
+
// Handle unsupported environment
|
|
23880
|
+
console.error('Unsupported environment');
|
|
23881
|
+
return () => console.error('Unsupported environment');
|
|
23882
|
+
};
|
|
23883
|
+
|
|
24038
23884
|
const onOffline = (callback) => {
|
|
24039
23885
|
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
24040
23886
|
window.addEventListener('offline', callback);
|
|
@@ -24050,7 +23896,9 @@ const onOffline = (callback) => {
|
|
|
24050
23896
|
};
|
|
24051
23897
|
|
|
24052
23898
|
const resolveChannels = async (channelIds) => {
|
|
24053
|
-
|
|
23899
|
+
var _a, _b, _c;
|
|
23900
|
+
await getChannelByIds(channelIds);
|
|
23901
|
+
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 : [];
|
|
24054
23902
|
fireEvent('local.channel.resolved', channels);
|
|
24055
23903
|
};
|
|
24056
23904
|
|
|
@@ -25178,13 +25026,6 @@ const stopUnreadSync = () => {
|
|
|
25178
25026
|
setMarkerSyncEvents([]);
|
|
25179
25027
|
unRegisterEventListeners();
|
|
25180
25028
|
};
|
|
25181
|
-
/**
|
|
25182
|
-
* @deprecated Please use `startUnreadSync` instead
|
|
25183
|
-
*/
|
|
25184
|
-
const stopUnreadSyncing = () => {
|
|
25185
|
-
console.warn('`stopUnreadSyncing` has been deprecated, please use `stopUnreadSync` instead');
|
|
25186
|
-
return stopUnreadSync();
|
|
25187
|
-
};
|
|
25188
25029
|
setIntervalTask(async () => {
|
|
25189
25030
|
if (!isSyncRunning)
|
|
25190
25031
|
return;
|
|
@@ -25882,100 +25723,6 @@ const removeFunctionProperties = (obj) => {
|
|
|
25882
25723
|
return Object.fromEntries(entries);
|
|
25883
25724
|
};
|
|
25884
25725
|
|
|
25885
|
-
/**
|
|
25886
|
-
* @deprecated This function is deprecated
|
|
25887
|
-
*/
|
|
25888
|
-
const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
|
|
25889
|
-
const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
|
|
25890
|
-
const { cache } = getActiveClient();
|
|
25891
|
-
if (!cache) {
|
|
25892
|
-
console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
|
|
25893
|
-
}
|
|
25894
|
-
let model;
|
|
25895
|
-
let isUnsyncedModel = false; // for messages
|
|
25896
|
-
const disposers = [];
|
|
25897
|
-
const dispatcher = (data) => {
|
|
25898
|
-
const { data: newModel } = data, rest = __rest(data, ["data"]);
|
|
25899
|
-
if (!callbackFilter || callbackFilter(newModel, model)) {
|
|
25900
|
-
callback(Object.assign({ data: callbackDataSelector(newModel) }, rest));
|
|
25901
|
-
}
|
|
25902
|
-
// resolve all getter on data model to a static value to avoid comparison problems
|
|
25903
|
-
model = convertGetterPropsToStatic(newModel);
|
|
25904
|
-
};
|
|
25905
|
-
const realtimeRouter = (eventModel, forceDispatch = false) => {
|
|
25906
|
-
if (id !== eventModel[key]) {
|
|
25907
|
-
return;
|
|
25908
|
-
}
|
|
25909
|
-
if (model) {
|
|
25910
|
-
if (!forceDispatch && isEqual(model, eventModel)) {
|
|
25911
|
-
return;
|
|
25912
|
-
}
|
|
25913
|
-
}
|
|
25914
|
-
dispatcher({ loading: false, data: eventModel, origin: 'event' });
|
|
25915
|
-
};
|
|
25916
|
-
const onFetch = () => {
|
|
25917
|
-
// TODO: Ihis `@ts-ignore` is bring back to fix the build and it needs to be removed later
|
|
25918
|
-
// @ts-ignore
|
|
25919
|
-
const query = createQuery(fetcher, id, true);
|
|
25920
|
-
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
25921
|
-
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
25922
|
-
dispatcher({
|
|
25923
|
-
// @ts-ignore
|
|
25924
|
-
data,
|
|
25925
|
-
origin,
|
|
25926
|
-
loading: false,
|
|
25927
|
-
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
25928
|
-
});
|
|
25929
|
-
isUnsyncedModel = true;
|
|
25930
|
-
disposers.forEach(fn => fn());
|
|
25931
|
-
}
|
|
25932
|
-
else if (!isUnsyncedModel) {
|
|
25933
|
-
// @ts-ignore
|
|
25934
|
-
dispatcher({ loading, data, origin, error });
|
|
25935
|
-
}
|
|
25936
|
-
if (error) {
|
|
25937
|
-
disposers.forEach(fn => fn());
|
|
25938
|
-
}
|
|
25939
|
-
});
|
|
25940
|
-
};
|
|
25941
|
-
disposers.push(...eventHandlers.map(fn => fn(eventModel => realtimeRouter(eventModel, forceDispatch))));
|
|
25942
|
-
onFetch();
|
|
25943
|
-
return () => {
|
|
25944
|
-
disposers.forEach(fn => fn());
|
|
25945
|
-
};
|
|
25946
|
-
};
|
|
25947
|
-
|
|
25948
|
-
/**
|
|
25949
|
-
* @deprecated Please use unreadCount from `getUserUnread` instead.
|
|
25950
|
-
*
|
|
25951
|
-
* ```js
|
|
25952
|
-
* import { getTotalUnreadCount } from '@amityco/ts-sdk';
|
|
25953
|
-
*
|
|
25954
|
-
* const unsubscribe = getTotalUnreadCount(response => {
|
|
25955
|
-
* totalUnreadCount = response.data;
|
|
25956
|
-
* });
|
|
25957
|
-
* ```
|
|
25958
|
-
*
|
|
25959
|
-
* Observe current user's unread count from {@link Amity.UserMarker}
|
|
25960
|
-
*
|
|
25961
|
-
* @param callback the function to call when new data are available
|
|
25962
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the events
|
|
25963
|
-
*
|
|
25964
|
-
* @category Message Live Object
|
|
25965
|
-
*/
|
|
25966
|
-
const getTotalUnreadCount = (callback) => {
|
|
25967
|
-
const { _id: userId } = getActiveUser();
|
|
25968
|
-
if (!userId)
|
|
25969
|
-
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25970
|
-
const callbackDataSelector = (data) => { var _a; return (_a = data === null || data === void 0 ? void 0 : data.unreadCount) !== null && _a !== void 0 ? _a : 0; };
|
|
25971
|
-
return liveObject(userId, callback, 'userId', async () => {
|
|
25972
|
-
const { data: userMarker, cachedAt } = await getUserMarker();
|
|
25973
|
-
return { data: userMarker, cachedAt };
|
|
25974
|
-
}, [onUserMarkerFetchedLegacy], {
|
|
25975
|
-
callbackDataSelector,
|
|
25976
|
-
});
|
|
25977
|
-
};
|
|
25978
|
-
|
|
25979
25726
|
/**
|
|
25980
25727
|
*
|
|
25981
25728
|
* ```js
|
|
@@ -26017,7 +25764,7 @@ const getUserUnread = (callback) => {
|
|
|
26017
25764
|
model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
|
|
26018
25765
|
callback({
|
|
26019
25766
|
data: callbackModel
|
|
26020
|
-
? Object.assign(Object.assign({}, callbackModel), {
|
|
25767
|
+
? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
|
|
26021
25768
|
loading: data.loading,
|
|
26022
25769
|
error: data.error,
|
|
26023
25770
|
});
|
|
@@ -26105,7 +25852,6 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
26105
25852
|
onClientBanned: onClientBanned,
|
|
26106
25853
|
onSessionStateChange: onSessionStateChange,
|
|
26107
25854
|
onNetworkActivities: onNetworkActivities,
|
|
26108
|
-
getTotalUnreadCount: getTotalUnreadCount,
|
|
26109
25855
|
getUserUnread: getUserUnread,
|
|
26110
25856
|
getMarkerSyncEvents: getMarkerSyncEvents,
|
|
26111
25857
|
setMarkerSyncEvents: setMarkerSyncEvents,
|
|
@@ -26114,7 +25860,6 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
26114
25860
|
startMarkerSync: startMarkerSync,
|
|
26115
25861
|
startUnreadSync: startUnreadSync,
|
|
26116
25862
|
stopUnreadSync: stopUnreadSync,
|
|
26117
|
-
stopUnreadSyncing: stopUnreadSyncing,
|
|
26118
25863
|
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
|
|
26119
25864
|
});
|
|
26120
25865
|
|
|
@@ -26199,311 +25944,134 @@ const unBlockUser = async (userId) => {
|
|
|
26199
25944
|
};
|
|
26200
25945
|
/* end_public_function */
|
|
26201
25946
|
|
|
26202
|
-
|
|
26203
|
-
|
|
26204
|
-
|
|
26205
|
-
this.queryParams = queryParams;
|
|
26206
|
-
this.http = http;
|
|
26207
|
-
}
|
|
26208
|
-
loadFirstPage() {
|
|
26209
|
-
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
26210
|
-
}
|
|
26211
|
-
loadNextPage() {
|
|
26212
|
-
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
26213
|
-
}
|
|
26214
|
-
loadPreviousPage() {
|
|
26215
|
-
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
26216
|
-
}
|
|
26217
|
-
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
26218
|
-
var _a, _b, _c, _d;
|
|
26219
|
-
if (direction === 'prev' && !this.previousToken)
|
|
26220
|
-
return;
|
|
26221
|
-
if (direction === 'next' && !this.nextToken)
|
|
26222
|
-
return;
|
|
26223
|
-
let token;
|
|
26224
|
-
if (direction === 'prev')
|
|
26225
|
-
token = this.previousToken;
|
|
26226
|
-
if (direction === 'next')
|
|
26227
|
-
token = this.nextToken;
|
|
26228
|
-
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
26229
|
-
if (direction === 'first') {
|
|
26230
|
-
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
26231
|
-
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
26232
|
-
}
|
|
26233
|
-
if (direction === 'prev')
|
|
26234
|
-
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
26235
|
-
if (direction === 'next')
|
|
26236
|
-
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
26237
|
-
return queryResponse;
|
|
26238
|
-
}
|
|
26239
|
-
getNextToken() {
|
|
26240
|
-
return this.nextToken;
|
|
26241
|
-
}
|
|
26242
|
-
getPrevToken() {
|
|
26243
|
-
return this.previousToken;
|
|
26244
|
-
}
|
|
26245
|
-
}
|
|
26246
|
-
|
|
26247
|
-
class BlockedUserPaginationController extends PaginationController {
|
|
26248
|
-
async getRequest(queryParams, token) {
|
|
26249
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
26250
|
-
const options = token ? { token } : { limit };
|
|
26251
|
-
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
26252
|
-
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
26253
|
-
});
|
|
26254
|
-
return queryResponse;
|
|
26255
|
-
}
|
|
26256
|
-
}
|
|
26257
|
-
|
|
26258
|
-
class QueryStreamController {
|
|
26259
|
-
constructor(query, cacheKey) {
|
|
26260
|
-
this.query = query;
|
|
26261
|
-
this.cacheKey = cacheKey;
|
|
26262
|
-
}
|
|
26263
|
-
}
|
|
26264
|
-
|
|
26265
|
-
var EnumFollowActions;
|
|
26266
|
-
(function (EnumFollowActions) {
|
|
26267
|
-
EnumFollowActions["OnRequested"] = "onRequested";
|
|
26268
|
-
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
26269
|
-
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
26270
|
-
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
26271
|
-
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
26272
|
-
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
26273
|
-
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
26274
|
-
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
26275
|
-
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
26276
|
-
|
|
26277
|
-
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
26278
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
26279
|
-
super(query, cacheKey);
|
|
26280
|
-
this.notifyChange = notifyChange;
|
|
26281
|
-
this.preparePayload = preparePayload;
|
|
26282
|
-
}
|
|
26283
|
-
async saveToMainDB(response) {
|
|
26284
|
-
const processedPayload = await this.preparePayload(response);
|
|
26285
|
-
const client = getActiveClient();
|
|
26286
|
-
const cachedAt = client.cache && Date.now();
|
|
26287
|
-
if (client.cache) {
|
|
26288
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
26289
|
-
}
|
|
26290
|
-
}
|
|
26291
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
26292
|
-
var _a, _b;
|
|
26293
|
-
if (refresh) {
|
|
26294
|
-
pushToCache(this.cacheKey, {
|
|
26295
|
-
data: response.users.map(getResolver('user')),
|
|
26296
|
-
});
|
|
26297
|
-
}
|
|
26298
|
-
else {
|
|
26299
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26300
|
-
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26301
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
26302
|
-
}
|
|
26303
|
-
}
|
|
26304
|
-
reactor(action) {
|
|
26305
|
-
return (targetUser) => {
|
|
26306
|
-
var _a;
|
|
26307
|
-
if (action === EnumFollowActions.OnFollowed) {
|
|
26308
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26309
|
-
const updatedCollection = collection === null || collection === void 0 ? void 0 : collection.data.filter(id => id !== targetUser.userId);
|
|
26310
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: updatedCollection }));
|
|
26311
|
-
}
|
|
26312
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
26313
|
-
};
|
|
26314
|
-
}
|
|
26315
|
-
subscribeRTE(createSubscriber) {
|
|
26316
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
26317
|
-
}
|
|
26318
|
-
}
|
|
26319
|
-
|
|
26320
|
-
class PaginationNoPageController {
|
|
26321
|
-
constructor(queryParams) {
|
|
26322
|
-
const { http } = getActiveClient();
|
|
26323
|
-
this.queryParams = queryParams;
|
|
26324
|
-
this.http = http;
|
|
26325
|
-
}
|
|
26326
|
-
async onFetch() {
|
|
26327
|
-
const queryResponse = await this.getRequest(this.queryParams);
|
|
26328
|
-
return queryResponse;
|
|
26329
|
-
}
|
|
26330
|
-
}
|
|
26331
|
-
|
|
26332
|
-
class LiveCollectionController {
|
|
26333
|
-
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
26334
|
-
this.paginationController = paginationController;
|
|
26335
|
-
this.queryStreamId = queryStreamId;
|
|
26336
|
-
this.cacheKey = cacheKey;
|
|
26337
|
-
this.callback = callback;
|
|
26338
|
-
}
|
|
26339
|
-
async refresh() {
|
|
26340
|
-
try {
|
|
26341
|
-
let result;
|
|
26342
|
-
if (this.paginationController instanceof PaginationNoPageController) {
|
|
26343
|
-
result = await this.paginationController.onFetch();
|
|
26344
|
-
}
|
|
26345
|
-
else {
|
|
26346
|
-
result = await this.paginationController.loadFirstPage();
|
|
26347
|
-
}
|
|
26348
|
-
if (!result)
|
|
26349
|
-
return;
|
|
26350
|
-
await this.persistModel(result);
|
|
26351
|
-
this.persistQueryStream({
|
|
26352
|
-
response: result,
|
|
26353
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26354
|
-
refresh: true,
|
|
26355
|
-
});
|
|
26356
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26357
|
-
}
|
|
26358
|
-
catch (e) {
|
|
26359
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26360
|
-
}
|
|
26361
|
-
}
|
|
26362
|
-
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
26363
|
-
this.setup();
|
|
26364
|
-
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
26365
|
-
if (initial) {
|
|
26366
|
-
this.refresh();
|
|
26367
|
-
}
|
|
26368
|
-
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
26369
|
-
this.loadPrevPage();
|
|
26370
|
-
}
|
|
26371
|
-
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
26372
|
-
this.loadNextPage();
|
|
26373
|
-
}
|
|
26374
|
-
}
|
|
26375
|
-
async loadNextPage() {
|
|
26376
|
-
try {
|
|
26377
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
26378
|
-
return;
|
|
26379
|
-
const result = await this.paginationController.loadNextPage();
|
|
26380
|
-
if (!result)
|
|
26381
|
-
return;
|
|
26382
|
-
await this.persistModel(result);
|
|
26383
|
-
this.persistQueryStream({
|
|
26384
|
-
response: result,
|
|
26385
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26386
|
-
});
|
|
26387
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26388
|
-
}
|
|
26389
|
-
catch (e) {
|
|
26390
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26391
|
-
}
|
|
26392
|
-
}
|
|
26393
|
-
async loadPrevPage() {
|
|
26394
|
-
try {
|
|
26395
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
26396
|
-
return;
|
|
26397
|
-
const result = await this.paginationController.loadPreviousPage();
|
|
26398
|
-
if (!result)
|
|
26399
|
-
return;
|
|
26400
|
-
await this.persistModel(result);
|
|
26401
|
-
this.persistQueryStream({
|
|
26402
|
-
response: result,
|
|
26403
|
-
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
26404
|
-
});
|
|
26405
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26406
|
-
}
|
|
26407
|
-
catch (e) {
|
|
26408
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26409
|
-
}
|
|
26410
|
-
}
|
|
26411
|
-
shouldNotify(data) {
|
|
26412
|
-
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
26413
|
-
if (isEqual(this.snapshot, newData))
|
|
26414
|
-
return false;
|
|
26415
|
-
this.snapshot = newData;
|
|
26416
|
-
return true;
|
|
26417
|
-
}
|
|
26418
|
-
getCacheKey() {
|
|
26419
|
-
return this.cacheKey;
|
|
26420
|
-
}
|
|
26421
|
-
}
|
|
26422
|
-
|
|
26423
|
-
function prepareBlockedUserPayload(response) {
|
|
26424
|
-
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
26425
|
-
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
26426
|
-
const followUser = users.find(user => user.userId === follow.from);
|
|
26427
|
-
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
26428
|
-
}), users: users.map(convertRawUserToInternalUser) });
|
|
26429
|
-
}
|
|
26430
|
-
|
|
25947
|
+
/* begin_public_function
|
|
25948
|
+
id: user.relationship.follow
|
|
25949
|
+
*/
|
|
26431
25950
|
/**
|
|
26432
25951
|
* ```js
|
|
26433
|
-
* import {
|
|
26434
|
-
* const
|
|
26435
|
-
* // ...
|
|
26436
|
-
* })
|
|
25952
|
+
* import { follow } from '@amityco/ts-sdk'
|
|
25953
|
+
* const status = await follow('foobar')
|
|
26437
25954
|
* ```
|
|
26438
25955
|
*
|
|
26439
|
-
*
|
|
25956
|
+
* Follow the user
|
|
26440
25957
|
*
|
|
26441
|
-
* @param
|
|
26442
|
-
* @returns
|
|
25958
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
25959
|
+
* @returns the status {@link Amity.FollowStatus}
|
|
26443
25960
|
*
|
|
26444
|
-
* @category
|
|
25961
|
+
* @category Follow API
|
|
25962
|
+
* @async
|
|
26445
25963
|
*/
|
|
26446
|
-
const
|
|
25964
|
+
const follow = async (userId) => {
|
|
25965
|
+
const client = getActiveClient();
|
|
25966
|
+
client.log('follow/follow', userId);
|
|
25967
|
+
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
25968
|
+
const cachedAt = client.cache && Date.now();
|
|
25969
|
+
if (client.cache) {
|
|
25970
|
+
ingestInCache(data, { cachedAt });
|
|
25971
|
+
}
|
|
25972
|
+
const payload = prepareFollowStatusPayload(data);
|
|
25973
|
+
if (data.follows[0].status === 'accepted') {
|
|
25974
|
+
fireEvent('local.follow.created', payload);
|
|
25975
|
+
}
|
|
25976
|
+
else {
|
|
25977
|
+
fireEvent('local.follow.requested', payload);
|
|
25978
|
+
}
|
|
25979
|
+
return {
|
|
25980
|
+
data: data.follows[0],
|
|
25981
|
+
cachedAt,
|
|
25982
|
+
};
|
|
25983
|
+
};
|
|
25984
|
+
/* end_public_function */
|
|
26447
25985
|
|
|
25986
|
+
/* begin_public_function
|
|
25987
|
+
id: user.relationship.unfollow
|
|
25988
|
+
*/
|
|
26448
25989
|
/**
|
|
26449
25990
|
* ```js
|
|
26450
|
-
* import {
|
|
26451
|
-
*
|
|
26452
|
-
* // ...
|
|
26453
|
-
* })
|
|
25991
|
+
* import { unfollow } from '@amityco/ts-sdk'
|
|
25992
|
+
* await unfollow('foobar')
|
|
26454
25993
|
* ```
|
|
26455
25994
|
*
|
|
26456
|
-
*
|
|
25995
|
+
* Cancel the follow request or unfollow the user
|
|
26457
25996
|
*
|
|
26458
|
-
* @param
|
|
26459
|
-
* @returns
|
|
25997
|
+
* @param userId the ID of the {@link Amity.InternalUser}
|
|
25998
|
+
* @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
|
|
26460
25999
|
*
|
|
26461
|
-
* @category
|
|
26000
|
+
* @category Follow API
|
|
26001
|
+
* @async
|
|
26462
26002
|
*/
|
|
26463
|
-
const
|
|
26003
|
+
const unfollow = async (userId) => {
|
|
26004
|
+
const client = getActiveClient();
|
|
26005
|
+
client.log('follow/unfollow', userId);
|
|
26006
|
+
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
26007
|
+
if (client.cache) {
|
|
26008
|
+
ingestInCache(data);
|
|
26009
|
+
}
|
|
26010
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26011
|
+
fireEvent('local.follow.unfollowed', payload);
|
|
26012
|
+
return true;
|
|
26013
|
+
};
|
|
26014
|
+
/* end_public_function */
|
|
26464
26015
|
|
|
26016
|
+
/* begin_public_function
|
|
26017
|
+
id: user.relationship.accept_follow
|
|
26018
|
+
*/
|
|
26465
26019
|
/**
|
|
26466
26020
|
* ```js
|
|
26467
|
-
* import {
|
|
26468
|
-
*
|
|
26469
|
-
* // ...
|
|
26470
|
-
* })
|
|
26021
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
26022
|
+
* await UserRepository.Relationship.acceptMyFollower('foobar')
|
|
26471
26023
|
* ```
|
|
26472
26024
|
*
|
|
26473
|
-
*
|
|
26025
|
+
* Accept the follow request
|
|
26474
26026
|
*
|
|
26475
|
-
* @param
|
|
26476
|
-
* @returns
|
|
26027
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
26028
|
+
* @returns A success boolean if the follow request was accepted
|
|
26477
26029
|
*
|
|
26478
|
-
* @category
|
|
26030
|
+
* @category Follow API
|
|
26031
|
+
* @async
|
|
26479
26032
|
*/
|
|
26480
|
-
const
|
|
26033
|
+
const acceptMyFollower = async (userId) => {
|
|
26034
|
+
const client = getActiveClient();
|
|
26035
|
+
client.log('follow/acceptMyFollower', userId);
|
|
26036
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
26037
|
+
if (client.cache) {
|
|
26038
|
+
ingestInCache(data);
|
|
26039
|
+
}
|
|
26040
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26041
|
+
fireEvent('local.follow.accepted', payload);
|
|
26042
|
+
return true;
|
|
26043
|
+
};
|
|
26044
|
+
/* end_public_function */
|
|
26481
26045
|
|
|
26046
|
+
/* begin_public_function
|
|
26047
|
+
id: user.relationship.decline_follow
|
|
26048
|
+
*/
|
|
26482
26049
|
/**
|
|
26483
26050
|
* ```js
|
|
26484
|
-
* import {
|
|
26485
|
-
*
|
|
26486
|
-
* // ...
|
|
26487
|
-
* })
|
|
26051
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
26052
|
+
* await UserRepository.Relationship.declineMyFollower('foobar')
|
|
26488
26053
|
* ```
|
|
26489
26054
|
*
|
|
26490
|
-
*
|
|
26055
|
+
* Decline the follow request or delete the follower
|
|
26491
26056
|
*
|
|
26492
|
-
* @param
|
|
26493
|
-
* @returns
|
|
26057
|
+
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
26058
|
+
* @returns A success boolean if the follow request was decline
|
|
26494
26059
|
*
|
|
26495
|
-
* @category
|
|
26060
|
+
* @category Follow API
|
|
26061
|
+
* @async
|
|
26496
26062
|
*/
|
|
26497
|
-
const
|
|
26498
|
-
|
|
26499
|
-
|
|
26500
|
-
|
|
26501
|
-
|
|
26502
|
-
|
|
26503
|
-
|
|
26504
|
-
|
|
26505
|
-
|
|
26506
|
-
|
|
26063
|
+
const declineMyFollower = async (userId) => {
|
|
26064
|
+
const client = getActiveClient();
|
|
26065
|
+
client.log('follow/declineMyFollower', userId);
|
|
26066
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
26067
|
+
if (client.cache) {
|
|
26068
|
+
ingestInCache(data);
|
|
26069
|
+
}
|
|
26070
|
+
const payload = prepareFollowStatusPayload(data);
|
|
26071
|
+
fireEvent('local.follow.requestDeclined', payload);
|
|
26072
|
+
return true;
|
|
26073
|
+
};
|
|
26074
|
+
/* end_public_function */
|
|
26507
26075
|
|
|
26508
26076
|
const createFollowEventSubscriber = (event, callback) => {
|
|
26509
26077
|
const client = getActiveClient();
|
|
@@ -26767,446 +26335,50 @@ const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscri
|
|
|
26767
26335
|
|
|
26768
26336
|
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
26769
26337
|
|
|
26770
|
-
|
|
26771
|
-
|
|
26772
|
-
|
|
26773
|
-
|
|
26774
|
-
|
|
26775
|
-
const client = getActiveClient();
|
|
26776
|
-
const { objectSyncMap } = client;
|
|
26777
|
-
/*
|
|
26778
|
-
* 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.
|
|
26779
|
-
* 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.
|
|
26780
|
-
*/
|
|
26781
|
-
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
26782
|
-
? sourceModel[sourceModelProp]
|
|
26783
|
-
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
26784
|
-
const model = (_b = pullFromCache([
|
|
26785
|
-
destinationDomain,
|
|
26786
|
-
'get',
|
|
26787
|
-
`${resolvedId}`,
|
|
26788
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
26789
|
-
if (!model)
|
|
26790
|
-
return;
|
|
26791
|
-
return callback(model);
|
|
26792
|
-
});
|
|
26793
|
-
|
|
26794
|
-
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
26795
|
-
constructor(query, callback) {
|
|
26796
|
-
const queryStreamId = hash(query);
|
|
26797
|
-
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
26798
|
-
const paginationController = new BlockedUserPaginationController(query);
|
|
26799
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
26800
|
-
this.query = query;
|
|
26801
|
-
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
26802
|
-
this.callback = callback.bind(this);
|
|
26803
|
-
this.loadPage({ initial: true });
|
|
26804
|
-
}
|
|
26805
|
-
setup() {
|
|
26806
|
-
var _a;
|
|
26807
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26808
|
-
if (!collection) {
|
|
26809
|
-
pushToCache(this.cacheKey, {
|
|
26810
|
-
data: [],
|
|
26811
|
-
params: {},
|
|
26812
|
-
});
|
|
26813
|
-
}
|
|
26338
|
+
class PaginationController {
|
|
26339
|
+
constructor(queryParams) {
|
|
26340
|
+
const { http } = getActiveClient();
|
|
26341
|
+
this.queryParams = queryParams;
|
|
26342
|
+
this.http = http;
|
|
26814
26343
|
}
|
|
26815
|
-
|
|
26816
|
-
|
|
26344
|
+
loadFirstPage() {
|
|
26345
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
26817
26346
|
}
|
|
26818
|
-
|
|
26819
|
-
this.
|
|
26347
|
+
loadNextPage() {
|
|
26348
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
26820
26349
|
}
|
|
26821
|
-
|
|
26822
|
-
return this.
|
|
26823
|
-
{
|
|
26824
|
-
fn: onUserDeleted$2,
|
|
26825
|
-
action: EnumUserActions.OnUserDeleted,
|
|
26826
|
-
},
|
|
26827
|
-
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
26828
|
-
{
|
|
26829
|
-
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
26830
|
-
action: EnumFollowActions.OnFollowed,
|
|
26831
|
-
},
|
|
26832
|
-
{
|
|
26833
|
-
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
26834
|
-
action: EnumFollowActions.OnFollowed,
|
|
26835
|
-
},
|
|
26836
|
-
]);
|
|
26350
|
+
loadPreviousPage() {
|
|
26351
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
26837
26352
|
}
|
|
26838
|
-
|
|
26839
|
-
var _a, _b;
|
|
26840
|
-
|
|
26841
|
-
if (!collection)
|
|
26353
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
26354
|
+
var _a, _b, _c, _d;
|
|
26355
|
+
if (direction === 'prev' && !this.previousToken)
|
|
26842
26356
|
return;
|
|
26843
|
-
|
|
26844
|
-
.map(id => pullFromCache(['user', 'get', id]))
|
|
26845
|
-
.filter(isNonNullable)
|
|
26846
|
-
.map(({ data }) => data)
|
|
26847
|
-
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
26848
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
26357
|
+
if (direction === 'next' && !this.nextToken)
|
|
26849
26358
|
return;
|
|
26850
|
-
|
|
26851
|
-
|
|
26852
|
-
|
|
26853
|
-
|
|
26854
|
-
|
|
26855
|
-
|
|
26856
|
-
|
|
26857
|
-
|
|
26858
|
-
|
|
26859
|
-
|
|
26860
|
-
|
|
26861
|
-
|
|
26862
|
-
|
|
26863
|
-
|
|
26864
|
-
|
|
26865
|
-
|
|
26866
|
-
/* begin_public_function
|
|
26867
|
-
id: user.get_blocked_users
|
|
26868
|
-
*/
|
|
26869
|
-
/**
|
|
26870
|
-
* ```js
|
|
26871
|
-
* import { UserRepository } from '@amityco/ts-sdk'
|
|
26872
|
-
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
26873
|
-
* ```
|
|
26874
|
-
*
|
|
26875
|
-
* Blocks a {@link Amity.InternalUser}
|
|
26876
|
-
*
|
|
26877
|
-
* @param params The params to get blocked {@link Amity.InternalUser}s
|
|
26878
|
-
* @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
|
|
26879
|
-
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
26880
|
-
*
|
|
26881
|
-
* @category Post API
|
|
26882
|
-
* @async
|
|
26883
|
-
*/
|
|
26884
|
-
const getBlockedUsers$1 = (params, callback, config) => {
|
|
26885
|
-
const { log, cache } = getActiveClient();
|
|
26886
|
-
if (!cache) {
|
|
26887
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
26888
|
-
}
|
|
26889
|
-
const timestamp = Date.now();
|
|
26890
|
-
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
26891
|
-
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
26892
|
-
const disposers = blockedUserLiveCollection.startSubscription();
|
|
26893
|
-
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
26894
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
26895
|
-
return () => {
|
|
26896
|
-
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
26897
|
-
disposers.forEach(fn => fn());
|
|
26898
|
-
dropFromCache(cacheKey);
|
|
26899
|
-
};
|
|
26900
|
-
};
|
|
26901
|
-
/* end_public_function */
|
|
26902
|
-
|
|
26903
|
-
/* eslint-disable no-use-before-define */
|
|
26904
|
-
const getBlockedUsers = (params, callback, config) => {
|
|
26905
|
-
console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
|
|
26906
|
-
return getBlockedUsers$1(params, callback);
|
|
26907
|
-
};
|
|
26908
|
-
|
|
26909
|
-
/* begin_public_function
|
|
26910
|
-
id: user.relationship.follow
|
|
26911
|
-
*/
|
|
26912
|
-
/**
|
|
26913
|
-
* ```js
|
|
26914
|
-
* import { follow } from '@amityco/ts-sdk'
|
|
26915
|
-
* const status = await follow('foobar')
|
|
26916
|
-
* ```
|
|
26917
|
-
*
|
|
26918
|
-
* Follow the user
|
|
26919
|
-
*
|
|
26920
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
26921
|
-
* @returns the status {@link Amity.FollowStatus}
|
|
26922
|
-
*
|
|
26923
|
-
* @category Follow API
|
|
26924
|
-
* @async
|
|
26925
|
-
*/
|
|
26926
|
-
const follow = async (userId) => {
|
|
26927
|
-
const client = getActiveClient();
|
|
26928
|
-
client.log('follow/follow', userId);
|
|
26929
|
-
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
26930
|
-
const cachedAt = client.cache && Date.now();
|
|
26931
|
-
if (client.cache) {
|
|
26932
|
-
ingestInCache(data, { cachedAt });
|
|
26933
|
-
}
|
|
26934
|
-
const payload = prepareFollowStatusPayload(data);
|
|
26935
|
-
if (data.follows[0].status === 'accepted') {
|
|
26936
|
-
fireEvent('local.follow.created', payload);
|
|
26937
|
-
}
|
|
26938
|
-
else {
|
|
26939
|
-
fireEvent('local.follow.requested', payload);
|
|
26940
|
-
}
|
|
26941
|
-
return {
|
|
26942
|
-
data: data.follows[0],
|
|
26943
|
-
cachedAt,
|
|
26944
|
-
};
|
|
26945
|
-
};
|
|
26946
|
-
/* end_public_function */
|
|
26947
|
-
|
|
26948
|
-
/* begin_public_function
|
|
26949
|
-
id: user.relationship.unfollow
|
|
26950
|
-
*/
|
|
26951
|
-
/**
|
|
26952
|
-
* ```js
|
|
26953
|
-
* import { unfollow } from '@amityco/ts-sdk'
|
|
26954
|
-
* await unfollow('foobar')
|
|
26955
|
-
* ```
|
|
26956
|
-
*
|
|
26957
|
-
* Cancel the follow request or unfollow the user
|
|
26958
|
-
*
|
|
26959
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
26960
|
-
* @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
|
|
26961
|
-
*
|
|
26962
|
-
* @category Follow API
|
|
26963
|
-
* @async
|
|
26964
|
-
*/
|
|
26965
|
-
const unfollow = async (userId) => {
|
|
26966
|
-
const client = getActiveClient();
|
|
26967
|
-
client.log('follow/unfollow', userId);
|
|
26968
|
-
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
26969
|
-
if (client.cache) {
|
|
26970
|
-
ingestInCache(data);
|
|
26971
|
-
}
|
|
26972
|
-
const payload = prepareFollowStatusPayload(data);
|
|
26973
|
-
fireEvent('local.follow.unfollowed', payload);
|
|
26974
|
-
return true;
|
|
26975
|
-
};
|
|
26976
|
-
/* end_public_function */
|
|
26977
|
-
|
|
26978
|
-
/**
|
|
26979
|
-
* @deprecated This API renamed to `acceptMyFollower`.
|
|
26980
|
-
* Please use acceptMyFollower() instead.
|
|
26981
|
-
*
|
|
26982
|
-
* ```js
|
|
26983
|
-
* import { acceptFollower } from '@amityco/ts-sdk'
|
|
26984
|
-
* await acceptFollower('foobar')
|
|
26985
|
-
* ```
|
|
26986
|
-
*
|
|
26987
|
-
* Accept the follow request
|
|
26988
|
-
*
|
|
26989
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
26990
|
-
* @returns A success boolean if the follow request was accepted
|
|
26991
|
-
*
|
|
26992
|
-
* @category Follow API
|
|
26993
|
-
* @async
|
|
26994
|
-
*/
|
|
26995
|
-
const acceptFollower = async (userId) => {
|
|
26996
|
-
const client = getActiveClient();
|
|
26997
|
-
client.log('follow/acceptFollower', userId);
|
|
26998
|
-
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
26999
|
-
if (client.cache) {
|
|
27000
|
-
ingestInCache(data);
|
|
27001
|
-
}
|
|
27002
|
-
const payload = prepareFollowStatusPayload(data);
|
|
27003
|
-
fireEvent('local.follow.accepted', payload);
|
|
27004
|
-
return true;
|
|
27005
|
-
};
|
|
27006
|
-
|
|
27007
|
-
/* begin_public_function
|
|
27008
|
-
id: user.relationship.accept_follow
|
|
27009
|
-
*/
|
|
27010
|
-
/**
|
|
27011
|
-
* ```js
|
|
27012
|
-
* import { UserRepository } from '@amityco/ts-sdk'
|
|
27013
|
-
* await UserRepository.Relationship.acceptMyFollower('foobar')
|
|
27014
|
-
* ```
|
|
27015
|
-
*
|
|
27016
|
-
* Accept the follow request
|
|
27017
|
-
*
|
|
27018
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
27019
|
-
* @returns A success boolean if the follow request was accepted
|
|
27020
|
-
*
|
|
27021
|
-
* @category Follow API
|
|
27022
|
-
* @async
|
|
27023
|
-
*/
|
|
27024
|
-
const acceptMyFollower = async (userId) => {
|
|
27025
|
-
const client = getActiveClient();
|
|
27026
|
-
client.log('follow/acceptMyFollower', userId);
|
|
27027
|
-
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
27028
|
-
if (client.cache) {
|
|
27029
|
-
ingestInCache(data);
|
|
26359
|
+
let token;
|
|
26360
|
+
if (direction === 'prev')
|
|
26361
|
+
token = this.previousToken;
|
|
26362
|
+
if (direction === 'next')
|
|
26363
|
+
token = this.nextToken;
|
|
26364
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
26365
|
+
if (direction === 'first') {
|
|
26366
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
26367
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
26368
|
+
}
|
|
26369
|
+
if (direction === 'prev')
|
|
26370
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
26371
|
+
if (direction === 'next')
|
|
26372
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
26373
|
+
return queryResponse;
|
|
27030
26374
|
}
|
|
27031
|
-
|
|
27032
|
-
|
|
27033
|
-
return true;
|
|
27034
|
-
};
|
|
27035
|
-
/* end_public_function */
|
|
27036
|
-
|
|
27037
|
-
/**
|
|
27038
|
-
* @deprecated This API renamed to `declineMyFollower`.
|
|
27039
|
-
* Please use declineMyFollower() instead.
|
|
27040
|
-
*
|
|
27041
|
-
* ```js
|
|
27042
|
-
* import { declineFollower } from '@amityco/ts-sdk'
|
|
27043
|
-
* await declineFollower('foobar')
|
|
27044
|
-
* ```
|
|
27045
|
-
*
|
|
27046
|
-
* Decline the follow request or delete the follower
|
|
27047
|
-
*
|
|
27048
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
27049
|
-
* @returns A success boolean if the follow request was decline
|
|
27050
|
-
*
|
|
27051
|
-
* @category Follow API
|
|
27052
|
-
* @async
|
|
27053
|
-
*/
|
|
27054
|
-
const declineFollower = async (userId) => {
|
|
27055
|
-
const client = getActiveClient();
|
|
27056
|
-
client.log('follow/declineFollower', userId);
|
|
27057
|
-
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
27058
|
-
if (client.cache) {
|
|
27059
|
-
ingestInCache(data);
|
|
26375
|
+
getNextToken() {
|
|
26376
|
+
return this.nextToken;
|
|
27060
26377
|
}
|
|
27061
|
-
|
|
27062
|
-
|
|
27063
|
-
return true;
|
|
27064
|
-
};
|
|
27065
|
-
|
|
27066
|
-
/* begin_public_function
|
|
27067
|
-
id: user.relationship.decline_follow
|
|
27068
|
-
*/
|
|
27069
|
-
/**
|
|
27070
|
-
* ```js
|
|
27071
|
-
* import { UserRepository } from '@amityco/ts-sdk'
|
|
27072
|
-
* await UserRepository.Relationship.declineMyFollower('foobar')
|
|
27073
|
-
* ```
|
|
27074
|
-
*
|
|
27075
|
-
* Decline the follow request or delete the follower
|
|
27076
|
-
*
|
|
27077
|
-
* @param userId the ID of the {@link Amity.InternalUser} follower
|
|
27078
|
-
* @returns A success boolean if the follow request was decline
|
|
27079
|
-
*
|
|
27080
|
-
* @category Follow API
|
|
27081
|
-
* @async
|
|
27082
|
-
*/
|
|
27083
|
-
const declineMyFollower = async (userId) => {
|
|
27084
|
-
const client = getActiveClient();
|
|
27085
|
-
client.log('follow/declineMyFollower', userId);
|
|
27086
|
-
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
27087
|
-
if (client.cache) {
|
|
27088
|
-
ingestInCache(data);
|
|
26378
|
+
getPrevToken() {
|
|
26379
|
+
return this.previousToken;
|
|
27089
26380
|
}
|
|
27090
|
-
|
|
27091
|
-
fireEvent('local.follow.requestDeclined', payload);
|
|
27092
|
-
return true;
|
|
27093
|
-
};
|
|
27094
|
-
/* end_public_function */
|
|
27095
|
-
|
|
27096
|
-
/**
|
|
27097
|
-
* ```js
|
|
27098
|
-
* import { observeFollowInfo } from '@amityco/ts-sdk'
|
|
27099
|
-
*
|
|
27100
|
-
* let followInfo = {}
|
|
27101
|
-
* const dispose = observeFollowInfo(userId, updated => followInfo = updated)
|
|
27102
|
-
* ```
|
|
27103
|
-
*
|
|
27104
|
-
* Observe all mutation on a given {@link Amity.FollowInfo}
|
|
27105
|
-
*
|
|
27106
|
-
* @param userId the ID of the user to observe
|
|
27107
|
-
* @param callback the function to call when new data are available
|
|
27108
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
|
|
27109
|
-
*
|
|
27110
|
-
* @category Follow Observer
|
|
27111
|
-
*/
|
|
27112
|
-
const observeFollowInfo = (userId, callback, policy = 'cache_then_server') => {
|
|
27113
|
-
const { log } = getActiveClient();
|
|
27114
|
-
const timestamp = Date.now();
|
|
27115
|
-
log(`observeFollowInfo(tmpid: ${timestamp}) > listen`);
|
|
27116
|
-
const router = (result, action) => {
|
|
27117
|
-
var _a, _b;
|
|
27118
|
-
if (callback instanceof Function)
|
|
27119
|
-
return callback(result);
|
|
27120
|
-
if (action !== 'onFetch')
|
|
27121
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
27122
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
27123
|
-
};
|
|
27124
|
-
const realtimeRouter = (result, action) => {
|
|
27125
|
-
var _a;
|
|
27126
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
|
|
27127
|
-
return;
|
|
27128
|
-
router(result, action);
|
|
27129
|
-
};
|
|
27130
|
-
const disposers = [];
|
|
27131
|
-
disposers.push(onFollowInfoUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')));
|
|
27132
|
-
runQuery(createQuery(getFollowInfo$1, userId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
27133
|
-
return () => {
|
|
27134
|
-
log(`observeFollowInfo(tmpid: ${timestamp}) > dispose`);
|
|
27135
|
-
disposers.forEach(fn => fn());
|
|
27136
|
-
};
|
|
27137
|
-
};
|
|
27138
|
-
|
|
27139
|
-
/**
|
|
27140
|
-
* ```js
|
|
27141
|
-
* import { observeFollowers } from '@amityco/ts-sdk'
|
|
27142
|
-
*
|
|
27143
|
-
* let followers = []
|
|
27144
|
-
* const unsub = observeFollowers('userId', follower => merge(followers, follower))
|
|
27145
|
-
* ```
|
|
27146
|
-
*
|
|
27147
|
-
* Observe all mutations on a list of followers {@link Amity.FollowStatus} for a given user
|
|
27148
|
-
*
|
|
27149
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
27150
|
-
* @param callback the function to call when new data are available
|
|
27151
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
27152
|
-
*
|
|
27153
|
-
* @category Follow Observer
|
|
27154
|
-
*/
|
|
27155
|
-
const observeFollowers = (userId, callback) => {
|
|
27156
|
-
const { log } = getActiveClient();
|
|
27157
|
-
const timestamp = Date.now();
|
|
27158
|
-
log(`observeFollowers(tmpid: ${timestamp}) > listen`);
|
|
27159
|
-
const disposers = [];
|
|
27160
|
-
const router = (status, action) => {
|
|
27161
|
-
var _a, _b;
|
|
27162
|
-
if (callback instanceof Function) {
|
|
27163
|
-
return callback(status);
|
|
27164
|
-
}
|
|
27165
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
27166
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
27167
|
-
};
|
|
27168
|
-
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')));
|
|
27169
|
-
return () => {
|
|
27170
|
-
log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
|
|
27171
|
-
disposers.forEach(fn => fn());
|
|
27172
|
-
};
|
|
27173
|
-
};
|
|
27174
|
-
|
|
27175
|
-
/**
|
|
27176
|
-
* ```js
|
|
27177
|
-
* import { observeFollowings } from '@amityco/ts-sdk'
|
|
27178
|
-
*
|
|
27179
|
-
* let followings = []
|
|
27180
|
-
* const unsub = observeFollowers('userId', follower => merge(followings, following))
|
|
27181
|
-
* ```
|
|
27182
|
-
*
|
|
27183
|
-
* Observe all mutations on a list of followings {@link Amity.FollowStatus} for a given user
|
|
27184
|
-
*
|
|
27185
|
-
* @param userId the ID of the {@link Amity.InternalUser}
|
|
27186
|
-
* @param callback the function to call when new data are available
|
|
27187
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
27188
|
-
*
|
|
27189
|
-
* @category Follow Observer
|
|
27190
|
-
*/
|
|
27191
|
-
const observeFollowings = (userId, callback) => {
|
|
27192
|
-
const { log } = getActiveClient();
|
|
27193
|
-
const timestamp = Date.now();
|
|
27194
|
-
log(`observeFollowings(tmpid: ${timestamp}) > listen`);
|
|
27195
|
-
const disposers = [];
|
|
27196
|
-
const router = (status, action) => {
|
|
27197
|
-
var _a, _b;
|
|
27198
|
-
if (callback instanceof Function) {
|
|
27199
|
-
return callback(status);
|
|
27200
|
-
}
|
|
27201
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
27202
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
27203
|
-
};
|
|
27204
|
-
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')));
|
|
27205
|
-
return () => {
|
|
27206
|
-
log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
|
|
27207
|
-
disposers.forEach(fn => fn());
|
|
27208
|
-
};
|
|
27209
|
-
};
|
|
26381
|
+
}
|
|
27210
26382
|
|
|
27211
26383
|
class FollowerPaginationController extends PaginationController {
|
|
27212
26384
|
async getRequest(queryParams, token) {
|
|
@@ -27221,6 +26393,25 @@ class FollowerPaginationController extends PaginationController {
|
|
|
27221
26393
|
}
|
|
27222
26394
|
}
|
|
27223
26395
|
|
|
26396
|
+
class QueryStreamController {
|
|
26397
|
+
constructor(query, cacheKey) {
|
|
26398
|
+
this.query = query;
|
|
26399
|
+
this.cacheKey = cacheKey;
|
|
26400
|
+
}
|
|
26401
|
+
}
|
|
26402
|
+
|
|
26403
|
+
var EnumFollowActions;
|
|
26404
|
+
(function (EnumFollowActions) {
|
|
26405
|
+
EnumFollowActions["OnRequested"] = "onRequested";
|
|
26406
|
+
EnumFollowActions["OnAccepted"] = "onAccepted";
|
|
26407
|
+
EnumFollowActions["OnDeclined"] = "onDeclined";
|
|
26408
|
+
EnumFollowActions["OnCanceled"] = "onCanceled";
|
|
26409
|
+
EnumFollowActions["OnFollowed"] = "onFollowed";
|
|
26410
|
+
EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
|
|
26411
|
+
EnumFollowActions["OnDeleted"] = "onDeleted";
|
|
26412
|
+
EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
|
|
26413
|
+
})(EnumFollowActions || (EnumFollowActions = {}));
|
|
26414
|
+
|
|
27224
26415
|
class FollowerQueryStreamController extends QueryStreamController {
|
|
27225
26416
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27226
26417
|
super(query, cacheKey);
|
|
@@ -27276,6 +26467,109 @@ class FollowerQueryStreamController extends QueryStreamController {
|
|
|
27276
26467
|
}
|
|
27277
26468
|
}
|
|
27278
26469
|
|
|
26470
|
+
class PaginationNoPageController {
|
|
26471
|
+
constructor(queryParams) {
|
|
26472
|
+
const { http } = getActiveClient();
|
|
26473
|
+
this.queryParams = queryParams;
|
|
26474
|
+
this.http = http;
|
|
26475
|
+
}
|
|
26476
|
+
async onFetch() {
|
|
26477
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
26478
|
+
return queryResponse;
|
|
26479
|
+
}
|
|
26480
|
+
}
|
|
26481
|
+
|
|
26482
|
+
class LiveCollectionController {
|
|
26483
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
26484
|
+
this.paginationController = paginationController;
|
|
26485
|
+
this.queryStreamId = queryStreamId;
|
|
26486
|
+
this.cacheKey = cacheKey;
|
|
26487
|
+
this.callback = callback;
|
|
26488
|
+
}
|
|
26489
|
+
async refresh() {
|
|
26490
|
+
try {
|
|
26491
|
+
let result;
|
|
26492
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
26493
|
+
result = await this.paginationController.onFetch();
|
|
26494
|
+
}
|
|
26495
|
+
else {
|
|
26496
|
+
result = await this.paginationController.loadFirstPage();
|
|
26497
|
+
}
|
|
26498
|
+
if (!result)
|
|
26499
|
+
return;
|
|
26500
|
+
await this.persistModel(result);
|
|
26501
|
+
this.persistQueryStream({
|
|
26502
|
+
response: result,
|
|
26503
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26504
|
+
refresh: true,
|
|
26505
|
+
});
|
|
26506
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26507
|
+
}
|
|
26508
|
+
catch (e) {
|
|
26509
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26510
|
+
}
|
|
26511
|
+
}
|
|
26512
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
26513
|
+
this.setup();
|
|
26514
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
26515
|
+
if (initial) {
|
|
26516
|
+
this.refresh();
|
|
26517
|
+
}
|
|
26518
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
26519
|
+
this.loadPrevPage();
|
|
26520
|
+
}
|
|
26521
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
26522
|
+
this.loadNextPage();
|
|
26523
|
+
}
|
|
26524
|
+
}
|
|
26525
|
+
async loadNextPage() {
|
|
26526
|
+
try {
|
|
26527
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
26528
|
+
return;
|
|
26529
|
+
const result = await this.paginationController.loadNextPage();
|
|
26530
|
+
if (!result)
|
|
26531
|
+
return;
|
|
26532
|
+
await this.persistModel(result);
|
|
26533
|
+
this.persistQueryStream({
|
|
26534
|
+
response: result,
|
|
26535
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26536
|
+
});
|
|
26537
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26538
|
+
}
|
|
26539
|
+
catch (e) {
|
|
26540
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26541
|
+
}
|
|
26542
|
+
}
|
|
26543
|
+
async loadPrevPage() {
|
|
26544
|
+
try {
|
|
26545
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
26546
|
+
return;
|
|
26547
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
26548
|
+
if (!result)
|
|
26549
|
+
return;
|
|
26550
|
+
await this.persistModel(result);
|
|
26551
|
+
this.persistQueryStream({
|
|
26552
|
+
response: result,
|
|
26553
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
26554
|
+
});
|
|
26555
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26556
|
+
}
|
|
26557
|
+
catch (e) {
|
|
26558
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26559
|
+
}
|
|
26560
|
+
}
|
|
26561
|
+
shouldNotify(data) {
|
|
26562
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
26563
|
+
if (isEqual(this.snapshot, newData))
|
|
26564
|
+
return false;
|
|
26565
|
+
this.snapshot = newData;
|
|
26566
|
+
return true;
|
|
26567
|
+
}
|
|
26568
|
+
getCacheKey() {
|
|
26569
|
+
return this.cacheKey;
|
|
26570
|
+
}
|
|
26571
|
+
}
|
|
26572
|
+
|
|
27279
26573
|
const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
27280
26574
|
const client = getActiveClient();
|
|
27281
26575
|
const filter = (data) => {
|
|
@@ -27620,6 +26914,69 @@ const getFollowings = (params, callback, config) => {
|
|
|
27620
26914
|
};
|
|
27621
26915
|
/* end_public_function */
|
|
27622
26916
|
|
|
26917
|
+
/**
|
|
26918
|
+
* @deprecated This function will to be deprecated soon.
|
|
26919
|
+
*/
|
|
26920
|
+
const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
|
|
26921
|
+
const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
|
|
26922
|
+
const { cache } = getActiveClient();
|
|
26923
|
+
if (!cache) {
|
|
26924
|
+
console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
|
|
26925
|
+
}
|
|
26926
|
+
let model;
|
|
26927
|
+
let isUnsyncedModel = false; // for messages
|
|
26928
|
+
const disposers = [];
|
|
26929
|
+
const dispatcher = (data) => {
|
|
26930
|
+
const { data: newModel } = data, rest = __rest(data, ["data"]);
|
|
26931
|
+
if (!callbackFilter || callbackFilter(newModel, model)) {
|
|
26932
|
+
callback(Object.assign({ data: callbackDataSelector(newModel) }, rest));
|
|
26933
|
+
}
|
|
26934
|
+
// resolve all getter on data model to a static value to avoid comparison problems
|
|
26935
|
+
model = convertGetterPropsToStatic(newModel);
|
|
26936
|
+
};
|
|
26937
|
+
const realtimeRouter = (eventModel, forceDispatch = false) => {
|
|
26938
|
+
if (id !== eventModel[key]) {
|
|
26939
|
+
return;
|
|
26940
|
+
}
|
|
26941
|
+
if (model) {
|
|
26942
|
+
if (!forceDispatch && isEqual(model, eventModel)) {
|
|
26943
|
+
return;
|
|
26944
|
+
}
|
|
26945
|
+
}
|
|
26946
|
+
dispatcher({ loading: false, data: eventModel, origin: 'event' });
|
|
26947
|
+
};
|
|
26948
|
+
const onFetch = () => {
|
|
26949
|
+
// TODO: Ihis `@ts-ignore` is bring back to fix the build and it needs to be removed later
|
|
26950
|
+
// @ts-ignore
|
|
26951
|
+
const query = createQuery(fetcher, id, true);
|
|
26952
|
+
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
26953
|
+
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
26954
|
+
dispatcher({
|
|
26955
|
+
// @ts-ignore
|
|
26956
|
+
data,
|
|
26957
|
+
origin,
|
|
26958
|
+
loading: false,
|
|
26959
|
+
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
26960
|
+
});
|
|
26961
|
+
isUnsyncedModel = true;
|
|
26962
|
+
disposers.forEach(fn => fn());
|
|
26963
|
+
}
|
|
26964
|
+
else if (!isUnsyncedModel) {
|
|
26965
|
+
// @ts-ignore
|
|
26966
|
+
dispatcher({ loading, data, origin, error });
|
|
26967
|
+
}
|
|
26968
|
+
if (error) {
|
|
26969
|
+
disposers.forEach(fn => fn());
|
|
26970
|
+
}
|
|
26971
|
+
});
|
|
26972
|
+
};
|
|
26973
|
+
disposers.push(...eventHandlers.map(fn => fn(eventModel => realtimeRouter(eventModel, forceDispatch))));
|
|
26974
|
+
onFetch();
|
|
26975
|
+
return () => {
|
|
26976
|
+
disposers.forEach(fn => fn());
|
|
26977
|
+
};
|
|
26978
|
+
};
|
|
26979
|
+
|
|
27623
26980
|
/* begin_public_function
|
|
27624
26981
|
id: user.relationship.get_follow_info
|
|
27625
26982
|
*/
|
|
@@ -27685,12 +27042,9 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
27685
27042
|
__proto__: null,
|
|
27686
27043
|
blockUser: blockUser,
|
|
27687
27044
|
unBlockUser: unBlockUser,
|
|
27688
|
-
getBlockedUsers: getBlockedUsers,
|
|
27689
27045
|
follow: follow,
|
|
27690
27046
|
unfollow: unfollow,
|
|
27691
|
-
acceptFollower: acceptFollower,
|
|
27692
27047
|
acceptMyFollower: acceptMyFollower,
|
|
27693
|
-
declineFollower: declineFollower,
|
|
27694
27048
|
declineMyFollower: declineMyFollower,
|
|
27695
27049
|
onUserFollowed: onUserFollowed,
|
|
27696
27050
|
onUserUnfollowed: onUserUnfollowed,
|
|
@@ -27705,9 +27059,6 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
27705
27059
|
onLocalFollowerRequested: onLocalFollowerRequested,
|
|
27706
27060
|
onLocalFollowRequestAccepted: onLocalFollowRequestAccepted,
|
|
27707
27061
|
onLocalFollowRequestDeclined: onLocalFollowRequestDeclined,
|
|
27708
|
-
observeFollowInfo: observeFollowInfo,
|
|
27709
|
-
observeFollowers: observeFollowers,
|
|
27710
|
-
observeFollowings: observeFollowings,
|
|
27711
27062
|
getFollowers: getFollowers,
|
|
27712
27063
|
getFollowings: getFollowings,
|
|
27713
27064
|
getFollowInfo: getFollowInfo,
|
|
@@ -27895,6 +27246,74 @@ const isUserFlaggedByMe = async (userId) => {
|
|
|
27895
27246
|
};
|
|
27896
27247
|
/* end_public_function */
|
|
27897
27248
|
|
|
27249
|
+
/**
|
|
27250
|
+
* ```js
|
|
27251
|
+
* import { onUserUpdated } from '@amityco/ts-sdk'
|
|
27252
|
+
* const dispose = onUserUpdated(user => {
|
|
27253
|
+
* // ...
|
|
27254
|
+
* })
|
|
27255
|
+
* ```
|
|
27256
|
+
*
|
|
27257
|
+
* Fired when a {@link Amity.InternalUser} has been updated
|
|
27258
|
+
*
|
|
27259
|
+
* @param callback The function to call when the event was fired
|
|
27260
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27261
|
+
*
|
|
27262
|
+
* @category User Events
|
|
27263
|
+
*/
|
|
27264
|
+
const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
|
|
27265
|
+
|
|
27266
|
+
/**
|
|
27267
|
+
* ```js
|
|
27268
|
+
* import { onUserFlagged } from '@amityco/ts-sdk'
|
|
27269
|
+
* const dispose = onUserFlagged(user => {
|
|
27270
|
+
* // ...
|
|
27271
|
+
* })
|
|
27272
|
+
* ```
|
|
27273
|
+
*
|
|
27274
|
+
* Fired when a {@link Amity.InternalUser} has been flagged
|
|
27275
|
+
*
|
|
27276
|
+
* @param callback The function to call when the event was fired
|
|
27277
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27278
|
+
*
|
|
27279
|
+
* @category User Events
|
|
27280
|
+
*/
|
|
27281
|
+
const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
|
|
27282
|
+
|
|
27283
|
+
/**
|
|
27284
|
+
* ```js
|
|
27285
|
+
* import { onUserUnflagged } from '@amityco/ts-sdk'
|
|
27286
|
+
* const dispose = onUserUnflagged(user => {
|
|
27287
|
+
* // ...
|
|
27288
|
+
* })
|
|
27289
|
+
* ```
|
|
27290
|
+
*
|
|
27291
|
+
* Fired when a flag has been removed from a {@link Amity.InternalUser}
|
|
27292
|
+
*
|
|
27293
|
+
* @param callback The function to call when the event was fired
|
|
27294
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27295
|
+
*
|
|
27296
|
+
* @category User Events
|
|
27297
|
+
*/
|
|
27298
|
+
const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
|
|
27299
|
+
|
|
27300
|
+
/**
|
|
27301
|
+
* ```js
|
|
27302
|
+
* import { onUserFlagCleared } from '@amityco/ts-sdk'
|
|
27303
|
+
* const dispose = onUserFlagCleared(user => {
|
|
27304
|
+
* // ...
|
|
27305
|
+
* })
|
|
27306
|
+
* ```
|
|
27307
|
+
*
|
|
27308
|
+
* Fired when flags have been cleared for a {@link Amity.InternalUser}
|
|
27309
|
+
*
|
|
27310
|
+
* @param callback The function to call when the event was fired
|
|
27311
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27312
|
+
*
|
|
27313
|
+
* @category User Events
|
|
27314
|
+
*/
|
|
27315
|
+
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
27316
|
+
|
|
27898
27317
|
/**
|
|
27899
27318
|
* ```js
|
|
27900
27319
|
* import { onUserFetched } from '@amityco/ts-sdk'
|
|
@@ -27926,7 +27345,7 @@ const onUserFetched = (callback) => createUserEventSubscriber('user.fetched', ca
|
|
|
27926
27345
|
* @category Private
|
|
27927
27346
|
* @async
|
|
27928
27347
|
*/
|
|
27929
|
-
const getUser$
|
|
27348
|
+
const getUser$1 = async (userId) => {
|
|
27930
27349
|
const client = getActiveClient();
|
|
27931
27350
|
client.log('user/getUser', userId);
|
|
27932
27351
|
isInTombstone('user', userId);
|
|
@@ -27962,7 +27381,7 @@ const getUser$2 = async (userId) => {
|
|
|
27962
27381
|
*
|
|
27963
27382
|
* @category User API
|
|
27964
27383
|
*/
|
|
27965
|
-
getUser$
|
|
27384
|
+
getUser$1.locally = (userId) => {
|
|
27966
27385
|
const client = getActiveClient();
|
|
27967
27386
|
client.log('user/getUser.locally', userId);
|
|
27968
27387
|
if (!client.cache)
|
|
@@ -27998,11 +27417,11 @@ getUser$2.locally = (userId) => {
|
|
|
27998
27417
|
*
|
|
27999
27418
|
* @category Message Live Object
|
|
28000
27419
|
*/
|
|
28001
|
-
const getUser
|
|
27420
|
+
const getUser = (userId, callback) => {
|
|
28002
27421
|
const reactor = (response) => {
|
|
28003
27422
|
return callback(Object.assign(Object.assign({}, response), { data: response.data ? LinkedObject.user(response.data) : response.data }));
|
|
28004
27423
|
};
|
|
28005
|
-
return liveObject(userId, reactor, 'userId', getUser$
|
|
27424
|
+
return liveObject(userId, reactor, 'userId', getUser$1, [
|
|
28006
27425
|
onUserFetched,
|
|
28007
27426
|
onUserUpdated,
|
|
28008
27427
|
onUserDeleted$2,
|
|
@@ -28015,10 +27434,10 @@ const getUser$1 = (userId, callback) => {
|
|
|
28015
27434
|
|
|
28016
27435
|
class UserPaginationController extends PaginationController {
|
|
28017
27436
|
async getRequest(queryParams, token) {
|
|
28018
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT
|
|
27437
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
28019
27438
|
const options = token ? { token } : { limit };
|
|
28020
27439
|
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
28021
|
-
params: Object.assign(Object.assign({}, params), {
|
|
27440
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
28022
27441
|
});
|
|
28023
27442
|
return queryResponse;
|
|
28024
27443
|
}
|
|
@@ -28070,6 +27489,15 @@ class UserQueryStreamController extends QueryStreamController {
|
|
|
28070
27489
|
}
|
|
28071
27490
|
}
|
|
28072
27491
|
|
|
27492
|
+
var EnumUserActions;
|
|
27493
|
+
(function (EnumUserActions) {
|
|
27494
|
+
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
27495
|
+
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
27496
|
+
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
27497
|
+
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
27498
|
+
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
27499
|
+
})(EnumUserActions || (EnumUserActions = {}));
|
|
27500
|
+
|
|
28073
27501
|
class UserLiveCollectionController extends LiveCollectionController {
|
|
28074
27502
|
constructor(query, callback) {
|
|
28075
27503
|
const queryStreamId = hash(query);
|
|
@@ -28128,21 +27556,17 @@ class UserLiveCollectionController extends LiveCollectionController {
|
|
|
28128
27556
|
}
|
|
28129
27557
|
applyFilter(data) {
|
|
28130
27558
|
let users = data;
|
|
28131
|
-
|
|
28132
|
-
|
|
28133
|
-
|
|
28134
|
-
|
|
28135
|
-
|
|
28136
|
-
|
|
28137
|
-
|
|
28138
|
-
|
|
28139
|
-
|
|
28140
|
-
|
|
28141
|
-
|
|
28142
|
-
}
|
|
28143
|
-
})();
|
|
28144
|
-
users = users.sort(sortFn);
|
|
28145
|
-
}
|
|
27559
|
+
const sortFn = (() => {
|
|
27560
|
+
switch (this.query.sortBy) {
|
|
27561
|
+
case 'firstCreated':
|
|
27562
|
+
return sortByFirstCreated;
|
|
27563
|
+
case 'lastCreated':
|
|
27564
|
+
return sortByLastCreated;
|
|
27565
|
+
default:
|
|
27566
|
+
return sortByLastCreated;
|
|
27567
|
+
}
|
|
27568
|
+
})();
|
|
27569
|
+
users = users.sort(sortFn);
|
|
28146
27570
|
if (this.query.filter === 'flagged') {
|
|
28147
27571
|
users = users.filter(user => !!user.hashFlag);
|
|
28148
27572
|
}
|
|
@@ -28189,90 +27613,200 @@ const getUsers = (params, callback, config) => {
|
|
|
28189
27613
|
};
|
|
28190
27614
|
/* end_public_function */
|
|
28191
27615
|
|
|
28192
|
-
|
|
28193
|
-
|
|
28194
|
-
|
|
28195
|
-
|
|
28196
|
-
|
|
28197
|
-
|
|
28198
|
-
|
|
28199
|
-
|
|
28200
|
-
|
|
28201
|
-
|
|
28202
|
-
|
|
28203
|
-
|
|
28204
|
-
|
|
28205
|
-
|
|
28206
|
-
|
|
28207
|
-
|
|
28208
|
-
|
|
28209
|
-
|
|
28210
|
-
|
|
28211
|
-
|
|
28212
|
-
|
|
28213
|
-
|
|
28214
|
-
|
|
28215
|
-
|
|
28216
|
-
|
|
28217
|
-
|
|
28218
|
-
|
|
28219
|
-
|
|
28220
|
-
|
|
28221
|
-
|
|
28222
|
-
|
|
28223
|
-
|
|
28224
|
-
|
|
28225
|
-
|
|
28226
|
-
|
|
28227
|
-
|
|
28228
|
-
|
|
27616
|
+
class BlockedUserPaginationController extends PaginationController {
|
|
27617
|
+
async getRequest(queryParams, token) {
|
|
27618
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
27619
|
+
const options = token ? { token } : { limit };
|
|
27620
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
27621
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
27622
|
+
});
|
|
27623
|
+
return queryResponse;
|
|
27624
|
+
}
|
|
27625
|
+
}
|
|
27626
|
+
|
|
27627
|
+
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
27628
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27629
|
+
super(query, cacheKey);
|
|
27630
|
+
this.notifyChange = notifyChange;
|
|
27631
|
+
this.preparePayload = preparePayload;
|
|
27632
|
+
}
|
|
27633
|
+
async saveToMainDB(response) {
|
|
27634
|
+
const processedPayload = await this.preparePayload(response);
|
|
27635
|
+
const client = getActiveClient();
|
|
27636
|
+
const cachedAt = client.cache && Date.now();
|
|
27637
|
+
if (client.cache) {
|
|
27638
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27639
|
+
}
|
|
27640
|
+
}
|
|
27641
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27642
|
+
var _a, _b;
|
|
27643
|
+
if (refresh) {
|
|
27644
|
+
pushToCache(this.cacheKey, {
|
|
27645
|
+
data: response.users.map(getResolver('user')),
|
|
27646
|
+
});
|
|
27647
|
+
}
|
|
27648
|
+
else {
|
|
27649
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27650
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27651
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
27652
|
+
}
|
|
27653
|
+
}
|
|
27654
|
+
reactor(action) {
|
|
27655
|
+
return (targetUser) => {
|
|
27656
|
+
var _a;
|
|
27657
|
+
if (action === EnumFollowActions.OnFollowed) {
|
|
27658
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27659
|
+
const updatedCollection = collection === null || collection === void 0 ? void 0 : collection.data.filter(id => id !== targetUser.userId);
|
|
27660
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: updatedCollection }));
|
|
27661
|
+
}
|
|
27662
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27663
|
+
};
|
|
27664
|
+
}
|
|
27665
|
+
subscribeRTE(createSubscriber) {
|
|
27666
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27667
|
+
}
|
|
27668
|
+
}
|
|
27669
|
+
|
|
27670
|
+
function prepareBlockedUserPayload(response) {
|
|
27671
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
27672
|
+
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
27673
|
+
const followUser = users.find(user => user.userId === follow.from);
|
|
27674
|
+
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
27675
|
+
}), users: users.map(convertRawUserToInternalUser) });
|
|
27676
|
+
}
|
|
27677
|
+
|
|
27678
|
+
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
27679
|
+
var _a, _b;
|
|
27680
|
+
if (!sourceModel) {
|
|
27681
|
+
return sourceModel;
|
|
27682
|
+
}
|
|
27683
|
+
const client = getActiveClient();
|
|
27684
|
+
const { objectSyncMap } = client;
|
|
27685
|
+
/*
|
|
27686
|
+
* 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.
|
|
27687
|
+
* 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.
|
|
27688
|
+
*/
|
|
27689
|
+
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
27690
|
+
? sourceModel[sourceModelProp]
|
|
27691
|
+
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
27692
|
+
const model = (_b = pullFromCache([
|
|
27693
|
+
destinationDomain,
|
|
27694
|
+
'get',
|
|
27695
|
+
`${resolvedId}`,
|
|
27696
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
27697
|
+
if (!model)
|
|
28229
27698
|
return;
|
|
28230
|
-
return
|
|
28231
|
-
|
|
28232
|
-
cachedAt: cached.cachedAt,
|
|
28233
|
-
};
|
|
28234
|
-
};
|
|
27699
|
+
return callback(model);
|
|
27700
|
+
});
|
|
28235
27701
|
|
|
27702
|
+
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
27703
|
+
constructor(query, callback) {
|
|
27704
|
+
const queryStreamId = hash(query);
|
|
27705
|
+
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
27706
|
+
const paginationController = new BlockedUserPaginationController(query);
|
|
27707
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27708
|
+
this.query = query;
|
|
27709
|
+
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
27710
|
+
this.callback = callback.bind(this);
|
|
27711
|
+
this.loadPage({ initial: true });
|
|
27712
|
+
}
|
|
27713
|
+
setup() {
|
|
27714
|
+
var _a;
|
|
27715
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27716
|
+
if (!collection) {
|
|
27717
|
+
pushToCache(this.cacheKey, {
|
|
27718
|
+
data: [],
|
|
27719
|
+
params: {},
|
|
27720
|
+
});
|
|
27721
|
+
}
|
|
27722
|
+
}
|
|
27723
|
+
async persistModel(queryPayload) {
|
|
27724
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27725
|
+
}
|
|
27726
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27727
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27728
|
+
}
|
|
27729
|
+
startSubscription() {
|
|
27730
|
+
return this.queryStreamController.subscribeRTE([
|
|
27731
|
+
{
|
|
27732
|
+
fn: onUserDeleted$2,
|
|
27733
|
+
action: EnumUserActions.OnUserDeleted,
|
|
27734
|
+
},
|
|
27735
|
+
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
27736
|
+
{
|
|
27737
|
+
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
27738
|
+
action: EnumFollowActions.OnFollowed,
|
|
27739
|
+
},
|
|
27740
|
+
{
|
|
27741
|
+
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
27742
|
+
action: EnumFollowActions.OnFollowed,
|
|
27743
|
+
},
|
|
27744
|
+
]);
|
|
27745
|
+
}
|
|
27746
|
+
notifyChange({ origin, loading, error }) {
|
|
27747
|
+
var _a, _b;
|
|
27748
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27749
|
+
if (!collection)
|
|
27750
|
+
return;
|
|
27751
|
+
const data = this.applyFilter((_b = collection.data
|
|
27752
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
27753
|
+
.filter(isNonNullable)
|
|
27754
|
+
.map(({ data }) => data)
|
|
27755
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
27756
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
27757
|
+
return;
|
|
27758
|
+
this.callback({
|
|
27759
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
27760
|
+
data,
|
|
27761
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
27762
|
+
loading,
|
|
27763
|
+
error,
|
|
27764
|
+
});
|
|
27765
|
+
}
|
|
27766
|
+
// eslint-disable-next-line class-methods-use-this
|
|
27767
|
+
applyFilter(data) {
|
|
27768
|
+
let users = data;
|
|
27769
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
27770
|
+
return users;
|
|
27771
|
+
}
|
|
27772
|
+
}
|
|
27773
|
+
|
|
27774
|
+
/* begin_public_function
|
|
27775
|
+
id: user.get_blocked_users
|
|
27776
|
+
*/
|
|
28236
27777
|
/**
|
|
28237
27778
|
* ```js
|
|
28238
|
-
* import {
|
|
28239
|
-
*
|
|
28240
|
-
* let user = {}
|
|
28241
|
-
* const dispose = observeUser(userId, updated => user = updated)
|
|
27779
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
27780
|
+
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
28242
27781
|
* ```
|
|
28243
27782
|
*
|
|
28244
|
-
*
|
|
28245
|
-
*
|
|
28246
|
-
* @
|
|
27783
|
+
* Blocks a {@link Amity.InternalUser}
|
|
27784
|
+
*
|
|
27785
|
+
* @param params The params to get blocked {@link Amity.InternalUser}s
|
|
27786
|
+
* @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
|
|
27787
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
28247
27788
|
*
|
|
28248
|
-
*
|
|
28249
|
-
* @
|
|
27789
|
+
* @category Post API
|
|
27790
|
+
* @async
|
|
28250
27791
|
*/
|
|
28251
|
-
const
|
|
28252
|
-
const { log } = getActiveClient();
|
|
27792
|
+
const getBlockedUsers = (params, callback, config) => {
|
|
27793
|
+
const { log, cache } = getActiveClient();
|
|
27794
|
+
if (!cache) {
|
|
27795
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
27796
|
+
}
|
|
28253
27797
|
const timestamp = Date.now();
|
|
28254
|
-
log(`
|
|
28255
|
-
|
|
28256
|
-
const
|
|
28257
|
-
|
|
28258
|
-
|
|
28259
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
|
|
28260
|
-
return;
|
|
28261
|
-
const newResult = Object.assign(Object.assign({}, result), { data: LinkedObject.user(result.data) });
|
|
28262
|
-
if (callback instanceof Function)
|
|
28263
|
-
return callback(newResult);
|
|
28264
|
-
if (action !== 'onFetch')
|
|
28265
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, newResult);
|
|
28266
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, newResult);
|
|
28267
|
-
};
|
|
28268
|
-
const disposers = [];
|
|
28269
|
-
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')));
|
|
28270
|
-
runQuery(createQuery(getUser, userId), result => result.data && router(result, 'onFetch'));
|
|
27798
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
27799
|
+
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
27800
|
+
const disposers = blockedUserLiveCollection.startSubscription();
|
|
27801
|
+
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
27802
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
28271
27803
|
return () => {
|
|
28272
|
-
log(`
|
|
27804
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
28273
27805
|
disposers.forEach(fn => fn());
|
|
27806
|
+
dropFromCache(cacheKey);
|
|
28274
27807
|
};
|
|
28275
|
-
};
|
|
27808
|
+
};
|
|
27809
|
+
/* end_public_function */
|
|
28276
27810
|
|
|
28277
27811
|
class SearchUserPaginationController extends PaginationController {
|
|
28278
27812
|
async getRequest(queryParams, token) {
|
|
@@ -28457,74 +27991,6 @@ const queryReachUser = async ({ viewId, viewedType, limit, token, }) => {
|
|
|
28457
27991
|
return response.data;
|
|
28458
27992
|
};
|
|
28459
27993
|
|
|
28460
|
-
/**
|
|
28461
|
-
* @deprecated: Please use {@link UserRepository.getReachUsers} instead
|
|
28462
|
-
* @param params
|
|
28463
|
-
* @param callback
|
|
28464
|
-
*/
|
|
28465
|
-
const getViewedUsers = (params, callback) => {
|
|
28466
|
-
const { log, cache } = getActiveClient();
|
|
28467
|
-
const cacheKey = ['postViewedUsers', 'collection', { postId: params.postId }];
|
|
28468
|
-
if (!cache) {
|
|
28469
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
28470
|
-
}
|
|
28471
|
-
const timestamp = Date.now();
|
|
28472
|
-
log(`getViewedUsers(tmpid: ${timestamp}) > listen`);
|
|
28473
|
-
const { limit: queryLimit, postId } = params;
|
|
28474
|
-
const responder = (snapshot) => {
|
|
28475
|
-
var _a, _b;
|
|
28476
|
-
let users = [];
|
|
28477
|
-
if (snapshot === null || snapshot === void 0 ? void 0 : snapshot.data) {
|
|
28478
|
-
users =
|
|
28479
|
-
snapshot.data
|
|
28480
|
-
.map((userId) => pullFromCache(['user', 'get', userId]))
|
|
28481
|
-
.filter(Boolean)
|
|
28482
|
-
.map(data => data === null || data === void 0 ? void 0 : data.data) || [];
|
|
28483
|
-
}
|
|
28484
|
-
callback({
|
|
28485
|
-
// eslint-disable-next-line no-use-before-define
|
|
28486
|
-
onNextPage: onFetch,
|
|
28487
|
-
data: users,
|
|
28488
|
-
hasNextPage: !!((_b = (_a = snapshot.params) === null || _a === void 0 ? void 0 : _a.page) === null || _b === void 0 ? void 0 : _b.next),
|
|
28489
|
-
loading: snapshot.loading || false,
|
|
28490
|
-
});
|
|
28491
|
-
};
|
|
28492
|
-
const onFetch = (initial = false) => {
|
|
28493
|
-
var _a, _b, _c;
|
|
28494
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28495
|
-
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
28496
|
-
if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
28497
|
-
return;
|
|
28498
|
-
const query = createQuery(queryReachUser, {
|
|
28499
|
-
viewId: postId,
|
|
28500
|
-
viewedType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
28501
|
-
limit: queryLimit || 10,
|
|
28502
|
-
token: !initial ? (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) === null || _c === void 0 ? void 0 : _c.next : undefined,
|
|
28503
|
-
});
|
|
28504
|
-
runQuery(query, result => {
|
|
28505
|
-
var _a, _b, _c, _d, _e;
|
|
28506
|
-
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 : [];
|
|
28507
|
-
if ((_d = result.data) === null || _d === void 0 ? void 0 : _d.users) {
|
|
28508
|
-
userIds = [
|
|
28509
|
-
...new Set([...userIds, ...result.data.users.map(({ userId }) => userId)]),
|
|
28510
|
-
];
|
|
28511
|
-
}
|
|
28512
|
-
const saveToCache = {
|
|
28513
|
-
loading: result.loading,
|
|
28514
|
-
params: { page: (_e = result.data) === null || _e === void 0 ? void 0 : _e.paging },
|
|
28515
|
-
data: userIds || [],
|
|
28516
|
-
};
|
|
28517
|
-
pushToCache(cacheKey, saveToCache);
|
|
28518
|
-
responder(saveToCache);
|
|
28519
|
-
}, queryOptions(COLLECTION_DEFAULT_CACHING_POLICY, CACHE_SHORTEN_LIFESPAN));
|
|
28520
|
-
};
|
|
28521
|
-
onFetch(true);
|
|
28522
|
-
return () => {
|
|
28523
|
-
log(`getViewedUsers(tmpid: ${timestamp}) > dispose`);
|
|
28524
|
-
dropFromCache(cacheKey);
|
|
28525
|
-
};
|
|
28526
|
-
};
|
|
28527
|
-
|
|
28528
27994
|
const getReachedUsers = (params, callback) => {
|
|
28529
27995
|
// Pre-defined function to avoid undefined function call
|
|
28530
27996
|
let onFetch = (initial = false) => undefined;
|
|
@@ -28612,12 +28078,10 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
28612
28078
|
onUserFlagged: onUserFlagged,
|
|
28613
28079
|
onUserUnflagged: onUserUnflagged,
|
|
28614
28080
|
onUserFlagCleared: onUserFlagCleared,
|
|
28615
|
-
getUser: getUser
|
|
28081
|
+
getUser: getUser,
|
|
28616
28082
|
getUsers: getUsers,
|
|
28617
|
-
|
|
28618
|
-
getBlockedUsers: getBlockedUsers$1,
|
|
28083
|
+
getBlockedUsers: getBlockedUsers,
|
|
28619
28084
|
searchUserByDisplayName: searchUserByDisplayName,
|
|
28620
|
-
getViewedUsers: getViewedUsers,
|
|
28621
28085
|
getReachedUsers: getReachedUsers,
|
|
28622
28086
|
get AmityUserSearchMatchType () { return AmityUserSearchMatchType; }
|
|
28623
28087
|
});
|
|
@@ -28867,181 +28331,6 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
28867
28331
|
};
|
|
28868
28332
|
/* end_public_function */
|
|
28869
28333
|
|
|
28870
|
-
/**
|
|
28871
|
-
* ```js
|
|
28872
|
-
* import { createImage } from '@amityco/ts-sdk'
|
|
28873
|
-
* const created = await createImage(formData)
|
|
28874
|
-
* ```
|
|
28875
|
-
*
|
|
28876
|
-
* Creates an {@link Amity.File<'image'>}
|
|
28877
|
-
*
|
|
28878
|
-
* @param formData The data necessary to create a new {@link Amity.File<'image'>}
|
|
28879
|
-
* @param onProgress The callback to track the upload progress
|
|
28880
|
-
* @returns The newly created {@link Amity.File<'image'>}
|
|
28881
|
-
*
|
|
28882
|
-
* @category File API
|
|
28883
|
-
* @async
|
|
28884
|
-
*/
|
|
28885
|
-
const createImage = async (formData, onProgress) => {
|
|
28886
|
-
const client = getActiveClient();
|
|
28887
|
-
client.log('file/createImage', formData);
|
|
28888
|
-
const files = formData.getAll('files');
|
|
28889
|
-
if (!files.length)
|
|
28890
|
-
throw new Error('The formData object must have a `files` key.');
|
|
28891
|
-
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
28892
|
-
formData.append('accessType', accessType);
|
|
28893
|
-
formData.append('preferredFilename', files[0].name);
|
|
28894
|
-
const headers = 'getHeaders' in formData
|
|
28895
|
-
? formData.getHeaders()
|
|
28896
|
-
: { 'content-type': 'multipart/form-data' };
|
|
28897
|
-
const { data } = await client.http.post('/api/v4/images', formData, {
|
|
28898
|
-
headers,
|
|
28899
|
-
onUploadProgress({ loaded, total = 100 }) {
|
|
28900
|
-
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
28901
|
-
},
|
|
28902
|
-
});
|
|
28903
|
-
// API-FIX: payload should be serialized properly
|
|
28904
|
-
// const { files } = data
|
|
28905
|
-
const cachedAt = client.cache && Date.now();
|
|
28906
|
-
if (client.cache)
|
|
28907
|
-
ingestInCache({ files: data }, { cachedAt });
|
|
28908
|
-
return {
|
|
28909
|
-
data,
|
|
28910
|
-
cachedAt,
|
|
28911
|
-
};
|
|
28912
|
-
};
|
|
28913
|
-
/* end_public_function */
|
|
28914
|
-
|
|
28915
|
-
/**
|
|
28916
|
-
* ```js
|
|
28917
|
-
* import { FileRepository } from '@amityco/ts-sdk'
|
|
28918
|
-
* const created = await FileRepository.createFile(formData)
|
|
28919
|
-
* ```
|
|
28920
|
-
*
|
|
28921
|
-
* Creates an {@link Amity.File}
|
|
28922
|
-
*
|
|
28923
|
-
* @param formData The data necessary to create a new {@link Amity.File}
|
|
28924
|
-
* @param onProgress The callback to track the upload progress
|
|
28925
|
-
* @returns The newly created {@link Amity.File}
|
|
28926
|
-
*
|
|
28927
|
-
* @category File API
|
|
28928
|
-
* @async
|
|
28929
|
-
*/
|
|
28930
|
-
const createFile = async (formData, onProgress) => {
|
|
28931
|
-
const client = getActiveClient();
|
|
28932
|
-
client.log('file/createFile', formData);
|
|
28933
|
-
const files = formData.getAll('files');
|
|
28934
|
-
if (!files.length)
|
|
28935
|
-
throw new Error('The formData object must have a `files` key.');
|
|
28936
|
-
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
28937
|
-
formData.append('accessType', accessType);
|
|
28938
|
-
formData.append('preferredFilename', files[0].name);
|
|
28939
|
-
const headers = 'getHeaders' in formData
|
|
28940
|
-
? formData.getHeaders()
|
|
28941
|
-
: { 'content-type': 'multipart/form-data' };
|
|
28942
|
-
const { data } = await client.http.post('/api/v4/files', formData, {
|
|
28943
|
-
headers,
|
|
28944
|
-
onUploadProgress({ loaded, total = 100 }) {
|
|
28945
|
-
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
28946
|
-
},
|
|
28947
|
-
});
|
|
28948
|
-
// API-FIX: payload should be serialized properly
|
|
28949
|
-
// const { files } = data
|
|
28950
|
-
const cachedAt = client.cache && Date.now();
|
|
28951
|
-
if (client.cache)
|
|
28952
|
-
ingestInCache({ files: data }, { cachedAt });
|
|
28953
|
-
return {
|
|
28954
|
-
data,
|
|
28955
|
-
cachedAt,
|
|
28956
|
-
};
|
|
28957
|
-
};
|
|
28958
|
-
|
|
28959
|
-
/**
|
|
28960
|
-
* ```js
|
|
28961
|
-
* import { FileRepository } from '@amityco/ts-sdk'
|
|
28962
|
-
* const created = await FileRepository.createVideo(formData)
|
|
28963
|
-
* ```
|
|
28964
|
-
*
|
|
28965
|
-
* Creates an {@link Amity.File<'video'>}
|
|
28966
|
-
*
|
|
28967
|
-
* @param formData The data necessary to create a new {@link Amity.File<'video'>}
|
|
28968
|
-
* @param feedType The {@link Amity.File<'video'>} feed type
|
|
28969
|
-
* @param onProgress The callback to track the upload progress
|
|
28970
|
-
* @returns The newly uploaded {@link Amity.File<'video'>}
|
|
28971
|
-
*
|
|
28972
|
-
* @category File API
|
|
28973
|
-
* @async
|
|
28974
|
-
*/
|
|
28975
|
-
const createVideo = async (formData, feedType, onProgress) => {
|
|
28976
|
-
const client = getActiveClient();
|
|
28977
|
-
client.log('file/createVideo', formData);
|
|
28978
|
-
const files = formData.getAll('files');
|
|
28979
|
-
if (!files.length)
|
|
28980
|
-
throw new Error('The formData object must have a `files` key.');
|
|
28981
|
-
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
28982
|
-
formData.append('accessType', accessType);
|
|
28983
|
-
formData.append('preferredFilename', files[0].name);
|
|
28984
|
-
if (feedType) {
|
|
28985
|
-
formData.append('feedType', feedType);
|
|
28986
|
-
}
|
|
28987
|
-
const headers = 'getHeaders' in formData
|
|
28988
|
-
? formData.getHeaders()
|
|
28989
|
-
: { 'content-type': 'multipart/form-data' };
|
|
28990
|
-
const { data } = await client.http.post('/api/v4/videos', formData, {
|
|
28991
|
-
headers,
|
|
28992
|
-
onUploadProgress({ loaded, total = 100 }) {
|
|
28993
|
-
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
28994
|
-
},
|
|
28995
|
-
});
|
|
28996
|
-
// API-FIX: payload should be serialized properly
|
|
28997
|
-
// const { files } = data
|
|
28998
|
-
const cachedAt = client.cache && Date.now();
|
|
28999
|
-
if (client.cache)
|
|
29000
|
-
ingestInCache({ files: data }, { cachedAt });
|
|
29001
|
-
return {
|
|
29002
|
-
data,
|
|
29003
|
-
cachedAt,
|
|
29004
|
-
};
|
|
29005
|
-
};
|
|
29006
|
-
|
|
29007
|
-
/**
|
|
29008
|
-
* ```js
|
|
29009
|
-
* import { observeFile } from '@amityco/ts-sdk'
|
|
29010
|
-
*
|
|
29011
|
-
* let file = {}
|
|
29012
|
-
* const dispose = observeFile(fileId, updated => file = updated)
|
|
29013
|
-
* ```
|
|
29014
|
-
*
|
|
29015
|
-
* Observe all mutation on a given {@link Amity.File}
|
|
29016
|
-
*
|
|
29017
|
-
* @param fileId the ID of the file to observe
|
|
29018
|
-
* @param callback the function to call when new data are available
|
|
29019
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the file
|
|
29020
|
-
*
|
|
29021
|
-
* @category File Observer
|
|
29022
|
-
*/
|
|
29023
|
-
const observeFile = (fileId, callback) => {
|
|
29024
|
-
const { log } = getActiveClient();
|
|
29025
|
-
const timestamp = Date.now();
|
|
29026
|
-
log(`observeFile(tmpid: ${timestamp}) > listen`);
|
|
29027
|
-
// wrapper function to make sure
|
|
29028
|
-
const router = (result, action) => {
|
|
29029
|
-
var _a, _b, _c;
|
|
29030
|
-
// filter function
|
|
29031
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.fileId) !== fileId)
|
|
29032
|
-
return;
|
|
29033
|
-
if (callback instanceof Function)
|
|
29034
|
-
return callback(result);
|
|
29035
|
-
if (action !== 'onFetch')
|
|
29036
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, result);
|
|
29037
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
|
|
29038
|
-
};
|
|
29039
|
-
runQuery(createQuery(getFile, fileId), result => result.data && router(result, 'onFetch'));
|
|
29040
|
-
return () => {
|
|
29041
|
-
log(`observeFile(tmpid: ${timestamp}) > dispose`);
|
|
29042
|
-
};
|
|
29043
|
-
};
|
|
29044
|
-
|
|
29045
28334
|
var index$i = /*#__PURE__*/Object.freeze({
|
|
29046
28335
|
__proto__: null,
|
|
29047
28336
|
getFile: getFile,
|
|
@@ -29049,11 +28338,7 @@ var index$i = /*#__PURE__*/Object.freeze({
|
|
|
29049
28338
|
deleteFile: deleteFile,
|
|
29050
28339
|
fileUrlWithSize: fileUrlWithSize,
|
|
29051
28340
|
uploadVideo: uploadVideo,
|
|
29052
|
-
uploadImage: uploadImage
|
|
29053
|
-
createImage: createImage,
|
|
29054
|
-
createFile: createFile,
|
|
29055
|
-
createVideo: createVideo,
|
|
29056
|
-
observeFile: observeFile
|
|
28341
|
+
uploadImage: uploadImage
|
|
29057
28342
|
});
|
|
29058
28343
|
|
|
29059
28344
|
/**
|
|
@@ -29074,16 +28359,12 @@ var index$i = /*#__PURE__*/Object.freeze({
|
|
|
29074
28359
|
const queryRoles = async (query) => {
|
|
29075
28360
|
const client = getActiveClient();
|
|
29076
28361
|
client.log('role/queryRoles', query);
|
|
29077
|
-
const _a = query !== null && query !== void 0 ? query : {}, {
|
|
28362
|
+
const _a = query !== null && query !== void 0 ? query : {}, { limit = 10, queryToken, displayName, sortBy } = _a, params = __rest(_a, ["limit", "queryToken", "displayName", "sortBy"]);
|
|
29078
28363
|
const options = (() => {
|
|
29079
28364
|
if (queryToken)
|
|
29080
28365
|
return { token: queryToken };
|
|
29081
28366
|
if (limit)
|
|
29082
28367
|
return { limit };
|
|
29083
|
-
if (page)
|
|
29084
|
-
return {
|
|
29085
|
-
token: toToken(page, 'skiplimit'),
|
|
29086
|
-
};
|
|
29087
28368
|
return undefined;
|
|
29088
28369
|
})();
|
|
29089
28370
|
// API-FIX: parameters should be querystring.
|
|
@@ -29211,12 +28492,9 @@ const dispatchReactable = (referenceType, model) => {
|
|
|
29211
28492
|
* @category Message API
|
|
29212
28493
|
* @async
|
|
29213
28494
|
*/
|
|
29214
|
-
const getMessage$
|
|
28495
|
+
const getMessage$1 = async (messageId, isLive = false) => {
|
|
29215
28496
|
const client = getActiveClient();
|
|
29216
28497
|
client.log('message/getMessage', messageId);
|
|
29217
|
-
if (!isLive) {
|
|
29218
|
-
console.log('getMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
|
|
29219
|
-
}
|
|
29220
28498
|
isInTombstone('message', messageId);
|
|
29221
28499
|
let data;
|
|
29222
28500
|
try {
|
|
@@ -29253,7 +28531,7 @@ const getMessage$2 = async (messageId, isLive = false) => {
|
|
|
29253
28531
|
*
|
|
29254
28532
|
* @category Message API
|
|
29255
28533
|
*/
|
|
29256
|
-
getMessage$
|
|
28534
|
+
getMessage$1.locally = (messageId) => {
|
|
29257
28535
|
const client = getActiveClient();
|
|
29258
28536
|
client.log('message/getMessage.locally', messageId);
|
|
29259
28537
|
if (!client.cache)
|
|
@@ -31182,7 +30460,7 @@ const getChannel$1 = async (channelId) => {
|
|
|
31182
30460
|
ingestInCache(data, { cachedAt });
|
|
31183
30461
|
const { channels } = data;
|
|
31184
30462
|
return {
|
|
31185
|
-
data:
|
|
30463
|
+
data: channels.find(channel => channel.channelId === channelId),
|
|
31186
30464
|
cachedAt,
|
|
31187
30465
|
};
|
|
31188
30466
|
};
|
|
@@ -31212,7 +30490,7 @@ getChannel$1.locally = (channelId) => {
|
|
|
31212
30490
|
if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) === 0)
|
|
31213
30491
|
return;
|
|
31214
30492
|
return {
|
|
31215
|
-
data:
|
|
30493
|
+
data: cached[0].data,
|
|
31216
30494
|
cachedAt: cached[0].cachedAt,
|
|
31217
30495
|
};
|
|
31218
30496
|
};
|
|
@@ -31237,7 +30515,7 @@ const deleteChannel = async (channelId) => {
|
|
|
31237
30515
|
await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
31238
30516
|
const deleted = await getChannel$1(channelId);
|
|
31239
30517
|
// no need for event, fired by server
|
|
31240
|
-
return deleted.data;
|
|
30518
|
+
return constructChannelDynamicValue(deleted.data);
|
|
31241
30519
|
};
|
|
31242
30520
|
|
|
31243
30521
|
/* begin_public_function
|
|
@@ -31359,81 +30637,6 @@ const unmuteChannel = async (channelId) => {
|
|
|
31359
30637
|
};
|
|
31360
30638
|
/* end_public_function */
|
|
31361
30639
|
|
|
31362
|
-
/**
|
|
31363
|
-
* ```js
|
|
31364
|
-
* import { observeChannel } from '@amityco/ts-sdk'
|
|
31365
|
-
*
|
|
31366
|
-
* let channel = {}
|
|
31367
|
-
* const dispose = observeChannel(channelId, ({ data }) => channel = data)
|
|
31368
|
-
* ```
|
|
31369
|
-
*
|
|
31370
|
-
* Observe all mutation on a given {@link Amity.Channel}
|
|
31371
|
-
*
|
|
31372
|
-
* @param channelId the ID of the channel to observe
|
|
31373
|
-
* @param callback the function to call when new data are available
|
|
31374
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channel
|
|
31375
|
-
*
|
|
31376
|
-
* @category Channel Observer
|
|
31377
|
-
*/
|
|
31378
|
-
const observeChannel = (channelId, callback) => {
|
|
31379
|
-
const { log } = getActiveClient();
|
|
31380
|
-
const timestamp = Date.now();
|
|
31381
|
-
log(`observeChannel(tmpid: ${timestamp}) > listen`);
|
|
31382
|
-
// wrapper function to make sure
|
|
31383
|
-
const router = (result, action) => {
|
|
31384
|
-
var _a, _b, _c;
|
|
31385
|
-
// filter function
|
|
31386
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.channelId) !== channelId)
|
|
31387
|
-
return;
|
|
31388
|
-
if (callback instanceof Function)
|
|
31389
|
-
return callback(Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
|
|
31390
|
-
if (action !== 'onFetch')
|
|
31391
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
|
|
31392
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
|
|
31393
|
-
};
|
|
31394
|
-
const disposers = [];
|
|
31395
|
-
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 */)));
|
|
31396
|
-
runQuery(createQuery(getChannel$1, channelId), result => result.data && router(result, "onFetch" /* Amity.ChannelActionType.OnFetch */));
|
|
31397
|
-
return () => {
|
|
31398
|
-
log(`observeChannel(tmpid: ${timestamp}) > dispose`);
|
|
31399
|
-
disposers.forEach(fn => fn());
|
|
31400
|
-
};
|
|
31401
|
-
};
|
|
31402
|
-
|
|
31403
|
-
/**
|
|
31404
|
-
* ```js
|
|
31405
|
-
* import { observeChannels } from '@amityco/ts-sdk'
|
|
31406
|
-
*
|
|
31407
|
-
* let channels = []
|
|
31408
|
-
* const unsub = observeChannels(channel => merge(channels, channel))
|
|
31409
|
-
* ```
|
|
31410
|
-
*
|
|
31411
|
-
* Observe all mutations on a list of {@link Amity.Channel} for a current user
|
|
31412
|
-
*
|
|
31413
|
-
* @param callback the function to call when new data are available
|
|
31414
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
31415
|
-
*
|
|
31416
|
-
* @category Channel Observer
|
|
31417
|
-
*/
|
|
31418
|
-
const observeChannels = (callback) => {
|
|
31419
|
-
const { log } = getActiveClient();
|
|
31420
|
-
const timestamp = Date.now();
|
|
31421
|
-
log(`observeChannels(tmpid: ${timestamp}) > listen`);
|
|
31422
|
-
const disposers = [];
|
|
31423
|
-
const router = (channel, action) => {
|
|
31424
|
-
var _a, _b;
|
|
31425
|
-
if (callback instanceof Function)
|
|
31426
|
-
return callback(LinkedObject.channel(constructChannelDynamicValue(channel)));
|
|
31427
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, LinkedObject.channel(constructChannelDynamicValue(channel)));
|
|
31428
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, LinkedObject.channel(constructChannelDynamicValue(channel)));
|
|
31429
|
-
};
|
|
31430
|
-
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 */)));
|
|
31431
|
-
return () => {
|
|
31432
|
-
log(`observeChannels(tmpid: ${timestamp}) > dispose`);
|
|
31433
|
-
disposers.forEach(fn => fn());
|
|
31434
|
-
};
|
|
31435
|
-
};
|
|
31436
|
-
|
|
31437
30640
|
/**
|
|
31438
30641
|
* ```js
|
|
31439
30642
|
* import { onMessageUpdated } from '@amityco/ts-sdk'
|
|
@@ -31712,69 +30915,6 @@ const onSubChannelFetched = (callback) => {
|
|
|
31712
30915
|
return createEventSubscriber(getActiveClient(), 'onSubChannelFetched', 'local.message-feed.fetched', payload => callback(payload.messageFeeds[0]));
|
|
31713
30916
|
};
|
|
31714
30917
|
|
|
31715
|
-
/**
|
|
31716
|
-
* ```js
|
|
31717
|
-
* import { getMessages } from '@amityco/ts-sdk'
|
|
31718
|
-
* const messages = await getMessages(['foo', 'bar'])
|
|
31719
|
-
* ```
|
|
31720
|
-
*
|
|
31721
|
-
* Fetches a collection of {@link Amity.Message} objects
|
|
31722
|
-
*
|
|
31723
|
-
* @param messageIds the IDs of the {@link Amity.Message} to fetch
|
|
31724
|
-
* @returns the associated collection of {@link Amity.Message} objects
|
|
31725
|
-
*
|
|
31726
|
-
* @category Message API
|
|
31727
|
-
* @async
|
|
31728
|
-
*/
|
|
31729
|
-
const getMessages$1 = async (messageIds) => {
|
|
31730
|
-
const client = getActiveClient();
|
|
31731
|
-
client.log('message/getMessages', messageIds);
|
|
31732
|
-
const { data: payload } = await client.http.get(`/api/v5/messages/list`, {
|
|
31733
|
-
params: { messageIds: messageIds.map(encodeURIComponent) },
|
|
31734
|
-
});
|
|
31735
|
-
const data = await prepareMessagePayload(payload);
|
|
31736
|
-
const cachedAt = client.cache && Date.now();
|
|
31737
|
-
if (client.cache)
|
|
31738
|
-
ingestInCache(data, { cachedAt });
|
|
31739
|
-
const { messages } = data;
|
|
31740
|
-
fireEvent('local.message.fetched', { messages });
|
|
31741
|
-
return {
|
|
31742
|
-
data: messages.map(message => LinkedObject.message(message)),
|
|
31743
|
-
cachedAt,
|
|
31744
|
-
};
|
|
31745
|
-
};
|
|
31746
|
-
/**
|
|
31747
|
-
* ```js
|
|
31748
|
-
* import { getMessages } from '@amityco/ts-sdk'
|
|
31749
|
-
* const messages = getMessages.locally(['foo', 'bar']) ?? []
|
|
31750
|
-
* ```
|
|
31751
|
-
*
|
|
31752
|
-
* Fetches a collection of {@link Amity.Message} objects from cache
|
|
31753
|
-
*
|
|
31754
|
-
* @param messageIds the IDs of the {@link Amity.Message} to fetch
|
|
31755
|
-
* @returns the associated collection of {@link Amity.Message} objects
|
|
31756
|
-
*
|
|
31757
|
-
* @category Message API
|
|
31758
|
-
*/
|
|
31759
|
-
getMessages$1.locally = (messageIds) => {
|
|
31760
|
-
var _a;
|
|
31761
|
-
const client = getActiveClient();
|
|
31762
|
-
client.log('message/getMessages.locally', messageIds);
|
|
31763
|
-
if (!client.cache)
|
|
31764
|
-
return;
|
|
31765
|
-
const cached = messageIds
|
|
31766
|
-
.map(messageId => pullFromCache(['message', 'get', messageId]))
|
|
31767
|
-
.filter(Boolean);
|
|
31768
|
-
const messages = cached.map(({ data }) => data);
|
|
31769
|
-
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
31770
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.length) < messageIds.length)
|
|
31771
|
-
return;
|
|
31772
|
-
return {
|
|
31773
|
-
data: messages,
|
|
31774
|
-
cachedAt: oldest.cachedAt,
|
|
31775
|
-
};
|
|
31776
|
-
};
|
|
31777
|
-
|
|
31778
30918
|
const getLocalId = () => `LOCAL_${uuid()}`;
|
|
31779
30919
|
// FIXME: temp solution
|
|
31780
30920
|
let uniqueId;
|
|
@@ -31801,7 +30941,7 @@ const createMessageOptimistic = (bundle) => {
|
|
|
31801
30941
|
if (subChannel.data.channelId === subChannel.data.subChannelId) {
|
|
31802
30942
|
const channel = pullFromCache(['channel', 'get', subChannel.data.channelId]);
|
|
31803
30943
|
if (channel === null || channel === void 0 ? void 0 : channel.data) {
|
|
31804
|
-
upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_a =
|
|
30944
|
+
upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_a = subChannel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
|
|
31805
30945
|
}
|
|
31806
30946
|
}
|
|
31807
30947
|
}
|
|
@@ -32087,7 +31227,7 @@ const softDeleteMessage = async (messageId) => {
|
|
|
32087
31227
|
client.log('message/softDeleteMessage', messageId);
|
|
32088
31228
|
// API-FIX: This endpoint has not been implemented yet.
|
|
32089
31229
|
await client.http.delete(`/api/v5/messages/${encodeURIComponent(messageId)}`);
|
|
32090
|
-
const deleted = await getMessage$
|
|
31230
|
+
const deleted = await getMessage$1(messageId);
|
|
32091
31231
|
fireEvent('local.message.deleted', { messages: [deleted.data] });
|
|
32092
31232
|
return LinkedObject.message(deleted.data);
|
|
32093
31233
|
};
|
|
@@ -32561,12 +31701,12 @@ const onMessageFetched = (callback) => {
|
|
|
32561
31701
|
*
|
|
32562
31702
|
* @category Message Live Object
|
|
32563
31703
|
*/
|
|
32564
|
-
const getMessage
|
|
31704
|
+
const getMessage = (messageId, callback) => {
|
|
32565
31705
|
const responder = (snapshot) => {
|
|
32566
31706
|
const { data } = snapshot;
|
|
32567
31707
|
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.message(snapshot.data) : data }));
|
|
32568
31708
|
};
|
|
32569
|
-
return liveObject(messageId, responder, 'messageId', getMessage$
|
|
31709
|
+
return liveObject(messageId, responder, 'messageId', getMessage$1, [
|
|
32570
31710
|
onMessageFetched,
|
|
32571
31711
|
onMessageUpdated,
|
|
32572
31712
|
onMessageDeleted,
|
|
@@ -32615,7 +31755,7 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
32615
31755
|
}
|
|
32616
31756
|
reactor(action) {
|
|
32617
31757
|
return (payload) => {
|
|
32618
|
-
var _a, _b, _c
|
|
31758
|
+
var _a, _b, _c;
|
|
32619
31759
|
if (action === 'onCreate') {
|
|
32620
31760
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
32621
31761
|
const { referenceId } = payload;
|
|
@@ -32625,14 +31765,9 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
32625
31765
|
return;
|
|
32626
31766
|
if (this.query.type && this.query.type !== payload.dataType)
|
|
32627
31767
|
return;
|
|
32628
|
-
if (this.query.dataType && this.query.dataType !== payload.dataType)
|
|
32629
|
-
return;
|
|
32630
31768
|
if (this.query.excludingTags &&
|
|
32631
31769
|
((_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); })))
|
|
32632
31770
|
return;
|
|
32633
|
-
if (this.query.excludeTags &&
|
|
32634
|
-
((_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); })))
|
|
32635
|
-
return;
|
|
32636
31771
|
if (!!this.query.hasFlags !== !!payload.flagCount)
|
|
32637
31772
|
return;
|
|
32638
31773
|
if (this.query.parentId && this.query.parentId !== payload.parentId)
|
|
@@ -32642,9 +31777,7 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
32642
31777
|
payload.isDeleted)
|
|
32643
31778
|
return;
|
|
32644
31779
|
if (this.query.includingTags &&
|
|
32645
|
-
!((
|
|
32646
|
-
return;
|
|
32647
|
-
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); })))
|
|
31780
|
+
!((_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); })))
|
|
32648
31781
|
return;
|
|
32649
31782
|
if ((!this.query.sortBy || this.query.sortBy === 'segmentDesc') &&
|
|
32650
31783
|
!this.paginationController.getPrevToken()) {
|
|
@@ -32744,26 +31877,6 @@ class MessageLiveCollectionController extends LiveCollectionController {
|
|
|
32744
31877
|
}
|
|
32745
31878
|
applyFilter(data) {
|
|
32746
31879
|
let messages = data;
|
|
32747
|
-
messages = messages.filter(m => {
|
|
32748
|
-
if (this.query.tags) {
|
|
32749
|
-
return this.query.tags.find(value => {
|
|
32750
|
-
if (!m.tags)
|
|
32751
|
-
return false;
|
|
32752
|
-
return m.tags.includes(value);
|
|
32753
|
-
});
|
|
32754
|
-
}
|
|
32755
|
-
return true;
|
|
32756
|
-
});
|
|
32757
|
-
messages = messages.filter(m => {
|
|
32758
|
-
if (this.query.excludeTags) {
|
|
32759
|
-
return (this.query.excludeTags || []).find(value => {
|
|
32760
|
-
if (!m.tags)
|
|
32761
|
-
return true;
|
|
32762
|
-
return !m.tags.includes(value);
|
|
32763
|
-
});
|
|
32764
|
-
}
|
|
32765
|
-
return true;
|
|
32766
|
-
});
|
|
32767
31880
|
/*
|
|
32768
31881
|
* for cases when message is deleted via RTE, this flag is used to get
|
|
32769
31882
|
* items from cache that are !deleted
|
|
@@ -32843,164 +31956,8 @@ const getMessages = (params, callback, config) => {
|
|
|
32843
31956
|
};
|
|
32844
31957
|
/* end_public_function */
|
|
32845
31958
|
|
|
32846
|
-
/**
|
|
32847
|
-
* ```js
|
|
32848
|
-
* import { getMessage } from '@amityco/ts-sdk'
|
|
32849
|
-
* const message = await getMessage('foobar')
|
|
32850
|
-
* ```
|
|
32851
|
-
*
|
|
32852
|
-
* Fetches a {@link Amity.Message} object
|
|
32853
|
-
*
|
|
32854
|
-
* @param messageId the ID of the {@link Amity.Message} to fetch
|
|
32855
|
-
* @returns the associated {@link Amity.Message} object
|
|
32856
|
-
*
|
|
32857
|
-
* @category Message API
|
|
32858
|
-
* @async
|
|
32859
|
-
*/
|
|
32860
|
-
const getMessage = async (messageId, isLive = false) => {
|
|
32861
|
-
const client = getActiveClient();
|
|
32862
|
-
client.log('message/getMessage', messageId);
|
|
32863
|
-
if (!isLive) {
|
|
32864
|
-
console.log('getMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
|
|
32865
|
-
}
|
|
32866
|
-
isInTombstone('message', messageId);
|
|
32867
|
-
let data;
|
|
32868
|
-
try {
|
|
32869
|
-
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
32870
|
-
const { data: payload } = await client.http.get(`/api/v5/messages/${encodeURIComponent(messageId)}`);
|
|
32871
|
-
data = await prepareMessagePayload(payload);
|
|
32872
|
-
}
|
|
32873
|
-
catch (error) {
|
|
32874
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
32875
|
-
pushToTombstone('message', messageId);
|
|
32876
|
-
}
|
|
32877
|
-
throw error;
|
|
32878
|
-
}
|
|
32879
|
-
const cachedAt = client.cache && Date.now();
|
|
32880
|
-
if (client.cache)
|
|
32881
|
-
ingestInCache(data, { cachedAt });
|
|
32882
|
-
const { messages } = data;
|
|
32883
|
-
fireEvent('local.message.fetched', { messages });
|
|
32884
|
-
return {
|
|
32885
|
-
data: LinkedObject.message(messages.find(message => message.messageId === messageId)),
|
|
32886
|
-
cachedAt,
|
|
32887
|
-
};
|
|
32888
|
-
};
|
|
32889
|
-
/**
|
|
32890
|
-
* ```js
|
|
32891
|
-
* import { getMessage } from '@amityco/ts-sdk'
|
|
32892
|
-
* const message = getMessage.locally('foobar')
|
|
32893
|
-
* ```
|
|
32894
|
-
*
|
|
32895
|
-
* Fetches a {@link Amity.Message} object
|
|
32896
|
-
*
|
|
32897
|
-
* @param messageId the ID of the {@link Amity.Message} to fetch
|
|
32898
|
-
* @returns the associated {@link Amity.Message} object
|
|
32899
|
-
*
|
|
32900
|
-
* @category Message API
|
|
32901
|
-
*/
|
|
32902
|
-
getMessage.locally = (messageId) => {
|
|
32903
|
-
const client = getActiveClient();
|
|
32904
|
-
client.log('message/getMessage.locally', messageId);
|
|
32905
|
-
if (!client.cache)
|
|
32906
|
-
return;
|
|
32907
|
-
const cached = pullFromCache(['message', 'get', messageId]);
|
|
32908
|
-
if (!cached)
|
|
32909
|
-
return;
|
|
32910
|
-
return {
|
|
32911
|
-
data: cached.data,
|
|
32912
|
-
cachedAt: cached.cachedAt,
|
|
32913
|
-
};
|
|
32914
|
-
};
|
|
32915
|
-
|
|
32916
|
-
/**
|
|
32917
|
-
* ```js
|
|
32918
|
-
* import { observeMessage } from '@amityco/ts-sdk'
|
|
32919
|
-
*
|
|
32920
|
-
* let message = {}
|
|
32921
|
-
*
|
|
32922
|
-
* const unsub = observeMessage(messageId, updated => message = updated)
|
|
32923
|
-
* ```
|
|
32924
|
-
*
|
|
32925
|
-
* Observe all mutations on a {@link Amity.Message} given a single messageId
|
|
32926
|
-
*
|
|
32927
|
-
* @param client the client to observe the message with
|
|
32928
|
-
* @param messageId the ID of the message to observe
|
|
32929
|
-
* @param callback the function to call when new data are available
|
|
32930
|
-
* @param policy a query policy option for this observer
|
|
32931
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
|
|
32932
|
-
*
|
|
32933
|
-
* @category Message Observer
|
|
32934
|
-
*/
|
|
32935
|
-
const observeMessage = (messageId, callback, policy = 'cache_then_server') => {
|
|
32936
|
-
const { log } = getActiveClient();
|
|
32937
|
-
const timestamp = Date.now();
|
|
32938
|
-
log(`observeMessage(tmpid: ${timestamp}) > listen`);
|
|
32939
|
-
console.log('observeMessage will be deprecated on 15th November 2022, please use liveMessage instead.');
|
|
32940
|
-
// wrapper function to make sure
|
|
32941
|
-
const router = (result, action) => {
|
|
32942
|
-
var _a, _b, _c;
|
|
32943
|
-
// filter function
|
|
32944
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.messageId) !== messageId)
|
|
32945
|
-
return;
|
|
32946
|
-
if (callback instanceof Function)
|
|
32947
|
-
return callback(result);
|
|
32948
|
-
if (action !== 'onFetch')
|
|
32949
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, result);
|
|
32950
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
|
|
32951
|
-
};
|
|
32952
|
-
const disposers = [];
|
|
32953
|
-
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')));
|
|
32954
|
-
if (policy !== 'no_fetch') {
|
|
32955
|
-
runQuery(createQuery(getMessage, messageId), result => result.data && router(result, 'onFetch'), queryOptions(policy));
|
|
32956
|
-
}
|
|
32957
|
-
return () => {
|
|
32958
|
-
log(`observeMessages(tmpid: ${timestamp}) > dispose`);
|
|
32959
|
-
disposers.forEach(fn => fn());
|
|
32960
|
-
};
|
|
32961
|
-
};
|
|
32962
|
-
|
|
32963
|
-
/**
|
|
32964
|
-
* ```js
|
|
32965
|
-
* import { observeMessages } from '@amityco/ts-sdk'
|
|
32966
|
-
*
|
|
32967
|
-
* let messages = []
|
|
32968
|
-
*
|
|
32969
|
-
* const unsubscribe = observeMessages(channelId, message => merge(messages, message))
|
|
32970
|
-
* ```
|
|
32971
|
-
*
|
|
32972
|
-
* Observe all mutations on a list of {@link Amity.Message} for a given {@link Amity.SubChannel} object
|
|
32973
|
-
*
|
|
32974
|
-
* @param subChannelId the ID of the channel where to observe the messages
|
|
32975
|
-
* @param callback the function to call when new data are available
|
|
32976
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
32977
|
-
*
|
|
32978
|
-
* @category Message Observer
|
|
32979
|
-
*/
|
|
32980
|
-
const observeMessages = (subChannelId, callback) => {
|
|
32981
|
-
const { log } = getActiveClient();
|
|
32982
|
-
const timestamp = Date.now();
|
|
32983
|
-
log(`observeMessages(tmpid: ${timestamp}) > listen`);
|
|
32984
|
-
const disposers = [];
|
|
32985
|
-
const router = (message, action) => {
|
|
32986
|
-
var _a, _b, _c;
|
|
32987
|
-
if (((_a = message.data) === null || _a === void 0 ? void 0 : _a.subChannelId) !== subChannelId)
|
|
32988
|
-
return;
|
|
32989
|
-
if (callback instanceof Function)
|
|
32990
|
-
return callback(message);
|
|
32991
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, message);
|
|
32992
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, message);
|
|
32993
|
-
};
|
|
32994
|
-
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')));
|
|
32995
|
-
return () => {
|
|
32996
|
-
log(`observeMessages(tmpid: ${timestamp}) > dispose`);
|
|
32997
|
-
disposers.forEach(fn => fn());
|
|
32998
|
-
};
|
|
32999
|
-
};
|
|
33000
|
-
|
|
33001
31959
|
var index$g = /*#__PURE__*/Object.freeze({
|
|
33002
31960
|
__proto__: null,
|
|
33003
|
-
getMessageByIds: getMessages$1,
|
|
33004
31961
|
createMessage: createMessage,
|
|
33005
31962
|
updateMessage: updateMessage,
|
|
33006
31963
|
editMessage: editMessage,
|
|
@@ -33022,10 +31979,8 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
33022
31979
|
onMessageReactionAdded: onMessageReactionAdded,
|
|
33023
31980
|
onMessageReactionRemoved: onMessageReactionRemoved,
|
|
33024
31981
|
onMessageFetched: onMessageFetched,
|
|
33025
|
-
getMessage: getMessage
|
|
31982
|
+
getMessage: getMessage,
|
|
33026
31983
|
getMessages: getMessages,
|
|
33027
|
-
observeMessage: observeMessage,
|
|
33028
|
-
observeMessages: observeMessages,
|
|
33029
31984
|
convertFromRaw: convertFromRaw$1,
|
|
33030
31985
|
prepareMessagePayload: prepareMessagePayload,
|
|
33031
31986
|
convertParams: convertParams,
|
|
@@ -33542,8 +32497,6 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
33542
32497
|
getSubChannel: getSubChannel,
|
|
33543
32498
|
getSubChannels: getSubChannels,
|
|
33544
32499
|
markReadEngineOnLoginHandler: markReadEngineOnLoginHandler,
|
|
33545
|
-
startReading: startReading,
|
|
33546
|
-
stopReading: stopReading,
|
|
33547
32500
|
startMessageReceiptSync: startMessageReceiptSync,
|
|
33548
32501
|
stopMessageReceiptSync: stopMessageReceiptSync
|
|
33549
32502
|
});
|
|
@@ -33594,7 +32547,9 @@ const getChannel = (channelId, callback) => {
|
|
|
33594
32547
|
const reactor = async (response) => {
|
|
33595
32548
|
if (!response.data)
|
|
33596
32549
|
return callback(response);
|
|
33597
|
-
const data = Object.assign(Object.assign({}, response), {
|
|
32550
|
+
const data = Object.assign(Object.assign({}, response), {
|
|
32551
|
+
// TODO: refactor to be a function to construct public channel object
|
|
32552
|
+
data: LinkedObject.channel(constructChannelDynamicValue(getChannelMessagePreviewWithUser(response.data))) });
|
|
33598
32553
|
const newSnapshot = __rest(data, ["origin"]);
|
|
33599
32554
|
/**
|
|
33600
32555
|
* check equality of previous data and current data to avoid redundancy
|
|
@@ -33929,8 +32884,11 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
33929
32884
|
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
33930
32885
|
.filter(Boolean)
|
|
33931
32886
|
.map(({ data }) => data)
|
|
32887
|
+
// add messagePreview >> Amity.InternalChannel -> Amity.InternalChannel
|
|
33932
32888
|
.map(getChannelMessagePreviewWithUser)
|
|
32889
|
+
// construct getter value >> Amity.StaticInternalChannel -> Amity.Channel
|
|
33933
32890
|
.map(constructChannelDynamicValue)
|
|
32891
|
+
// add markAsRead >> Amity.InternalChannel -> Amity.Channel
|
|
33934
32892
|
.map(LinkedObject.channel)) !== null && _b !== void 0 ? _b : [];
|
|
33935
32893
|
if (this.paginationController instanceof ChannelPaginationController) {
|
|
33936
32894
|
data = this.applyFilter(data);
|
|
@@ -34578,11 +33536,6 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
34578
33536
|
return false;
|
|
34579
33537
|
});
|
|
34580
33538
|
}
|
|
34581
|
-
if (this.query.search) {
|
|
34582
|
-
// eslint-disable-next-line no-console
|
|
34583
|
-
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.');
|
|
34584
|
-
channelMembers = filterBySearchTerm(channelMembers, this.query.search);
|
|
34585
|
-
}
|
|
34586
33539
|
if (this.query.includeDeleted === false) {
|
|
34587
33540
|
channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted) !== true; });
|
|
34588
33541
|
}
|
|
@@ -34616,11 +33569,6 @@ const applyFilter$1 = (data, params) => {
|
|
|
34616
33569
|
return params.memberships.includes(member.membership);
|
|
34617
33570
|
});
|
|
34618
33571
|
}
|
|
34619
|
-
if (params.search) {
|
|
34620
|
-
// eslint-disable-next-line no-console
|
|
34621
|
-
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.');
|
|
34622
|
-
channelMembers = filterBySearchTerm(channelMembers, params.search);
|
|
34623
|
-
}
|
|
34624
33572
|
// sort, 'lastCreated' is the default sort order
|
|
34625
33573
|
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
34626
33574
|
channelMembers = channelMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
@@ -34920,7 +33868,6 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
34920
33868
|
leaveChannel: leaveChannel,
|
|
34921
33869
|
muteChannel: muteChannel,
|
|
34922
33870
|
unmuteChannel: unmuteChannel,
|
|
34923
|
-
markAsRead: markAsRead,
|
|
34924
33871
|
onChannelCreated: onChannelCreated,
|
|
34925
33872
|
onChannelUpdated: onChannelUpdated,
|
|
34926
33873
|
onChannelDeleted: onChannelDeleted,
|
|
@@ -34933,8 +33880,6 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
34933
33880
|
onChannelMemberUnbanned: onChannelMemberUnbanned,
|
|
34934
33881
|
onChannelMemberRoleAdded: onChannelMemberRoleAdded,
|
|
34935
33882
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
34936
|
-
observeChannel: observeChannel,
|
|
34937
|
-
observeChannels: observeChannels,
|
|
34938
33883
|
getChannel: getChannel,
|
|
34939
33884
|
getChannels: getChannels,
|
|
34940
33885
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
@@ -35245,77 +34190,6 @@ const leaveCommunity = async (communityId) => {
|
|
|
35245
34190
|
};
|
|
35246
34191
|
/* end_public_function */
|
|
35247
34192
|
|
|
35248
|
-
/* begin_public_function
|
|
35249
|
-
id: community.query.trending_communities
|
|
35250
|
-
*/
|
|
35251
|
-
/**
|
|
35252
|
-
* @deprecated This API renamed to `getTrendingCommunities()`.
|
|
35253
|
-
* Please use getTrendingCommunities() instead.
|
|
35254
|
-
*
|
|
35255
|
-
* ```js
|
|
35256
|
-
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
35257
|
-
* const trendingCommunities = await CommunityRepository.getTrendingCommunities()
|
|
35258
|
-
* ```
|
|
35259
|
-
*
|
|
35260
|
-
* Gets a list of top trending {@link Amity.Community} objects
|
|
35261
|
-
*
|
|
35262
|
-
* @param query The query parameters
|
|
35263
|
-
* @returns A list of {@link Amity.Community} objects
|
|
35264
|
-
*
|
|
35265
|
-
* @category Community API
|
|
35266
|
-
* @async
|
|
35267
|
-
*/
|
|
35268
|
-
const getTopTrendingCommunities = async (query) => {
|
|
35269
|
-
const client = getActiveClient();
|
|
35270
|
-
client.log('channel/getTopTrendingCommunities', query);
|
|
35271
|
-
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
35272
|
-
// API-FIX: backend doesnt answer Amity.Response
|
|
35273
|
-
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
35274
|
-
const { data: payload } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
35275
|
-
const data = prepareCommunityPayload(payload);
|
|
35276
|
-
const { communities } = data;
|
|
35277
|
-
const cachedAt = client.cache && Date.now();
|
|
35278
|
-
if (client.cache) {
|
|
35279
|
-
ingestInCache(data, { cachedAt });
|
|
35280
|
-
const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
35281
|
-
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
35282
|
-
}
|
|
35283
|
-
return { data: communities, cachedAt };
|
|
35284
|
-
};
|
|
35285
|
-
/* end_public_function */
|
|
35286
|
-
/**
|
|
35287
|
-
* ```js
|
|
35288
|
-
* import { getTopTrendingCommunities } from '@amityco/ts-sdk'
|
|
35289
|
-
* const communities = getTopTrendingCommunities.locally()
|
|
35290
|
-
* ```
|
|
35291
|
-
*
|
|
35292
|
-
* Gets a list of top trending {@link Amity.Community} objects from cache
|
|
35293
|
-
*
|
|
35294
|
-
* @param query The query parameters
|
|
35295
|
-
* @returns communities
|
|
35296
|
-
*
|
|
35297
|
-
* @category Community API
|
|
35298
|
-
*/
|
|
35299
|
-
getTopTrendingCommunities.locally = (query) => {
|
|
35300
|
-
var _a, _b;
|
|
35301
|
-
const client = getActiveClient();
|
|
35302
|
-
client.log('community/getTopTrendingCommunities.locally', query);
|
|
35303
|
-
if (!client.cache)
|
|
35304
|
-
return;
|
|
35305
|
-
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
35306
|
-
const queryKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
35307
|
-
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
35308
|
-
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
35309
|
-
return;
|
|
35310
|
-
const communities = data.communities
|
|
35311
|
-
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
35312
|
-
.filter(Boolean)
|
|
35313
|
-
.map(({ data }) => data);
|
|
35314
|
-
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
35315
|
-
? { data: communities, cachedAt }
|
|
35316
|
-
: undefined;
|
|
35317
|
-
};
|
|
35318
|
-
|
|
35319
34193
|
const createCommunityEventSubscriber = (event, callback) => {
|
|
35320
34194
|
const client = getActiveClient();
|
|
35321
34195
|
const filter = (payload) => {
|
|
@@ -35386,7 +34260,224 @@ const onCommunityUpdated = (callback) => createCommunityEventSubscriber('communi
|
|
|
35386
34260
|
*
|
|
35387
34261
|
* @category Community Events
|
|
35388
34262
|
*/
|
|
35389
|
-
const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
|
|
34263
|
+
const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
|
|
34264
|
+
|
|
34265
|
+
/**
|
|
34266
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
34267
|
+
* TODO: check if querybyIds is supported
|
|
34268
|
+
*/
|
|
34269
|
+
class CommunitiesPaginationController$1 extends PaginationController {
|
|
34270
|
+
async getRequest(queryParams, token) {
|
|
34271
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
34272
|
+
const options = token ? { token } : { limit };
|
|
34273
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
34274
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
34275
|
+
});
|
|
34276
|
+
return queryResponse;
|
|
34277
|
+
}
|
|
34278
|
+
}
|
|
34279
|
+
|
|
34280
|
+
class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
34281
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
34282
|
+
super(query, cacheKey);
|
|
34283
|
+
this.notifyChange = notifyChange;
|
|
34284
|
+
this.preparePayload = preparePayload;
|
|
34285
|
+
}
|
|
34286
|
+
async saveToMainDB(response) {
|
|
34287
|
+
const processedPayload = await this.preparePayload(response);
|
|
34288
|
+
const client = getActiveClient();
|
|
34289
|
+
const cachedAt = client.cache && Date.now();
|
|
34290
|
+
if (client.cache) {
|
|
34291
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
34292
|
+
}
|
|
34293
|
+
}
|
|
34294
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
34295
|
+
var _a, _b;
|
|
34296
|
+
if (refresh) {
|
|
34297
|
+
pushToCache(this.cacheKey, {
|
|
34298
|
+
data: response.communities.map(getResolver('community')),
|
|
34299
|
+
});
|
|
34300
|
+
}
|
|
34301
|
+
else {
|
|
34302
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34303
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
34304
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
34305
|
+
}
|
|
34306
|
+
}
|
|
34307
|
+
reactor(action) {
|
|
34308
|
+
return (community) => {
|
|
34309
|
+
var _a;
|
|
34310
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34311
|
+
if (!collection)
|
|
34312
|
+
return;
|
|
34313
|
+
pushToCache(this.cacheKey, collection);
|
|
34314
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
34315
|
+
};
|
|
34316
|
+
}
|
|
34317
|
+
subscribeRTE(createSubscriber) {
|
|
34318
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
34319
|
+
}
|
|
34320
|
+
}
|
|
34321
|
+
|
|
34322
|
+
var EnumCommunityActions$4;
|
|
34323
|
+
(function (EnumCommunityActions) {
|
|
34324
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
34325
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
34326
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
34327
|
+
})(EnumCommunityActions$4 || (EnumCommunityActions$4 = {}));
|
|
34328
|
+
|
|
34329
|
+
var EnumCommunityMemberActions$1;
|
|
34330
|
+
(function (EnumCommunityMemberActions) {
|
|
34331
|
+
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
34332
|
+
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
34333
|
+
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
34334
|
+
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
34335
|
+
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
34336
|
+
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
34337
|
+
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
34338
|
+
EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
|
|
34339
|
+
EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
|
|
34340
|
+
EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
|
|
34341
|
+
EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
|
|
34342
|
+
})(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
|
|
34343
|
+
|
|
34344
|
+
/* begin_public_function
|
|
34345
|
+
id: community.membership.add_members
|
|
34346
|
+
*/
|
|
34347
|
+
/**
|
|
34348
|
+
* ```js
|
|
34349
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
34350
|
+
* const updated = await CommunityRepository.moderation.addMembers(communityId, ['foo', 'bar'])
|
|
34351
|
+
* ```
|
|
34352
|
+
*
|
|
34353
|
+
* Adds a list of {@link Amity.InternalUser} to a {@link Amity.Community} to add users to
|
|
34354
|
+
*
|
|
34355
|
+
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
34356
|
+
* @param userIds The list of IDs {@link Amity.InternalUser} to add
|
|
34357
|
+
* @returns A success boolean if the {@link Amity.InternalUser} were added to the {@link Amity.Community}
|
|
34358
|
+
*
|
|
34359
|
+
* @category Community API
|
|
34360
|
+
* @async
|
|
34361
|
+
*/
|
|
34362
|
+
const addMembers = async (communityId, userIds) => {
|
|
34363
|
+
const client = getActiveClient();
|
|
34364
|
+
client.log('community/moderation/addMembers', communityId, userIds);
|
|
34365
|
+
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
34366
|
+
fireEvent('local.community.userAdded', payload);
|
|
34367
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
34368
|
+
if (client.cache)
|
|
34369
|
+
ingestInCache(data);
|
|
34370
|
+
const { communityUsers } = data;
|
|
34371
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
34372
|
+
};
|
|
34373
|
+
/* end_public_function */
|
|
34374
|
+
|
|
34375
|
+
/* begin_public_function
|
|
34376
|
+
id: community.membership.remove_member
|
|
34377
|
+
*/
|
|
34378
|
+
/**
|
|
34379
|
+
* ```js
|
|
34380
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
34381
|
+
* const updated = await CommunityRepository.moderation.removeMembers(communityId, ['foo', 'bar'])
|
|
34382
|
+
* ```
|
|
34383
|
+
*
|
|
34384
|
+
* Removes a list of {@link Amity.InternalUser} from a {@link Amity.Community}
|
|
34385
|
+
*
|
|
34386
|
+
* @param communityId The ID of the {@link Amity.Community} to edit
|
|
34387
|
+
* @param userIds The list of IDs {@link Amity.InternalUser} to remove
|
|
34388
|
+
* @returns A success boolean if the list of {@link Amity.InternalUser} were removed from the {@link Amity.Community}
|
|
34389
|
+
*
|
|
34390
|
+
* @category Community API
|
|
34391
|
+
* @async
|
|
34392
|
+
*/
|
|
34393
|
+
const removeMembers = async (communityId, userIds) => {
|
|
34394
|
+
const client = getActiveClient();
|
|
34395
|
+
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
34396
|
+
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
34397
|
+
fireEvent('local.community.userRemoved', payload);
|
|
34398
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
34399
|
+
if (client.cache)
|
|
34400
|
+
ingestInCache(data);
|
|
34401
|
+
const { communityUsers } = data;
|
|
34402
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
34403
|
+
};
|
|
34404
|
+
/* end_public_function */
|
|
34405
|
+
|
|
34406
|
+
/**
|
|
34407
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
34408
|
+
* TODO: check if querybyIds is supported
|
|
34409
|
+
*/
|
|
34410
|
+
class CommunityMembersPaginationController extends PaginationController {
|
|
34411
|
+
async getRequest(queryParams, token) {
|
|
34412
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
34413
|
+
const options = token ? { token } : { limit };
|
|
34414
|
+
const isDeleted = includeDeleted === false ? false : undefined;
|
|
34415
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
34416
|
+
params: Object.assign(Object.assign({}, params), { options,
|
|
34417
|
+
isDeleted }),
|
|
34418
|
+
});
|
|
34419
|
+
return queryResponse;
|
|
34420
|
+
}
|
|
34421
|
+
}
|
|
34422
|
+
|
|
34423
|
+
class CommunityMembersQueryStreamController extends QueryStreamController {
|
|
34424
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
34425
|
+
super(query, cacheKey);
|
|
34426
|
+
this.notifyChange = notifyChange;
|
|
34427
|
+
this.preparePayload = preparePayload;
|
|
34428
|
+
}
|
|
34429
|
+
async saveToMainDB(response) {
|
|
34430
|
+
const processedPayload = await this.preparePayload(response);
|
|
34431
|
+
const client = getActiveClient();
|
|
34432
|
+
const cachedAt = client.cache && Date.now();
|
|
34433
|
+
if (client.cache) {
|
|
34434
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
34435
|
+
}
|
|
34436
|
+
}
|
|
34437
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
34438
|
+
var _a, _b;
|
|
34439
|
+
if (refresh) {
|
|
34440
|
+
pushToCache(this.cacheKey, {
|
|
34441
|
+
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
34442
|
+
});
|
|
34443
|
+
}
|
|
34444
|
+
else {
|
|
34445
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34446
|
+
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
34447
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
34448
|
+
...new Set([
|
|
34449
|
+
...communityUsers,
|
|
34450
|
+
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
34451
|
+
]),
|
|
34452
|
+
] }));
|
|
34453
|
+
}
|
|
34454
|
+
}
|
|
34455
|
+
reactor(action) {
|
|
34456
|
+
return (community, communityMembers) => {
|
|
34457
|
+
var _a;
|
|
34458
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34459
|
+
if (!collection)
|
|
34460
|
+
return;
|
|
34461
|
+
communityMembers.forEach(communityMember => {
|
|
34462
|
+
const communityMemberCacheId = getResolver('communityUsers')({
|
|
34463
|
+
communityId: this.query.communityId,
|
|
34464
|
+
userId: communityMember.userId,
|
|
34465
|
+
});
|
|
34466
|
+
if (communityMember.communityMembership === 'none') {
|
|
34467
|
+
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
34468
|
+
}
|
|
34469
|
+
else if (!collection.data.includes(communityMemberCacheId)) {
|
|
34470
|
+
collection.data = [communityMemberCacheId, ...collection.data];
|
|
34471
|
+
}
|
|
34472
|
+
});
|
|
34473
|
+
pushToCache(this.cacheKey, collection);
|
|
34474
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
34475
|
+
};
|
|
34476
|
+
}
|
|
34477
|
+
subscribeRTE(createSubscriber) {
|
|
34478
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
34479
|
+
}
|
|
34480
|
+
}
|
|
35390
34481
|
|
|
35391
34482
|
function hasPermission(member, payload, permission) {
|
|
35392
34483
|
if (member.permissions.some(x => x === permission)) {
|
|
@@ -35680,271 +34771,6 @@ const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubs
|
|
|
35680
34771
|
|
|
35681
34772
|
const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
|
|
35682
34773
|
|
|
35683
|
-
/**
|
|
35684
|
-
* ```js
|
|
35685
|
-
* import { observeCommunity } from '@amityco/ts-sdk'
|
|
35686
|
-
*
|
|
35687
|
-
* let community = {}
|
|
35688
|
-
* const dispose = observeCommunity(communityId, updated => community = updated)
|
|
35689
|
-
* ```
|
|
35690
|
-
*
|
|
35691
|
-
* Observe all mutation on a given {@link Amity.Community}
|
|
35692
|
-
*
|
|
35693
|
-
* @param communityId the ID of the community to observe
|
|
35694
|
-
* @param callback the function to call when new data are available
|
|
35695
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community
|
|
35696
|
-
*
|
|
35697
|
-
* @category Community Observer
|
|
35698
|
-
*/
|
|
35699
|
-
const observeCommunity = (communityId, callback) => {
|
|
35700
|
-
const { log } = getActiveClient();
|
|
35701
|
-
const timestamp = Date.now();
|
|
35702
|
-
log(`observeCommunity(tmpid: ${timestamp}) > listen`);
|
|
35703
|
-
// wrapper function to make sure
|
|
35704
|
-
const router = (result, action) => {
|
|
35705
|
-
var _a, _b;
|
|
35706
|
-
if (callback instanceof Function)
|
|
35707
|
-
return callback(result);
|
|
35708
|
-
if (action !== 'onFetch')
|
|
35709
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
35710
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
35711
|
-
};
|
|
35712
|
-
const realtimeRouter = (result, action) => {
|
|
35713
|
-
var _a;
|
|
35714
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.communityId) !== communityId)
|
|
35715
|
-
return;
|
|
35716
|
-
router(result, action);
|
|
35717
|
-
};
|
|
35718
|
-
const disposers = [];
|
|
35719
|
-
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')));
|
|
35720
|
-
runQuery(createQuery(getCommunity$1, communityId), result => (result.data || result.error) && router(result, 'onFetch'));
|
|
35721
|
-
return () => {
|
|
35722
|
-
log(`observeCommunity(tmpid: ${timestamp}) > dispose`);
|
|
35723
|
-
disposers.forEach(fn => fn());
|
|
35724
|
-
};
|
|
35725
|
-
};
|
|
35726
|
-
|
|
35727
|
-
/**
|
|
35728
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
35729
|
-
* TODO: check if querybyIds is supported
|
|
35730
|
-
*/
|
|
35731
|
-
class CommunitiesPaginationController$1 extends PaginationController {
|
|
35732
|
-
async getRequest(queryParams, token) {
|
|
35733
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35734
|
-
const options = token ? { token } : { limit };
|
|
35735
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
35736
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
35737
|
-
});
|
|
35738
|
-
return queryResponse;
|
|
35739
|
-
}
|
|
35740
|
-
}
|
|
35741
|
-
|
|
35742
|
-
class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
35743
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
35744
|
-
super(query, cacheKey);
|
|
35745
|
-
this.notifyChange = notifyChange;
|
|
35746
|
-
this.preparePayload = preparePayload;
|
|
35747
|
-
}
|
|
35748
|
-
async saveToMainDB(response) {
|
|
35749
|
-
const processedPayload = await this.preparePayload(response);
|
|
35750
|
-
const client = getActiveClient();
|
|
35751
|
-
const cachedAt = client.cache && Date.now();
|
|
35752
|
-
if (client.cache) {
|
|
35753
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
35754
|
-
}
|
|
35755
|
-
}
|
|
35756
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
35757
|
-
var _a, _b;
|
|
35758
|
-
if (refresh) {
|
|
35759
|
-
pushToCache(this.cacheKey, {
|
|
35760
|
-
data: response.communities.map(getResolver('community')),
|
|
35761
|
-
});
|
|
35762
|
-
}
|
|
35763
|
-
else {
|
|
35764
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35765
|
-
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
35766
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
35767
|
-
}
|
|
35768
|
-
}
|
|
35769
|
-
reactor(action) {
|
|
35770
|
-
return (community) => {
|
|
35771
|
-
var _a;
|
|
35772
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35773
|
-
if (!collection)
|
|
35774
|
-
return;
|
|
35775
|
-
pushToCache(this.cacheKey, collection);
|
|
35776
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
35777
|
-
};
|
|
35778
|
-
}
|
|
35779
|
-
subscribeRTE(createSubscriber) {
|
|
35780
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
35781
|
-
}
|
|
35782
|
-
}
|
|
35783
|
-
|
|
35784
|
-
var EnumCommunityActions$4;
|
|
35785
|
-
(function (EnumCommunityActions) {
|
|
35786
|
-
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
35787
|
-
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
35788
|
-
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
35789
|
-
})(EnumCommunityActions$4 || (EnumCommunityActions$4 = {}));
|
|
35790
|
-
|
|
35791
|
-
var EnumCommunityMemberActions$1;
|
|
35792
|
-
(function (EnumCommunityMemberActions) {
|
|
35793
|
-
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
35794
|
-
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
35795
|
-
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
35796
|
-
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
35797
|
-
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
35798
|
-
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
35799
|
-
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
35800
|
-
EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
|
|
35801
|
-
EnumCommunityMemberActions["OnCommunityUserAdded"] = "OnCommunityUserAdded";
|
|
35802
|
-
EnumCommunityMemberActions["onCommunityUserRemoved"] = "onCommunityUserRemoved";
|
|
35803
|
-
EnumCommunityMemberActions["OnUserDeleted"] = "OnUserDeleted";
|
|
35804
|
-
})(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
|
|
35805
|
-
|
|
35806
|
-
/* begin_public_function
|
|
35807
|
-
id: community.membership.add_members
|
|
35808
|
-
*/
|
|
35809
|
-
/**
|
|
35810
|
-
* ```js
|
|
35811
|
-
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
35812
|
-
* const updated = await CommunityRepository.moderation.addMembers(communityId, ['foo', 'bar'])
|
|
35813
|
-
* ```
|
|
35814
|
-
*
|
|
35815
|
-
* Adds a list of {@link Amity.InternalUser} to a {@link Amity.Community} to add users to
|
|
35816
|
-
*
|
|
35817
|
-
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
35818
|
-
* @param userIds The list of IDs {@link Amity.InternalUser} to add
|
|
35819
|
-
* @returns A success boolean if the {@link Amity.InternalUser} were added to the {@link Amity.Community}
|
|
35820
|
-
*
|
|
35821
|
-
* @category Community API
|
|
35822
|
-
* @async
|
|
35823
|
-
*/
|
|
35824
|
-
const addMembers = async (communityId, userIds) => {
|
|
35825
|
-
const client = getActiveClient();
|
|
35826
|
-
client.log('community/moderation/addMembers', communityId, userIds);
|
|
35827
|
-
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
35828
|
-
fireEvent('local.community.userAdded', payload);
|
|
35829
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
35830
|
-
if (client.cache)
|
|
35831
|
-
ingestInCache(data);
|
|
35832
|
-
const { communityUsers } = data;
|
|
35833
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
35834
|
-
};
|
|
35835
|
-
/* end_public_function */
|
|
35836
|
-
|
|
35837
|
-
/* begin_public_function
|
|
35838
|
-
id: community.membership.remove_member
|
|
35839
|
-
*/
|
|
35840
|
-
/**
|
|
35841
|
-
* ```js
|
|
35842
|
-
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
35843
|
-
* const updated = await CommunityRepository.moderation.removeMembers(communityId, ['foo', 'bar'])
|
|
35844
|
-
* ```
|
|
35845
|
-
*
|
|
35846
|
-
* Removes a list of {@link Amity.InternalUser} from a {@link Amity.Community}
|
|
35847
|
-
*
|
|
35848
|
-
* @param communityId The ID of the {@link Amity.Community} to edit
|
|
35849
|
-
* @param userIds The list of IDs {@link Amity.InternalUser} to remove
|
|
35850
|
-
* @returns A success boolean if the list of {@link Amity.InternalUser} were removed from the {@link Amity.Community}
|
|
35851
|
-
*
|
|
35852
|
-
* @category Community API
|
|
35853
|
-
* @async
|
|
35854
|
-
*/
|
|
35855
|
-
const removeMembers = async (communityId, userIds) => {
|
|
35856
|
-
const client = getActiveClient();
|
|
35857
|
-
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
35858
|
-
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
35859
|
-
fireEvent('local.community.userRemoved', payload);
|
|
35860
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
35861
|
-
if (client.cache)
|
|
35862
|
-
ingestInCache(data);
|
|
35863
|
-
const { communityUsers } = data;
|
|
35864
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
35865
|
-
};
|
|
35866
|
-
/* end_public_function */
|
|
35867
|
-
|
|
35868
|
-
/**
|
|
35869
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
35870
|
-
* TODO: check if querybyIds is supported
|
|
35871
|
-
*/
|
|
35872
|
-
class CommunityMembersPaginationController extends PaginationController {
|
|
35873
|
-
async getRequest(queryParams, token) {
|
|
35874
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
35875
|
-
const options = token ? { token } : { limit };
|
|
35876
|
-
const isDeleted = includeDeleted === false ? false : undefined;
|
|
35877
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
35878
|
-
params: Object.assign(Object.assign({}, params), { options,
|
|
35879
|
-
isDeleted }),
|
|
35880
|
-
});
|
|
35881
|
-
return queryResponse;
|
|
35882
|
-
}
|
|
35883
|
-
}
|
|
35884
|
-
|
|
35885
|
-
class CommunityMembersQueryStreamController extends QueryStreamController {
|
|
35886
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
35887
|
-
super(query, cacheKey);
|
|
35888
|
-
this.notifyChange = notifyChange;
|
|
35889
|
-
this.preparePayload = preparePayload;
|
|
35890
|
-
}
|
|
35891
|
-
async saveToMainDB(response) {
|
|
35892
|
-
const processedPayload = await this.preparePayload(response);
|
|
35893
|
-
const client = getActiveClient();
|
|
35894
|
-
const cachedAt = client.cache && Date.now();
|
|
35895
|
-
if (client.cache) {
|
|
35896
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
35897
|
-
}
|
|
35898
|
-
}
|
|
35899
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
35900
|
-
var _a, _b;
|
|
35901
|
-
if (refresh) {
|
|
35902
|
-
pushToCache(this.cacheKey, {
|
|
35903
|
-
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
35904
|
-
});
|
|
35905
|
-
}
|
|
35906
|
-
else {
|
|
35907
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35908
|
-
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
35909
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
35910
|
-
...new Set([
|
|
35911
|
-
...communityUsers,
|
|
35912
|
-
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
35913
|
-
]),
|
|
35914
|
-
] }));
|
|
35915
|
-
}
|
|
35916
|
-
}
|
|
35917
|
-
reactor(action) {
|
|
35918
|
-
return (community, communityMembers) => {
|
|
35919
|
-
var _a;
|
|
35920
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35921
|
-
if (!collection)
|
|
35922
|
-
return;
|
|
35923
|
-
if (action === EnumCommunityMemberActions$1.OnCommunityUserRoleAdded &&
|
|
35924
|
-
this.query.sortBy === 'displayName') {
|
|
35925
|
-
return;
|
|
35926
|
-
}
|
|
35927
|
-
communityMembers.forEach(communityMember => {
|
|
35928
|
-
const communityMemberCacheId = getResolver('communityUsers')({
|
|
35929
|
-
communityId: this.query.communityId,
|
|
35930
|
-
userId: communityMember.userId,
|
|
35931
|
-
});
|
|
35932
|
-
if (communityMember.communityMembership === 'none') {
|
|
35933
|
-
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
35934
|
-
}
|
|
35935
|
-
else if (!collection.data.includes(communityMemberCacheId)) {
|
|
35936
|
-
collection.data = [communityMemberCacheId, ...collection.data];
|
|
35937
|
-
}
|
|
35938
|
-
});
|
|
35939
|
-
pushToCache(this.cacheKey, collection);
|
|
35940
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
35941
|
-
};
|
|
35942
|
-
}
|
|
35943
|
-
subscribeRTE(createSubscriber) {
|
|
35944
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
35945
|
-
}
|
|
35946
|
-
}
|
|
35947
|
-
|
|
35948
34774
|
/**
|
|
35949
34775
|
* ```js
|
|
35950
34776
|
* import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk'
|
|
@@ -36122,9 +34948,6 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
36122
34948
|
return memberships.includes(communityMembership);
|
|
36123
34949
|
});
|
|
36124
34950
|
}
|
|
36125
|
-
if (this.query.search) {
|
|
36126
|
-
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
36127
|
-
}
|
|
36128
34951
|
if (this.query.includeDeleted === false) {
|
|
36129
34952
|
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) !== true);
|
|
36130
34953
|
}
|
|
@@ -36132,15 +34955,6 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
36132
34955
|
case 'firstCreated':
|
|
36133
34956
|
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
36134
34957
|
break;
|
|
36135
|
-
case 'displayName':
|
|
36136
|
-
communityMembers = communityMembers.sort((a, b) => {
|
|
36137
|
-
var _a, _b, _c, _d;
|
|
36138
|
-
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)) {
|
|
36139
|
-
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);
|
|
36140
|
-
}
|
|
36141
|
-
return 0;
|
|
36142
|
-
});
|
|
36143
|
-
break;
|
|
36144
34958
|
case 'lastCreated':
|
|
36145
34959
|
default:
|
|
36146
34960
|
communityMembers = communityMembers.sort(sortByLastCreated);
|
|
@@ -36162,9 +34976,6 @@ const applyFilter = (data, params) => {
|
|
|
36162
34976
|
return membership.includes(communityMembership);
|
|
36163
34977
|
});
|
|
36164
34978
|
}
|
|
36165
|
-
if (params.search) {
|
|
36166
|
-
communityMembers = filterBySearchTerm(communityMembers, params.search);
|
|
36167
|
-
}
|
|
36168
34979
|
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
36169
34980
|
communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
36170
34981
|
return communityMembers;
|
|
@@ -36521,209 +35332,202 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
36521
35332
|
if (this.query.membership && userId) {
|
|
36522
35333
|
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
36523
35334
|
}
|
|
36524
|
-
return communities;
|
|
36525
|
-
}
|
|
36526
|
-
}
|
|
36527
|
-
|
|
36528
|
-
/* begin_public_function
|
|
36529
|
-
id: community.query
|
|
36530
|
-
*/
|
|
36531
|
-
/**
|
|
36532
|
-
* ```js
|
|
36533
|
-
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
36534
|
-
*
|
|
36535
|
-
* let communities = []
|
|
36536
|
-
* const unsub = CommunityRepository.searchCommunities({
|
|
36537
|
-
* displayName: Amity.Community['displayName'],
|
|
36538
|
-
* }, response => merge(communities, response.data))
|
|
36539
|
-
* ```
|
|
36540
|
-
*
|
|
36541
|
-
* Observe all mutations on a list of {@link Amity.Community}s
|
|
36542
|
-
*
|
|
36543
|
-
* @param params for querying communities
|
|
36544
|
-
* @param callback the function to call when new data are available
|
|
36545
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
|
|
36546
|
-
*
|
|
36547
|
-
* @category Community Live Collection
|
|
36548
|
-
*/
|
|
36549
|
-
const searchCommunities = (params, callback, config) => {
|
|
36550
|
-
const { log, cache } = getActiveClient();
|
|
36551
|
-
if (!cache) {
|
|
36552
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
36553
|
-
}
|
|
36554
|
-
const timestamp = Date.now();
|
|
36555
|
-
log(`searchCommunities(tmpid: ${timestamp}) > listen`);
|
|
36556
|
-
const searchCommunitiesLiveCollection = new SearchCommunityLiveCollectionController(params, callback);
|
|
36557
|
-
const disposers = searchCommunitiesLiveCollection.startSubscription();
|
|
36558
|
-
const cacheKey = searchCommunitiesLiveCollection.getCacheKey();
|
|
36559
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
36560
|
-
return () => {
|
|
36561
|
-
log(`searchCommunities(tmpid: ${timestamp}) > dispose`);
|
|
36562
|
-
disposers.forEach(fn => fn());
|
|
36563
|
-
};
|
|
36564
|
-
};
|
|
36565
|
-
/* end_public_function */
|
|
36566
|
-
|
|
36567
|
-
/**
|
|
36568
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
36569
|
-
* TODO: check if querybyIds is supported
|
|
36570
|
-
*/
|
|
36571
|
-
class CommunitiesPaginationController extends PaginationController {
|
|
36572
|
-
async getRequest(queryParams, token) {
|
|
36573
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
36574
|
-
const options = token ? { token } : { limit };
|
|
36575
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
36576
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted),
|
|
36577
|
-
});
|
|
36578
|
-
return queryResponse;
|
|
36579
|
-
}
|
|
36580
|
-
}
|
|
36581
|
-
|
|
36582
|
-
|
|
36583
|
-
(
|
|
36584
|
-
|
|
36585
|
-
|
|
36586
|
-
|
|
36587
|
-
}
|
|
36588
|
-
|
|
36589
|
-
|
|
36590
|
-
|
|
36591
|
-
|
|
36592
|
-
|
|
36593
|
-
|
|
36594
|
-
|
|
36595
|
-
|
|
36596
|
-
|
|
36597
|
-
|
|
36598
|
-
|
|
36599
|
-
if (
|
|
36600
|
-
|
|
36601
|
-
|
|
36602
|
-
|
|
36603
|
-
|
|
36604
|
-
|
|
36605
|
-
|
|
36606
|
-
|
|
36607
|
-
pushToCache(this.cacheKey, {
|
|
36608
|
-
|
|
36609
|
-
|
|
36610
|
-
|
|
36611
|
-
|
|
36612
|
-
|
|
36613
|
-
const
|
|
36614
|
-
|
|
36615
|
-
|
|
36616
|
-
|
|
36617
|
-
|
|
36618
|
-
|
|
36619
|
-
|
|
36620
|
-
|
|
36621
|
-
|
|
36622
|
-
|
|
36623
|
-
|
|
36624
|
-
|
|
36625
|
-
|
|
36626
|
-
|
|
36627
|
-
|
|
36628
|
-
|
|
36629
|
-
|
|
36630
|
-
|
|
36631
|
-
|
|
36632
|
-
|
|
36633
|
-
|
|
36634
|
-
|
|
36635
|
-
|
|
36636
|
-
|
|
36637
|
-
|
|
36638
|
-
|
|
36639
|
-
|
|
36640
|
-
|
|
36641
|
-
|
|
36642
|
-
|
|
36643
|
-
|
|
36644
|
-
|
|
36645
|
-
this.
|
|
36646
|
-
|
|
36647
|
-
|
|
36648
|
-
|
|
36649
|
-
|
|
36650
|
-
|
|
36651
|
-
|
|
36652
|
-
|
|
36653
|
-
|
|
36654
|
-
|
|
36655
|
-
|
|
36656
|
-
|
|
36657
|
-
|
|
36658
|
-
|
|
36659
|
-
}
|
|
36660
|
-
|
|
36661
|
-
|
|
36662
|
-
}
|
|
36663
|
-
|
|
36664
|
-
this.queryStreamController.
|
|
36665
|
-
|
|
36666
|
-
|
|
36667
|
-
|
|
36668
|
-
{ fn:
|
|
36669
|
-
{ fn:
|
|
36670
|
-
{ fn:
|
|
36671
|
-
{ fn:
|
|
36672
|
-
{ fn:
|
|
36673
|
-
|
|
36674
|
-
|
|
36675
|
-
|
|
36676
|
-
|
|
36677
|
-
|
|
36678
|
-
|
|
36679
|
-
|
|
36680
|
-
const
|
|
36681
|
-
|
|
36682
|
-
|
|
36683
|
-
|
|
36684
|
-
|
|
36685
|
-
|
|
36686
|
-
|
|
36687
|
-
|
|
36688
|
-
|
|
36689
|
-
|
|
36690
|
-
|
|
36691
|
-
|
|
36692
|
-
|
|
36693
|
-
|
|
36694
|
-
|
|
36695
|
-
});
|
|
36696
|
-
|
|
36697
|
-
|
|
36698
|
-
|
|
36699
|
-
|
|
36700
|
-
if (
|
|
36701
|
-
communities =
|
|
36702
|
-
}
|
|
36703
|
-
if (this.query.
|
|
36704
|
-
communities = communities.filter(c => { var _a; return (_a = c.
|
|
36705
|
-
}
|
|
36706
|
-
if (this.query.
|
|
36707
|
-
communities = communities
|
|
36708
|
-
}
|
|
36709
|
-
if (this.query.membership && userId) {
|
|
36710
|
-
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
36711
|
-
}
|
|
36712
|
-
if (!this.query.displayName) {
|
|
36713
|
-
const sortFn = (() => {
|
|
36714
|
-
switch (this.query.sortBy) {
|
|
36715
|
-
case 'firstCreated':
|
|
36716
|
-
return sortByFirstCreated;
|
|
36717
|
-
case 'lastCreated':
|
|
36718
|
-
return sortByLastCreated;
|
|
36719
|
-
case 'displayName':
|
|
36720
|
-
return sortByDisplayName;
|
|
36721
|
-
default:
|
|
36722
|
-
return sortByLastCreated;
|
|
36723
|
-
}
|
|
36724
|
-
})();
|
|
36725
|
-
communities = communities.sort(sortFn);
|
|
35335
|
+
return communities;
|
|
35336
|
+
}
|
|
35337
|
+
}
|
|
35338
|
+
|
|
35339
|
+
/* begin_public_function
|
|
35340
|
+
id: community.query
|
|
35341
|
+
*/
|
|
35342
|
+
/**
|
|
35343
|
+
* ```js
|
|
35344
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
35345
|
+
*
|
|
35346
|
+
* let communities = []
|
|
35347
|
+
* const unsub = CommunityRepository.searchCommunities({
|
|
35348
|
+
* displayName: Amity.Community['displayName'],
|
|
35349
|
+
* }, response => merge(communities, response.data))
|
|
35350
|
+
* ```
|
|
35351
|
+
*
|
|
35352
|
+
* Observe all mutations on a list of {@link Amity.Community}s
|
|
35353
|
+
*
|
|
35354
|
+
* @param params for querying communities
|
|
35355
|
+
* @param callback the function to call when new data are available
|
|
35356
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
|
|
35357
|
+
*
|
|
35358
|
+
* @category Community Live Collection
|
|
35359
|
+
*/
|
|
35360
|
+
const searchCommunities = (params, callback, config) => {
|
|
35361
|
+
const { log, cache } = getActiveClient();
|
|
35362
|
+
if (!cache) {
|
|
35363
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
35364
|
+
}
|
|
35365
|
+
const timestamp = Date.now();
|
|
35366
|
+
log(`searchCommunities(tmpid: ${timestamp}) > listen`);
|
|
35367
|
+
const searchCommunitiesLiveCollection = new SearchCommunityLiveCollectionController(params, callback);
|
|
35368
|
+
const disposers = searchCommunitiesLiveCollection.startSubscription();
|
|
35369
|
+
const cacheKey = searchCommunitiesLiveCollection.getCacheKey();
|
|
35370
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
35371
|
+
return () => {
|
|
35372
|
+
log(`searchCommunities(tmpid: ${timestamp}) > dispose`);
|
|
35373
|
+
disposers.forEach(fn => fn());
|
|
35374
|
+
};
|
|
35375
|
+
};
|
|
35376
|
+
/* end_public_function */
|
|
35377
|
+
|
|
35378
|
+
/**
|
|
35379
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
35380
|
+
* TODO: check if querybyIds is supported
|
|
35381
|
+
*/
|
|
35382
|
+
class CommunitiesPaginationController extends PaginationController {
|
|
35383
|
+
async getRequest(queryParams, token) {
|
|
35384
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35385
|
+
const options = token ? { token } : { limit };
|
|
35386
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
35387
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), filter: params.membership, options }),
|
|
35388
|
+
});
|
|
35389
|
+
return queryResponse;
|
|
35390
|
+
}
|
|
35391
|
+
}
|
|
35392
|
+
|
|
35393
|
+
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
35394
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
35395
|
+
super(query, cacheKey);
|
|
35396
|
+
this.notifyChange = notifyChange;
|
|
35397
|
+
this.preparePayload = preparePayload;
|
|
35398
|
+
}
|
|
35399
|
+
async saveToMainDB(response) {
|
|
35400
|
+
const processedPayload = await this.preparePayload(response);
|
|
35401
|
+
const client = getActiveClient();
|
|
35402
|
+
const cachedAt = client.cache && Date.now();
|
|
35403
|
+
if (client.cache) {
|
|
35404
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
35405
|
+
saveCommunityUsers(response.communities, response.communityUsers);
|
|
35406
|
+
}
|
|
35407
|
+
}
|
|
35408
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
35409
|
+
var _a, _b;
|
|
35410
|
+
if (refresh) {
|
|
35411
|
+
pushToCache(this.cacheKey, {
|
|
35412
|
+
data: response.communities.map(getResolver('community')),
|
|
35413
|
+
});
|
|
35414
|
+
}
|
|
35415
|
+
else {
|
|
35416
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35417
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
35418
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
35419
|
+
}
|
|
35420
|
+
}
|
|
35421
|
+
reactor(action) {
|
|
35422
|
+
return (community) => {
|
|
35423
|
+
var _a;
|
|
35424
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35425
|
+
if (!collection)
|
|
35426
|
+
return;
|
|
35427
|
+
/*
|
|
35428
|
+
* Simply update a collection and let responder decide what to do with data
|
|
35429
|
+
*/
|
|
35430
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
35431
|
+
pushToCache(this.cacheKey, collection);
|
|
35432
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
35433
|
+
};
|
|
35434
|
+
}
|
|
35435
|
+
subscribeRTE(createSubscriber) {
|
|
35436
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
35437
|
+
}
|
|
35438
|
+
}
|
|
35439
|
+
|
|
35440
|
+
var EnumCommunityActions$3;
|
|
35441
|
+
(function (EnumCommunityActions) {
|
|
35442
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
35443
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
35444
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
35445
|
+
})(EnumCommunityActions$3 || (EnumCommunityActions$3 = {}));
|
|
35446
|
+
|
|
35447
|
+
class CommunityLiveCollectionController extends LiveCollectionController {
|
|
35448
|
+
constructor(query, callback) {
|
|
35449
|
+
const queryStreamId = hash(query);
|
|
35450
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
35451
|
+
const paginationController = new CommunitiesPaginationController(query);
|
|
35452
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
35453
|
+
this.query = query;
|
|
35454
|
+
this.queryStreamController = new CommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
35455
|
+
this.callback = callback.bind(this);
|
|
35456
|
+
this.loadPage({ initial: true });
|
|
35457
|
+
}
|
|
35458
|
+
setup() {
|
|
35459
|
+
var _a;
|
|
35460
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35461
|
+
if (!collection) {
|
|
35462
|
+
pushToCache(this.cacheKey, {
|
|
35463
|
+
data: [],
|
|
35464
|
+
params: {},
|
|
35465
|
+
});
|
|
35466
|
+
}
|
|
35467
|
+
}
|
|
35468
|
+
async persistModel(queryPayload) {
|
|
35469
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
35470
|
+
}
|
|
35471
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
35472
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
35473
|
+
}
|
|
35474
|
+
startSubscription() {
|
|
35475
|
+
return this.queryStreamController.subscribeRTE([
|
|
35476
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions$3.OnCommunityCreated },
|
|
35477
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$3.OnCommunityDeleted },
|
|
35478
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$3.OnCommunityUpdated },
|
|
35479
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
35480
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
35481
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
35482
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
35483
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
35484
|
+
]);
|
|
35485
|
+
}
|
|
35486
|
+
notifyChange({ origin, loading, error }) {
|
|
35487
|
+
var _a, _b;
|
|
35488
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35489
|
+
if (!collection)
|
|
35490
|
+
return;
|
|
35491
|
+
const data = this.applyFilter((_b = collection.data
|
|
35492
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
35493
|
+
.filter(isNonNullable)
|
|
35494
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
35495
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
35496
|
+
return;
|
|
35497
|
+
this.callback({
|
|
35498
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
35499
|
+
data,
|
|
35500
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
35501
|
+
loading,
|
|
35502
|
+
error,
|
|
35503
|
+
});
|
|
35504
|
+
}
|
|
35505
|
+
applyFilter(data) {
|
|
35506
|
+
const { userId } = getActiveClient();
|
|
35507
|
+
let communities = data;
|
|
35508
|
+
if (!this.query.includeDeleted) {
|
|
35509
|
+
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
35510
|
+
}
|
|
35511
|
+
if (this.query.categoryId) {
|
|
35512
|
+
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
|
|
35513
|
+
}
|
|
35514
|
+
if (this.query.tags) {
|
|
35515
|
+
communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
35516
|
+
}
|
|
35517
|
+
if (this.query.membership && userId) {
|
|
35518
|
+
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
36726
35519
|
}
|
|
35520
|
+
const sortFn = (() => {
|
|
35521
|
+
switch (this.query.sortBy) {
|
|
35522
|
+
case 'firstCreated':
|
|
35523
|
+
return sortByFirstCreated;
|
|
35524
|
+
case 'lastCreated':
|
|
35525
|
+
return sortByLastCreated;
|
|
35526
|
+
default:
|
|
35527
|
+
return sortByLastCreated;
|
|
35528
|
+
}
|
|
35529
|
+
})();
|
|
35530
|
+
communities = communities.sort(sortFn);
|
|
36727
35531
|
return communities;
|
|
36728
35532
|
}
|
|
36729
35533
|
}
|
|
@@ -37477,11 +36281,9 @@ var index$9 = /*#__PURE__*/Object.freeze({
|
|
|
37477
36281
|
deleteCommunity: deleteCommunity,
|
|
37478
36282
|
joinCommunity: joinCommunity,
|
|
37479
36283
|
leaveCommunity: leaveCommunity,
|
|
37480
|
-
getTopTrendingCommunities: getTopTrendingCommunities,
|
|
37481
36284
|
onCommunityCreated: onCommunityCreated,
|
|
37482
36285
|
onCommunityUpdated: onCommunityUpdated,
|
|
37483
36286
|
onCommunityDeleted: onCommunityDeleted,
|
|
37484
|
-
observeCommunity: observeCommunity,
|
|
37485
36287
|
searchCommunities: searchCommunities,
|
|
37486
36288
|
getCommunities: getCommunities,
|
|
37487
36289
|
getCommunity: getCommunity,
|
|
@@ -37731,21 +36533,10 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
37731
36533
|
const queryGlobalFeed = async (query) => {
|
|
37732
36534
|
const client = getActiveClient();
|
|
37733
36535
|
client.log('feed/queryGlobalFeed', query);
|
|
37734
|
-
const _a = query !== null && query !== void 0 ? query : {}, {
|
|
37735
|
-
/*
|
|
37736
|
-
* TODO: Remove useCustomRanking key from query
|
|
37737
|
-
*/
|
|
37738
|
-
if (useCustomRanking)
|
|
37739
|
-
console.warn('The param "useCustomRanking" has been deprecated. To get custom ranking feed use FeedRepository.getCustomRankingGlobalFeed instead');
|
|
37740
|
-
if (page)
|
|
37741
|
-
console.warn('The param "page" has been deprecated. Please use "queryToken" instead.');
|
|
36536
|
+
const _a = query !== null && query !== void 0 ? query : {}, { queryToken } = _a, params = __rest(_a, ["queryToken"]);
|
|
37742
36537
|
const options = (() => {
|
|
37743
36538
|
if (queryToken)
|
|
37744
36539
|
return { token: queryToken };
|
|
37745
|
-
if (page)
|
|
37746
|
-
return {
|
|
37747
|
-
token: toToken(page, 'skiplimit'),
|
|
37748
|
-
};
|
|
37749
36540
|
return undefined;
|
|
37750
36541
|
})();
|
|
37751
36542
|
const { data: queryPayload } = await client.http.get(`/api/v4/me/global-feeds`, {
|
|
@@ -37758,20 +36549,12 @@ const queryGlobalFeed = async (query) => {
|
|
|
37758
36549
|
const cachedAt = client.cache && Date.now();
|
|
37759
36550
|
if (client.cache) {
|
|
37760
36551
|
ingestInCache(Object.assign(Object.assign({}, data), { communitis: processedCommunity }));
|
|
37761
|
-
const cacheKey = [
|
|
37762
|
-
'globalFeed',
|
|
37763
|
-
'query',
|
|
37764
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
37765
|
-
];
|
|
36552
|
+
const cacheKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
37766
36553
|
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
37767
36554
|
}
|
|
37768
|
-
const nextPage = toPage(paging.next);
|
|
37769
|
-
const prevPage = toPage(paging.previous);
|
|
37770
36555
|
return {
|
|
37771
36556
|
data: posts.map(LinkedObject.post),
|
|
37772
36557
|
cachedAt,
|
|
37773
|
-
prevPage,
|
|
37774
|
-
nextPage,
|
|
37775
36558
|
paging,
|
|
37776
36559
|
};
|
|
37777
36560
|
};
|
|
@@ -37796,12 +36579,8 @@ queryGlobalFeed.locally = (query) => {
|
|
|
37796
36579
|
client.log('post/queryGlobalFeed.locally', query);
|
|
37797
36580
|
if (!client.cache)
|
|
37798
36581
|
return;
|
|
37799
|
-
const
|
|
37800
|
-
const queryKey = [
|
|
37801
|
-
'globalFeed',
|
|
37802
|
-
'query',
|
|
37803
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
37804
|
-
];
|
|
36582
|
+
const params = __rest(query !== null && query !== void 0 ? query : {}, []);
|
|
36583
|
+
const queryKey = ['globalFeed', 'query', Object.assign({}, params)];
|
|
37805
36584
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
37806
36585
|
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
37807
36586
|
return;
|
|
@@ -37811,14 +36590,10 @@ queryGlobalFeed.locally = (query) => {
|
|
|
37811
36590
|
.map(({ data }) => data)
|
|
37812
36591
|
.map(LinkedObject.post);
|
|
37813
36592
|
const { paging } = data;
|
|
37814
|
-
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
37815
|
-
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
37816
36593
|
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
37817
36594
|
? {
|
|
37818
36595
|
data: posts,
|
|
37819
36596
|
cachedAt,
|
|
37820
|
-
prevPage,
|
|
37821
|
-
nextPage,
|
|
37822
36597
|
paging,
|
|
37823
36598
|
}
|
|
37824
36599
|
: undefined;
|
|
@@ -37844,14 +36619,10 @@ queryGlobalFeed.locally = (query) => {
|
|
|
37844
36619
|
const getCustomRankingGlobalFeed = async (query) => {
|
|
37845
36620
|
const client = getActiveClient();
|
|
37846
36621
|
client.log('feed/getCustomRankingGlobalFeed', query);
|
|
37847
|
-
const _a = query !== null && query !== void 0 ? query : {}, {
|
|
36622
|
+
const _a = query !== null && query !== void 0 ? query : {}, { queryToken, limit } = _a, params = __rest(_a, ["queryToken", "limit"]);
|
|
37848
36623
|
const options = (() => {
|
|
37849
36624
|
if (queryToken)
|
|
37850
36625
|
return { token: queryToken };
|
|
37851
|
-
if (page)
|
|
37852
|
-
return {
|
|
37853
|
-
token: toToken(page, 'skiplimit'),
|
|
37854
|
-
};
|
|
37855
36626
|
return undefined;
|
|
37856
36627
|
})();
|
|
37857
36628
|
const { data: queryPayload } = await client.http.get(`/api/v5/me/global-feeds`, {
|
|
@@ -37863,16 +36634,10 @@ const getCustomRankingGlobalFeed = async (query) => {
|
|
|
37863
36634
|
const cachedAt = client.cache && Date.now();
|
|
37864
36635
|
if (client.cache) {
|
|
37865
36636
|
ingestInCache(data);
|
|
37866
|
-
const cacheKey = [
|
|
37867
|
-
'customGlobalFeed',
|
|
37868
|
-
'query',
|
|
37869
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
37870
|
-
];
|
|
36637
|
+
const cacheKey = ['customGlobalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
37871
36638
|
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
37872
36639
|
}
|
|
37873
|
-
|
|
37874
|
-
const prevPage = toPage(paging.previous);
|
|
37875
|
-
return { data: posts.map(LinkedObject.post), cachedAt, prevPage, nextPage, paging };
|
|
36640
|
+
return { data: posts.map(LinkedObject.post), cachedAt, paging };
|
|
37876
36641
|
};
|
|
37877
36642
|
/* end_public_function */
|
|
37878
36643
|
/**
|
|
@@ -37895,12 +36660,8 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
37895
36660
|
client.log('post/getCustomRankingGlobalFeed.locally', query);
|
|
37896
36661
|
if (!client.cache)
|
|
37897
36662
|
return;
|
|
37898
|
-
const
|
|
37899
|
-
const queryKey = [
|
|
37900
|
-
'customGlobalFeed',
|
|
37901
|
-
'query',
|
|
37902
|
-
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
37903
|
-
];
|
|
36663
|
+
const params = __rest(query !== null && query !== void 0 ? query : {}, []);
|
|
36664
|
+
const queryKey = ['customGlobalFeed', 'query', Object.assign({}, params)];
|
|
37904
36665
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
37905
36666
|
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
37906
36667
|
return;
|
|
@@ -37908,11 +36669,9 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
37908
36669
|
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
37909
36670
|
.filter(Boolean)
|
|
37910
36671
|
.map(({ data }) => data);
|
|
37911
|
-
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
37912
|
-
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
37913
36672
|
const { paging } = data;
|
|
37914
36673
|
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
37915
|
-
? { data: posts.map(LinkedObject.post), cachedAt,
|
|
36674
|
+
? { data: posts.map(LinkedObject.post), cachedAt, paging }
|
|
37916
36675
|
: undefined;
|
|
37917
36676
|
};
|
|
37918
36677
|
|
|
@@ -38043,44 +36802,6 @@ const createPost = async (bundle) => {
|
|
|
38043
36802
|
};
|
|
38044
36803
|
/* end_public_function */
|
|
38045
36804
|
|
|
38046
|
-
/* begin_public_function
|
|
38047
|
-
id: post.edit
|
|
38048
|
-
*/
|
|
38049
|
-
/**
|
|
38050
|
-
* ```js
|
|
38051
|
-
* import { updatePost } from '@amityco/ts-sdk'
|
|
38052
|
-
* const updated = await updatePost(postId, {
|
|
38053
|
-
* data: { text: 'hello world' }
|
|
38054
|
-
* })
|
|
38055
|
-
* ```
|
|
38056
|
-
*
|
|
38057
|
-
* Updates an {@link Amity.Post}
|
|
38058
|
-
*
|
|
38059
|
-
* @param postId The ID of the {@link Amity.Post} to edit
|
|
38060
|
-
* @param patch The patch data to apply
|
|
38061
|
-
* @returns the updated {@link Amity.Post} object
|
|
38062
|
-
*
|
|
38063
|
-
* @category Post API
|
|
38064
|
-
* @async
|
|
38065
|
-
*/
|
|
38066
|
-
const updatePost = async (postId, patch) => {
|
|
38067
|
-
const client = getActiveClient();
|
|
38068
|
-
client.log('user/updatePost', patch);
|
|
38069
|
-
console.warn('Deprecation: updatePost has been renamed to editPost. Update post API will be deprecated soon.');
|
|
38070
|
-
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
|
|
38071
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
38072
|
-
const cachedAt = client.cache && Date.now();
|
|
38073
|
-
if (client.cache)
|
|
38074
|
-
ingestInCache(data, { cachedAt });
|
|
38075
|
-
fireEvent('local.post.updated', payload);
|
|
38076
|
-
const { posts } = data;
|
|
38077
|
-
return {
|
|
38078
|
-
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
38079
|
-
cachedAt,
|
|
38080
|
-
};
|
|
38081
|
-
};
|
|
38082
|
-
/* end_public_function */
|
|
38083
|
-
|
|
38084
36805
|
/* begin_public_function
|
|
38085
36806
|
id: post.edit, post.edit.custom_post
|
|
38086
36807
|
*/
|
|
@@ -38398,91 +37119,6 @@ const isPostFlaggedByMe = async (postId) => {
|
|
|
38398
37119
|
};
|
|
38399
37120
|
/* end_public_function */
|
|
38400
37121
|
|
|
38401
|
-
/**
|
|
38402
|
-
* ```js
|
|
38403
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
38404
|
-
*
|
|
38405
|
-
* let posts = []
|
|
38406
|
-
* const unsub = PostRepository.observePosts({
|
|
38407
|
-
* targetType: Amity.PostTargetType,
|
|
38408
|
-
* targetId: Amity.InternalPost['targetId'],
|
|
38409
|
-
* }, post => merge(posts, post))
|
|
38410
|
-
* ```
|
|
38411
|
-
*
|
|
38412
|
-
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
38413
|
-
*
|
|
38414
|
-
* @param params
|
|
38415
|
-
* @param callback the function to call when new data are available
|
|
38416
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
38417
|
-
*
|
|
38418
|
-
* @category Post Observer
|
|
38419
|
-
*/
|
|
38420
|
-
const observePosts = (params, callback) => {
|
|
38421
|
-
const { log } = getActiveClient();
|
|
38422
|
-
const timestamp = Date.now();
|
|
38423
|
-
log(`observePosts(tmpid: ${timestamp}) > listen`);
|
|
38424
|
-
const disposers = [];
|
|
38425
|
-
const router = (post, action) => {
|
|
38426
|
-
var _a, _b;
|
|
38427
|
-
if (params.targetId !== post.targetId || params.targetType !== post.targetType)
|
|
38428
|
-
return;
|
|
38429
|
-
if (callback instanceof Function)
|
|
38430
|
-
return callback(LinkedObject.post(post));
|
|
38431
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, LinkedObject.post(post));
|
|
38432
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, LinkedObject.post(post));
|
|
38433
|
-
};
|
|
38434
|
-
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')));
|
|
38435
|
-
return () => {
|
|
38436
|
-
log(`observePosts(tmpid: ${timestamp}) > dispose`);
|
|
38437
|
-
disposers.forEach(fn => fn());
|
|
38438
|
-
};
|
|
38439
|
-
};
|
|
38440
|
-
|
|
38441
|
-
/**
|
|
38442
|
-
* ```js
|
|
38443
|
-
* import { observePost } from '@amityco/ts-sdk'
|
|
38444
|
-
*
|
|
38445
|
-
* let post = {}
|
|
38446
|
-
* const dispose = observePost(postId, updated => post = updated)
|
|
38447
|
-
* ```
|
|
38448
|
-
*
|
|
38449
|
-
* Observe all mutations on a given {@link Amity.Post}
|
|
38450
|
-
*
|
|
38451
|
-
* @param postId the ID of the post to observe
|
|
38452
|
-
* @param callback the function to call when new data are available
|
|
38453
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
|
|
38454
|
-
*
|
|
38455
|
-
* @category Post Observer
|
|
38456
|
-
*/
|
|
38457
|
-
const observePost = (postId, callback, policy = 'cache_then_server') => {
|
|
38458
|
-
const { log } = getActiveClient();
|
|
38459
|
-
const timestamp = Date.now();
|
|
38460
|
-
log(`observePost(tmpid: ${timestamp}) > listen`);
|
|
38461
|
-
// wrapper function to make sure
|
|
38462
|
-
const router = (result, action) => {
|
|
38463
|
-
var _a, _b;
|
|
38464
|
-
if (callback instanceof Function)
|
|
38465
|
-
return callback(result);
|
|
38466
|
-
if (action !== 'onFetch')
|
|
38467
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
38468
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
38469
|
-
};
|
|
38470
|
-
const realtimeRouter = (result, action) => {
|
|
38471
|
-
var _a;
|
|
38472
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.postId) !== postId)
|
|
38473
|
-
return;
|
|
38474
|
-
router(Object.assign(Object.assign({}, result), { data: result.data && LinkedObject.post(result.data) }), action);
|
|
38475
|
-
};
|
|
38476
|
-
const disposers = [];
|
|
38477
|
-
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')));
|
|
38478
|
-
runQuery(createQuery(getPost$2, postId), result => (result.data || result.error) &&
|
|
38479
|
-
router(Object.assign(Object.assign({}, result), { data: result.data && LinkedObject.post(result.data) }), 'onFetch'), queryOptions(policy));
|
|
38480
|
-
return () => {
|
|
38481
|
-
log(`observePosts(tmpid: ${timestamp}) > dispose`);
|
|
38482
|
-
disposers.forEach(fn => fn());
|
|
38483
|
-
};
|
|
38484
|
-
};
|
|
38485
|
-
|
|
38486
37122
|
/* begin_public_function
|
|
38487
37123
|
id: comment.get_by_ids
|
|
38488
37124
|
*/
|
|
@@ -38958,43 +37594,6 @@ const isCommentFlaggedByMe = async (commentId) => {
|
|
|
38958
37594
|
};
|
|
38959
37595
|
/* end_public_function */
|
|
38960
37596
|
|
|
38961
|
-
/**
|
|
38962
|
-
* ```js
|
|
38963
|
-
* import { observeComments } from '@amityco/ts-sdk'
|
|
38964
|
-
*
|
|
38965
|
-
* let comments = []
|
|
38966
|
-
* const unsub = observeComments(postId, comment => merge(comments, comment))
|
|
38967
|
-
* ```
|
|
38968
|
-
*
|
|
38969
|
-
* Observe all mutations on a list of {@link Amity.InternalComment} for a given {@link Amity.Post} object
|
|
38970
|
-
*
|
|
38971
|
-
* @param postId the ID of the post where to observe the comments
|
|
38972
|
-
* @param callback the function to call when new data are available
|
|
38973
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comments
|
|
38974
|
-
*
|
|
38975
|
-
* @category InternalComment Observer
|
|
38976
|
-
*/
|
|
38977
|
-
const observeComments = (postId, callback) => {
|
|
38978
|
-
const { log } = getActiveClient();
|
|
38979
|
-
const timestamp = Date.now();
|
|
38980
|
-
log(`observeComments(tmpid: ${timestamp}) > listen`);
|
|
38981
|
-
const disposers = [];
|
|
38982
|
-
const router = (comment, action) => {
|
|
38983
|
-
var _a, _b;
|
|
38984
|
-
if (comment.referenceId !== postId)
|
|
38985
|
-
return;
|
|
38986
|
-
if (callback instanceof Function)
|
|
38987
|
-
return callback(comment);
|
|
38988
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, comment);
|
|
38989
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, comment);
|
|
38990
|
-
};
|
|
38991
|
-
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')));
|
|
38992
|
-
return () => {
|
|
38993
|
-
log(`observeComments(tmpid: ${timestamp}) > dispose`);
|
|
38994
|
-
disposers.forEach(fn => fn());
|
|
38995
|
-
};
|
|
38996
|
-
};
|
|
38997
|
-
|
|
38998
37597
|
const getComment$1 = async (commentId) => {
|
|
38999
37598
|
const client = getActiveClient();
|
|
39000
37599
|
client.log('comment/getComment', commentId);
|
|
@@ -39034,50 +37633,6 @@ getComment$1.locally = (commentId) => {
|
|
|
39034
37633
|
};
|
|
39035
37634
|
};
|
|
39036
37635
|
|
|
39037
|
-
/**
|
|
39038
|
-
* ```js
|
|
39039
|
-
* import { observeComment } from '@amityco/ts-sdk'
|
|
39040
|
-
*
|
|
39041
|
-
* let comment = {}
|
|
39042
|
-
* const dispose = observeComment(commentId, ({ data }) => comment = data)
|
|
39043
|
-
* ```
|
|
39044
|
-
*
|
|
39045
|
-
* Observe all mutation on a given {@link Amity.InternalComment}
|
|
39046
|
-
*
|
|
39047
|
-
* @param commentId the ID of the comment to observe
|
|
39048
|
-
* @param callback the function to call when new data are available
|
|
39049
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
39050
|
-
*
|
|
39051
|
-
* @category InternalComment Observer
|
|
39052
|
-
*/
|
|
39053
|
-
const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
39054
|
-
const { log } = getActiveClient();
|
|
39055
|
-
const timestamp = Date.now();
|
|
39056
|
-
log(`observeComment(tmpid: ${timestamp}) > listen`);
|
|
39057
|
-
// wrapper function to make sure
|
|
39058
|
-
const router = (result, action) => {
|
|
39059
|
-
var _a, _b;
|
|
39060
|
-
if (callback instanceof Function)
|
|
39061
|
-
return callback(result);
|
|
39062
|
-
if (action !== 'onFetch')
|
|
39063
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
39064
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
39065
|
-
};
|
|
39066
|
-
const realtimeRouter = (result, action) => {
|
|
39067
|
-
var _a;
|
|
39068
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.commentId) !== commentId)
|
|
39069
|
-
return;
|
|
39070
|
-
router(result, action);
|
|
39071
|
-
};
|
|
39072
|
-
const disposers = [];
|
|
39073
|
-
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')));
|
|
39074
|
-
runQuery(createQuery(getComment$1, commentId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
39075
|
-
return () => {
|
|
39076
|
-
log(`observeComment(tmpid: ${timestamp}) > dispose`);
|
|
39077
|
-
disposers.forEach(fn => fn());
|
|
39078
|
-
};
|
|
39079
|
-
};
|
|
39080
|
-
|
|
39081
37636
|
/**
|
|
39082
37637
|
* ```js
|
|
39083
37638
|
* import { onCommentDeleteLocal } from '@amityco/ts-sdk'
|
|
@@ -39453,8 +38008,6 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
39453
38008
|
onCommentUnflagged: onCommentUnflagged,
|
|
39454
38009
|
onCommentReactionAdded: onCommentReactionAdded,
|
|
39455
38010
|
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
39456
|
-
observeComments: observeComments,
|
|
39457
|
-
observeComment: observeComment,
|
|
39458
38011
|
getComment: getComment,
|
|
39459
38012
|
getComments: getComments
|
|
39460
38013
|
});
|
|
@@ -40448,7 +39001,6 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
40448
39001
|
__proto__: null,
|
|
40449
39002
|
getPostByIds: getPostByIds,
|
|
40450
39003
|
createPost: createPost,
|
|
40451
|
-
updatePost: updatePost,
|
|
40452
39004
|
editPost: editPost,
|
|
40453
39005
|
deletePost: deletePost,
|
|
40454
39006
|
softDeletePost: softDeletePost,
|
|
@@ -40467,8 +39019,6 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
40467
39019
|
onPostUnflagged: onPostUnflagged,
|
|
40468
39020
|
onPostReactionAdded: onPostReactionAdded,
|
|
40469
39021
|
onPostReactionRemoved: onPostReactionRemoved,
|
|
40470
|
-
observePosts: observePosts,
|
|
40471
|
-
observePost: observePost,
|
|
40472
39022
|
getPost: getPost$1,
|
|
40473
39023
|
getPosts: getPosts,
|
|
40474
39024
|
getPinnedPosts: getPinnedPosts,
|
|
@@ -40661,47 +39211,6 @@ const disposeStream = async (streamId) => {
|
|
|
40661
39211
|
};
|
|
40662
39212
|
/* end_public_function */
|
|
40663
39213
|
|
|
40664
|
-
/* begin_public_function
|
|
40665
|
-
id: stream.query
|
|
40666
|
-
*/
|
|
40667
|
-
/**
|
|
40668
|
-
* @deprecated This API renamed to `getStreams`.
|
|
40669
|
-
* Please use getStreams() instead.
|
|
40670
|
-
* ```js
|
|
40671
|
-
* import { getStreams } from '@amityco/ts-sdk'
|
|
40672
|
-
* const streams = await getStreams()
|
|
40673
|
-
* ```
|
|
40674
|
-
*
|
|
40675
|
-
* Queries a paginable list of {@link Amity.InternalStream} objects
|
|
40676
|
-
*
|
|
40677
|
-
* @param query The query parameters
|
|
40678
|
-
* @returns A page of {@link Amity.InternalStream} objects
|
|
40679
|
-
*
|
|
40680
|
-
* @category Stream API
|
|
40681
|
-
* @async
|
|
40682
|
-
*/
|
|
40683
|
-
const queryStreams = async (query) => {
|
|
40684
|
-
const client = getActiveClient();
|
|
40685
|
-
client.log('stream/queryStreams', query);
|
|
40686
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
40687
|
-
const { data } = await client.http.get(`/api/v3/video-streaming`, {
|
|
40688
|
-
params: Object.assign(Object.assign({}, params), { options: {
|
|
40689
|
-
token: toToken(page, 'skiplimit'),
|
|
40690
|
-
} }),
|
|
40691
|
-
});
|
|
40692
|
-
// API-FIX: backend to response Amity.Response: const { paging, videoStreamings } = unwrapPayload(data)
|
|
40693
|
-
// API-FIX: seems returned data has a results identifier on top of data, like no other apis, and this is beautiful
|
|
40694
|
-
const { paging, results: payload } = data;
|
|
40695
|
-
const { videoStreamings } = payload;
|
|
40696
|
-
const cachedAt = client.cache && Date.now();
|
|
40697
|
-
if (client.cache)
|
|
40698
|
-
ingestInCache(payload, { cachedAt });
|
|
40699
|
-
const nextPage = toPage(paging.next);
|
|
40700
|
-
const prevPage = toPage(paging.previous);
|
|
40701
|
-
return { data: videoStreamings, cachedAt, prevPage, nextPage };
|
|
40702
|
-
};
|
|
40703
|
-
/* end_public_function */
|
|
40704
|
-
|
|
40705
39214
|
/**
|
|
40706
39215
|
* ```js
|
|
40707
39216
|
* import { onStreamStarted } from '@amityco/ts-sdk'
|
|
@@ -40723,7 +39232,7 @@ const onStreamStarted = (callback) => {
|
|
|
40723
39232
|
ingestInCache(payload);
|
|
40724
39233
|
callback(payload.videoStreamings[0]);
|
|
40725
39234
|
};
|
|
40726
|
-
return createEventSubscriber(client, 'stream/onStreamStarted', '
|
|
39235
|
+
return createEventSubscriber(client, 'stream/onStreamStarted', 'video-streaming.didStart', filter);
|
|
40727
39236
|
};
|
|
40728
39237
|
|
|
40729
39238
|
/**
|
|
@@ -40747,7 +39256,7 @@ const onStreamStopped = (callback) => {
|
|
|
40747
39256
|
ingestInCache(payload);
|
|
40748
39257
|
callback(payload.videoStreamings[0]);
|
|
40749
39258
|
};
|
|
40750
|
-
return createEventSubscriber(client, 'stream/onStreamStropped', '
|
|
39259
|
+
return createEventSubscriber(client, 'stream/onStreamStropped', 'video-streaming.didStop', filter);
|
|
40751
39260
|
};
|
|
40752
39261
|
|
|
40753
39262
|
/**
|
|
@@ -40771,7 +39280,7 @@ const onStreamRecorded = (callback) => {
|
|
|
40771
39280
|
ingestInCache(payload);
|
|
40772
39281
|
callback(payload.videoStreamings[0]);
|
|
40773
39282
|
};
|
|
40774
|
-
return createEventSubscriber(client, 'stream/onStreamRecorded', '
|
|
39283
|
+
return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
|
|
40775
39284
|
};
|
|
40776
39285
|
|
|
40777
39286
|
/**
|
|
@@ -40795,7 +39304,7 @@ const onStreamFlagged = (callback) => {
|
|
|
40795
39304
|
ingestInCache(payload);
|
|
40796
39305
|
callback(payload.videoStreamings[0]);
|
|
40797
39306
|
};
|
|
40798
|
-
return createEventSubscriber(client, 'stream/onStreamFlagged', '
|
|
39307
|
+
return createEventSubscriber(client, 'stream/onStreamFlagged', 'video-streaming.didFlag', filter);
|
|
40799
39308
|
};
|
|
40800
39309
|
|
|
40801
39310
|
/**
|
|
@@ -40819,7 +39328,7 @@ const onStreamTerminated = (callback) => {
|
|
|
40819
39328
|
ingestInCache(payload);
|
|
40820
39329
|
callback(payload.videoStreamings[0]);
|
|
40821
39330
|
};
|
|
40822
|
-
return createEventSubscriber(client, 'stream/onStreamTerminated', '
|
|
39331
|
+
return createEventSubscriber(client, 'stream/onStreamTerminated', 'video-streaming.didTerminate', filter);
|
|
40823
39332
|
};
|
|
40824
39333
|
|
|
40825
39334
|
/* eslint-disable no-use-before-define */
|
|
@@ -41028,8 +39537,6 @@ var index$4 = /*#__PURE__*/Object.freeze({
|
|
|
41028
39537
|
updateStream: updateStream,
|
|
41029
39538
|
deleteStream: deleteStream,
|
|
41030
39539
|
disposeStream: disposeStream,
|
|
41031
|
-
queryStreams: queryStreams,
|
|
41032
|
-
getStream: getStream,
|
|
41033
39540
|
onStreamStarted: onStreamStarted,
|
|
41034
39541
|
onStreamStopped: onStreamStopped,
|
|
41035
39542
|
onStreamRecorded: onStreamRecorded,
|
|
@@ -41284,50 +39791,6 @@ const onPollDeleted = (callback) => {
|
|
|
41284
39791
|
return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
|
|
41285
39792
|
};
|
|
41286
39793
|
|
|
41287
|
-
/**
|
|
41288
|
-
* ```js
|
|
41289
|
-
* import { observePoll } from '@amityco/ts-sdk'
|
|
41290
|
-
*
|
|
41291
|
-
* let poll = {}
|
|
41292
|
-
* const dispose = observePoll(pollId, updated => poll = updated)
|
|
41293
|
-
* ```
|
|
41294
|
-
*
|
|
41295
|
-
* Observe all mutation on a given {@link Amity.Poll}
|
|
41296
|
-
*
|
|
41297
|
-
* @param pollId the ID of the poll to observe
|
|
41298
|
-
* @param callback the function to call when new data are available
|
|
41299
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
|
|
41300
|
-
*
|
|
41301
|
-
* @category Poll Observer
|
|
41302
|
-
*/
|
|
41303
|
-
const observePoll = (pollId, callback, policy = 'cache_then_server') => {
|
|
41304
|
-
const { log } = getActiveClient();
|
|
41305
|
-
const timestamp = Date.now();
|
|
41306
|
-
log(`observePoll(tmpid: ${timestamp}) > listen`);
|
|
41307
|
-
// wrapper function to make sure
|
|
41308
|
-
const router = (result, action) => {
|
|
41309
|
-
var _a, _b;
|
|
41310
|
-
if (callback instanceof Function)
|
|
41311
|
-
return callback(result);
|
|
41312
|
-
if (action !== 'onFetch')
|
|
41313
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
41314
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
41315
|
-
};
|
|
41316
|
-
const realtimeRouter = (result, action) => {
|
|
41317
|
-
var _a;
|
|
41318
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.pollId) !== pollId)
|
|
41319
|
-
return;
|
|
41320
|
-
router(result, action);
|
|
41321
|
-
};
|
|
41322
|
-
const disposers = [];
|
|
41323
|
-
disposers.push(onPollUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPollDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')));
|
|
41324
|
-
runQuery(createQuery(getPoll$1, pollId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
41325
|
-
return () => {
|
|
41326
|
-
log(`observePoll(tmpid: ${timestamp}) > dispose`);
|
|
41327
|
-
disposers.forEach(fn => fn());
|
|
41328
|
-
};
|
|
41329
|
-
};
|
|
41330
|
-
|
|
41331
39794
|
/* begin_public_function
|
|
41332
39795
|
id: poll.get
|
|
41333
39796
|
*/
|
|
@@ -41363,7 +39826,6 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
41363
39826
|
votePoll: votePoll,
|
|
41364
39827
|
onPollUpdated: onPollUpdated,
|
|
41365
39828
|
onPollDeleted: onPollDeleted,
|
|
41366
|
-
observePoll: observePoll,
|
|
41367
39829
|
getPoll: getPoll
|
|
41368
39830
|
});
|
|
41369
39831
|
|
|
@@ -41821,7 +40283,7 @@ const createOptimisticTarget = async ({ targetId, targetType, }) => {
|
|
|
41821
40283
|
optimisticTarget = Object.assign(Object.assign({}, optimisticTarget), { targetPublicId: community.data.communityId, targetUpdatedAt: (_a = community.data.updatedAt) !== null && _a !== void 0 ? _a : new Date().toISOString() });
|
|
41822
40284
|
}
|
|
41823
40285
|
if (targetType === 'user') {
|
|
41824
|
-
const user = await getUser$
|
|
40286
|
+
const user = await getUser$1(targetId);
|
|
41825
40287
|
optimisticTarget = Object.assign(Object.assign({}, optimisticTarget), { targetPublicId: user.data.userPublicId, targetUpdatedAt: (_b = user.data.updatedAt) !== null && _b !== void 0 ? _b : new Date().toISOString() });
|
|
41826
40288
|
}
|
|
41827
40289
|
pushToCache(["storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */, 'get', targetId], optimisticTarget);
|
|
@@ -42964,4 +41426,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
|
|
|
42964
41426
|
return { accessToken: data.accessToken };
|
|
42965
41427
|
};
|
|
42966
41428
|
|
|
42967
|
-
export { API_REGIONS, index as AdRepository, index$8 as CategoryRepository, index$c as ChannelRepository, index$l as Client, index$6 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$9 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$7 as FeedRepository, FileAccessTypeEnum, index$i as FileRepository, FileType, index$2 as LiveStreamPlayer, MessageContentType, index$g as MessageRepository, index$3 as PollRepository, PostContentType, index$5 as PostRepository, index$h as ReactionRepository, index$1 as StoryRepository, index$4 as StreamRepository, index$f as SubChannelRepository, SubscriptionLevels, index$j as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|
|
41429
|
+
export { API_REGIONS, index as AdRepository, index$8 as CategoryRepository, index$c as ChannelRepository, index$l as Client, index$6 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$9 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$7 as FeedRepository, FileAccessTypeEnum, index$i as FileRepository, FileType, index$2 as LiveStreamPlayer, MessageContentType, index$g as MessageRepository, index$3 as PollRepository, PostContentType, index$5 as PostRepository, index$h as ReactionRepository, index$1 as StoryRepository, index$4 as StreamRepository, index$f as SubChannelRepository, SubscriptionLevels, index$j as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|