@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.cjs.js
CHANGED
|
@@ -20,7 +20,10 @@ var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
|
|
|
20
20
|
var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
|
|
21
21
|
|
|
22
22
|
var _a$1;
|
|
23
|
-
|
|
23
|
+
/* eslint-disable no-undef */
|
|
24
|
+
const theGlobal =
|
|
25
|
+
// eslint-disable-next-line no-nested-ternary
|
|
26
|
+
typeof globalThis === 'object' ? globalThis : typeof global === 'object' ? global : window;
|
|
24
27
|
const { process: safeProcess = {} } = theGlobal;
|
|
25
28
|
const isProduction = ((_a$1 = safeProcess.env) === null || _a$1 === void 0 ? void 0 : _a$1.NODE_ENV) === 'production';
|
|
26
29
|
|
|
@@ -35,7 +38,7 @@ const VERSION$1 = (_b = (_a = safeProcess.env) === null || _a === void 0 ? void
|
|
|
35
38
|
*
|
|
36
39
|
* @hidden
|
|
37
40
|
*/
|
|
38
|
-
const isSkipLimit = (json) =>
|
|
41
|
+
const isSkipLimit = (json) => ['skip', 'limit'].some(prop => prop in json);
|
|
39
42
|
/**
|
|
40
43
|
* Type guard to find if the a given decoded backend token uses "after/before" pagination style
|
|
41
44
|
*
|
|
@@ -44,7 +47,7 @@ const isSkipLimit = (json) => (['skip', 'limit'].some(prop => prop in json));
|
|
|
44
47
|
*
|
|
45
48
|
* @hidden
|
|
46
49
|
*/
|
|
47
|
-
const isAfterBefore = (json) =>
|
|
50
|
+
const isAfterBefore = (json) => ['after', 'before', 'first', 'last', 'limit'].some(prop => prop in json);
|
|
48
51
|
/**
|
|
49
52
|
* Type guard to find if the a given decoded backend token uses v4 or newer "after/before" pagination style
|
|
50
53
|
*
|
|
@@ -53,7 +56,7 @@ const isAfterBefore = (json) => (['after', 'before', 'first', 'last', 'limit'].s
|
|
|
53
56
|
*
|
|
54
57
|
* @hidden
|
|
55
58
|
*/
|
|
56
|
-
const isAfterBeforeRaw = (json) =>
|
|
59
|
+
const isAfterBeforeRaw = (json) => 'limit' in json;
|
|
57
60
|
/**
|
|
58
61
|
* Type guard to find if the a given object is wrapped around Amity.Paged<>
|
|
59
62
|
*
|
|
@@ -63,9 +66,9 @@ const isAfterBeforeRaw = (json) => ('limit' in json);
|
|
|
63
66
|
* @hidden
|
|
64
67
|
*/
|
|
65
68
|
const isPaged = (payload) => {
|
|
66
|
-
return ((payload === null || payload === void 0 ? void 0 : payload.hasOwnProperty('data'))
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
return ((payload === null || payload === void 0 ? void 0 : payload.hasOwnProperty('data')) &&
|
|
70
|
+
(payload === null || payload === void 0 ? void 0 : payload.hasOwnProperty('nextPage')) &&
|
|
71
|
+
(payload === null || payload === void 0 ? void 0 : payload.hasOwnProperty('prevPage')));
|
|
69
72
|
};
|
|
70
73
|
/**
|
|
71
74
|
* Converts a paging object into a b64 string token
|
|
@@ -95,19 +98,19 @@ const toToken = (paging, style) => {
|
|
|
95
98
|
"before" or "after" value. if that would change,
|
|
96
99
|
we'd need to move toward a more simple: `!paging.before`
|
|
97
100
|
*/
|
|
98
|
-
if (!isNaN(paging === null || paging === void 0 ? void 0 : paging.before)) {
|
|
101
|
+
if (!Number.isNaN(paging === null || paging === void 0 ? void 0 : paging.before)) {
|
|
99
102
|
payload = {
|
|
100
103
|
before: paging.before,
|
|
101
104
|
last: paging.limit,
|
|
102
105
|
};
|
|
103
106
|
}
|
|
104
|
-
else if (!isNaN(paging === null || paging === void 0 ? void 0 : paging.after)) {
|
|
107
|
+
else if (!Number.isNaN(paging === null || paging === void 0 ? void 0 : paging.after)) {
|
|
105
108
|
payload = {
|
|
106
109
|
after: paging.after,
|
|
107
110
|
first: paging.limit,
|
|
108
111
|
};
|
|
109
112
|
}
|
|
110
|
-
else if (!isNaN(paging === null || paging === void 0 ? void 0 : paging.limit)) {
|
|
113
|
+
else if (!Number.isNaN(paging === null || paging === void 0 ? void 0 : paging.limit)) {
|
|
111
114
|
payload = {
|
|
112
115
|
last: paging.limit,
|
|
113
116
|
};
|
|
@@ -132,7 +135,7 @@ const toToken = (paging, style) => {
|
|
|
132
135
|
*/
|
|
133
136
|
const toPage = (token) => {
|
|
134
137
|
if (!token)
|
|
135
|
-
return
|
|
138
|
+
return undefined;
|
|
136
139
|
// don't try catch, let it throw
|
|
137
140
|
const json = JSON.parse(jsBase64.decode(token));
|
|
138
141
|
if (isSkipLimit(json)) {
|
|
@@ -141,21 +144,21 @@ const toPage = (token) => {
|
|
|
141
144
|
limit: json.limit,
|
|
142
145
|
};
|
|
143
146
|
}
|
|
144
|
-
|
|
147
|
+
if (isAfterBefore(json)) {
|
|
145
148
|
if ('before' in json) {
|
|
146
149
|
return {
|
|
147
150
|
before: json.before,
|
|
148
151
|
limit: json.last,
|
|
149
152
|
};
|
|
150
153
|
}
|
|
151
|
-
|
|
154
|
+
if ('after' in json) {
|
|
152
155
|
return {
|
|
153
156
|
after: json.after,
|
|
154
157
|
limit: json.first,
|
|
155
158
|
};
|
|
156
159
|
}
|
|
157
160
|
}
|
|
158
|
-
return
|
|
161
|
+
return undefined;
|
|
159
162
|
};
|
|
160
163
|
/**
|
|
161
164
|
* Converts a b64 string token into a paging object
|
|
@@ -167,15 +170,16 @@ const toPage = (token) => {
|
|
|
167
170
|
*/
|
|
168
171
|
const toPageRaw = (token) => {
|
|
169
172
|
if (!token)
|
|
170
|
-
return
|
|
173
|
+
return undefined;
|
|
171
174
|
// don't try catch, let it throw
|
|
172
175
|
const json = JSON.parse(jsBase64.decode(token));
|
|
173
176
|
if (isAfterBeforeRaw(json)) {
|
|
174
177
|
return json;
|
|
175
178
|
}
|
|
176
|
-
return
|
|
179
|
+
return undefined;
|
|
177
180
|
};
|
|
178
181
|
|
|
182
|
+
/* eslint-disable no-use-before-define */
|
|
179
183
|
/**
|
|
180
184
|
* Type guard to check and cast that a given async function is has the ".locally" property
|
|
181
185
|
*
|
|
@@ -184,7 +188,7 @@ const toPageRaw = (token) => {
|
|
|
184
188
|
*
|
|
185
189
|
* @hidden
|
|
186
190
|
*/
|
|
187
|
-
const isFetcher = (func) =>
|
|
191
|
+
const isFetcher = (func) => 'locally' in func;
|
|
188
192
|
/**
|
|
189
193
|
* Type guard to check and cast that a given async function is has the ".optimistically" property
|
|
190
194
|
*
|
|
@@ -193,7 +197,7 @@ const isFetcher = (func) => ('locally' in func);
|
|
|
193
197
|
*
|
|
194
198
|
* @hidden
|
|
195
199
|
*/
|
|
196
|
-
const isMutator = (func) =>
|
|
200
|
+
const isMutator = (func) => 'optimistically' in func;
|
|
197
201
|
/**
|
|
198
202
|
* Type guard to check and cast that a given async function is has
|
|
199
203
|
* the ".locally" or ".optimistically" property
|
|
@@ -212,7 +216,7 @@ const isOffline = (func) => isFetcher(func) || isMutator(func);
|
|
|
212
216
|
*
|
|
213
217
|
* @hidden
|
|
214
218
|
*/
|
|
215
|
-
const isCachable = (model) =>
|
|
219
|
+
const isCachable = (model) => model === null || model === void 0 ? void 0 : model.hasOwnProperty('cachedAt');
|
|
216
220
|
/**
|
|
217
221
|
* Checks if a model is considered local (cachedAt === -1)
|
|
218
222
|
*
|
|
@@ -270,7 +274,7 @@ const createQuery = (func, ...args) => ({ func, args });
|
|
|
270
274
|
const queryOptions = (policy, lifeSpan = 2 * 60 * 1000) => {
|
|
271
275
|
if (policy === 'cache_only')
|
|
272
276
|
return { lifeSpan: Infinity };
|
|
273
|
-
|
|
277
|
+
if (policy === 'server_only')
|
|
274
278
|
return { lifeSpan: 0 };
|
|
275
279
|
return { lifeSpan };
|
|
276
280
|
};
|
|
@@ -296,9 +300,7 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
296
300
|
// offline first
|
|
297
301
|
if (isOffline(func) && options.lifeSpan !== 0) {
|
|
298
302
|
try {
|
|
299
|
-
local = isMutator(func)
|
|
300
|
-
? func.optimistically(...args)
|
|
301
|
-
: func.locally(...args);
|
|
303
|
+
local = isMutator(func) ? func.optimistically(...args) : func.locally(...args);
|
|
302
304
|
}
|
|
303
305
|
catch (error) {
|
|
304
306
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(undefined, {
|
|
@@ -310,7 +312,7 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
310
312
|
const shouldAbort = isCachable(local) && isFresh(local, options.lifeSpan);
|
|
311
313
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(local, {
|
|
312
314
|
origin: 'local',
|
|
313
|
-
loading: !(isFetcher(func) && shouldAbort)
|
|
315
|
+
loading: !(isFetcher(func) && shouldAbort),
|
|
314
316
|
}));
|
|
315
317
|
if (shouldAbort)
|
|
316
318
|
return;
|
|
@@ -318,13 +320,13 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
318
320
|
else {
|
|
319
321
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(undefined, {
|
|
320
322
|
origin: 'local',
|
|
321
|
-
loading: true
|
|
323
|
+
loading: true,
|
|
322
324
|
}));
|
|
323
325
|
}
|
|
324
326
|
func(...args)
|
|
325
327
|
.then(fresh => {
|
|
326
328
|
// @ts-ignore i know.
|
|
327
|
-
//
|
|
329
|
+
// isLocal(local) && syncInCache(local, fresh)
|
|
328
330
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(fresh, {
|
|
329
331
|
origin: 'server',
|
|
330
332
|
loading: false,
|
|
@@ -338,6 +340,7 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
338
340
|
}));
|
|
339
341
|
});
|
|
340
342
|
};
|
|
343
|
+
// eslint-disable-next-line no-redeclare
|
|
341
344
|
function createSnapshot(data, options) {
|
|
342
345
|
if (isPaged(data) || isCachable(data))
|
|
343
346
|
return Object.assign(Object.assign({}, options), data);
|
|
@@ -391,6 +394,7 @@ const sortByLastCreated = ({ createdAt: a }, { createdAt: b }) => new Date(b).va
|
|
|
391
394
|
*/
|
|
392
395
|
const sortByLastActivity = ({ lastActivity: a }, { lastActivity: b }) => new Date(b).valueOf() - new Date(a).valueOf();
|
|
393
396
|
|
|
397
|
+
/* eslint-disable max-classes-per-file */
|
|
394
398
|
/**
|
|
395
399
|
* Generic ASC error
|
|
396
400
|
* @category Errors
|
|
@@ -420,6 +424,7 @@ class ASCApiError extends ASCError {
|
|
|
420
424
|
* @param code A normalized error code
|
|
421
425
|
* @param level A normalized failure level descriptor
|
|
422
426
|
*/
|
|
427
|
+
// eslint-disable-next-line no-useless-constructor
|
|
423
428
|
constructor(message, code, level) {
|
|
424
429
|
super(message, code, level);
|
|
425
430
|
}
|
|
@@ -446,7 +451,9 @@ class ASCConnectionError extends ASCError {
|
|
|
446
451
|
* @param message A custom error message
|
|
447
452
|
*/
|
|
448
453
|
constructor(event, message = 'SDK client is having connection issues') {
|
|
449
|
-
super(`${message} (${event})`, event === 'disconnected'
|
|
454
|
+
super(`${message} (${event})`, event === 'disconnected'
|
|
455
|
+
? 800211 /* DISCONNECTED */
|
|
456
|
+
: 800210 /* CONNECTION_ERROR */, "error" /* ERROR */);
|
|
450
457
|
this.event = event;
|
|
451
458
|
}
|
|
452
459
|
}
|
|
@@ -486,12 +493,12 @@ const setActiveClient = (client) => {
|
|
|
486
493
|
* @hidden
|
|
487
494
|
*/
|
|
488
495
|
const createLogger = (session) => {
|
|
489
|
-
const active =
|
|
490
|
-
&& !isProduction);
|
|
496
|
+
const active = `${session === null || session === void 0 ? void 0 : session.trim()}`.length > 0 && !isProduction;
|
|
491
497
|
const logger = debug__default['default'](session);
|
|
492
498
|
const print = (topic, ...args) => {
|
|
493
499
|
active && logger(topic, args);
|
|
494
500
|
};
|
|
501
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
495
502
|
print.__instance__ = logger;
|
|
496
503
|
return print;
|
|
497
504
|
};
|
|
@@ -524,7 +531,7 @@ const unwrapPayload = (response) => {
|
|
|
524
531
|
if (response.status === 'success') {
|
|
525
532
|
return response.data;
|
|
526
533
|
}
|
|
527
|
-
|
|
534
|
+
if (response.status === 'fail') {
|
|
528
535
|
throw new ASCUnknownError(response.code);
|
|
529
536
|
}
|
|
530
537
|
else if (response.status === 'error') {
|
|
@@ -546,9 +553,10 @@ const stringify = (params, prefix) => {
|
|
|
546
553
|
if (Array.isArray(value)) {
|
|
547
554
|
return value.map(item => `${key}[]=${item}`).join('&');
|
|
548
555
|
}
|
|
549
|
-
|
|
556
|
+
if (typeof value !== 'object') {
|
|
550
557
|
return `${key}=${value}`;
|
|
551
558
|
}
|
|
559
|
+
// @ts-ignore
|
|
552
560
|
return stringify(value, prefix !== null && prefix !== void 0 ? prefix : name);
|
|
553
561
|
})
|
|
554
562
|
.join('&');
|
|
@@ -575,9 +583,10 @@ const createHttpTransport = (endpoint) => {
|
|
|
575
583
|
httpsAgent: new HttpAgent.HttpsAgent(options),
|
|
576
584
|
paramsSerializer: stringify,
|
|
577
585
|
});
|
|
578
|
-
instance.interceptors.response.use(
|
|
586
|
+
instance.interceptors.response.use(response => response, error => {
|
|
579
587
|
var _a;
|
|
580
588
|
const { response } = error;
|
|
589
|
+
// eslint-disable-next-line no-console
|
|
581
590
|
console.error((_a = response === null || response === void 0 ? void 0 : response.data) !== null && _a !== void 0 ? _a : error);
|
|
582
591
|
if (response)
|
|
583
592
|
unwrapPayload(response.data);
|
|
@@ -14595,6 +14604,7 @@ function extend() {
|
|
|
14595
14604
|
|
|
14596
14605
|
var mqtt = mqtt$1.exports;
|
|
14597
14606
|
|
|
14607
|
+
/* eslint-disable no-console */
|
|
14598
14608
|
const QOS_FAILURE_CODE = 128;
|
|
14599
14609
|
const RETRY_BASE_TIMEOUT = 1000;
|
|
14600
14610
|
const RETRY_COUNT_MAX = 10;
|
|
@@ -14609,7 +14619,7 @@ function getMqttOptions(params) {
|
|
|
14609
14619
|
topic: 'WillMsg',
|
|
14610
14620
|
payload: 'Connection Closed abnormally..!',
|
|
14611
14621
|
qos: 0,
|
|
14612
|
-
retain: false
|
|
14622
|
+
retain: false,
|
|
14613
14623
|
} }, params);
|
|
14614
14624
|
}
|
|
14615
14625
|
/**
|
|
@@ -14625,6 +14635,12 @@ const createMqttTransport = (endpoint) => {
|
|
|
14625
14635
|
let mqttClient;
|
|
14626
14636
|
let retryCount = 0;
|
|
14627
14637
|
let allowReconnection = true;
|
|
14638
|
+
const reconnect = () => {
|
|
14639
|
+
setTimeout(() => {
|
|
14640
|
+
retryCount += 1;
|
|
14641
|
+
mqttClient.reconnect();
|
|
14642
|
+
}, RETRY_BASE_TIMEOUT * 2 ** (retryCount > RETRY_COUNT_MAX ? RETRY_COUNT_MAX : retryCount));
|
|
14643
|
+
};
|
|
14628
14644
|
async function connect(params) {
|
|
14629
14645
|
if (mqttClient) {
|
|
14630
14646
|
mqttClient.removeAllListeners();
|
|
@@ -14636,6 +14652,7 @@ const createMqttTransport = (endpoint) => {
|
|
|
14636
14652
|
allowReconnection = true;
|
|
14637
14653
|
});
|
|
14638
14654
|
mqttClient.on('error', (error) => {
|
|
14655
|
+
// eslint-disable-next-line default-case
|
|
14639
14656
|
switch (error.code) {
|
|
14640
14657
|
case 2 /* IDENTIFIER_REJECTED */:
|
|
14641
14658
|
case 4 /* BAD_USERNAME_OR_PASSWORD */:
|
|
@@ -14650,12 +14667,6 @@ const createMqttTransport = (endpoint) => {
|
|
|
14650
14667
|
});
|
|
14651
14668
|
return new Promise(resolve => mqttClient.once('connect', () => resolve()));
|
|
14652
14669
|
}
|
|
14653
|
-
const reconnect = () => {
|
|
14654
|
-
setTimeout(() => {
|
|
14655
|
-
retryCount = retryCount + 1;
|
|
14656
|
-
mqttClient.reconnect();
|
|
14657
|
-
}, RETRY_BASE_TIMEOUT * Math.pow(2, retryCount > RETRY_COUNT_MAX ? RETRY_COUNT_MAX : retryCount));
|
|
14658
|
-
};
|
|
14659
14670
|
return {
|
|
14660
14671
|
connect,
|
|
14661
14672
|
async disconnect() {
|
|
@@ -14689,8 +14700,8 @@ const createMqttTransport = (endpoint) => {
|
|
|
14689
14700
|
if (error || granted[0].qos === QOS_FAILURE_CODE) {
|
|
14690
14701
|
const ascError = error
|
|
14691
14702
|
? new ASCError(error.message, 800000 /* UNKNOWN_ERROR */, "error" /* ERROR */)
|
|
14692
|
-
// TODO throw the actual error, once BE can tell us the actual error code
|
|
14693
|
-
|
|
14703
|
+
: // TODO throw the actual error, once BE can tell us the actual error code
|
|
14704
|
+
new ASCUnknownError(800000 /* UNKNOWN_ERROR */, "error" /* ERROR */);
|
|
14694
14705
|
console.error(`Failed to subscribe to topic ${topic}`, ascError);
|
|
14695
14706
|
callback === null || callback === void 0 ? void 0 : callback(ascError);
|
|
14696
14707
|
}
|
|
@@ -14709,10 +14720,11 @@ const createMqttTransport = (endpoint) => {
|
|
|
14709
14720
|
},
|
|
14710
14721
|
unsubscribe(topic) {
|
|
14711
14722
|
mqttClient === null || mqttClient === void 0 ? void 0 : mqttClient.unsubscribe(topic);
|
|
14712
|
-
}
|
|
14723
|
+
},
|
|
14713
14724
|
};
|
|
14714
14725
|
};
|
|
14715
14726
|
|
|
14727
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
14716
14728
|
let tasks = [];
|
|
14717
14729
|
let timer;
|
|
14718
14730
|
/**
|
|
@@ -14729,6 +14741,7 @@ const scheduleTask = (task) => {
|
|
|
14729
14741
|
}, 0);
|
|
14730
14742
|
};
|
|
14731
14743
|
|
|
14744
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
14732
14745
|
// need to sync up the list
|
|
14733
14746
|
const WS_EVENTS = [
|
|
14734
14747
|
'disconnected',
|
|
@@ -14755,7 +14768,7 @@ const MQTT_EVENTS = [
|
|
|
14755
14768
|
'error',
|
|
14756
14769
|
'close',
|
|
14757
14770
|
'end',
|
|
14758
|
-
'reconnect'
|
|
14771
|
+
'reconnect',
|
|
14759
14772
|
];
|
|
14760
14773
|
/** @hidden */
|
|
14761
14774
|
const createEventEmitter = () => {
|
|
@@ -14819,7 +14832,9 @@ const createEventSubscriber = (client, namespace, event, fn) => {
|
|
|
14819
14832
|
*/
|
|
14820
14833
|
const fireEvent = (event, payload) => {
|
|
14821
14834
|
const { emitter } = getActiveClient();
|
|
14822
|
-
scheduleTask(() => {
|
|
14835
|
+
scheduleTask(() => {
|
|
14836
|
+
emitter.emit(event, payload);
|
|
14837
|
+
});
|
|
14823
14838
|
};
|
|
14824
14839
|
|
|
14825
14840
|
/**
|
|
@@ -14836,7 +14851,7 @@ const fireEvent = (event, payload) => {
|
|
|
14836
14851
|
* @returns A {@link Amity.Client} instance
|
|
14837
14852
|
*
|
|
14838
14853
|
* @category Client API
|
|
14839
|
-
|
|
14854
|
+
* */
|
|
14840
14855
|
const createClient = (apiKey, apiRegion = API_REGIONS.SG, debugSession = 'amity') => {
|
|
14841
14856
|
const log = createLogger(debugSession);
|
|
14842
14857
|
log('client/api/createClient', {
|
|
@@ -14929,6 +14944,24 @@ const getDeviceInfo = () => {
|
|
|
14929
14944
|
};
|
|
14930
14945
|
};
|
|
14931
14946
|
|
|
14947
|
+
let activeUser = null;
|
|
14948
|
+
/**
|
|
14949
|
+
* for internal use
|
|
14950
|
+
*/
|
|
14951
|
+
const getActiveUser = () => {
|
|
14952
|
+
if (!activeUser) {
|
|
14953
|
+
throw new ASCError('Connect client first', 800000 /* UNKNOWN_ERROR */, "fatal" /* FATAL */);
|
|
14954
|
+
}
|
|
14955
|
+
return activeUser;
|
|
14956
|
+
};
|
|
14957
|
+
const setActiveUser = (user) => {
|
|
14958
|
+
activeUser = {
|
|
14959
|
+
_id: user._id,
|
|
14960
|
+
userId: user.userId,
|
|
14961
|
+
path: user.path,
|
|
14962
|
+
};
|
|
14963
|
+
};
|
|
14964
|
+
|
|
14932
14965
|
/**
|
|
14933
14966
|
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
14934
14967
|
*
|
|
@@ -14946,8 +14979,8 @@ const getToken = async (params) => {
|
|
|
14946
14979
|
client.log('client/api/getToken', params);
|
|
14947
14980
|
const deviceInfo = await getDeviceInfo();
|
|
14948
14981
|
const { data } = await client.http.post('/v1/device', Object.assign(Object.assign({}, params), { deviceInfo }), {
|
|
14949
|
-
|
|
14950
|
-
headers: { 'X-API-Key': client.apiKey }
|
|
14982
|
+
// @ts-ignore
|
|
14983
|
+
headers: { 'X-API-Key': client.apiKey },
|
|
14951
14984
|
});
|
|
14952
14985
|
return data;
|
|
14953
14986
|
};
|
|
@@ -14976,12 +15009,12 @@ const EVENTS = [
|
|
|
14976
15009
|
*/
|
|
14977
15010
|
const onConnectionError = (callback) => {
|
|
14978
15011
|
const client = getActiveClient();
|
|
14979
|
-
const subscribers = EVENTS.map(event =>
|
|
15012
|
+
const subscribers = EVENTS.map(event => createEventSubscriber(client, `client/onConnectionError(${event})`, event, response => {
|
|
14980
15013
|
const error = (response === null || response === void 0 ? void 0 : response.code)
|
|
14981
15014
|
? new ASCError(response.message, response.code, "fatal" /* FATAL */)
|
|
14982
15015
|
: new ASCConnectionError(event);
|
|
14983
15016
|
callback(error);
|
|
14984
|
-
}))
|
|
15017
|
+
}));
|
|
14985
15018
|
return () => {
|
|
14986
15019
|
subscribers.forEach(fn => fn());
|
|
14987
15020
|
};
|
|
@@ -15029,6 +15062,7 @@ const onClientBanned = (callback) => {
|
|
|
15029
15062
|
});
|
|
15030
15063
|
};
|
|
15031
15064
|
|
|
15065
|
+
/* eslint-disable no-param-reassign */
|
|
15032
15066
|
/**
|
|
15033
15067
|
* ```js
|
|
15034
15068
|
* import { connectClient } from '@amityco/ts-sdk/client/api'
|
|
@@ -15059,7 +15093,7 @@ const connectClient = async (params) => {
|
|
|
15059
15093
|
// ignored since we enforce default values just before.
|
|
15060
15094
|
const { accessToken, users } = await getToken(params);
|
|
15061
15095
|
// manually setup the token for http transport
|
|
15062
|
-
client.http.defaults.headers.common
|
|
15096
|
+
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
15063
15097
|
// manually setup the token for ws transport
|
|
15064
15098
|
client.ws.io.opts.query = { token: accessToken };
|
|
15065
15099
|
// FIXME: events are duplicated if connectClient is called few times without disconnectClient
|
|
@@ -15076,8 +15110,8 @@ const connectClient = async (params) => {
|
|
|
15076
15110
|
unsubscribe();
|
|
15077
15111
|
});
|
|
15078
15112
|
client.userId = params.userId;
|
|
15079
|
-
client._internalUserId = users[0]._id;
|
|
15080
15113
|
client.accessToken = accessToken;
|
|
15114
|
+
setActiveUser(users[0]);
|
|
15081
15115
|
return client.ws.connected;
|
|
15082
15116
|
};
|
|
15083
15117
|
|
|
@@ -15097,9 +15131,9 @@ const isConnected = () => {
|
|
|
15097
15131
|
var _a, _b;
|
|
15098
15132
|
const client = getActiveClient();
|
|
15099
15133
|
client.log('client/api/isConnected', client);
|
|
15100
|
-
return !!(client.userId
|
|
15101
|
-
|
|
15102
|
-
|
|
15134
|
+
return !!(client.userId &&
|
|
15135
|
+
((_b = (_a = client.http.defaults.headers.common) === null || _a === void 0 ? void 0 : _a.Authorization) === null || _b === void 0 ? void 0 : _b.length) &&
|
|
15136
|
+
client.ws.connected);
|
|
15103
15137
|
};
|
|
15104
15138
|
|
|
15105
15139
|
exports.SubscriptionLevels = void 0;
|
|
@@ -15110,7 +15144,7 @@ exports.SubscriptionLevels = void 0;
|
|
|
15110
15144
|
SubscriptionLevels["POST_AND_COMMENT"] = "post_and_comment";
|
|
15111
15145
|
SubscriptionLevels["USER"] = "user";
|
|
15112
15146
|
})(exports.SubscriptionLevels || (exports.SubscriptionLevels = {}));
|
|
15113
|
-
const getCommunityUserTopic = (
|
|
15147
|
+
const getCommunityUserTopic = (path, level) => {
|
|
15114
15148
|
switch (level) {
|
|
15115
15149
|
case 'post':
|
|
15116
15150
|
return `${path}/post/+`;
|
|
@@ -15122,8 +15156,8 @@ const getCommunityUserTopic = ({ path }, level) => {
|
|
|
15122
15156
|
return path;
|
|
15123
15157
|
}
|
|
15124
15158
|
};
|
|
15125
|
-
const getCommunityTopic = ({ path }, level = exports.SubscriptionLevels.COMMUNITY) => getCommunityUserTopic(
|
|
15126
|
-
const getUserTopic = ({ path }, level = exports.SubscriptionLevels.USER) => getCommunityUserTopic(
|
|
15159
|
+
const getCommunityTopic = ({ path }, level = exports.SubscriptionLevels.COMMUNITY) => getCommunityUserTopic(path, level);
|
|
15160
|
+
const getUserTopic = ({ path }, level = exports.SubscriptionLevels.USER) => getCommunityUserTopic(level === exports.SubscriptionLevels.USER ? path : path.replace(/^(\w*)/, '$1/social'), level);
|
|
15127
15161
|
const getPostTopic = ({ path }, level = exports.SubscriptionLevels.POST) => {
|
|
15128
15162
|
switch (level) {
|
|
15129
15163
|
case 'comment':
|
|
@@ -15135,13 +15169,24 @@ const getPostTopic = ({ path }, level = exports.SubscriptionLevels.POST) => {
|
|
|
15135
15169
|
const getCommentTopic = ({ path }) => {
|
|
15136
15170
|
return path;
|
|
15137
15171
|
};
|
|
15172
|
+
const getMyFollowersTopic = () => {
|
|
15173
|
+
const user = getActiveUser();
|
|
15174
|
+
const [networkId] = user.path.split('/user/');
|
|
15175
|
+
return `${networkId}/membership/${user._id}/+/+`;
|
|
15176
|
+
};
|
|
15177
|
+
const getMyFollowingsTopic = () => {
|
|
15178
|
+
const user = getActiveUser();
|
|
15179
|
+
const [networkId] = user.path.split('/user/');
|
|
15180
|
+
return `${networkId}/membership/+/${user._id}/+`;
|
|
15181
|
+
};
|
|
15138
15182
|
let mqttAccessToken;
|
|
15139
15183
|
let mqttUserId;
|
|
15140
15184
|
function subscribeTopic(topic, callback) {
|
|
15141
|
-
const { mqtt, emitter, accessToken
|
|
15142
|
-
|
|
15185
|
+
const { mqtt, emitter, accessToken } = getActiveClient();
|
|
15186
|
+
const user = getActiveUser();
|
|
15187
|
+
if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
|
|
15143
15188
|
mqttAccessToken = accessToken;
|
|
15144
|
-
mqttUserId =
|
|
15189
|
+
mqttUserId = user._id;
|
|
15145
15190
|
mqtt.connect({ accessToken: mqttAccessToken, userId: mqttUserId });
|
|
15146
15191
|
proxyMqttEvents(mqtt, emitter);
|
|
15147
15192
|
}
|
|
@@ -15224,12 +15269,15 @@ const restoreCache = async (storageKey = 'amitySdk') => {
|
|
|
15224
15269
|
try {
|
|
15225
15270
|
cache = JSON.parse(serializedData);
|
|
15226
15271
|
}
|
|
15227
|
-
catch (err) {
|
|
15272
|
+
catch (err) {
|
|
15273
|
+
//
|
|
15274
|
+
}
|
|
15228
15275
|
// current cache should override. in case there's something fresher.
|
|
15229
15276
|
client.cache.data = Object.assign(Object.assign({}, cache), client.cache.data);
|
|
15230
15277
|
return true;
|
|
15231
15278
|
};
|
|
15232
15279
|
|
|
15280
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
15233
15281
|
/**
|
|
15234
15282
|
* ```js
|
|
15235
15283
|
* import { backupCache } from '@amityco/ts-sdk'
|
|
@@ -15259,8 +15307,7 @@ const backupCache = async (storageKey = 'amitySdk', persistIf = (entry) => entry
|
|
|
15259
15307
|
log('cache/api/backupCache', { storageKey });
|
|
15260
15308
|
// prepare a subset of the cache where only
|
|
15261
15309
|
// objects to backup are there
|
|
15262
|
-
const offlineEntries = Object.fromEntries(Object.entries(cache.data)
|
|
15263
|
-
.filter(([_, entry]) => persistIf(entry)));
|
|
15310
|
+
const offlineEntries = Object.fromEntries(Object.entries(cache.data).filter(([_, entry]) => persistIf(entry)));
|
|
15264
15311
|
// nothing to backup, abort
|
|
15265
15312
|
if (!Object.keys(offlineEntries).length)
|
|
15266
15313
|
return false;
|
|
@@ -15306,9 +15353,9 @@ const wipeCache = async (storageKey = 'amitySdk') => {
|
|
|
15306
15353
|
* @category Cache
|
|
15307
15354
|
* @hidden
|
|
15308
15355
|
*/
|
|
15309
|
-
const normalize = (source) =>
|
|
15356
|
+
const normalize = (source) => Object.keys(source)
|
|
15310
15357
|
.sort()
|
|
15311
|
-
.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: source[key] })), {})
|
|
15358
|
+
.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: source[key] })), {});
|
|
15312
15359
|
/**
|
|
15313
15360
|
* Encodes a given {@link Amity.CacheKey} to a plain string
|
|
15314
15361
|
*
|
|
@@ -15318,7 +15365,7 @@ const normalize = (source) => (Object.keys(source)
|
|
|
15318
15365
|
* @category Cache
|
|
15319
15366
|
* @hidden
|
|
15320
15367
|
*/
|
|
15321
|
-
const encodeKey = (key) =>
|
|
15368
|
+
const encodeKey = (key) => JSON.stringify(key, (_, val) => (typeof val === 'object' ? normalize(val) : val));
|
|
15322
15369
|
/**
|
|
15323
15370
|
* Decodes a string back into a {@link Amity.CacheKey}
|
|
15324
15371
|
|
|
@@ -15343,14 +15390,14 @@ const partialMatch = (predicate, candidate) => {
|
|
|
15343
15390
|
if (predicate === candidate)
|
|
15344
15391
|
return true;
|
|
15345
15392
|
// if one or the other is nullish, there can't be equality
|
|
15346
|
-
|
|
15393
|
+
if (!predicate || !candidate)
|
|
15347
15394
|
return false;
|
|
15348
15395
|
// we only perform recursive check on objects
|
|
15349
|
-
|
|
15396
|
+
if (typeof predicate !== 'object') {
|
|
15350
15397
|
return false;
|
|
15351
15398
|
}
|
|
15352
15399
|
// recursively call for partial match based on the predicate
|
|
15353
|
-
return Object.keys(predicate).every(
|
|
15400
|
+
return Object.keys(predicate).every(key => partialMatch(predicate[key], candidate[key]));
|
|
15354
15401
|
};
|
|
15355
15402
|
|
|
15356
15403
|
/**
|
|
@@ -15373,8 +15420,7 @@ const queryCache = (key) => {
|
|
|
15373
15420
|
if (!cache)
|
|
15374
15421
|
return;
|
|
15375
15422
|
log('cache/api/queryCache', { key });
|
|
15376
|
-
return Object
|
|
15377
|
-
.keys(cache.data)
|
|
15423
|
+
return Object.keys(cache.data)
|
|
15378
15424
|
.filter(stringKey => {
|
|
15379
15425
|
const decodedKey = decodeKey(stringKey);
|
|
15380
15426
|
return partialMatch(key, decodedKey);
|
|
@@ -15403,9 +15449,7 @@ const pullFromCache = (key) => {
|
|
|
15403
15449
|
return;
|
|
15404
15450
|
log('cache/api/pullFromCache', key);
|
|
15405
15451
|
const str = encodeKey(key);
|
|
15406
|
-
return
|
|
15407
|
-
? cache.data[str]
|
|
15408
|
-
: undefined;
|
|
15452
|
+
return cache.data[str] ? cache.data[str] : undefined;
|
|
15409
15453
|
};
|
|
15410
15454
|
|
|
15411
15455
|
/**
|
|
@@ -15431,8 +15475,10 @@ const pushToCache = (key, data, options = { cachedAt: Date.now() }) => {
|
|
|
15431
15475
|
// if consumer did not pass offline but a offline policy is
|
|
15432
15476
|
// defined, use the fn to determine if the object needs to
|
|
15433
15477
|
// be saved in persistent storage or not.
|
|
15434
|
-
if (!(options === null || options === void 0 ? void 0 : options.hasOwnProperty('offline')) && cache.persistIf)
|
|
15478
|
+
if (!(options === null || options === void 0 ? void 0 : options.hasOwnProperty('offline')) && cache.persistIf) {
|
|
15479
|
+
// eslint-disable-next-line no-param-reassign
|
|
15435
15480
|
options.offline = cache.persistIf(key, data);
|
|
15481
|
+
}
|
|
15436
15482
|
const encodedKey = encodeKey(key);
|
|
15437
15483
|
cache.data[encodedKey] = Object.assign({ key, data }, options);
|
|
15438
15484
|
return true;
|
|
@@ -15464,9 +15510,7 @@ const mergeInCache = (key, mutation, options) => {
|
|
|
15464
15510
|
const oldVal = pullFromCache(key);
|
|
15465
15511
|
if (!oldVal)
|
|
15466
15512
|
return false;
|
|
15467
|
-
const newVal = typeof mutation === 'function'
|
|
15468
|
-
? mutation(oldVal.data)
|
|
15469
|
-
: Object.assign(Object.assign({}, oldVal.data), mutation);
|
|
15513
|
+
const newVal = typeof mutation === 'function' ? mutation(oldVal.data) : Object.assign(Object.assign({}, oldVal.data), mutation);
|
|
15470
15514
|
pushToCache(key, newVal, options);
|
|
15471
15515
|
return true;
|
|
15472
15516
|
};
|
|
@@ -15494,9 +15538,7 @@ const upsertInCache = (key, data, options = { cachedAt: Date.now() }) => {
|
|
|
15494
15538
|
return false;
|
|
15495
15539
|
log('cache/api/upsertInCache', { key, data, options });
|
|
15496
15540
|
const cached = pullFromCache(key);
|
|
15497
|
-
return cached
|
|
15498
|
-
? mergeInCache(key, data, options)
|
|
15499
|
-
: pushToCache(key, data, options);
|
|
15541
|
+
return cached ? mergeInCache(key, data, options) : pushToCache(key, data, options);
|
|
15500
15542
|
};
|
|
15501
15543
|
|
|
15502
15544
|
/**
|
|
@@ -15520,7 +15562,7 @@ const dropFromCache = (key, exact = false) => {
|
|
|
15520
15562
|
return false;
|
|
15521
15563
|
log('cache/api/dropFromCache', { key, exact });
|
|
15522
15564
|
if (!exact) {
|
|
15523
|
-
return
|
|
15565
|
+
return Object.keys(cache.data)
|
|
15524
15566
|
.map(stringKey => decodeKey(stringKey))
|
|
15525
15567
|
.filter(candidate => partialMatch(key, candidate))
|
|
15526
15568
|
.map(filteredKey => dropFromCache(filteredKey, true))
|
|
@@ -15543,10 +15585,14 @@ const idResolvers = {
|
|
|
15543
15585
|
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
15544
15586
|
message: ({ messageId }) => messageId,
|
|
15545
15587
|
community: ({ communityId }) => communityId,
|
|
15588
|
+
category: ({ categoryId }) => categoryId,
|
|
15546
15589
|
communityUsers: ({ communityId, userId }) => `${communityId}#${userId}`,
|
|
15547
15590
|
post: ({ postId }) => postId,
|
|
15548
15591
|
comment: ({ commentId }) => commentId,
|
|
15592
|
+
poll: ({ pollId }) => pollId,
|
|
15549
15593
|
stream: ({ streamId }) => streamId,
|
|
15594
|
+
follow: ({ from, to }) => `${from}#${to}`,
|
|
15595
|
+
followCount: ({ userId }) => userId,
|
|
15550
15596
|
};
|
|
15551
15597
|
/**
|
|
15552
15598
|
* Retrieve the id resolver matching a domain name
|
|
@@ -15554,7 +15600,7 @@ const idResolvers = {
|
|
|
15554
15600
|
* @param name the domain name for the resolve
|
|
15555
15601
|
* @returns an idResolver function for the given domain name
|
|
15556
15602
|
*/
|
|
15557
|
-
const getResolver = (name) =>
|
|
15603
|
+
const getResolver = (name) => idResolvers[name];
|
|
15558
15604
|
|
|
15559
15605
|
/**
|
|
15560
15606
|
* A map of v3 response keys to a store name.
|
|
@@ -15568,11 +15614,15 @@ const PAYLOAD2MODEL = {
|
|
|
15568
15614
|
channelUsers: 'channelUsers',
|
|
15569
15615
|
messages: 'message',
|
|
15570
15616
|
communities: 'community',
|
|
15617
|
+
categories: 'category',
|
|
15571
15618
|
communityUsers: 'communityUsers',
|
|
15572
15619
|
posts: 'post',
|
|
15573
15620
|
postChildren: 'post',
|
|
15574
15621
|
comments: 'comment',
|
|
15622
|
+
polls: 'poll',
|
|
15575
15623
|
videoStreamings: 'stream',
|
|
15624
|
+
follows: 'follow',
|
|
15625
|
+
followCounts: 'followCount',
|
|
15576
15626
|
};
|
|
15577
15627
|
|
|
15578
15628
|
/**
|
|
@@ -15585,8 +15635,7 @@ const PAYLOAD2MODEL = {
|
|
|
15585
15635
|
* @hidden
|
|
15586
15636
|
*/
|
|
15587
15637
|
const ingestInCache = (payload = {}, options) => {
|
|
15588
|
-
Object.entries(payload)
|
|
15589
|
-
.forEach(([key, models]) => {
|
|
15638
|
+
Object.entries(payload).forEach(([key, models]) => {
|
|
15590
15639
|
const type = PAYLOAD2MODEL[key];
|
|
15591
15640
|
if (!type)
|
|
15592
15641
|
return;
|
|
@@ -15666,13 +15715,15 @@ const getUsers = async (userIds) => {
|
|
|
15666
15715
|
client.log('user/getUsers', userIds);
|
|
15667
15716
|
const encodedUserIds = userIds.map(userId => encodeURIComponent(userId));
|
|
15668
15717
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
15669
|
-
const { data } = await client.http.get(`/api/v3/users/list`, {
|
|
15718
|
+
const { data } = await client.http.get(`/api/v3/users/list`, {
|
|
15719
|
+
params: { userIds: encodedUserIds },
|
|
15720
|
+
});
|
|
15670
15721
|
const cachedAt = client.cache && Date.now();
|
|
15671
15722
|
if (client.cache)
|
|
15672
15723
|
ingestInCache(data, { cachedAt });
|
|
15673
15724
|
return {
|
|
15674
15725
|
data: data.users,
|
|
15675
|
-
cachedAt
|
|
15726
|
+
cachedAt,
|
|
15676
15727
|
};
|
|
15677
15728
|
};
|
|
15678
15729
|
/**
|
|
@@ -15698,7 +15749,7 @@ getUsers.locally = (userIds) => {
|
|
|
15698
15749
|
.map(userId => pullFromCache(['user', 'get', userId]))
|
|
15699
15750
|
.filter(Boolean);
|
|
15700
15751
|
const users = cached.map(({ data }) => data);
|
|
15701
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
15752
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
15702
15753
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < userIds.length)
|
|
15703
15754
|
return;
|
|
15704
15755
|
return {
|
|
@@ -15752,14 +15803,14 @@ function __rest(s, e) {
|
|
|
15752
15803
|
const queryUsers = async (query = {}) => {
|
|
15753
15804
|
const client = getActiveClient();
|
|
15754
15805
|
client.log('user/queryUsers', query);
|
|
15755
|
-
const { page, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query
|
|
15756
|
-
// API-FIX: parameters should be querystring.
|
|
15757
|
-
, ["page", "displayName", "filter", "sortBy"]);
|
|
15806
|
+
const { page, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query, ["page", "displayName", "filter", "sortBy"]);
|
|
15758
15807
|
// API-FIX: parameters should be querystring.
|
|
15759
|
-
const { data } = await client.http.get(`/api/v3/users`, {
|
|
15808
|
+
const { data } = await client.http.get(`/api/v3/users`, {
|
|
15809
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter,
|
|
15760
15810
|
sortBy, options: {
|
|
15761
15811
|
token: toToken(page, 'skiplimit'),
|
|
15762
|
-
} })
|
|
15812
|
+
} }),
|
|
15813
|
+
});
|
|
15763
15814
|
// unpacking
|
|
15764
15815
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
15765
15816
|
const { users } = payload;
|
|
@@ -15965,7 +16016,7 @@ const observeUser = (userId, callback) => {
|
|
|
15965
16016
|
*
|
|
15966
16017
|
* Fetches a {@link Amity.File} object
|
|
15967
16018
|
*
|
|
15968
|
-
* @param
|
|
16019
|
+
* @param fileId the ID of the {@link Amity.File} to fetch
|
|
15969
16020
|
* @returns the associated {@link Amity.File} object
|
|
15970
16021
|
*
|
|
15971
16022
|
* @category File API
|
|
@@ -16021,6 +16072,7 @@ getFile.locally = (fileId) => {
|
|
|
16021
16072
|
* Creates an {@link Amity.File}
|
|
16022
16073
|
*
|
|
16023
16074
|
* @param formData The data necessary to create a new {@link Amity.File}
|
|
16075
|
+
* @param onProgress The callback to track the upload progress
|
|
16024
16076
|
* @returns The newly created {@link Amity.File}
|
|
16025
16077
|
*
|
|
16026
16078
|
* @category File API
|
|
@@ -16029,15 +16081,16 @@ getFile.locally = (fileId) => {
|
|
|
16029
16081
|
const createFile = async (formData, onProgress) => {
|
|
16030
16082
|
const client = getActiveClient();
|
|
16031
16083
|
client.log('file/createFile', formData);
|
|
16032
|
-
if (!formData.getAll('
|
|
16033
|
-
throw new Error('The formData object must have a `
|
|
16084
|
+
if (!formData.getAll('files').length)
|
|
16085
|
+
throw new Error('The formData object must have a `files` key.');
|
|
16034
16086
|
const headers = 'getHeaders' in formData
|
|
16035
16087
|
? formData.getHeaders()
|
|
16036
16088
|
: { 'content-type': 'multipart/form-data' };
|
|
16037
|
-
const { data } = await client.http.post('/api/
|
|
16038
|
-
headers,
|
|
16089
|
+
const { data } = await client.http.post('/api/v4/files', formData, {
|
|
16090
|
+
headers,
|
|
16091
|
+
onUploadProgress({ loaded, total }) {
|
|
16039
16092
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
16040
|
-
}
|
|
16093
|
+
},
|
|
16041
16094
|
});
|
|
16042
16095
|
// API-FIX: payload should be serialized properly
|
|
16043
16096
|
// const { files } = data
|
|
@@ -16045,7 +16098,7 @@ const createFile = async (formData, onProgress) => {
|
|
|
16045
16098
|
if (client.cache)
|
|
16046
16099
|
ingestInCache({ files: data }, { cachedAt });
|
|
16047
16100
|
return {
|
|
16048
|
-
data
|
|
16101
|
+
data,
|
|
16049
16102
|
cachedAt,
|
|
16050
16103
|
};
|
|
16051
16104
|
};
|
|
@@ -16085,6 +16138,47 @@ const fileUrlWithSize = (fileUrl, size) => {
|
|
|
16085
16138
|
return `${fileUrl}?size=${size}`;
|
|
16086
16139
|
};
|
|
16087
16140
|
|
|
16141
|
+
/**
|
|
16142
|
+
* ```js
|
|
16143
|
+
* import { createVideo } from '@amityco/ts-sdk'
|
|
16144
|
+
* const created = await createVideo(formData)
|
|
16145
|
+
* ```
|
|
16146
|
+
*
|
|
16147
|
+
* Creates an {@link Amity.File<'video'>}
|
|
16148
|
+
*
|
|
16149
|
+
* @param formData The data necessary to create a new {@link Amity.File<'video'>}
|
|
16150
|
+
* @param onProgress The callback to track the upload progress
|
|
16151
|
+
* @returns The newly created {@link Amity.File<'video'>}
|
|
16152
|
+
*
|
|
16153
|
+
* @category File API
|
|
16154
|
+
* @async
|
|
16155
|
+
*/
|
|
16156
|
+
const createVideo = async (formData, onProgress) => {
|
|
16157
|
+
const client = getActiveClient();
|
|
16158
|
+
client.log('file/createVideo', formData);
|
|
16159
|
+
if (!formData.getAll('files').length)
|
|
16160
|
+
throw new Error('The formData object must have a `files` key.');
|
|
16161
|
+
const headers = 'getHeaders' in formData
|
|
16162
|
+
? formData.getHeaders()
|
|
16163
|
+
: { 'content-type': 'multipart/form-data' };
|
|
16164
|
+
const { data } = await client.http.post('/api/v4/videos', formData, {
|
|
16165
|
+
headers,
|
|
16166
|
+
onUploadProgress({ loaded, total }) {
|
|
16167
|
+
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
16168
|
+
},
|
|
16169
|
+
});
|
|
16170
|
+
// API-FIX: payload should be serialized properly
|
|
16171
|
+
// const { files } = data
|
|
16172
|
+
const cachedAt = client.cache && Date.now();
|
|
16173
|
+
if (client.cache)
|
|
16174
|
+
ingestInCache({ files: data }, { cachedAt });
|
|
16175
|
+
return {
|
|
16176
|
+
data,
|
|
16177
|
+
cachedAt,
|
|
16178
|
+
};
|
|
16179
|
+
};
|
|
16180
|
+
// TODO: consider doing local creation with URL.createObjectURL()
|
|
16181
|
+
|
|
16088
16182
|
/**
|
|
16089
16183
|
* ```js
|
|
16090
16184
|
* import { observeFile } from '@amityco/ts-sdk'
|
|
@@ -16316,13 +16410,15 @@ const getMessages = async (messageIds) => {
|
|
|
16316
16410
|
const client = getActiveClient();
|
|
16317
16411
|
client.log('message/getMessages', messageIds);
|
|
16318
16412
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
16319
|
-
const { data } = await client.http.get(`/api/v3/messages/list`, {
|
|
16413
|
+
const { data } = await client.http.get(`/api/v3/messages/list`, {
|
|
16414
|
+
params: { messageIds },
|
|
16415
|
+
});
|
|
16320
16416
|
const cachedAt = client.cache && Date.now();
|
|
16321
16417
|
if (client.cache)
|
|
16322
16418
|
ingestInCache(data, { cachedAt });
|
|
16323
16419
|
return {
|
|
16324
16420
|
data: data.messages,
|
|
16325
|
-
cachedAt
|
|
16421
|
+
cachedAt,
|
|
16326
16422
|
};
|
|
16327
16423
|
};
|
|
16328
16424
|
/**
|
|
@@ -16348,7 +16444,7 @@ getMessages.locally = (messageIds) => {
|
|
|
16348
16444
|
.map(messageId => pullFromCache(['message', 'get', messageId]))
|
|
16349
16445
|
.filter(Boolean);
|
|
16350
16446
|
const messages = cached.map(({ data }) => data);
|
|
16351
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
16447
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
16352
16448
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < messageIds.length)
|
|
16353
16449
|
return;
|
|
16354
16450
|
return {
|
|
@@ -16374,19 +16470,16 @@ getMessages.locally = (messageIds) => {
|
|
|
16374
16470
|
const queryMessages = async (query) => {
|
|
16375
16471
|
const client = getActiveClient();
|
|
16376
16472
|
client.log('message/queryMessages', query);
|
|
16377
|
-
const { page = { limit: 10 } } = query, params = __rest(query
|
|
16378
|
-
// API-FIX: parameters should be querystring. (1)
|
|
16379
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
16380
|
-
// API-FIX: pagination should not be indexed on channelSegment (3)
|
|
16381
|
-
// const { data } = await client.http.get<Amity.Response<Amity.Paged<Amity.MessagePayload>>>(
|
|
16382
|
-
, ["page"]);
|
|
16473
|
+
const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
|
|
16383
16474
|
// API-FIX: parameters should be querystring. (1)
|
|
16384
16475
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16385
16476
|
// API-FIX: pagination should not be indexed on channelSegment (3)
|
|
16386
16477
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<Amity.MessagePayload>>>(
|
|
16387
|
-
const { data } = await client.http.get(`/api/v3/messages`, {
|
|
16478
|
+
const { data } = await client.http.get(`/api/v3/messages`, {
|
|
16479
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
16388
16480
|
token: toToken(page, 'afterbefore'),
|
|
16389
|
-
} }),
|
|
16481
|
+
} }),
|
|
16482
|
+
});
|
|
16390
16483
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16391
16484
|
// const { paging, messages } = unwrapPayload(data)
|
|
16392
16485
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
@@ -16394,7 +16487,11 @@ const queryMessages = async (query) => {
|
|
|
16394
16487
|
const cachedAt = client.cache && Date.now();
|
|
16395
16488
|
if (client.cache) {
|
|
16396
16489
|
ingestInCache(payload, { cachedAt });
|
|
16397
|
-
const cacheKey = [
|
|
16490
|
+
const cacheKey = [
|
|
16491
|
+
'message',
|
|
16492
|
+
'query',
|
|
16493
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
16494
|
+
];
|
|
16398
16495
|
pushToCache(cacheKey, { messages: messages.map(getResolver('message')), paging });
|
|
16399
16496
|
}
|
|
16400
16497
|
const nextPage = toPage(paging.next);
|
|
@@ -16496,7 +16593,7 @@ createMessage.optimistically = (bundle) => {
|
|
|
16496
16593
|
fireEvent('v3.message.didCreate', { messages: [message] });
|
|
16497
16594
|
return {
|
|
16498
16595
|
data: message,
|
|
16499
|
-
cachedAt: -1
|
|
16596
|
+
cachedAt: -1,
|
|
16500
16597
|
};
|
|
16501
16598
|
};
|
|
16502
16599
|
|
|
@@ -16560,7 +16657,7 @@ updateMessage.optimistically = (messageId, patch) => {
|
|
|
16560
16657
|
fireEvent('v3.message.didUpdate', { messages: [updated] });
|
|
16561
16658
|
return {
|
|
16562
16659
|
data: updated,
|
|
16563
|
-
cachedAt
|
|
16660
|
+
cachedAt,
|
|
16564
16661
|
};
|
|
16565
16662
|
};
|
|
16566
16663
|
|
|
@@ -16612,7 +16709,7 @@ deleteMessage.optimistically = (messageId) => {
|
|
|
16612
16709
|
fireEvent('v3.message.didDelete', { messages: [deleted] });
|
|
16613
16710
|
return {
|
|
16614
16711
|
data: deleted,
|
|
16615
|
-
cachedAt
|
|
16712
|
+
cachedAt,
|
|
16616
16713
|
};
|
|
16617
16714
|
};
|
|
16618
16715
|
|
|
@@ -16633,17 +16730,15 @@ deleteMessage.optimistically = (messageId) => {
|
|
|
16633
16730
|
const queryPosts = async (query) => {
|
|
16634
16731
|
const client = getActiveClient();
|
|
16635
16732
|
client.log('post/queryPosts', query);
|
|
16636
|
-
const { page = { limit: 10 } } = query, params = __rest(query
|
|
16637
|
-
// API-FIX: parameters should be querystring. (1)
|
|
16638
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
16639
|
-
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16640
|
-
, ["page"]);
|
|
16733
|
+
const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
|
|
16641
16734
|
// API-FIX: parameters should be querystring. (1)
|
|
16642
16735
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16643
16736
|
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16644
|
-
const { data } = await client.http.get(`/api/v4/posts`, {
|
|
16737
|
+
const { data } = await client.http.get(`/api/v4/posts`, {
|
|
16738
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
16645
16739
|
token: toToken(page, 'afterbeforeraw'),
|
|
16646
|
-
} }),
|
|
16740
|
+
} }),
|
|
16741
|
+
});
|
|
16647
16742
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16648
16743
|
// const { paging, posts } = unwrapPayload(data)
|
|
16649
16744
|
// unpacking
|
|
@@ -16713,13 +16808,15 @@ const getPosts = async (postIds) => {
|
|
|
16713
16808
|
client.log('post/getPosts', postIds);
|
|
16714
16809
|
const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
|
|
16715
16810
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
16716
|
-
const { data } = await client.http.get(`/api/v3/posts/list`, {
|
|
16811
|
+
const { data } = await client.http.get(`/api/v3/posts/list`, {
|
|
16812
|
+
params: { postIds: encodedPostIds },
|
|
16813
|
+
});
|
|
16717
16814
|
const cachedAt = client.cache && Date.now();
|
|
16718
16815
|
if (client.cache)
|
|
16719
16816
|
ingestInCache(data, { cachedAt });
|
|
16720
16817
|
return {
|
|
16721
16818
|
data: data.posts,
|
|
16722
|
-
cachedAt
|
|
16819
|
+
cachedAt,
|
|
16723
16820
|
};
|
|
16724
16821
|
};
|
|
16725
16822
|
/**
|
|
@@ -16745,7 +16842,7 @@ getPosts.locally = (postIds) => {
|
|
|
16745
16842
|
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
16746
16843
|
.filter(Boolean);
|
|
16747
16844
|
const posts = cached.map(({ data }) => data);
|
|
16748
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
16845
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
16749
16846
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
|
|
16750
16847
|
return;
|
|
16751
16848
|
return {
|
|
@@ -16796,7 +16893,7 @@ const getPost = async (postId) => {
|
|
|
16796
16893
|
/**
|
|
16797
16894
|
* ```js
|
|
16798
16895
|
* import { getPost } from '@amityco/ts-sdk'
|
|
16799
|
-
* const { data
|
|
16896
|
+
* const { data: post } = getPost.locally('foobar')
|
|
16800
16897
|
* ```
|
|
16801
16898
|
*
|
|
16802
16899
|
* Fetches a {@link Amity.Post} object from cache
|
|
@@ -16842,8 +16939,10 @@ const createPost = async (bundle) => {
|
|
|
16842
16939
|
const client = getActiveClient();
|
|
16843
16940
|
client.log('post/createPost', bundle);
|
|
16844
16941
|
// API-FIX: backend rejects that we pass the dataType manually T_T
|
|
16845
|
-
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType))
|
|
16942
|
+
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
|
|
16943
|
+
// eslint-disable-next-line no-param-reassign
|
|
16846
16944
|
delete bundle.dataType;
|
|
16945
|
+
}
|
|
16847
16946
|
const { data } = await client.http.post('/api/v4/posts', bundle);
|
|
16848
16947
|
const cachedAt = client.cache && Date.now();
|
|
16849
16948
|
if (client.cache)
|
|
@@ -16911,15 +17010,21 @@ const queryCommunities = async (query) => {
|
|
|
16911
17010
|
// API-FIX: parameters should be querystring.
|
|
16912
17011
|
// API-FIX: backend doesnt answer Amity.Response
|
|
16913
17012
|
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<CommunityPayload>>>(
|
|
16914
|
-
const { data } = await client.http.get(`/api/v3/communities`, {
|
|
16915
|
-
|
|
16916
|
-
|
|
17013
|
+
const { data } = await client.http.get(`/api/v3/communities`, {
|
|
17014
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
|
|
17015
|
+
token: toToken(page, 'skiplimit'),
|
|
17016
|
+
} }),
|
|
17017
|
+
});
|
|
16917
17018
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
16918
17019
|
const { communities } = payload;
|
|
16919
17020
|
const cachedAt = client.cache && Date.now();
|
|
16920
17021
|
if (client.cache) {
|
|
16921
17022
|
ingestInCache(payload, { cachedAt });
|
|
16922
|
-
const cacheKey = [
|
|
17023
|
+
const cacheKey = [
|
|
17024
|
+
'community',
|
|
17025
|
+
'query',
|
|
17026
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
17027
|
+
];
|
|
16923
17028
|
pushToCache(cacheKey, { communities: communities.map(getResolver('community')), paging });
|
|
16924
17029
|
}
|
|
16925
17030
|
const nextPage = toPage(paging.next);
|
|
@@ -16963,13 +17068,15 @@ const getCommunities = async (communityIds) => {
|
|
|
16963
17068
|
const client = getActiveClient();
|
|
16964
17069
|
client.log('community/getCommunities', communityIds);
|
|
16965
17070
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
16966
|
-
const { data } = await client.http.get(`/api/v3/communities/list`, {
|
|
17071
|
+
const { data } = await client.http.get(`/api/v3/communities/list`, {
|
|
17072
|
+
params: { communityIds },
|
|
17073
|
+
});
|
|
16967
17074
|
const cachedAt = client.cache && Date.now();
|
|
16968
17075
|
if (client.cache)
|
|
16969
17076
|
ingestInCache(data, { cachedAt });
|
|
16970
17077
|
return {
|
|
16971
17078
|
data: data.communities,
|
|
16972
|
-
cachedAt
|
|
17079
|
+
cachedAt,
|
|
16973
17080
|
};
|
|
16974
17081
|
};
|
|
16975
17082
|
/**
|
|
@@ -16995,7 +17102,7 @@ getCommunities.locally = (communityIds) => {
|
|
|
16995
17102
|
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
16996
17103
|
.filter(Boolean);
|
|
16997
17104
|
const communities = cached.map(({ data }) => data);
|
|
16998
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
17105
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
16999
17106
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < communityIds.length)
|
|
17000
17107
|
return;
|
|
17001
17108
|
return {
|
|
@@ -17165,8 +17272,7 @@ const joinCommunity = async (communityId) => {
|
|
|
17165
17272
|
ingestInCache(data, { cachedAt });
|
|
17166
17273
|
fireEvent('community.joined', data);
|
|
17167
17274
|
const { communityUsers } = data;
|
|
17168
|
-
return !!communityUsers.find(communityUser =>
|
|
17169
|
-
&& communityUser.communityMembership === 'member'));
|
|
17275
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
17170
17276
|
};
|
|
17171
17277
|
|
|
17172
17278
|
/**
|
|
@@ -17192,8 +17298,7 @@ const leaveCommunity = async (communityId) => {
|
|
|
17192
17298
|
ingestInCache(data, { cachedAt });
|
|
17193
17299
|
fireEvent('community.left', data);
|
|
17194
17300
|
const { communityUsers } = data;
|
|
17195
|
-
return !!communityUsers.find(communityUser =>
|
|
17196
|
-
&& communityUser.communityMembership !== 'member'));
|
|
17301
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
17197
17302
|
};
|
|
17198
17303
|
|
|
17199
17304
|
/**
|
|
@@ -17209,7 +17314,7 @@ const leaveCommunity = async (communityId) => {
|
|
|
17209
17314
|
*
|
|
17210
17315
|
* @category Community API
|
|
17211
17316
|
* @async
|
|
17212
|
-
|
|
17317
|
+
* */
|
|
17213
17318
|
const queryCommunityMembers = async (query) => {
|
|
17214
17319
|
const client = getActiveClient();
|
|
17215
17320
|
client.log('community/queryCommunityMembers', query);
|
|
@@ -17271,8 +17376,7 @@ const addCommunityMembers = async (communityId, userIds) => {
|
|
|
17271
17376
|
ingestInCache(data);
|
|
17272
17377
|
fireEvent('community.userAdded', data);
|
|
17273
17378
|
const { communityUsers } = data;
|
|
17274
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17275
|
-
communityUser.communityMembership === 'member');
|
|
17379
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
17276
17380
|
};
|
|
17277
17381
|
|
|
17278
17382
|
/**
|
|
@@ -17298,60 +17402,187 @@ const removeCommunityMembers = async (communityId, userIds) => {
|
|
|
17298
17402
|
ingestInCache(data);
|
|
17299
17403
|
fireEvent('community.userRemoved', data);
|
|
17300
17404
|
const { communityUsers } = data;
|
|
17301
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17302
|
-
communityUser.communityMembership !== 'member');
|
|
17405
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
17303
17406
|
};
|
|
17304
17407
|
|
|
17305
17408
|
/**
|
|
17306
17409
|
* ```js
|
|
17307
|
-
* import {
|
|
17308
|
-
* const updated = await
|
|
17410
|
+
* import { addCommunityMembersRoles } from '@amityco/ts-sdk'
|
|
17411
|
+
* const updated = await addCommunityMembersRoles(communityId, ['foo'], ['bar'])
|
|
17309
17412
|
* ```
|
|
17310
17413
|
*
|
|
17311
|
-
* Adds
|
|
17414
|
+
* Adds a list of {@link Amity.Role} to a list of {@link Amity.User} on a {@link Amity.Community}
|
|
17312
17415
|
*
|
|
17313
17416
|
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
17314
|
-
* @param
|
|
17417
|
+
* @param roleIds Array of IDs of the {@link Amity.Role} to apply
|
|
17315
17418
|
* @param userId Array of IDs of the {@link Amity.User} to perform
|
|
17316
17419
|
* @returns A success boolean if the {@link Amity.Role} were added to list of {@link Amity.User} in the {@link Amity.Community}
|
|
17317
17420
|
*
|
|
17318
17421
|
* @category Community API
|
|
17319
17422
|
* @async
|
|
17320
17423
|
*/
|
|
17321
|
-
const
|
|
17424
|
+
const addCommunityMembersRoles = async (communityId, roleIds, userIds) => {
|
|
17322
17425
|
const client = getActiveClient();
|
|
17323
|
-
client.log('community/
|
|
17324
|
-
const { data } = await client.http.post(`/api/
|
|
17426
|
+
client.log('community/addCommunityMembersRoles', communityId, roleIds, userIds);
|
|
17427
|
+
const { data } = await client.http.post(`/api/v4/communities/${communityId}/users/roles`, { communityId, roles: roleIds, userIds });
|
|
17325
17428
|
if (client.cache)
|
|
17326
17429
|
ingestInCache(data);
|
|
17327
17430
|
const { communityUsers } = data;
|
|
17328
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17431
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17432
|
+
roleIds.some(role => communityUser.roles.includes(role)));
|
|
17329
17433
|
};
|
|
17330
17434
|
|
|
17331
17435
|
/**
|
|
17332
17436
|
* ```js
|
|
17333
|
-
* import {
|
|
17334
|
-
* const updated = await
|
|
17437
|
+
* import { removeCommunityMembersRoles } from '@amityco/ts-sdk'
|
|
17438
|
+
* const updated = await removeCommunityMembersRoles(communityId, ['foo'], ['bar'])
|
|
17335
17439
|
* ```
|
|
17336
17440
|
*
|
|
17337
|
-
* Removes
|
|
17441
|
+
* Removes a list of {@link Amity.Role} from a list of {@link Amity.User} on a {@link Amity.Community}
|
|
17338
17442
|
*
|
|
17339
17443
|
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
17340
|
-
* @param
|
|
17444
|
+
* @param roleIds Array of IDs of the {@link Amity.Role} to apply
|
|
17341
17445
|
* @param userId Array of IDs of the {@link Amity.User} to perform
|
|
17342
17446
|
* @returns A success boolean if the {@link Amity.Role} were removed from list of {@link Amity.User} in the {@link Amity.Community}
|
|
17343
17447
|
*
|
|
17344
17448
|
* @category Community API
|
|
17345
17449
|
* @async
|
|
17346
17450
|
*/
|
|
17347
|
-
const
|
|
17451
|
+
const removeCommunityMembersRoles = async (communityId, roleIds, userIds) => {
|
|
17348
17452
|
const client = getActiveClient();
|
|
17349
|
-
client.log('community/
|
|
17350
|
-
const { data } = await client.http.delete(`/api/
|
|
17453
|
+
client.log('community/removeCommunityMembersRoles', communityId, roleIds, userIds);
|
|
17454
|
+
const { data } = await client.http.delete(`/api/v4/communities/${communityId}/users/roles`, { data: { communityId, roles: roleIds, userIds } });
|
|
17351
17455
|
if (client.cache)
|
|
17352
17456
|
ingestInCache(data);
|
|
17353
17457
|
const { communityUsers } = data;
|
|
17354
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17458
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17459
|
+
!roleIds.some(role => communityUser.roles.includes(role)));
|
|
17460
|
+
};
|
|
17461
|
+
|
|
17462
|
+
/**
|
|
17463
|
+
* ```js
|
|
17464
|
+
* import { getTopTrendingCommunities } from '@amityco/ts-sdk'
|
|
17465
|
+
* const trendingCommunities = await getTopTrendingCommunities()
|
|
17466
|
+
* ```
|
|
17467
|
+
*
|
|
17468
|
+
* Gets a list of top trending {@link Amity.Community} objects
|
|
17469
|
+
*
|
|
17470
|
+
* @param query The query parameters
|
|
17471
|
+
* @returns A list of {@link Amity.Community} objects
|
|
17472
|
+
*
|
|
17473
|
+
* @category Community API
|
|
17474
|
+
* @async
|
|
17475
|
+
*/
|
|
17476
|
+
const getTopTrendingCommunities = async (query) => {
|
|
17477
|
+
const client = getActiveClient();
|
|
17478
|
+
client.log('channel/getTopTrendingCommunities', query);
|
|
17479
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17480
|
+
// API-FIX: backend doesnt answer Amity.Response
|
|
17481
|
+
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
17482
|
+
const { data } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
17483
|
+
const { communities } = data;
|
|
17484
|
+
const cachedAt = client.cache && Date.now();
|
|
17485
|
+
if (client.cache) {
|
|
17486
|
+
ingestInCache(data, { cachedAt });
|
|
17487
|
+
const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
17488
|
+
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
17489
|
+
}
|
|
17490
|
+
return { data: communities, cachedAt };
|
|
17491
|
+
};
|
|
17492
|
+
/**
|
|
17493
|
+
* ```js
|
|
17494
|
+
* import { getTopTrendingCommunities } from '@amityco/ts-sdk'
|
|
17495
|
+
* const communities = getTopTrendingCommunities.locally()
|
|
17496
|
+
* ```
|
|
17497
|
+
*
|
|
17498
|
+
* Gets a list of top trending {@link Amity.Community} objects from cache
|
|
17499
|
+
*
|
|
17500
|
+
* @param query The query parameters
|
|
17501
|
+
* @returns communities
|
|
17502
|
+
*
|
|
17503
|
+
* @category Community API
|
|
17504
|
+
*/
|
|
17505
|
+
getTopTrendingCommunities.locally = (query) => {
|
|
17506
|
+
var _a, _b;
|
|
17507
|
+
const client = getActiveClient();
|
|
17508
|
+
client.log('community/getTopTrendingCommunities.locally', query);
|
|
17509
|
+
if (!client.cache)
|
|
17510
|
+
return;
|
|
17511
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17512
|
+
const queryKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
17513
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
17514
|
+
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
17515
|
+
return;
|
|
17516
|
+
const communities = data.communities
|
|
17517
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
17518
|
+
.filter(Boolean)
|
|
17519
|
+
.map(({ data }) => data);
|
|
17520
|
+
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
17521
|
+
? { data: communities, cachedAt }
|
|
17522
|
+
: undefined;
|
|
17523
|
+
};
|
|
17524
|
+
|
|
17525
|
+
/**
|
|
17526
|
+
* ```js
|
|
17527
|
+
* import { getRecommendedCommunities } from '@amityco/ts-sdk'
|
|
17528
|
+
* const communities = await getRecommendedCommunities()
|
|
17529
|
+
* ```
|
|
17530
|
+
*
|
|
17531
|
+
* Gets a list of recommended {@link Amity.Community} objects
|
|
17532
|
+
*
|
|
17533
|
+
* @param query The query parameters
|
|
17534
|
+
* @returns A list of {@link Amity.Community} objects
|
|
17535
|
+
*
|
|
17536
|
+
* @category Community API
|
|
17537
|
+
* @async
|
|
17538
|
+
*/
|
|
17539
|
+
const getRecommendedCommunities = async (query) => {
|
|
17540
|
+
const client = getActiveClient();
|
|
17541
|
+
client.log('channel/getRecommendedCommunities', query);
|
|
17542
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17543
|
+
// API-FIX: backend doesnt answer Amity.Response
|
|
17544
|
+
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
17545
|
+
const { data } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
|
|
17546
|
+
const { communities } = data;
|
|
17547
|
+
const cachedAt = client.cache && Date.now();
|
|
17548
|
+
if (client.cache) {
|
|
17549
|
+
ingestInCache(data, { cachedAt });
|
|
17550
|
+
const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
17551
|
+
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
17552
|
+
}
|
|
17553
|
+
return { data: communities, cachedAt };
|
|
17554
|
+
};
|
|
17555
|
+
/**
|
|
17556
|
+
* ```js
|
|
17557
|
+
* import { getRecommendedCommunities } from '@amityco/ts-sdk'
|
|
17558
|
+
* const communities = getRecommendedCommunities.locally()
|
|
17559
|
+
* ```
|
|
17560
|
+
*
|
|
17561
|
+
* Gets a list of recommended {@link Amity.Community} objects from cache
|
|
17562
|
+
*
|
|
17563
|
+
* @param query The query parameters
|
|
17564
|
+
* @returns communities
|
|
17565
|
+
*
|
|
17566
|
+
* @category Community API
|
|
17567
|
+
*/
|
|
17568
|
+
getRecommendedCommunities.locally = (query) => {
|
|
17569
|
+
var _a, _b;
|
|
17570
|
+
const client = getActiveClient();
|
|
17571
|
+
client.log('community/getRecommendedCommunities.locally', query);
|
|
17572
|
+
if (!client.cache)
|
|
17573
|
+
return;
|
|
17574
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17575
|
+
const queryKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
17576
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
17577
|
+
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
17578
|
+
return;
|
|
17579
|
+
const communities = data.communities
|
|
17580
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
17581
|
+
.filter(Boolean)
|
|
17582
|
+
.map(({ data }) => data);
|
|
17583
|
+
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
17584
|
+
? { data: communities, cachedAt }
|
|
17585
|
+
: undefined;
|
|
17355
17586
|
};
|
|
17356
17587
|
|
|
17357
17588
|
/**
|
|
@@ -17371,7 +17602,7 @@ const removeCommunityMembersRole = async (communityId, roleId, userIds) => {
|
|
|
17371
17602
|
const deletePost = async (postId, permanent = false) => {
|
|
17372
17603
|
const client = getActiveClient();
|
|
17373
17604
|
client.log('post/deletePost', postId);
|
|
17374
|
-
|
|
17605
|
+
const post = await getPost(postId);
|
|
17375
17606
|
// API-FIX: This endpoint has not been implemented yet.
|
|
17376
17607
|
await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
17377
17608
|
params: {
|
|
@@ -17418,12 +17649,7 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
17418
17649
|
const queryComments = async (query) => {
|
|
17419
17650
|
const client = getActiveClient();
|
|
17420
17651
|
client.log('comment/queryComments', query);
|
|
17421
|
-
const { page = { limit: 10 } } = query, params = __rest(query
|
|
17422
|
-
// const filterByParentId = query.parentId !== undefined
|
|
17423
|
-
// API-FIX: parameters should be querystring. (1)
|
|
17424
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
17425
|
-
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.CommentPayload>>>(
|
|
17426
|
-
, ["page"]);
|
|
17652
|
+
const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
|
|
17427
17653
|
// const filterByParentId = query.parentId !== undefined
|
|
17428
17654
|
// API-FIX: parameters should be querystring. (1)
|
|
17429
17655
|
// API-FIX: backend should answer Amity.Response (2)
|
|
@@ -17442,7 +17668,11 @@ const queryComments = async (query) => {
|
|
|
17442
17668
|
const cachedAt = client.cache && Date.now();
|
|
17443
17669
|
if (client.cache) {
|
|
17444
17670
|
ingestInCache(payload, { cachedAt });
|
|
17445
|
-
const cacheKey = [
|
|
17671
|
+
const cacheKey = [
|
|
17672
|
+
'comment',
|
|
17673
|
+
'query',
|
|
17674
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
17675
|
+
];
|
|
17446
17676
|
pushToCache(cacheKey, { comments: comments.map(getResolver('comment')), paging });
|
|
17447
17677
|
}
|
|
17448
17678
|
const nextPage = toPage(paging.next);
|
|
@@ -17503,13 +17733,15 @@ const getComments = async (commentIds) => {
|
|
|
17503
17733
|
client.log('comment/getComments', commentIds);
|
|
17504
17734
|
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
17505
17735
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
17506
|
-
const { data } = await client.http.get(`/api/v3/comments/list`, {
|
|
17736
|
+
const { data } = await client.http.get(`/api/v3/comments/list`, {
|
|
17737
|
+
params: { commentIds: encodedCommentIds },
|
|
17738
|
+
});
|
|
17507
17739
|
const cachedAt = client.cache && Date.now();
|
|
17508
17740
|
if (client.cache)
|
|
17509
17741
|
ingestInCache(data, { cachedAt });
|
|
17510
17742
|
return {
|
|
17511
17743
|
data: data.comments,
|
|
17512
|
-
cachedAt
|
|
17744
|
+
cachedAt,
|
|
17513
17745
|
};
|
|
17514
17746
|
};
|
|
17515
17747
|
/**
|
|
@@ -17535,7 +17767,7 @@ getComments.locally = (commentIds) => {
|
|
|
17535
17767
|
.map(commentId => pullFromCache(['comment', 'get', commentId]))
|
|
17536
17768
|
.filter(Boolean);
|
|
17537
17769
|
const comments = cached.map(({ data }) => data);
|
|
17538
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
17770
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
17539
17771
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
|
|
17540
17772
|
return;
|
|
17541
17773
|
return {
|
|
@@ -17718,9 +17950,9 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
17718
17950
|
const fetchReference = async (referenceType, referenceId) => {
|
|
17719
17951
|
if (referenceType === 'message')
|
|
17720
17952
|
return getMessage(referenceId);
|
|
17721
|
-
|
|
17953
|
+
if (referenceType === 'post')
|
|
17722
17954
|
return getPost(referenceId);
|
|
17723
|
-
|
|
17955
|
+
if (referenceType === 'comment')
|
|
17724
17956
|
return getComment(referenceId);
|
|
17725
17957
|
throw new Error(`Incorrect referenceType: ${referenceType}`);
|
|
17726
17958
|
};
|
|
@@ -17757,7 +17989,9 @@ const preparePayloadForCache = (event, payload) => {
|
|
|
17757
17989
|
if (!cached.myReactions.includes(payload.reactor.reactionName)) {
|
|
17758
17990
|
return;
|
|
17759
17991
|
}
|
|
17760
|
-
Object.assign(model, {
|
|
17992
|
+
Object.assign(model, {
|
|
17993
|
+
myReactions: cached.myReactions.filter(x => x !== payload.reactor.reactionName),
|
|
17994
|
+
});
|
|
17761
17995
|
}
|
|
17762
17996
|
};
|
|
17763
17997
|
|
|
@@ -17776,7 +18010,7 @@ const preparePayloadForCache = (event, payload) => {
|
|
|
17776
18010
|
*
|
|
17777
18011
|
* @category Reaction API
|
|
17778
18012
|
* @async
|
|
17779
|
-
|
|
18013
|
+
* */
|
|
17780
18014
|
const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
17781
18015
|
var _a, _b;
|
|
17782
18016
|
const client = getActiveClient();
|
|
@@ -17785,7 +18019,11 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17785
18019
|
referenceType,
|
|
17786
18020
|
reactionName,
|
|
17787
18021
|
});
|
|
17788
|
-
await client.http.post('/api/v2/reactions', {
|
|
18022
|
+
await client.http.post('/api/v2/reactions', {
|
|
18023
|
+
referenceId,
|
|
18024
|
+
referenceType,
|
|
18025
|
+
reactionName,
|
|
18026
|
+
});
|
|
17789
18027
|
const model = await fetchReference(referenceType, referenceId);
|
|
17790
18028
|
dispatchReactable(referenceType, model.data);
|
|
17791
18029
|
return (_b = (_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)) !== null && _b !== void 0 ? _b : false;
|
|
@@ -17804,7 +18042,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17804
18042
|
* @returns The added result.
|
|
17805
18043
|
*
|
|
17806
18044
|
* @category Reaction API
|
|
17807
|
-
|
|
18045
|
+
* */
|
|
17808
18046
|
addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
17809
18047
|
var _a, _b, _c, _d, _e;
|
|
17810
18048
|
const client = getActiveClient();
|
|
@@ -17815,7 +18053,11 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
17815
18053
|
});
|
|
17816
18054
|
if (!client.cache)
|
|
17817
18055
|
return;
|
|
17818
|
-
const model = pullFromCache([
|
|
18056
|
+
const model = pullFromCache([
|
|
18057
|
+
referenceType,
|
|
18058
|
+
'get',
|
|
18059
|
+
referenceId,
|
|
18060
|
+
]);
|
|
17819
18061
|
if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
17820
18062
|
return;
|
|
17821
18063
|
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 }) });
|
|
@@ -17839,7 +18081,7 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
17839
18081
|
*
|
|
17840
18082
|
* @category Reaction API
|
|
17841
18083
|
* @async
|
|
17842
|
-
|
|
18084
|
+
* */
|
|
17843
18085
|
const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
17844
18086
|
var _a, _b;
|
|
17845
18087
|
const client = getActiveClient();
|
|
@@ -17848,7 +18090,9 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17848
18090
|
referenceType,
|
|
17849
18091
|
reactionName,
|
|
17850
18092
|
});
|
|
17851
|
-
await client.http.delete(`/api/v2/reactions`, {
|
|
18093
|
+
await client.http.delete(`/api/v2/reactions`, {
|
|
18094
|
+
data: { referenceId, referenceType, reactionName },
|
|
18095
|
+
});
|
|
17852
18096
|
const model = await fetchReference(referenceType, referenceId);
|
|
17853
18097
|
dispatchReactable(referenceType, model.data);
|
|
17854
18098
|
return (_b = !((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName))) !== null && _b !== void 0 ? _b : false;
|
|
@@ -17867,7 +18111,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17867
18111
|
* @returns The added result.
|
|
17868
18112
|
*
|
|
17869
18113
|
* @category Reaction API
|
|
17870
|
-
|
|
18114
|
+
* */
|
|
17871
18115
|
removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
17872
18116
|
var _a, _b, _c, _d, _e;
|
|
17873
18117
|
const client = getActiveClient();
|
|
@@ -17878,7 +18122,11 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
17878
18122
|
});
|
|
17879
18123
|
if (!client.cache)
|
|
17880
18124
|
return;
|
|
17881
|
-
const model = pullFromCache([
|
|
18125
|
+
const model = pullFromCache([
|
|
18126
|
+
referenceType,
|
|
18127
|
+
'get',
|
|
18128
|
+
referenceId,
|
|
18129
|
+
]);
|
|
17882
18130
|
if (!(model === null || model === void 0 ? void 0 : model.data) || !((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
17883
18131
|
return;
|
|
17884
18132
|
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) }) });
|
|
@@ -18057,6 +18305,7 @@ const onPostReactionAdded = (callback) => {
|
|
|
18057
18305
|
}
|
|
18058
18306
|
else {
|
|
18059
18307
|
preparePayloadForCache('post.addReaction', payload);
|
|
18308
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18060
18309
|
const postPayload = __rest(payload, ["reactor"]);
|
|
18061
18310
|
ingestInCache(postPayload);
|
|
18062
18311
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
@@ -18089,6 +18338,7 @@ const onPostReactionRemoved = (callback) => {
|
|
|
18089
18338
|
}
|
|
18090
18339
|
else {
|
|
18091
18340
|
preparePayloadForCache('post.removeReaction', payload);
|
|
18341
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18092
18342
|
const postPayload = __rest(payload, ["reactor"]);
|
|
18093
18343
|
ingestInCache(postPayload);
|
|
18094
18344
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
@@ -18108,7 +18358,11 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
18108
18358
|
}
|
|
18109
18359
|
else {
|
|
18110
18360
|
ingestInCache(payload);
|
|
18111
|
-
const comment = pullFromCache([
|
|
18361
|
+
const comment = pullFromCache([
|
|
18362
|
+
'comment',
|
|
18363
|
+
'get',
|
|
18364
|
+
payload.comments[0].commentId,
|
|
18365
|
+
]);
|
|
18112
18366
|
if (['comment.created'].includes(event)) {
|
|
18113
18367
|
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; });
|
|
18114
18368
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
@@ -18227,9 +18481,14 @@ const onCommentReactionAdded = (callback) => {
|
|
|
18227
18481
|
}
|
|
18228
18482
|
else {
|
|
18229
18483
|
preparePayloadForCache('comment.addReaction', payload);
|
|
18484
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18230
18485
|
const commentPayload = __rest(payload, ["reactor"]);
|
|
18231
18486
|
ingestInCache(commentPayload);
|
|
18232
|
-
const comment = pullFromCache([
|
|
18487
|
+
const comment = pullFromCache([
|
|
18488
|
+
'comment',
|
|
18489
|
+
'get',
|
|
18490
|
+
payload.comments[0].commentId,
|
|
18491
|
+
]);
|
|
18233
18492
|
callback(comment.data);
|
|
18234
18493
|
}
|
|
18235
18494
|
};
|
|
@@ -18259,9 +18518,14 @@ const onCommentReactionRemoved = (callback) => {
|
|
|
18259
18518
|
}
|
|
18260
18519
|
else {
|
|
18261
18520
|
preparePayloadForCache('comment.removeReaction', payload);
|
|
18521
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18262
18522
|
const commentPayload = __rest(payload, ["reactor"]);
|
|
18263
18523
|
ingestInCache(commentPayload);
|
|
18264
|
-
const comment = pullFromCache([
|
|
18524
|
+
const comment = pullFromCache([
|
|
18525
|
+
'comment',
|
|
18526
|
+
'get',
|
|
18527
|
+
payload.comments[0].commentId,
|
|
18528
|
+
]);
|
|
18265
18529
|
callback(comment.data);
|
|
18266
18530
|
}
|
|
18267
18531
|
};
|
|
@@ -18284,7 +18548,7 @@ const onCommentReactionRemoved = (callback) => {
|
|
|
18284
18548
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18285
18549
|
*
|
|
18286
18550
|
* @category Message Events
|
|
18287
|
-
|
|
18551
|
+
* */
|
|
18288
18552
|
const onReactionRemoved = (referenceType, referenceId, callback) => {
|
|
18289
18553
|
const callbackWrapper = (model) => {
|
|
18290
18554
|
if (getResolver(referenceType)(model) === referenceId) {
|
|
@@ -18295,7 +18559,11 @@ const onReactionRemoved = (referenceType, referenceId, callback) => {
|
|
|
18295
18559
|
const client = getActiveClient();
|
|
18296
18560
|
const filter = (payload) => {
|
|
18297
18561
|
var _a;
|
|
18298
|
-
const cached = pullFromCache([
|
|
18562
|
+
const cached = pullFromCache([
|
|
18563
|
+
'message',
|
|
18564
|
+
'get',
|
|
18565
|
+
payload.messages[0].messageId,
|
|
18566
|
+
]);
|
|
18299
18567
|
const isReactionEvent = ((_a = cached === null || cached === void 0 ? void 0 : cached.data) === null || _a === void 0 ? void 0 : _a.reactionsCount) !== payload.messages[0].reactionsCount;
|
|
18300
18568
|
ingestInCache(payload);
|
|
18301
18569
|
if (isReactionEvent) {
|
|
@@ -18345,12 +18613,12 @@ var REFERENCE_TYPES = {
|
|
|
18345
18613
|
*
|
|
18346
18614
|
* @category Report API
|
|
18347
18615
|
* @async
|
|
18348
|
-
|
|
18616
|
+
* */
|
|
18349
18617
|
const createReport = async (referenceType, referenceId) => {
|
|
18350
18618
|
const client = getActiveClient();
|
|
18351
18619
|
client.log('report/createReport', { referenceType, referenceId });
|
|
18352
18620
|
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
18353
|
-
const { data } = await client.http.post(`/api/v3/${domainName}/${
|
|
18621
|
+
const { data } = await client.http.post(`/api/v3/${domainName}/${encodeURIComponent(referenceId)}/flag`);
|
|
18354
18622
|
if (client.cache)
|
|
18355
18623
|
ingestInCache(data);
|
|
18356
18624
|
const event = referenceType === 'message'
|
|
@@ -18372,7 +18640,7 @@ const createReport = async (referenceType, referenceId) => {
|
|
|
18372
18640
|
*
|
|
18373
18641
|
* @category Report API
|
|
18374
18642
|
* @async
|
|
18375
|
-
|
|
18643
|
+
* */
|
|
18376
18644
|
const deleteReport = async (referenceType, referenceId) => {
|
|
18377
18645
|
const client = getActiveClient();
|
|
18378
18646
|
client.log('report/deleteReport', { referenceType, referenceId });
|
|
@@ -18399,7 +18667,7 @@ const deleteReport = async (referenceType, referenceId) => {
|
|
|
18399
18667
|
*
|
|
18400
18668
|
* @category Report API
|
|
18401
18669
|
* @async
|
|
18402
|
-
|
|
18670
|
+
* */
|
|
18403
18671
|
const isReportedByMe = async (referenceType, referenceId) => {
|
|
18404
18672
|
var _a, _b;
|
|
18405
18673
|
const client = getActiveClient();
|
|
@@ -18434,15 +18702,21 @@ const queryChannels = async (query) => {
|
|
|
18434
18702
|
// API-FIX: parameters should be querystring.
|
|
18435
18703
|
// API-FIX: backend doesnt answer Amity.Response
|
|
18436
18704
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<ChannelPayload>>>(
|
|
18437
|
-
const { data } = await client.http.get(`/api/v3/channels`, {
|
|
18705
|
+
const { data } = await client.http.get(`/api/v3/channels`, {
|
|
18706
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
|
|
18438
18707
|
token: toToken(page, 'skiplimit'),
|
|
18439
|
-
} })
|
|
18708
|
+
} }),
|
|
18709
|
+
});
|
|
18440
18710
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
18441
18711
|
const { channels } = payload;
|
|
18442
18712
|
const cachedAt = client.cache && Date.now();
|
|
18443
18713
|
if (client.cache) {
|
|
18444
18714
|
ingestInCache(payload, { cachedAt });
|
|
18445
|
-
const cacheKey = [
|
|
18715
|
+
const cacheKey = [
|
|
18716
|
+
'channel',
|
|
18717
|
+
'query',
|
|
18718
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
18719
|
+
];
|
|
18446
18720
|
pushToCache(cacheKey, { channels: channels.map(getResolver('channel')), paging });
|
|
18447
18721
|
}
|
|
18448
18722
|
const nextPage = toPage(paging.next);
|
|
@@ -18487,13 +18761,15 @@ const getChannels = async (channelIds) => {
|
|
|
18487
18761
|
client.log('channel/getChannels', channelIds);
|
|
18488
18762
|
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
18489
18763
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
18490
|
-
const { data } = await client.http.get(`/api/v3/channels/list`, {
|
|
18764
|
+
const { data } = await client.http.get(`/api/v3/channels/list`, {
|
|
18765
|
+
params: { channelIds: encodedChannelIds },
|
|
18766
|
+
});
|
|
18491
18767
|
const cachedAt = client.cache && Date.now();
|
|
18492
18768
|
if (client.cache)
|
|
18493
18769
|
ingestInCache(data, { cachedAt });
|
|
18494
18770
|
return {
|
|
18495
18771
|
data: data.channels,
|
|
18496
|
-
cachedAt
|
|
18772
|
+
cachedAt,
|
|
18497
18773
|
};
|
|
18498
18774
|
};
|
|
18499
18775
|
/**
|
|
@@ -18519,7 +18795,7 @@ getChannels.locally = (channelIds) => {
|
|
|
18519
18795
|
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
18520
18796
|
.filter(Boolean);
|
|
18521
18797
|
const channels = cached.map(({ data }) => data);
|
|
18522
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
18798
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
18523
18799
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < channelIds.length)
|
|
18524
18800
|
return;
|
|
18525
18801
|
return {
|
|
@@ -18663,7 +18939,6 @@ const updateChannel = async (channelId, patch) => {
|
|
|
18663
18939
|
const deleteChannel = async (channelId) => {
|
|
18664
18940
|
const client = getActiveClient();
|
|
18665
18941
|
client.log('channel/deleteChannel', channelId);
|
|
18666
|
-
// API-FIX: This endpoint has not been implemented yet.
|
|
18667
18942
|
await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
18668
18943
|
const deleted = await getChannel(channelId);
|
|
18669
18944
|
// no need for event, fired by server
|
|
@@ -18691,8 +18966,7 @@ const joinChannel = async (channelId) => {
|
|
|
18691
18966
|
if (client.cache)
|
|
18692
18967
|
ingestInCache(data);
|
|
18693
18968
|
const { channelUsers } = data;
|
|
18694
|
-
return !!channelUsers.find(channelUser =>
|
|
18695
|
-
&& channelUser.membership === 'member'));
|
|
18969
|
+
return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership === 'member');
|
|
18696
18970
|
};
|
|
18697
18971
|
|
|
18698
18972
|
/**
|
|
@@ -18716,8 +18990,7 @@ const leaveChannel = async (channelId) => {
|
|
|
18716
18990
|
if (client.cache)
|
|
18717
18991
|
ingestInCache(data);
|
|
18718
18992
|
const { channelUsers } = data;
|
|
18719
|
-
return !!channelUsers.find(channelUser =>
|
|
18720
|
-
&& channelUser.membership !== 'member'));
|
|
18993
|
+
return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership !== 'member');
|
|
18721
18994
|
};
|
|
18722
18995
|
|
|
18723
18996
|
/**
|
|
@@ -18733,7 +19006,7 @@ const leaveChannel = async (channelId) => {
|
|
|
18733
19006
|
*
|
|
18734
19007
|
* @category Channel API
|
|
18735
19008
|
* @async
|
|
18736
|
-
|
|
19009
|
+
* */
|
|
18737
19010
|
const queryChannelMembers = async (query) => {
|
|
18738
19011
|
const client = getActiveClient();
|
|
18739
19012
|
client.log('channel/queryChannelMembers', query);
|
|
@@ -19229,7 +19502,11 @@ const createCommunityEventSubscriber = (event, callback) => {
|
|
|
19229
19502
|
}
|
|
19230
19503
|
else {
|
|
19231
19504
|
ingestInCache(payload);
|
|
19232
|
-
const community = pullFromCache([
|
|
19505
|
+
const community = pullFromCache([
|
|
19506
|
+
'community',
|
|
19507
|
+
'get',
|
|
19508
|
+
payload.communities[0].communityId,
|
|
19509
|
+
]);
|
|
19233
19510
|
callback(community.data);
|
|
19234
19511
|
}
|
|
19235
19512
|
};
|
|
@@ -19239,8 +19516,8 @@ function hasPermission(member, payload, permission) {
|
|
|
19239
19516
|
if (member.permissions.some(x => x === permission)) {
|
|
19240
19517
|
return true;
|
|
19241
19518
|
}
|
|
19242
|
-
return payload
|
|
19243
|
-
.find(user => user.userId === member.userId)
|
|
19519
|
+
return payload
|
|
19520
|
+
.users.find(user => user.userId === member.userId)
|
|
19244
19521
|
.permissions.some(x => x === permission);
|
|
19245
19522
|
}
|
|
19246
19523
|
function getEventRelatedMember(event, payload) {
|
|
@@ -19270,11 +19547,15 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
|
|
|
19270
19547
|
}
|
|
19271
19548
|
else {
|
|
19272
19549
|
ingestInCache(payload);
|
|
19273
|
-
const community = pullFromCache([
|
|
19550
|
+
const community = pullFromCache([
|
|
19551
|
+
'community',
|
|
19552
|
+
'get',
|
|
19553
|
+
payload.communities[0].communityId,
|
|
19554
|
+
]);
|
|
19274
19555
|
const member = pullFromCache([
|
|
19275
19556
|
'communityUsers',
|
|
19276
19557
|
'get',
|
|
19277
|
-
getResolver('communityUsers')(getEventRelatedMember(event, payload))
|
|
19558
|
+
getResolver('communityUsers')(getEventRelatedMember(event, payload)),
|
|
19278
19559
|
]);
|
|
19279
19560
|
callback(community.data, member.data);
|
|
19280
19561
|
}
|
|
@@ -19481,90 +19762,802 @@ const observeCommunity = (communityId, callback) => {
|
|
|
19481
19762
|
|
|
19482
19763
|
/**
|
|
19483
19764
|
* ```js
|
|
19484
|
-
* import {
|
|
19485
|
-
* const
|
|
19765
|
+
* import { queryCategories } from '@amityco/ts-sdk'
|
|
19766
|
+
* const { data: categories, prevPage, nextPage } = await queryCategories()
|
|
19486
19767
|
* ```
|
|
19487
19768
|
*
|
|
19488
|
-
* Queries a paginable list of {@link Amity.
|
|
19769
|
+
* Queries a paginable list of {@link Amity.Category} objects
|
|
19489
19770
|
*
|
|
19490
19771
|
* @param query The query parameters
|
|
19491
|
-
* @returns A page of {@link Amity.
|
|
19772
|
+
* @returns A page of {@link Amity.Category} objects
|
|
19492
19773
|
*
|
|
19493
|
-
* @category
|
|
19774
|
+
* @category Category API
|
|
19494
19775
|
* @async
|
|
19495
|
-
|
|
19496
|
-
const
|
|
19776
|
+
* */
|
|
19777
|
+
const queryCategories = async (query) => {
|
|
19497
19778
|
const client = getActiveClient();
|
|
19498
|
-
client.log('
|
|
19499
|
-
const _a = query !== null && query !== void 0 ? query : {}, {
|
|
19500
|
-
const { data } = await client.http.get(
|
|
19501
|
-
|
|
19502
|
-
|
|
19779
|
+
client.log('category/queryCategories', query);
|
|
19780
|
+
const _a = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 } } = _a, params = __rest(_a, ["page"]);
|
|
19781
|
+
const { data } = await client.http.get(`/api/v3/community-categories`, {
|
|
19782
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
19783
|
+
token: toToken(page, 'skiplimit'),
|
|
19784
|
+
} }),
|
|
19785
|
+
});
|
|
19503
19786
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19504
|
-
const {
|
|
19787
|
+
const { categories } = payload;
|
|
19505
19788
|
const cachedAt = client.cache && Date.now();
|
|
19506
19789
|
if (client.cache) {
|
|
19507
|
-
ingestInCache(payload);
|
|
19508
|
-
const cacheKey = [
|
|
19509
|
-
|
|
19790
|
+
ingestInCache(payload, { cachedAt });
|
|
19791
|
+
const cacheKey = [
|
|
19792
|
+
'category',
|
|
19793
|
+
'query',
|
|
19794
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
19795
|
+
];
|
|
19796
|
+
pushToCache(cacheKey, { categories: categories.map(getResolver('category')), paging });
|
|
19510
19797
|
}
|
|
19511
19798
|
const nextPage = toPage(paging.next);
|
|
19512
19799
|
const prevPage = toPage(paging.previous);
|
|
19513
|
-
return { data:
|
|
19800
|
+
return { data: categories, cachedAt, prevPage, nextPage };
|
|
19514
19801
|
};
|
|
19515
19802
|
/**
|
|
19516
19803
|
* ```js
|
|
19517
|
-
* import {
|
|
19518
|
-
* const
|
|
19804
|
+
* import { queryCategories } from '@amityco/ts-sdk'
|
|
19805
|
+
* const { data: categories, prevPage, nextPage } = queryCategories.locally()
|
|
19519
19806
|
* ```
|
|
19520
19807
|
*
|
|
19521
|
-
* Queries a paginable list of {@link Amity.
|
|
19808
|
+
* Queries a paginable list of {@link Amity.Category} objects from cache
|
|
19522
19809
|
*
|
|
19523
19810
|
* @param query The query parameters
|
|
19524
|
-
* @returns
|
|
19811
|
+
* @returns categories
|
|
19525
19812
|
*
|
|
19526
|
-
* @category
|
|
19527
|
-
|
|
19528
|
-
|
|
19529
|
-
queryGlobalFeed.locally = (query) => {
|
|
19813
|
+
* @category category API
|
|
19814
|
+
*/
|
|
19815
|
+
queryCategories.locally = (query) => {
|
|
19530
19816
|
var _a, _b;
|
|
19531
19817
|
const client = getActiveClient();
|
|
19532
|
-
client.log('
|
|
19818
|
+
client.log('category/queryCategories.locally', query);
|
|
19533
19819
|
if (!client.cache)
|
|
19534
19820
|
return;
|
|
19535
|
-
const _c = query !== null && query !== void 0 ? query : {}, {
|
|
19536
|
-
const queryKey = ['
|
|
19821
|
+
const _c = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 } } = _c, params = __rest(_c, ["page"]);
|
|
19822
|
+
const queryKey = ['category', 'query', Object.assign(Object.assign({}, params), { options: Object.assign({}, page) })];
|
|
19537
19823
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19538
|
-
if (!(data === null || data === void 0 ? void 0 : data.
|
|
19824
|
+
if (!(data === null || data === void 0 ? void 0 : data.categories.length))
|
|
19539
19825
|
return;
|
|
19540
|
-
const
|
|
19541
|
-
.map(
|
|
19826
|
+
const categories = data.categories
|
|
19827
|
+
.map(categoryId => pullFromCache(['category', 'get', categoryId]))
|
|
19542
19828
|
.filter(Boolean)
|
|
19543
19829
|
.map(({ data }) => data);
|
|
19544
19830
|
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19545
19831
|
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19546
|
-
return
|
|
19547
|
-
? { data:
|
|
19832
|
+
return categories.length === ((_b = data === null || data === void 0 ? void 0 : data.categories) === null || _b === void 0 ? void 0 : _b.length)
|
|
19833
|
+
? { data: categories, cachedAt, prevPage, nextPage }
|
|
19548
19834
|
: undefined;
|
|
19549
19835
|
};
|
|
19550
19836
|
|
|
19551
19837
|
/**
|
|
19552
19838
|
* ```js
|
|
19553
|
-
* import {
|
|
19554
|
-
*
|
|
19555
|
-
* let posts = []
|
|
19556
|
-
* const unsub = observePosts({
|
|
19557
|
-
* targetType: Amity.PostTargetType,
|
|
19558
|
-
* targetId: Amity.Post['targetId'],
|
|
19559
|
-
* }, post => merge(posts, post))
|
|
19839
|
+
* import { getCategory } from '@amityco/ts-sdk'
|
|
19840
|
+
* const { data: category } = await getCategory('foo')
|
|
19560
19841
|
* ```
|
|
19561
19842
|
*
|
|
19562
|
-
*
|
|
19843
|
+
* Fetches a {@link Amity.Category} object
|
|
19563
19844
|
*
|
|
19564
|
-
* @param
|
|
19565
|
-
* @
|
|
19566
|
-
*
|
|
19567
|
-
* @
|
|
19845
|
+
* @param categoryId the ID of the {@link Amity.Category} to fetch
|
|
19846
|
+
* @returns the associated {@link Amity.Category} object
|
|
19847
|
+
*
|
|
19848
|
+
* @category Category API
|
|
19849
|
+
* @async
|
|
19850
|
+
*/
|
|
19851
|
+
const getCategory = async (categoryId) => {
|
|
19852
|
+
const client = getActiveClient();
|
|
19853
|
+
client.log('category/getCategory', categoryId);
|
|
19854
|
+
const { data } = await client.http.get(`/api/v3/community-categories/${encodeURIComponent(categoryId)}`);
|
|
19855
|
+
const cachedAt = client.cache && Date.now();
|
|
19856
|
+
if (client.cache)
|
|
19857
|
+
ingestInCache(data, { cachedAt });
|
|
19858
|
+
const { categories } = data;
|
|
19859
|
+
return {
|
|
19860
|
+
data: categories.find(category => category.categoryId === categoryId),
|
|
19861
|
+
cachedAt,
|
|
19862
|
+
};
|
|
19863
|
+
};
|
|
19864
|
+
/**
|
|
19865
|
+
* ```js
|
|
19866
|
+
* import { getCategory } from '@amityco/ts-sdk'
|
|
19867
|
+
* const { data: category } = getCategory.locally('foobar')
|
|
19868
|
+
* ```
|
|
19869
|
+
*
|
|
19870
|
+
* Fetches a {@link Amity.Category} object from cache
|
|
19871
|
+
*
|
|
19872
|
+
* @param categoryId the ID of the {@link Amity.Category} to fetch
|
|
19873
|
+
* @returns the associated {@link Amity.Category} object
|
|
19874
|
+
*
|
|
19875
|
+
* @category Category API
|
|
19876
|
+
*/
|
|
19877
|
+
getCategory.locally = (categoryId) => {
|
|
19878
|
+
const client = getActiveClient();
|
|
19879
|
+
client.log('category/getCategory.locally', categoryId);
|
|
19880
|
+
if (!client.cache)
|
|
19881
|
+
return;
|
|
19882
|
+
const cached = pullFromCache(['category', 'get', categoryId]);
|
|
19883
|
+
if (!cached)
|
|
19884
|
+
return;
|
|
19885
|
+
return {
|
|
19886
|
+
data: cached.data,
|
|
19887
|
+
cachedAt: cached.cachedAt,
|
|
19888
|
+
};
|
|
19889
|
+
};
|
|
19890
|
+
|
|
19891
|
+
/**
|
|
19892
|
+
* ```js
|
|
19893
|
+
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
19894
|
+
* const posts = await queryGlobalFeed()
|
|
19895
|
+
* ```
|
|
19896
|
+
*
|
|
19897
|
+
* Queries a paginable list of {@link Amity.Post} objects
|
|
19898
|
+
*
|
|
19899
|
+
* @param query The query parameters
|
|
19900
|
+
* @returns A page of {@link Amity.Post} objects
|
|
19901
|
+
*
|
|
19902
|
+
* @category Feed API
|
|
19903
|
+
* @async
|
|
19904
|
+
* */
|
|
19905
|
+
const queryGlobalFeed = async (query) => {
|
|
19906
|
+
const client = getActiveClient();
|
|
19907
|
+
client.log('feed/queryGlobalFeed', query);
|
|
19908
|
+
const _a = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _a, params = __rest(_a, ["useCustomRanking", "page"]);
|
|
19909
|
+
const { data } = await client.http.get(useCustomRanking ? `/api/v5/me/global-feeds` : `/api/v4/me/global-feeds`, {
|
|
19910
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
19911
|
+
token: toToken(page, 'skiplimit'),
|
|
19912
|
+
} }),
|
|
19913
|
+
});
|
|
19914
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19915
|
+
const { posts } = payload;
|
|
19916
|
+
const cachedAt = client.cache && Date.now();
|
|
19917
|
+
if (client.cache) {
|
|
19918
|
+
ingestInCache(payload);
|
|
19919
|
+
const cacheKey = [
|
|
19920
|
+
'globalFeed',
|
|
19921
|
+
'query',
|
|
19922
|
+
Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) }),
|
|
19923
|
+
];
|
|
19924
|
+
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
19925
|
+
}
|
|
19926
|
+
const nextPage = toPage(paging.next);
|
|
19927
|
+
const prevPage = toPage(paging.previous);
|
|
19928
|
+
return { data: posts, cachedAt, prevPage, nextPage };
|
|
19929
|
+
};
|
|
19930
|
+
/**
|
|
19931
|
+
* ```js
|
|
19932
|
+
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
19933
|
+
* const posts = await queryGlobalFeed.locally()
|
|
19934
|
+
* ```
|
|
19935
|
+
*
|
|
19936
|
+
* Queries a paginable list of {@link Amity.Post} objects from cache
|
|
19937
|
+
*
|
|
19938
|
+
* @param query The query parameters
|
|
19939
|
+
* @returns A page of {@link Amity.Post} objects
|
|
19940
|
+
*
|
|
19941
|
+
* @category Feed API
|
|
19942
|
+
* @async
|
|
19943
|
+
* */
|
|
19944
|
+
queryGlobalFeed.locally = (query) => {
|
|
19945
|
+
var _a, _b;
|
|
19946
|
+
const client = getActiveClient();
|
|
19947
|
+
client.log('post/queryGlobalFeed.locally', query);
|
|
19948
|
+
if (!client.cache)
|
|
19949
|
+
return;
|
|
19950
|
+
const _c = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _c, params = __rest(_c, ["useCustomRanking", "page"]);
|
|
19951
|
+
const queryKey = [
|
|
19952
|
+
'globalFeed',
|
|
19953
|
+
'query',
|
|
19954
|
+
Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) }),
|
|
19955
|
+
];
|
|
19956
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19957
|
+
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
19958
|
+
return;
|
|
19959
|
+
const posts = data.posts
|
|
19960
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
19961
|
+
.filter(Boolean)
|
|
19962
|
+
.map(({ data }) => data);
|
|
19963
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19964
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19965
|
+
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
19966
|
+
? { data: posts, cachedAt, prevPage, nextPage }
|
|
19967
|
+
: undefined;
|
|
19968
|
+
};
|
|
19969
|
+
|
|
19970
|
+
const queryFollows = async (key, query) => {
|
|
19971
|
+
const client = getActiveClient();
|
|
19972
|
+
client.log(`follow/queryF${key.substring(1)}`, query);
|
|
19973
|
+
const { userId, page } = query, params = __rest(query, ["userId", "page"]);
|
|
19974
|
+
const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/${key}` : `/api/v4/users/${userId}/${key}`, {
|
|
19975
|
+
params: Object.assign(Object.assign({}, params), { token: toToken(page, 'skiplimit') }),
|
|
19976
|
+
});
|
|
19977
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19978
|
+
const { follows } = payload;
|
|
19979
|
+
const cachedAt = client.cache && Date.now();
|
|
19980
|
+
if (client.cache) {
|
|
19981
|
+
ingestInCache(payload, { cachedAt });
|
|
19982
|
+
const cacheKey = [
|
|
19983
|
+
key,
|
|
19984
|
+
'query',
|
|
19985
|
+
Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page) }),
|
|
19986
|
+
];
|
|
19987
|
+
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
19988
|
+
}
|
|
19989
|
+
const nextPage = toPage(paging.next);
|
|
19990
|
+
const prevPage = toPage(paging.previous);
|
|
19991
|
+
return { data: follows, cachedAt, prevPage, nextPage };
|
|
19992
|
+
};
|
|
19993
|
+
queryFollows.locally = (key, query) => {
|
|
19994
|
+
var _a, _b;
|
|
19995
|
+
const client = getActiveClient();
|
|
19996
|
+
client.log(`follow/queryF${key.substring(1)}.locally`, query);
|
|
19997
|
+
if (!client.cache)
|
|
19998
|
+
return;
|
|
19999
|
+
const { page } = query, params = __rest(query, ["page"]);
|
|
20000
|
+
const queryKey = [key, 'query', Object.assign(Object.assign({}, params), { options: Object.assign({}, page) })];
|
|
20001
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
20002
|
+
if (!(data === null || data === void 0 ? void 0 : data.follows.length)) {
|
|
20003
|
+
return;
|
|
20004
|
+
}
|
|
20005
|
+
const follows = data.follows
|
|
20006
|
+
.map(key => pullFromCache(['follow', 'get', key]))
|
|
20007
|
+
.filter(Boolean)
|
|
20008
|
+
.map(({ data }) => data);
|
|
20009
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
20010
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
20011
|
+
return follows.length === ((_b = data === null || data === void 0 ? void 0 : data.follows) === null || _b === void 0 ? void 0 : _b.length)
|
|
20012
|
+
? { data: follows, cachedAt, prevPage, nextPage }
|
|
20013
|
+
: undefined;
|
|
20014
|
+
};
|
|
20015
|
+
|
|
20016
|
+
/**
|
|
20017
|
+
* ```js
|
|
20018
|
+
* import { queryFollowers } from '@amityco/ts-sdk'
|
|
20019
|
+
* const { data: followers, prevPage, nextPage } = await queryFollowers({ userId })
|
|
20020
|
+
* ```
|
|
20021
|
+
*
|
|
20022
|
+
* Queries a paginable list of {@link Amity.FollowStatus}
|
|
20023
|
+
*
|
|
20024
|
+
* @param query The query parameters
|
|
20025
|
+
* @returns followers
|
|
20026
|
+
*
|
|
20027
|
+
* @category Follow API
|
|
20028
|
+
* @async
|
|
20029
|
+
*/
|
|
20030
|
+
const queryFollowers = async (query) => queryFollows('followers', query);
|
|
20031
|
+
/**
|
|
20032
|
+
* ```js
|
|
20033
|
+
* import { queryFollowers } from '@amityco/ts-sdk'
|
|
20034
|
+
* const { data: followers, prevPage, nextPage } = queryFollowers.locally({ userId })
|
|
20035
|
+
* ```
|
|
20036
|
+
*
|
|
20037
|
+
* Queries a paginable list of {@link Amity.FollowStatus} objects from cache
|
|
20038
|
+
*
|
|
20039
|
+
* @param query The query parameters
|
|
20040
|
+
* @returns followers
|
|
20041
|
+
*
|
|
20042
|
+
* @category Post API
|
|
20043
|
+
*/
|
|
20044
|
+
queryFollowers.locally = (query) => queryFollows.locally('followers', query);
|
|
20045
|
+
|
|
20046
|
+
/**
|
|
20047
|
+
* ```js
|
|
20048
|
+
* import { queryFollowings } from '@amityco/ts-sdk'
|
|
20049
|
+
* const { data: followings, prevPage, nextPage } = await queryFollowings({ userId })
|
|
20050
|
+
* ```
|
|
20051
|
+
*
|
|
20052
|
+
* Queries a paginable list of {@link Amity.FollowStatus}
|
|
20053
|
+
*
|
|
20054
|
+
* @param query The query parameters
|
|
20055
|
+
* @returns followings
|
|
20056
|
+
*
|
|
20057
|
+
* @category Follow API
|
|
20058
|
+
* @async
|
|
20059
|
+
*/
|
|
20060
|
+
const queryFollowings = async (query) => queryFollows('following', query);
|
|
20061
|
+
/**
|
|
20062
|
+
* ```js
|
|
20063
|
+
* import { queryFollowings } from '@amityco/ts-sdk'
|
|
20064
|
+
* const { data: followings, prevPage, nextPage } = queryFollowings.locally({ userId })
|
|
20065
|
+
* ```
|
|
20066
|
+
*
|
|
20067
|
+
* Queries a paginable list of {@link Amity.FollowStatus} objects from cache
|
|
20068
|
+
*
|
|
20069
|
+
* @param query The query parameters
|
|
20070
|
+
* @returns followings
|
|
20071
|
+
*
|
|
20072
|
+
* @category Post API
|
|
20073
|
+
*/
|
|
20074
|
+
queryFollowings.locally = (query) => queryFollows.locally('following', query);
|
|
20075
|
+
|
|
20076
|
+
const getCacheKey = (userId) => [
|
|
20077
|
+
'followInfo',
|
|
20078
|
+
'get',
|
|
20079
|
+
`${getActiveClient().userId}#${userId}`,
|
|
20080
|
+
];
|
|
20081
|
+
/**
|
|
20082
|
+
* ```js
|
|
20083
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
20084
|
+
* const { data: followInfo } = await getFollowInfo('foobar')
|
|
20085
|
+
* ```
|
|
20086
|
+
*
|
|
20087
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user
|
|
20088
|
+
*
|
|
20089
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20090
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
20091
|
+
*
|
|
20092
|
+
* @category Follow API
|
|
20093
|
+
* @async
|
|
20094
|
+
*/
|
|
20095
|
+
const getFollowInfo = async (userId) => {
|
|
20096
|
+
var _a, _b;
|
|
20097
|
+
const client = getActiveClient();
|
|
20098
|
+
client.log('follow/getFollowInfo', userId);
|
|
20099
|
+
const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/followInfo` : `/api/v4/users/${userId}/followInfo`);
|
|
20100
|
+
const cachedAt = client.cache && Date.now();
|
|
20101
|
+
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 });
|
|
20102
|
+
if (client.cache) {
|
|
20103
|
+
pushToCache(getCacheKey(userId), followInfo, { cachedAt });
|
|
20104
|
+
}
|
|
20105
|
+
return {
|
|
20106
|
+
data: followInfo,
|
|
20107
|
+
cachedAt,
|
|
20108
|
+
};
|
|
20109
|
+
};
|
|
20110
|
+
/**
|
|
20111
|
+
* ```js
|
|
20112
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
20113
|
+
* const { data: followInfo } = getFollowInfo.locally('foobar')
|
|
20114
|
+
* ```
|
|
20115
|
+
*
|
|
20116
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user from cache
|
|
20117
|
+
*
|
|
20118
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20119
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
20120
|
+
*
|
|
20121
|
+
* @category Follow API
|
|
20122
|
+
*/
|
|
20123
|
+
getFollowInfo.locally = (userId) => {
|
|
20124
|
+
const client = getActiveClient();
|
|
20125
|
+
client.log('follow/getFollowInfo.locally', userId);
|
|
20126
|
+
if (!client.cache) {
|
|
20127
|
+
return;
|
|
20128
|
+
}
|
|
20129
|
+
const cached = pullFromCache(getCacheKey(userId));
|
|
20130
|
+
if (!cached) {
|
|
20131
|
+
return;
|
|
20132
|
+
}
|
|
20133
|
+
return {
|
|
20134
|
+
data: cached.data,
|
|
20135
|
+
cachedAt: cached.cachedAt,
|
|
20136
|
+
};
|
|
20137
|
+
};
|
|
20138
|
+
|
|
20139
|
+
/**
|
|
20140
|
+
* ```js
|
|
20141
|
+
* import { follow } from '@amityco/ts-sdk'
|
|
20142
|
+
* const status = await follow('foobar')
|
|
20143
|
+
* ```
|
|
20144
|
+
*
|
|
20145
|
+
* Follow the user
|
|
20146
|
+
*
|
|
20147
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20148
|
+
* @returns the status {@link Amity.FollowStatus}
|
|
20149
|
+
*
|
|
20150
|
+
* @category Follow API
|
|
20151
|
+
* @async
|
|
20152
|
+
*/
|
|
20153
|
+
const follow = async (userId) => {
|
|
20154
|
+
const client = getActiveClient();
|
|
20155
|
+
client.log('follow/follow', userId);
|
|
20156
|
+
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
20157
|
+
const cachedAt = client.cache && Date.now();
|
|
20158
|
+
if (client.cache) {
|
|
20159
|
+
ingestInCache(data, { cachedAt });
|
|
20160
|
+
}
|
|
20161
|
+
fireEvent(data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested', data.follows[0]);
|
|
20162
|
+
return {
|
|
20163
|
+
data: data.follows[0],
|
|
20164
|
+
cachedAt,
|
|
20165
|
+
};
|
|
20166
|
+
};
|
|
20167
|
+
|
|
20168
|
+
/**
|
|
20169
|
+
* ```js
|
|
20170
|
+
* import { unfollow } from '@amityco/ts-sdk'
|
|
20171
|
+
* await unfollow('foobar')
|
|
20172
|
+
* ```
|
|
20173
|
+
*
|
|
20174
|
+
* Cancel the follow request or unfollow the user
|
|
20175
|
+
*
|
|
20176
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20177
|
+
* @returns A success boolean if the user {@link Amity.User} was unfollowed
|
|
20178
|
+
*
|
|
20179
|
+
* @category Follow API
|
|
20180
|
+
* @async
|
|
20181
|
+
*/
|
|
20182
|
+
const unfollow = async (userId) => {
|
|
20183
|
+
const client = getActiveClient();
|
|
20184
|
+
client.log('follow/unfollow', userId);
|
|
20185
|
+
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
20186
|
+
if (client.cache) {
|
|
20187
|
+
ingestInCache(data);
|
|
20188
|
+
}
|
|
20189
|
+
fireEvent('follow.unfollowed', data.follows[0]);
|
|
20190
|
+
return true;
|
|
20191
|
+
};
|
|
20192
|
+
|
|
20193
|
+
/**
|
|
20194
|
+
* ```js
|
|
20195
|
+
* import { acceptFollower } from '@amityco/ts-sdk'
|
|
20196
|
+
* await acceptFollower('foobar')
|
|
20197
|
+
* ```
|
|
20198
|
+
*
|
|
20199
|
+
* Accept the follow request
|
|
20200
|
+
*
|
|
20201
|
+
* @param userId the ID of the {@link Amity.User} follower
|
|
20202
|
+
* @returns A success boolean if the follow request was accepted
|
|
20203
|
+
*
|
|
20204
|
+
* @category Follow API
|
|
20205
|
+
* @async
|
|
20206
|
+
*/
|
|
20207
|
+
const acceptFollower = async (userId) => {
|
|
20208
|
+
const client = getActiveClient();
|
|
20209
|
+
client.log('follow/acceptFollower', userId);
|
|
20210
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
20211
|
+
if (client.cache) {
|
|
20212
|
+
ingestInCache(data);
|
|
20213
|
+
}
|
|
20214
|
+
fireEvent('follow.accepted', data.follows[0]);
|
|
20215
|
+
return true;
|
|
20216
|
+
};
|
|
20217
|
+
|
|
20218
|
+
/**
|
|
20219
|
+
* ```js
|
|
20220
|
+
* import { declineFollower } from '@amityco/ts-sdk'
|
|
20221
|
+
* await declineFollower('foobar')
|
|
20222
|
+
* ```
|
|
20223
|
+
*
|
|
20224
|
+
* Decline the follow request or delete the follower
|
|
20225
|
+
*
|
|
20226
|
+
* @param userId the ID of the {@link Amity.User} follower
|
|
20227
|
+
* @returns A success boolean if the follow request was decline
|
|
20228
|
+
*
|
|
20229
|
+
* @category Follow API
|
|
20230
|
+
* @async
|
|
20231
|
+
*/
|
|
20232
|
+
const declineFollower = async (userId) => {
|
|
20233
|
+
const client = getActiveClient();
|
|
20234
|
+
client.log('follow/declineFollower', userId);
|
|
20235
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
20236
|
+
if (client.cache) {
|
|
20237
|
+
ingestInCache(data);
|
|
20238
|
+
}
|
|
20239
|
+
fireEvent('follow.requestDeclined', data.follows[0]);
|
|
20240
|
+
return true;
|
|
20241
|
+
};
|
|
20242
|
+
|
|
20243
|
+
const createFollowEventSubscriber = (event, callback) => {
|
|
20244
|
+
const client = getActiveClient();
|
|
20245
|
+
const filter = (payload) => {
|
|
20246
|
+
var _a, _b;
|
|
20247
|
+
if (!client.cache) {
|
|
20248
|
+
callback(payload);
|
|
20249
|
+
}
|
|
20250
|
+
else {
|
|
20251
|
+
ingestInCache({ follows: [payload] });
|
|
20252
|
+
const queries = [
|
|
20253
|
+
...((_a = queryCache(['followers', 'query'])) !== null && _a !== void 0 ? _a : []),
|
|
20254
|
+
...((_b = queryCache(['followings', 'query'])) !== null && _b !== void 0 ? _b : []),
|
|
20255
|
+
];
|
|
20256
|
+
queries
|
|
20257
|
+
// @ts-ignore
|
|
20258
|
+
.filter(({ key }) => key[2].userId === payload.from || key[2].userId === payload.to)
|
|
20259
|
+
.forEach(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
20260
|
+
callback(payload);
|
|
20261
|
+
}
|
|
20262
|
+
};
|
|
20263
|
+
return createEventSubscriber(client, event, event, filter);
|
|
20264
|
+
};
|
|
20265
|
+
|
|
20266
|
+
/**
|
|
20267
|
+
* ```js
|
|
20268
|
+
* import { onUserFollowed } from '@amityco/ts-sdk'
|
|
20269
|
+
* const dispose = onUserFollowed(status => {
|
|
20270
|
+
* // ...
|
|
20271
|
+
* })
|
|
20272
|
+
* ```
|
|
20273
|
+
*
|
|
20274
|
+
* Fired when a user follows another users and confirmation is not required
|
|
20275
|
+
*
|
|
20276
|
+
* @param callback The function to call when the event was fired
|
|
20277
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20278
|
+
*
|
|
20279
|
+
* @category Follow Events
|
|
20280
|
+
*/
|
|
20281
|
+
const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
|
|
20282
|
+
|
|
20283
|
+
/**
|
|
20284
|
+
* ```js
|
|
20285
|
+
* import { onUserUnfollowed } from '@amityco/ts-sdk'
|
|
20286
|
+
* const dispose = onUserFollowed(status => {
|
|
20287
|
+
* // ...
|
|
20288
|
+
* })
|
|
20289
|
+
* ```
|
|
20290
|
+
*
|
|
20291
|
+
* Fired when a user unfollows
|
|
20292
|
+
*
|
|
20293
|
+
* @param callback The function to call when the event was fired
|
|
20294
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20295
|
+
*
|
|
20296
|
+
* @category Follow Events
|
|
20297
|
+
*/
|
|
20298
|
+
const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
|
|
20299
|
+
|
|
20300
|
+
/**
|
|
20301
|
+
* ```js
|
|
20302
|
+
* import { onFollowerDeleted } from '@amityco/ts-sdk'
|
|
20303
|
+
* const dispose = onFollowerDeleted(status => {
|
|
20304
|
+
* // ...
|
|
20305
|
+
* })
|
|
20306
|
+
* ```
|
|
20307
|
+
*
|
|
20308
|
+
* Fired when a follower has been deleted
|
|
20309
|
+
*
|
|
20310
|
+
* @param callback The function to call when the event was fired
|
|
20311
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20312
|
+
*
|
|
20313
|
+
* @category Follow Events
|
|
20314
|
+
*/
|
|
20315
|
+
const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
|
|
20316
|
+
|
|
20317
|
+
/**
|
|
20318
|
+
* ```js
|
|
20319
|
+
* import { onFollowerRequested } from '@amityco/ts-sdk'
|
|
20320
|
+
* const dispose = onFollowerRequested(status => {
|
|
20321
|
+
* // ...
|
|
20322
|
+
* })
|
|
20323
|
+
* ```
|
|
20324
|
+
*
|
|
20325
|
+
* Fired when a user follows another users and confirmation is required
|
|
20326
|
+
*
|
|
20327
|
+
* @param callback The function to call when the event was fired
|
|
20328
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20329
|
+
*
|
|
20330
|
+
* @category Follow Events
|
|
20331
|
+
*/
|
|
20332
|
+
const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
|
|
20333
|
+
|
|
20334
|
+
/**
|
|
20335
|
+
* ```js
|
|
20336
|
+
* import { onFollowRequestCanceled } from '@amityco/ts-sdk'
|
|
20337
|
+
* const dispose = onFollowRequestCanceled(status => {
|
|
20338
|
+
* // ...
|
|
20339
|
+
* })
|
|
20340
|
+
* ```
|
|
20341
|
+
*
|
|
20342
|
+
* Fired when a follow request has been canceled
|
|
20343
|
+
*
|
|
20344
|
+
* @param callback The function to call when the event was fired
|
|
20345
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20346
|
+
*
|
|
20347
|
+
* @category Follow Events
|
|
20348
|
+
*/
|
|
20349
|
+
const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
|
|
20350
|
+
|
|
20351
|
+
/**
|
|
20352
|
+
* ```js
|
|
20353
|
+
* import { onFollowRequestAccepted } from '@amityco/ts-sdk'
|
|
20354
|
+
* const dispose = onFollowRequestAccepted(status => {
|
|
20355
|
+
* // ...
|
|
20356
|
+
* })
|
|
20357
|
+
* ```
|
|
20358
|
+
*
|
|
20359
|
+
* Fired when a follow request has been accepted
|
|
20360
|
+
*
|
|
20361
|
+
* @param callback The function to call when the event was fired
|
|
20362
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20363
|
+
*
|
|
20364
|
+
* @category Follow Events
|
|
20365
|
+
*/
|
|
20366
|
+
const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
|
|
20367
|
+
|
|
20368
|
+
/**
|
|
20369
|
+
* ```js
|
|
20370
|
+
* import { onFollowRequestDeclined } from '@amityco/ts-sdk'
|
|
20371
|
+
* const dispose = onFollowRequestDeclined(status => {
|
|
20372
|
+
* // ...
|
|
20373
|
+
* })
|
|
20374
|
+
* ```
|
|
20375
|
+
*
|
|
20376
|
+
* Fired when a follow request has been declined
|
|
20377
|
+
*
|
|
20378
|
+
* @param callback The function to call when the event was fired
|
|
20379
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20380
|
+
*
|
|
20381
|
+
* @category Follow Events
|
|
20382
|
+
*/
|
|
20383
|
+
const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
|
|
20384
|
+
|
|
20385
|
+
/**
|
|
20386
|
+
* ```js
|
|
20387
|
+
* import { onFollowInfoUpdated } from '@amityco/ts-sdk'
|
|
20388
|
+
* const dispose = onFollowInfoUpdated(followInfo => {
|
|
20389
|
+
* // ...
|
|
20390
|
+
* })
|
|
20391
|
+
* ```
|
|
20392
|
+
*
|
|
20393
|
+
* Fired when a {@link Amity.FollowInfo} has been updated
|
|
20394
|
+
*
|
|
20395
|
+
* @param callback The function to call when the event was fired
|
|
20396
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20397
|
+
*
|
|
20398
|
+
* @category Follow Events
|
|
20399
|
+
*/
|
|
20400
|
+
const onFollowInfoUpdated = (callback) => {
|
|
20401
|
+
const handler = async (payload) => {
|
|
20402
|
+
const [{ data: followInfoFrom }, { data: followInfoTo }] = await Promise.all([
|
|
20403
|
+
getFollowInfo(payload.from),
|
|
20404
|
+
getFollowInfo(payload.to),
|
|
20405
|
+
]);
|
|
20406
|
+
callback(followInfoFrom);
|
|
20407
|
+
callback(followInfoTo);
|
|
20408
|
+
};
|
|
20409
|
+
const disposers = [
|
|
20410
|
+
createFollowEventSubscriber('follow.created', handler),
|
|
20411
|
+
createFollowEventSubscriber('follow.requested', handler),
|
|
20412
|
+
createFollowEventSubscriber('follow.accepted', handler),
|
|
20413
|
+
createFollowEventSubscriber('follow.unfollowed', handler),
|
|
20414
|
+
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
20415
|
+
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
20416
|
+
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
20417
|
+
];
|
|
20418
|
+
return () => {
|
|
20419
|
+
disposers.forEach(fn => fn());
|
|
20420
|
+
};
|
|
20421
|
+
};
|
|
20422
|
+
|
|
20423
|
+
/**
|
|
20424
|
+
* ```js
|
|
20425
|
+
* import { observeFollowInfo } from '@amityco/ts-sdk'
|
|
20426
|
+
*
|
|
20427
|
+
* let followInfo = {}
|
|
20428
|
+
* const dispose = observeFollowInfo(userId, updated => followInfo = updated)
|
|
20429
|
+
* ```
|
|
20430
|
+
*
|
|
20431
|
+
* Observe all mutation on a given {@link Amity.FollowInfo}
|
|
20432
|
+
*
|
|
20433
|
+
* @param userId the ID of the user to observe
|
|
20434
|
+
* @param callback the function to call when new data are available
|
|
20435
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
|
|
20436
|
+
*
|
|
20437
|
+
* @category Follow Observer
|
|
20438
|
+
*/
|
|
20439
|
+
const observeFollowInfo = (userId, callback, policy = 'cache_then_server') => {
|
|
20440
|
+
const { log } = getActiveClient();
|
|
20441
|
+
const timestamp = Date.now();
|
|
20442
|
+
log(`observeFollowInfo(tmpid: ${timestamp}) > listen`);
|
|
20443
|
+
const router = (result, action) => {
|
|
20444
|
+
var _a, _b;
|
|
20445
|
+
if (callback instanceof Function)
|
|
20446
|
+
return callback(result);
|
|
20447
|
+
if (action !== 'onFetch')
|
|
20448
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
20449
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
20450
|
+
};
|
|
20451
|
+
const realtimeRouter = (result, action) => {
|
|
20452
|
+
var _a;
|
|
20453
|
+
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
|
|
20454
|
+
return;
|
|
20455
|
+
router(result, action);
|
|
20456
|
+
};
|
|
20457
|
+
const disposers = [];
|
|
20458
|
+
disposers.push(onFollowInfoUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')));
|
|
20459
|
+
runQuery(createQuery(getFollowInfo, userId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
20460
|
+
return () => {
|
|
20461
|
+
log(`observeFollowInfo(tmpid: ${timestamp}) > dispose`);
|
|
20462
|
+
disposers.forEach(fn => fn());
|
|
20463
|
+
};
|
|
20464
|
+
};
|
|
20465
|
+
|
|
20466
|
+
/**
|
|
20467
|
+
* ```js
|
|
20468
|
+
* import { observeFollowers } from '@amityco/ts-sdk'
|
|
20469
|
+
*
|
|
20470
|
+
* let followers = []
|
|
20471
|
+
* const unsub = observeFollowers('userId', follower => merge(followers, follower))
|
|
20472
|
+
* ```
|
|
20473
|
+
*
|
|
20474
|
+
* Observe all mutations on a list of followers {@link Amity.FollowStatus} for a given user
|
|
20475
|
+
*
|
|
20476
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20477
|
+
* @param callback the function to call when new data are available
|
|
20478
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
20479
|
+
*
|
|
20480
|
+
* @category Follow Observer
|
|
20481
|
+
*/
|
|
20482
|
+
const observeFollowers = (userId, callback) => {
|
|
20483
|
+
const { log } = getActiveClient();
|
|
20484
|
+
const timestamp = Date.now();
|
|
20485
|
+
log(`observeFollowers(tmpid: ${timestamp}) > listen`);
|
|
20486
|
+
const disposers = [];
|
|
20487
|
+
const router = (status, action) => {
|
|
20488
|
+
var _a, _b;
|
|
20489
|
+
if (status.from !== userId) {
|
|
20490
|
+
return;
|
|
20491
|
+
}
|
|
20492
|
+
if (callback instanceof Function) {
|
|
20493
|
+
return callback(status);
|
|
20494
|
+
}
|
|
20495
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
20496
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
20497
|
+
};
|
|
20498
|
+
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')));
|
|
20499
|
+
return () => {
|
|
20500
|
+
log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
|
|
20501
|
+
disposers.forEach(fn => fn());
|
|
20502
|
+
};
|
|
20503
|
+
};
|
|
20504
|
+
|
|
20505
|
+
/**
|
|
20506
|
+
* ```js
|
|
20507
|
+
* import { observeFollowings } from '@amityco/ts-sdk'
|
|
20508
|
+
*
|
|
20509
|
+
* let followings = []
|
|
20510
|
+
* const unsub = observeFollowers('userId', follower => merge(followings, following))
|
|
20511
|
+
* ```
|
|
20512
|
+
*
|
|
20513
|
+
* Observe all mutations on a list of followings {@link Amity.FollowStatus} for a given user
|
|
20514
|
+
*
|
|
20515
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20516
|
+
* @param callback the function to call when new data are available
|
|
20517
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
20518
|
+
*
|
|
20519
|
+
* @category Follow Observer
|
|
20520
|
+
*/
|
|
20521
|
+
const observeFollowings = (userId, callback) => {
|
|
20522
|
+
const { log } = getActiveClient();
|
|
20523
|
+
const timestamp = Date.now();
|
|
20524
|
+
log(`observeFollowings(tmpid: ${timestamp}) > listen`);
|
|
20525
|
+
const disposers = [];
|
|
20526
|
+
const router = (status, action) => {
|
|
20527
|
+
var _a, _b;
|
|
20528
|
+
if (status.to !== userId) {
|
|
20529
|
+
return;
|
|
20530
|
+
}
|
|
20531
|
+
if (callback instanceof Function) {
|
|
20532
|
+
return callback(status);
|
|
20533
|
+
}
|
|
20534
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
20535
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
20536
|
+
};
|
|
20537
|
+
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')));
|
|
20538
|
+
return () => {
|
|
20539
|
+
log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
|
|
20540
|
+
disposers.forEach(fn => fn());
|
|
20541
|
+
};
|
|
20542
|
+
};
|
|
20543
|
+
|
|
20544
|
+
/**
|
|
20545
|
+
* ```js
|
|
20546
|
+
* import { observePosts } from '@amityco/ts-sdk'
|
|
20547
|
+
*
|
|
20548
|
+
* let posts = []
|
|
20549
|
+
* const unsub = observePosts({
|
|
20550
|
+
* targetType: Amity.PostTargetType,
|
|
20551
|
+
* targetId: Amity.Post['targetId'],
|
|
20552
|
+
* }, post => merge(posts, post))
|
|
20553
|
+
* ```
|
|
20554
|
+
*
|
|
20555
|
+
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
20556
|
+
*
|
|
20557
|
+
* @param targetType the type of the target
|
|
20558
|
+
* @param targetId the ID of the target
|
|
20559
|
+
* @param callback the function to call when new data are available
|
|
20560
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
19568
20561
|
*
|
|
19569
20562
|
* @category Post Observer
|
|
19570
20563
|
*/
|
|
@@ -19575,8 +20568,7 @@ const observePosts = (params, callback) => {
|
|
|
19575
20568
|
const disposers = [];
|
|
19576
20569
|
const router = (post, action) => {
|
|
19577
20570
|
var _a, _b;
|
|
19578
|
-
if (params.targetId !== post.targetId
|
|
19579
|
-
|| params.targetType !== post.targetType)
|
|
20571
|
+
if (params.targetId !== post.targetId || params.targetType !== post.targetType)
|
|
19580
20572
|
return;
|
|
19581
20573
|
if (callback instanceof Function)
|
|
19582
20574
|
return callback(post);
|
|
@@ -19715,6 +20707,178 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
|
|
|
19715
20707
|
};
|
|
19716
20708
|
};
|
|
19717
20709
|
|
|
20710
|
+
/**
|
|
20711
|
+
* ```js
|
|
20712
|
+
* import { getPoll } from '@amityco/ts-sdk'
|
|
20713
|
+
* const poll = await getPoll('foobar')
|
|
20714
|
+
* ```
|
|
20715
|
+
*
|
|
20716
|
+
* Fetches a {@link Amity.Poll} object
|
|
20717
|
+
*
|
|
20718
|
+
* @param pollId the ID of the {@link Amity.Poll} to fetch
|
|
20719
|
+
* @returns the associated {@link Amity.Poll} object
|
|
20720
|
+
*
|
|
20721
|
+
* @category Poll API
|
|
20722
|
+
* @async
|
|
20723
|
+
*/
|
|
20724
|
+
const getPoll = async (pollId) => {
|
|
20725
|
+
const client = getActiveClient();
|
|
20726
|
+
client.log('poll/getPoll', pollId);
|
|
20727
|
+
const { data } = await client.http.get(`/api/v3/polls/${pollId}`);
|
|
20728
|
+
const cachedAt = client.cache && Date.now();
|
|
20729
|
+
if (client.cache)
|
|
20730
|
+
ingestInCache(data, { cachedAt });
|
|
20731
|
+
const { polls } = data;
|
|
20732
|
+
return {
|
|
20733
|
+
data: polls.find(poll => poll.pollId === pollId),
|
|
20734
|
+
cachedAt,
|
|
20735
|
+
};
|
|
20736
|
+
};
|
|
20737
|
+
/**
|
|
20738
|
+
* ```js
|
|
20739
|
+
* import { getPoll } from '@amityco/ts-sdk'
|
|
20740
|
+
* const poll = getPoll.locally('foobar')
|
|
20741
|
+
* ```
|
|
20742
|
+
*
|
|
20743
|
+
* Fetches a {@link Amity.Poll} object
|
|
20744
|
+
*
|
|
20745
|
+
* @param pollId the ID of the {@link Amity.Poll} to fetch
|
|
20746
|
+
* @returns the associated {@link Amity.Poll} object
|
|
20747
|
+
*
|
|
20748
|
+
* @category Poll API
|
|
20749
|
+
*/
|
|
20750
|
+
getPoll.locally = (pollId) => {
|
|
20751
|
+
const client = getActiveClient();
|
|
20752
|
+
client.log('poll/getPoll', pollId);
|
|
20753
|
+
if (!client.cache)
|
|
20754
|
+
return;
|
|
20755
|
+
const cached = pullFromCache(['poll', 'get', pollId]);
|
|
20756
|
+
if (!cached)
|
|
20757
|
+
return;
|
|
20758
|
+
return {
|
|
20759
|
+
data: cached.data,
|
|
20760
|
+
cachedAt: cached.cachedAt,
|
|
20761
|
+
};
|
|
20762
|
+
};
|
|
20763
|
+
|
|
20764
|
+
/**
|
|
20765
|
+
* ```js
|
|
20766
|
+
* import { createPoll } from '@amityco/ts-sdk'
|
|
20767
|
+
* const created = await createPoll({
|
|
20768
|
+
* question: 'question',
|
|
20769
|
+
* answers: [
|
|
20770
|
+
* { dataType: 'text', data: 'answer1' },
|
|
20771
|
+
* { dataType: 'text', data: 'answer2' },
|
|
20772
|
+
* ],
|
|
20773
|
+
* closedIn: 1649136484
|
|
20774
|
+
* }))
|
|
20775
|
+
* ```
|
|
20776
|
+
*
|
|
20777
|
+
* Creates an {@link Amity.Poll}
|
|
20778
|
+
*
|
|
20779
|
+
* @param bundle The data necessary to create a new {@link Amity.Poll}
|
|
20780
|
+
* @returns The newly created {@link Amity.Poll}
|
|
20781
|
+
*
|
|
20782
|
+
* @category Poll API
|
|
20783
|
+
* @async
|
|
20784
|
+
*/
|
|
20785
|
+
const createPoll = async (bundle) => {
|
|
20786
|
+
const client = getActiveClient();
|
|
20787
|
+
client.log('post/createPoll', bundle);
|
|
20788
|
+
const { data } = await client.http.post('/api/v3/polls', bundle);
|
|
20789
|
+
const cachedAt = client.cache && Date.now();
|
|
20790
|
+
if (client.cache)
|
|
20791
|
+
ingestInCache(data, { cachedAt });
|
|
20792
|
+
const { polls } = data;
|
|
20793
|
+
return {
|
|
20794
|
+
data: polls[0],
|
|
20795
|
+
cachedAt,
|
|
20796
|
+
};
|
|
20797
|
+
};
|
|
20798
|
+
|
|
20799
|
+
/**
|
|
20800
|
+
* ```js
|
|
20801
|
+
* import { closePoll } from '@amityco/ts-sdk'
|
|
20802
|
+
* const updated = await closePoll(pollId)
|
|
20803
|
+
* ```
|
|
20804
|
+
*
|
|
20805
|
+
* Updates an {@link Amity.Poll}
|
|
20806
|
+
*
|
|
20807
|
+
* @param pollId The ID of the {@link Amity.Poll} to close
|
|
20808
|
+
* @returns the updated {@link Amity.Poll} object
|
|
20809
|
+
*
|
|
20810
|
+
* @category Poll API
|
|
20811
|
+
* @async
|
|
20812
|
+
*/
|
|
20813
|
+
const closePoll = async (pollId) => {
|
|
20814
|
+
const client = getActiveClient();
|
|
20815
|
+
client.log('user/closePoll', pollId);
|
|
20816
|
+
const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}`, { status: 'closed' });
|
|
20817
|
+
const cachedAt = client.cache && Date.now();
|
|
20818
|
+
if (client.cache)
|
|
20819
|
+
ingestInCache(data, { cachedAt });
|
|
20820
|
+
const { polls } = data;
|
|
20821
|
+
return {
|
|
20822
|
+
data: polls.find(poll => poll.pollId === pollId),
|
|
20823
|
+
cachedAt,
|
|
20824
|
+
};
|
|
20825
|
+
};
|
|
20826
|
+
|
|
20827
|
+
/**
|
|
20828
|
+
* ```js
|
|
20829
|
+
* import { deletePoll } from '@amityco/ts-sdk'
|
|
20830
|
+
* const success = await deletePoll(pollId)
|
|
20831
|
+
* ```
|
|
20832
|
+
*
|
|
20833
|
+
* Deletes a {@link Amity.Poll}
|
|
20834
|
+
*
|
|
20835
|
+
* @param pollId The {@link Amity.Poll} ID to delete
|
|
20836
|
+
* @return A success boolean if the {@link Amity.Poll} was deleted
|
|
20837
|
+
*
|
|
20838
|
+
* @category Poll API
|
|
20839
|
+
* @async
|
|
20840
|
+
*/
|
|
20841
|
+
const deletePoll = async (pollId) => {
|
|
20842
|
+
const client = getActiveClient();
|
|
20843
|
+
client.log('poll/deletePoll', pollId);
|
|
20844
|
+
const poll = await getPoll(pollId);
|
|
20845
|
+
// API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
|
|
20846
|
+
const { data } = await client.http.delete(`/api/v3/polls/${pollId}`);
|
|
20847
|
+
const { success } = data; // unwrapPayload(data)
|
|
20848
|
+
const deleted = Object.assign(Object.assign({}, poll.data), { isDeleted: true });
|
|
20849
|
+
upsertInCache(['poll', 'get', pollId], deleted);
|
|
20850
|
+
return success;
|
|
20851
|
+
};
|
|
20852
|
+
|
|
20853
|
+
/**
|
|
20854
|
+
* ```js
|
|
20855
|
+
* import { votePoll } from '@amityco/ts-sdk'
|
|
20856
|
+
* const voted = await votePoll(pollId)
|
|
20857
|
+
* ```
|
|
20858
|
+
*
|
|
20859
|
+
* Votes for an {@link Amity.Poll}
|
|
20860
|
+
*
|
|
20861
|
+
* @param pollId The ID of the {@link Amity.Poll} to vote
|
|
20862
|
+
* @param answerIds The IDs of the {@link Amity.Poll} answers to vote {@link Amity.Poll}
|
|
20863
|
+
* @returns the updated {@link Amity.Poll} object
|
|
20864
|
+
*
|
|
20865
|
+
* @category Poll API
|
|
20866
|
+
* @async
|
|
20867
|
+
*/
|
|
20868
|
+
const votePoll = async (pollId, answerIds) => {
|
|
20869
|
+
const client = getActiveClient();
|
|
20870
|
+
client.log('user/votePoll', pollId);
|
|
20871
|
+
const { data } = await client.http.post(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds });
|
|
20872
|
+
const cachedAt = client.cache && Date.now();
|
|
20873
|
+
if (client.cache)
|
|
20874
|
+
ingestInCache(data, { cachedAt });
|
|
20875
|
+
const { polls } = data;
|
|
20876
|
+
return {
|
|
20877
|
+
data: polls.find(poll => poll.pollId === pollId),
|
|
20878
|
+
cachedAt,
|
|
20879
|
+
};
|
|
20880
|
+
};
|
|
20881
|
+
|
|
19718
20882
|
/**
|
|
19719
20883
|
* ```js
|
|
19720
20884
|
* import { getStream } from '@amityco/ts-sdk'
|
|
@@ -19787,9 +20951,11 @@ const queryStreams = async (query) => {
|
|
|
19787
20951
|
const client = getActiveClient();
|
|
19788
20952
|
client.log('stream/queryStreams', query);
|
|
19789
20953
|
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
19790
|
-
const { data } = await client.http.get(`/api/v3/video-streaming`, {
|
|
20954
|
+
const { data } = await client.http.get(`/api/v3/video-streaming`, {
|
|
20955
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
19791
20956
|
token: toToken(page, 'skiplimit'),
|
|
19792
|
-
} })
|
|
20957
|
+
} }),
|
|
20958
|
+
});
|
|
19793
20959
|
// API-FIX: backend to response Amity.Response: const { paging, videoStreamings } = unwrapPayload(data)
|
|
19794
20960
|
// API-FIX: seems returned data has a results identifier on top of data, like no other apis, and this is beautiful
|
|
19795
20961
|
const { paging, results: payload } = data;
|
|
@@ -19895,7 +21061,7 @@ const updateStream = async (streamId, patch) => {
|
|
|
19895
21061
|
const deleteStream = async (streamId) => {
|
|
19896
21062
|
const client = getActiveClient();
|
|
19897
21063
|
client.log('stream/deleteStream', streamId);
|
|
19898
|
-
|
|
21064
|
+
const stream = await getStream(streamId);
|
|
19899
21065
|
// API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
|
|
19900
21066
|
// API-FIX: swagger docs are wrong!
|
|
19901
21067
|
const { data } = await client.http.delete(`/api/v3/video-streaming/${streamId}`);
|
|
@@ -20008,12 +21174,14 @@ const onStreamRecorded = (callback) => {
|
|
|
20008
21174
|
|
|
20009
21175
|
exports.API_REGIONS = API_REGIONS;
|
|
20010
21176
|
exports.VERSION = VERSION$1;
|
|
21177
|
+
exports.acceptFollower = acceptFollower;
|
|
20011
21178
|
exports.addChannelMembers = addChannelMembers;
|
|
20012
21179
|
exports.addChannelMembersRole = addChannelMembersRole;
|
|
20013
21180
|
exports.addCommunityMembers = addCommunityMembers;
|
|
20014
|
-
exports.
|
|
21181
|
+
exports.addCommunityMembersRoles = addCommunityMembersRoles;
|
|
20015
21182
|
exports.addReaction = addReaction;
|
|
20016
21183
|
exports.backupCache = backupCache;
|
|
21184
|
+
exports.closePoll = closePoll;
|
|
20017
21185
|
exports.connectClient = connectClient;
|
|
20018
21186
|
exports.createChannel = createChannel;
|
|
20019
21187
|
exports.createClient = createClient;
|
|
@@ -20021,15 +21189,19 @@ exports.createComment = createComment;
|
|
|
20021
21189
|
exports.createCommunity = createCommunity;
|
|
20022
21190
|
exports.createFile = createFile;
|
|
20023
21191
|
exports.createMessage = createMessage;
|
|
21192
|
+
exports.createPoll = createPoll;
|
|
20024
21193
|
exports.createPost = createPost;
|
|
20025
21194
|
exports.createQuery = createQuery;
|
|
20026
21195
|
exports.createReport = createReport;
|
|
20027
21196
|
exports.createStream = createStream;
|
|
21197
|
+
exports.createVideo = createVideo;
|
|
21198
|
+
exports.declineFollower = declineFollower;
|
|
20028
21199
|
exports.deleteChannel = deleteChannel;
|
|
20029
21200
|
exports.deleteComment = deleteComment;
|
|
20030
21201
|
exports.deleteCommunity = deleteCommunity;
|
|
20031
21202
|
exports.deleteFile = deleteFile;
|
|
20032
21203
|
exports.deleteMessage = deleteMessage;
|
|
21204
|
+
exports.deletePoll = deletePoll;
|
|
20033
21205
|
exports.deletePost = deletePost;
|
|
20034
21206
|
exports.deleteReport = deleteReport;
|
|
20035
21207
|
exports.deleteStream = deleteStream;
|
|
@@ -20040,7 +21212,9 @@ exports.dropFromCache = dropFromCache;
|
|
|
20040
21212
|
exports.enableCache = enableCache;
|
|
20041
21213
|
exports.fileUrlWithSize = fileUrlWithSize;
|
|
20042
21214
|
exports.filterByPropEquality = filterByPropEquality;
|
|
21215
|
+
exports.follow = follow;
|
|
20043
21216
|
exports.getActiveClient = getActiveClient;
|
|
21217
|
+
exports.getCategory = getCategory;
|
|
20044
21218
|
exports.getChannel = getChannel;
|
|
20045
21219
|
exports.getChannels = getChannels;
|
|
20046
21220
|
exports.getComment = getComment;
|
|
@@ -20050,13 +21224,19 @@ exports.getCommunities = getCommunities;
|
|
|
20050
21224
|
exports.getCommunity = getCommunity;
|
|
20051
21225
|
exports.getCommunityTopic = getCommunityTopic;
|
|
20052
21226
|
exports.getFile = getFile;
|
|
21227
|
+
exports.getFollowInfo = getFollowInfo;
|
|
20053
21228
|
exports.getMessage = getMessage;
|
|
20054
21229
|
exports.getMessages = getMessages;
|
|
21230
|
+
exports.getMyFollowersTopic = getMyFollowersTopic;
|
|
21231
|
+
exports.getMyFollowingsTopic = getMyFollowingsTopic;
|
|
21232
|
+
exports.getPoll = getPoll;
|
|
20055
21233
|
exports.getPost = getPost;
|
|
20056
21234
|
exports.getPostTopic = getPostTopic;
|
|
20057
21235
|
exports.getPosts = getPosts;
|
|
21236
|
+
exports.getRecommendedCommunities = getRecommendedCommunities;
|
|
20058
21237
|
exports.getRole = getRole;
|
|
20059
21238
|
exports.getStream = getStream;
|
|
21239
|
+
exports.getTopTrendingCommunities = getTopTrendingCommunities;
|
|
20060
21240
|
exports.getUser = getUser;
|
|
20061
21241
|
exports.getUserTopic = getUserTopic;
|
|
20062
21242
|
exports.getUsers = getUsers;
|
|
@@ -20082,6 +21262,9 @@ exports.observeComment = observeComment;
|
|
|
20082
21262
|
exports.observeComments = observeComments;
|
|
20083
21263
|
exports.observeCommunity = observeCommunity;
|
|
20084
21264
|
exports.observeFile = observeFile;
|
|
21265
|
+
exports.observeFollowInfo = observeFollowInfo;
|
|
21266
|
+
exports.observeFollowers = observeFollowers;
|
|
21267
|
+
exports.observeFollowings = observeFollowings;
|
|
20085
21268
|
exports.observeMessage = observeMessage;
|
|
20086
21269
|
exports.observeMessages = observeMessages;
|
|
20087
21270
|
exports.observePost = observePost;
|
|
@@ -20110,6 +21293,12 @@ exports.onCommunityUserBanned = onCommunityUserBanned;
|
|
|
20110
21293
|
exports.onCommunityUserRemoved = onCommunityUserRemoved;
|
|
20111
21294
|
exports.onCommunityUserUnbanned = onCommunityUserUnbanned;
|
|
20112
21295
|
exports.onConnectionError = onConnectionError;
|
|
21296
|
+
exports.onFollowInfoUpdated = onFollowInfoUpdated;
|
|
21297
|
+
exports.onFollowRequestAccepted = onFollowRequestAccepted;
|
|
21298
|
+
exports.onFollowRequestCanceled = onFollowRequestCanceled;
|
|
21299
|
+
exports.onFollowRequestDeclined = onFollowRequestDeclined;
|
|
21300
|
+
exports.onFollowerDeleted = onFollowerDeleted;
|
|
21301
|
+
exports.onFollowerRequested = onFollowerRequested;
|
|
20113
21302
|
exports.onMemberAdded = onMemberAdded;
|
|
20114
21303
|
exports.onMemberRemoved = onMemberRemoved;
|
|
20115
21304
|
exports.onMessageCreated = onMessageCreated;
|
|
@@ -20130,16 +21319,21 @@ exports.onStreamStarted = onStreamStarted;
|
|
|
20130
21319
|
exports.onStreamStopped = onStreamStopped;
|
|
20131
21320
|
exports.onUserFlagCleared = onUserFlagCleared;
|
|
20132
21321
|
exports.onUserFlagged = onUserFlagged;
|
|
21322
|
+
exports.onUserFollowed = onUserFollowed;
|
|
20133
21323
|
exports.onUserUnflagged = onUserUnflagged;
|
|
21324
|
+
exports.onUserUnfollowed = onUserUnfollowed;
|
|
20134
21325
|
exports.onUserUpdated = onUserUpdated;
|
|
20135
21326
|
exports.pullFromCache = pullFromCache;
|
|
20136
21327
|
exports.pushToCache = pushToCache;
|
|
20137
21328
|
exports.queryCache = queryCache;
|
|
21329
|
+
exports.queryCategories = queryCategories;
|
|
20138
21330
|
exports.queryChannelMembers = queryChannelMembers;
|
|
20139
21331
|
exports.queryChannels = queryChannels;
|
|
20140
21332
|
exports.queryComments = queryComments;
|
|
20141
21333
|
exports.queryCommunities = queryCommunities;
|
|
20142
21334
|
exports.queryCommunityMembers = queryCommunityMembers;
|
|
21335
|
+
exports.queryFollowers = queryFollowers;
|
|
21336
|
+
exports.queryFollowings = queryFollowings;
|
|
20143
21337
|
exports.queryGlobalFeed = queryGlobalFeed;
|
|
20144
21338
|
exports.queryMessages = queryMessages;
|
|
20145
21339
|
exports.queryOptions = queryOptions;
|
|
@@ -20150,7 +21344,7 @@ exports.queryUsers = queryUsers;
|
|
|
20150
21344
|
exports.removeChannelMembers = removeChannelMembers;
|
|
20151
21345
|
exports.removeChannelMembersRole = removeChannelMembersRole;
|
|
20152
21346
|
exports.removeCommunityMembers = removeCommunityMembers;
|
|
20153
|
-
exports.
|
|
21347
|
+
exports.removeCommunityMembersRoles = removeCommunityMembersRoles;
|
|
20154
21348
|
exports.removeReaction = removeReaction;
|
|
20155
21349
|
exports.restoreCache = restoreCache;
|
|
20156
21350
|
exports.runQuery = runQuery;
|
|
@@ -20164,6 +21358,7 @@ exports.subscribeTopic = subscribeTopic;
|
|
|
20164
21358
|
exports.toPage = toPage;
|
|
20165
21359
|
exports.toPageRaw = toPageRaw;
|
|
20166
21360
|
exports.toToken = toToken;
|
|
21361
|
+
exports.unfollow = unfollow;
|
|
20167
21362
|
exports.updateChannel = updateChannel;
|
|
20168
21363
|
exports.updateComment = updateComment;
|
|
20169
21364
|
exports.updateCommunity = updateCommunity;
|
|
@@ -20172,4 +21367,5 @@ exports.updatePost = updatePost;
|
|
|
20172
21367
|
exports.updateStream = updateStream;
|
|
20173
21368
|
exports.updateUser = updateUser;
|
|
20174
21369
|
exports.upsertInCache = upsertInCache;
|
|
21370
|
+
exports.votePoll = votePoll;
|
|
20175
21371
|
exports.wipeCache = wipeCache;
|