X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fusers%2Fme.ts;h=000c706b5c10a592a130df386e8e7a865d60e525;hb=f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9;hp=2300f5dbe301003290bf64d490d5bb3c83bb9e54;hpb=240085d0056fd97ac3c7fa8fa4ce9bc32afc4d6e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index 2300f5dbe..000c706b5 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts @@ -20,7 +20,8 @@ import { deleteMeValidator, userSubscriptionsSortValidator, videoImportsSortValidator, - videosSortValidator + videosSortValidator, + areSubscriptionsExistValidator } from '../../../middlewares/validators' import { AccountVideoRateModel } from '../../../models/account/account-video-rate' import { UserModel } from '../../../models/account/user' @@ -98,7 +99,6 @@ meRouter.post('/me/avatar/pick', // ##### Subscriptions part ##### meRouter.get('/me/subscriptions/videos', - authenticate, authenticate, paginationValidator, videosSortValidator, @@ -108,6 +108,12 @@ meRouter.get('/me/subscriptions/videos', asyncMiddleware(getUserSubscriptionVideos) ) +meRouter.get('/me/subscriptions/exist', + authenticate, + areSubscriptionsExistValidator, + asyncMiddleware(areSubscriptionsExist) +) + meRouter.get('/me/subscriptions', authenticate, paginationValidator, @@ -143,6 +149,37 @@ export { // --------------------------------------------------------------------------- +async function areSubscriptionsExist (req: express.Request, res: express.Response) { + const uris = req.query.uris as string[] + const user = res.locals.oauth.token.User as UserModel + + const handles = uris.map(u => { + let [ name, host ] = u.split('@') + if (host === CONFIG.WEBSERVER.HOST) host = null + + return { name, host, uri: u } + }) + + const results = await ActorFollowModel.listSubscribedIn(user.Account.Actor.id, handles) + + const existObject: { [id: string ]: boolean } = {} + for (const handle of handles) { + const obj = results.find(r => { + const server = r.ActorFollowing.Server + + return r.ActorFollowing.preferredUsername === handle.name && + ( + (!server && !handle.host) || + (server.host === handle.host) + ) + }) + + existObject[handle.uri] = obj !== undefined + } + + return res.json(existObject) +} + async function addUserSubscription (req: express.Request, res: express.Response) { const user = res.locals.oauth.token.User as UserModel const [ name, host ] = req.body.uri.split('@')