@amityco/ts-sdk 0.0.1-beta.15 → 0.0.1-beta.18
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/.eslintrc.json +51 -0
- package/dist/@types/core/cache.d.ts +12 -12
- package/dist/@types/core/cache.d.ts.map +1 -1
- package/dist/@types/core/errors.d.ts +1 -1
- package/dist/@types/core/errors.d.ts.map +1 -1
- package/dist/@types/core/events.d.ts +10 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +31 -23
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/paging.d.ts +10 -10
- package/dist/@types/core/paging.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +16 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/core/query.d.ts +8 -7
- package/dist/@types/core/query.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +1 -1
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/category.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +1 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +0 -1
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +2 -2
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +4 -4
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +1 -1
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +5 -5
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/follow.d.ts +20 -0
- package/dist/@types/domains/follow.d.ts.map +1 -0
- package/dist/@types/domains/group.d.ts +4 -4
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/@types/domains/mention.d.ts +6 -6
- package/dist/@types/domains/mention.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +2 -2
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/partials.d.ts.map +1 -1
- package/dist/@types/domains/poll.d.ts +27 -0
- package/dist/@types/domains/poll.d.ts.map +1 -0
- package/dist/@types/domains/post.d.ts +5 -5
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/reaction.d.ts +2 -2
- package/dist/@types/domains/reaction.d.ts.map +1 -1
- package/dist/@types/domains/stream.d.ts +3 -3
- package/dist/@types/domains/stream.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +1 -0
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/@types/global.d.ts +2 -2
- package/dist/@types/global.d.ts.map +1 -1
- package/dist/@types/index.d.ts +2 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/cache/api/backupCache.d.ts.map +1 -1
- package/dist/cache/api/disableCache.d.ts.map +1 -1
- package/dist/cache/api/dropFromCache.d.ts.map +1 -1
- package/dist/cache/api/enableCache.d.ts.map +1 -1
- package/dist/cache/api/index.d.ts.map +1 -1
- package/dist/cache/api/ingestInCache.d.ts.map +1 -1
- package/dist/cache/api/mergeInCache.d.ts +1 -1
- package/dist/cache/api/mergeInCache.d.ts.map +1 -1
- package/dist/cache/api/pullFromCache.d.ts.map +1 -1
- package/dist/cache/api/pushToCache.d.ts.map +1 -1
- package/dist/cache/api/queryCache.d.ts.map +1 -1
- package/dist/cache/api/restoreCache.d.ts.map +1 -1
- package/dist/cache/api/snipeIdFromCollection.d.ts.map +1 -1
- package/dist/cache/api/upsertInCache.d.ts +1 -1
- package/dist/cache/api/upsertInCache.d.ts.map +1 -1
- package/dist/cache/api/wipeCache.d.ts.map +1 -1
- package/dist/cache/utils/index.d.ts.map +1 -1
- package/dist/category/api/getCategory.d.ts +18 -2
- package/dist/category/api/getCategory.d.ts.map +1 -1
- package/dist/category/api/index.d.ts.map +1 -1
- package/dist/category/api/queryCategories.d.ts +24 -12
- package/dist/category/api/queryCategories.d.ts.map +1 -1
- package/dist/channel/api/addChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/addChannelMembersRole.d.ts.map +1 -1
- package/dist/channel/api/createChannel.d.ts +1 -1
- package/dist/channel/api/createChannel.d.ts.map +1 -1
- package/dist/channel/api/deleteChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannels.d.ts.map +1 -1
- package/dist/channel/api/index.d.ts.map +1 -1
- package/dist/channel/api/joinChannel.d.ts.map +1 -1
- package/dist/channel/api/leaveChannel.d.ts.map +1 -1
- package/dist/channel/api/queryChannelMembers.d.ts +2 -2
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/queryChannels.d.ts +1 -1
- package/dist/channel/api/queryChannels.d.ts.map +1 -1
- package/dist/channel/api/removeChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/removeChannelMembersRole.d.ts.map +1 -1
- package/dist/channel/api/updateChannel.d.ts.map +1 -1
- package/dist/channel/events/index.d.ts.map +1 -1
- package/dist/channel/events/onChannelCreated.d.ts.map +1 -1
- package/dist/channel/events/onChannelDeleted.d.ts.map +1 -1
- package/dist/channel/events/onChannelJoined.d.ts.map +1 -1
- package/dist/channel/events/onChannelLeft.d.ts.map +1 -1
- package/dist/channel/events/onChannelUpdated.d.ts.map +1 -1
- package/dist/channel/events/onMemberAdded.d.ts.map +1 -1
- package/dist/channel/events/onMemberRemoved.d.ts.map +1 -1
- package/dist/channel/observers/index.d.ts.map +1 -1
- package/dist/channel/observers/observeChannel.d.ts.map +1 -1
- package/dist/client/api/activeClient.d.ts.map +1 -1
- package/dist/client/api/activeUser.d.ts +6 -0
- package/dist/client/api/activeUser.d.ts.map +1 -0
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/disconnectClient.d.ts.map +1 -1
- package/dist/client/api/getToken.d.ts.map +1 -1
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/isConnected.d.ts.map +1 -1
- package/dist/client/events/index.d.ts.map +1 -1
- package/dist/client/events/onClientBanned.d.ts.map +1 -1
- package/dist/client/events/onClientDisconnected.d.ts.map +1 -1
- package/dist/client/events/onConnectionError.d.ts.map +1 -1
- package/dist/client/utils/endpoints.d.ts.map +1 -1
- package/dist/comment/api/createComment.d.ts.map +1 -1
- package/dist/comment/api/deleteComment.d.ts.map +1 -1
- package/dist/comment/api/getComment.d.ts.map +1 -1
- package/dist/comment/api/getComments.d.ts.map +1 -1
- package/dist/comment/api/index.d.ts.map +1 -1
- package/dist/comment/api/queryComments.d.ts.map +1 -1
- package/dist/comment/api/updateComment.d.ts.map +1 -1
- package/dist/comment/events/index.d.ts.map +1 -1
- package/dist/comment/events/onCommentCreated.d.ts.map +1 -1
- package/dist/comment/events/onCommentDeleted.d.ts.map +1 -1
- package/dist/comment/events/onCommentFlagged.d.ts.map +1 -1
- package/dist/comment/events/onCommentReactionAdded.d.ts.map +1 -1
- package/dist/comment/events/onCommentReactionRemoved.d.ts.map +1 -1
- package/dist/comment/events/onCommentUnflagged.d.ts.map +1 -1
- package/dist/comment/events/onCommentUpdated.d.ts.map +1 -1
- package/dist/comment/events/utils.d.ts.map +1 -1
- package/dist/comment/observers/index.d.ts.map +1 -1
- package/dist/comment/observers/observeComment.d.ts.map +1 -1
- package/dist/comment/observers/observeComments.d.ts.map +1 -1
- package/dist/community/api/addCommunityMembers.d.ts.map +1 -1
- package/dist/community/api/addCommunityMembersRoles.d.ts +18 -0
- package/dist/community/api/addCommunityMembersRoles.d.ts.map +1 -0
- package/dist/community/api/createCommunity.d.ts.map +1 -1
- package/dist/community/api/deleteCommunity.d.ts.map +1 -1
- package/dist/community/api/getCommunities.d.ts.map +1 -1
- package/dist/community/api/getCommunity.d.ts.map +1 -1
- package/dist/community/api/getRecommendedCommunities.d.ts +32 -0
- package/dist/community/api/getRecommendedCommunities.d.ts.map +1 -0
- package/dist/community/api/getTopTrendingCommunities.d.ts +32 -0
- package/dist/community/api/getTopTrendingCommunities.d.ts.map +1 -0
- package/dist/community/api/index.d.ts +4 -2
- package/dist/community/api/index.d.ts.map +1 -1
- package/dist/community/api/joinCommunity.d.ts.map +1 -1
- package/dist/community/api/leaveCommunity.d.ts.map +1 -1
- package/dist/community/api/queryCommunities.d.ts +1 -1
- package/dist/community/api/queryCommunities.d.ts.map +1 -1
- package/dist/community/api/queryCommunityMembers.d.ts +2 -2
- package/dist/community/api/queryCommunityMembers.d.ts.map +1 -1
- package/dist/community/api/removeCommunityMembers.d.ts.map +1 -1
- package/dist/community/api/removeCommunityMembersRoles.d.ts +18 -0
- package/dist/community/api/removeCommunityMembersRoles.d.ts.map +1 -0
- package/dist/community/api/updateCommunity.d.ts.map +1 -1
- package/dist/community/events/index.d.ts.map +1 -1
- package/dist/community/events/onCommunityCreated.d.ts.map +1 -1
- package/dist/community/events/onCommunityDeleted.d.ts.map +1 -1
- package/dist/community/events/onCommunityJoined.d.ts.map +1 -1
- package/dist/community/events/onCommunityLeft.d.ts.map +1 -1
- package/dist/community/events/onCommunityUpdated.d.ts.map +1 -1
- package/dist/community/events/onCommunityUserAdded.d.ts.map +1 -1
- package/dist/community/events/onCommunityUserBanned.d.ts.map +1 -1
- package/dist/community/events/onCommunityUserRemoved.d.ts.map +1 -1
- package/dist/community/events/onCommunityUserUnbanned.d.ts.map +1 -1
- package/dist/community/events/utils.d.ts.map +1 -1
- package/dist/community/observers/index.d.ts.map +1 -1
- package/dist/community/observers/observeCommunity.d.ts.map +1 -1
- package/dist/core/debug.d.ts.map +1 -1
- package/dist/core/device.d.ts.map +1 -1
- package/dist/core/errors.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/microtasks.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/identifyModel.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/query/filtering.d.ts +1 -1
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/core/query/index.d.ts.map +1 -1
- package/dist/core/query/paging.d.ts +6 -6
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/core/query/query.d.ts.map +1 -1
- package/dist/core/query/sorting.d.ts +1 -1
- package/dist/core/query/sorting.d.ts.map +1 -1
- package/dist/core/subscription.d.ts +2 -0
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/core/transports/http.d.ts.map +1 -1
- package/dist/core/transports/mqtt.d.ts.map +1 -1
- package/dist/core/transports/utils.d.ts.map +1 -1
- package/dist/core/transports/ws.d.ts +1 -1
- package/dist/core/transports/ws.d.ts.map +1 -1
- package/dist/core/uuid.d.ts.map +1 -1
- package/dist/feed/api/index.d.ts.map +1 -1
- package/dist/feed/api/queryGlobalFeed.d.ts +3 -3
- package/dist/feed/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/file/api/createFile.d.ts +2 -1
- package/dist/file/api/createFile.d.ts.map +1 -1
- package/dist/file/api/createVideo.d.ts +17 -0
- package/dist/file/api/createVideo.d.ts.map +1 -0
- package/dist/file/api/deleteFile.d.ts.map +1 -1
- package/dist/file/api/fileUrlWithSize.d.ts.map +1 -1
- package/dist/file/api/getFile.d.ts +1 -1
- package/dist/file/api/getFile.d.ts.map +1 -1
- package/dist/file/api/index.d.ts +1 -0
- package/dist/file/api/index.d.ts.map +1 -1
- package/dist/file/observers/index.d.ts.map +1 -1
- package/dist/file/observers/observeFile.d.ts.map +1 -1
- package/dist/follow/api/acceptFollower.d.ts +16 -0
- package/dist/follow/api/acceptFollower.d.ts.map +1 -0
- package/dist/follow/api/declineFollower.d.ts +16 -0
- package/dist/follow/api/declineFollower.d.ts.map +1 -0
- package/dist/follow/api/follow.d.ts +16 -0
- package/dist/follow/api/follow.d.ts.map +1 -0
- package/dist/follow/api/getFollowInfo.d.ts +32 -0
- package/dist/follow/api/getFollowInfo.d.ts.map +1 -0
- package/dist/follow/api/index.d.ts +8 -0
- package/dist/follow/api/index.d.ts.map +1 -0
- package/dist/follow/api/queryFollowers.d.ts +36 -0
- package/dist/follow/api/queryFollowers.d.ts.map +1 -0
- package/dist/follow/api/queryFollowings.d.ts +36 -0
- package/dist/follow/api/queryFollowings.d.ts.map +1 -0
- package/dist/follow/api/unfollow.d.ts +16 -0
- package/dist/follow/api/unfollow.d.ts.map +1 -0
- package/dist/follow/api/utils.d.ts +9 -0
- package/dist/follow/api/utils.d.ts.map +1 -0
- package/dist/follow/events/index.d.ts +9 -0
- package/dist/follow/events/index.d.ts.map +1 -0
- package/dist/follow/events/onFollowInfoUpdated.d.ts +17 -0
- package/dist/follow/events/onFollowInfoUpdated.d.ts.map +1 -0
- package/dist/follow/events/onFollowRequestAccepted.d.ts +17 -0
- package/dist/follow/events/onFollowRequestAccepted.d.ts.map +1 -0
- package/dist/follow/events/onFollowRequestCanceled.d.ts +17 -0
- package/dist/follow/events/onFollowRequestCanceled.d.ts.map +1 -0
- package/dist/follow/events/onFollowRequestDeclined.d.ts +17 -0
- package/dist/follow/events/onFollowRequestDeclined.d.ts.map +1 -0
- package/dist/follow/events/onFollowerDeleted.d.ts +17 -0
- package/dist/follow/events/onFollowerDeleted.d.ts.map +1 -0
- package/dist/follow/events/onFollowerRequested.d.ts +17 -0
- package/dist/follow/events/onFollowerRequested.d.ts.map +1 -0
- package/dist/follow/events/onUserFollowed.d.ts +17 -0
- package/dist/follow/events/onUserFollowed.d.ts.map +1 -0
- package/dist/follow/events/onUserUnfollowed.d.ts +17 -0
- package/dist/follow/events/onUserUnfollowed.d.ts.map +1 -0
- package/dist/follow/events/utils.d.ts +2 -0
- package/dist/follow/events/utils.d.ts.map +1 -0
- package/dist/follow/observers/index.d.ts +4 -0
- package/dist/follow/observers/index.d.ts.map +1 -0
- package/dist/follow/observers/observeFollowInfo.d.ts +18 -0
- package/dist/follow/observers/observeFollowInfo.d.ts.map +1 -0
- package/dist/follow/observers/observeFollowers.d.ts +18 -0
- package/dist/follow/observers/observeFollowers.d.ts.map +1 -0
- package/dist/follow/observers/observeFollowings.d.ts +18 -0
- package/dist/follow/observers/observeFollowings.d.ts.map +1 -0
- package/dist/index.cjs.js +1455 -259
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1424 -258
- package/dist/index.umd.js +5 -5
- package/dist/message/api/createMessage.d.ts +2 -2
- package/dist/message/api/createMessage.d.ts.map +1 -1
- package/dist/message/api/deleteMessage.d.ts.map +1 -1
- package/dist/message/api/getMessage.d.ts.map +1 -1
- package/dist/message/api/getMessages.d.ts.map +1 -1
- package/dist/message/api/index.d.ts.map +1 -1
- package/dist/message/api/queryMessages.d.ts.map +1 -1
- package/dist/message/api/updateMessage.d.ts.map +1 -1
- package/dist/message/events/index.d.ts.map +1 -1
- package/dist/message/events/onMessageCreated.d.ts.map +1 -1
- package/dist/message/events/onMessageDeleted.d.ts.map +1 -1
- package/dist/message/events/onMessageUpdated.d.ts.map +1 -1
- package/dist/message/observers/index.d.ts.map +1 -1
- package/dist/message/observers/observeMessage.d.ts.map +1 -1
- package/dist/message/observers/observeMessages.d.ts +5 -1
- package/dist/message/observers/observeMessages.d.ts.map +1 -1
- package/dist/poll/api/closePoll.d.ts +16 -0
- package/dist/poll/api/closePoll.d.ts.map +1 -0
- package/dist/poll/api/createPoll.d.ts +23 -0
- package/dist/poll/api/createPoll.d.ts.map +1 -0
- package/dist/poll/api/deletePoll.d.ts +16 -0
- package/dist/poll/api/deletePoll.d.ts.map +1 -0
- package/dist/poll/api/getPoll.d.ts +32 -0
- package/dist/poll/api/getPoll.d.ts.map +1 -0
- package/dist/poll/api/index.d.ts +6 -0
- package/dist/poll/api/index.d.ts.map +1 -0
- package/dist/poll/api/votePoll.d.ts +17 -0
- package/dist/poll/api/votePoll.d.ts.map +1 -0
- package/dist/post/api/createPost.d.ts +1 -1
- package/dist/post/api/createPost.d.ts.map +1 -1
- package/dist/post/api/deletePost.d.ts.map +1 -1
- package/dist/post/api/getPost.d.ts +1 -1
- package/dist/post/api/getPost.d.ts.map +1 -1
- package/dist/post/api/getPosts.d.ts.map +1 -1
- package/dist/post/api/index.d.ts.map +1 -1
- package/dist/post/api/queryPosts.d.ts +2 -2
- package/dist/post/api/queryPosts.d.ts.map +1 -1
- package/dist/post/api/updatePost.d.ts +1 -1
- package/dist/post/api/updatePost.d.ts.map +1 -1
- package/dist/post/events/index.d.ts.map +1 -1
- package/dist/post/events/onPostApproved.d.ts.map +1 -1
- package/dist/post/events/onPostCreated.d.ts.map +1 -1
- package/dist/post/events/onPostDeclined.d.ts.map +1 -1
- package/dist/post/events/onPostDeleted.d.ts.map +1 -1
- package/dist/post/events/onPostFlagged.d.ts.map +1 -1
- package/dist/post/events/onPostReactionAdded.d.ts.map +1 -1
- package/dist/post/events/onPostReactionRemoved.d.ts.map +1 -1
- package/dist/post/events/onPostUnflagged.d.ts.map +1 -1
- package/dist/post/events/onPostUpdated.d.ts.map +1 -1
- package/dist/post/events/utils.d.ts.map +1 -1
- package/dist/post/observers/index.d.ts.map +1 -1
- package/dist/post/observers/observePost.d.ts.map +1 -1
- package/dist/post/observers/observePosts.d.ts +11 -1
- package/dist/post/observers/observePosts.d.ts.map +1 -1
- package/dist/reaction/api/addReaction.d.ts +2 -2
- package/dist/reaction/api/addReaction.d.ts.map +1 -1
- package/dist/reaction/api/index.d.ts.map +1 -1
- package/dist/reaction/api/removeReaction.d.ts +2 -2
- package/dist/reaction/api/removeReaction.d.ts.map +1 -1
- package/dist/reaction/events/index.d.ts.map +1 -1
- package/dist/reaction/events/onReactionAdded.d.ts +1 -1
- package/dist/reaction/events/onReactionAdded.d.ts.map +1 -1
- package/dist/reaction/events/onReactionRemoved.d.ts +1 -1
- package/dist/reaction/events/onReactionRemoved.d.ts.map +1 -1
- package/dist/reaction/utils/dispatchReactable.d.ts.map +1 -1
- package/dist/reaction/utils/fetchReference.d.ts.map +1 -1
- package/dist/reaction/utils/index.d.ts.map +1 -1
- package/dist/reaction/utils/preparePayloadForCache.d.ts.map +1 -1
- package/dist/report/api/createReport.d.ts +1 -1
- package/dist/report/api/createReport.d.ts.map +1 -1
- package/dist/report/api/deleteReport.d.ts +1 -1
- package/dist/report/api/deleteReport.d.ts.map +1 -1
- package/dist/report/api/index.d.ts.map +1 -1
- package/dist/report/api/isReportedByMe.d.ts +1 -1
- package/dist/report/api/isReportedByMe.d.ts.map +1 -1
- package/dist/report/constants/referenceTypes.d.ts.map +1 -1
- package/dist/role/api/getRole.d.ts.map +1 -1
- package/dist/role/api/index.d.ts.map +1 -1
- package/dist/role/api/queryRoles.d.ts +1 -1
- package/dist/role/api/queryRoles.d.ts.map +1 -1
- package/dist/stream/api/createStream.d.ts.map +1 -1
- package/dist/stream/api/deleteStream.d.ts.map +1 -1
- package/dist/stream/api/disposeStream.d.ts.map +1 -1
- package/dist/stream/api/getStream.d.ts.map +1 -1
- package/dist/stream/api/index.d.ts.map +1 -1
- package/dist/stream/api/queryStreams.d.ts +1 -1
- package/dist/stream/api/queryStreams.d.ts.map +1 -1
- package/dist/stream/api/updateStream.d.ts.map +1 -1
- package/dist/stream/events/index.d.ts.map +1 -1
- package/dist/stream/events/onStreamRecorded.d.ts.map +1 -1
- package/dist/stream/events/onStreamStarted.d.ts.map +1 -1
- package/dist/stream/events/onStreamStopped.d.ts.map +1 -1
- package/dist/user/api/getUser.d.ts.map +1 -1
- package/dist/user/api/getUsers.d.ts.map +1 -1
- package/dist/user/api/index.d.ts.map +1 -1
- package/dist/user/api/queryUsers.d.ts.map +1 -1
- package/dist/user/api/updateUser.d.ts +1 -1
- package/dist/user/api/updateUser.d.ts.map +1 -1
- package/dist/user/events/index.d.ts.map +1 -1
- package/dist/user/events/onUserFlagCleared.d.ts.map +1 -1
- package/dist/user/events/onUserFlagged.d.ts.map +1 -1
- package/dist/user/events/onUserUnflagged.d.ts.map +1 -1
- package/dist/user/events/onUserUpdated.d.ts.map +1 -1
- package/dist/user/events/utils.d.ts.map +1 -1
- package/dist/user/observers/index.d.ts.map +1 -1
- package/dist/user/observers/observeUser.d.ts.map +1 -1
- package/dist/utils/env.d.ts +1 -1
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +1 -1
- package/rollup.config.js +11 -11
- package/src/@types/core/cache.ts +29 -28
- package/src/@types/core/errors.ts +3 -3
- package/src/@types/core/events.ts +97 -83
- package/src/@types/core/model.ts +40 -33
- package/src/@types/core/paging.ts +31 -31
- package/src/@types/core/payload.ts +91 -71
- package/src/@types/core/permissions.ts +6 -7
- package/src/@types/core/query.ts +41 -36
- package/src/@types/core/transport.ts +37 -28
- package/src/@types/domains/category.ts +7 -8
- package/src/@types/domains/channel.ts +29 -30
- package/src/@types/domains/client.ts +24 -25
- package/src/@types/domains/comment.ts +19 -20
- package/src/@types/domains/community.ts +22 -23
- package/src/@types/domains/content.ts +26 -22
- package/src/@types/domains/feed.ts +8 -9
- package/src/@types/domains/file.ts +28 -28
- package/src/@types/domains/follow.ts +23 -0
- package/src/@types/domains/group.ts +24 -26
- package/src/@types/domains/mention.ts +13 -12
- package/src/@types/domains/message.ts +15 -16
- package/src/@types/domains/partials.ts +29 -29
- package/src/@types/domains/poll.ts +32 -0
- package/src/@types/domains/post.ts +24 -24
- package/src/@types/domains/reaction.ts +17 -18
- package/src/@types/domains/stream.ts +37 -38
- package/src/@types/domains/user.ts +13 -13
- package/src/@types/global.ts +20 -17
- package/src/@types/index.ts +26 -23
- package/src/cache/api/backupCache.ts +14 -18
- package/src/cache/api/disableCache.ts +6 -6
- package/src/cache/api/dropFromCache.ts +13 -16
- package/src/cache/api/enableCache.ts +6 -6
- package/src/cache/api/index.ts +11 -11
- package/src/cache/api/ingestInCache.ts +15 -16
- package/src/cache/api/mergeInCache.ts +10 -12
- package/src/cache/api/pullFromCache.ts +9 -11
- package/src/cache/api/pushToCache.ts +14 -12
- package/src/cache/api/queryCache.ts +11 -12
- package/src/cache/api/restoreCache.ts +16 -15
- package/src/cache/api/snipeIdFromCollection.ts +19 -24
- package/src/cache/api/upsertInCache.ts +11 -13
- package/src/cache/api/wipeCache.ts +10 -12
- package/src/cache/utils/index.ts +15 -25
- package/src/category/api/getCategory.ts +50 -14
- package/src/category/api/index.ts +2 -2
- package/src/category/api/queryCategories.ts +88 -27
- package/src/channel/api/addChannelMembers.ts +14 -15
- package/src/channel/api/addChannelMembersRole.ts +12 -13
- package/src/channel/api/createChannel.ts +18 -13
- package/src/channel/api/deleteChannel.ts +9 -10
- package/src/channel/api/getChannel.ts +18 -19
- package/src/channel/api/getChannels.ts +22 -24
- package/src/channel/api/index.ts +13 -13
- package/src/channel/api/joinChannel.ts +12 -15
- package/src/channel/api/leaveChannel.ts +12 -15
- package/src/channel/api/queryChannelMembers.ts +35 -36
- package/src/channel/api/queryChannels.ts +44 -47
- package/src/channel/api/removeChannelMembers.ts +14 -15
- package/src/channel/api/removeChannelMembersRole.ts +12 -13
- package/src/channel/api/updateChannel.ts +12 -11
- package/src/channel/events/index.ts +6 -6
- package/src/channel/events/onChannelCreated.ts +9 -14
- package/src/channel/events/onChannelDeleted.ts +9 -14
- package/src/channel/events/onChannelJoined.ts +9 -14
- package/src/channel/events/onChannelLeft.ts +9 -14
- package/src/channel/events/onChannelUpdated.ts +9 -14
- package/src/channel/events/onMemberAdded.ts +9 -14
- package/src/channel/events/onMemberRemoved.ts +9 -14
- package/src/channel/observers/index.ts +1 -1
- package/src/channel/observers/observeChannel.ts +24 -30
- package/src/client/api/activeClient.ts +7 -7
- package/src/client/api/activeUser.ts +26 -0
- package/src/client/api/connectClient.ts +33 -29
- package/src/client/api/createClient.ts +22 -18
- package/src/client/api/disconnectClient.ts +14 -14
- package/src/client/api/getToken.ts +22 -17
- package/src/client/api/index.ts +5 -5
- package/src/client/api/isConnected.ts +8 -8
- package/src/client/events/index.ts +3 -3
- package/src/client/events/onClientBanned.ts +5 -7
- package/src/client/events/onClientDisconnected.ts +5 -7
- package/src/client/events/onConnectionError.ts +17 -24
- package/src/client/utils/endpoints.ts +3 -3
- package/src/comment/api/createComment.ts +19 -18
- package/src/comment/api/deleteComment.ts +21 -22
- package/src/comment/api/getComment.ts +22 -23
- package/src/comment/api/getComments.ts +24 -26
- package/src/comment/api/index.ts +6 -6
- package/src/comment/api/queryComments.ts +53 -50
- package/src/comment/api/updateComment.ts +14 -13
- package/src/comment/events/index.ts +7 -7
- package/src/comment/events/onCommentCreated.ts +3 -5
- package/src/comment/events/onCommentDeleted.ts +3 -5
- package/src/comment/events/onCommentFlagged.ts +3 -5
- package/src/comment/events/onCommentReactionAdded.ts +20 -20
- package/src/comment/events/onCommentReactionRemoved.ts +20 -20
- package/src/comment/events/onCommentUnflagged.ts +3 -5
- package/src/comment/events/onCommentUpdated.ts +3 -5
- package/src/comment/events/utils.ts +19 -20
- package/src/comment/observers/index.ts +2 -2
- package/src/comment/observers/observeComment.ts +48 -37
- package/src/comment/observers/observeComments.ts +34 -19
- package/src/community/api/addCommunityMembers.ts +14 -15
- package/src/community/api/addCommunityMembersRoles.ts +42 -0
- package/src/community/api/createCommunity.ts +26 -19
- package/src/community/api/deleteCommunity.ts +10 -12
- package/src/community/api/getCommunities.ts +24 -26
- package/src/community/api/getCommunity.ts +20 -21
- package/src/community/api/getRecommendedCommunities.ts +87 -0
- package/src/community/api/getTopTrendingCommunities.ts +87 -0
- package/src/community/api/index.ts +15 -13
- package/src/community/api/joinCommunity.ts +16 -16
- package/src/community/api/leaveCommunity.ts +16 -16
- package/src/community/api/queryCommunities.ts +48 -50
- package/src/community/api/queryCommunityMembers.ts +34 -35
- package/src/community/api/removeCommunityMembers.ts +14 -15
- package/src/community/api/removeCommunityMembersRoles.ts +42 -0
- package/src/community/api/updateCommunity.ts +18 -14
- package/src/community/events/index.ts +9 -9
- package/src/community/events/onCommunityCreated.ts +2 -2
- package/src/community/events/onCommunityDeleted.ts +2 -2
- package/src/community/events/onCommunityJoined.ts +4 -3
- package/src/community/events/onCommunityLeft.ts +4 -3
- package/src/community/events/onCommunityUpdated.ts +2 -2
- package/src/community/events/onCommunityUserAdded.ts +4 -3
- package/src/community/events/onCommunityUserBanned.ts +4 -3
- package/src/community/events/onCommunityUserRemoved.ts +4 -3
- package/src/community/events/onCommunityUserUnbanned.ts +4 -3
- package/src/community/events/utils.ts +46 -44
- package/src/community/observers/index.ts +1 -1
- package/src/community/observers/observeCommunity.ts +57 -39
- package/src/core/debug.ts +10 -12
- package/src/core/device.ts +11 -12
- package/src/core/errors.ts +16 -19
- package/src/core/events.ts +47 -47
- package/src/core/microtasks.ts +12 -11
- package/src/core/model/idResolvers.ts +10 -7
- package/src/core/model/identifyModel.ts +16 -11
- package/src/core/model/index.ts +9 -4
- package/src/core/query/filtering.ts +5 -3
- package/src/core/query/index.ts +4 -4
- package/src/core/query/paging.ts +47 -52
- package/src/core/query/query.ts +58 -64
- package/src/core/query/sorting.ts +21 -15
- package/src/core/subscription.ts +36 -16
- package/src/core/transports/http.ts +27 -25
- package/src/core/transports/mqtt.ts +70 -51
- package/src/core/transports/utils.ts +8 -7
- package/src/core/transports/ws.ts +16 -17
- package/src/core/uuid.ts +3 -2
- package/src/feed/api/index.ts +1 -1
- package/src/feed/api/queryGlobalFeed.ts +53 -43
- package/src/file/api/createFile.ts +23 -22
- package/src/file/api/createVideo.ts +58 -0
- package/src/file/api/deleteFile.ts +9 -11
- package/src/file/api/fileUrlWithSize.ts +2 -2
- package/src/file/api/getFile.ts +19 -24
- package/src/file/api/index.ts +5 -4
- package/src/file/observers/index.ts +1 -1
- package/src/file/observers/observeFile.ts +17 -23
- package/src/follow/api/acceptFollower.ts +34 -0
- package/src/follow/api/declineFollower.ts +34 -0
- package/src/follow/api/follow.ts +44 -0
- package/src/follow/api/getFollowInfo.ts +83 -0
- package/src/follow/api/index.ts +8 -0
- package/src/follow/api/queryFollowers.ts +39 -0
- package/src/follow/api/queryFollowings.ts +39 -0
- package/src/follow/api/unfollow.ts +34 -0
- package/src/follow/api/utils.ts +82 -0
- package/src/follow/events/index.ts +10 -0
- package/src/follow/events/onFollowInfoUpdated.ts +45 -0
- package/src/follow/events/onFollowRequestAccepted.ts +20 -0
- package/src/follow/events/onFollowRequestCanceled.ts +20 -0
- package/src/follow/events/onFollowRequestDeclined.ts +20 -0
- package/src/follow/events/onFollowerDeleted.ts +20 -0
- package/src/follow/events/onFollowerRequested.ts +20 -0
- package/src/follow/events/onUserFollowed.ts +19 -0
- package/src/follow/events/onUserUnfollowed.ts +20 -0
- package/src/follow/events/utils.ts +33 -0
- package/src/follow/observers/index.ts +3 -0
- package/src/follow/observers/observeFollowInfo.ts +64 -0
- package/src/follow/observers/observeFollowers.ts +77 -0
- package/src/follow/observers/observeFollowings.ts +77 -0
- package/src/index.ts +43 -35
- package/src/message/api/createMessage.ts +31 -29
- package/src/message/api/deleteMessage.ts +22 -22
- package/src/message/api/getMessage.ts +18 -19
- package/src/message/api/getMessages.ts +22 -24
- package/src/message/api/index.ts +6 -6
- package/src/message/api/queryMessages.ts +55 -47
- package/src/message/api/updateMessage.ts +26 -25
- package/src/message/events/index.ts +3 -3
- package/src/message/events/onMessageCreated.ts +10 -17
- package/src/message/events/onMessageDeleted.ts +10 -17
- package/src/message/events/onMessageUpdated.ts +10 -17
- package/src/message/observers/index.ts +2 -2
- package/src/message/observers/observeMessage.ts +23 -29
- package/src/message/observers/observeMessages.ts +20 -22
- package/src/poll/api/closePoll.ts +39 -0
- package/src/poll/api/createPoll.ts +43 -0
- package/src/poll/api/deletePoll.ts +36 -0
- package/src/poll/api/getPoll.ts +64 -0
- package/src/poll/api/index.ts +7 -0
- package/src/poll/api/votePoll.ts +41 -0
- package/src/post/api/createPost.ts +20 -20
- package/src/post/api/deletePost.ts +22 -25
- package/src/post/api/getPost.ts +23 -28
- package/src/post/api/getPosts.ts +24 -28
- package/src/post/api/index.ts +6 -6
- package/src/post/api/queryPosts.ts +49 -51
- package/src/post/api/updatePost.ts +15 -15
- package/src/post/events/index.ts +9 -9
- package/src/post/events/onPostApproved.ts +2 -2
- package/src/post/events/onPostCreated.ts +2 -2
- package/src/post/events/onPostDeclined.ts +2 -2
- package/src/post/events/onPostDeleted.ts +2 -2
- package/src/post/events/onPostFlagged.ts +2 -2
- package/src/post/events/onPostReactionAdded.ts +15 -19
- package/src/post/events/onPostReactionRemoved.ts +15 -19
- package/src/post/events/onPostUnflagged.ts +2 -2
- package/src/post/events/onPostUpdated.ts +2 -2
- package/src/post/events/utils.ts +19 -24
- package/src/post/observers/index.ts +2 -2
- package/src/post/observers/observePost.ts +46 -34
- package/src/post/observers/observePosts.ts +47 -24
- package/src/reaction/api/addReaction.ts +32 -27
- package/src/reaction/api/index.ts +2 -2
- package/src/reaction/api/removeReaction.ts +30 -27
- package/src/reaction/events/index.ts +1 -1
- package/src/reaction/events/onReactionAdded.ts +26 -22
- package/src/reaction/events/onReactionRemoved.ts +26 -22
- package/src/reaction/utils/dispatchReactable.ts +5 -7
- package/src/reaction/utils/fetchReference.ts +8 -11
- package/src/reaction/utils/index.ts +3 -3
- package/src/reaction/utils/preparePayloadForCache.ts +27 -19
- package/src/report/api/createReport.ts +20 -19
- package/src/report/api/deleteReport.ts +20 -19
- package/src/report/api/index.ts +3 -3
- package/src/report/api/isReportedByMe.ts +13 -13
- package/src/report/constants/referenceTypes.ts +1 -1
- package/src/role/api/getRole.ts +19 -26
- package/src/role/api/index.ts +2 -2
- package/src/role/api/queryRoles.ts +29 -32
- package/src/stream/api/createStream.ts +11 -13
- package/src/stream/api/deleteStream.ts +14 -16
- package/src/stream/api/disposeStream.ts +11 -11
- package/src/stream/api/getStream.ts +21 -21
- package/src/stream/api/index.ts +6 -6
- package/src/stream/api/queryStreams.ts +36 -37
- package/src/stream/api/updateStream.ts +12 -12
- package/src/stream/events/index.ts +3 -3
- package/src/stream/events/onStreamRecorded.ts +10 -12
- package/src/stream/events/onStreamStarted.ts +10 -12
- package/src/stream/events/onStreamStopped.ts +10 -17
- package/src/user/api/getUser.ts +18 -22
- package/src/user/api/getUsers.ts +23 -27
- package/src/user/api/index.ts +4 -4
- package/src/user/api/queryUsers.ts +42 -46
- package/src/user/api/updateUser.ts +18 -13
- package/src/user/events/index.ts +4 -4
- package/src/user/events/onUserFlagCleared.ts +2 -2
- package/src/user/events/onUserFlagged.ts +2 -2
- package/src/user/events/onUserUnflagged.ts +2 -2
- package/src/user/events/onUserUpdated.ts +2 -2
- package/src/user/events/utils.ts +10 -15
- package/src/user/observers/index.ts +1 -1
- package/src/user/observers/observeUser.ts +25 -34
- package/src/utils/env.ts +9 -4
- package/src/version.ts +2 -2
- package/dist/community/api/addCommunityMembersRole.d.ts +0 -18
- package/dist/community/api/addCommunityMembersRole.d.ts.map +0 -1
- package/dist/community/api/removeCommunityMembersRole.d.ts +0 -18
- package/dist/community/api/removeCommunityMembersRole.d.ts.map +0 -1
- package/src/community/api/addCommunityMembersRole.ts +0 -41
- package/src/community/api/removeCommunityMembersRole.ts +0 -41
package/dist/index.esm.js
CHANGED
|
@@ -7,7 +7,10 @@ import mitt from 'mitt';
|
|
|
7
7
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
8
8
|
|
|
9
9
|
var _a$1;
|
|
10
|
-
|
|
10
|
+
/* eslint-disable no-undef */
|
|
11
|
+
const theGlobal =
|
|
12
|
+
// eslint-disable-next-line no-nested-ternary
|
|
13
|
+
typeof globalThis === 'object' ? globalThis : typeof global === 'object' ? global : window;
|
|
11
14
|
const { process: safeProcess = {} } = theGlobal;
|
|
12
15
|
const isProduction = ((_a$1 = safeProcess.env) === null || _a$1 === void 0 ? void 0 : _a$1.NODE_ENV) === 'production';
|
|
13
16
|
|
|
@@ -22,7 +25,7 @@ const VERSION$1 = (_b = (_a = safeProcess.env) === null || _a === void 0 ? void
|
|
|
22
25
|
*
|
|
23
26
|
* @hidden
|
|
24
27
|
*/
|
|
25
|
-
const isSkipLimit = (json) =>
|
|
28
|
+
const isSkipLimit = (json) => ['skip', 'limit'].some(prop => prop in json);
|
|
26
29
|
/**
|
|
27
30
|
* Type guard to find if the a given decoded backend token uses "after/before" pagination style
|
|
28
31
|
*
|
|
@@ -31,7 +34,7 @@ const isSkipLimit = (json) => (['skip', 'limit'].some(prop => prop in json));
|
|
|
31
34
|
*
|
|
32
35
|
* @hidden
|
|
33
36
|
*/
|
|
34
|
-
const isAfterBefore = (json) =>
|
|
37
|
+
const isAfterBefore = (json) => ['after', 'before', 'first', 'last', 'limit'].some(prop => prop in json);
|
|
35
38
|
/**
|
|
36
39
|
* Type guard to find if the a given decoded backend token uses v4 or newer "after/before" pagination style
|
|
37
40
|
*
|
|
@@ -40,7 +43,7 @@ const isAfterBefore = (json) => (['after', 'before', 'first', 'last', 'limit'].s
|
|
|
40
43
|
*
|
|
41
44
|
* @hidden
|
|
42
45
|
*/
|
|
43
|
-
const isAfterBeforeRaw = (json) =>
|
|
46
|
+
const isAfterBeforeRaw = (json) => 'limit' in json;
|
|
44
47
|
/**
|
|
45
48
|
* Type guard to find if the a given object is wrapped around Amity.Paged<>
|
|
46
49
|
*
|
|
@@ -50,9 +53,9 @@ const isAfterBeforeRaw = (json) => ('limit' in json);
|
|
|
50
53
|
* @hidden
|
|
51
54
|
*/
|
|
52
55
|
const isPaged = (payload) => {
|
|
53
|
-
return ((payload === null || payload === void 0 ? void 0 : payload.hasOwnProperty('data'))
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
return ((payload === null || payload === void 0 ? void 0 : payload.hasOwnProperty('data')) &&
|
|
57
|
+
(payload === null || payload === void 0 ? void 0 : payload.hasOwnProperty('nextPage')) &&
|
|
58
|
+
(payload === null || payload === void 0 ? void 0 : payload.hasOwnProperty('prevPage')));
|
|
56
59
|
};
|
|
57
60
|
/**
|
|
58
61
|
* Converts a paging object into a b64 string token
|
|
@@ -82,19 +85,19 @@ const toToken = (paging, style) => {
|
|
|
82
85
|
"before" or "after" value. if that would change,
|
|
83
86
|
we'd need to move toward a more simple: `!paging.before`
|
|
84
87
|
*/
|
|
85
|
-
if (!isNaN(paging === null || paging === void 0 ? void 0 : paging.before)) {
|
|
88
|
+
if (!Number.isNaN(paging === null || paging === void 0 ? void 0 : paging.before)) {
|
|
86
89
|
payload = {
|
|
87
90
|
before: paging.before,
|
|
88
91
|
last: paging.limit,
|
|
89
92
|
};
|
|
90
93
|
}
|
|
91
|
-
else if (!isNaN(paging === null || paging === void 0 ? void 0 : paging.after)) {
|
|
94
|
+
else if (!Number.isNaN(paging === null || paging === void 0 ? void 0 : paging.after)) {
|
|
92
95
|
payload = {
|
|
93
96
|
after: paging.after,
|
|
94
97
|
first: paging.limit,
|
|
95
98
|
};
|
|
96
99
|
}
|
|
97
|
-
else if (!isNaN(paging === null || paging === void 0 ? void 0 : paging.limit)) {
|
|
100
|
+
else if (!Number.isNaN(paging === null || paging === void 0 ? void 0 : paging.limit)) {
|
|
98
101
|
payload = {
|
|
99
102
|
last: paging.limit,
|
|
100
103
|
};
|
|
@@ -119,7 +122,7 @@ const toToken = (paging, style) => {
|
|
|
119
122
|
*/
|
|
120
123
|
const toPage = (token) => {
|
|
121
124
|
if (!token)
|
|
122
|
-
return
|
|
125
|
+
return undefined;
|
|
123
126
|
// don't try catch, let it throw
|
|
124
127
|
const json = JSON.parse(decode(token));
|
|
125
128
|
if (isSkipLimit(json)) {
|
|
@@ -128,21 +131,21 @@ const toPage = (token) => {
|
|
|
128
131
|
limit: json.limit,
|
|
129
132
|
};
|
|
130
133
|
}
|
|
131
|
-
|
|
134
|
+
if (isAfterBefore(json)) {
|
|
132
135
|
if ('before' in json) {
|
|
133
136
|
return {
|
|
134
137
|
before: json.before,
|
|
135
138
|
limit: json.last,
|
|
136
139
|
};
|
|
137
140
|
}
|
|
138
|
-
|
|
141
|
+
if ('after' in json) {
|
|
139
142
|
return {
|
|
140
143
|
after: json.after,
|
|
141
144
|
limit: json.first,
|
|
142
145
|
};
|
|
143
146
|
}
|
|
144
147
|
}
|
|
145
|
-
return
|
|
148
|
+
return undefined;
|
|
146
149
|
};
|
|
147
150
|
/**
|
|
148
151
|
* Converts a b64 string token into a paging object
|
|
@@ -154,15 +157,16 @@ const toPage = (token) => {
|
|
|
154
157
|
*/
|
|
155
158
|
const toPageRaw = (token) => {
|
|
156
159
|
if (!token)
|
|
157
|
-
return
|
|
160
|
+
return undefined;
|
|
158
161
|
// don't try catch, let it throw
|
|
159
162
|
const json = JSON.parse(decode(token));
|
|
160
163
|
if (isAfterBeforeRaw(json)) {
|
|
161
164
|
return json;
|
|
162
165
|
}
|
|
163
|
-
return
|
|
166
|
+
return undefined;
|
|
164
167
|
};
|
|
165
168
|
|
|
169
|
+
/* eslint-disable no-use-before-define */
|
|
166
170
|
/**
|
|
167
171
|
* Type guard to check and cast that a given async function is has the ".locally" property
|
|
168
172
|
*
|
|
@@ -171,7 +175,7 @@ const toPageRaw = (token) => {
|
|
|
171
175
|
*
|
|
172
176
|
* @hidden
|
|
173
177
|
*/
|
|
174
|
-
const isFetcher = (func) =>
|
|
178
|
+
const isFetcher = (func) => 'locally' in func;
|
|
175
179
|
/**
|
|
176
180
|
* Type guard to check and cast that a given async function is has the ".optimistically" property
|
|
177
181
|
*
|
|
@@ -180,7 +184,7 @@ const isFetcher = (func) => ('locally' in func);
|
|
|
180
184
|
*
|
|
181
185
|
* @hidden
|
|
182
186
|
*/
|
|
183
|
-
const isMutator = (func) =>
|
|
187
|
+
const isMutator = (func) => 'optimistically' in func;
|
|
184
188
|
/**
|
|
185
189
|
* Type guard to check and cast that a given async function is has
|
|
186
190
|
* the ".locally" or ".optimistically" property
|
|
@@ -199,7 +203,7 @@ const isOffline = (func) => isFetcher(func) || isMutator(func);
|
|
|
199
203
|
*
|
|
200
204
|
* @hidden
|
|
201
205
|
*/
|
|
202
|
-
const isCachable = (model) =>
|
|
206
|
+
const isCachable = (model) => model === null || model === void 0 ? void 0 : model.hasOwnProperty('cachedAt');
|
|
203
207
|
/**
|
|
204
208
|
* Checks if a model is considered local (cachedAt === -1)
|
|
205
209
|
*
|
|
@@ -257,7 +261,7 @@ const createQuery = (func, ...args) => ({ func, args });
|
|
|
257
261
|
const queryOptions = (policy, lifeSpan = 2 * 60 * 1000) => {
|
|
258
262
|
if (policy === 'cache_only')
|
|
259
263
|
return { lifeSpan: Infinity };
|
|
260
|
-
|
|
264
|
+
if (policy === 'server_only')
|
|
261
265
|
return { lifeSpan: 0 };
|
|
262
266
|
return { lifeSpan };
|
|
263
267
|
};
|
|
@@ -283,9 +287,7 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
283
287
|
// offline first
|
|
284
288
|
if (isOffline(func) && options.lifeSpan !== 0) {
|
|
285
289
|
try {
|
|
286
|
-
local = isMutator(func)
|
|
287
|
-
? func.optimistically(...args)
|
|
288
|
-
: func.locally(...args);
|
|
290
|
+
local = isMutator(func) ? func.optimistically(...args) : func.locally(...args);
|
|
289
291
|
}
|
|
290
292
|
catch (error) {
|
|
291
293
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(undefined, {
|
|
@@ -297,7 +299,7 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
297
299
|
const shouldAbort = isCachable(local) && isFresh(local, options.lifeSpan);
|
|
298
300
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(local, {
|
|
299
301
|
origin: 'local',
|
|
300
|
-
loading: !(isFetcher(func) && shouldAbort)
|
|
302
|
+
loading: !(isFetcher(func) && shouldAbort),
|
|
301
303
|
}));
|
|
302
304
|
if (shouldAbort)
|
|
303
305
|
return;
|
|
@@ -305,13 +307,13 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
305
307
|
else {
|
|
306
308
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(undefined, {
|
|
307
309
|
origin: 'local',
|
|
308
|
-
loading: true
|
|
310
|
+
loading: true,
|
|
309
311
|
}));
|
|
310
312
|
}
|
|
311
313
|
func(...args)
|
|
312
314
|
.then(fresh => {
|
|
313
315
|
// @ts-ignore i know.
|
|
314
|
-
//
|
|
316
|
+
// isLocal(local) && syncInCache(local, fresh)
|
|
315
317
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(fresh, {
|
|
316
318
|
origin: 'server',
|
|
317
319
|
loading: false,
|
|
@@ -325,6 +327,7 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
325
327
|
}));
|
|
326
328
|
});
|
|
327
329
|
};
|
|
330
|
+
// eslint-disable-next-line no-redeclare
|
|
328
331
|
function createSnapshot(data, options) {
|
|
329
332
|
if (isPaged(data) || isCachable(data))
|
|
330
333
|
return Object.assign(Object.assign({}, options), data);
|
|
@@ -378,6 +381,7 @@ const sortByLastCreated = ({ createdAt: a }, { createdAt: b }) => new Date(b).va
|
|
|
378
381
|
*/
|
|
379
382
|
const sortByLastActivity = ({ lastActivity: a }, { lastActivity: b }) => new Date(b).valueOf() - new Date(a).valueOf();
|
|
380
383
|
|
|
384
|
+
/* eslint-disable max-classes-per-file */
|
|
381
385
|
/**
|
|
382
386
|
* Generic ASC error
|
|
383
387
|
* @category Errors
|
|
@@ -407,6 +411,7 @@ class ASCApiError extends ASCError {
|
|
|
407
411
|
* @param code A normalized error code
|
|
408
412
|
* @param level A normalized failure level descriptor
|
|
409
413
|
*/
|
|
414
|
+
// eslint-disable-next-line no-useless-constructor
|
|
410
415
|
constructor(message, code, level) {
|
|
411
416
|
super(message, code, level);
|
|
412
417
|
}
|
|
@@ -433,7 +438,9 @@ class ASCConnectionError extends ASCError {
|
|
|
433
438
|
* @param message A custom error message
|
|
434
439
|
*/
|
|
435
440
|
constructor(event, message = 'SDK client is having connection issues') {
|
|
436
|
-
super(`${message} (${event})`, event === 'disconnected'
|
|
441
|
+
super(`${message} (${event})`, event === 'disconnected'
|
|
442
|
+
? 800211 /* DISCONNECTED */
|
|
443
|
+
: 800210 /* CONNECTION_ERROR */, "error" /* ERROR */);
|
|
437
444
|
this.event = event;
|
|
438
445
|
}
|
|
439
446
|
}
|
|
@@ -473,12 +480,12 @@ const setActiveClient = (client) => {
|
|
|
473
480
|
* @hidden
|
|
474
481
|
*/
|
|
475
482
|
const createLogger = (session) => {
|
|
476
|
-
const active =
|
|
477
|
-
&& !isProduction);
|
|
483
|
+
const active = `${session === null || session === void 0 ? void 0 : session.trim()}`.length > 0 && !isProduction;
|
|
478
484
|
const logger = debug(session);
|
|
479
485
|
const print = (topic, ...args) => {
|
|
480
486
|
active && logger(topic, args);
|
|
481
487
|
};
|
|
488
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
482
489
|
print.__instance__ = logger;
|
|
483
490
|
return print;
|
|
484
491
|
};
|
|
@@ -511,7 +518,7 @@ const unwrapPayload = (response) => {
|
|
|
511
518
|
if (response.status === 'success') {
|
|
512
519
|
return response.data;
|
|
513
520
|
}
|
|
514
|
-
|
|
521
|
+
if (response.status === 'fail') {
|
|
515
522
|
throw new ASCUnknownError(response.code);
|
|
516
523
|
}
|
|
517
524
|
else if (response.status === 'error') {
|
|
@@ -533,9 +540,10 @@ const stringify = (params, prefix) => {
|
|
|
533
540
|
if (Array.isArray(value)) {
|
|
534
541
|
return value.map(item => `${key}[]=${item}`).join('&');
|
|
535
542
|
}
|
|
536
|
-
|
|
543
|
+
if (typeof value !== 'object') {
|
|
537
544
|
return `${key}=${value}`;
|
|
538
545
|
}
|
|
546
|
+
// @ts-ignore
|
|
539
547
|
return stringify(value, prefix !== null && prefix !== void 0 ? prefix : name);
|
|
540
548
|
})
|
|
541
549
|
.join('&');
|
|
@@ -562,9 +570,10 @@ const createHttpTransport = (endpoint) => {
|
|
|
562
570
|
httpsAgent: new HttpsAgent(options),
|
|
563
571
|
paramsSerializer: stringify,
|
|
564
572
|
});
|
|
565
|
-
instance.interceptors.response.use(
|
|
573
|
+
instance.interceptors.response.use(response => response, error => {
|
|
566
574
|
var _a;
|
|
567
575
|
const { response } = error;
|
|
576
|
+
// eslint-disable-next-line no-console
|
|
568
577
|
console.error((_a = response === null || response === void 0 ? void 0 : response.data) !== null && _a !== void 0 ? _a : error);
|
|
569
578
|
if (response)
|
|
570
579
|
unwrapPayload(response.data);
|
|
@@ -14582,6 +14591,7 @@ function extend() {
|
|
|
14582
14591
|
|
|
14583
14592
|
var mqtt = mqtt$1.exports;
|
|
14584
14593
|
|
|
14594
|
+
/* eslint-disable no-console */
|
|
14585
14595
|
const QOS_FAILURE_CODE = 128;
|
|
14586
14596
|
const RETRY_BASE_TIMEOUT = 1000;
|
|
14587
14597
|
const RETRY_COUNT_MAX = 10;
|
|
@@ -14596,7 +14606,7 @@ function getMqttOptions(params) {
|
|
|
14596
14606
|
topic: 'WillMsg',
|
|
14597
14607
|
payload: 'Connection Closed abnormally..!',
|
|
14598
14608
|
qos: 0,
|
|
14599
|
-
retain: false
|
|
14609
|
+
retain: false,
|
|
14600
14610
|
} }, params);
|
|
14601
14611
|
}
|
|
14602
14612
|
/**
|
|
@@ -14612,6 +14622,12 @@ const createMqttTransport = (endpoint) => {
|
|
|
14612
14622
|
let mqttClient;
|
|
14613
14623
|
let retryCount = 0;
|
|
14614
14624
|
let allowReconnection = true;
|
|
14625
|
+
const reconnect = () => {
|
|
14626
|
+
setTimeout(() => {
|
|
14627
|
+
retryCount += 1;
|
|
14628
|
+
mqttClient.reconnect();
|
|
14629
|
+
}, RETRY_BASE_TIMEOUT * 2 ** (retryCount > RETRY_COUNT_MAX ? RETRY_COUNT_MAX : retryCount));
|
|
14630
|
+
};
|
|
14615
14631
|
async function connect(params) {
|
|
14616
14632
|
if (mqttClient) {
|
|
14617
14633
|
mqttClient.removeAllListeners();
|
|
@@ -14623,6 +14639,7 @@ const createMqttTransport = (endpoint) => {
|
|
|
14623
14639
|
allowReconnection = true;
|
|
14624
14640
|
});
|
|
14625
14641
|
mqttClient.on('error', (error) => {
|
|
14642
|
+
// eslint-disable-next-line default-case
|
|
14626
14643
|
switch (error.code) {
|
|
14627
14644
|
case 2 /* IDENTIFIER_REJECTED */:
|
|
14628
14645
|
case 4 /* BAD_USERNAME_OR_PASSWORD */:
|
|
@@ -14637,12 +14654,6 @@ const createMqttTransport = (endpoint) => {
|
|
|
14637
14654
|
});
|
|
14638
14655
|
return new Promise(resolve => mqttClient.once('connect', () => resolve()));
|
|
14639
14656
|
}
|
|
14640
|
-
const reconnect = () => {
|
|
14641
|
-
setTimeout(() => {
|
|
14642
|
-
retryCount = retryCount + 1;
|
|
14643
|
-
mqttClient.reconnect();
|
|
14644
|
-
}, RETRY_BASE_TIMEOUT * Math.pow(2, retryCount > RETRY_COUNT_MAX ? RETRY_COUNT_MAX : retryCount));
|
|
14645
|
-
};
|
|
14646
14657
|
return {
|
|
14647
14658
|
connect,
|
|
14648
14659
|
async disconnect() {
|
|
@@ -14676,8 +14687,8 @@ const createMqttTransport = (endpoint) => {
|
|
|
14676
14687
|
if (error || granted[0].qos === QOS_FAILURE_CODE) {
|
|
14677
14688
|
const ascError = error
|
|
14678
14689
|
? new ASCError(error.message, 800000 /* UNKNOWN_ERROR */, "error" /* ERROR */)
|
|
14679
|
-
// TODO throw the actual error, once BE can tell us the actual error code
|
|
14680
|
-
|
|
14690
|
+
: // TODO throw the actual error, once BE can tell us the actual error code
|
|
14691
|
+
new ASCUnknownError(800000 /* UNKNOWN_ERROR */, "error" /* ERROR */);
|
|
14681
14692
|
console.error(`Failed to subscribe to topic ${topic}`, ascError);
|
|
14682
14693
|
callback === null || callback === void 0 ? void 0 : callback(ascError);
|
|
14683
14694
|
}
|
|
@@ -14696,10 +14707,11 @@ const createMqttTransport = (endpoint) => {
|
|
|
14696
14707
|
},
|
|
14697
14708
|
unsubscribe(topic) {
|
|
14698
14709
|
mqttClient === null || mqttClient === void 0 ? void 0 : mqttClient.unsubscribe(topic);
|
|
14699
|
-
}
|
|
14710
|
+
},
|
|
14700
14711
|
};
|
|
14701
14712
|
};
|
|
14702
14713
|
|
|
14714
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
14703
14715
|
let tasks = [];
|
|
14704
14716
|
let timer;
|
|
14705
14717
|
/**
|
|
@@ -14716,6 +14728,7 @@ const scheduleTask = (task) => {
|
|
|
14716
14728
|
}, 0);
|
|
14717
14729
|
};
|
|
14718
14730
|
|
|
14731
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
14719
14732
|
// need to sync up the list
|
|
14720
14733
|
const WS_EVENTS = [
|
|
14721
14734
|
'disconnected',
|
|
@@ -14742,7 +14755,7 @@ const MQTT_EVENTS = [
|
|
|
14742
14755
|
'error',
|
|
14743
14756
|
'close',
|
|
14744
14757
|
'end',
|
|
14745
|
-
'reconnect'
|
|
14758
|
+
'reconnect',
|
|
14746
14759
|
];
|
|
14747
14760
|
/** @hidden */
|
|
14748
14761
|
const createEventEmitter = () => {
|
|
@@ -14806,7 +14819,9 @@ const createEventSubscriber = (client, namespace, event, fn) => {
|
|
|
14806
14819
|
*/
|
|
14807
14820
|
const fireEvent = (event, payload) => {
|
|
14808
14821
|
const { emitter } = getActiveClient();
|
|
14809
|
-
scheduleTask(() => {
|
|
14822
|
+
scheduleTask(() => {
|
|
14823
|
+
emitter.emit(event, payload);
|
|
14824
|
+
});
|
|
14810
14825
|
};
|
|
14811
14826
|
|
|
14812
14827
|
/**
|
|
@@ -14823,7 +14838,7 @@ const fireEvent = (event, payload) => {
|
|
|
14823
14838
|
* @returns A {@link Amity.Client} instance
|
|
14824
14839
|
*
|
|
14825
14840
|
* @category Client API
|
|
14826
|
-
|
|
14841
|
+
* */
|
|
14827
14842
|
const createClient = (apiKey, apiRegion = API_REGIONS.SG, debugSession = 'amity') => {
|
|
14828
14843
|
const log = createLogger(debugSession);
|
|
14829
14844
|
log('client/api/createClient', {
|
|
@@ -14916,6 +14931,24 @@ const getDeviceInfo = () => {
|
|
|
14916
14931
|
};
|
|
14917
14932
|
};
|
|
14918
14933
|
|
|
14934
|
+
let activeUser = null;
|
|
14935
|
+
/**
|
|
14936
|
+
* for internal use
|
|
14937
|
+
*/
|
|
14938
|
+
const getActiveUser = () => {
|
|
14939
|
+
if (!activeUser) {
|
|
14940
|
+
throw new ASCError('Connect client first', 800000 /* UNKNOWN_ERROR */, "fatal" /* FATAL */);
|
|
14941
|
+
}
|
|
14942
|
+
return activeUser;
|
|
14943
|
+
};
|
|
14944
|
+
const setActiveUser = (user) => {
|
|
14945
|
+
activeUser = {
|
|
14946
|
+
_id: user._id,
|
|
14947
|
+
userId: user.userId,
|
|
14948
|
+
path: user.path,
|
|
14949
|
+
};
|
|
14950
|
+
};
|
|
14951
|
+
|
|
14919
14952
|
/**
|
|
14920
14953
|
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
14921
14954
|
*
|
|
@@ -14933,8 +14966,8 @@ const getToken = async (params) => {
|
|
|
14933
14966
|
client.log('client/api/getToken', params);
|
|
14934
14967
|
const deviceInfo = await getDeviceInfo();
|
|
14935
14968
|
const { data } = await client.http.post('/v1/device', Object.assign(Object.assign({}, params), { deviceInfo }), {
|
|
14936
|
-
|
|
14937
|
-
headers: { 'X-API-Key': client.apiKey }
|
|
14969
|
+
// @ts-ignore
|
|
14970
|
+
headers: { 'X-API-Key': client.apiKey },
|
|
14938
14971
|
});
|
|
14939
14972
|
return data;
|
|
14940
14973
|
};
|
|
@@ -14963,12 +14996,12 @@ const EVENTS = [
|
|
|
14963
14996
|
*/
|
|
14964
14997
|
const onConnectionError = (callback) => {
|
|
14965
14998
|
const client = getActiveClient();
|
|
14966
|
-
const subscribers = EVENTS.map(event =>
|
|
14999
|
+
const subscribers = EVENTS.map(event => createEventSubscriber(client, `client/onConnectionError(${event})`, event, response => {
|
|
14967
15000
|
const error = (response === null || response === void 0 ? void 0 : response.code)
|
|
14968
15001
|
? new ASCError(response.message, response.code, "fatal" /* FATAL */)
|
|
14969
15002
|
: new ASCConnectionError(event);
|
|
14970
15003
|
callback(error);
|
|
14971
|
-
}))
|
|
15004
|
+
}));
|
|
14972
15005
|
return () => {
|
|
14973
15006
|
subscribers.forEach(fn => fn());
|
|
14974
15007
|
};
|
|
@@ -15016,6 +15049,7 @@ const onClientBanned = (callback) => {
|
|
|
15016
15049
|
});
|
|
15017
15050
|
};
|
|
15018
15051
|
|
|
15052
|
+
/* eslint-disable no-param-reassign */
|
|
15019
15053
|
/**
|
|
15020
15054
|
* ```js
|
|
15021
15055
|
* import { connectClient } from '@amityco/ts-sdk/client/api'
|
|
@@ -15046,7 +15080,7 @@ const connectClient = async (params) => {
|
|
|
15046
15080
|
// ignored since we enforce default values just before.
|
|
15047
15081
|
const { accessToken, users } = await getToken(params);
|
|
15048
15082
|
// manually setup the token for http transport
|
|
15049
|
-
client.http.defaults.headers.common
|
|
15083
|
+
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
15050
15084
|
// manually setup the token for ws transport
|
|
15051
15085
|
client.ws.io.opts.query = { token: accessToken };
|
|
15052
15086
|
// FIXME: events are duplicated if connectClient is called few times without disconnectClient
|
|
@@ -15063,8 +15097,8 @@ const connectClient = async (params) => {
|
|
|
15063
15097
|
unsubscribe();
|
|
15064
15098
|
});
|
|
15065
15099
|
client.userId = params.userId;
|
|
15066
|
-
client._internalUserId = users[0]._id;
|
|
15067
15100
|
client.accessToken = accessToken;
|
|
15101
|
+
setActiveUser(users[0]);
|
|
15068
15102
|
return client.ws.connected;
|
|
15069
15103
|
};
|
|
15070
15104
|
|
|
@@ -15084,9 +15118,9 @@ const isConnected = () => {
|
|
|
15084
15118
|
var _a, _b;
|
|
15085
15119
|
const client = getActiveClient();
|
|
15086
15120
|
client.log('client/api/isConnected', client);
|
|
15087
|
-
return !!(client.userId
|
|
15088
|
-
|
|
15089
|
-
|
|
15121
|
+
return !!(client.userId &&
|
|
15122
|
+
((_b = (_a = client.http.defaults.headers.common) === null || _a === void 0 ? void 0 : _a.Authorization) === null || _b === void 0 ? void 0 : _b.length) &&
|
|
15123
|
+
client.ws.connected);
|
|
15090
15124
|
};
|
|
15091
15125
|
|
|
15092
15126
|
var SubscriptionLevels;
|
|
@@ -15097,7 +15131,7 @@ var SubscriptionLevels;
|
|
|
15097
15131
|
SubscriptionLevels["POST_AND_COMMENT"] = "post_and_comment";
|
|
15098
15132
|
SubscriptionLevels["USER"] = "user";
|
|
15099
15133
|
})(SubscriptionLevels || (SubscriptionLevels = {}));
|
|
15100
|
-
const getCommunityUserTopic = (
|
|
15134
|
+
const getCommunityUserTopic = (path, level) => {
|
|
15101
15135
|
switch (level) {
|
|
15102
15136
|
case 'post':
|
|
15103
15137
|
return `${path}/post/+`;
|
|
@@ -15109,8 +15143,8 @@ const getCommunityUserTopic = ({ path }, level) => {
|
|
|
15109
15143
|
return path;
|
|
15110
15144
|
}
|
|
15111
15145
|
};
|
|
15112
|
-
const getCommunityTopic = ({ path }, level = SubscriptionLevels.COMMUNITY) => getCommunityUserTopic(
|
|
15113
|
-
const getUserTopic = ({ path }, level = SubscriptionLevels.USER) => getCommunityUserTopic(
|
|
15146
|
+
const getCommunityTopic = ({ path }, level = SubscriptionLevels.COMMUNITY) => getCommunityUserTopic(path, level);
|
|
15147
|
+
const getUserTopic = ({ path }, level = SubscriptionLevels.USER) => getCommunityUserTopic(level === SubscriptionLevels.USER ? path : path.replace(/^(\w*)/, '$1/social'), level);
|
|
15114
15148
|
const getPostTopic = ({ path }, level = SubscriptionLevels.POST) => {
|
|
15115
15149
|
switch (level) {
|
|
15116
15150
|
case 'comment':
|
|
@@ -15122,13 +15156,24 @@ const getPostTopic = ({ path }, level = SubscriptionLevels.POST) => {
|
|
|
15122
15156
|
const getCommentTopic = ({ path }) => {
|
|
15123
15157
|
return path;
|
|
15124
15158
|
};
|
|
15159
|
+
const getMyFollowersTopic = () => {
|
|
15160
|
+
const user = getActiveUser();
|
|
15161
|
+
const [networkId] = user.path.split('/user/');
|
|
15162
|
+
return `${networkId}/membership/${user._id}/+/+`;
|
|
15163
|
+
};
|
|
15164
|
+
const getMyFollowingsTopic = () => {
|
|
15165
|
+
const user = getActiveUser();
|
|
15166
|
+
const [networkId] = user.path.split('/user/');
|
|
15167
|
+
return `${networkId}/membership/+/${user._id}/+`;
|
|
15168
|
+
};
|
|
15125
15169
|
let mqttAccessToken;
|
|
15126
15170
|
let mqttUserId;
|
|
15127
15171
|
function subscribeTopic(topic, callback) {
|
|
15128
|
-
const { mqtt, emitter, accessToken
|
|
15129
|
-
|
|
15172
|
+
const { mqtt, emitter, accessToken } = getActiveClient();
|
|
15173
|
+
const user = getActiveUser();
|
|
15174
|
+
if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
|
|
15130
15175
|
mqttAccessToken = accessToken;
|
|
15131
|
-
mqttUserId =
|
|
15176
|
+
mqttUserId = user._id;
|
|
15132
15177
|
mqtt.connect({ accessToken: mqttAccessToken, userId: mqttUserId });
|
|
15133
15178
|
proxyMqttEvents(mqtt, emitter);
|
|
15134
15179
|
}
|
|
@@ -15211,12 +15256,15 @@ const restoreCache = async (storageKey = 'amitySdk') => {
|
|
|
15211
15256
|
try {
|
|
15212
15257
|
cache = JSON.parse(serializedData);
|
|
15213
15258
|
}
|
|
15214
|
-
catch (err) {
|
|
15259
|
+
catch (err) {
|
|
15260
|
+
//
|
|
15261
|
+
}
|
|
15215
15262
|
// current cache should override. in case there's something fresher.
|
|
15216
15263
|
client.cache.data = Object.assign(Object.assign({}, cache), client.cache.data);
|
|
15217
15264
|
return true;
|
|
15218
15265
|
};
|
|
15219
15266
|
|
|
15267
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
15220
15268
|
/**
|
|
15221
15269
|
* ```js
|
|
15222
15270
|
* import { backupCache } from '@amityco/ts-sdk'
|
|
@@ -15246,8 +15294,7 @@ const backupCache = async (storageKey = 'amitySdk', persistIf = (entry) => entry
|
|
|
15246
15294
|
log('cache/api/backupCache', { storageKey });
|
|
15247
15295
|
// prepare a subset of the cache where only
|
|
15248
15296
|
// objects to backup are there
|
|
15249
|
-
const offlineEntries = Object.fromEntries(Object.entries(cache.data)
|
|
15250
|
-
.filter(([_, entry]) => persistIf(entry)));
|
|
15297
|
+
const offlineEntries = Object.fromEntries(Object.entries(cache.data).filter(([_, entry]) => persistIf(entry)));
|
|
15251
15298
|
// nothing to backup, abort
|
|
15252
15299
|
if (!Object.keys(offlineEntries).length)
|
|
15253
15300
|
return false;
|
|
@@ -15293,9 +15340,9 @@ const wipeCache = async (storageKey = 'amitySdk') => {
|
|
|
15293
15340
|
* @category Cache
|
|
15294
15341
|
* @hidden
|
|
15295
15342
|
*/
|
|
15296
|
-
const normalize = (source) =>
|
|
15343
|
+
const normalize = (source) => Object.keys(source)
|
|
15297
15344
|
.sort()
|
|
15298
|
-
.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: source[key] })), {})
|
|
15345
|
+
.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: source[key] })), {});
|
|
15299
15346
|
/**
|
|
15300
15347
|
* Encodes a given {@link Amity.CacheKey} to a plain string
|
|
15301
15348
|
*
|
|
@@ -15305,7 +15352,7 @@ const normalize = (source) => (Object.keys(source)
|
|
|
15305
15352
|
* @category Cache
|
|
15306
15353
|
* @hidden
|
|
15307
15354
|
*/
|
|
15308
|
-
const encodeKey = (key) =>
|
|
15355
|
+
const encodeKey = (key) => JSON.stringify(key, (_, val) => (typeof val === 'object' ? normalize(val) : val));
|
|
15309
15356
|
/**
|
|
15310
15357
|
* Decodes a string back into a {@link Amity.CacheKey}
|
|
15311
15358
|
|
|
@@ -15330,14 +15377,14 @@ const partialMatch = (predicate, candidate) => {
|
|
|
15330
15377
|
if (predicate === candidate)
|
|
15331
15378
|
return true;
|
|
15332
15379
|
// if one or the other is nullish, there can't be equality
|
|
15333
|
-
|
|
15380
|
+
if (!predicate || !candidate)
|
|
15334
15381
|
return false;
|
|
15335
15382
|
// we only perform recursive check on objects
|
|
15336
|
-
|
|
15383
|
+
if (typeof predicate !== 'object') {
|
|
15337
15384
|
return false;
|
|
15338
15385
|
}
|
|
15339
15386
|
// recursively call for partial match based on the predicate
|
|
15340
|
-
return Object.keys(predicate).every(
|
|
15387
|
+
return Object.keys(predicate).every(key => partialMatch(predicate[key], candidate[key]));
|
|
15341
15388
|
};
|
|
15342
15389
|
|
|
15343
15390
|
/**
|
|
@@ -15360,8 +15407,7 @@ const queryCache = (key) => {
|
|
|
15360
15407
|
if (!cache)
|
|
15361
15408
|
return;
|
|
15362
15409
|
log('cache/api/queryCache', { key });
|
|
15363
|
-
return Object
|
|
15364
|
-
.keys(cache.data)
|
|
15410
|
+
return Object.keys(cache.data)
|
|
15365
15411
|
.filter(stringKey => {
|
|
15366
15412
|
const decodedKey = decodeKey(stringKey);
|
|
15367
15413
|
return partialMatch(key, decodedKey);
|
|
@@ -15390,9 +15436,7 @@ const pullFromCache = (key) => {
|
|
|
15390
15436
|
return;
|
|
15391
15437
|
log('cache/api/pullFromCache', key);
|
|
15392
15438
|
const str = encodeKey(key);
|
|
15393
|
-
return
|
|
15394
|
-
? cache.data[str]
|
|
15395
|
-
: undefined;
|
|
15439
|
+
return cache.data[str] ? cache.data[str] : undefined;
|
|
15396
15440
|
};
|
|
15397
15441
|
|
|
15398
15442
|
/**
|
|
@@ -15418,8 +15462,10 @@ const pushToCache = (key, data, options = { cachedAt: Date.now() }) => {
|
|
|
15418
15462
|
// if consumer did not pass offline but a offline policy is
|
|
15419
15463
|
// defined, use the fn to determine if the object needs to
|
|
15420
15464
|
// be saved in persistent storage or not.
|
|
15421
|
-
if (!(options === null || options === void 0 ? void 0 : options.hasOwnProperty('offline')) && cache.persistIf)
|
|
15465
|
+
if (!(options === null || options === void 0 ? void 0 : options.hasOwnProperty('offline')) && cache.persistIf) {
|
|
15466
|
+
// eslint-disable-next-line no-param-reassign
|
|
15422
15467
|
options.offline = cache.persistIf(key, data);
|
|
15468
|
+
}
|
|
15423
15469
|
const encodedKey = encodeKey(key);
|
|
15424
15470
|
cache.data[encodedKey] = Object.assign({ key, data }, options);
|
|
15425
15471
|
return true;
|
|
@@ -15451,9 +15497,7 @@ const mergeInCache = (key, mutation, options) => {
|
|
|
15451
15497
|
const oldVal = pullFromCache(key);
|
|
15452
15498
|
if (!oldVal)
|
|
15453
15499
|
return false;
|
|
15454
|
-
const newVal = typeof mutation === 'function'
|
|
15455
|
-
? mutation(oldVal.data)
|
|
15456
|
-
: Object.assign(Object.assign({}, oldVal.data), mutation);
|
|
15500
|
+
const newVal = typeof mutation === 'function' ? mutation(oldVal.data) : Object.assign(Object.assign({}, oldVal.data), mutation);
|
|
15457
15501
|
pushToCache(key, newVal, options);
|
|
15458
15502
|
return true;
|
|
15459
15503
|
};
|
|
@@ -15481,9 +15525,7 @@ const upsertInCache = (key, data, options = { cachedAt: Date.now() }) => {
|
|
|
15481
15525
|
return false;
|
|
15482
15526
|
log('cache/api/upsertInCache', { key, data, options });
|
|
15483
15527
|
const cached = pullFromCache(key);
|
|
15484
|
-
return cached
|
|
15485
|
-
? mergeInCache(key, data, options)
|
|
15486
|
-
: pushToCache(key, data, options);
|
|
15528
|
+
return cached ? mergeInCache(key, data, options) : pushToCache(key, data, options);
|
|
15487
15529
|
};
|
|
15488
15530
|
|
|
15489
15531
|
/**
|
|
@@ -15507,7 +15549,7 @@ const dropFromCache = (key, exact = false) => {
|
|
|
15507
15549
|
return false;
|
|
15508
15550
|
log('cache/api/dropFromCache', { key, exact });
|
|
15509
15551
|
if (!exact) {
|
|
15510
|
-
return
|
|
15552
|
+
return Object.keys(cache.data)
|
|
15511
15553
|
.map(stringKey => decodeKey(stringKey))
|
|
15512
15554
|
.filter(candidate => partialMatch(key, candidate))
|
|
15513
15555
|
.map(filteredKey => dropFromCache(filteredKey, true))
|
|
@@ -15530,10 +15572,14 @@ const idResolvers = {
|
|
|
15530
15572
|
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
15531
15573
|
message: ({ messageId }) => messageId,
|
|
15532
15574
|
community: ({ communityId }) => communityId,
|
|
15575
|
+
category: ({ categoryId }) => categoryId,
|
|
15533
15576
|
communityUsers: ({ communityId, userId }) => `${communityId}#${userId}`,
|
|
15534
15577
|
post: ({ postId }) => postId,
|
|
15535
15578
|
comment: ({ commentId }) => commentId,
|
|
15579
|
+
poll: ({ pollId }) => pollId,
|
|
15536
15580
|
stream: ({ streamId }) => streamId,
|
|
15581
|
+
follow: ({ from, to }) => `${from}#${to}`,
|
|
15582
|
+
followCount: ({ userId }) => userId,
|
|
15537
15583
|
};
|
|
15538
15584
|
/**
|
|
15539
15585
|
* Retrieve the id resolver matching a domain name
|
|
@@ -15541,7 +15587,7 @@ const idResolvers = {
|
|
|
15541
15587
|
* @param name the domain name for the resolve
|
|
15542
15588
|
* @returns an idResolver function for the given domain name
|
|
15543
15589
|
*/
|
|
15544
|
-
const getResolver = (name) =>
|
|
15590
|
+
const getResolver = (name) => idResolvers[name];
|
|
15545
15591
|
|
|
15546
15592
|
/**
|
|
15547
15593
|
* A map of v3 response keys to a store name.
|
|
@@ -15555,11 +15601,15 @@ const PAYLOAD2MODEL = {
|
|
|
15555
15601
|
channelUsers: 'channelUsers',
|
|
15556
15602
|
messages: 'message',
|
|
15557
15603
|
communities: 'community',
|
|
15604
|
+
categories: 'category',
|
|
15558
15605
|
communityUsers: 'communityUsers',
|
|
15559
15606
|
posts: 'post',
|
|
15560
15607
|
postChildren: 'post',
|
|
15561
15608
|
comments: 'comment',
|
|
15609
|
+
polls: 'poll',
|
|
15562
15610
|
videoStreamings: 'stream',
|
|
15611
|
+
follows: 'follow',
|
|
15612
|
+
followCounts: 'followCount',
|
|
15563
15613
|
};
|
|
15564
15614
|
|
|
15565
15615
|
/**
|
|
@@ -15572,8 +15622,7 @@ const PAYLOAD2MODEL = {
|
|
|
15572
15622
|
* @hidden
|
|
15573
15623
|
*/
|
|
15574
15624
|
const ingestInCache = (payload = {}, options) => {
|
|
15575
|
-
Object.entries(payload)
|
|
15576
|
-
.forEach(([key, models]) => {
|
|
15625
|
+
Object.entries(payload).forEach(([key, models]) => {
|
|
15577
15626
|
const type = PAYLOAD2MODEL[key];
|
|
15578
15627
|
if (!type)
|
|
15579
15628
|
return;
|
|
@@ -15653,13 +15702,15 @@ const getUsers = async (userIds) => {
|
|
|
15653
15702
|
client.log('user/getUsers', userIds);
|
|
15654
15703
|
const encodedUserIds = userIds.map(userId => encodeURIComponent(userId));
|
|
15655
15704
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
15656
|
-
const { data } = await client.http.get(`/api/v3/users/list`, {
|
|
15705
|
+
const { data } = await client.http.get(`/api/v3/users/list`, {
|
|
15706
|
+
params: { userIds: encodedUserIds },
|
|
15707
|
+
});
|
|
15657
15708
|
const cachedAt = client.cache && Date.now();
|
|
15658
15709
|
if (client.cache)
|
|
15659
15710
|
ingestInCache(data, { cachedAt });
|
|
15660
15711
|
return {
|
|
15661
15712
|
data: data.users,
|
|
15662
|
-
cachedAt
|
|
15713
|
+
cachedAt,
|
|
15663
15714
|
};
|
|
15664
15715
|
};
|
|
15665
15716
|
/**
|
|
@@ -15685,7 +15736,7 @@ getUsers.locally = (userIds) => {
|
|
|
15685
15736
|
.map(userId => pullFromCache(['user', 'get', userId]))
|
|
15686
15737
|
.filter(Boolean);
|
|
15687
15738
|
const users = cached.map(({ data }) => data);
|
|
15688
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
15739
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
15689
15740
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < userIds.length)
|
|
15690
15741
|
return;
|
|
15691
15742
|
return {
|
|
@@ -15739,14 +15790,14 @@ function __rest(s, e) {
|
|
|
15739
15790
|
const queryUsers = async (query = {}) => {
|
|
15740
15791
|
const client = getActiveClient();
|
|
15741
15792
|
client.log('user/queryUsers', query);
|
|
15742
|
-
const { page, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query
|
|
15743
|
-
// API-FIX: parameters should be querystring.
|
|
15744
|
-
, ["page", "displayName", "filter", "sortBy"]);
|
|
15793
|
+
const { page, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query, ["page", "displayName", "filter", "sortBy"]);
|
|
15745
15794
|
// API-FIX: parameters should be querystring.
|
|
15746
|
-
const { data } = await client.http.get(`/api/v3/users`, {
|
|
15795
|
+
const { data } = await client.http.get(`/api/v3/users`, {
|
|
15796
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter,
|
|
15747
15797
|
sortBy, options: {
|
|
15748
15798
|
token: toToken(page, 'skiplimit'),
|
|
15749
|
-
} })
|
|
15799
|
+
} }),
|
|
15800
|
+
});
|
|
15750
15801
|
// unpacking
|
|
15751
15802
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
15752
15803
|
const { users } = payload;
|
|
@@ -15952,7 +16003,7 @@ const observeUser = (userId, callback) => {
|
|
|
15952
16003
|
*
|
|
15953
16004
|
* Fetches a {@link Amity.File} object
|
|
15954
16005
|
*
|
|
15955
|
-
* @param
|
|
16006
|
+
* @param fileId the ID of the {@link Amity.File} to fetch
|
|
15956
16007
|
* @returns the associated {@link Amity.File} object
|
|
15957
16008
|
*
|
|
15958
16009
|
* @category File API
|
|
@@ -16008,6 +16059,7 @@ getFile.locally = (fileId) => {
|
|
|
16008
16059
|
* Creates an {@link Amity.File}
|
|
16009
16060
|
*
|
|
16010
16061
|
* @param formData The data necessary to create a new {@link Amity.File}
|
|
16062
|
+
* @param onProgress The callback to track the upload progress
|
|
16011
16063
|
* @returns The newly created {@link Amity.File}
|
|
16012
16064
|
*
|
|
16013
16065
|
* @category File API
|
|
@@ -16016,15 +16068,16 @@ getFile.locally = (fileId) => {
|
|
|
16016
16068
|
const createFile = async (formData, onProgress) => {
|
|
16017
16069
|
const client = getActiveClient();
|
|
16018
16070
|
client.log('file/createFile', formData);
|
|
16019
|
-
if (!formData.getAll('
|
|
16020
|
-
throw new Error('The formData object must have a `
|
|
16071
|
+
if (!formData.getAll('files').length)
|
|
16072
|
+
throw new Error('The formData object must have a `files` key.');
|
|
16021
16073
|
const headers = 'getHeaders' in formData
|
|
16022
16074
|
? formData.getHeaders()
|
|
16023
16075
|
: { 'content-type': 'multipart/form-data' };
|
|
16024
|
-
const { data } = await client.http.post('/api/
|
|
16025
|
-
headers,
|
|
16076
|
+
const { data } = await client.http.post('/api/v4/files', formData, {
|
|
16077
|
+
headers,
|
|
16078
|
+
onUploadProgress({ loaded, total }) {
|
|
16026
16079
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
16027
|
-
}
|
|
16080
|
+
},
|
|
16028
16081
|
});
|
|
16029
16082
|
// API-FIX: payload should be serialized properly
|
|
16030
16083
|
// const { files } = data
|
|
@@ -16032,7 +16085,7 @@ const createFile = async (formData, onProgress) => {
|
|
|
16032
16085
|
if (client.cache)
|
|
16033
16086
|
ingestInCache({ files: data }, { cachedAt });
|
|
16034
16087
|
return {
|
|
16035
|
-
data
|
|
16088
|
+
data,
|
|
16036
16089
|
cachedAt,
|
|
16037
16090
|
};
|
|
16038
16091
|
};
|
|
@@ -16072,6 +16125,47 @@ const fileUrlWithSize = (fileUrl, size) => {
|
|
|
16072
16125
|
return `${fileUrl}?size=${size}`;
|
|
16073
16126
|
};
|
|
16074
16127
|
|
|
16128
|
+
/**
|
|
16129
|
+
* ```js
|
|
16130
|
+
* import { createVideo } from '@amityco/ts-sdk'
|
|
16131
|
+
* const created = await createVideo(formData)
|
|
16132
|
+
* ```
|
|
16133
|
+
*
|
|
16134
|
+
* Creates an {@link Amity.File<'video'>}
|
|
16135
|
+
*
|
|
16136
|
+
* @param formData The data necessary to create a new {@link Amity.File<'video'>}
|
|
16137
|
+
* @param onProgress The callback to track the upload progress
|
|
16138
|
+
* @returns The newly created {@link Amity.File<'video'>}
|
|
16139
|
+
*
|
|
16140
|
+
* @category File API
|
|
16141
|
+
* @async
|
|
16142
|
+
*/
|
|
16143
|
+
const createVideo = async (formData, onProgress) => {
|
|
16144
|
+
const client = getActiveClient();
|
|
16145
|
+
client.log('file/createVideo', formData);
|
|
16146
|
+
if (!formData.getAll('files').length)
|
|
16147
|
+
throw new Error('The formData object must have a `files` key.');
|
|
16148
|
+
const headers = 'getHeaders' in formData
|
|
16149
|
+
? formData.getHeaders()
|
|
16150
|
+
: { 'content-type': 'multipart/form-data' };
|
|
16151
|
+
const { data } = await client.http.post('/api/v4/videos', formData, {
|
|
16152
|
+
headers,
|
|
16153
|
+
onUploadProgress({ loaded, total }) {
|
|
16154
|
+
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
16155
|
+
},
|
|
16156
|
+
});
|
|
16157
|
+
// API-FIX: payload should be serialized properly
|
|
16158
|
+
// const { files } = data
|
|
16159
|
+
const cachedAt = client.cache && Date.now();
|
|
16160
|
+
if (client.cache)
|
|
16161
|
+
ingestInCache({ files: data }, { cachedAt });
|
|
16162
|
+
return {
|
|
16163
|
+
data,
|
|
16164
|
+
cachedAt,
|
|
16165
|
+
};
|
|
16166
|
+
};
|
|
16167
|
+
// TODO: consider doing local creation with URL.createObjectURL()
|
|
16168
|
+
|
|
16075
16169
|
/**
|
|
16076
16170
|
* ```js
|
|
16077
16171
|
* import { observeFile } from '@amityco/ts-sdk'
|
|
@@ -16303,13 +16397,15 @@ const getMessages = async (messageIds) => {
|
|
|
16303
16397
|
const client = getActiveClient();
|
|
16304
16398
|
client.log('message/getMessages', messageIds);
|
|
16305
16399
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
16306
|
-
const { data } = await client.http.get(`/api/v3/messages/list`, {
|
|
16400
|
+
const { data } = await client.http.get(`/api/v3/messages/list`, {
|
|
16401
|
+
params: { messageIds },
|
|
16402
|
+
});
|
|
16307
16403
|
const cachedAt = client.cache && Date.now();
|
|
16308
16404
|
if (client.cache)
|
|
16309
16405
|
ingestInCache(data, { cachedAt });
|
|
16310
16406
|
return {
|
|
16311
16407
|
data: data.messages,
|
|
16312
|
-
cachedAt
|
|
16408
|
+
cachedAt,
|
|
16313
16409
|
};
|
|
16314
16410
|
};
|
|
16315
16411
|
/**
|
|
@@ -16335,7 +16431,7 @@ getMessages.locally = (messageIds) => {
|
|
|
16335
16431
|
.map(messageId => pullFromCache(['message', 'get', messageId]))
|
|
16336
16432
|
.filter(Boolean);
|
|
16337
16433
|
const messages = cached.map(({ data }) => data);
|
|
16338
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
16434
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
16339
16435
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < messageIds.length)
|
|
16340
16436
|
return;
|
|
16341
16437
|
return {
|
|
@@ -16361,19 +16457,16 @@ getMessages.locally = (messageIds) => {
|
|
|
16361
16457
|
const queryMessages = async (query) => {
|
|
16362
16458
|
const client = getActiveClient();
|
|
16363
16459
|
client.log('message/queryMessages', query);
|
|
16364
|
-
const { page = { limit: 10 } } = query, params = __rest(query
|
|
16365
|
-
// API-FIX: parameters should be querystring. (1)
|
|
16366
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
16367
|
-
// API-FIX: pagination should not be indexed on channelSegment (3)
|
|
16368
|
-
// const { data } = await client.http.get<Amity.Response<Amity.Paged<Amity.MessagePayload>>>(
|
|
16369
|
-
, ["page"]);
|
|
16460
|
+
const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
|
|
16370
16461
|
// API-FIX: parameters should be querystring. (1)
|
|
16371
16462
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16372
16463
|
// API-FIX: pagination should not be indexed on channelSegment (3)
|
|
16373
16464
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<Amity.MessagePayload>>>(
|
|
16374
|
-
const { data } = await client.http.get(`/api/v3/messages`, {
|
|
16465
|
+
const { data } = await client.http.get(`/api/v3/messages`, {
|
|
16466
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
16375
16467
|
token: toToken(page, 'afterbefore'),
|
|
16376
|
-
} }),
|
|
16468
|
+
} }),
|
|
16469
|
+
});
|
|
16377
16470
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16378
16471
|
// const { paging, messages } = unwrapPayload(data)
|
|
16379
16472
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
@@ -16381,7 +16474,11 @@ const queryMessages = async (query) => {
|
|
|
16381
16474
|
const cachedAt = client.cache && Date.now();
|
|
16382
16475
|
if (client.cache) {
|
|
16383
16476
|
ingestInCache(payload, { cachedAt });
|
|
16384
|
-
const cacheKey = [
|
|
16477
|
+
const cacheKey = [
|
|
16478
|
+
'message',
|
|
16479
|
+
'query',
|
|
16480
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
16481
|
+
];
|
|
16385
16482
|
pushToCache(cacheKey, { messages: messages.map(getResolver('message')), paging });
|
|
16386
16483
|
}
|
|
16387
16484
|
const nextPage = toPage(paging.next);
|
|
@@ -16483,7 +16580,7 @@ createMessage.optimistically = (bundle) => {
|
|
|
16483
16580
|
fireEvent('v3.message.didCreate', { messages: [message] });
|
|
16484
16581
|
return {
|
|
16485
16582
|
data: message,
|
|
16486
|
-
cachedAt: -1
|
|
16583
|
+
cachedAt: -1,
|
|
16487
16584
|
};
|
|
16488
16585
|
};
|
|
16489
16586
|
|
|
@@ -16547,7 +16644,7 @@ updateMessage.optimistically = (messageId, patch) => {
|
|
|
16547
16644
|
fireEvent('v3.message.didUpdate', { messages: [updated] });
|
|
16548
16645
|
return {
|
|
16549
16646
|
data: updated,
|
|
16550
|
-
cachedAt
|
|
16647
|
+
cachedAt,
|
|
16551
16648
|
};
|
|
16552
16649
|
};
|
|
16553
16650
|
|
|
@@ -16599,7 +16696,7 @@ deleteMessage.optimistically = (messageId) => {
|
|
|
16599
16696
|
fireEvent('v3.message.didDelete', { messages: [deleted] });
|
|
16600
16697
|
return {
|
|
16601
16698
|
data: deleted,
|
|
16602
|
-
cachedAt
|
|
16699
|
+
cachedAt,
|
|
16603
16700
|
};
|
|
16604
16701
|
};
|
|
16605
16702
|
|
|
@@ -16620,17 +16717,15 @@ deleteMessage.optimistically = (messageId) => {
|
|
|
16620
16717
|
const queryPosts = async (query) => {
|
|
16621
16718
|
const client = getActiveClient();
|
|
16622
16719
|
client.log('post/queryPosts', query);
|
|
16623
|
-
const { page = { limit: 10 } } = query, params = __rest(query
|
|
16624
|
-
// API-FIX: parameters should be querystring. (1)
|
|
16625
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
16626
|
-
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16627
|
-
, ["page"]);
|
|
16720
|
+
const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
|
|
16628
16721
|
// API-FIX: parameters should be querystring. (1)
|
|
16629
16722
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16630
16723
|
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16631
|
-
const { data } = await client.http.get(`/api/v4/posts`, {
|
|
16724
|
+
const { data } = await client.http.get(`/api/v4/posts`, {
|
|
16725
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
16632
16726
|
token: toToken(page, 'afterbeforeraw'),
|
|
16633
|
-
} }),
|
|
16727
|
+
} }),
|
|
16728
|
+
});
|
|
16634
16729
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16635
16730
|
// const { paging, posts } = unwrapPayload(data)
|
|
16636
16731
|
// unpacking
|
|
@@ -16700,13 +16795,15 @@ const getPosts = async (postIds) => {
|
|
|
16700
16795
|
client.log('post/getPosts', postIds);
|
|
16701
16796
|
const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
|
|
16702
16797
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
16703
|
-
const { data } = await client.http.get(`/api/v3/posts/list`, {
|
|
16798
|
+
const { data } = await client.http.get(`/api/v3/posts/list`, {
|
|
16799
|
+
params: { postIds: encodedPostIds },
|
|
16800
|
+
});
|
|
16704
16801
|
const cachedAt = client.cache && Date.now();
|
|
16705
16802
|
if (client.cache)
|
|
16706
16803
|
ingestInCache(data, { cachedAt });
|
|
16707
16804
|
return {
|
|
16708
16805
|
data: data.posts,
|
|
16709
|
-
cachedAt
|
|
16806
|
+
cachedAt,
|
|
16710
16807
|
};
|
|
16711
16808
|
};
|
|
16712
16809
|
/**
|
|
@@ -16732,7 +16829,7 @@ getPosts.locally = (postIds) => {
|
|
|
16732
16829
|
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
16733
16830
|
.filter(Boolean);
|
|
16734
16831
|
const posts = cached.map(({ data }) => data);
|
|
16735
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
16832
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
16736
16833
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
|
|
16737
16834
|
return;
|
|
16738
16835
|
return {
|
|
@@ -16783,7 +16880,7 @@ const getPost = async (postId) => {
|
|
|
16783
16880
|
/**
|
|
16784
16881
|
* ```js
|
|
16785
16882
|
* import { getPost } from '@amityco/ts-sdk'
|
|
16786
|
-
* const { data
|
|
16883
|
+
* const { data: post } = getPost.locally('foobar')
|
|
16787
16884
|
* ```
|
|
16788
16885
|
*
|
|
16789
16886
|
* Fetches a {@link Amity.Post} object from cache
|
|
@@ -16829,8 +16926,10 @@ const createPost = async (bundle) => {
|
|
|
16829
16926
|
const client = getActiveClient();
|
|
16830
16927
|
client.log('post/createPost', bundle);
|
|
16831
16928
|
// API-FIX: backend rejects that we pass the dataType manually T_T
|
|
16832
|
-
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType))
|
|
16929
|
+
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
|
|
16930
|
+
// eslint-disable-next-line no-param-reassign
|
|
16833
16931
|
delete bundle.dataType;
|
|
16932
|
+
}
|
|
16834
16933
|
const { data } = await client.http.post('/api/v4/posts', bundle);
|
|
16835
16934
|
const cachedAt = client.cache && Date.now();
|
|
16836
16935
|
if (client.cache)
|
|
@@ -16898,15 +16997,21 @@ const queryCommunities = async (query) => {
|
|
|
16898
16997
|
// API-FIX: parameters should be querystring.
|
|
16899
16998
|
// API-FIX: backend doesnt answer Amity.Response
|
|
16900
16999
|
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<CommunityPayload>>>(
|
|
16901
|
-
const { data } = await client.http.get(`/api/v3/communities`, {
|
|
16902
|
-
|
|
16903
|
-
|
|
17000
|
+
const { data } = await client.http.get(`/api/v3/communities`, {
|
|
17001
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
|
|
17002
|
+
token: toToken(page, 'skiplimit'),
|
|
17003
|
+
} }),
|
|
17004
|
+
});
|
|
16904
17005
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
16905
17006
|
const { communities } = payload;
|
|
16906
17007
|
const cachedAt = client.cache && Date.now();
|
|
16907
17008
|
if (client.cache) {
|
|
16908
17009
|
ingestInCache(payload, { cachedAt });
|
|
16909
|
-
const cacheKey = [
|
|
17010
|
+
const cacheKey = [
|
|
17011
|
+
'community',
|
|
17012
|
+
'query',
|
|
17013
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
17014
|
+
];
|
|
16910
17015
|
pushToCache(cacheKey, { communities: communities.map(getResolver('community')), paging });
|
|
16911
17016
|
}
|
|
16912
17017
|
const nextPage = toPage(paging.next);
|
|
@@ -16950,13 +17055,15 @@ const getCommunities = async (communityIds) => {
|
|
|
16950
17055
|
const client = getActiveClient();
|
|
16951
17056
|
client.log('community/getCommunities', communityIds);
|
|
16952
17057
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
16953
|
-
const { data } = await client.http.get(`/api/v3/communities/list`, {
|
|
17058
|
+
const { data } = await client.http.get(`/api/v3/communities/list`, {
|
|
17059
|
+
params: { communityIds },
|
|
17060
|
+
});
|
|
16954
17061
|
const cachedAt = client.cache && Date.now();
|
|
16955
17062
|
if (client.cache)
|
|
16956
17063
|
ingestInCache(data, { cachedAt });
|
|
16957
17064
|
return {
|
|
16958
17065
|
data: data.communities,
|
|
16959
|
-
cachedAt
|
|
17066
|
+
cachedAt,
|
|
16960
17067
|
};
|
|
16961
17068
|
};
|
|
16962
17069
|
/**
|
|
@@ -16982,7 +17089,7 @@ getCommunities.locally = (communityIds) => {
|
|
|
16982
17089
|
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
16983
17090
|
.filter(Boolean);
|
|
16984
17091
|
const communities = cached.map(({ data }) => data);
|
|
16985
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
17092
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
16986
17093
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < communityIds.length)
|
|
16987
17094
|
return;
|
|
16988
17095
|
return {
|
|
@@ -17152,8 +17259,7 @@ const joinCommunity = async (communityId) => {
|
|
|
17152
17259
|
ingestInCache(data, { cachedAt });
|
|
17153
17260
|
fireEvent('community.joined', data);
|
|
17154
17261
|
const { communityUsers } = data;
|
|
17155
|
-
return !!communityUsers.find(communityUser =>
|
|
17156
|
-
&& communityUser.communityMembership === 'member'));
|
|
17262
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
17157
17263
|
};
|
|
17158
17264
|
|
|
17159
17265
|
/**
|
|
@@ -17179,8 +17285,7 @@ const leaveCommunity = async (communityId) => {
|
|
|
17179
17285
|
ingestInCache(data, { cachedAt });
|
|
17180
17286
|
fireEvent('community.left', data);
|
|
17181
17287
|
const { communityUsers } = data;
|
|
17182
|
-
return !!communityUsers.find(communityUser =>
|
|
17183
|
-
&& communityUser.communityMembership !== 'member'));
|
|
17288
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
17184
17289
|
};
|
|
17185
17290
|
|
|
17186
17291
|
/**
|
|
@@ -17196,7 +17301,7 @@ const leaveCommunity = async (communityId) => {
|
|
|
17196
17301
|
*
|
|
17197
17302
|
* @category Community API
|
|
17198
17303
|
* @async
|
|
17199
|
-
|
|
17304
|
+
* */
|
|
17200
17305
|
const queryCommunityMembers = async (query) => {
|
|
17201
17306
|
const client = getActiveClient();
|
|
17202
17307
|
client.log('community/queryCommunityMembers', query);
|
|
@@ -17258,8 +17363,7 @@ const addCommunityMembers = async (communityId, userIds) => {
|
|
|
17258
17363
|
ingestInCache(data);
|
|
17259
17364
|
fireEvent('community.userAdded', data);
|
|
17260
17365
|
const { communityUsers } = data;
|
|
17261
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17262
|
-
communityUser.communityMembership === 'member');
|
|
17366
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
17263
17367
|
};
|
|
17264
17368
|
|
|
17265
17369
|
/**
|
|
@@ -17285,60 +17389,187 @@ const removeCommunityMembers = async (communityId, userIds) => {
|
|
|
17285
17389
|
ingestInCache(data);
|
|
17286
17390
|
fireEvent('community.userRemoved', data);
|
|
17287
17391
|
const { communityUsers } = data;
|
|
17288
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17289
|
-
communityUser.communityMembership !== 'member');
|
|
17392
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
17290
17393
|
};
|
|
17291
17394
|
|
|
17292
17395
|
/**
|
|
17293
17396
|
* ```js
|
|
17294
|
-
* import {
|
|
17295
|
-
* const updated = await
|
|
17397
|
+
* import { addCommunityMembersRoles } from '@amityco/ts-sdk'
|
|
17398
|
+
* const updated = await addCommunityMembersRoles(communityId, ['foo'], ['bar'])
|
|
17296
17399
|
* ```
|
|
17297
17400
|
*
|
|
17298
|
-
* Adds
|
|
17401
|
+
* Adds a list of {@link Amity.Role} to a list of {@link Amity.User} on a {@link Amity.Community}
|
|
17299
17402
|
*
|
|
17300
17403
|
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
17301
|
-
* @param
|
|
17404
|
+
* @param roleIds Array of IDs of the {@link Amity.Role} to apply
|
|
17302
17405
|
* @param userId Array of IDs of the {@link Amity.User} to perform
|
|
17303
17406
|
* @returns A success boolean if the {@link Amity.Role} were added to list of {@link Amity.User} in the {@link Amity.Community}
|
|
17304
17407
|
*
|
|
17305
17408
|
* @category Community API
|
|
17306
17409
|
* @async
|
|
17307
17410
|
*/
|
|
17308
|
-
const
|
|
17411
|
+
const addCommunityMembersRoles = async (communityId, roleIds, userIds) => {
|
|
17309
17412
|
const client = getActiveClient();
|
|
17310
|
-
client.log('community/
|
|
17311
|
-
const { data } = await client.http.post(`/api/
|
|
17413
|
+
client.log('community/addCommunityMembersRoles', communityId, roleIds, userIds);
|
|
17414
|
+
const { data } = await client.http.post(`/api/v4/communities/${communityId}/users/roles`, { communityId, roles: roleIds, userIds });
|
|
17312
17415
|
if (client.cache)
|
|
17313
17416
|
ingestInCache(data);
|
|
17314
17417
|
const { communityUsers } = data;
|
|
17315
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17418
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17419
|
+
roleIds.some(role => communityUser.roles.includes(role)));
|
|
17316
17420
|
};
|
|
17317
17421
|
|
|
17318
17422
|
/**
|
|
17319
17423
|
* ```js
|
|
17320
|
-
* import {
|
|
17321
|
-
* const updated = await
|
|
17424
|
+
* import { removeCommunityMembersRoles } from '@amityco/ts-sdk'
|
|
17425
|
+
* const updated = await removeCommunityMembersRoles(communityId, ['foo'], ['bar'])
|
|
17322
17426
|
* ```
|
|
17323
17427
|
*
|
|
17324
|
-
* Removes
|
|
17428
|
+
* Removes a list of {@link Amity.Role} from a list of {@link Amity.User} on a {@link Amity.Community}
|
|
17325
17429
|
*
|
|
17326
17430
|
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
17327
|
-
* @param
|
|
17431
|
+
* @param roleIds Array of IDs of the {@link Amity.Role} to apply
|
|
17328
17432
|
* @param userId Array of IDs of the {@link Amity.User} to perform
|
|
17329
17433
|
* @returns A success boolean if the {@link Amity.Role} were removed from list of {@link Amity.User} in the {@link Amity.Community}
|
|
17330
17434
|
*
|
|
17331
17435
|
* @category Community API
|
|
17332
17436
|
* @async
|
|
17333
17437
|
*/
|
|
17334
|
-
const
|
|
17438
|
+
const removeCommunityMembersRoles = async (communityId, roleIds, userIds) => {
|
|
17335
17439
|
const client = getActiveClient();
|
|
17336
|
-
client.log('community/
|
|
17337
|
-
const { data } = await client.http.delete(`/api/
|
|
17440
|
+
client.log('community/removeCommunityMembersRoles', communityId, roleIds, userIds);
|
|
17441
|
+
const { data } = await client.http.delete(`/api/v4/communities/${communityId}/users/roles`, { data: { communityId, roles: roleIds, userIds } });
|
|
17338
17442
|
if (client.cache)
|
|
17339
17443
|
ingestInCache(data);
|
|
17340
17444
|
const { communityUsers } = data;
|
|
17341
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17445
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17446
|
+
!roleIds.some(role => communityUser.roles.includes(role)));
|
|
17447
|
+
};
|
|
17448
|
+
|
|
17449
|
+
/**
|
|
17450
|
+
* ```js
|
|
17451
|
+
* import { getTopTrendingCommunities } from '@amityco/ts-sdk'
|
|
17452
|
+
* const trendingCommunities = await getTopTrendingCommunities()
|
|
17453
|
+
* ```
|
|
17454
|
+
*
|
|
17455
|
+
* Gets a list of top trending {@link Amity.Community} objects
|
|
17456
|
+
*
|
|
17457
|
+
* @param query The query parameters
|
|
17458
|
+
* @returns A list of {@link Amity.Community} objects
|
|
17459
|
+
*
|
|
17460
|
+
* @category Community API
|
|
17461
|
+
* @async
|
|
17462
|
+
*/
|
|
17463
|
+
const getTopTrendingCommunities = async (query) => {
|
|
17464
|
+
const client = getActiveClient();
|
|
17465
|
+
client.log('channel/getTopTrendingCommunities', query);
|
|
17466
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17467
|
+
// API-FIX: backend doesnt answer Amity.Response
|
|
17468
|
+
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
17469
|
+
const { data } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
17470
|
+
const { communities } = data;
|
|
17471
|
+
const cachedAt = client.cache && Date.now();
|
|
17472
|
+
if (client.cache) {
|
|
17473
|
+
ingestInCache(data, { cachedAt });
|
|
17474
|
+
const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
17475
|
+
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
17476
|
+
}
|
|
17477
|
+
return { data: communities, cachedAt };
|
|
17478
|
+
};
|
|
17479
|
+
/**
|
|
17480
|
+
* ```js
|
|
17481
|
+
* import { getTopTrendingCommunities } from '@amityco/ts-sdk'
|
|
17482
|
+
* const communities = getTopTrendingCommunities.locally()
|
|
17483
|
+
* ```
|
|
17484
|
+
*
|
|
17485
|
+
* Gets a list of top trending {@link Amity.Community} objects from cache
|
|
17486
|
+
*
|
|
17487
|
+
* @param query The query parameters
|
|
17488
|
+
* @returns communities
|
|
17489
|
+
*
|
|
17490
|
+
* @category Community API
|
|
17491
|
+
*/
|
|
17492
|
+
getTopTrendingCommunities.locally = (query) => {
|
|
17493
|
+
var _a, _b;
|
|
17494
|
+
const client = getActiveClient();
|
|
17495
|
+
client.log('community/getTopTrendingCommunities.locally', query);
|
|
17496
|
+
if (!client.cache)
|
|
17497
|
+
return;
|
|
17498
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17499
|
+
const queryKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
17500
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
17501
|
+
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
17502
|
+
return;
|
|
17503
|
+
const communities = data.communities
|
|
17504
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
17505
|
+
.filter(Boolean)
|
|
17506
|
+
.map(({ data }) => data);
|
|
17507
|
+
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
17508
|
+
? { data: communities, cachedAt }
|
|
17509
|
+
: undefined;
|
|
17510
|
+
};
|
|
17511
|
+
|
|
17512
|
+
/**
|
|
17513
|
+
* ```js
|
|
17514
|
+
* import { getRecommendedCommunities } from '@amityco/ts-sdk'
|
|
17515
|
+
* const communities = await getRecommendedCommunities()
|
|
17516
|
+
* ```
|
|
17517
|
+
*
|
|
17518
|
+
* Gets a list of recommended {@link Amity.Community} objects
|
|
17519
|
+
*
|
|
17520
|
+
* @param query The query parameters
|
|
17521
|
+
* @returns A list of {@link Amity.Community} objects
|
|
17522
|
+
*
|
|
17523
|
+
* @category Community API
|
|
17524
|
+
* @async
|
|
17525
|
+
*/
|
|
17526
|
+
const getRecommendedCommunities = async (query) => {
|
|
17527
|
+
const client = getActiveClient();
|
|
17528
|
+
client.log('channel/getRecommendedCommunities', query);
|
|
17529
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17530
|
+
// API-FIX: backend doesnt answer Amity.Response
|
|
17531
|
+
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
17532
|
+
const { data } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
|
|
17533
|
+
const { communities } = data;
|
|
17534
|
+
const cachedAt = client.cache && Date.now();
|
|
17535
|
+
if (client.cache) {
|
|
17536
|
+
ingestInCache(data, { cachedAt });
|
|
17537
|
+
const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
17538
|
+
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
17539
|
+
}
|
|
17540
|
+
return { data: communities, cachedAt };
|
|
17541
|
+
};
|
|
17542
|
+
/**
|
|
17543
|
+
* ```js
|
|
17544
|
+
* import { getRecommendedCommunities } from '@amityco/ts-sdk'
|
|
17545
|
+
* const communities = getRecommendedCommunities.locally()
|
|
17546
|
+
* ```
|
|
17547
|
+
*
|
|
17548
|
+
* Gets a list of recommended {@link Amity.Community} objects from cache
|
|
17549
|
+
*
|
|
17550
|
+
* @param query The query parameters
|
|
17551
|
+
* @returns communities
|
|
17552
|
+
*
|
|
17553
|
+
* @category Community API
|
|
17554
|
+
*/
|
|
17555
|
+
getRecommendedCommunities.locally = (query) => {
|
|
17556
|
+
var _a, _b;
|
|
17557
|
+
const client = getActiveClient();
|
|
17558
|
+
client.log('community/getRecommendedCommunities.locally', query);
|
|
17559
|
+
if (!client.cache)
|
|
17560
|
+
return;
|
|
17561
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17562
|
+
const queryKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
17563
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
17564
|
+
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
17565
|
+
return;
|
|
17566
|
+
const communities = data.communities
|
|
17567
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
17568
|
+
.filter(Boolean)
|
|
17569
|
+
.map(({ data }) => data);
|
|
17570
|
+
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
17571
|
+
? { data: communities, cachedAt }
|
|
17572
|
+
: undefined;
|
|
17342
17573
|
};
|
|
17343
17574
|
|
|
17344
17575
|
/**
|
|
@@ -17358,7 +17589,7 @@ const removeCommunityMembersRole = async (communityId, roleId, userIds) => {
|
|
|
17358
17589
|
const deletePost = async (postId, permanent = false) => {
|
|
17359
17590
|
const client = getActiveClient();
|
|
17360
17591
|
client.log('post/deletePost', postId);
|
|
17361
|
-
|
|
17592
|
+
const post = await getPost(postId);
|
|
17362
17593
|
// API-FIX: This endpoint has not been implemented yet.
|
|
17363
17594
|
await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
17364
17595
|
params: {
|
|
@@ -17405,12 +17636,7 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
17405
17636
|
const queryComments = async (query) => {
|
|
17406
17637
|
const client = getActiveClient();
|
|
17407
17638
|
client.log('comment/queryComments', query);
|
|
17408
|
-
const { page = { limit: 10 } } = query, params = __rest(query
|
|
17409
|
-
// const filterByParentId = query.parentId !== undefined
|
|
17410
|
-
// API-FIX: parameters should be querystring. (1)
|
|
17411
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
17412
|
-
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.CommentPayload>>>(
|
|
17413
|
-
, ["page"]);
|
|
17639
|
+
const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
|
|
17414
17640
|
// const filterByParentId = query.parentId !== undefined
|
|
17415
17641
|
// API-FIX: parameters should be querystring. (1)
|
|
17416
17642
|
// API-FIX: backend should answer Amity.Response (2)
|
|
@@ -17429,7 +17655,11 @@ const queryComments = async (query) => {
|
|
|
17429
17655
|
const cachedAt = client.cache && Date.now();
|
|
17430
17656
|
if (client.cache) {
|
|
17431
17657
|
ingestInCache(payload, { cachedAt });
|
|
17432
|
-
const cacheKey = [
|
|
17658
|
+
const cacheKey = [
|
|
17659
|
+
'comment',
|
|
17660
|
+
'query',
|
|
17661
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
17662
|
+
];
|
|
17433
17663
|
pushToCache(cacheKey, { comments: comments.map(getResolver('comment')), paging });
|
|
17434
17664
|
}
|
|
17435
17665
|
const nextPage = toPage(paging.next);
|
|
@@ -17490,13 +17720,15 @@ const getComments = async (commentIds) => {
|
|
|
17490
17720
|
client.log('comment/getComments', commentIds);
|
|
17491
17721
|
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
17492
17722
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
17493
|
-
const { data } = await client.http.get(`/api/v3/comments/list`, {
|
|
17723
|
+
const { data } = await client.http.get(`/api/v3/comments/list`, {
|
|
17724
|
+
params: { commentIds: encodedCommentIds },
|
|
17725
|
+
});
|
|
17494
17726
|
const cachedAt = client.cache && Date.now();
|
|
17495
17727
|
if (client.cache)
|
|
17496
17728
|
ingestInCache(data, { cachedAt });
|
|
17497
17729
|
return {
|
|
17498
17730
|
data: data.comments,
|
|
17499
|
-
cachedAt
|
|
17731
|
+
cachedAt,
|
|
17500
17732
|
};
|
|
17501
17733
|
};
|
|
17502
17734
|
/**
|
|
@@ -17522,7 +17754,7 @@ getComments.locally = (commentIds) => {
|
|
|
17522
17754
|
.map(commentId => pullFromCache(['comment', 'get', commentId]))
|
|
17523
17755
|
.filter(Boolean);
|
|
17524
17756
|
const comments = cached.map(({ data }) => data);
|
|
17525
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
17757
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
17526
17758
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
|
|
17527
17759
|
return;
|
|
17528
17760
|
return {
|
|
@@ -17705,9 +17937,9 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
17705
17937
|
const fetchReference = async (referenceType, referenceId) => {
|
|
17706
17938
|
if (referenceType === 'message')
|
|
17707
17939
|
return getMessage(referenceId);
|
|
17708
|
-
|
|
17940
|
+
if (referenceType === 'post')
|
|
17709
17941
|
return getPost(referenceId);
|
|
17710
|
-
|
|
17942
|
+
if (referenceType === 'comment')
|
|
17711
17943
|
return getComment(referenceId);
|
|
17712
17944
|
throw new Error(`Incorrect referenceType: ${referenceType}`);
|
|
17713
17945
|
};
|
|
@@ -17744,7 +17976,9 @@ const preparePayloadForCache = (event, payload) => {
|
|
|
17744
17976
|
if (!cached.myReactions.includes(payload.reactor.reactionName)) {
|
|
17745
17977
|
return;
|
|
17746
17978
|
}
|
|
17747
|
-
Object.assign(model, {
|
|
17979
|
+
Object.assign(model, {
|
|
17980
|
+
myReactions: cached.myReactions.filter(x => x !== payload.reactor.reactionName),
|
|
17981
|
+
});
|
|
17748
17982
|
}
|
|
17749
17983
|
};
|
|
17750
17984
|
|
|
@@ -17763,7 +17997,7 @@ const preparePayloadForCache = (event, payload) => {
|
|
|
17763
17997
|
*
|
|
17764
17998
|
* @category Reaction API
|
|
17765
17999
|
* @async
|
|
17766
|
-
|
|
18000
|
+
* */
|
|
17767
18001
|
const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
17768
18002
|
var _a, _b;
|
|
17769
18003
|
const client = getActiveClient();
|
|
@@ -17772,7 +18006,11 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17772
18006
|
referenceType,
|
|
17773
18007
|
reactionName,
|
|
17774
18008
|
});
|
|
17775
|
-
await client.http.post('/api/v2/reactions', {
|
|
18009
|
+
await client.http.post('/api/v2/reactions', {
|
|
18010
|
+
referenceId,
|
|
18011
|
+
referenceType,
|
|
18012
|
+
reactionName,
|
|
18013
|
+
});
|
|
17776
18014
|
const model = await fetchReference(referenceType, referenceId);
|
|
17777
18015
|
dispatchReactable(referenceType, model.data);
|
|
17778
18016
|
return (_b = (_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)) !== null && _b !== void 0 ? _b : false;
|
|
@@ -17791,7 +18029,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17791
18029
|
* @returns The added result.
|
|
17792
18030
|
*
|
|
17793
18031
|
* @category Reaction API
|
|
17794
|
-
|
|
18032
|
+
* */
|
|
17795
18033
|
addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
17796
18034
|
var _a, _b, _c, _d, _e;
|
|
17797
18035
|
const client = getActiveClient();
|
|
@@ -17802,7 +18040,11 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
17802
18040
|
});
|
|
17803
18041
|
if (!client.cache)
|
|
17804
18042
|
return;
|
|
17805
|
-
const model = pullFromCache([
|
|
18043
|
+
const model = pullFromCache([
|
|
18044
|
+
referenceType,
|
|
18045
|
+
'get',
|
|
18046
|
+
referenceId,
|
|
18047
|
+
]);
|
|
17806
18048
|
if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
17807
18049
|
return;
|
|
17808
18050
|
const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
|
|
@@ -17826,7 +18068,7 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
17826
18068
|
*
|
|
17827
18069
|
* @category Reaction API
|
|
17828
18070
|
* @async
|
|
17829
|
-
|
|
18071
|
+
* */
|
|
17830
18072
|
const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
17831
18073
|
var _a, _b;
|
|
17832
18074
|
const client = getActiveClient();
|
|
@@ -17835,7 +18077,9 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17835
18077
|
referenceType,
|
|
17836
18078
|
reactionName,
|
|
17837
18079
|
});
|
|
17838
|
-
await client.http.delete(`/api/v2/reactions`, {
|
|
18080
|
+
await client.http.delete(`/api/v2/reactions`, {
|
|
18081
|
+
data: { referenceId, referenceType, reactionName },
|
|
18082
|
+
});
|
|
17839
18083
|
const model = await fetchReference(referenceType, referenceId);
|
|
17840
18084
|
dispatchReactable(referenceType, model.data);
|
|
17841
18085
|
return (_b = !((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName))) !== null && _b !== void 0 ? _b : false;
|
|
@@ -17854,7 +18098,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17854
18098
|
* @returns The added result.
|
|
17855
18099
|
*
|
|
17856
18100
|
* @category Reaction API
|
|
17857
|
-
|
|
18101
|
+
* */
|
|
17858
18102
|
removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
17859
18103
|
var _a, _b, _c, _d, _e;
|
|
17860
18104
|
const client = getActiveClient();
|
|
@@ -17865,7 +18109,11 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
17865
18109
|
});
|
|
17866
18110
|
if (!client.cache)
|
|
17867
18111
|
return;
|
|
17868
|
-
const model = pullFromCache([
|
|
18112
|
+
const model = pullFromCache([
|
|
18113
|
+
referenceType,
|
|
18114
|
+
'get',
|
|
18115
|
+
referenceId,
|
|
18116
|
+
]);
|
|
17869
18117
|
if (!(model === null || model === void 0 ? void 0 : model.data) || !((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
17870
18118
|
return;
|
|
17871
18119
|
const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) - 1) }) });
|
|
@@ -18044,6 +18292,7 @@ const onPostReactionAdded = (callback) => {
|
|
|
18044
18292
|
}
|
|
18045
18293
|
else {
|
|
18046
18294
|
preparePayloadForCache('post.addReaction', payload);
|
|
18295
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18047
18296
|
const postPayload = __rest(payload, ["reactor"]);
|
|
18048
18297
|
ingestInCache(postPayload);
|
|
18049
18298
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
@@ -18076,6 +18325,7 @@ const onPostReactionRemoved = (callback) => {
|
|
|
18076
18325
|
}
|
|
18077
18326
|
else {
|
|
18078
18327
|
preparePayloadForCache('post.removeReaction', payload);
|
|
18328
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18079
18329
|
const postPayload = __rest(payload, ["reactor"]);
|
|
18080
18330
|
ingestInCache(postPayload);
|
|
18081
18331
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
@@ -18095,7 +18345,11 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
18095
18345
|
}
|
|
18096
18346
|
else {
|
|
18097
18347
|
ingestInCache(payload);
|
|
18098
|
-
const comment = pullFromCache([
|
|
18348
|
+
const comment = pullFromCache([
|
|
18349
|
+
'comment',
|
|
18350
|
+
'get',
|
|
18351
|
+
payload.comments[0].commentId,
|
|
18352
|
+
]);
|
|
18099
18353
|
if (['comment.created'].includes(event)) {
|
|
18100
18354
|
const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
18101
18355
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
@@ -18214,9 +18468,14 @@ const onCommentReactionAdded = (callback) => {
|
|
|
18214
18468
|
}
|
|
18215
18469
|
else {
|
|
18216
18470
|
preparePayloadForCache('comment.addReaction', payload);
|
|
18471
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18217
18472
|
const commentPayload = __rest(payload, ["reactor"]);
|
|
18218
18473
|
ingestInCache(commentPayload);
|
|
18219
|
-
const comment = pullFromCache([
|
|
18474
|
+
const comment = pullFromCache([
|
|
18475
|
+
'comment',
|
|
18476
|
+
'get',
|
|
18477
|
+
payload.comments[0].commentId,
|
|
18478
|
+
]);
|
|
18220
18479
|
callback(comment.data);
|
|
18221
18480
|
}
|
|
18222
18481
|
};
|
|
@@ -18246,9 +18505,14 @@ const onCommentReactionRemoved = (callback) => {
|
|
|
18246
18505
|
}
|
|
18247
18506
|
else {
|
|
18248
18507
|
preparePayloadForCache('comment.removeReaction', payload);
|
|
18508
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18249
18509
|
const commentPayload = __rest(payload, ["reactor"]);
|
|
18250
18510
|
ingestInCache(commentPayload);
|
|
18251
|
-
const comment = pullFromCache([
|
|
18511
|
+
const comment = pullFromCache([
|
|
18512
|
+
'comment',
|
|
18513
|
+
'get',
|
|
18514
|
+
payload.comments[0].commentId,
|
|
18515
|
+
]);
|
|
18252
18516
|
callback(comment.data);
|
|
18253
18517
|
}
|
|
18254
18518
|
};
|
|
@@ -18271,7 +18535,7 @@ const onCommentReactionRemoved = (callback) => {
|
|
|
18271
18535
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18272
18536
|
*
|
|
18273
18537
|
* @category Message Events
|
|
18274
|
-
|
|
18538
|
+
* */
|
|
18275
18539
|
const onReactionRemoved = (referenceType, referenceId, callback) => {
|
|
18276
18540
|
const callbackWrapper = (model) => {
|
|
18277
18541
|
if (getResolver(referenceType)(model) === referenceId) {
|
|
@@ -18282,7 +18546,11 @@ const onReactionRemoved = (referenceType, referenceId, callback) => {
|
|
|
18282
18546
|
const client = getActiveClient();
|
|
18283
18547
|
const filter = (payload) => {
|
|
18284
18548
|
var _a;
|
|
18285
|
-
const cached = pullFromCache([
|
|
18549
|
+
const cached = pullFromCache([
|
|
18550
|
+
'message',
|
|
18551
|
+
'get',
|
|
18552
|
+
payload.messages[0].messageId,
|
|
18553
|
+
]);
|
|
18286
18554
|
const isReactionEvent = ((_a = cached === null || cached === void 0 ? void 0 : cached.data) === null || _a === void 0 ? void 0 : _a.reactionsCount) !== payload.messages[0].reactionsCount;
|
|
18287
18555
|
ingestInCache(payload);
|
|
18288
18556
|
if (isReactionEvent) {
|
|
@@ -18332,12 +18600,12 @@ var REFERENCE_TYPES = {
|
|
|
18332
18600
|
*
|
|
18333
18601
|
* @category Report API
|
|
18334
18602
|
* @async
|
|
18335
|
-
|
|
18603
|
+
* */
|
|
18336
18604
|
const createReport = async (referenceType, referenceId) => {
|
|
18337
18605
|
const client = getActiveClient();
|
|
18338
18606
|
client.log('report/createReport', { referenceType, referenceId });
|
|
18339
18607
|
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
18340
|
-
const { data } = await client.http.post(`/api/v3/${domainName}/${
|
|
18608
|
+
const { data } = await client.http.post(`/api/v3/${domainName}/${encodeURIComponent(referenceId)}/flag`);
|
|
18341
18609
|
if (client.cache)
|
|
18342
18610
|
ingestInCache(data);
|
|
18343
18611
|
const event = referenceType === 'message'
|
|
@@ -18359,7 +18627,7 @@ const createReport = async (referenceType, referenceId) => {
|
|
|
18359
18627
|
*
|
|
18360
18628
|
* @category Report API
|
|
18361
18629
|
* @async
|
|
18362
|
-
|
|
18630
|
+
* */
|
|
18363
18631
|
const deleteReport = async (referenceType, referenceId) => {
|
|
18364
18632
|
const client = getActiveClient();
|
|
18365
18633
|
client.log('report/deleteReport', { referenceType, referenceId });
|
|
@@ -18386,7 +18654,7 @@ const deleteReport = async (referenceType, referenceId) => {
|
|
|
18386
18654
|
*
|
|
18387
18655
|
* @category Report API
|
|
18388
18656
|
* @async
|
|
18389
|
-
|
|
18657
|
+
* */
|
|
18390
18658
|
const isReportedByMe = async (referenceType, referenceId) => {
|
|
18391
18659
|
var _a, _b;
|
|
18392
18660
|
const client = getActiveClient();
|
|
@@ -18421,15 +18689,21 @@ const queryChannels = async (query) => {
|
|
|
18421
18689
|
// API-FIX: parameters should be querystring.
|
|
18422
18690
|
// API-FIX: backend doesnt answer Amity.Response
|
|
18423
18691
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<ChannelPayload>>>(
|
|
18424
|
-
const { data } = await client.http.get(`/api/v3/channels`, {
|
|
18692
|
+
const { data } = await client.http.get(`/api/v3/channels`, {
|
|
18693
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
|
|
18425
18694
|
token: toToken(page, 'skiplimit'),
|
|
18426
|
-
} })
|
|
18695
|
+
} }),
|
|
18696
|
+
});
|
|
18427
18697
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
18428
18698
|
const { channels } = payload;
|
|
18429
18699
|
const cachedAt = client.cache && Date.now();
|
|
18430
18700
|
if (client.cache) {
|
|
18431
18701
|
ingestInCache(payload, { cachedAt });
|
|
18432
|
-
const cacheKey = [
|
|
18702
|
+
const cacheKey = [
|
|
18703
|
+
'channel',
|
|
18704
|
+
'query',
|
|
18705
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
18706
|
+
];
|
|
18433
18707
|
pushToCache(cacheKey, { channels: channels.map(getResolver('channel')), paging });
|
|
18434
18708
|
}
|
|
18435
18709
|
const nextPage = toPage(paging.next);
|
|
@@ -18474,13 +18748,15 @@ const getChannels = async (channelIds) => {
|
|
|
18474
18748
|
client.log('channel/getChannels', channelIds);
|
|
18475
18749
|
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
18476
18750
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
18477
|
-
const { data } = await client.http.get(`/api/v3/channels/list`, {
|
|
18751
|
+
const { data } = await client.http.get(`/api/v3/channels/list`, {
|
|
18752
|
+
params: { channelIds: encodedChannelIds },
|
|
18753
|
+
});
|
|
18478
18754
|
const cachedAt = client.cache && Date.now();
|
|
18479
18755
|
if (client.cache)
|
|
18480
18756
|
ingestInCache(data, { cachedAt });
|
|
18481
18757
|
return {
|
|
18482
18758
|
data: data.channels,
|
|
18483
|
-
cachedAt
|
|
18759
|
+
cachedAt,
|
|
18484
18760
|
};
|
|
18485
18761
|
};
|
|
18486
18762
|
/**
|
|
@@ -18506,7 +18782,7 @@ getChannels.locally = (channelIds) => {
|
|
|
18506
18782
|
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
18507
18783
|
.filter(Boolean);
|
|
18508
18784
|
const channels = cached.map(({ data }) => data);
|
|
18509
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
18785
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
18510
18786
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < channelIds.length)
|
|
18511
18787
|
return;
|
|
18512
18788
|
return {
|
|
@@ -18650,7 +18926,6 @@ const updateChannel = async (channelId, patch) => {
|
|
|
18650
18926
|
const deleteChannel = async (channelId) => {
|
|
18651
18927
|
const client = getActiveClient();
|
|
18652
18928
|
client.log('channel/deleteChannel', channelId);
|
|
18653
|
-
// API-FIX: This endpoint has not been implemented yet.
|
|
18654
18929
|
await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
18655
18930
|
const deleted = await getChannel(channelId);
|
|
18656
18931
|
// no need for event, fired by server
|
|
@@ -18678,8 +18953,7 @@ const joinChannel = async (channelId) => {
|
|
|
18678
18953
|
if (client.cache)
|
|
18679
18954
|
ingestInCache(data);
|
|
18680
18955
|
const { channelUsers } = data;
|
|
18681
|
-
return !!channelUsers.find(channelUser =>
|
|
18682
|
-
&& channelUser.membership === 'member'));
|
|
18956
|
+
return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership === 'member');
|
|
18683
18957
|
};
|
|
18684
18958
|
|
|
18685
18959
|
/**
|
|
@@ -18703,8 +18977,7 @@ const leaveChannel = async (channelId) => {
|
|
|
18703
18977
|
if (client.cache)
|
|
18704
18978
|
ingestInCache(data);
|
|
18705
18979
|
const { channelUsers } = data;
|
|
18706
|
-
return !!channelUsers.find(channelUser =>
|
|
18707
|
-
&& channelUser.membership !== 'member'));
|
|
18980
|
+
return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership !== 'member');
|
|
18708
18981
|
};
|
|
18709
18982
|
|
|
18710
18983
|
/**
|
|
@@ -18720,7 +18993,7 @@ const leaveChannel = async (channelId) => {
|
|
|
18720
18993
|
*
|
|
18721
18994
|
* @category Channel API
|
|
18722
18995
|
* @async
|
|
18723
|
-
|
|
18996
|
+
* */
|
|
18724
18997
|
const queryChannelMembers = async (query) => {
|
|
18725
18998
|
const client = getActiveClient();
|
|
18726
18999
|
client.log('channel/queryChannelMembers', query);
|
|
@@ -19216,7 +19489,11 @@ const createCommunityEventSubscriber = (event, callback) => {
|
|
|
19216
19489
|
}
|
|
19217
19490
|
else {
|
|
19218
19491
|
ingestInCache(payload);
|
|
19219
|
-
const community = pullFromCache([
|
|
19492
|
+
const community = pullFromCache([
|
|
19493
|
+
'community',
|
|
19494
|
+
'get',
|
|
19495
|
+
payload.communities[0].communityId,
|
|
19496
|
+
]);
|
|
19220
19497
|
callback(community.data);
|
|
19221
19498
|
}
|
|
19222
19499
|
};
|
|
@@ -19226,8 +19503,8 @@ function hasPermission(member, payload, permission) {
|
|
|
19226
19503
|
if (member.permissions.some(x => x === permission)) {
|
|
19227
19504
|
return true;
|
|
19228
19505
|
}
|
|
19229
|
-
return payload
|
|
19230
|
-
.find(user => user.userId === member.userId)
|
|
19506
|
+
return payload
|
|
19507
|
+
.users.find(user => user.userId === member.userId)
|
|
19231
19508
|
.permissions.some(x => x === permission);
|
|
19232
19509
|
}
|
|
19233
19510
|
function getEventRelatedMember(event, payload) {
|
|
@@ -19257,11 +19534,15 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
|
|
|
19257
19534
|
}
|
|
19258
19535
|
else {
|
|
19259
19536
|
ingestInCache(payload);
|
|
19260
|
-
const community = pullFromCache([
|
|
19537
|
+
const community = pullFromCache([
|
|
19538
|
+
'community',
|
|
19539
|
+
'get',
|
|
19540
|
+
payload.communities[0].communityId,
|
|
19541
|
+
]);
|
|
19261
19542
|
const member = pullFromCache([
|
|
19262
19543
|
'communityUsers',
|
|
19263
19544
|
'get',
|
|
19264
|
-
getResolver('communityUsers')(getEventRelatedMember(event, payload))
|
|
19545
|
+
getResolver('communityUsers')(getEventRelatedMember(event, payload)),
|
|
19265
19546
|
]);
|
|
19266
19547
|
callback(community.data, member.data);
|
|
19267
19548
|
}
|
|
@@ -19468,90 +19749,802 @@ const observeCommunity = (communityId, callback) => {
|
|
|
19468
19749
|
|
|
19469
19750
|
/**
|
|
19470
19751
|
* ```js
|
|
19471
|
-
* import {
|
|
19472
|
-
* const
|
|
19752
|
+
* import { queryCategories } from '@amityco/ts-sdk'
|
|
19753
|
+
* const { data: categories, prevPage, nextPage } = await queryCategories()
|
|
19473
19754
|
* ```
|
|
19474
19755
|
*
|
|
19475
|
-
* Queries a paginable list of {@link Amity.
|
|
19756
|
+
* Queries a paginable list of {@link Amity.Category} objects
|
|
19476
19757
|
*
|
|
19477
19758
|
* @param query The query parameters
|
|
19478
|
-
* @returns A page of {@link Amity.
|
|
19759
|
+
* @returns A page of {@link Amity.Category} objects
|
|
19479
19760
|
*
|
|
19480
|
-
* @category
|
|
19761
|
+
* @category Category API
|
|
19481
19762
|
* @async
|
|
19482
|
-
|
|
19483
|
-
const
|
|
19763
|
+
* */
|
|
19764
|
+
const queryCategories = async (query) => {
|
|
19484
19765
|
const client = getActiveClient();
|
|
19485
|
-
client.log('
|
|
19486
|
-
const _a = query !== null && query !== void 0 ? query : {}, {
|
|
19487
|
-
const { data } = await client.http.get(
|
|
19488
|
-
|
|
19489
|
-
|
|
19766
|
+
client.log('category/queryCategories', query);
|
|
19767
|
+
const _a = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 } } = _a, params = __rest(_a, ["page"]);
|
|
19768
|
+
const { data } = await client.http.get(`/api/v3/community-categories`, {
|
|
19769
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
19770
|
+
token: toToken(page, 'skiplimit'),
|
|
19771
|
+
} }),
|
|
19772
|
+
});
|
|
19490
19773
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19491
|
-
const {
|
|
19774
|
+
const { categories } = payload;
|
|
19492
19775
|
const cachedAt = client.cache && Date.now();
|
|
19493
19776
|
if (client.cache) {
|
|
19494
|
-
ingestInCache(payload);
|
|
19495
|
-
const cacheKey = [
|
|
19496
|
-
|
|
19777
|
+
ingestInCache(payload, { cachedAt });
|
|
19778
|
+
const cacheKey = [
|
|
19779
|
+
'category',
|
|
19780
|
+
'query',
|
|
19781
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
19782
|
+
];
|
|
19783
|
+
pushToCache(cacheKey, { categories: categories.map(getResolver('category')), paging });
|
|
19497
19784
|
}
|
|
19498
19785
|
const nextPage = toPage(paging.next);
|
|
19499
19786
|
const prevPage = toPage(paging.previous);
|
|
19500
|
-
return { data:
|
|
19787
|
+
return { data: categories, cachedAt, prevPage, nextPage };
|
|
19501
19788
|
};
|
|
19502
19789
|
/**
|
|
19503
19790
|
* ```js
|
|
19504
|
-
* import {
|
|
19505
|
-
* const
|
|
19791
|
+
* import { queryCategories } from '@amityco/ts-sdk'
|
|
19792
|
+
* const { data: categories, prevPage, nextPage } = queryCategories.locally()
|
|
19506
19793
|
* ```
|
|
19507
19794
|
*
|
|
19508
|
-
* Queries a paginable list of {@link Amity.
|
|
19795
|
+
* Queries a paginable list of {@link Amity.Category} objects from cache
|
|
19509
19796
|
*
|
|
19510
19797
|
* @param query The query parameters
|
|
19511
|
-
* @returns
|
|
19798
|
+
* @returns categories
|
|
19512
19799
|
*
|
|
19513
|
-
* @category
|
|
19514
|
-
|
|
19515
|
-
|
|
19516
|
-
queryGlobalFeed.locally = (query) => {
|
|
19800
|
+
* @category category API
|
|
19801
|
+
*/
|
|
19802
|
+
queryCategories.locally = (query) => {
|
|
19517
19803
|
var _a, _b;
|
|
19518
19804
|
const client = getActiveClient();
|
|
19519
|
-
client.log('
|
|
19805
|
+
client.log('category/queryCategories.locally', query);
|
|
19520
19806
|
if (!client.cache)
|
|
19521
19807
|
return;
|
|
19522
|
-
const _c = query !== null && query !== void 0 ? query : {}, {
|
|
19523
|
-
const queryKey = ['
|
|
19808
|
+
const _c = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 } } = _c, params = __rest(_c, ["page"]);
|
|
19809
|
+
const queryKey = ['category', 'query', Object.assign(Object.assign({}, params), { options: Object.assign({}, page) })];
|
|
19524
19810
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19525
|
-
if (!(data === null || data === void 0 ? void 0 : data.
|
|
19811
|
+
if (!(data === null || data === void 0 ? void 0 : data.categories.length))
|
|
19526
19812
|
return;
|
|
19527
|
-
const
|
|
19528
|
-
.map(
|
|
19813
|
+
const categories = data.categories
|
|
19814
|
+
.map(categoryId => pullFromCache(['category', 'get', categoryId]))
|
|
19529
19815
|
.filter(Boolean)
|
|
19530
19816
|
.map(({ data }) => data);
|
|
19531
19817
|
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19532
19818
|
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19533
|
-
return
|
|
19534
|
-
? { data:
|
|
19819
|
+
return categories.length === ((_b = data === null || data === void 0 ? void 0 : data.categories) === null || _b === void 0 ? void 0 : _b.length)
|
|
19820
|
+
? { data: categories, cachedAt, prevPage, nextPage }
|
|
19535
19821
|
: undefined;
|
|
19536
19822
|
};
|
|
19537
19823
|
|
|
19538
19824
|
/**
|
|
19539
19825
|
* ```js
|
|
19540
|
-
* import {
|
|
19541
|
-
*
|
|
19542
|
-
* let posts = []
|
|
19543
|
-
* const unsub = observePosts({
|
|
19544
|
-
* targetType: Amity.PostTargetType,
|
|
19545
|
-
* targetId: Amity.Post['targetId'],
|
|
19546
|
-
* }, post => merge(posts, post))
|
|
19826
|
+
* import { getCategory } from '@amityco/ts-sdk'
|
|
19827
|
+
* const { data: category } = await getCategory('foo')
|
|
19547
19828
|
* ```
|
|
19548
19829
|
*
|
|
19549
|
-
*
|
|
19830
|
+
* Fetches a {@link Amity.Category} object
|
|
19550
19831
|
*
|
|
19551
|
-
* @param
|
|
19552
|
-
* @
|
|
19553
|
-
*
|
|
19554
|
-
* @
|
|
19832
|
+
* @param categoryId the ID of the {@link Amity.Category} to fetch
|
|
19833
|
+
* @returns the associated {@link Amity.Category} object
|
|
19834
|
+
*
|
|
19835
|
+
* @category Category API
|
|
19836
|
+
* @async
|
|
19837
|
+
*/
|
|
19838
|
+
const getCategory = async (categoryId) => {
|
|
19839
|
+
const client = getActiveClient();
|
|
19840
|
+
client.log('category/getCategory', categoryId);
|
|
19841
|
+
const { data } = await client.http.get(`/api/v3/community-categories/${encodeURIComponent(categoryId)}`);
|
|
19842
|
+
const cachedAt = client.cache && Date.now();
|
|
19843
|
+
if (client.cache)
|
|
19844
|
+
ingestInCache(data, { cachedAt });
|
|
19845
|
+
const { categories } = data;
|
|
19846
|
+
return {
|
|
19847
|
+
data: categories.find(category => category.categoryId === categoryId),
|
|
19848
|
+
cachedAt,
|
|
19849
|
+
};
|
|
19850
|
+
};
|
|
19851
|
+
/**
|
|
19852
|
+
* ```js
|
|
19853
|
+
* import { getCategory } from '@amityco/ts-sdk'
|
|
19854
|
+
* const { data: category } = getCategory.locally('foobar')
|
|
19855
|
+
* ```
|
|
19856
|
+
*
|
|
19857
|
+
* Fetches a {@link Amity.Category} object from cache
|
|
19858
|
+
*
|
|
19859
|
+
* @param categoryId the ID of the {@link Amity.Category} to fetch
|
|
19860
|
+
* @returns the associated {@link Amity.Category} object
|
|
19861
|
+
*
|
|
19862
|
+
* @category Category API
|
|
19863
|
+
*/
|
|
19864
|
+
getCategory.locally = (categoryId) => {
|
|
19865
|
+
const client = getActiveClient();
|
|
19866
|
+
client.log('category/getCategory.locally', categoryId);
|
|
19867
|
+
if (!client.cache)
|
|
19868
|
+
return;
|
|
19869
|
+
const cached = pullFromCache(['category', 'get', categoryId]);
|
|
19870
|
+
if (!cached)
|
|
19871
|
+
return;
|
|
19872
|
+
return {
|
|
19873
|
+
data: cached.data,
|
|
19874
|
+
cachedAt: cached.cachedAt,
|
|
19875
|
+
};
|
|
19876
|
+
};
|
|
19877
|
+
|
|
19878
|
+
/**
|
|
19879
|
+
* ```js
|
|
19880
|
+
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
19881
|
+
* const posts = await queryGlobalFeed()
|
|
19882
|
+
* ```
|
|
19883
|
+
*
|
|
19884
|
+
* Queries a paginable list of {@link Amity.Post} objects
|
|
19885
|
+
*
|
|
19886
|
+
* @param query The query parameters
|
|
19887
|
+
* @returns A page of {@link Amity.Post} objects
|
|
19888
|
+
*
|
|
19889
|
+
* @category Feed API
|
|
19890
|
+
* @async
|
|
19891
|
+
* */
|
|
19892
|
+
const queryGlobalFeed = async (query) => {
|
|
19893
|
+
const client = getActiveClient();
|
|
19894
|
+
client.log('feed/queryGlobalFeed', query);
|
|
19895
|
+
const _a = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _a, params = __rest(_a, ["useCustomRanking", "page"]);
|
|
19896
|
+
const { data } = await client.http.get(useCustomRanking ? `/api/v5/me/global-feeds` : `/api/v4/me/global-feeds`, {
|
|
19897
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
19898
|
+
token: toToken(page, 'skiplimit'),
|
|
19899
|
+
} }),
|
|
19900
|
+
});
|
|
19901
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19902
|
+
const { posts } = payload;
|
|
19903
|
+
const cachedAt = client.cache && Date.now();
|
|
19904
|
+
if (client.cache) {
|
|
19905
|
+
ingestInCache(payload);
|
|
19906
|
+
const cacheKey = [
|
|
19907
|
+
'globalFeed',
|
|
19908
|
+
'query',
|
|
19909
|
+
Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) }),
|
|
19910
|
+
];
|
|
19911
|
+
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
19912
|
+
}
|
|
19913
|
+
const nextPage = toPage(paging.next);
|
|
19914
|
+
const prevPage = toPage(paging.previous);
|
|
19915
|
+
return { data: posts, cachedAt, prevPage, nextPage };
|
|
19916
|
+
};
|
|
19917
|
+
/**
|
|
19918
|
+
* ```js
|
|
19919
|
+
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
19920
|
+
* const posts = await queryGlobalFeed.locally()
|
|
19921
|
+
* ```
|
|
19922
|
+
*
|
|
19923
|
+
* Queries a paginable list of {@link Amity.Post} objects from cache
|
|
19924
|
+
*
|
|
19925
|
+
* @param query The query parameters
|
|
19926
|
+
* @returns A page of {@link Amity.Post} objects
|
|
19927
|
+
*
|
|
19928
|
+
* @category Feed API
|
|
19929
|
+
* @async
|
|
19930
|
+
* */
|
|
19931
|
+
queryGlobalFeed.locally = (query) => {
|
|
19932
|
+
var _a, _b;
|
|
19933
|
+
const client = getActiveClient();
|
|
19934
|
+
client.log('post/queryGlobalFeed.locally', query);
|
|
19935
|
+
if (!client.cache)
|
|
19936
|
+
return;
|
|
19937
|
+
const _c = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _c, params = __rest(_c, ["useCustomRanking", "page"]);
|
|
19938
|
+
const queryKey = [
|
|
19939
|
+
'globalFeed',
|
|
19940
|
+
'query',
|
|
19941
|
+
Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) }),
|
|
19942
|
+
];
|
|
19943
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19944
|
+
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
19945
|
+
return;
|
|
19946
|
+
const posts = data.posts
|
|
19947
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
19948
|
+
.filter(Boolean)
|
|
19949
|
+
.map(({ data }) => data);
|
|
19950
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19951
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19952
|
+
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
19953
|
+
? { data: posts, cachedAt, prevPage, nextPage }
|
|
19954
|
+
: undefined;
|
|
19955
|
+
};
|
|
19956
|
+
|
|
19957
|
+
const queryFollows = async (key, query) => {
|
|
19958
|
+
const client = getActiveClient();
|
|
19959
|
+
client.log(`follow/queryF${key.substring(1)}`, query);
|
|
19960
|
+
const { userId, page } = query, params = __rest(query, ["userId", "page"]);
|
|
19961
|
+
const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/${key}` : `/api/v4/users/${userId}/${key}`, {
|
|
19962
|
+
params: Object.assign(Object.assign({}, params), { token: toToken(page, 'skiplimit') }),
|
|
19963
|
+
});
|
|
19964
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19965
|
+
const { follows } = payload;
|
|
19966
|
+
const cachedAt = client.cache && Date.now();
|
|
19967
|
+
if (client.cache) {
|
|
19968
|
+
ingestInCache(payload, { cachedAt });
|
|
19969
|
+
const cacheKey = [
|
|
19970
|
+
key,
|
|
19971
|
+
'query',
|
|
19972
|
+
Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page) }),
|
|
19973
|
+
];
|
|
19974
|
+
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
19975
|
+
}
|
|
19976
|
+
const nextPage = toPage(paging.next);
|
|
19977
|
+
const prevPage = toPage(paging.previous);
|
|
19978
|
+
return { data: follows, cachedAt, prevPage, nextPage };
|
|
19979
|
+
};
|
|
19980
|
+
queryFollows.locally = (key, query) => {
|
|
19981
|
+
var _a, _b;
|
|
19982
|
+
const client = getActiveClient();
|
|
19983
|
+
client.log(`follow/queryF${key.substring(1)}.locally`, query);
|
|
19984
|
+
if (!client.cache)
|
|
19985
|
+
return;
|
|
19986
|
+
const { page } = query, params = __rest(query, ["page"]);
|
|
19987
|
+
const queryKey = [key, 'query', Object.assign(Object.assign({}, params), { options: Object.assign({}, page) })];
|
|
19988
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19989
|
+
if (!(data === null || data === void 0 ? void 0 : data.follows.length)) {
|
|
19990
|
+
return;
|
|
19991
|
+
}
|
|
19992
|
+
const follows = data.follows
|
|
19993
|
+
.map(key => pullFromCache(['follow', 'get', key]))
|
|
19994
|
+
.filter(Boolean)
|
|
19995
|
+
.map(({ data }) => data);
|
|
19996
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19997
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19998
|
+
return follows.length === ((_b = data === null || data === void 0 ? void 0 : data.follows) === null || _b === void 0 ? void 0 : _b.length)
|
|
19999
|
+
? { data: follows, cachedAt, prevPage, nextPage }
|
|
20000
|
+
: undefined;
|
|
20001
|
+
};
|
|
20002
|
+
|
|
20003
|
+
/**
|
|
20004
|
+
* ```js
|
|
20005
|
+
* import { queryFollowers } from '@amityco/ts-sdk'
|
|
20006
|
+
* const { data: followers, prevPage, nextPage } = await queryFollowers({ userId })
|
|
20007
|
+
* ```
|
|
20008
|
+
*
|
|
20009
|
+
* Queries a paginable list of {@link Amity.FollowStatus}
|
|
20010
|
+
*
|
|
20011
|
+
* @param query The query parameters
|
|
20012
|
+
* @returns followers
|
|
20013
|
+
*
|
|
20014
|
+
* @category Follow API
|
|
20015
|
+
* @async
|
|
20016
|
+
*/
|
|
20017
|
+
const queryFollowers = async (query) => queryFollows('followers', query);
|
|
20018
|
+
/**
|
|
20019
|
+
* ```js
|
|
20020
|
+
* import { queryFollowers } from '@amityco/ts-sdk'
|
|
20021
|
+
* const { data: followers, prevPage, nextPage } = queryFollowers.locally({ userId })
|
|
20022
|
+
* ```
|
|
20023
|
+
*
|
|
20024
|
+
* Queries a paginable list of {@link Amity.FollowStatus} objects from cache
|
|
20025
|
+
*
|
|
20026
|
+
* @param query The query parameters
|
|
20027
|
+
* @returns followers
|
|
20028
|
+
*
|
|
20029
|
+
* @category Post API
|
|
20030
|
+
*/
|
|
20031
|
+
queryFollowers.locally = (query) => queryFollows.locally('followers', query);
|
|
20032
|
+
|
|
20033
|
+
/**
|
|
20034
|
+
* ```js
|
|
20035
|
+
* import { queryFollowings } from '@amityco/ts-sdk'
|
|
20036
|
+
* const { data: followings, prevPage, nextPage } = await queryFollowings({ userId })
|
|
20037
|
+
* ```
|
|
20038
|
+
*
|
|
20039
|
+
* Queries a paginable list of {@link Amity.FollowStatus}
|
|
20040
|
+
*
|
|
20041
|
+
* @param query The query parameters
|
|
20042
|
+
* @returns followings
|
|
20043
|
+
*
|
|
20044
|
+
* @category Follow API
|
|
20045
|
+
* @async
|
|
20046
|
+
*/
|
|
20047
|
+
const queryFollowings = async (query) => queryFollows('following', query);
|
|
20048
|
+
/**
|
|
20049
|
+
* ```js
|
|
20050
|
+
* import { queryFollowings } from '@amityco/ts-sdk'
|
|
20051
|
+
* const { data: followings, prevPage, nextPage } = queryFollowings.locally({ userId })
|
|
20052
|
+
* ```
|
|
20053
|
+
*
|
|
20054
|
+
* Queries a paginable list of {@link Amity.FollowStatus} objects from cache
|
|
20055
|
+
*
|
|
20056
|
+
* @param query The query parameters
|
|
20057
|
+
* @returns followings
|
|
20058
|
+
*
|
|
20059
|
+
* @category Post API
|
|
20060
|
+
*/
|
|
20061
|
+
queryFollowings.locally = (query) => queryFollows.locally('following', query);
|
|
20062
|
+
|
|
20063
|
+
const getCacheKey = (userId) => [
|
|
20064
|
+
'followInfo',
|
|
20065
|
+
'get',
|
|
20066
|
+
`${getActiveClient().userId}#${userId}`,
|
|
20067
|
+
];
|
|
20068
|
+
/**
|
|
20069
|
+
* ```js
|
|
20070
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
20071
|
+
* const { data: followInfo } = await getFollowInfo('foobar')
|
|
20072
|
+
* ```
|
|
20073
|
+
*
|
|
20074
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user
|
|
20075
|
+
*
|
|
20076
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20077
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
20078
|
+
*
|
|
20079
|
+
* @category Follow API
|
|
20080
|
+
* @async
|
|
20081
|
+
*/
|
|
20082
|
+
const getFollowInfo = async (userId) => {
|
|
20083
|
+
var _a, _b;
|
|
20084
|
+
const client = getActiveClient();
|
|
20085
|
+
client.log('follow/getFollowInfo', userId);
|
|
20086
|
+
const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/followInfo` : `/api/v4/users/${userId}/followInfo`);
|
|
20087
|
+
const cachedAt = client.cache && Date.now();
|
|
20088
|
+
const followInfo = Object.assign(Object.assign({}, data.followCounts[0]), { status: (_b = (_a = data.follows) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.status });
|
|
20089
|
+
if (client.cache) {
|
|
20090
|
+
pushToCache(getCacheKey(userId), followInfo, { cachedAt });
|
|
20091
|
+
}
|
|
20092
|
+
return {
|
|
20093
|
+
data: followInfo,
|
|
20094
|
+
cachedAt,
|
|
20095
|
+
};
|
|
20096
|
+
};
|
|
20097
|
+
/**
|
|
20098
|
+
* ```js
|
|
20099
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
20100
|
+
* const { data: followInfo } = getFollowInfo.locally('foobar')
|
|
20101
|
+
* ```
|
|
20102
|
+
*
|
|
20103
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user from cache
|
|
20104
|
+
*
|
|
20105
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20106
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
20107
|
+
*
|
|
20108
|
+
* @category Follow API
|
|
20109
|
+
*/
|
|
20110
|
+
getFollowInfo.locally = (userId) => {
|
|
20111
|
+
const client = getActiveClient();
|
|
20112
|
+
client.log('follow/getFollowInfo.locally', userId);
|
|
20113
|
+
if (!client.cache) {
|
|
20114
|
+
return;
|
|
20115
|
+
}
|
|
20116
|
+
const cached = pullFromCache(getCacheKey(userId));
|
|
20117
|
+
if (!cached) {
|
|
20118
|
+
return;
|
|
20119
|
+
}
|
|
20120
|
+
return {
|
|
20121
|
+
data: cached.data,
|
|
20122
|
+
cachedAt: cached.cachedAt,
|
|
20123
|
+
};
|
|
20124
|
+
};
|
|
20125
|
+
|
|
20126
|
+
/**
|
|
20127
|
+
* ```js
|
|
20128
|
+
* import { follow } from '@amityco/ts-sdk'
|
|
20129
|
+
* const status = await follow('foobar')
|
|
20130
|
+
* ```
|
|
20131
|
+
*
|
|
20132
|
+
* Follow the user
|
|
20133
|
+
*
|
|
20134
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20135
|
+
* @returns the status {@link Amity.FollowStatus}
|
|
20136
|
+
*
|
|
20137
|
+
* @category Follow API
|
|
20138
|
+
* @async
|
|
20139
|
+
*/
|
|
20140
|
+
const follow = async (userId) => {
|
|
20141
|
+
const client = getActiveClient();
|
|
20142
|
+
client.log('follow/follow', userId);
|
|
20143
|
+
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
20144
|
+
const cachedAt = client.cache && Date.now();
|
|
20145
|
+
if (client.cache) {
|
|
20146
|
+
ingestInCache(data, { cachedAt });
|
|
20147
|
+
}
|
|
20148
|
+
fireEvent(data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested', data.follows[0]);
|
|
20149
|
+
return {
|
|
20150
|
+
data: data.follows[0],
|
|
20151
|
+
cachedAt,
|
|
20152
|
+
};
|
|
20153
|
+
};
|
|
20154
|
+
|
|
20155
|
+
/**
|
|
20156
|
+
* ```js
|
|
20157
|
+
* import { unfollow } from '@amityco/ts-sdk'
|
|
20158
|
+
* await unfollow('foobar')
|
|
20159
|
+
* ```
|
|
20160
|
+
*
|
|
20161
|
+
* Cancel the follow request or unfollow the user
|
|
20162
|
+
*
|
|
20163
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20164
|
+
* @returns A success boolean if the user {@link Amity.User} was unfollowed
|
|
20165
|
+
*
|
|
20166
|
+
* @category Follow API
|
|
20167
|
+
* @async
|
|
20168
|
+
*/
|
|
20169
|
+
const unfollow = async (userId) => {
|
|
20170
|
+
const client = getActiveClient();
|
|
20171
|
+
client.log('follow/unfollow', userId);
|
|
20172
|
+
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
20173
|
+
if (client.cache) {
|
|
20174
|
+
ingestInCache(data);
|
|
20175
|
+
}
|
|
20176
|
+
fireEvent('follow.unfollowed', data.follows[0]);
|
|
20177
|
+
return true;
|
|
20178
|
+
};
|
|
20179
|
+
|
|
20180
|
+
/**
|
|
20181
|
+
* ```js
|
|
20182
|
+
* import { acceptFollower } from '@amityco/ts-sdk'
|
|
20183
|
+
* await acceptFollower('foobar')
|
|
20184
|
+
* ```
|
|
20185
|
+
*
|
|
20186
|
+
* Accept the follow request
|
|
20187
|
+
*
|
|
20188
|
+
* @param userId the ID of the {@link Amity.User} follower
|
|
20189
|
+
* @returns A success boolean if the follow request was accepted
|
|
20190
|
+
*
|
|
20191
|
+
* @category Follow API
|
|
20192
|
+
* @async
|
|
20193
|
+
*/
|
|
20194
|
+
const acceptFollower = async (userId) => {
|
|
20195
|
+
const client = getActiveClient();
|
|
20196
|
+
client.log('follow/acceptFollower', userId);
|
|
20197
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
20198
|
+
if (client.cache) {
|
|
20199
|
+
ingestInCache(data);
|
|
20200
|
+
}
|
|
20201
|
+
fireEvent('follow.accepted', data.follows[0]);
|
|
20202
|
+
return true;
|
|
20203
|
+
};
|
|
20204
|
+
|
|
20205
|
+
/**
|
|
20206
|
+
* ```js
|
|
20207
|
+
* import { declineFollower } from '@amityco/ts-sdk'
|
|
20208
|
+
* await declineFollower('foobar')
|
|
20209
|
+
* ```
|
|
20210
|
+
*
|
|
20211
|
+
* Decline the follow request or delete the follower
|
|
20212
|
+
*
|
|
20213
|
+
* @param userId the ID of the {@link Amity.User} follower
|
|
20214
|
+
* @returns A success boolean if the follow request was decline
|
|
20215
|
+
*
|
|
20216
|
+
* @category Follow API
|
|
20217
|
+
* @async
|
|
20218
|
+
*/
|
|
20219
|
+
const declineFollower = async (userId) => {
|
|
20220
|
+
const client = getActiveClient();
|
|
20221
|
+
client.log('follow/declineFollower', userId);
|
|
20222
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
20223
|
+
if (client.cache) {
|
|
20224
|
+
ingestInCache(data);
|
|
20225
|
+
}
|
|
20226
|
+
fireEvent('follow.requestDeclined', data.follows[0]);
|
|
20227
|
+
return true;
|
|
20228
|
+
};
|
|
20229
|
+
|
|
20230
|
+
const createFollowEventSubscriber = (event, callback) => {
|
|
20231
|
+
const client = getActiveClient();
|
|
20232
|
+
const filter = (payload) => {
|
|
20233
|
+
var _a, _b;
|
|
20234
|
+
if (!client.cache) {
|
|
20235
|
+
callback(payload);
|
|
20236
|
+
}
|
|
20237
|
+
else {
|
|
20238
|
+
ingestInCache({ follows: [payload] });
|
|
20239
|
+
const queries = [
|
|
20240
|
+
...((_a = queryCache(['followers', 'query'])) !== null && _a !== void 0 ? _a : []),
|
|
20241
|
+
...((_b = queryCache(['followings', 'query'])) !== null && _b !== void 0 ? _b : []),
|
|
20242
|
+
];
|
|
20243
|
+
queries
|
|
20244
|
+
// @ts-ignore
|
|
20245
|
+
.filter(({ key }) => key[2].userId === payload.from || key[2].userId === payload.to)
|
|
20246
|
+
.forEach(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
20247
|
+
callback(payload);
|
|
20248
|
+
}
|
|
20249
|
+
};
|
|
20250
|
+
return createEventSubscriber(client, event, event, filter);
|
|
20251
|
+
};
|
|
20252
|
+
|
|
20253
|
+
/**
|
|
20254
|
+
* ```js
|
|
20255
|
+
* import { onUserFollowed } from '@amityco/ts-sdk'
|
|
20256
|
+
* const dispose = onUserFollowed(status => {
|
|
20257
|
+
* // ...
|
|
20258
|
+
* })
|
|
20259
|
+
* ```
|
|
20260
|
+
*
|
|
20261
|
+
* Fired when a user follows another users and confirmation is not required
|
|
20262
|
+
*
|
|
20263
|
+
* @param callback The function to call when the event was fired
|
|
20264
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20265
|
+
*
|
|
20266
|
+
* @category Follow Events
|
|
20267
|
+
*/
|
|
20268
|
+
const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
|
|
20269
|
+
|
|
20270
|
+
/**
|
|
20271
|
+
* ```js
|
|
20272
|
+
* import { onUserUnfollowed } from '@amityco/ts-sdk'
|
|
20273
|
+
* const dispose = onUserFollowed(status => {
|
|
20274
|
+
* // ...
|
|
20275
|
+
* })
|
|
20276
|
+
* ```
|
|
20277
|
+
*
|
|
20278
|
+
* Fired when a user unfollows
|
|
20279
|
+
*
|
|
20280
|
+
* @param callback The function to call when the event was fired
|
|
20281
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20282
|
+
*
|
|
20283
|
+
* @category Follow Events
|
|
20284
|
+
*/
|
|
20285
|
+
const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
|
|
20286
|
+
|
|
20287
|
+
/**
|
|
20288
|
+
* ```js
|
|
20289
|
+
* import { onFollowerDeleted } from '@amityco/ts-sdk'
|
|
20290
|
+
* const dispose = onFollowerDeleted(status => {
|
|
20291
|
+
* // ...
|
|
20292
|
+
* })
|
|
20293
|
+
* ```
|
|
20294
|
+
*
|
|
20295
|
+
* Fired when a follower has been deleted
|
|
20296
|
+
*
|
|
20297
|
+
* @param callback The function to call when the event was fired
|
|
20298
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20299
|
+
*
|
|
20300
|
+
* @category Follow Events
|
|
20301
|
+
*/
|
|
20302
|
+
const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
|
|
20303
|
+
|
|
20304
|
+
/**
|
|
20305
|
+
* ```js
|
|
20306
|
+
* import { onFollowerRequested } from '@amityco/ts-sdk'
|
|
20307
|
+
* const dispose = onFollowerRequested(status => {
|
|
20308
|
+
* // ...
|
|
20309
|
+
* })
|
|
20310
|
+
* ```
|
|
20311
|
+
*
|
|
20312
|
+
* Fired when a user follows another users and confirmation is required
|
|
20313
|
+
*
|
|
20314
|
+
* @param callback The function to call when the event was fired
|
|
20315
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20316
|
+
*
|
|
20317
|
+
* @category Follow Events
|
|
20318
|
+
*/
|
|
20319
|
+
const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
|
|
20320
|
+
|
|
20321
|
+
/**
|
|
20322
|
+
* ```js
|
|
20323
|
+
* import { onFollowRequestCanceled } from '@amityco/ts-sdk'
|
|
20324
|
+
* const dispose = onFollowRequestCanceled(status => {
|
|
20325
|
+
* // ...
|
|
20326
|
+
* })
|
|
20327
|
+
* ```
|
|
20328
|
+
*
|
|
20329
|
+
* Fired when a follow request has been canceled
|
|
20330
|
+
*
|
|
20331
|
+
* @param callback The function to call when the event was fired
|
|
20332
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20333
|
+
*
|
|
20334
|
+
* @category Follow Events
|
|
20335
|
+
*/
|
|
20336
|
+
const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
|
|
20337
|
+
|
|
20338
|
+
/**
|
|
20339
|
+
* ```js
|
|
20340
|
+
* import { onFollowRequestAccepted } from '@amityco/ts-sdk'
|
|
20341
|
+
* const dispose = onFollowRequestAccepted(status => {
|
|
20342
|
+
* // ...
|
|
20343
|
+
* })
|
|
20344
|
+
* ```
|
|
20345
|
+
*
|
|
20346
|
+
* Fired when a follow request has been accepted
|
|
20347
|
+
*
|
|
20348
|
+
* @param callback The function to call when the event was fired
|
|
20349
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20350
|
+
*
|
|
20351
|
+
* @category Follow Events
|
|
20352
|
+
*/
|
|
20353
|
+
const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
|
|
20354
|
+
|
|
20355
|
+
/**
|
|
20356
|
+
* ```js
|
|
20357
|
+
* import { onFollowRequestDeclined } from '@amityco/ts-sdk'
|
|
20358
|
+
* const dispose = onFollowRequestDeclined(status => {
|
|
20359
|
+
* // ...
|
|
20360
|
+
* })
|
|
20361
|
+
* ```
|
|
20362
|
+
*
|
|
20363
|
+
* Fired when a follow request has been declined
|
|
20364
|
+
*
|
|
20365
|
+
* @param callback The function to call when the event was fired
|
|
20366
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20367
|
+
*
|
|
20368
|
+
* @category Follow Events
|
|
20369
|
+
*/
|
|
20370
|
+
const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
|
|
20371
|
+
|
|
20372
|
+
/**
|
|
20373
|
+
* ```js
|
|
20374
|
+
* import { onFollowInfoUpdated } from '@amityco/ts-sdk'
|
|
20375
|
+
* const dispose = onFollowInfoUpdated(followInfo => {
|
|
20376
|
+
* // ...
|
|
20377
|
+
* })
|
|
20378
|
+
* ```
|
|
20379
|
+
*
|
|
20380
|
+
* Fired when a {@link Amity.FollowInfo} has been updated
|
|
20381
|
+
*
|
|
20382
|
+
* @param callback The function to call when the event was fired
|
|
20383
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20384
|
+
*
|
|
20385
|
+
* @category Follow Events
|
|
20386
|
+
*/
|
|
20387
|
+
const onFollowInfoUpdated = (callback) => {
|
|
20388
|
+
const handler = async (payload) => {
|
|
20389
|
+
const [{ data: followInfoFrom }, { data: followInfoTo }] = await Promise.all([
|
|
20390
|
+
getFollowInfo(payload.from),
|
|
20391
|
+
getFollowInfo(payload.to),
|
|
20392
|
+
]);
|
|
20393
|
+
callback(followInfoFrom);
|
|
20394
|
+
callback(followInfoTo);
|
|
20395
|
+
};
|
|
20396
|
+
const disposers = [
|
|
20397
|
+
createFollowEventSubscriber('follow.created', handler),
|
|
20398
|
+
createFollowEventSubscriber('follow.requested', handler),
|
|
20399
|
+
createFollowEventSubscriber('follow.accepted', handler),
|
|
20400
|
+
createFollowEventSubscriber('follow.unfollowed', handler),
|
|
20401
|
+
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
20402
|
+
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
20403
|
+
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
20404
|
+
];
|
|
20405
|
+
return () => {
|
|
20406
|
+
disposers.forEach(fn => fn());
|
|
20407
|
+
};
|
|
20408
|
+
};
|
|
20409
|
+
|
|
20410
|
+
/**
|
|
20411
|
+
* ```js
|
|
20412
|
+
* import { observeFollowInfo } from '@amityco/ts-sdk'
|
|
20413
|
+
*
|
|
20414
|
+
* let followInfo = {}
|
|
20415
|
+
* const dispose = observeFollowInfo(userId, updated => followInfo = updated)
|
|
20416
|
+
* ```
|
|
20417
|
+
*
|
|
20418
|
+
* Observe all mutation on a given {@link Amity.FollowInfo}
|
|
20419
|
+
*
|
|
20420
|
+
* @param userId the ID of the user to observe
|
|
20421
|
+
* @param callback the function to call when new data are available
|
|
20422
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
|
|
20423
|
+
*
|
|
20424
|
+
* @category Follow Observer
|
|
20425
|
+
*/
|
|
20426
|
+
const observeFollowInfo = (userId, callback, policy = 'cache_then_server') => {
|
|
20427
|
+
const { log } = getActiveClient();
|
|
20428
|
+
const timestamp = Date.now();
|
|
20429
|
+
log(`observeFollowInfo(tmpid: ${timestamp}) > listen`);
|
|
20430
|
+
const router = (result, action) => {
|
|
20431
|
+
var _a, _b;
|
|
20432
|
+
if (callback instanceof Function)
|
|
20433
|
+
return callback(result);
|
|
20434
|
+
if (action !== 'onFetch')
|
|
20435
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
20436
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
20437
|
+
};
|
|
20438
|
+
const realtimeRouter = (result, action) => {
|
|
20439
|
+
var _a;
|
|
20440
|
+
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
|
|
20441
|
+
return;
|
|
20442
|
+
router(result, action);
|
|
20443
|
+
};
|
|
20444
|
+
const disposers = [];
|
|
20445
|
+
disposers.push(onFollowInfoUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')));
|
|
20446
|
+
runQuery(createQuery(getFollowInfo, userId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
20447
|
+
return () => {
|
|
20448
|
+
log(`observeFollowInfo(tmpid: ${timestamp}) > dispose`);
|
|
20449
|
+
disposers.forEach(fn => fn());
|
|
20450
|
+
};
|
|
20451
|
+
};
|
|
20452
|
+
|
|
20453
|
+
/**
|
|
20454
|
+
* ```js
|
|
20455
|
+
* import { observeFollowers } from '@amityco/ts-sdk'
|
|
20456
|
+
*
|
|
20457
|
+
* let followers = []
|
|
20458
|
+
* const unsub = observeFollowers('userId', follower => merge(followers, follower))
|
|
20459
|
+
* ```
|
|
20460
|
+
*
|
|
20461
|
+
* Observe all mutations on a list of followers {@link Amity.FollowStatus} for a given user
|
|
20462
|
+
*
|
|
20463
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20464
|
+
* @param callback the function to call when new data are available
|
|
20465
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
20466
|
+
*
|
|
20467
|
+
* @category Follow Observer
|
|
20468
|
+
*/
|
|
20469
|
+
const observeFollowers = (userId, callback) => {
|
|
20470
|
+
const { log } = getActiveClient();
|
|
20471
|
+
const timestamp = Date.now();
|
|
20472
|
+
log(`observeFollowers(tmpid: ${timestamp}) > listen`);
|
|
20473
|
+
const disposers = [];
|
|
20474
|
+
const router = (status, action) => {
|
|
20475
|
+
var _a, _b;
|
|
20476
|
+
if (status.from !== userId) {
|
|
20477
|
+
return;
|
|
20478
|
+
}
|
|
20479
|
+
if (callback instanceof Function) {
|
|
20480
|
+
return callback(status);
|
|
20481
|
+
}
|
|
20482
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
20483
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
20484
|
+
};
|
|
20485
|
+
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')));
|
|
20486
|
+
return () => {
|
|
20487
|
+
log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
|
|
20488
|
+
disposers.forEach(fn => fn());
|
|
20489
|
+
};
|
|
20490
|
+
};
|
|
20491
|
+
|
|
20492
|
+
/**
|
|
20493
|
+
* ```js
|
|
20494
|
+
* import { observeFollowings } from '@amityco/ts-sdk'
|
|
20495
|
+
*
|
|
20496
|
+
* let followings = []
|
|
20497
|
+
* const unsub = observeFollowers('userId', follower => merge(followings, following))
|
|
20498
|
+
* ```
|
|
20499
|
+
*
|
|
20500
|
+
* Observe all mutations on a list of followings {@link Amity.FollowStatus} for a given user
|
|
20501
|
+
*
|
|
20502
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20503
|
+
* @param callback the function to call when new data are available
|
|
20504
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
20505
|
+
*
|
|
20506
|
+
* @category Follow Observer
|
|
20507
|
+
*/
|
|
20508
|
+
const observeFollowings = (userId, callback) => {
|
|
20509
|
+
const { log } = getActiveClient();
|
|
20510
|
+
const timestamp = Date.now();
|
|
20511
|
+
log(`observeFollowings(tmpid: ${timestamp}) > listen`);
|
|
20512
|
+
const disposers = [];
|
|
20513
|
+
const router = (status, action) => {
|
|
20514
|
+
var _a, _b;
|
|
20515
|
+
if (status.to !== userId) {
|
|
20516
|
+
return;
|
|
20517
|
+
}
|
|
20518
|
+
if (callback instanceof Function) {
|
|
20519
|
+
return callback(status);
|
|
20520
|
+
}
|
|
20521
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
20522
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
20523
|
+
};
|
|
20524
|
+
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')));
|
|
20525
|
+
return () => {
|
|
20526
|
+
log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
|
|
20527
|
+
disposers.forEach(fn => fn());
|
|
20528
|
+
};
|
|
20529
|
+
};
|
|
20530
|
+
|
|
20531
|
+
/**
|
|
20532
|
+
* ```js
|
|
20533
|
+
* import { observePosts } from '@amityco/ts-sdk'
|
|
20534
|
+
*
|
|
20535
|
+
* let posts = []
|
|
20536
|
+
* const unsub = observePosts({
|
|
20537
|
+
* targetType: Amity.PostTargetType,
|
|
20538
|
+
* targetId: Amity.Post['targetId'],
|
|
20539
|
+
* }, post => merge(posts, post))
|
|
20540
|
+
* ```
|
|
20541
|
+
*
|
|
20542
|
+
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
20543
|
+
*
|
|
20544
|
+
* @param targetType the type of the target
|
|
20545
|
+
* @param targetId the ID of the target
|
|
20546
|
+
* @param callback the function to call when new data are available
|
|
20547
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
19555
20548
|
*
|
|
19556
20549
|
* @category Post Observer
|
|
19557
20550
|
*/
|
|
@@ -19562,8 +20555,7 @@ const observePosts = (params, callback) => {
|
|
|
19562
20555
|
const disposers = [];
|
|
19563
20556
|
const router = (post, action) => {
|
|
19564
20557
|
var _a, _b;
|
|
19565
|
-
if (params.targetId !== post.targetId
|
|
19566
|
-
|| params.targetType !== post.targetType)
|
|
20558
|
+
if (params.targetId !== post.targetId || params.targetType !== post.targetType)
|
|
19567
20559
|
return;
|
|
19568
20560
|
if (callback instanceof Function)
|
|
19569
20561
|
return callback(post);
|
|
@@ -19702,6 +20694,178 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
|
19702
20694
|
};
|
|
19703
20695
|
};
|
|
19704
20696
|
|
|
20697
|
+
/**
|
|
20698
|
+
* ```js
|
|
20699
|
+
* import { getPoll } from '@amityco/ts-sdk'
|
|
20700
|
+
* const poll = await getPoll('foobar')
|
|
20701
|
+
* ```
|
|
20702
|
+
*
|
|
20703
|
+
* Fetches a {@link Amity.Poll} object
|
|
20704
|
+
*
|
|
20705
|
+
* @param pollId the ID of the {@link Amity.Poll} to fetch
|
|
20706
|
+
* @returns the associated {@link Amity.Poll} object
|
|
20707
|
+
*
|
|
20708
|
+
* @category Poll API
|
|
20709
|
+
* @async
|
|
20710
|
+
*/
|
|
20711
|
+
const getPoll = async (pollId) => {
|
|
20712
|
+
const client = getActiveClient();
|
|
20713
|
+
client.log('poll/getPoll', pollId);
|
|
20714
|
+
const { data } = await client.http.get(`/api/v3/polls/${pollId}`);
|
|
20715
|
+
const cachedAt = client.cache && Date.now();
|
|
20716
|
+
if (client.cache)
|
|
20717
|
+
ingestInCache(data, { cachedAt });
|
|
20718
|
+
const { polls } = data;
|
|
20719
|
+
return {
|
|
20720
|
+
data: polls.find(poll => poll.pollId === pollId),
|
|
20721
|
+
cachedAt,
|
|
20722
|
+
};
|
|
20723
|
+
};
|
|
20724
|
+
/**
|
|
20725
|
+
* ```js
|
|
20726
|
+
* import { getPoll } from '@amityco/ts-sdk'
|
|
20727
|
+
* const poll = getPoll.locally('foobar')
|
|
20728
|
+
* ```
|
|
20729
|
+
*
|
|
20730
|
+
* Fetches a {@link Amity.Poll} object
|
|
20731
|
+
*
|
|
20732
|
+
* @param pollId the ID of the {@link Amity.Poll} to fetch
|
|
20733
|
+
* @returns the associated {@link Amity.Poll} object
|
|
20734
|
+
*
|
|
20735
|
+
* @category Poll API
|
|
20736
|
+
*/
|
|
20737
|
+
getPoll.locally = (pollId) => {
|
|
20738
|
+
const client = getActiveClient();
|
|
20739
|
+
client.log('poll/getPoll', pollId);
|
|
20740
|
+
if (!client.cache)
|
|
20741
|
+
return;
|
|
20742
|
+
const cached = pullFromCache(['poll', 'get', pollId]);
|
|
20743
|
+
if (!cached)
|
|
20744
|
+
return;
|
|
20745
|
+
return {
|
|
20746
|
+
data: cached.data,
|
|
20747
|
+
cachedAt: cached.cachedAt,
|
|
20748
|
+
};
|
|
20749
|
+
};
|
|
20750
|
+
|
|
20751
|
+
/**
|
|
20752
|
+
* ```js
|
|
20753
|
+
* import { createPoll } from '@amityco/ts-sdk'
|
|
20754
|
+
* const created = await createPoll({
|
|
20755
|
+
* question: 'question',
|
|
20756
|
+
* answers: [
|
|
20757
|
+
* { dataType: 'text', data: 'answer1' },
|
|
20758
|
+
* { dataType: 'text', data: 'answer2' },
|
|
20759
|
+
* ],
|
|
20760
|
+
* closedIn: 1649136484
|
|
20761
|
+
* }))
|
|
20762
|
+
* ```
|
|
20763
|
+
*
|
|
20764
|
+
* Creates an {@link Amity.Poll}
|
|
20765
|
+
*
|
|
20766
|
+
* @param bundle The data necessary to create a new {@link Amity.Poll}
|
|
20767
|
+
* @returns The newly created {@link Amity.Poll}
|
|
20768
|
+
*
|
|
20769
|
+
* @category Poll API
|
|
20770
|
+
* @async
|
|
20771
|
+
*/
|
|
20772
|
+
const createPoll = async (bundle) => {
|
|
20773
|
+
const client = getActiveClient();
|
|
20774
|
+
client.log('post/createPoll', bundle);
|
|
20775
|
+
const { data } = await client.http.post('/api/v3/polls', bundle);
|
|
20776
|
+
const cachedAt = client.cache && Date.now();
|
|
20777
|
+
if (client.cache)
|
|
20778
|
+
ingestInCache(data, { cachedAt });
|
|
20779
|
+
const { polls } = data;
|
|
20780
|
+
return {
|
|
20781
|
+
data: polls[0],
|
|
20782
|
+
cachedAt,
|
|
20783
|
+
};
|
|
20784
|
+
};
|
|
20785
|
+
|
|
20786
|
+
/**
|
|
20787
|
+
* ```js
|
|
20788
|
+
* import { closePoll } from '@amityco/ts-sdk'
|
|
20789
|
+
* const updated = await closePoll(pollId)
|
|
20790
|
+
* ```
|
|
20791
|
+
*
|
|
20792
|
+
* Updates an {@link Amity.Poll}
|
|
20793
|
+
*
|
|
20794
|
+
* @param pollId The ID of the {@link Amity.Poll} to close
|
|
20795
|
+
* @returns the updated {@link Amity.Poll} object
|
|
20796
|
+
*
|
|
20797
|
+
* @category Poll API
|
|
20798
|
+
* @async
|
|
20799
|
+
*/
|
|
20800
|
+
const closePoll = async (pollId) => {
|
|
20801
|
+
const client = getActiveClient();
|
|
20802
|
+
client.log('user/closePoll', pollId);
|
|
20803
|
+
const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}`, { status: 'closed' });
|
|
20804
|
+
const cachedAt = client.cache && Date.now();
|
|
20805
|
+
if (client.cache)
|
|
20806
|
+
ingestInCache(data, { cachedAt });
|
|
20807
|
+
const { polls } = data;
|
|
20808
|
+
return {
|
|
20809
|
+
data: polls.find(poll => poll.pollId === pollId),
|
|
20810
|
+
cachedAt,
|
|
20811
|
+
};
|
|
20812
|
+
};
|
|
20813
|
+
|
|
20814
|
+
/**
|
|
20815
|
+
* ```js
|
|
20816
|
+
* import { deletePoll } from '@amityco/ts-sdk'
|
|
20817
|
+
* const success = await deletePoll(pollId)
|
|
20818
|
+
* ```
|
|
20819
|
+
*
|
|
20820
|
+
* Deletes a {@link Amity.Poll}
|
|
20821
|
+
*
|
|
20822
|
+
* @param pollId The {@link Amity.Poll} ID to delete
|
|
20823
|
+
* @return A success boolean if the {@link Amity.Poll} was deleted
|
|
20824
|
+
*
|
|
20825
|
+
* @category Poll API
|
|
20826
|
+
* @async
|
|
20827
|
+
*/
|
|
20828
|
+
const deletePoll = async (pollId) => {
|
|
20829
|
+
const client = getActiveClient();
|
|
20830
|
+
client.log('poll/deletePoll', pollId);
|
|
20831
|
+
const poll = await getPoll(pollId);
|
|
20832
|
+
// API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
|
|
20833
|
+
const { data } = await client.http.delete(`/api/v3/polls/${pollId}`);
|
|
20834
|
+
const { success } = data; // unwrapPayload(data)
|
|
20835
|
+
const deleted = Object.assign(Object.assign({}, poll.data), { isDeleted: true });
|
|
20836
|
+
upsertInCache(['poll', 'get', pollId], deleted);
|
|
20837
|
+
return success;
|
|
20838
|
+
};
|
|
20839
|
+
|
|
20840
|
+
/**
|
|
20841
|
+
* ```js
|
|
20842
|
+
* import { votePoll } from '@amityco/ts-sdk'
|
|
20843
|
+
* const voted = await votePoll(pollId)
|
|
20844
|
+
* ```
|
|
20845
|
+
*
|
|
20846
|
+
* Votes for an {@link Amity.Poll}
|
|
20847
|
+
*
|
|
20848
|
+
* @param pollId The ID of the {@link Amity.Poll} to vote
|
|
20849
|
+
* @param answerIds The IDs of the {@link Amity.Poll} answers to vote {@link Amity.Poll}
|
|
20850
|
+
* @returns the updated {@link Amity.Poll} object
|
|
20851
|
+
*
|
|
20852
|
+
* @category Poll API
|
|
20853
|
+
* @async
|
|
20854
|
+
*/
|
|
20855
|
+
const votePoll = async (pollId, answerIds) => {
|
|
20856
|
+
const client = getActiveClient();
|
|
20857
|
+
client.log('user/votePoll', pollId);
|
|
20858
|
+
const { data } = await client.http.post(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds });
|
|
20859
|
+
const cachedAt = client.cache && Date.now();
|
|
20860
|
+
if (client.cache)
|
|
20861
|
+
ingestInCache(data, { cachedAt });
|
|
20862
|
+
const { polls } = data;
|
|
20863
|
+
return {
|
|
20864
|
+
data: polls.find(poll => poll.pollId === pollId),
|
|
20865
|
+
cachedAt,
|
|
20866
|
+
};
|
|
20867
|
+
};
|
|
20868
|
+
|
|
19705
20869
|
/**
|
|
19706
20870
|
* ```js
|
|
19707
20871
|
* import { getStream } from '@amityco/ts-sdk'
|
|
@@ -19774,9 +20938,11 @@ const queryStreams = async (query) => {
|
|
|
19774
20938
|
const client = getActiveClient();
|
|
19775
20939
|
client.log('stream/queryStreams', query);
|
|
19776
20940
|
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
19777
|
-
const { data } = await client.http.get(`/api/v3/video-streaming`, {
|
|
20941
|
+
const { data } = await client.http.get(`/api/v3/video-streaming`, {
|
|
20942
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
19778
20943
|
token: toToken(page, 'skiplimit'),
|
|
19779
|
-
} })
|
|
20944
|
+
} }),
|
|
20945
|
+
});
|
|
19780
20946
|
// API-FIX: backend to response Amity.Response: const { paging, videoStreamings } = unwrapPayload(data)
|
|
19781
20947
|
// API-FIX: seems returned data has a results identifier on top of data, like no other apis, and this is beautiful
|
|
19782
20948
|
const { paging, results: payload } = data;
|
|
@@ -19882,7 +21048,7 @@ const updateStream = async (streamId, patch) => {
|
|
|
19882
21048
|
const deleteStream = async (streamId) => {
|
|
19883
21049
|
const client = getActiveClient();
|
|
19884
21050
|
client.log('stream/deleteStream', streamId);
|
|
19885
|
-
|
|
21051
|
+
const stream = await getStream(streamId);
|
|
19886
21052
|
// API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
|
|
19887
21053
|
// API-FIX: swagger docs are wrong!
|
|
19888
21054
|
const { data } = await client.http.delete(`/api/v3/video-streaming/${streamId}`);
|
|
@@ -19993,4 +21159,4 @@ const onStreamRecorded = (callback) => {
|
|
|
19993
21159
|
return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
|
|
19994
21160
|
};
|
|
19995
21161
|
|
|
19996
|
-
export { API_REGIONS, SubscriptionLevels, VERSION$1 as VERSION, addChannelMembers, addChannelMembersRole, addCommunityMembers,
|
|
21162
|
+
export { API_REGIONS, SubscriptionLevels, VERSION$1 as VERSION, acceptFollower, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRoles, addReaction, backupCache, closePoll, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createMessage, createPoll, createPost, createQuery, createReport, createStream, createVideo, declineFollower, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePoll, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, follow, getActiveClient, getCategory, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getFollowInfo, getMessage, getMessages, getMyFollowersTopic, getMyFollowingsTopic, getPoll, getPost, getPostTopic, getPosts, getRecommendedCommunities, getRole, getStream, getTopTrendingCommunities, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeFollowInfo, observeFollowers, observeFollowings, observeMessage, observeMessages, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onFollowInfoUpdated, onFollowRequestAccepted, onFollowRequestCanceled, onFollowRequestDeclined, onFollowerDeleted, onFollowerRequested, onMemberAdded, onMemberRemoved, onMessageCreated, onMessageDeleted, onMessageUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserFlagCleared, onUserFlagged, onUserFollowed, onUserUnflagged, onUserUnfollowed, onUserUpdated, pullFromCache, pushToCache, queryCache, queryCategories, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryFollowers, queryFollowings, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRoles, removeReaction, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, unfollow, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, votePoll, wipeCache };
|