@amityco/ts-sdk 0.0.1-beta.14 → 0.0.1-beta.17
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/README.md +3 -3
- 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 +12 -3
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +29 -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 +11 -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/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 +1 -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 +4 -4
- 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 +12 -0
- package/dist/client/utils/endpoints.d.ts.map +1 -0
- 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 +1 -0
- 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 +1285 -267
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1258 -266
- 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/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 +38 -33
- package/src/@types/core/paging.ts +31 -31
- package/src/@types/core/payload.ts +85 -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/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 +24 -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 -9
- 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 +26 -22
- 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 +14 -0
- 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 +9 -7
- package/src/core/model/identifyModel.ts +15 -11
- package/src/core/model/index.ts +8 -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 +38 -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 +20 -19
- 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 +41 -34
- 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/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 +6 -3
- 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/dist/core/network.d.ts +0 -11
- package/dist/core/network.d.ts.map +0 -1
- package/src/community/api/addCommunityMembersRole.ts +0 -41
- package/src/community/api/removeCommunityMembersRole.ts +0 -41
- package/src/core/network.ts +0 -14
package/dist/index.cjs.js
CHANGED
|
@@ -20,6 +20,7 @@ var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
|
|
|
20
20
|
var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
|
|
21
21
|
|
|
22
22
|
var _a$1;
|
|
23
|
+
/* eslint-disable no-undef */
|
|
23
24
|
const theGlobal = globalThis || global || window;
|
|
24
25
|
const { process: safeProcess = {} } = theGlobal;
|
|
25
26
|
const isProduction = ((_a$1 = safeProcess.env) === null || _a$1 === void 0 ? void 0 : _a$1.NODE_ENV) === 'production';
|
|
@@ -35,7 +36,7 @@ const VERSION$1 = (_b = (_a = safeProcess.env) === null || _a === void 0 ? void
|
|
|
35
36
|
*
|
|
36
37
|
* @hidden
|
|
37
38
|
*/
|
|
38
|
-
const isSkipLimit = (json) =>
|
|
39
|
+
const isSkipLimit = (json) => ['skip', 'limit'].some(prop => prop in json);
|
|
39
40
|
/**
|
|
40
41
|
* Type guard to find if the a given decoded backend token uses "after/before" pagination style
|
|
41
42
|
*
|
|
@@ -44,7 +45,7 @@ const isSkipLimit = (json) => (['skip', 'limit'].some(prop => prop in json));
|
|
|
44
45
|
*
|
|
45
46
|
* @hidden
|
|
46
47
|
*/
|
|
47
|
-
const isAfterBefore = (json) =>
|
|
48
|
+
const isAfterBefore = (json) => ['after', 'before', 'first', 'last', 'limit'].some(prop => prop in json);
|
|
48
49
|
/**
|
|
49
50
|
* Type guard to find if the a given decoded backend token uses v4 or newer "after/before" pagination style
|
|
50
51
|
*
|
|
@@ -53,7 +54,7 @@ const isAfterBefore = (json) => (['after', 'before', 'first', 'last', 'limit'].s
|
|
|
53
54
|
*
|
|
54
55
|
* @hidden
|
|
55
56
|
*/
|
|
56
|
-
const isAfterBeforeRaw = (json) =>
|
|
57
|
+
const isAfterBeforeRaw = (json) => 'limit' in json;
|
|
57
58
|
/**
|
|
58
59
|
* Type guard to find if the a given object is wrapped around Amity.Paged<>
|
|
59
60
|
*
|
|
@@ -63,9 +64,9 @@ const isAfterBeforeRaw = (json) => ('limit' in json);
|
|
|
63
64
|
* @hidden
|
|
64
65
|
*/
|
|
65
66
|
const isPaged = (payload) => {
|
|
66
|
-
return ((payload === null || payload === void 0 ? void 0 : payload.hasOwnProperty('data'))
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
return ((payload === null || payload === void 0 ? void 0 : payload.hasOwnProperty('data')) &&
|
|
68
|
+
(payload === null || payload === void 0 ? void 0 : payload.hasOwnProperty('nextPage')) &&
|
|
69
|
+
(payload === null || payload === void 0 ? void 0 : payload.hasOwnProperty('prevPage')));
|
|
69
70
|
};
|
|
70
71
|
/**
|
|
71
72
|
* Converts a paging object into a b64 string token
|
|
@@ -95,19 +96,19 @@ const toToken = (paging, style) => {
|
|
|
95
96
|
"before" or "after" value. if that would change,
|
|
96
97
|
we'd need to move toward a more simple: `!paging.before`
|
|
97
98
|
*/
|
|
98
|
-
if (!isNaN(paging === null || paging === void 0 ? void 0 : paging.before)) {
|
|
99
|
+
if (!Number.isNaN(paging === null || paging === void 0 ? void 0 : paging.before)) {
|
|
99
100
|
payload = {
|
|
100
101
|
before: paging.before,
|
|
101
102
|
last: paging.limit,
|
|
102
103
|
};
|
|
103
104
|
}
|
|
104
|
-
else if (!isNaN(paging === null || paging === void 0 ? void 0 : paging.after)) {
|
|
105
|
+
else if (!Number.isNaN(paging === null || paging === void 0 ? void 0 : paging.after)) {
|
|
105
106
|
payload = {
|
|
106
107
|
after: paging.after,
|
|
107
108
|
first: paging.limit,
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
|
-
else if (!isNaN(paging === null || paging === void 0 ? void 0 : paging.limit)) {
|
|
111
|
+
else if (!Number.isNaN(paging === null || paging === void 0 ? void 0 : paging.limit)) {
|
|
111
112
|
payload = {
|
|
112
113
|
last: paging.limit,
|
|
113
114
|
};
|
|
@@ -132,7 +133,7 @@ const toToken = (paging, style) => {
|
|
|
132
133
|
*/
|
|
133
134
|
const toPage = (token) => {
|
|
134
135
|
if (!token)
|
|
135
|
-
return
|
|
136
|
+
return undefined;
|
|
136
137
|
// don't try catch, let it throw
|
|
137
138
|
const json = JSON.parse(jsBase64.decode(token));
|
|
138
139
|
if (isSkipLimit(json)) {
|
|
@@ -141,21 +142,21 @@ const toPage = (token) => {
|
|
|
141
142
|
limit: json.limit,
|
|
142
143
|
};
|
|
143
144
|
}
|
|
144
|
-
|
|
145
|
+
if (isAfterBefore(json)) {
|
|
145
146
|
if ('before' in json) {
|
|
146
147
|
return {
|
|
147
148
|
before: json.before,
|
|
148
149
|
limit: json.last,
|
|
149
150
|
};
|
|
150
151
|
}
|
|
151
|
-
|
|
152
|
+
if ('after' in json) {
|
|
152
153
|
return {
|
|
153
154
|
after: json.after,
|
|
154
155
|
limit: json.first,
|
|
155
156
|
};
|
|
156
157
|
}
|
|
157
158
|
}
|
|
158
|
-
return
|
|
159
|
+
return undefined;
|
|
159
160
|
};
|
|
160
161
|
/**
|
|
161
162
|
* Converts a b64 string token into a paging object
|
|
@@ -167,15 +168,16 @@ const toPage = (token) => {
|
|
|
167
168
|
*/
|
|
168
169
|
const toPageRaw = (token) => {
|
|
169
170
|
if (!token)
|
|
170
|
-
return
|
|
171
|
+
return undefined;
|
|
171
172
|
// don't try catch, let it throw
|
|
172
173
|
const json = JSON.parse(jsBase64.decode(token));
|
|
173
174
|
if (isAfterBeforeRaw(json)) {
|
|
174
175
|
return json;
|
|
175
176
|
}
|
|
176
|
-
return
|
|
177
|
+
return undefined;
|
|
177
178
|
};
|
|
178
179
|
|
|
180
|
+
/* eslint-disable no-use-before-define */
|
|
179
181
|
/**
|
|
180
182
|
* Type guard to check and cast that a given async function is has the ".locally" property
|
|
181
183
|
*
|
|
@@ -184,7 +186,7 @@ const toPageRaw = (token) => {
|
|
|
184
186
|
*
|
|
185
187
|
* @hidden
|
|
186
188
|
*/
|
|
187
|
-
const isFetcher = (func) =>
|
|
189
|
+
const isFetcher = (func) => 'locally' in func;
|
|
188
190
|
/**
|
|
189
191
|
* Type guard to check and cast that a given async function is has the ".optimistically" property
|
|
190
192
|
*
|
|
@@ -193,7 +195,7 @@ const isFetcher = (func) => ('locally' in func);
|
|
|
193
195
|
*
|
|
194
196
|
* @hidden
|
|
195
197
|
*/
|
|
196
|
-
const isMutator = (func) =>
|
|
198
|
+
const isMutator = (func) => 'optimistically' in func;
|
|
197
199
|
/**
|
|
198
200
|
* Type guard to check and cast that a given async function is has
|
|
199
201
|
* the ".locally" or ".optimistically" property
|
|
@@ -212,7 +214,7 @@ const isOffline = (func) => isFetcher(func) || isMutator(func);
|
|
|
212
214
|
*
|
|
213
215
|
* @hidden
|
|
214
216
|
*/
|
|
215
|
-
const isCachable = (model) =>
|
|
217
|
+
const isCachable = (model) => model === null || model === void 0 ? void 0 : model.hasOwnProperty('cachedAt');
|
|
216
218
|
/**
|
|
217
219
|
* Checks if a model is considered local (cachedAt === -1)
|
|
218
220
|
*
|
|
@@ -270,7 +272,7 @@ const createQuery = (func, ...args) => ({ func, args });
|
|
|
270
272
|
const queryOptions = (policy, lifeSpan = 2 * 60 * 1000) => {
|
|
271
273
|
if (policy === 'cache_only')
|
|
272
274
|
return { lifeSpan: Infinity };
|
|
273
|
-
|
|
275
|
+
if (policy === 'server_only')
|
|
274
276
|
return { lifeSpan: 0 };
|
|
275
277
|
return { lifeSpan };
|
|
276
278
|
};
|
|
@@ -296,9 +298,7 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
296
298
|
// offline first
|
|
297
299
|
if (isOffline(func) && options.lifeSpan !== 0) {
|
|
298
300
|
try {
|
|
299
|
-
local = isMutator(func)
|
|
300
|
-
? func.optimistically(...args)
|
|
301
|
-
: func.locally(...args);
|
|
301
|
+
local = isMutator(func) ? func.optimistically(...args) : func.locally(...args);
|
|
302
302
|
}
|
|
303
303
|
catch (error) {
|
|
304
304
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(undefined, {
|
|
@@ -310,7 +310,7 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
310
310
|
const shouldAbort = isCachable(local) && isFresh(local, options.lifeSpan);
|
|
311
311
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(local, {
|
|
312
312
|
origin: 'local',
|
|
313
|
-
loading: !(isFetcher(func) && shouldAbort)
|
|
313
|
+
loading: !(isFetcher(func) && shouldAbort),
|
|
314
314
|
}));
|
|
315
315
|
if (shouldAbort)
|
|
316
316
|
return;
|
|
@@ -318,13 +318,13 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
318
318
|
else {
|
|
319
319
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(undefined, {
|
|
320
320
|
origin: 'local',
|
|
321
|
-
loading: true
|
|
321
|
+
loading: true,
|
|
322
322
|
}));
|
|
323
323
|
}
|
|
324
324
|
func(...args)
|
|
325
325
|
.then(fresh => {
|
|
326
326
|
// @ts-ignore i know.
|
|
327
|
-
//
|
|
327
|
+
// isLocal(local) && syncInCache(local, fresh)
|
|
328
328
|
callback === null || callback === void 0 ? void 0 : callback(createSnapshot(fresh, {
|
|
329
329
|
origin: 'server',
|
|
330
330
|
loading: false,
|
|
@@ -338,6 +338,7 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
338
338
|
}));
|
|
339
339
|
});
|
|
340
340
|
};
|
|
341
|
+
// eslint-disable-next-line no-redeclare
|
|
341
342
|
function createSnapshot(data, options) {
|
|
342
343
|
if (isPaged(data) || isCachable(data))
|
|
343
344
|
return Object.assign(Object.assign({}, options), data);
|
|
@@ -391,6 +392,7 @@ const sortByLastCreated = ({ createdAt: a }, { createdAt: b }) => new Date(b).va
|
|
|
391
392
|
*/
|
|
392
393
|
const sortByLastActivity = ({ lastActivity: a }, { lastActivity: b }) => new Date(b).valueOf() - new Date(a).valueOf();
|
|
393
394
|
|
|
395
|
+
/* eslint-disable max-classes-per-file */
|
|
394
396
|
/**
|
|
395
397
|
* Generic ASC error
|
|
396
398
|
* @category Errors
|
|
@@ -420,6 +422,7 @@ class ASCApiError extends ASCError {
|
|
|
420
422
|
* @param code A normalized error code
|
|
421
423
|
* @param level A normalized failure level descriptor
|
|
422
424
|
*/
|
|
425
|
+
// eslint-disable-next-line no-useless-constructor
|
|
423
426
|
constructor(message, code, level) {
|
|
424
427
|
super(message, code, level);
|
|
425
428
|
}
|
|
@@ -446,7 +449,9 @@ class ASCConnectionError extends ASCError {
|
|
|
446
449
|
* @param message A custom error message
|
|
447
450
|
*/
|
|
448
451
|
constructor(event, message = 'SDK client is having connection issues') {
|
|
449
|
-
super(`${message} (${event})`, event === 'disconnected'
|
|
452
|
+
super(`${message} (${event})`, event === 'disconnected'
|
|
453
|
+
? 800211 /* DISCONNECTED */
|
|
454
|
+
: 800210 /* CONNECTION_ERROR */, "error" /* ERROR */);
|
|
450
455
|
this.event = event;
|
|
451
456
|
}
|
|
452
457
|
}
|
|
@@ -486,29 +491,28 @@ const setActiveClient = (client) => {
|
|
|
486
491
|
* @hidden
|
|
487
492
|
*/
|
|
488
493
|
const createLogger = (session) => {
|
|
489
|
-
const active =
|
|
490
|
-
&& !isProduction);
|
|
494
|
+
const active = `${session === null || session === void 0 ? void 0 : session.trim()}`.length > 0 && !isProduction;
|
|
491
495
|
const logger = debug__default['default'](session);
|
|
492
496
|
const print = (topic, ...args) => {
|
|
493
497
|
active && logger(topic, args);
|
|
494
498
|
};
|
|
499
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
495
500
|
print.__instance__ = logger;
|
|
496
501
|
return print;
|
|
497
502
|
};
|
|
498
503
|
|
|
499
|
-
const
|
|
504
|
+
const API_REGIONS = {
|
|
500
505
|
EU: 'eu',
|
|
501
506
|
SG: 'sg',
|
|
502
507
|
US: 'us',
|
|
503
508
|
};
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
};
|
|
509
|
+
const URLS = {
|
|
510
|
+
http: 'https://api.{region}.amity.co',
|
|
511
|
+
mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
|
|
512
|
+
};
|
|
513
|
+
function computeUrl(type, region) {
|
|
514
|
+
return URLS[type].replace('{region}', region);
|
|
515
|
+
}
|
|
512
516
|
|
|
513
517
|
/**
|
|
514
518
|
* Unwraps v3 server payload (for error handling and type extraction)
|
|
@@ -525,7 +529,7 @@ const unwrapPayload = (response) => {
|
|
|
525
529
|
if (response.status === 'success') {
|
|
526
530
|
return response.data;
|
|
527
531
|
}
|
|
528
|
-
|
|
532
|
+
if (response.status === 'fail') {
|
|
529
533
|
throw new ASCUnknownError(response.code);
|
|
530
534
|
}
|
|
531
535
|
else if (response.status === 'error') {
|
|
@@ -547,9 +551,10 @@ const stringify = (params, prefix) => {
|
|
|
547
551
|
if (Array.isArray(value)) {
|
|
548
552
|
return value.map(item => `${key}[]=${item}`).join('&');
|
|
549
553
|
}
|
|
550
|
-
|
|
554
|
+
if (typeof value !== 'object') {
|
|
551
555
|
return `${key}=${value}`;
|
|
552
556
|
}
|
|
557
|
+
// @ts-ignore
|
|
553
558
|
return stringify(value, prefix !== null && prefix !== void 0 ? prefix : name);
|
|
554
559
|
})
|
|
555
560
|
.join('&');
|
|
@@ -576,9 +581,10 @@ const createHttpTransport = (endpoint) => {
|
|
|
576
581
|
httpsAgent: new HttpAgent.HttpsAgent(options),
|
|
577
582
|
paramsSerializer: stringify,
|
|
578
583
|
});
|
|
579
|
-
instance.interceptors.response.use(
|
|
584
|
+
instance.interceptors.response.use(response => response, error => {
|
|
580
585
|
var _a;
|
|
581
586
|
const { response } = error;
|
|
587
|
+
// eslint-disable-next-line no-console
|
|
582
588
|
console.error((_a = response === null || response === void 0 ? void 0 : response.data) !== null && _a !== void 0 ? _a : error);
|
|
583
589
|
if (response)
|
|
584
590
|
unwrapPayload(response.data);
|
|
@@ -14596,6 +14602,7 @@ function extend() {
|
|
|
14596
14602
|
|
|
14597
14603
|
var mqtt = mqtt$1.exports;
|
|
14598
14604
|
|
|
14605
|
+
/* eslint-disable no-console */
|
|
14599
14606
|
const QOS_FAILURE_CODE = 128;
|
|
14600
14607
|
const RETRY_BASE_TIMEOUT = 1000;
|
|
14601
14608
|
const RETRY_COUNT_MAX = 10;
|
|
@@ -14610,7 +14617,7 @@ function getMqttOptions(params) {
|
|
|
14610
14617
|
topic: 'WillMsg',
|
|
14611
14618
|
payload: 'Connection Closed abnormally..!',
|
|
14612
14619
|
qos: 0,
|
|
14613
|
-
retain: false
|
|
14620
|
+
retain: false,
|
|
14614
14621
|
} }, params);
|
|
14615
14622
|
}
|
|
14616
14623
|
/**
|
|
@@ -14626,6 +14633,12 @@ const createMqttTransport = (endpoint) => {
|
|
|
14626
14633
|
let mqttClient;
|
|
14627
14634
|
let retryCount = 0;
|
|
14628
14635
|
let allowReconnection = true;
|
|
14636
|
+
const reconnect = () => {
|
|
14637
|
+
setTimeout(() => {
|
|
14638
|
+
retryCount += 1;
|
|
14639
|
+
mqttClient.reconnect();
|
|
14640
|
+
}, RETRY_BASE_TIMEOUT * 2 ** (retryCount > RETRY_COUNT_MAX ? RETRY_COUNT_MAX : retryCount));
|
|
14641
|
+
};
|
|
14629
14642
|
async function connect(params) {
|
|
14630
14643
|
if (mqttClient) {
|
|
14631
14644
|
mqttClient.removeAllListeners();
|
|
@@ -14637,6 +14650,7 @@ const createMqttTransport = (endpoint) => {
|
|
|
14637
14650
|
allowReconnection = true;
|
|
14638
14651
|
});
|
|
14639
14652
|
mqttClient.on('error', (error) => {
|
|
14653
|
+
// eslint-disable-next-line default-case
|
|
14640
14654
|
switch (error.code) {
|
|
14641
14655
|
case 2 /* IDENTIFIER_REJECTED */:
|
|
14642
14656
|
case 4 /* BAD_USERNAME_OR_PASSWORD */:
|
|
@@ -14651,12 +14665,6 @@ const createMqttTransport = (endpoint) => {
|
|
|
14651
14665
|
});
|
|
14652
14666
|
return new Promise(resolve => mqttClient.once('connect', () => resolve()));
|
|
14653
14667
|
}
|
|
14654
|
-
const reconnect = () => {
|
|
14655
|
-
setTimeout(() => {
|
|
14656
|
-
retryCount = retryCount + 1;
|
|
14657
|
-
mqttClient.reconnect();
|
|
14658
|
-
}, RETRY_BASE_TIMEOUT * Math.pow(2, retryCount > RETRY_COUNT_MAX ? RETRY_COUNT_MAX : retryCount));
|
|
14659
|
-
};
|
|
14660
14668
|
return {
|
|
14661
14669
|
connect,
|
|
14662
14670
|
async disconnect() {
|
|
@@ -14690,8 +14698,8 @@ const createMqttTransport = (endpoint) => {
|
|
|
14690
14698
|
if (error || granted[0].qos === QOS_FAILURE_CODE) {
|
|
14691
14699
|
const ascError = error
|
|
14692
14700
|
? new ASCError(error.message, 800000 /* UNKNOWN_ERROR */, "error" /* ERROR */)
|
|
14693
|
-
// TODO throw the actual error, once BE can tell us the actual error code
|
|
14694
|
-
|
|
14701
|
+
: // TODO throw the actual error, once BE can tell us the actual error code
|
|
14702
|
+
new ASCUnknownError(800000 /* UNKNOWN_ERROR */, "error" /* ERROR */);
|
|
14695
14703
|
console.error(`Failed to subscribe to topic ${topic}`, ascError);
|
|
14696
14704
|
callback === null || callback === void 0 ? void 0 : callback(ascError);
|
|
14697
14705
|
}
|
|
@@ -14710,10 +14718,11 @@ const createMqttTransport = (endpoint) => {
|
|
|
14710
14718
|
},
|
|
14711
14719
|
unsubscribe(topic) {
|
|
14712
14720
|
mqttClient === null || mqttClient === void 0 ? void 0 : mqttClient.unsubscribe(topic);
|
|
14713
|
-
}
|
|
14721
|
+
},
|
|
14714
14722
|
};
|
|
14715
14723
|
};
|
|
14716
14724
|
|
|
14725
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
14717
14726
|
let tasks = [];
|
|
14718
14727
|
let timer;
|
|
14719
14728
|
/**
|
|
@@ -14730,6 +14739,7 @@ const scheduleTask = (task) => {
|
|
|
14730
14739
|
}, 0);
|
|
14731
14740
|
};
|
|
14732
14741
|
|
|
14742
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
14733
14743
|
// need to sync up the list
|
|
14734
14744
|
const WS_EVENTS = [
|
|
14735
14745
|
'disconnected',
|
|
@@ -14756,7 +14766,7 @@ const MQTT_EVENTS = [
|
|
|
14756
14766
|
'error',
|
|
14757
14767
|
'close',
|
|
14758
14768
|
'end',
|
|
14759
|
-
'reconnect'
|
|
14769
|
+
'reconnect',
|
|
14760
14770
|
];
|
|
14761
14771
|
/** @hidden */
|
|
14762
14772
|
const createEventEmitter = () => {
|
|
@@ -14820,7 +14830,9 @@ const createEventSubscriber = (client, namespace, event, fn) => {
|
|
|
14820
14830
|
*/
|
|
14821
14831
|
const fireEvent = (event, payload) => {
|
|
14822
14832
|
const { emitter } = getActiveClient();
|
|
14823
|
-
scheduleTask(() => {
|
|
14833
|
+
scheduleTask(() => {
|
|
14834
|
+
emitter.emit(event, payload);
|
|
14835
|
+
});
|
|
14824
14836
|
};
|
|
14825
14837
|
|
|
14826
14838
|
/**
|
|
@@ -14832,21 +14844,21 @@ const fireEvent = (event, payload) => {
|
|
|
14832
14844
|
* Creates a new {@link Amity.Client} instance
|
|
14833
14845
|
*
|
|
14834
14846
|
* @param apiKey for the {@link Amity.Client} instance
|
|
14835
|
-
* @param
|
|
14847
|
+
* @param apiRegion endpoint to connect to
|
|
14836
14848
|
* @param debugSession session's identifier for the client's logger instance
|
|
14837
14849
|
* @returns A {@link Amity.Client} instance
|
|
14838
14850
|
*
|
|
14839
14851
|
* @category Client API
|
|
14840
|
-
|
|
14841
|
-
const createClient = (apiKey,
|
|
14852
|
+
* */
|
|
14853
|
+
const createClient = (apiKey, apiRegion = API_REGIONS.SG, debugSession = 'amity') => {
|
|
14842
14854
|
const log = createLogger(debugSession);
|
|
14843
14855
|
log('client/api/createClient', {
|
|
14844
14856
|
apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
|
|
14845
|
-
|
|
14857
|
+
apiRegion,
|
|
14846
14858
|
});
|
|
14847
|
-
const http = createHttpTransport(
|
|
14848
|
-
const ws = createWebsocketTransport(
|
|
14849
|
-
const mqtt = createMqttTransport(
|
|
14859
|
+
const http = createHttpTransport(computeUrl('http', apiRegion));
|
|
14860
|
+
const ws = createWebsocketTransport(computeUrl('http', apiRegion));
|
|
14861
|
+
const mqtt = createMqttTransport(computeUrl('mqtt', apiRegion));
|
|
14850
14862
|
const emitter = createEventEmitter();
|
|
14851
14863
|
const client = {
|
|
14852
14864
|
version: `${VERSION$1}`,
|
|
@@ -14930,6 +14942,24 @@ const getDeviceInfo = () => {
|
|
|
14930
14942
|
};
|
|
14931
14943
|
};
|
|
14932
14944
|
|
|
14945
|
+
let activeUser = null;
|
|
14946
|
+
/**
|
|
14947
|
+
* for internal use
|
|
14948
|
+
*/
|
|
14949
|
+
const getActiveUser = () => {
|
|
14950
|
+
if (!activeUser) {
|
|
14951
|
+
throw new ASCError('Connect client first', 800000 /* UNKNOWN_ERROR */, "fatal" /* FATAL */);
|
|
14952
|
+
}
|
|
14953
|
+
return activeUser;
|
|
14954
|
+
};
|
|
14955
|
+
const setActiveUser = (user) => {
|
|
14956
|
+
activeUser = {
|
|
14957
|
+
_id: user._id,
|
|
14958
|
+
userId: user.userId,
|
|
14959
|
+
path: user.path,
|
|
14960
|
+
};
|
|
14961
|
+
};
|
|
14962
|
+
|
|
14933
14963
|
/**
|
|
14934
14964
|
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
14935
14965
|
*
|
|
@@ -14947,8 +14977,8 @@ const getToken = async (params) => {
|
|
|
14947
14977
|
client.log('client/api/getToken', params);
|
|
14948
14978
|
const deviceInfo = await getDeviceInfo();
|
|
14949
14979
|
const { data } = await client.http.post('/v1/device', Object.assign(Object.assign({}, params), { deviceInfo }), {
|
|
14950
|
-
|
|
14951
|
-
headers: { 'X-API-Key': client.apiKey }
|
|
14980
|
+
// @ts-ignore
|
|
14981
|
+
headers: { 'X-API-Key': client.apiKey },
|
|
14952
14982
|
});
|
|
14953
14983
|
return data;
|
|
14954
14984
|
};
|
|
@@ -14977,12 +15007,12 @@ const EVENTS = [
|
|
|
14977
15007
|
*/
|
|
14978
15008
|
const onConnectionError = (callback) => {
|
|
14979
15009
|
const client = getActiveClient();
|
|
14980
|
-
const subscribers = EVENTS.map(event =>
|
|
15010
|
+
const subscribers = EVENTS.map(event => createEventSubscriber(client, `client/onConnectionError(${event})`, event, response => {
|
|
14981
15011
|
const error = (response === null || response === void 0 ? void 0 : response.code)
|
|
14982
15012
|
? new ASCError(response.message, response.code, "fatal" /* FATAL */)
|
|
14983
15013
|
: new ASCConnectionError(event);
|
|
14984
15014
|
callback(error);
|
|
14985
|
-
}))
|
|
15015
|
+
}));
|
|
14986
15016
|
return () => {
|
|
14987
15017
|
subscribers.forEach(fn => fn());
|
|
14988
15018
|
};
|
|
@@ -15030,6 +15060,7 @@ const onClientBanned = (callback) => {
|
|
|
15030
15060
|
});
|
|
15031
15061
|
};
|
|
15032
15062
|
|
|
15063
|
+
/* eslint-disable no-param-reassign */
|
|
15033
15064
|
/**
|
|
15034
15065
|
* ```js
|
|
15035
15066
|
* import { connectClient } from '@amityco/ts-sdk/client/api'
|
|
@@ -15060,7 +15091,7 @@ const connectClient = async (params) => {
|
|
|
15060
15091
|
// ignored since we enforce default values just before.
|
|
15061
15092
|
const { accessToken, users } = await getToken(params);
|
|
15062
15093
|
// manually setup the token for http transport
|
|
15063
|
-
client.http.defaults.headers.common
|
|
15094
|
+
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
15064
15095
|
// manually setup the token for ws transport
|
|
15065
15096
|
client.ws.io.opts.query = { token: accessToken };
|
|
15066
15097
|
// FIXME: events are duplicated if connectClient is called few times without disconnectClient
|
|
@@ -15077,8 +15108,8 @@ const connectClient = async (params) => {
|
|
|
15077
15108
|
unsubscribe();
|
|
15078
15109
|
});
|
|
15079
15110
|
client.userId = params.userId;
|
|
15080
|
-
client._internalUserId = users[0]._id;
|
|
15081
15111
|
client.accessToken = accessToken;
|
|
15112
|
+
setActiveUser(users[0]);
|
|
15082
15113
|
return client.ws.connected;
|
|
15083
15114
|
};
|
|
15084
15115
|
|
|
@@ -15098,9 +15129,9 @@ const isConnected = () => {
|
|
|
15098
15129
|
var _a, _b;
|
|
15099
15130
|
const client = getActiveClient();
|
|
15100
15131
|
client.log('client/api/isConnected', client);
|
|
15101
|
-
return !!(client.userId
|
|
15102
|
-
|
|
15103
|
-
|
|
15132
|
+
return !!(client.userId &&
|
|
15133
|
+
((_b = (_a = client.http.defaults.headers.common) === null || _a === void 0 ? void 0 : _a.Authorization) === null || _b === void 0 ? void 0 : _b.length) &&
|
|
15134
|
+
client.ws.connected);
|
|
15104
15135
|
};
|
|
15105
15136
|
|
|
15106
15137
|
exports.SubscriptionLevels = void 0;
|
|
@@ -15111,7 +15142,7 @@ exports.SubscriptionLevels = void 0;
|
|
|
15111
15142
|
SubscriptionLevels["POST_AND_COMMENT"] = "post_and_comment";
|
|
15112
15143
|
SubscriptionLevels["USER"] = "user";
|
|
15113
15144
|
})(exports.SubscriptionLevels || (exports.SubscriptionLevels = {}));
|
|
15114
|
-
const getCommunityUserTopic = (
|
|
15145
|
+
const getCommunityUserTopic = (path, level) => {
|
|
15115
15146
|
switch (level) {
|
|
15116
15147
|
case 'post':
|
|
15117
15148
|
return `${path}/post/+`;
|
|
@@ -15123,8 +15154,10 @@ const getCommunityUserTopic = ({ path }, level) => {
|
|
|
15123
15154
|
return path;
|
|
15124
15155
|
}
|
|
15125
15156
|
};
|
|
15126
|
-
const getCommunityTopic = ({ path }, level = exports.SubscriptionLevels.COMMUNITY) => getCommunityUserTopic(
|
|
15127
|
-
const getUserTopic = ({ path }, level = exports.SubscriptionLevels.USER) => getCommunityUserTopic(
|
|
15157
|
+
const getCommunityTopic = ({ path }, level = exports.SubscriptionLevels.COMMUNITY) => getCommunityUserTopic(path, level);
|
|
15158
|
+
const getUserTopic = ({ path }, level = exports.SubscriptionLevels.USER) => getCommunityUserTopic(level === exports.SubscriptionLevels.USER
|
|
15159
|
+
? path
|
|
15160
|
+
: path.replace(/^(?<networkId>\w*)/, '$<networkId>/social'), level);
|
|
15128
15161
|
const getPostTopic = ({ path }, level = exports.SubscriptionLevels.POST) => {
|
|
15129
15162
|
switch (level) {
|
|
15130
15163
|
case 'comment':
|
|
@@ -15136,13 +15169,24 @@ const getPostTopic = ({ path }, level = exports.SubscriptionLevels.POST) => {
|
|
|
15136
15169
|
const getCommentTopic = ({ path }) => {
|
|
15137
15170
|
return path;
|
|
15138
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
|
+
};
|
|
15139
15182
|
let mqttAccessToken;
|
|
15140
15183
|
let mqttUserId;
|
|
15141
15184
|
function subscribeTopic(topic, callback) {
|
|
15142
|
-
const { mqtt, emitter, accessToken
|
|
15143
|
-
|
|
15185
|
+
const { mqtt, emitter, accessToken } = getActiveClient();
|
|
15186
|
+
const user = getActiveUser();
|
|
15187
|
+
if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
|
|
15144
15188
|
mqttAccessToken = accessToken;
|
|
15145
|
-
mqttUserId =
|
|
15189
|
+
mqttUserId = user._id;
|
|
15146
15190
|
mqtt.connect({ accessToken: mqttAccessToken, userId: mqttUserId });
|
|
15147
15191
|
proxyMqttEvents(mqtt, emitter);
|
|
15148
15192
|
}
|
|
@@ -15225,12 +15269,15 @@ const restoreCache = async (storageKey = 'amitySdk') => {
|
|
|
15225
15269
|
try {
|
|
15226
15270
|
cache = JSON.parse(serializedData);
|
|
15227
15271
|
}
|
|
15228
|
-
catch (err) {
|
|
15272
|
+
catch (err) {
|
|
15273
|
+
//
|
|
15274
|
+
}
|
|
15229
15275
|
// current cache should override. in case there's something fresher.
|
|
15230
15276
|
client.cache.data = Object.assign(Object.assign({}, cache), client.cache.data);
|
|
15231
15277
|
return true;
|
|
15232
15278
|
};
|
|
15233
15279
|
|
|
15280
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
15234
15281
|
/**
|
|
15235
15282
|
* ```js
|
|
15236
15283
|
* import { backupCache } from '@amityco/ts-sdk'
|
|
@@ -15260,8 +15307,7 @@ const backupCache = async (storageKey = 'amitySdk', persistIf = (entry) => entry
|
|
|
15260
15307
|
log('cache/api/backupCache', { storageKey });
|
|
15261
15308
|
// prepare a subset of the cache where only
|
|
15262
15309
|
// objects to backup are there
|
|
15263
|
-
const offlineEntries = Object.fromEntries(Object.entries(cache.data)
|
|
15264
|
-
.filter(([_, entry]) => persistIf(entry)));
|
|
15310
|
+
const offlineEntries = Object.fromEntries(Object.entries(cache.data).filter(([_, entry]) => persistIf(entry)));
|
|
15265
15311
|
// nothing to backup, abort
|
|
15266
15312
|
if (!Object.keys(offlineEntries).length)
|
|
15267
15313
|
return false;
|
|
@@ -15307,9 +15353,9 @@ const wipeCache = async (storageKey = 'amitySdk') => {
|
|
|
15307
15353
|
* @category Cache
|
|
15308
15354
|
* @hidden
|
|
15309
15355
|
*/
|
|
15310
|
-
const normalize = (source) =>
|
|
15356
|
+
const normalize = (source) => Object.keys(source)
|
|
15311
15357
|
.sort()
|
|
15312
|
-
.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: source[key] })), {})
|
|
15358
|
+
.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: source[key] })), {});
|
|
15313
15359
|
/**
|
|
15314
15360
|
* Encodes a given {@link Amity.CacheKey} to a plain string
|
|
15315
15361
|
*
|
|
@@ -15319,7 +15365,7 @@ const normalize = (source) => (Object.keys(source)
|
|
|
15319
15365
|
* @category Cache
|
|
15320
15366
|
* @hidden
|
|
15321
15367
|
*/
|
|
15322
|
-
const encodeKey = (key) =>
|
|
15368
|
+
const encodeKey = (key) => JSON.stringify(key, (_, val) => (typeof val === 'object' ? normalize(val) : val));
|
|
15323
15369
|
/**
|
|
15324
15370
|
* Decodes a string back into a {@link Amity.CacheKey}
|
|
15325
15371
|
|
|
@@ -15344,14 +15390,14 @@ const partialMatch = (predicate, candidate) => {
|
|
|
15344
15390
|
if (predicate === candidate)
|
|
15345
15391
|
return true;
|
|
15346
15392
|
// if one or the other is nullish, there can't be equality
|
|
15347
|
-
|
|
15393
|
+
if (!predicate || !candidate)
|
|
15348
15394
|
return false;
|
|
15349
15395
|
// we only perform recursive check on objects
|
|
15350
|
-
|
|
15396
|
+
if (typeof predicate !== 'object') {
|
|
15351
15397
|
return false;
|
|
15352
15398
|
}
|
|
15353
15399
|
// recursively call for partial match based on the predicate
|
|
15354
|
-
return Object.keys(predicate).every(
|
|
15400
|
+
return Object.keys(predicate).every(key => partialMatch(predicate[key], candidate[key]));
|
|
15355
15401
|
};
|
|
15356
15402
|
|
|
15357
15403
|
/**
|
|
@@ -15374,8 +15420,7 @@ const queryCache = (key) => {
|
|
|
15374
15420
|
if (!cache)
|
|
15375
15421
|
return;
|
|
15376
15422
|
log('cache/api/queryCache', { key });
|
|
15377
|
-
return Object
|
|
15378
|
-
.keys(cache.data)
|
|
15423
|
+
return Object.keys(cache.data)
|
|
15379
15424
|
.filter(stringKey => {
|
|
15380
15425
|
const decodedKey = decodeKey(stringKey);
|
|
15381
15426
|
return partialMatch(key, decodedKey);
|
|
@@ -15404,9 +15449,7 @@ const pullFromCache = (key) => {
|
|
|
15404
15449
|
return;
|
|
15405
15450
|
log('cache/api/pullFromCache', key);
|
|
15406
15451
|
const str = encodeKey(key);
|
|
15407
|
-
return
|
|
15408
|
-
? cache.data[str]
|
|
15409
|
-
: undefined;
|
|
15452
|
+
return cache.data[str] ? cache.data[str] : undefined;
|
|
15410
15453
|
};
|
|
15411
15454
|
|
|
15412
15455
|
/**
|
|
@@ -15432,8 +15475,10 @@ const pushToCache = (key, data, options = { cachedAt: Date.now() }) => {
|
|
|
15432
15475
|
// if consumer did not pass offline but a offline policy is
|
|
15433
15476
|
// defined, use the fn to determine if the object needs to
|
|
15434
15477
|
// be saved in persistent storage or not.
|
|
15435
|
-
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
|
|
15436
15480
|
options.offline = cache.persistIf(key, data);
|
|
15481
|
+
}
|
|
15437
15482
|
const encodedKey = encodeKey(key);
|
|
15438
15483
|
cache.data[encodedKey] = Object.assign({ key, data }, options);
|
|
15439
15484
|
return true;
|
|
@@ -15465,9 +15510,7 @@ const mergeInCache = (key, mutation, options) => {
|
|
|
15465
15510
|
const oldVal = pullFromCache(key);
|
|
15466
15511
|
if (!oldVal)
|
|
15467
15512
|
return false;
|
|
15468
|
-
const newVal = typeof mutation === 'function'
|
|
15469
|
-
? mutation(oldVal.data)
|
|
15470
|
-
: Object.assign(Object.assign({}, oldVal.data), mutation);
|
|
15513
|
+
const newVal = typeof mutation === 'function' ? mutation(oldVal.data) : Object.assign(Object.assign({}, oldVal.data), mutation);
|
|
15471
15514
|
pushToCache(key, newVal, options);
|
|
15472
15515
|
return true;
|
|
15473
15516
|
};
|
|
@@ -15495,9 +15538,7 @@ const upsertInCache = (key, data, options = { cachedAt: Date.now() }) => {
|
|
|
15495
15538
|
return false;
|
|
15496
15539
|
log('cache/api/upsertInCache', { key, data, options });
|
|
15497
15540
|
const cached = pullFromCache(key);
|
|
15498
|
-
return cached
|
|
15499
|
-
? mergeInCache(key, data, options)
|
|
15500
|
-
: pushToCache(key, data, options);
|
|
15541
|
+
return cached ? mergeInCache(key, data, options) : pushToCache(key, data, options);
|
|
15501
15542
|
};
|
|
15502
15543
|
|
|
15503
15544
|
/**
|
|
@@ -15521,7 +15562,7 @@ const dropFromCache = (key, exact = false) => {
|
|
|
15521
15562
|
return false;
|
|
15522
15563
|
log('cache/api/dropFromCache', { key, exact });
|
|
15523
15564
|
if (!exact) {
|
|
15524
|
-
return
|
|
15565
|
+
return Object.keys(cache.data)
|
|
15525
15566
|
.map(stringKey => decodeKey(stringKey))
|
|
15526
15567
|
.filter(candidate => partialMatch(key, candidate))
|
|
15527
15568
|
.map(filteredKey => dropFromCache(filteredKey, true))
|
|
@@ -15544,10 +15585,13 @@ const idResolvers = {
|
|
|
15544
15585
|
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
15545
15586
|
message: ({ messageId }) => messageId,
|
|
15546
15587
|
community: ({ communityId }) => communityId,
|
|
15588
|
+
category: ({ categoryId }) => categoryId,
|
|
15547
15589
|
communityUsers: ({ communityId, userId }) => `${communityId}#${userId}`,
|
|
15548
15590
|
post: ({ postId }) => postId,
|
|
15549
15591
|
comment: ({ commentId }) => commentId,
|
|
15550
15592
|
stream: ({ streamId }) => streamId,
|
|
15593
|
+
follow: ({ from, to }) => `${from}#${to}`,
|
|
15594
|
+
followCount: ({ userId }) => userId,
|
|
15551
15595
|
};
|
|
15552
15596
|
/**
|
|
15553
15597
|
* Retrieve the id resolver matching a domain name
|
|
@@ -15555,7 +15599,7 @@ const idResolvers = {
|
|
|
15555
15599
|
* @param name the domain name for the resolve
|
|
15556
15600
|
* @returns an idResolver function for the given domain name
|
|
15557
15601
|
*/
|
|
15558
|
-
const getResolver = (name) =>
|
|
15602
|
+
const getResolver = (name) => idResolvers[name];
|
|
15559
15603
|
|
|
15560
15604
|
/**
|
|
15561
15605
|
* A map of v3 response keys to a store name.
|
|
@@ -15569,11 +15613,14 @@ const PAYLOAD2MODEL = {
|
|
|
15569
15613
|
channelUsers: 'channelUsers',
|
|
15570
15614
|
messages: 'message',
|
|
15571
15615
|
communities: 'community',
|
|
15616
|
+
categories: 'category',
|
|
15572
15617
|
communityUsers: 'communityUsers',
|
|
15573
15618
|
posts: 'post',
|
|
15574
15619
|
postChildren: 'post',
|
|
15575
15620
|
comments: 'comment',
|
|
15576
15621
|
videoStreamings: 'stream',
|
|
15622
|
+
follows: 'follow',
|
|
15623
|
+
followCounts: 'followCount',
|
|
15577
15624
|
};
|
|
15578
15625
|
|
|
15579
15626
|
/**
|
|
@@ -15586,8 +15633,7 @@ const PAYLOAD2MODEL = {
|
|
|
15586
15633
|
* @hidden
|
|
15587
15634
|
*/
|
|
15588
15635
|
const ingestInCache = (payload = {}, options) => {
|
|
15589
|
-
Object.entries(payload)
|
|
15590
|
-
.forEach(([key, models]) => {
|
|
15636
|
+
Object.entries(payload).forEach(([key, models]) => {
|
|
15591
15637
|
const type = PAYLOAD2MODEL[key];
|
|
15592
15638
|
if (!type)
|
|
15593
15639
|
return;
|
|
@@ -15667,13 +15713,15 @@ const getUsers = async (userIds) => {
|
|
|
15667
15713
|
client.log('user/getUsers', userIds);
|
|
15668
15714
|
const encodedUserIds = userIds.map(userId => encodeURIComponent(userId));
|
|
15669
15715
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
15670
|
-
const { data } = await client.http.get(`/api/v3/users/list`, {
|
|
15716
|
+
const { data } = await client.http.get(`/api/v3/users/list`, {
|
|
15717
|
+
params: { userIds: encodedUserIds },
|
|
15718
|
+
});
|
|
15671
15719
|
const cachedAt = client.cache && Date.now();
|
|
15672
15720
|
if (client.cache)
|
|
15673
15721
|
ingestInCache(data, { cachedAt });
|
|
15674
15722
|
return {
|
|
15675
15723
|
data: data.users,
|
|
15676
|
-
cachedAt
|
|
15724
|
+
cachedAt,
|
|
15677
15725
|
};
|
|
15678
15726
|
};
|
|
15679
15727
|
/**
|
|
@@ -15699,7 +15747,7 @@ getUsers.locally = (userIds) => {
|
|
|
15699
15747
|
.map(userId => pullFromCache(['user', 'get', userId]))
|
|
15700
15748
|
.filter(Boolean);
|
|
15701
15749
|
const users = cached.map(({ data }) => data);
|
|
15702
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
15750
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
15703
15751
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < userIds.length)
|
|
15704
15752
|
return;
|
|
15705
15753
|
return {
|
|
@@ -15753,14 +15801,14 @@ function __rest(s, e) {
|
|
|
15753
15801
|
const queryUsers = async (query = {}) => {
|
|
15754
15802
|
const client = getActiveClient();
|
|
15755
15803
|
client.log('user/queryUsers', query);
|
|
15756
|
-
const { page, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query
|
|
15804
|
+
const { page, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query, ["page", "displayName", "filter", "sortBy"]);
|
|
15757
15805
|
// API-FIX: parameters should be querystring.
|
|
15758
|
-
|
|
15759
|
-
|
|
15760
|
-
const { data } = await client.http.get(`/api/v3/users`, { params: Object.assign(Object.assign({}, params), { keyword: displayName, filter,
|
|
15806
|
+
const { data } = await client.http.get(`/api/v3/users`, {
|
|
15807
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter,
|
|
15761
15808
|
sortBy, options: {
|
|
15762
15809
|
token: toToken(page, 'skiplimit'),
|
|
15763
|
-
} })
|
|
15810
|
+
} }),
|
|
15811
|
+
});
|
|
15764
15812
|
// unpacking
|
|
15765
15813
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
15766
15814
|
const { users } = payload;
|
|
@@ -15966,7 +16014,7 @@ const observeUser = (userId, callback) => {
|
|
|
15966
16014
|
*
|
|
15967
16015
|
* Fetches a {@link Amity.File} object
|
|
15968
16016
|
*
|
|
15969
|
-
* @param
|
|
16017
|
+
* @param fileId the ID of the {@link Amity.File} to fetch
|
|
15970
16018
|
* @returns the associated {@link Amity.File} object
|
|
15971
16019
|
*
|
|
15972
16020
|
* @category File API
|
|
@@ -16022,6 +16070,7 @@ getFile.locally = (fileId) => {
|
|
|
16022
16070
|
* Creates an {@link Amity.File}
|
|
16023
16071
|
*
|
|
16024
16072
|
* @param formData The data necessary to create a new {@link Amity.File}
|
|
16073
|
+
* @param onProgress The callback to track the upload progress
|
|
16025
16074
|
* @returns The newly created {@link Amity.File}
|
|
16026
16075
|
*
|
|
16027
16076
|
* @category File API
|
|
@@ -16036,9 +16085,10 @@ const createFile = async (formData, onProgress) => {
|
|
|
16036
16085
|
? formData.getHeaders()
|
|
16037
16086
|
: { 'content-type': 'multipart/form-data' };
|
|
16038
16087
|
const { data } = await client.http.post('/api/v3/files', formData, {
|
|
16039
|
-
headers,
|
|
16088
|
+
headers,
|
|
16089
|
+
onUploadProgress({ loaded, total }) {
|
|
16040
16090
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
16041
|
-
}
|
|
16091
|
+
},
|
|
16042
16092
|
});
|
|
16043
16093
|
// API-FIX: payload should be serialized properly
|
|
16044
16094
|
// const { files } = data
|
|
@@ -16086,6 +16136,47 @@ const fileUrlWithSize = (fileUrl, size) => {
|
|
|
16086
16136
|
return `${fileUrl}?size=${size}`;
|
|
16087
16137
|
};
|
|
16088
16138
|
|
|
16139
|
+
/**
|
|
16140
|
+
* ```js
|
|
16141
|
+
* import { createVideo } from '@amityco/ts-sdk'
|
|
16142
|
+
* const created = await createVideo(formData)
|
|
16143
|
+
* ```
|
|
16144
|
+
*
|
|
16145
|
+
* Creates an {@link Amity.File<'video'>}
|
|
16146
|
+
*
|
|
16147
|
+
* @param formData The data necessary to create a new {@link Amity.File<'video'>}
|
|
16148
|
+
* @param onProgress The callback to track the upload progress
|
|
16149
|
+
* @returns The newly created {@link Amity.File<'video'>}
|
|
16150
|
+
*
|
|
16151
|
+
* @category File API
|
|
16152
|
+
* @async
|
|
16153
|
+
*/
|
|
16154
|
+
const createVideo = async (formData, onProgress) => {
|
|
16155
|
+
const client = getActiveClient();
|
|
16156
|
+
client.log('file/createVideo', formData);
|
|
16157
|
+
if (!formData.getAll('files').length)
|
|
16158
|
+
throw new Error('The formData object must have a `files` key.');
|
|
16159
|
+
const headers = 'getHeaders' in formData
|
|
16160
|
+
? formData.getHeaders()
|
|
16161
|
+
: { 'content-type': 'multipart/form-data' };
|
|
16162
|
+
const { data } = await client.http.post('/api/v4/videos', formData, {
|
|
16163
|
+
headers,
|
|
16164
|
+
onUploadProgress({ loaded, total }) {
|
|
16165
|
+
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
16166
|
+
},
|
|
16167
|
+
});
|
|
16168
|
+
// API-FIX: payload should be serialized properly
|
|
16169
|
+
// const { files } = data
|
|
16170
|
+
const cachedAt = client.cache && Date.now();
|
|
16171
|
+
if (client.cache)
|
|
16172
|
+
ingestInCache({ files: data }, { cachedAt });
|
|
16173
|
+
return {
|
|
16174
|
+
data,
|
|
16175
|
+
cachedAt,
|
|
16176
|
+
};
|
|
16177
|
+
};
|
|
16178
|
+
// TODO: consider doing local creation with URL.createObjectURL()
|
|
16179
|
+
|
|
16089
16180
|
/**
|
|
16090
16181
|
* ```js
|
|
16091
16182
|
* import { observeFile } from '@amityco/ts-sdk'
|
|
@@ -16317,13 +16408,15 @@ const getMessages = async (messageIds) => {
|
|
|
16317
16408
|
const client = getActiveClient();
|
|
16318
16409
|
client.log('message/getMessages', messageIds);
|
|
16319
16410
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
16320
|
-
const { data } = await client.http.get(`/api/v3/messages/list`, {
|
|
16411
|
+
const { data } = await client.http.get(`/api/v3/messages/list`, {
|
|
16412
|
+
params: { messageIds },
|
|
16413
|
+
});
|
|
16321
16414
|
const cachedAt = client.cache && Date.now();
|
|
16322
16415
|
if (client.cache)
|
|
16323
16416
|
ingestInCache(data, { cachedAt });
|
|
16324
16417
|
return {
|
|
16325
16418
|
data: data.messages,
|
|
16326
|
-
cachedAt
|
|
16419
|
+
cachedAt,
|
|
16327
16420
|
};
|
|
16328
16421
|
};
|
|
16329
16422
|
/**
|
|
@@ -16349,7 +16442,7 @@ getMessages.locally = (messageIds) => {
|
|
|
16349
16442
|
.map(messageId => pullFromCache(['message', 'get', messageId]))
|
|
16350
16443
|
.filter(Boolean);
|
|
16351
16444
|
const messages = cached.map(({ data }) => data);
|
|
16352
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
16445
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
16353
16446
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < messageIds.length)
|
|
16354
16447
|
return;
|
|
16355
16448
|
return {
|
|
@@ -16375,19 +16468,16 @@ getMessages.locally = (messageIds) => {
|
|
|
16375
16468
|
const queryMessages = async (query) => {
|
|
16376
16469
|
const client = getActiveClient();
|
|
16377
16470
|
client.log('message/queryMessages', query);
|
|
16378
|
-
const { page = { limit: 10 } } = query, params = __rest(query
|
|
16379
|
-
// API-FIX: parameters should be querystring. (1)
|
|
16380
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
16381
|
-
// API-FIX: pagination should not be indexed on channelSegment (3)
|
|
16382
|
-
// const { data } = await client.http.get<Amity.Response<Amity.Paged<Amity.MessagePayload>>>(
|
|
16383
|
-
, ["page"]);
|
|
16471
|
+
const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
|
|
16384
16472
|
// API-FIX: parameters should be querystring. (1)
|
|
16385
16473
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16386
16474
|
// API-FIX: pagination should not be indexed on channelSegment (3)
|
|
16387
16475
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<Amity.MessagePayload>>>(
|
|
16388
|
-
const { data } = await client.http.get(`/api/v3/messages`, {
|
|
16476
|
+
const { data } = await client.http.get(`/api/v3/messages`, {
|
|
16477
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
16389
16478
|
token: toToken(page, 'afterbefore'),
|
|
16390
|
-
} }),
|
|
16479
|
+
} }),
|
|
16480
|
+
});
|
|
16391
16481
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16392
16482
|
// const { paging, messages } = unwrapPayload(data)
|
|
16393
16483
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
@@ -16395,7 +16485,11 @@ const queryMessages = async (query) => {
|
|
|
16395
16485
|
const cachedAt = client.cache && Date.now();
|
|
16396
16486
|
if (client.cache) {
|
|
16397
16487
|
ingestInCache(payload, { cachedAt });
|
|
16398
|
-
const cacheKey = [
|
|
16488
|
+
const cacheKey = [
|
|
16489
|
+
'message',
|
|
16490
|
+
'query',
|
|
16491
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
16492
|
+
];
|
|
16399
16493
|
pushToCache(cacheKey, { messages: messages.map(getResolver('message')), paging });
|
|
16400
16494
|
}
|
|
16401
16495
|
const nextPage = toPage(paging.next);
|
|
@@ -16497,7 +16591,7 @@ createMessage.optimistically = (bundle) => {
|
|
|
16497
16591
|
fireEvent('v3.message.didCreate', { messages: [message] });
|
|
16498
16592
|
return {
|
|
16499
16593
|
data: message,
|
|
16500
|
-
cachedAt: -1
|
|
16594
|
+
cachedAt: -1,
|
|
16501
16595
|
};
|
|
16502
16596
|
};
|
|
16503
16597
|
|
|
@@ -16561,7 +16655,7 @@ updateMessage.optimistically = (messageId, patch) => {
|
|
|
16561
16655
|
fireEvent('v3.message.didUpdate', { messages: [updated] });
|
|
16562
16656
|
return {
|
|
16563
16657
|
data: updated,
|
|
16564
|
-
cachedAt
|
|
16658
|
+
cachedAt,
|
|
16565
16659
|
};
|
|
16566
16660
|
};
|
|
16567
16661
|
|
|
@@ -16613,7 +16707,7 @@ deleteMessage.optimistically = (messageId) => {
|
|
|
16613
16707
|
fireEvent('v3.message.didDelete', { messages: [deleted] });
|
|
16614
16708
|
return {
|
|
16615
16709
|
data: deleted,
|
|
16616
|
-
cachedAt
|
|
16710
|
+
cachedAt,
|
|
16617
16711
|
};
|
|
16618
16712
|
};
|
|
16619
16713
|
|
|
@@ -16634,17 +16728,15 @@ deleteMessage.optimistically = (messageId) => {
|
|
|
16634
16728
|
const queryPosts = async (query) => {
|
|
16635
16729
|
const client = getActiveClient();
|
|
16636
16730
|
client.log('post/queryPosts', query);
|
|
16637
|
-
const { page = { limit: 10 } } = query, params = __rest(query
|
|
16638
|
-
// API-FIX: parameters should be querystring. (1)
|
|
16639
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
16640
|
-
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16641
|
-
, ["page"]);
|
|
16731
|
+
const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
|
|
16642
16732
|
// API-FIX: parameters should be querystring. (1)
|
|
16643
16733
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16644
16734
|
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16645
|
-
const { data } = await client.http.get(`/api/v4/posts`, {
|
|
16735
|
+
const { data } = await client.http.get(`/api/v4/posts`, {
|
|
16736
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
16646
16737
|
token: toToken(page, 'afterbeforeraw'),
|
|
16647
|
-
} }),
|
|
16738
|
+
} }),
|
|
16739
|
+
});
|
|
16648
16740
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16649
16741
|
// const { paging, posts } = unwrapPayload(data)
|
|
16650
16742
|
// unpacking
|
|
@@ -16714,13 +16806,15 @@ const getPosts = async (postIds) => {
|
|
|
16714
16806
|
client.log('post/getPosts', postIds);
|
|
16715
16807
|
const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
|
|
16716
16808
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
16717
|
-
const { data } = await client.http.get(`/api/v3/posts/list`, {
|
|
16809
|
+
const { data } = await client.http.get(`/api/v3/posts/list`, {
|
|
16810
|
+
params: { postIds: encodedPostIds },
|
|
16811
|
+
});
|
|
16718
16812
|
const cachedAt = client.cache && Date.now();
|
|
16719
16813
|
if (client.cache)
|
|
16720
16814
|
ingestInCache(data, { cachedAt });
|
|
16721
16815
|
return {
|
|
16722
16816
|
data: data.posts,
|
|
16723
|
-
cachedAt
|
|
16817
|
+
cachedAt,
|
|
16724
16818
|
};
|
|
16725
16819
|
};
|
|
16726
16820
|
/**
|
|
@@ -16746,7 +16840,7 @@ getPosts.locally = (postIds) => {
|
|
|
16746
16840
|
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
16747
16841
|
.filter(Boolean);
|
|
16748
16842
|
const posts = cached.map(({ data }) => data);
|
|
16749
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
16843
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
16750
16844
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
|
|
16751
16845
|
return;
|
|
16752
16846
|
return {
|
|
@@ -16797,7 +16891,7 @@ const getPost = async (postId) => {
|
|
|
16797
16891
|
/**
|
|
16798
16892
|
* ```js
|
|
16799
16893
|
* import { getPost } from '@amityco/ts-sdk'
|
|
16800
|
-
* const { data
|
|
16894
|
+
* const { data: post } = getPost.locally('foobar')
|
|
16801
16895
|
* ```
|
|
16802
16896
|
*
|
|
16803
16897
|
* Fetches a {@link Amity.Post} object from cache
|
|
@@ -16843,8 +16937,10 @@ const createPost = async (bundle) => {
|
|
|
16843
16937
|
const client = getActiveClient();
|
|
16844
16938
|
client.log('post/createPost', bundle);
|
|
16845
16939
|
// API-FIX: backend rejects that we pass the dataType manually T_T
|
|
16846
|
-
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType))
|
|
16940
|
+
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
|
|
16941
|
+
// eslint-disable-next-line no-param-reassign
|
|
16847
16942
|
delete bundle.dataType;
|
|
16943
|
+
}
|
|
16848
16944
|
const { data } = await client.http.post('/api/v4/posts', bundle);
|
|
16849
16945
|
const cachedAt = client.cache && Date.now();
|
|
16850
16946
|
if (client.cache)
|
|
@@ -16912,15 +17008,21 @@ const queryCommunities = async (query) => {
|
|
|
16912
17008
|
// API-FIX: parameters should be querystring.
|
|
16913
17009
|
// API-FIX: backend doesnt answer Amity.Response
|
|
16914
17010
|
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<CommunityPayload>>>(
|
|
16915
|
-
const { data } = await client.http.get(`/api/v3/communities`, {
|
|
16916
|
-
|
|
16917
|
-
|
|
17011
|
+
const { data } = await client.http.get(`/api/v3/communities`, {
|
|
17012
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
|
|
17013
|
+
token: toToken(page, 'skiplimit'),
|
|
17014
|
+
} }),
|
|
17015
|
+
});
|
|
16918
17016
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
16919
17017
|
const { communities } = payload;
|
|
16920
17018
|
const cachedAt = client.cache && Date.now();
|
|
16921
17019
|
if (client.cache) {
|
|
16922
17020
|
ingestInCache(payload, { cachedAt });
|
|
16923
|
-
const cacheKey = [
|
|
17021
|
+
const cacheKey = [
|
|
17022
|
+
'community',
|
|
17023
|
+
'query',
|
|
17024
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
17025
|
+
];
|
|
16924
17026
|
pushToCache(cacheKey, { communities: communities.map(getResolver('community')), paging });
|
|
16925
17027
|
}
|
|
16926
17028
|
const nextPage = toPage(paging.next);
|
|
@@ -16964,13 +17066,15 @@ const getCommunities = async (communityIds) => {
|
|
|
16964
17066
|
const client = getActiveClient();
|
|
16965
17067
|
client.log('community/getCommunities', communityIds);
|
|
16966
17068
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
16967
|
-
const { data } = await client.http.get(`/api/v3/communities/list`, {
|
|
17069
|
+
const { data } = await client.http.get(`/api/v3/communities/list`, {
|
|
17070
|
+
params: { communityIds },
|
|
17071
|
+
});
|
|
16968
17072
|
const cachedAt = client.cache && Date.now();
|
|
16969
17073
|
if (client.cache)
|
|
16970
17074
|
ingestInCache(data, { cachedAt });
|
|
16971
17075
|
return {
|
|
16972
17076
|
data: data.communities,
|
|
16973
|
-
cachedAt
|
|
17077
|
+
cachedAt,
|
|
16974
17078
|
};
|
|
16975
17079
|
};
|
|
16976
17080
|
/**
|
|
@@ -16996,7 +17100,7 @@ getCommunities.locally = (communityIds) => {
|
|
|
16996
17100
|
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
16997
17101
|
.filter(Boolean);
|
|
16998
17102
|
const communities = cached.map(({ data }) => data);
|
|
16999
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
17103
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
17000
17104
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < communityIds.length)
|
|
17001
17105
|
return;
|
|
17002
17106
|
return {
|
|
@@ -17166,8 +17270,7 @@ const joinCommunity = async (communityId) => {
|
|
|
17166
17270
|
ingestInCache(data, { cachedAt });
|
|
17167
17271
|
fireEvent('community.joined', data);
|
|
17168
17272
|
const { communityUsers } = data;
|
|
17169
|
-
return !!communityUsers.find(communityUser =>
|
|
17170
|
-
&& communityUser.communityMembership === 'member'));
|
|
17273
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
17171
17274
|
};
|
|
17172
17275
|
|
|
17173
17276
|
/**
|
|
@@ -17193,8 +17296,7 @@ const leaveCommunity = async (communityId) => {
|
|
|
17193
17296
|
ingestInCache(data, { cachedAt });
|
|
17194
17297
|
fireEvent('community.left', data);
|
|
17195
17298
|
const { communityUsers } = data;
|
|
17196
|
-
return !!communityUsers.find(communityUser =>
|
|
17197
|
-
&& communityUser.communityMembership !== 'member'));
|
|
17299
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
17198
17300
|
};
|
|
17199
17301
|
|
|
17200
17302
|
/**
|
|
@@ -17210,7 +17312,7 @@ const leaveCommunity = async (communityId) => {
|
|
|
17210
17312
|
*
|
|
17211
17313
|
* @category Community API
|
|
17212
17314
|
* @async
|
|
17213
|
-
|
|
17315
|
+
* */
|
|
17214
17316
|
const queryCommunityMembers = async (query) => {
|
|
17215
17317
|
const client = getActiveClient();
|
|
17216
17318
|
client.log('community/queryCommunityMembers', query);
|
|
@@ -17272,8 +17374,7 @@ const addCommunityMembers = async (communityId, userIds) => {
|
|
|
17272
17374
|
ingestInCache(data);
|
|
17273
17375
|
fireEvent('community.userAdded', data);
|
|
17274
17376
|
const { communityUsers } = data;
|
|
17275
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17276
|
-
communityUser.communityMembership === 'member');
|
|
17377
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
17277
17378
|
};
|
|
17278
17379
|
|
|
17279
17380
|
/**
|
|
@@ -17299,60 +17400,187 @@ const removeCommunityMembers = async (communityId, userIds) => {
|
|
|
17299
17400
|
ingestInCache(data);
|
|
17300
17401
|
fireEvent('community.userRemoved', data);
|
|
17301
17402
|
const { communityUsers } = data;
|
|
17302
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17303
|
-
communityUser.communityMembership !== 'member');
|
|
17403
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
17304
17404
|
};
|
|
17305
17405
|
|
|
17306
17406
|
/**
|
|
17307
17407
|
* ```js
|
|
17308
|
-
* import {
|
|
17309
|
-
* const updated = await
|
|
17408
|
+
* import { addCommunityMembersRoles } from '@amityco/ts-sdk'
|
|
17409
|
+
* const updated = await addCommunityMembersRoles(communityId, ['foo'], ['bar'])
|
|
17310
17410
|
* ```
|
|
17311
17411
|
*
|
|
17312
|
-
* Adds
|
|
17412
|
+
* Adds a list of {@link Amity.Role} to a list of {@link Amity.User} on a {@link Amity.Community}
|
|
17313
17413
|
*
|
|
17314
17414
|
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
17315
|
-
* @param
|
|
17415
|
+
* @param roleIds Array of IDs of the {@link Amity.Role} to apply
|
|
17316
17416
|
* @param userId Array of IDs of the {@link Amity.User} to perform
|
|
17317
17417
|
* @returns A success boolean if the {@link Amity.Role} were added to list of {@link Amity.User} in the {@link Amity.Community}
|
|
17318
17418
|
*
|
|
17319
17419
|
* @category Community API
|
|
17320
17420
|
* @async
|
|
17321
17421
|
*/
|
|
17322
|
-
const
|
|
17422
|
+
const addCommunityMembersRoles = async (communityId, roleIds, userIds) => {
|
|
17323
17423
|
const client = getActiveClient();
|
|
17324
|
-
client.log('community/
|
|
17325
|
-
const { data } = await client.http.post(`/api/
|
|
17424
|
+
client.log('community/addCommunityMembersRoles', communityId, roleIds, userIds);
|
|
17425
|
+
const { data } = await client.http.post(`/api/v4/communities/${communityId}/users/roles`, { communityId, roles: roleIds, userIds });
|
|
17326
17426
|
if (client.cache)
|
|
17327
17427
|
ingestInCache(data);
|
|
17328
17428
|
const { communityUsers } = data;
|
|
17329
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17429
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17430
|
+
roleIds.some(role => communityUser.roles.includes(role)));
|
|
17330
17431
|
};
|
|
17331
17432
|
|
|
17332
17433
|
/**
|
|
17333
17434
|
* ```js
|
|
17334
|
-
* import {
|
|
17335
|
-
* const updated = await
|
|
17435
|
+
* import { removeCommunityMembersRoles } from '@amityco/ts-sdk'
|
|
17436
|
+
* const updated = await removeCommunityMembersRoles(communityId, ['foo'], ['bar'])
|
|
17336
17437
|
* ```
|
|
17337
17438
|
*
|
|
17338
|
-
* Removes
|
|
17439
|
+
* Removes a list of {@link Amity.Role} from a list of {@link Amity.User} on a {@link Amity.Community}
|
|
17339
17440
|
*
|
|
17340
17441
|
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
17341
|
-
* @param
|
|
17442
|
+
* @param roleIds Array of IDs of the {@link Amity.Role} to apply
|
|
17342
17443
|
* @param userId Array of IDs of the {@link Amity.User} to perform
|
|
17343
17444
|
* @returns A success boolean if the {@link Amity.Role} were removed from list of {@link Amity.User} in the {@link Amity.Community}
|
|
17344
17445
|
*
|
|
17345
17446
|
* @category Community API
|
|
17346
17447
|
* @async
|
|
17347
17448
|
*/
|
|
17348
|
-
const
|
|
17449
|
+
const removeCommunityMembersRoles = async (communityId, roleIds, userIds) => {
|
|
17349
17450
|
const client = getActiveClient();
|
|
17350
|
-
client.log('community/
|
|
17351
|
-
const { data } = await client.http.delete(`/api/
|
|
17451
|
+
client.log('community/removeCommunityMembersRoles', communityId, roleIds, userIds);
|
|
17452
|
+
const { data } = await client.http.delete(`/api/v4/communities/${communityId}/users/roles`, { data: { communityId, roles: roleIds, userIds } });
|
|
17352
17453
|
if (client.cache)
|
|
17353
17454
|
ingestInCache(data);
|
|
17354
17455
|
const { communityUsers } = data;
|
|
17355
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17456
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
17457
|
+
!roleIds.some(role => communityUser.roles.includes(role)));
|
|
17458
|
+
};
|
|
17459
|
+
|
|
17460
|
+
/**
|
|
17461
|
+
* ```js
|
|
17462
|
+
* import { getTopTrendingCommunities } from '@amityco/ts-sdk'
|
|
17463
|
+
* const trendingCommunities = await getTopTrendingCommunities()
|
|
17464
|
+
* ```
|
|
17465
|
+
*
|
|
17466
|
+
* Gets a list of top trending {@link Amity.Community} objects
|
|
17467
|
+
*
|
|
17468
|
+
* @param query The query parameters
|
|
17469
|
+
* @returns A list of {@link Amity.Community} objects
|
|
17470
|
+
*
|
|
17471
|
+
* @category Community API
|
|
17472
|
+
* @async
|
|
17473
|
+
*/
|
|
17474
|
+
const getTopTrendingCommunities = async (query) => {
|
|
17475
|
+
const client = getActiveClient();
|
|
17476
|
+
client.log('channel/getTopTrendingCommunities', query);
|
|
17477
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17478
|
+
// API-FIX: backend doesnt answer Amity.Response
|
|
17479
|
+
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
17480
|
+
const { data } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
17481
|
+
const { communities } = data;
|
|
17482
|
+
const cachedAt = client.cache && Date.now();
|
|
17483
|
+
if (client.cache) {
|
|
17484
|
+
ingestInCache(data, { cachedAt });
|
|
17485
|
+
const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
17486
|
+
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
17487
|
+
}
|
|
17488
|
+
return { data: communities, cachedAt };
|
|
17489
|
+
};
|
|
17490
|
+
/**
|
|
17491
|
+
* ```js
|
|
17492
|
+
* import { getTopTrendingCommunities } from '@amityco/ts-sdk'
|
|
17493
|
+
* const communities = getTopTrendingCommunities.locally()
|
|
17494
|
+
* ```
|
|
17495
|
+
*
|
|
17496
|
+
* Gets a list of top trending {@link Amity.Community} objects from cache
|
|
17497
|
+
*
|
|
17498
|
+
* @param query The query parameters
|
|
17499
|
+
* @returns communities
|
|
17500
|
+
*
|
|
17501
|
+
* @category Community API
|
|
17502
|
+
*/
|
|
17503
|
+
getTopTrendingCommunities.locally = (query) => {
|
|
17504
|
+
var _a, _b;
|
|
17505
|
+
const client = getActiveClient();
|
|
17506
|
+
client.log('community/getTopTrendingCommunities.locally', query);
|
|
17507
|
+
if (!client.cache)
|
|
17508
|
+
return;
|
|
17509
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17510
|
+
const queryKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
17511
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
17512
|
+
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
17513
|
+
return;
|
|
17514
|
+
const communities = data.communities
|
|
17515
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
17516
|
+
.filter(Boolean)
|
|
17517
|
+
.map(({ data }) => data);
|
|
17518
|
+
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
17519
|
+
? { data: communities, cachedAt }
|
|
17520
|
+
: undefined;
|
|
17521
|
+
};
|
|
17522
|
+
|
|
17523
|
+
/**
|
|
17524
|
+
* ```js
|
|
17525
|
+
* import { getRecommendedCommunities } from '@amityco/ts-sdk'
|
|
17526
|
+
* const communities = await getRecommendedCommunities()
|
|
17527
|
+
* ```
|
|
17528
|
+
*
|
|
17529
|
+
* Gets a list of recommended {@link Amity.Community} objects
|
|
17530
|
+
*
|
|
17531
|
+
* @param query The query parameters
|
|
17532
|
+
* @returns A list of {@link Amity.Community} objects
|
|
17533
|
+
*
|
|
17534
|
+
* @category Community API
|
|
17535
|
+
* @async
|
|
17536
|
+
*/
|
|
17537
|
+
const getRecommendedCommunities = async (query) => {
|
|
17538
|
+
const client = getActiveClient();
|
|
17539
|
+
client.log('channel/getRecommendedCommunities', query);
|
|
17540
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17541
|
+
// API-FIX: backend doesnt answer Amity.Response
|
|
17542
|
+
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
17543
|
+
const { data } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
|
|
17544
|
+
const { communities } = data;
|
|
17545
|
+
const cachedAt = client.cache && Date.now();
|
|
17546
|
+
if (client.cache) {
|
|
17547
|
+
ingestInCache(data, { cachedAt });
|
|
17548
|
+
const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
17549
|
+
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
17550
|
+
}
|
|
17551
|
+
return { data: communities, cachedAt };
|
|
17552
|
+
};
|
|
17553
|
+
/**
|
|
17554
|
+
* ```js
|
|
17555
|
+
* import { getRecommendedCommunities } from '@amityco/ts-sdk'
|
|
17556
|
+
* const communities = getRecommendedCommunities.locally()
|
|
17557
|
+
* ```
|
|
17558
|
+
*
|
|
17559
|
+
* Gets a list of recommended {@link Amity.Community} objects from cache
|
|
17560
|
+
*
|
|
17561
|
+
* @param query The query parameters
|
|
17562
|
+
* @returns communities
|
|
17563
|
+
*
|
|
17564
|
+
* @category Community API
|
|
17565
|
+
*/
|
|
17566
|
+
getRecommendedCommunities.locally = (query) => {
|
|
17567
|
+
var _a, _b;
|
|
17568
|
+
const client = getActiveClient();
|
|
17569
|
+
client.log('community/getRecommendedCommunities.locally', query);
|
|
17570
|
+
if (!client.cache)
|
|
17571
|
+
return;
|
|
17572
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17573
|
+
const queryKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
17574
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
17575
|
+
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
17576
|
+
return;
|
|
17577
|
+
const communities = data.communities
|
|
17578
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
17579
|
+
.filter(Boolean)
|
|
17580
|
+
.map(({ data }) => data);
|
|
17581
|
+
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
17582
|
+
? { data: communities, cachedAt }
|
|
17583
|
+
: undefined;
|
|
17356
17584
|
};
|
|
17357
17585
|
|
|
17358
17586
|
/**
|
|
@@ -17372,7 +17600,7 @@ const removeCommunityMembersRole = async (communityId, roleId, userIds) => {
|
|
|
17372
17600
|
const deletePost = async (postId, permanent = false) => {
|
|
17373
17601
|
const client = getActiveClient();
|
|
17374
17602
|
client.log('post/deletePost', postId);
|
|
17375
|
-
|
|
17603
|
+
const post = await getPost(postId);
|
|
17376
17604
|
// API-FIX: This endpoint has not been implemented yet.
|
|
17377
17605
|
await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
17378
17606
|
params: {
|
|
@@ -17419,12 +17647,7 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
17419
17647
|
const queryComments = async (query) => {
|
|
17420
17648
|
const client = getActiveClient();
|
|
17421
17649
|
client.log('comment/queryComments', query);
|
|
17422
|
-
const { page = { limit: 10 } } = query, params = __rest(query
|
|
17423
|
-
// const filterByParentId = query.parentId !== undefined
|
|
17424
|
-
// API-FIX: parameters should be querystring. (1)
|
|
17425
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
17426
|
-
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.CommentPayload>>>(
|
|
17427
|
-
, ["page"]);
|
|
17650
|
+
const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
|
|
17428
17651
|
// const filterByParentId = query.parentId !== undefined
|
|
17429
17652
|
// API-FIX: parameters should be querystring. (1)
|
|
17430
17653
|
// API-FIX: backend should answer Amity.Response (2)
|
|
@@ -17443,7 +17666,11 @@ const queryComments = async (query) => {
|
|
|
17443
17666
|
const cachedAt = client.cache && Date.now();
|
|
17444
17667
|
if (client.cache) {
|
|
17445
17668
|
ingestInCache(payload, { cachedAt });
|
|
17446
|
-
const cacheKey = [
|
|
17669
|
+
const cacheKey = [
|
|
17670
|
+
'comment',
|
|
17671
|
+
'query',
|
|
17672
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
17673
|
+
];
|
|
17447
17674
|
pushToCache(cacheKey, { comments: comments.map(getResolver('comment')), paging });
|
|
17448
17675
|
}
|
|
17449
17676
|
const nextPage = toPage(paging.next);
|
|
@@ -17504,13 +17731,15 @@ const getComments = async (commentIds) => {
|
|
|
17504
17731
|
client.log('comment/getComments', commentIds);
|
|
17505
17732
|
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
17506
17733
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
17507
|
-
const { data } = await client.http.get(`/api/v3/comments/list`, {
|
|
17734
|
+
const { data } = await client.http.get(`/api/v3/comments/list`, {
|
|
17735
|
+
params: { commentIds: encodedCommentIds },
|
|
17736
|
+
});
|
|
17508
17737
|
const cachedAt = client.cache && Date.now();
|
|
17509
17738
|
if (client.cache)
|
|
17510
17739
|
ingestInCache(data, { cachedAt });
|
|
17511
17740
|
return {
|
|
17512
17741
|
data: data.comments,
|
|
17513
|
-
cachedAt
|
|
17742
|
+
cachedAt,
|
|
17514
17743
|
};
|
|
17515
17744
|
};
|
|
17516
17745
|
/**
|
|
@@ -17536,7 +17765,7 @@ getComments.locally = (commentIds) => {
|
|
|
17536
17765
|
.map(commentId => pullFromCache(['comment', 'get', commentId]))
|
|
17537
17766
|
.filter(Boolean);
|
|
17538
17767
|
const comments = cached.map(({ data }) => data);
|
|
17539
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
17768
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
17540
17769
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
|
|
17541
17770
|
return;
|
|
17542
17771
|
return {
|
|
@@ -17719,9 +17948,9 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
17719
17948
|
const fetchReference = async (referenceType, referenceId) => {
|
|
17720
17949
|
if (referenceType === 'message')
|
|
17721
17950
|
return getMessage(referenceId);
|
|
17722
|
-
|
|
17951
|
+
if (referenceType === 'post')
|
|
17723
17952
|
return getPost(referenceId);
|
|
17724
|
-
|
|
17953
|
+
if (referenceType === 'comment')
|
|
17725
17954
|
return getComment(referenceId);
|
|
17726
17955
|
throw new Error(`Incorrect referenceType: ${referenceType}`);
|
|
17727
17956
|
};
|
|
@@ -17758,7 +17987,9 @@ const preparePayloadForCache = (event, payload) => {
|
|
|
17758
17987
|
if (!cached.myReactions.includes(payload.reactor.reactionName)) {
|
|
17759
17988
|
return;
|
|
17760
17989
|
}
|
|
17761
|
-
Object.assign(model, {
|
|
17990
|
+
Object.assign(model, {
|
|
17991
|
+
myReactions: cached.myReactions.filter(x => x !== payload.reactor.reactionName),
|
|
17992
|
+
});
|
|
17762
17993
|
}
|
|
17763
17994
|
};
|
|
17764
17995
|
|
|
@@ -17777,7 +18008,7 @@ const preparePayloadForCache = (event, payload) => {
|
|
|
17777
18008
|
*
|
|
17778
18009
|
* @category Reaction API
|
|
17779
18010
|
* @async
|
|
17780
|
-
|
|
18011
|
+
* */
|
|
17781
18012
|
const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
17782
18013
|
var _a, _b;
|
|
17783
18014
|
const client = getActiveClient();
|
|
@@ -17786,7 +18017,11 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17786
18017
|
referenceType,
|
|
17787
18018
|
reactionName,
|
|
17788
18019
|
});
|
|
17789
|
-
await client.http.post('/api/v2/reactions', {
|
|
18020
|
+
await client.http.post('/api/v2/reactions', {
|
|
18021
|
+
referenceId,
|
|
18022
|
+
referenceType,
|
|
18023
|
+
reactionName,
|
|
18024
|
+
});
|
|
17790
18025
|
const model = await fetchReference(referenceType, referenceId);
|
|
17791
18026
|
dispatchReactable(referenceType, model.data);
|
|
17792
18027
|
return (_b = (_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)) !== null && _b !== void 0 ? _b : false;
|
|
@@ -17805,7 +18040,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17805
18040
|
* @returns The added result.
|
|
17806
18041
|
*
|
|
17807
18042
|
* @category Reaction API
|
|
17808
|
-
|
|
18043
|
+
* */
|
|
17809
18044
|
addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
17810
18045
|
var _a, _b, _c, _d, _e;
|
|
17811
18046
|
const client = getActiveClient();
|
|
@@ -17816,7 +18051,11 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
17816
18051
|
});
|
|
17817
18052
|
if (!client.cache)
|
|
17818
18053
|
return;
|
|
17819
|
-
const model = pullFromCache([
|
|
18054
|
+
const model = pullFromCache([
|
|
18055
|
+
referenceType,
|
|
18056
|
+
'get',
|
|
18057
|
+
referenceId,
|
|
18058
|
+
]);
|
|
17820
18059
|
if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
17821
18060
|
return;
|
|
17822
18061
|
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 }) });
|
|
@@ -17840,7 +18079,7 @@ addReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
17840
18079
|
*
|
|
17841
18080
|
* @category Reaction API
|
|
17842
18081
|
* @async
|
|
17843
|
-
|
|
18082
|
+
* */
|
|
17844
18083
|
const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
17845
18084
|
var _a, _b;
|
|
17846
18085
|
const client = getActiveClient();
|
|
@@ -17849,7 +18088,9 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17849
18088
|
referenceType,
|
|
17850
18089
|
reactionName,
|
|
17851
18090
|
});
|
|
17852
|
-
await client.http.delete(`/api/v2/reactions`, {
|
|
18091
|
+
await client.http.delete(`/api/v2/reactions`, {
|
|
18092
|
+
data: { referenceId, referenceType, reactionName },
|
|
18093
|
+
});
|
|
17853
18094
|
const model = await fetchReference(referenceType, referenceId);
|
|
17854
18095
|
dispatchReactable(referenceType, model.data);
|
|
17855
18096
|
return (_b = !((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName))) !== null && _b !== void 0 ? _b : false;
|
|
@@ -17868,7 +18109,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17868
18109
|
* @returns The added result.
|
|
17869
18110
|
*
|
|
17870
18111
|
* @category Reaction API
|
|
17871
|
-
|
|
18112
|
+
* */
|
|
17872
18113
|
removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
17873
18114
|
var _a, _b, _c, _d, _e;
|
|
17874
18115
|
const client = getActiveClient();
|
|
@@ -17879,7 +18120,11 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
17879
18120
|
});
|
|
17880
18121
|
if (!client.cache)
|
|
17881
18122
|
return;
|
|
17882
|
-
const model = pullFromCache([
|
|
18123
|
+
const model = pullFromCache([
|
|
18124
|
+
referenceType,
|
|
18125
|
+
'get',
|
|
18126
|
+
referenceId,
|
|
18127
|
+
]);
|
|
17883
18128
|
if (!(model === null || model === void 0 ? void 0 : model.data) || !((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
17884
18129
|
return;
|
|
17885
18130
|
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) }) });
|
|
@@ -18058,6 +18303,7 @@ const onPostReactionAdded = (callback) => {
|
|
|
18058
18303
|
}
|
|
18059
18304
|
else {
|
|
18060
18305
|
preparePayloadForCache('post.addReaction', payload);
|
|
18306
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18061
18307
|
const postPayload = __rest(payload, ["reactor"]);
|
|
18062
18308
|
ingestInCache(postPayload);
|
|
18063
18309
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
@@ -18090,6 +18336,7 @@ const onPostReactionRemoved = (callback) => {
|
|
|
18090
18336
|
}
|
|
18091
18337
|
else {
|
|
18092
18338
|
preparePayloadForCache('post.removeReaction', payload);
|
|
18339
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18093
18340
|
const postPayload = __rest(payload, ["reactor"]);
|
|
18094
18341
|
ingestInCache(postPayload);
|
|
18095
18342
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
@@ -18109,7 +18356,11 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
18109
18356
|
}
|
|
18110
18357
|
else {
|
|
18111
18358
|
ingestInCache(payload);
|
|
18112
|
-
const comment = pullFromCache([
|
|
18359
|
+
const comment = pullFromCache([
|
|
18360
|
+
'comment',
|
|
18361
|
+
'get',
|
|
18362
|
+
payload.comments[0].commentId,
|
|
18363
|
+
]);
|
|
18113
18364
|
if (['comment.created'].includes(event)) {
|
|
18114
18365
|
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; });
|
|
18115
18366
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
@@ -18228,9 +18479,14 @@ const onCommentReactionAdded = (callback) => {
|
|
|
18228
18479
|
}
|
|
18229
18480
|
else {
|
|
18230
18481
|
preparePayloadForCache('comment.addReaction', payload);
|
|
18482
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18231
18483
|
const commentPayload = __rest(payload, ["reactor"]);
|
|
18232
18484
|
ingestInCache(commentPayload);
|
|
18233
|
-
const comment = pullFromCache([
|
|
18485
|
+
const comment = pullFromCache([
|
|
18486
|
+
'comment',
|
|
18487
|
+
'get',
|
|
18488
|
+
payload.comments[0].commentId,
|
|
18489
|
+
]);
|
|
18234
18490
|
callback(comment.data);
|
|
18235
18491
|
}
|
|
18236
18492
|
};
|
|
@@ -18260,9 +18516,14 @@ const onCommentReactionRemoved = (callback) => {
|
|
|
18260
18516
|
}
|
|
18261
18517
|
else {
|
|
18262
18518
|
preparePayloadForCache('comment.removeReaction', payload);
|
|
18519
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18263
18520
|
const commentPayload = __rest(payload, ["reactor"]);
|
|
18264
18521
|
ingestInCache(commentPayload);
|
|
18265
|
-
const comment = pullFromCache([
|
|
18522
|
+
const comment = pullFromCache([
|
|
18523
|
+
'comment',
|
|
18524
|
+
'get',
|
|
18525
|
+
payload.comments[0].commentId,
|
|
18526
|
+
]);
|
|
18266
18527
|
callback(comment.data);
|
|
18267
18528
|
}
|
|
18268
18529
|
};
|
|
@@ -18285,7 +18546,7 @@ const onCommentReactionRemoved = (callback) => {
|
|
|
18285
18546
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18286
18547
|
*
|
|
18287
18548
|
* @category Message Events
|
|
18288
|
-
|
|
18549
|
+
* */
|
|
18289
18550
|
const onReactionRemoved = (referenceType, referenceId, callback) => {
|
|
18290
18551
|
const callbackWrapper = (model) => {
|
|
18291
18552
|
if (getResolver(referenceType)(model) === referenceId) {
|
|
@@ -18296,7 +18557,11 @@ const onReactionRemoved = (referenceType, referenceId, callback) => {
|
|
|
18296
18557
|
const client = getActiveClient();
|
|
18297
18558
|
const filter = (payload) => {
|
|
18298
18559
|
var _a;
|
|
18299
|
-
const cached = pullFromCache([
|
|
18560
|
+
const cached = pullFromCache([
|
|
18561
|
+
'message',
|
|
18562
|
+
'get',
|
|
18563
|
+
payload.messages[0].messageId,
|
|
18564
|
+
]);
|
|
18300
18565
|
const isReactionEvent = ((_a = cached === null || cached === void 0 ? void 0 : cached.data) === null || _a === void 0 ? void 0 : _a.reactionsCount) !== payload.messages[0].reactionsCount;
|
|
18301
18566
|
ingestInCache(payload);
|
|
18302
18567
|
if (isReactionEvent) {
|
|
@@ -18346,12 +18611,12 @@ var REFERENCE_TYPES = {
|
|
|
18346
18611
|
*
|
|
18347
18612
|
* @category Report API
|
|
18348
18613
|
* @async
|
|
18349
|
-
|
|
18614
|
+
* */
|
|
18350
18615
|
const createReport = async (referenceType, referenceId) => {
|
|
18351
18616
|
const client = getActiveClient();
|
|
18352
18617
|
client.log('report/createReport', { referenceType, referenceId });
|
|
18353
18618
|
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
18354
|
-
const { data } = await client.http.post(`/api/v3/${domainName}/${
|
|
18619
|
+
const { data } = await client.http.post(`/api/v3/${domainName}/${encodeURIComponent(referenceId)}/flag`);
|
|
18355
18620
|
if (client.cache)
|
|
18356
18621
|
ingestInCache(data);
|
|
18357
18622
|
const event = referenceType === 'message'
|
|
@@ -18373,7 +18638,7 @@ const createReport = async (referenceType, referenceId) => {
|
|
|
18373
18638
|
*
|
|
18374
18639
|
* @category Report API
|
|
18375
18640
|
* @async
|
|
18376
|
-
|
|
18641
|
+
* */
|
|
18377
18642
|
const deleteReport = async (referenceType, referenceId) => {
|
|
18378
18643
|
const client = getActiveClient();
|
|
18379
18644
|
client.log('report/deleteReport', { referenceType, referenceId });
|
|
@@ -18400,7 +18665,7 @@ const deleteReport = async (referenceType, referenceId) => {
|
|
|
18400
18665
|
*
|
|
18401
18666
|
* @category Report API
|
|
18402
18667
|
* @async
|
|
18403
|
-
|
|
18668
|
+
* */
|
|
18404
18669
|
const isReportedByMe = async (referenceType, referenceId) => {
|
|
18405
18670
|
var _a, _b;
|
|
18406
18671
|
const client = getActiveClient();
|
|
@@ -18435,15 +18700,21 @@ const queryChannels = async (query) => {
|
|
|
18435
18700
|
// API-FIX: parameters should be querystring.
|
|
18436
18701
|
// API-FIX: backend doesnt answer Amity.Response
|
|
18437
18702
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<ChannelPayload>>>(
|
|
18438
|
-
const { data } = await client.http.get(`/api/v3/channels`, {
|
|
18703
|
+
const { data } = await client.http.get(`/api/v3/channels`, {
|
|
18704
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
|
|
18439
18705
|
token: toToken(page, 'skiplimit'),
|
|
18440
|
-
} })
|
|
18706
|
+
} }),
|
|
18707
|
+
});
|
|
18441
18708
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
18442
18709
|
const { channels } = payload;
|
|
18443
18710
|
const cachedAt = client.cache && Date.now();
|
|
18444
18711
|
if (client.cache) {
|
|
18445
18712
|
ingestInCache(payload, { cachedAt });
|
|
18446
|
-
const cacheKey = [
|
|
18713
|
+
const cacheKey = [
|
|
18714
|
+
'channel',
|
|
18715
|
+
'query',
|
|
18716
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
18717
|
+
];
|
|
18447
18718
|
pushToCache(cacheKey, { channels: channels.map(getResolver('channel')), paging });
|
|
18448
18719
|
}
|
|
18449
18720
|
const nextPage = toPage(paging.next);
|
|
@@ -18488,13 +18759,15 @@ const getChannels = async (channelIds) => {
|
|
|
18488
18759
|
client.log('channel/getChannels', channelIds);
|
|
18489
18760
|
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
18490
18761
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
18491
|
-
const { data } = await client.http.get(`/api/v3/channels/list`, {
|
|
18762
|
+
const { data } = await client.http.get(`/api/v3/channels/list`, {
|
|
18763
|
+
params: { channelIds: encodedChannelIds },
|
|
18764
|
+
});
|
|
18492
18765
|
const cachedAt = client.cache && Date.now();
|
|
18493
18766
|
if (client.cache)
|
|
18494
18767
|
ingestInCache(data, { cachedAt });
|
|
18495
18768
|
return {
|
|
18496
18769
|
data: data.channels,
|
|
18497
|
-
cachedAt
|
|
18770
|
+
cachedAt,
|
|
18498
18771
|
};
|
|
18499
18772
|
};
|
|
18500
18773
|
/**
|
|
@@ -18520,7 +18793,7 @@ getChannels.locally = (channelIds) => {
|
|
|
18520
18793
|
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
18521
18794
|
.filter(Boolean);
|
|
18522
18795
|
const channels = cached.map(({ data }) => data);
|
|
18523
|
-
const oldest = (_a = cached.sort((a, b) => a.cachedAt < b.cachedAt ? -1 : 1)) === null || _a === void 0 ? void 0 : _a[0];
|
|
18796
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
18524
18797
|
if ((cached === null || cached === void 0 ? void 0 : cached.length) < channelIds.length)
|
|
18525
18798
|
return;
|
|
18526
18799
|
return {
|
|
@@ -18692,8 +18965,7 @@ const joinChannel = async (channelId) => {
|
|
|
18692
18965
|
if (client.cache)
|
|
18693
18966
|
ingestInCache(data);
|
|
18694
18967
|
const { channelUsers } = data;
|
|
18695
|
-
return !!channelUsers.find(channelUser =>
|
|
18696
|
-
&& channelUser.membership === 'member'));
|
|
18968
|
+
return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership === 'member');
|
|
18697
18969
|
};
|
|
18698
18970
|
|
|
18699
18971
|
/**
|
|
@@ -18717,8 +18989,7 @@ const leaveChannel = async (channelId) => {
|
|
|
18717
18989
|
if (client.cache)
|
|
18718
18990
|
ingestInCache(data);
|
|
18719
18991
|
const { channelUsers } = data;
|
|
18720
|
-
return !!channelUsers.find(channelUser =>
|
|
18721
|
-
&& channelUser.membership !== 'member'));
|
|
18992
|
+
return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership !== 'member');
|
|
18722
18993
|
};
|
|
18723
18994
|
|
|
18724
18995
|
/**
|
|
@@ -18734,7 +19005,7 @@ const leaveChannel = async (channelId) => {
|
|
|
18734
19005
|
*
|
|
18735
19006
|
* @category Channel API
|
|
18736
19007
|
* @async
|
|
18737
|
-
|
|
19008
|
+
* */
|
|
18738
19009
|
const queryChannelMembers = async (query) => {
|
|
18739
19010
|
const client = getActiveClient();
|
|
18740
19011
|
client.log('channel/queryChannelMembers', query);
|
|
@@ -19230,7 +19501,11 @@ const createCommunityEventSubscriber = (event, callback) => {
|
|
|
19230
19501
|
}
|
|
19231
19502
|
else {
|
|
19232
19503
|
ingestInCache(payload);
|
|
19233
|
-
const community = pullFromCache([
|
|
19504
|
+
const community = pullFromCache([
|
|
19505
|
+
'community',
|
|
19506
|
+
'get',
|
|
19507
|
+
payload.communities[0].communityId,
|
|
19508
|
+
]);
|
|
19234
19509
|
callback(community.data);
|
|
19235
19510
|
}
|
|
19236
19511
|
};
|
|
@@ -19240,8 +19515,8 @@ function hasPermission(member, payload, permission) {
|
|
|
19240
19515
|
if (member.permissions.some(x => x === permission)) {
|
|
19241
19516
|
return true;
|
|
19242
19517
|
}
|
|
19243
|
-
return payload
|
|
19244
|
-
.find(user => user.userId === member.userId)
|
|
19518
|
+
return payload
|
|
19519
|
+
.users.find(user => user.userId === member.userId)
|
|
19245
19520
|
.permissions.some(x => x === permission);
|
|
19246
19521
|
}
|
|
19247
19522
|
function getEventRelatedMember(event, payload) {
|
|
@@ -19271,11 +19546,15 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
|
|
|
19271
19546
|
}
|
|
19272
19547
|
else {
|
|
19273
19548
|
ingestInCache(payload);
|
|
19274
|
-
const community = pullFromCache([
|
|
19549
|
+
const community = pullFromCache([
|
|
19550
|
+
'community',
|
|
19551
|
+
'get',
|
|
19552
|
+
payload.communities[0].communityId,
|
|
19553
|
+
]);
|
|
19275
19554
|
const member = pullFromCache([
|
|
19276
19555
|
'communityUsers',
|
|
19277
19556
|
'get',
|
|
19278
|
-
getResolver('communityUsers')(getEventRelatedMember(event, payload))
|
|
19557
|
+
getResolver('communityUsers')(getEventRelatedMember(event, payload)),
|
|
19279
19558
|
]);
|
|
19280
19559
|
callback(community.data, member.data);
|
|
19281
19560
|
}
|
|
@@ -19482,89 +19761,801 @@ const observeCommunity = (communityId, callback) => {
|
|
|
19482
19761
|
|
|
19483
19762
|
/**
|
|
19484
19763
|
* ```js
|
|
19485
|
-
* import {
|
|
19486
|
-
* const
|
|
19764
|
+
* import { queryCategories } from '@amityco/ts-sdk'
|
|
19765
|
+
* const { data: categories, prevPage, nextPage } = await queryCategories()
|
|
19487
19766
|
* ```
|
|
19488
19767
|
*
|
|
19489
|
-
* Queries a paginable list of {@link Amity.
|
|
19768
|
+
* Queries a paginable list of {@link Amity.Category} objects
|
|
19490
19769
|
*
|
|
19491
19770
|
* @param query The query parameters
|
|
19492
|
-
* @returns A page of {@link Amity.
|
|
19771
|
+
* @returns A page of {@link Amity.Category} objects
|
|
19493
19772
|
*
|
|
19494
|
-
* @category
|
|
19773
|
+
* @category Category API
|
|
19495
19774
|
* @async
|
|
19496
|
-
|
|
19497
|
-
const
|
|
19775
|
+
* */
|
|
19776
|
+
const queryCategories = async (query) => {
|
|
19498
19777
|
const client = getActiveClient();
|
|
19499
|
-
client.log('
|
|
19500
|
-
const _a = query !== null && query !== void 0 ? query : {}, {
|
|
19501
|
-
const { data } = await client.http.get(
|
|
19502
|
-
|
|
19503
|
-
|
|
19778
|
+
client.log('category/queryCategories', query);
|
|
19779
|
+
const _a = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 } } = _a, params = __rest(_a, ["page"]);
|
|
19780
|
+
const { data } = await client.http.get(`/api/v3/community-categories`, {
|
|
19781
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
19782
|
+
token: toToken(page, 'skiplimit'),
|
|
19783
|
+
} }),
|
|
19784
|
+
});
|
|
19504
19785
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19505
|
-
const {
|
|
19786
|
+
const { categories } = payload;
|
|
19506
19787
|
const cachedAt = client.cache && Date.now();
|
|
19507
19788
|
if (client.cache) {
|
|
19508
|
-
ingestInCache(payload);
|
|
19509
|
-
const cacheKey = [
|
|
19510
|
-
|
|
19789
|
+
ingestInCache(payload, { cachedAt });
|
|
19790
|
+
const cacheKey = [
|
|
19791
|
+
'category',
|
|
19792
|
+
'query',
|
|
19793
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
19794
|
+
];
|
|
19795
|
+
pushToCache(cacheKey, { categories: categories.map(getResolver('category')), paging });
|
|
19511
19796
|
}
|
|
19512
19797
|
const nextPage = toPage(paging.next);
|
|
19513
19798
|
const prevPage = toPage(paging.previous);
|
|
19514
|
-
return { data:
|
|
19799
|
+
return { data: categories, cachedAt, prevPage, nextPage };
|
|
19515
19800
|
};
|
|
19516
19801
|
/**
|
|
19517
19802
|
* ```js
|
|
19518
|
-
* import {
|
|
19519
|
-
* const
|
|
19803
|
+
* import { queryCategories } from '@amityco/ts-sdk'
|
|
19804
|
+
* const { data: categories, prevPage, nextPage } = queryCategories.locally()
|
|
19520
19805
|
* ```
|
|
19521
19806
|
*
|
|
19522
|
-
* Queries a paginable list of {@link Amity.
|
|
19807
|
+
* Queries a paginable list of {@link Amity.Category} objects from cache
|
|
19523
19808
|
*
|
|
19524
19809
|
* @param query The query parameters
|
|
19525
|
-
* @returns
|
|
19810
|
+
* @returns categories
|
|
19526
19811
|
*
|
|
19527
|
-
* @category
|
|
19528
|
-
|
|
19529
|
-
|
|
19530
|
-
queryGlobalFeed.locally = (query) => {
|
|
19812
|
+
* @category category API
|
|
19813
|
+
*/
|
|
19814
|
+
queryCategories.locally = (query) => {
|
|
19531
19815
|
var _a, _b;
|
|
19532
19816
|
const client = getActiveClient();
|
|
19533
|
-
client.log('
|
|
19817
|
+
client.log('category/queryCategories.locally', query);
|
|
19534
19818
|
if (!client.cache)
|
|
19535
19819
|
return;
|
|
19536
|
-
const _c = query !== null && query !== void 0 ? query : {}, {
|
|
19537
|
-
const queryKey = ['
|
|
19820
|
+
const _c = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 } } = _c, params = __rest(_c, ["page"]);
|
|
19821
|
+
const queryKey = ['category', 'query', Object.assign(Object.assign({}, params), { options: Object.assign({}, page) })];
|
|
19538
19822
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19539
|
-
if (!(data === null || data === void 0 ? void 0 : data.
|
|
19823
|
+
if (!(data === null || data === void 0 ? void 0 : data.categories.length))
|
|
19540
19824
|
return;
|
|
19541
|
-
const
|
|
19542
|
-
.map(
|
|
19825
|
+
const categories = data.categories
|
|
19826
|
+
.map(categoryId => pullFromCache(['category', 'get', categoryId]))
|
|
19543
19827
|
.filter(Boolean)
|
|
19544
19828
|
.map(({ data }) => data);
|
|
19545
19829
|
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19546
19830
|
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19547
|
-
return
|
|
19548
|
-
? { data:
|
|
19831
|
+
return categories.length === ((_b = data === null || data === void 0 ? void 0 : data.categories) === null || _b === void 0 ? void 0 : _b.length)
|
|
19832
|
+
? { data: categories, cachedAt, prevPage, nextPage }
|
|
19549
19833
|
: undefined;
|
|
19550
19834
|
};
|
|
19551
19835
|
|
|
19552
19836
|
/**
|
|
19553
19837
|
* ```js
|
|
19554
|
-
* import {
|
|
19555
|
-
*
|
|
19556
|
-
* let posts = []
|
|
19557
|
-
* const unsub = observePosts({
|
|
19558
|
-
* targetType: Amity.PostTargetType,
|
|
19559
|
-
* targetId: Amity.Post['targetId'],
|
|
19560
|
-
* }, post => merge(posts, post))
|
|
19838
|
+
* import { getCategory } from '@amityco/ts-sdk'
|
|
19839
|
+
* const { data: category } = await getCategory('foo')
|
|
19561
19840
|
* ```
|
|
19562
19841
|
*
|
|
19563
|
-
*
|
|
19842
|
+
* Fetches a {@link Amity.Category} object
|
|
19564
19843
|
*
|
|
19565
|
-
* @param
|
|
19566
|
-
* @
|
|
19567
|
-
*
|
|
19844
|
+
* @param categoryId the ID of the {@link Amity.Category} to fetch
|
|
19845
|
+
* @returns the associated {@link Amity.Category} object
|
|
19846
|
+
*
|
|
19847
|
+
* @category Category API
|
|
19848
|
+
* @async
|
|
19849
|
+
*/
|
|
19850
|
+
const getCategory = async (categoryId) => {
|
|
19851
|
+
const client = getActiveClient();
|
|
19852
|
+
client.log('category/getCategory', categoryId);
|
|
19853
|
+
const { data } = await client.http.get(`/api/v3/community-categories/${encodeURIComponent(categoryId)}`);
|
|
19854
|
+
const cachedAt = client.cache && Date.now();
|
|
19855
|
+
if (client.cache)
|
|
19856
|
+
ingestInCache(data, { cachedAt });
|
|
19857
|
+
const { categories } = data;
|
|
19858
|
+
return {
|
|
19859
|
+
data: categories.find(category => category.categoryId === categoryId),
|
|
19860
|
+
cachedAt,
|
|
19861
|
+
};
|
|
19862
|
+
};
|
|
19863
|
+
/**
|
|
19864
|
+
* ```js
|
|
19865
|
+
* import { getCategory } from '@amityco/ts-sdk'
|
|
19866
|
+
* const { data: category } = getCategory.locally('foobar')
|
|
19867
|
+
* ```
|
|
19868
|
+
*
|
|
19869
|
+
* Fetches a {@link Amity.Category} object from cache
|
|
19870
|
+
*
|
|
19871
|
+
* @param categoryId the ID of the {@link Amity.Category} to fetch
|
|
19872
|
+
* @returns the associated {@link Amity.Category} object
|
|
19873
|
+
*
|
|
19874
|
+
* @category Category API
|
|
19875
|
+
*/
|
|
19876
|
+
getCategory.locally = (categoryId) => {
|
|
19877
|
+
const client = getActiveClient();
|
|
19878
|
+
client.log('category/getCategory.locally', categoryId);
|
|
19879
|
+
if (!client.cache)
|
|
19880
|
+
return;
|
|
19881
|
+
const cached = pullFromCache(['category', 'get', categoryId]);
|
|
19882
|
+
if (!cached)
|
|
19883
|
+
return;
|
|
19884
|
+
return {
|
|
19885
|
+
data: cached.data,
|
|
19886
|
+
cachedAt: cached.cachedAt,
|
|
19887
|
+
};
|
|
19888
|
+
};
|
|
19889
|
+
|
|
19890
|
+
/**
|
|
19891
|
+
* ```js
|
|
19892
|
+
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
19893
|
+
* const posts = await queryGlobalFeed()
|
|
19894
|
+
* ```
|
|
19895
|
+
*
|
|
19896
|
+
* Queries a paginable list of {@link Amity.Post} objects
|
|
19897
|
+
*
|
|
19898
|
+
* @param query The query parameters
|
|
19899
|
+
* @returns A page of {@link Amity.Post} objects
|
|
19900
|
+
*
|
|
19901
|
+
* @category Feed API
|
|
19902
|
+
* @async
|
|
19903
|
+
* */
|
|
19904
|
+
const queryGlobalFeed = async (query) => {
|
|
19905
|
+
const client = getActiveClient();
|
|
19906
|
+
client.log('feed/queryGlobalFeed', query);
|
|
19907
|
+
const _a = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _a, params = __rest(_a, ["useCustomRanking", "page"]);
|
|
19908
|
+
const { data } = await client.http.get(useCustomRanking ? `/api/v5/me/global-feeds` : `/api/v4/me/global-feeds`, {
|
|
19909
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
19910
|
+
token: toToken(page, 'skiplimit'),
|
|
19911
|
+
} }),
|
|
19912
|
+
});
|
|
19913
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19914
|
+
const { posts } = payload;
|
|
19915
|
+
const cachedAt = client.cache && Date.now();
|
|
19916
|
+
if (client.cache) {
|
|
19917
|
+
ingestInCache(payload);
|
|
19918
|
+
const cacheKey = [
|
|
19919
|
+
'globalFeed',
|
|
19920
|
+
'query',
|
|
19921
|
+
Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) }),
|
|
19922
|
+
];
|
|
19923
|
+
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
19924
|
+
}
|
|
19925
|
+
const nextPage = toPage(paging.next);
|
|
19926
|
+
const prevPage = toPage(paging.previous);
|
|
19927
|
+
return { data: posts, cachedAt, prevPage, nextPage };
|
|
19928
|
+
};
|
|
19929
|
+
/**
|
|
19930
|
+
* ```js
|
|
19931
|
+
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
19932
|
+
* const posts = await queryGlobalFeed.locally()
|
|
19933
|
+
* ```
|
|
19934
|
+
*
|
|
19935
|
+
* Queries a paginable list of {@link Amity.Post} objects from cache
|
|
19936
|
+
*
|
|
19937
|
+
* @param query The query parameters
|
|
19938
|
+
* @returns A page of {@link Amity.Post} objects
|
|
19939
|
+
*
|
|
19940
|
+
* @category Feed API
|
|
19941
|
+
* @async
|
|
19942
|
+
* */
|
|
19943
|
+
queryGlobalFeed.locally = (query) => {
|
|
19944
|
+
var _a, _b;
|
|
19945
|
+
const client = getActiveClient();
|
|
19946
|
+
client.log('post/queryGlobalFeed.locally', query);
|
|
19947
|
+
if (!client.cache)
|
|
19948
|
+
return;
|
|
19949
|
+
const _c = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _c, params = __rest(_c, ["useCustomRanking", "page"]);
|
|
19950
|
+
const queryKey = [
|
|
19951
|
+
'globalFeed',
|
|
19952
|
+
'query',
|
|
19953
|
+
Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) }),
|
|
19954
|
+
];
|
|
19955
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19956
|
+
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
19957
|
+
return;
|
|
19958
|
+
const posts = data.posts
|
|
19959
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
19960
|
+
.filter(Boolean)
|
|
19961
|
+
.map(({ data }) => data);
|
|
19962
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19963
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19964
|
+
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
19965
|
+
? { data: posts, cachedAt, prevPage, nextPage }
|
|
19966
|
+
: undefined;
|
|
19967
|
+
};
|
|
19968
|
+
|
|
19969
|
+
const queryFollows = async (key, query) => {
|
|
19970
|
+
const client = getActiveClient();
|
|
19971
|
+
client.log(`follow/queryF${key.substring(1)}`, query);
|
|
19972
|
+
const { userId, page } = query, params = __rest(query, ["userId", "page"]);
|
|
19973
|
+
const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/${key}` : `/api/v4/users/${userId}/${key}`, {
|
|
19974
|
+
params: Object.assign(Object.assign({}, params), { token: toToken(page, 'skiplimit') }),
|
|
19975
|
+
});
|
|
19976
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19977
|
+
const { follows } = payload;
|
|
19978
|
+
const cachedAt = client.cache && Date.now();
|
|
19979
|
+
if (client.cache) {
|
|
19980
|
+
ingestInCache(payload, { cachedAt });
|
|
19981
|
+
const cacheKey = [
|
|
19982
|
+
key,
|
|
19983
|
+
'query',
|
|
19984
|
+
Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page) }),
|
|
19985
|
+
];
|
|
19986
|
+
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
19987
|
+
}
|
|
19988
|
+
const nextPage = toPage(paging.next);
|
|
19989
|
+
const prevPage = toPage(paging.previous);
|
|
19990
|
+
return { data: follows, cachedAt, prevPage, nextPage };
|
|
19991
|
+
};
|
|
19992
|
+
queryFollows.locally = (key, query) => {
|
|
19993
|
+
var _a, _b;
|
|
19994
|
+
const client = getActiveClient();
|
|
19995
|
+
client.log(`follow/queryF${key.substring(1)}.locally`, query);
|
|
19996
|
+
if (!client.cache)
|
|
19997
|
+
return;
|
|
19998
|
+
const { page } = query, params = __rest(query, ["page"]);
|
|
19999
|
+
const queryKey = [key, 'query', Object.assign(Object.assign({}, params), { options: Object.assign({}, page) })];
|
|
20000
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
20001
|
+
if (!(data === null || data === void 0 ? void 0 : data.follows.length)) {
|
|
20002
|
+
return;
|
|
20003
|
+
}
|
|
20004
|
+
const follows = data.follows
|
|
20005
|
+
.map(key => pullFromCache(['follow', 'get', key]))
|
|
20006
|
+
.filter(Boolean)
|
|
20007
|
+
.map(({ data }) => data);
|
|
20008
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
20009
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
20010
|
+
return follows.length === ((_b = data === null || data === void 0 ? void 0 : data.follows) === null || _b === void 0 ? void 0 : _b.length)
|
|
20011
|
+
? { data: follows, cachedAt, prevPage, nextPage }
|
|
20012
|
+
: undefined;
|
|
20013
|
+
};
|
|
20014
|
+
|
|
20015
|
+
/**
|
|
20016
|
+
* ```js
|
|
20017
|
+
* import { queryFollowers } from '@amityco/ts-sdk'
|
|
20018
|
+
* const { data: followers, prevPage, nextPage } = await queryFollowers({ userId })
|
|
20019
|
+
* ```
|
|
20020
|
+
*
|
|
20021
|
+
* Queries a paginable list of {@link Amity.FollowStatus}
|
|
20022
|
+
*
|
|
20023
|
+
* @param query The query parameters
|
|
20024
|
+
* @returns followers
|
|
20025
|
+
*
|
|
20026
|
+
* @category Follow API
|
|
20027
|
+
* @async
|
|
20028
|
+
*/
|
|
20029
|
+
const queryFollowers = async (query) => queryFollows('followers', query);
|
|
20030
|
+
/**
|
|
20031
|
+
* ```js
|
|
20032
|
+
* import { queryFollowers } from '@amityco/ts-sdk'
|
|
20033
|
+
* const { data: followers, prevPage, nextPage } = queryFollowers.locally({ userId })
|
|
20034
|
+
* ```
|
|
20035
|
+
*
|
|
20036
|
+
* Queries a paginable list of {@link Amity.FollowStatus} objects from cache
|
|
20037
|
+
*
|
|
20038
|
+
* @param query The query parameters
|
|
20039
|
+
* @returns followers
|
|
20040
|
+
*
|
|
20041
|
+
* @category Post API
|
|
20042
|
+
*/
|
|
20043
|
+
queryFollowers.locally = (query) => queryFollows.locally('followers', query);
|
|
20044
|
+
|
|
20045
|
+
/**
|
|
20046
|
+
* ```js
|
|
20047
|
+
* import { queryFollowings } from '@amityco/ts-sdk'
|
|
20048
|
+
* const { data: followings, prevPage, nextPage } = await queryFollowings({ userId })
|
|
20049
|
+
* ```
|
|
20050
|
+
*
|
|
20051
|
+
* Queries a paginable list of {@link Amity.FollowStatus}
|
|
20052
|
+
*
|
|
20053
|
+
* @param query The query parameters
|
|
20054
|
+
* @returns followings
|
|
20055
|
+
*
|
|
20056
|
+
* @category Follow API
|
|
20057
|
+
* @async
|
|
20058
|
+
*/
|
|
20059
|
+
const queryFollowings = async (query) => queryFollows('following', query);
|
|
20060
|
+
/**
|
|
20061
|
+
* ```js
|
|
20062
|
+
* import { queryFollowings } from '@amityco/ts-sdk'
|
|
20063
|
+
* const { data: followings, prevPage, nextPage } = queryFollowings.locally({ userId })
|
|
20064
|
+
* ```
|
|
20065
|
+
*
|
|
20066
|
+
* Queries a paginable list of {@link Amity.FollowStatus} objects from cache
|
|
20067
|
+
*
|
|
20068
|
+
* @param query The query parameters
|
|
20069
|
+
* @returns followings
|
|
20070
|
+
*
|
|
20071
|
+
* @category Post API
|
|
20072
|
+
*/
|
|
20073
|
+
queryFollowings.locally = (query) => queryFollows.locally('following', query);
|
|
20074
|
+
|
|
20075
|
+
const getCacheKey = (userId) => [
|
|
20076
|
+
'followInfo',
|
|
20077
|
+
'get',
|
|
20078
|
+
`${getActiveClient().userId}#${userId}`,
|
|
20079
|
+
];
|
|
20080
|
+
/**
|
|
20081
|
+
* ```js
|
|
20082
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
20083
|
+
* const { data: followInfo } = await getFollowInfo('foobar')
|
|
20084
|
+
* ```
|
|
20085
|
+
*
|
|
20086
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user
|
|
20087
|
+
*
|
|
20088
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20089
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
20090
|
+
*
|
|
20091
|
+
* @category Follow API
|
|
20092
|
+
* @async
|
|
20093
|
+
*/
|
|
20094
|
+
const getFollowInfo = async (userId) => {
|
|
20095
|
+
var _a, _b;
|
|
20096
|
+
const client = getActiveClient();
|
|
20097
|
+
client.log('follow/getFollowInfo', userId);
|
|
20098
|
+
const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/followInfo` : `/api/v4/users/${userId}/followInfo`);
|
|
20099
|
+
const cachedAt = client.cache && Date.now();
|
|
20100
|
+
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 });
|
|
20101
|
+
if (client.cache) {
|
|
20102
|
+
pushToCache(getCacheKey(userId), followInfo, { cachedAt });
|
|
20103
|
+
}
|
|
20104
|
+
return {
|
|
20105
|
+
data: followInfo,
|
|
20106
|
+
cachedAt,
|
|
20107
|
+
};
|
|
20108
|
+
};
|
|
20109
|
+
/**
|
|
20110
|
+
* ```js
|
|
20111
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
20112
|
+
* const { data: followInfo } = getFollowInfo.locally('foobar')
|
|
20113
|
+
* ```
|
|
20114
|
+
*
|
|
20115
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user from cache
|
|
20116
|
+
*
|
|
20117
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20118
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
20119
|
+
*
|
|
20120
|
+
* @category Follow API
|
|
20121
|
+
*/
|
|
20122
|
+
getFollowInfo.locally = (userId) => {
|
|
20123
|
+
const client = getActiveClient();
|
|
20124
|
+
client.log('follow/getFollowInfo.locally', userId);
|
|
20125
|
+
if (!client.cache) {
|
|
20126
|
+
return;
|
|
20127
|
+
}
|
|
20128
|
+
const cached = pullFromCache(getCacheKey(userId));
|
|
20129
|
+
if (!cached) {
|
|
20130
|
+
return;
|
|
20131
|
+
}
|
|
20132
|
+
return {
|
|
20133
|
+
data: cached.data,
|
|
20134
|
+
cachedAt: cached.cachedAt,
|
|
20135
|
+
};
|
|
20136
|
+
};
|
|
20137
|
+
|
|
20138
|
+
/**
|
|
20139
|
+
* ```js
|
|
20140
|
+
* import { follow } from '@amityco/ts-sdk'
|
|
20141
|
+
* const status = await follow('foobar')
|
|
20142
|
+
* ```
|
|
20143
|
+
*
|
|
20144
|
+
* Follow the user
|
|
20145
|
+
*
|
|
20146
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20147
|
+
* @returns the status {@link Amity.FollowStatus}
|
|
20148
|
+
*
|
|
20149
|
+
* @category Follow API
|
|
20150
|
+
* @async
|
|
20151
|
+
*/
|
|
20152
|
+
const follow = async (userId) => {
|
|
20153
|
+
const client = getActiveClient();
|
|
20154
|
+
client.log('follow/follow', userId);
|
|
20155
|
+
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
20156
|
+
const cachedAt = client.cache && Date.now();
|
|
20157
|
+
if (client.cache) {
|
|
20158
|
+
ingestInCache(data, { cachedAt });
|
|
20159
|
+
}
|
|
20160
|
+
fireEvent(data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested', data.follows[0]);
|
|
20161
|
+
return {
|
|
20162
|
+
data: data.follows[0],
|
|
20163
|
+
cachedAt,
|
|
20164
|
+
};
|
|
20165
|
+
};
|
|
20166
|
+
|
|
20167
|
+
/**
|
|
20168
|
+
* ```js
|
|
20169
|
+
* import { unfollow } from '@amityco/ts-sdk'
|
|
20170
|
+
* await unfollow('foobar')
|
|
20171
|
+
* ```
|
|
20172
|
+
*
|
|
20173
|
+
* Cancel the follow request or unfollow the user
|
|
20174
|
+
*
|
|
20175
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20176
|
+
* @returns A success boolean if the user {@link Amity.User} was unfollowed
|
|
20177
|
+
*
|
|
20178
|
+
* @category Follow API
|
|
20179
|
+
* @async
|
|
20180
|
+
*/
|
|
20181
|
+
const unfollow = async (userId) => {
|
|
20182
|
+
const client = getActiveClient();
|
|
20183
|
+
client.log('follow/unfollow', userId);
|
|
20184
|
+
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
20185
|
+
if (client.cache) {
|
|
20186
|
+
ingestInCache(data);
|
|
20187
|
+
}
|
|
20188
|
+
fireEvent('follow.unfollowed', data.follows[0]);
|
|
20189
|
+
return true;
|
|
20190
|
+
};
|
|
20191
|
+
|
|
20192
|
+
/**
|
|
20193
|
+
* ```js
|
|
20194
|
+
* import { acceptFollower } from '@amityco/ts-sdk'
|
|
20195
|
+
* await acceptFollower('foobar')
|
|
20196
|
+
* ```
|
|
20197
|
+
*
|
|
20198
|
+
* Accept the follow request
|
|
20199
|
+
*
|
|
20200
|
+
* @param userId the ID of the {@link Amity.User} follower
|
|
20201
|
+
* @returns A success boolean if the follow request was accepted
|
|
20202
|
+
*
|
|
20203
|
+
* @category Follow API
|
|
20204
|
+
* @async
|
|
20205
|
+
*/
|
|
20206
|
+
const acceptFollower = async (userId) => {
|
|
20207
|
+
const client = getActiveClient();
|
|
20208
|
+
client.log('follow/acceptFollower', userId);
|
|
20209
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
20210
|
+
if (client.cache) {
|
|
20211
|
+
ingestInCache(data);
|
|
20212
|
+
}
|
|
20213
|
+
fireEvent('follow.accepted', data.follows[0]);
|
|
20214
|
+
return true;
|
|
20215
|
+
};
|
|
20216
|
+
|
|
20217
|
+
/**
|
|
20218
|
+
* ```js
|
|
20219
|
+
* import { declineFollower } from '@amityco/ts-sdk'
|
|
20220
|
+
* await declineFollower('foobar')
|
|
20221
|
+
* ```
|
|
20222
|
+
*
|
|
20223
|
+
* Decline the follow request or delete the follower
|
|
20224
|
+
*
|
|
20225
|
+
* @param userId the ID of the {@link Amity.User} follower
|
|
20226
|
+
* @returns A success boolean if the follow request was decline
|
|
20227
|
+
*
|
|
20228
|
+
* @category Follow API
|
|
20229
|
+
* @async
|
|
20230
|
+
*/
|
|
20231
|
+
const declineFollower = async (userId) => {
|
|
20232
|
+
const client = getActiveClient();
|
|
20233
|
+
client.log('follow/declineFollower', userId);
|
|
20234
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
20235
|
+
if (client.cache) {
|
|
20236
|
+
ingestInCache(data);
|
|
20237
|
+
}
|
|
20238
|
+
fireEvent('follow.requestDeclined', data.follows[0]);
|
|
20239
|
+
return true;
|
|
20240
|
+
};
|
|
20241
|
+
|
|
20242
|
+
const createFollowEventSubscriber = (event, callback) => {
|
|
20243
|
+
const client = getActiveClient();
|
|
20244
|
+
const filter = (payload) => {
|
|
20245
|
+
var _a, _b;
|
|
20246
|
+
if (!client.cache) {
|
|
20247
|
+
callback(payload);
|
|
20248
|
+
}
|
|
20249
|
+
else {
|
|
20250
|
+
ingestInCache({ follows: [payload] });
|
|
20251
|
+
const queries = [
|
|
20252
|
+
...((_a = queryCache(['followers', 'query'])) !== null && _a !== void 0 ? _a : []),
|
|
20253
|
+
...((_b = queryCache(['followings', 'query'])) !== null && _b !== void 0 ? _b : []),
|
|
20254
|
+
];
|
|
20255
|
+
queries
|
|
20256
|
+
// @ts-ignore
|
|
20257
|
+
.filter(({ key }) => key[2].userId === payload.from || key[2].userId === payload.to)
|
|
20258
|
+
.forEach(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
20259
|
+
callback(payload);
|
|
20260
|
+
}
|
|
20261
|
+
};
|
|
20262
|
+
return createEventSubscriber(client, event, event, filter);
|
|
20263
|
+
};
|
|
20264
|
+
|
|
20265
|
+
/**
|
|
20266
|
+
* ```js
|
|
20267
|
+
* import { onUserFollowed } from '@amityco/ts-sdk'
|
|
20268
|
+
* const dispose = onUserFollowed(status => {
|
|
20269
|
+
* // ...
|
|
20270
|
+
* })
|
|
20271
|
+
* ```
|
|
20272
|
+
*
|
|
20273
|
+
* Fired when a user follows another users and confirmation is not required
|
|
20274
|
+
*
|
|
20275
|
+
* @param callback The function to call when the event was fired
|
|
20276
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20277
|
+
*
|
|
20278
|
+
* @category Follow Events
|
|
20279
|
+
*/
|
|
20280
|
+
const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
|
|
20281
|
+
|
|
20282
|
+
/**
|
|
20283
|
+
* ```js
|
|
20284
|
+
* import { onUserUnfollowed } from '@amityco/ts-sdk'
|
|
20285
|
+
* const dispose = onUserFollowed(status => {
|
|
20286
|
+
* // ...
|
|
20287
|
+
* })
|
|
20288
|
+
* ```
|
|
20289
|
+
*
|
|
20290
|
+
* Fired when a user unfollows
|
|
20291
|
+
*
|
|
20292
|
+
* @param callback The function to call when the event was fired
|
|
20293
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20294
|
+
*
|
|
20295
|
+
* @category Follow Events
|
|
20296
|
+
*/
|
|
20297
|
+
const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
|
|
20298
|
+
|
|
20299
|
+
/**
|
|
20300
|
+
* ```js
|
|
20301
|
+
* import { onFollowerDeleted } from '@amityco/ts-sdk'
|
|
20302
|
+
* const dispose = onFollowerDeleted(status => {
|
|
20303
|
+
* // ...
|
|
20304
|
+
* })
|
|
20305
|
+
* ```
|
|
20306
|
+
*
|
|
20307
|
+
* Fired when a follower has been deleted
|
|
20308
|
+
*
|
|
20309
|
+
* @param callback The function to call when the event was fired
|
|
20310
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20311
|
+
*
|
|
20312
|
+
* @category Follow Events
|
|
20313
|
+
*/
|
|
20314
|
+
const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
|
|
20315
|
+
|
|
20316
|
+
/**
|
|
20317
|
+
* ```js
|
|
20318
|
+
* import { onFollowerRequested } from '@amityco/ts-sdk'
|
|
20319
|
+
* const dispose = onFollowerRequested(status => {
|
|
20320
|
+
* // ...
|
|
20321
|
+
* })
|
|
20322
|
+
* ```
|
|
20323
|
+
*
|
|
20324
|
+
* Fired when a user follows another users and confirmation is required
|
|
20325
|
+
*
|
|
20326
|
+
* @param callback The function to call when the event was fired
|
|
20327
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20328
|
+
*
|
|
20329
|
+
* @category Follow Events
|
|
20330
|
+
*/
|
|
20331
|
+
const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
|
|
20332
|
+
|
|
20333
|
+
/**
|
|
20334
|
+
* ```js
|
|
20335
|
+
* import { onFollowRequestCanceled } from '@amityco/ts-sdk'
|
|
20336
|
+
* const dispose = onFollowRequestCanceled(status => {
|
|
20337
|
+
* // ...
|
|
20338
|
+
* })
|
|
20339
|
+
* ```
|
|
20340
|
+
*
|
|
20341
|
+
* Fired when a follow request has been canceled
|
|
20342
|
+
*
|
|
20343
|
+
* @param callback The function to call when the event was fired
|
|
20344
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20345
|
+
*
|
|
20346
|
+
* @category Follow Events
|
|
20347
|
+
*/
|
|
20348
|
+
const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
|
|
20349
|
+
|
|
20350
|
+
/**
|
|
20351
|
+
* ```js
|
|
20352
|
+
* import { onFollowRequestAccepted } from '@amityco/ts-sdk'
|
|
20353
|
+
* const dispose = onFollowRequestAccepted(status => {
|
|
20354
|
+
* // ...
|
|
20355
|
+
* })
|
|
20356
|
+
* ```
|
|
20357
|
+
*
|
|
20358
|
+
* Fired when a follow request has been accepted
|
|
20359
|
+
*
|
|
20360
|
+
* @param callback The function to call when the event was fired
|
|
20361
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20362
|
+
*
|
|
20363
|
+
* @category Follow Events
|
|
20364
|
+
*/
|
|
20365
|
+
const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
|
|
20366
|
+
|
|
20367
|
+
/**
|
|
20368
|
+
* ```js
|
|
20369
|
+
* import { onFollowRequestDeclined } from '@amityco/ts-sdk'
|
|
20370
|
+
* const dispose = onFollowRequestDeclined(status => {
|
|
20371
|
+
* // ...
|
|
20372
|
+
* })
|
|
20373
|
+
* ```
|
|
20374
|
+
*
|
|
20375
|
+
* Fired when a follow request has been declined
|
|
20376
|
+
*
|
|
20377
|
+
* @param callback The function to call when the event was fired
|
|
20378
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20379
|
+
*
|
|
20380
|
+
* @category Follow Events
|
|
20381
|
+
*/
|
|
20382
|
+
const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
|
|
20383
|
+
|
|
20384
|
+
/**
|
|
20385
|
+
* ```js
|
|
20386
|
+
* import { onFollowInfoUpdated } from '@amityco/ts-sdk'
|
|
20387
|
+
* const dispose = onFollowInfoUpdated(followInfo => {
|
|
20388
|
+
* // ...
|
|
20389
|
+
* })
|
|
20390
|
+
* ```
|
|
20391
|
+
*
|
|
20392
|
+
* Fired when a {@link Amity.FollowInfo} has been updated
|
|
20393
|
+
*
|
|
20394
|
+
* @param callback The function to call when the event was fired
|
|
20395
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20396
|
+
*
|
|
20397
|
+
* @category Follow Events
|
|
20398
|
+
*/
|
|
20399
|
+
const onFollowInfoUpdated = (callback) => {
|
|
20400
|
+
const handler = async (payload) => {
|
|
20401
|
+
const [{ data: followInfoFrom }, { data: followInfoTo }] = await Promise.all([
|
|
20402
|
+
getFollowInfo(payload.from),
|
|
20403
|
+
getFollowInfo(payload.to),
|
|
20404
|
+
]);
|
|
20405
|
+
callback(followInfoFrom);
|
|
20406
|
+
callback(followInfoTo);
|
|
20407
|
+
};
|
|
20408
|
+
const disposers = [
|
|
20409
|
+
createFollowEventSubscriber('follow.created', handler),
|
|
20410
|
+
createFollowEventSubscriber('follow.requested', handler),
|
|
20411
|
+
createFollowEventSubscriber('follow.accepted', handler),
|
|
20412
|
+
createFollowEventSubscriber('follow.unfollowed', handler),
|
|
20413
|
+
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
20414
|
+
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
20415
|
+
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
20416
|
+
];
|
|
20417
|
+
return () => {
|
|
20418
|
+
disposers.forEach(fn => fn());
|
|
20419
|
+
};
|
|
20420
|
+
};
|
|
20421
|
+
|
|
20422
|
+
/**
|
|
20423
|
+
* ```js
|
|
20424
|
+
* import { observeFollowInfo } from '@amityco/ts-sdk'
|
|
20425
|
+
*
|
|
20426
|
+
* let followInfo = {}
|
|
20427
|
+
* const dispose = observeFollowInfo(userId, updated => followInfo = updated)
|
|
20428
|
+
* ```
|
|
20429
|
+
*
|
|
20430
|
+
* Observe all mutation on a given {@link Amity.FollowInfo}
|
|
20431
|
+
*
|
|
20432
|
+
* @param userId the ID of the user to observe
|
|
20433
|
+
* @param callback the function to call when new data are available
|
|
20434
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
|
|
20435
|
+
*
|
|
20436
|
+
* @category Follow Observer
|
|
20437
|
+
*/
|
|
20438
|
+
const observeFollowInfo = (userId, callback, policy = 'cache_then_server') => {
|
|
20439
|
+
const { log } = getActiveClient();
|
|
20440
|
+
const timestamp = Date.now();
|
|
20441
|
+
log(`observeFollowInfo(tmpid: ${timestamp}) > listen`);
|
|
20442
|
+
const router = (result, action) => {
|
|
20443
|
+
var _a, _b;
|
|
20444
|
+
if (callback instanceof Function)
|
|
20445
|
+
return callback(result);
|
|
20446
|
+
if (action !== 'onFetch')
|
|
20447
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
20448
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
20449
|
+
};
|
|
20450
|
+
const realtimeRouter = (result, action) => {
|
|
20451
|
+
var _a;
|
|
20452
|
+
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
|
|
20453
|
+
return;
|
|
20454
|
+
router(result, action);
|
|
20455
|
+
};
|
|
20456
|
+
const disposers = [];
|
|
20457
|
+
disposers.push(onFollowInfoUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')));
|
|
20458
|
+
runQuery(createQuery(getFollowInfo, userId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
20459
|
+
return () => {
|
|
20460
|
+
log(`observeFollowInfo(tmpid: ${timestamp}) > dispose`);
|
|
20461
|
+
disposers.forEach(fn => fn());
|
|
20462
|
+
};
|
|
20463
|
+
};
|
|
20464
|
+
|
|
20465
|
+
/**
|
|
20466
|
+
* ```js
|
|
20467
|
+
* import { observeFollowers } from '@amityco/ts-sdk'
|
|
20468
|
+
*
|
|
20469
|
+
* let followers = []
|
|
20470
|
+
* const unsub = observeFollowers('userId', follower => merge(followers, follower))
|
|
20471
|
+
* ```
|
|
20472
|
+
*
|
|
20473
|
+
* Observe all mutations on a list of followers {@link Amity.FollowStatus} for a given user
|
|
20474
|
+
*
|
|
20475
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20476
|
+
* @param callback the function to call when new data are available
|
|
20477
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
20478
|
+
*
|
|
20479
|
+
* @category Follow Observer
|
|
20480
|
+
*/
|
|
20481
|
+
const observeFollowers = (userId, callback) => {
|
|
20482
|
+
const { log } = getActiveClient();
|
|
20483
|
+
const timestamp = Date.now();
|
|
20484
|
+
log(`observeFollowers(tmpid: ${timestamp}) > listen`);
|
|
20485
|
+
const disposers = [];
|
|
20486
|
+
const router = (status, action) => {
|
|
20487
|
+
var _a, _b;
|
|
20488
|
+
if (status.from !== userId) {
|
|
20489
|
+
return;
|
|
20490
|
+
}
|
|
20491
|
+
if (callback instanceof Function) {
|
|
20492
|
+
return callback(status);
|
|
20493
|
+
}
|
|
20494
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
20495
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
20496
|
+
};
|
|
20497
|
+
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')));
|
|
20498
|
+
return () => {
|
|
20499
|
+
log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
|
|
20500
|
+
disposers.forEach(fn => fn());
|
|
20501
|
+
};
|
|
20502
|
+
};
|
|
20503
|
+
|
|
20504
|
+
/**
|
|
20505
|
+
* ```js
|
|
20506
|
+
* import { observeFollowings } from '@amityco/ts-sdk'
|
|
20507
|
+
*
|
|
20508
|
+
* let followings = []
|
|
20509
|
+
* const unsub = observeFollowers('userId', follower => merge(followings, following))
|
|
20510
|
+
* ```
|
|
20511
|
+
*
|
|
20512
|
+
* Observe all mutations on a list of followings {@link Amity.FollowStatus} for a given user
|
|
20513
|
+
*
|
|
20514
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20515
|
+
* @param callback the function to call when new data are available
|
|
20516
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
20517
|
+
*
|
|
20518
|
+
* @category Follow Observer
|
|
20519
|
+
*/
|
|
20520
|
+
const observeFollowings = (userId, callback) => {
|
|
20521
|
+
const { log } = getActiveClient();
|
|
20522
|
+
const timestamp = Date.now();
|
|
20523
|
+
log(`observeFollowings(tmpid: ${timestamp}) > listen`);
|
|
20524
|
+
const disposers = [];
|
|
20525
|
+
const router = (status, action) => {
|
|
20526
|
+
var _a, _b;
|
|
20527
|
+
if (status.to !== userId) {
|
|
20528
|
+
return;
|
|
20529
|
+
}
|
|
20530
|
+
if (callback instanceof Function) {
|
|
20531
|
+
return callback(status);
|
|
20532
|
+
}
|
|
20533
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
20534
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
20535
|
+
};
|
|
20536
|
+
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')));
|
|
20537
|
+
return () => {
|
|
20538
|
+
log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
|
|
20539
|
+
disposers.forEach(fn => fn());
|
|
20540
|
+
};
|
|
20541
|
+
};
|
|
20542
|
+
|
|
20543
|
+
/**
|
|
20544
|
+
* ```js
|
|
20545
|
+
* import { observePosts } from '@amityco/ts-sdk'
|
|
20546
|
+
*
|
|
20547
|
+
* let posts = []
|
|
20548
|
+
* const unsub = observePosts({
|
|
20549
|
+
* targetType: Amity.PostTargetType,
|
|
20550
|
+
* targetId: Amity.Post['targetId'],
|
|
20551
|
+
* }, post => merge(posts, post))
|
|
20552
|
+
* ```
|
|
20553
|
+
*
|
|
20554
|
+
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
20555
|
+
*
|
|
20556
|
+
* @param targetType the type of the target
|
|
20557
|
+
* @param targetId the ID of the target
|
|
20558
|
+
* @param callback the function to call when new data are available
|
|
19568
20559
|
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
19569
20560
|
*
|
|
19570
20561
|
* @category Post Observer
|
|
@@ -19576,8 +20567,7 @@ const observePosts = (params, callback) => {
|
|
|
19576
20567
|
const disposers = [];
|
|
19577
20568
|
const router = (post, action) => {
|
|
19578
20569
|
var _a, _b;
|
|
19579
|
-
if (params.targetId !== post.targetId
|
|
19580
|
-
|| params.targetType !== post.targetType)
|
|
20570
|
+
if (params.targetId !== post.targetId || params.targetType !== post.targetType)
|
|
19581
20571
|
return;
|
|
19582
20572
|
if (callback instanceof Function)
|
|
19583
20573
|
return callback(post);
|
|
@@ -19788,9 +20778,11 @@ const queryStreams = async (query) => {
|
|
|
19788
20778
|
const client = getActiveClient();
|
|
19789
20779
|
client.log('stream/queryStreams', query);
|
|
19790
20780
|
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
19791
|
-
const { data } = await client.http.get(`/api/v3/video-streaming`, {
|
|
20781
|
+
const { data } = await client.http.get(`/api/v3/video-streaming`, {
|
|
20782
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
19792
20783
|
token: toToken(page, 'skiplimit'),
|
|
19793
|
-
} })
|
|
20784
|
+
} }),
|
|
20785
|
+
});
|
|
19794
20786
|
// API-FIX: backend to response Amity.Response: const { paging, videoStreamings } = unwrapPayload(data)
|
|
19795
20787
|
// API-FIX: seems returned data has a results identifier on top of data, like no other apis, and this is beautiful
|
|
19796
20788
|
const { paging, results: payload } = data;
|
|
@@ -19896,7 +20888,7 @@ const updateStream = async (streamId, patch) => {
|
|
|
19896
20888
|
const deleteStream = async (streamId) => {
|
|
19897
20889
|
const client = getActiveClient();
|
|
19898
20890
|
client.log('stream/deleteStream', streamId);
|
|
19899
|
-
|
|
20891
|
+
const stream = await getStream(streamId);
|
|
19900
20892
|
// API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
|
|
19901
20893
|
// API-FIX: swagger docs are wrong!
|
|
19902
20894
|
const { data } = await client.http.delete(`/api/v3/video-streaming/${streamId}`);
|
|
@@ -20007,11 +20999,13 @@ const onStreamRecorded = (callback) => {
|
|
|
20007
20999
|
return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
|
|
20008
21000
|
};
|
|
20009
21001
|
|
|
21002
|
+
exports.API_REGIONS = API_REGIONS;
|
|
20010
21003
|
exports.VERSION = VERSION$1;
|
|
21004
|
+
exports.acceptFollower = acceptFollower;
|
|
20011
21005
|
exports.addChannelMembers = addChannelMembers;
|
|
20012
21006
|
exports.addChannelMembersRole = addChannelMembersRole;
|
|
20013
21007
|
exports.addCommunityMembers = addCommunityMembers;
|
|
20014
|
-
exports.
|
|
21008
|
+
exports.addCommunityMembersRoles = addCommunityMembersRoles;
|
|
20015
21009
|
exports.addReaction = addReaction;
|
|
20016
21010
|
exports.backupCache = backupCache;
|
|
20017
21011
|
exports.connectClient = connectClient;
|
|
@@ -20025,6 +21019,8 @@ exports.createPost = createPost;
|
|
|
20025
21019
|
exports.createQuery = createQuery;
|
|
20026
21020
|
exports.createReport = createReport;
|
|
20027
21021
|
exports.createStream = createStream;
|
|
21022
|
+
exports.createVideo = createVideo;
|
|
21023
|
+
exports.declineFollower = declineFollower;
|
|
20028
21024
|
exports.deleteChannel = deleteChannel;
|
|
20029
21025
|
exports.deleteComment = deleteComment;
|
|
20030
21026
|
exports.deleteCommunity = deleteCommunity;
|
|
@@ -20040,7 +21036,9 @@ exports.dropFromCache = dropFromCache;
|
|
|
20040
21036
|
exports.enableCache = enableCache;
|
|
20041
21037
|
exports.fileUrlWithSize = fileUrlWithSize;
|
|
20042
21038
|
exports.filterByPropEquality = filterByPropEquality;
|
|
21039
|
+
exports.follow = follow;
|
|
20043
21040
|
exports.getActiveClient = getActiveClient;
|
|
21041
|
+
exports.getCategory = getCategory;
|
|
20044
21042
|
exports.getChannel = getChannel;
|
|
20045
21043
|
exports.getChannels = getChannels;
|
|
20046
21044
|
exports.getComment = getComment;
|
|
@@ -20050,13 +21048,18 @@ exports.getCommunities = getCommunities;
|
|
|
20050
21048
|
exports.getCommunity = getCommunity;
|
|
20051
21049
|
exports.getCommunityTopic = getCommunityTopic;
|
|
20052
21050
|
exports.getFile = getFile;
|
|
21051
|
+
exports.getFollowInfo = getFollowInfo;
|
|
20053
21052
|
exports.getMessage = getMessage;
|
|
20054
21053
|
exports.getMessages = getMessages;
|
|
21054
|
+
exports.getMyFollowersTopic = getMyFollowersTopic;
|
|
21055
|
+
exports.getMyFollowingsTopic = getMyFollowingsTopic;
|
|
20055
21056
|
exports.getPost = getPost;
|
|
20056
21057
|
exports.getPostTopic = getPostTopic;
|
|
20057
21058
|
exports.getPosts = getPosts;
|
|
21059
|
+
exports.getRecommendedCommunities = getRecommendedCommunities;
|
|
20058
21060
|
exports.getRole = getRole;
|
|
20059
21061
|
exports.getStream = getStream;
|
|
21062
|
+
exports.getTopTrendingCommunities = getTopTrendingCommunities;
|
|
20060
21063
|
exports.getUser = getUser;
|
|
20061
21064
|
exports.getUserTopic = getUserTopic;
|
|
20062
21065
|
exports.getUsers = getUsers;
|
|
@@ -20082,6 +21085,9 @@ exports.observeComment = observeComment;
|
|
|
20082
21085
|
exports.observeComments = observeComments;
|
|
20083
21086
|
exports.observeCommunity = observeCommunity;
|
|
20084
21087
|
exports.observeFile = observeFile;
|
|
21088
|
+
exports.observeFollowInfo = observeFollowInfo;
|
|
21089
|
+
exports.observeFollowers = observeFollowers;
|
|
21090
|
+
exports.observeFollowings = observeFollowings;
|
|
20085
21091
|
exports.observeMessage = observeMessage;
|
|
20086
21092
|
exports.observeMessages = observeMessages;
|
|
20087
21093
|
exports.observePost = observePost;
|
|
@@ -20110,6 +21116,12 @@ exports.onCommunityUserBanned = onCommunityUserBanned;
|
|
|
20110
21116
|
exports.onCommunityUserRemoved = onCommunityUserRemoved;
|
|
20111
21117
|
exports.onCommunityUserUnbanned = onCommunityUserUnbanned;
|
|
20112
21118
|
exports.onConnectionError = onConnectionError;
|
|
21119
|
+
exports.onFollowInfoUpdated = onFollowInfoUpdated;
|
|
21120
|
+
exports.onFollowRequestAccepted = onFollowRequestAccepted;
|
|
21121
|
+
exports.onFollowRequestCanceled = onFollowRequestCanceled;
|
|
21122
|
+
exports.onFollowRequestDeclined = onFollowRequestDeclined;
|
|
21123
|
+
exports.onFollowerDeleted = onFollowerDeleted;
|
|
21124
|
+
exports.onFollowerRequested = onFollowerRequested;
|
|
20113
21125
|
exports.onMemberAdded = onMemberAdded;
|
|
20114
21126
|
exports.onMemberRemoved = onMemberRemoved;
|
|
20115
21127
|
exports.onMessageCreated = onMessageCreated;
|
|
@@ -20130,16 +21142,21 @@ exports.onStreamStarted = onStreamStarted;
|
|
|
20130
21142
|
exports.onStreamStopped = onStreamStopped;
|
|
20131
21143
|
exports.onUserFlagCleared = onUserFlagCleared;
|
|
20132
21144
|
exports.onUserFlagged = onUserFlagged;
|
|
21145
|
+
exports.onUserFollowed = onUserFollowed;
|
|
20133
21146
|
exports.onUserUnflagged = onUserUnflagged;
|
|
21147
|
+
exports.onUserUnfollowed = onUserUnfollowed;
|
|
20134
21148
|
exports.onUserUpdated = onUserUpdated;
|
|
20135
21149
|
exports.pullFromCache = pullFromCache;
|
|
20136
21150
|
exports.pushToCache = pushToCache;
|
|
20137
21151
|
exports.queryCache = queryCache;
|
|
21152
|
+
exports.queryCategories = queryCategories;
|
|
20138
21153
|
exports.queryChannelMembers = queryChannelMembers;
|
|
20139
21154
|
exports.queryChannels = queryChannels;
|
|
20140
21155
|
exports.queryComments = queryComments;
|
|
20141
21156
|
exports.queryCommunities = queryCommunities;
|
|
20142
21157
|
exports.queryCommunityMembers = queryCommunityMembers;
|
|
21158
|
+
exports.queryFollowers = queryFollowers;
|
|
21159
|
+
exports.queryFollowings = queryFollowings;
|
|
20143
21160
|
exports.queryGlobalFeed = queryGlobalFeed;
|
|
20144
21161
|
exports.queryMessages = queryMessages;
|
|
20145
21162
|
exports.queryOptions = queryOptions;
|
|
@@ -20150,7 +21167,7 @@ exports.queryUsers = queryUsers;
|
|
|
20150
21167
|
exports.removeChannelMembers = removeChannelMembers;
|
|
20151
21168
|
exports.removeChannelMembersRole = removeChannelMembersRole;
|
|
20152
21169
|
exports.removeCommunityMembers = removeCommunityMembers;
|
|
20153
|
-
exports.
|
|
21170
|
+
exports.removeCommunityMembersRoles = removeCommunityMembersRoles;
|
|
20154
21171
|
exports.removeReaction = removeReaction;
|
|
20155
21172
|
exports.restoreCache = restoreCache;
|
|
20156
21173
|
exports.runQuery = runQuery;
|
|
@@ -20164,6 +21181,7 @@ exports.subscribeTopic = subscribeTopic;
|
|
|
20164
21181
|
exports.toPage = toPage;
|
|
20165
21182
|
exports.toPageRaw = toPageRaw;
|
|
20166
21183
|
exports.toToken = toToken;
|
|
21184
|
+
exports.unfollow = unfollow;
|
|
20167
21185
|
exports.updateChannel = updateChannel;
|
|
20168
21186
|
exports.updateComment = updateComment;
|
|
20169
21187
|
exports.updateCommunity = updateCommunity;
|