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