From 39fdb3c032875ab8c9a1e5e52f76d3baa0ac4e63 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 15 Dec 2017 17:38:48 +0100 Subject: [PATCH] Unfollow with host --- .../+admin/follows/shared/follow.service.ts | 2 +- .../custom-validators/activitypub/actor.ts | 42 +------------------ .../migrations/0130-video-channel-actor.ts | 4 +- .../lib/activitypub/process/process-follow.ts | 2 +- 4 files changed, 5 insertions(+), 45 deletions(-) diff --git a/client/src/app/+admin/follows/shared/follow.service.ts b/client/src/app/+admin/follows/shared/follow.service.ts index 3a430ff64..089be9d64 100644 --- a/client/src/app/+admin/follows/shared/follow.service.ts +++ b/client/src/app/+admin/follows/shared/follow.service.ts @@ -47,7 +47,7 @@ export class FollowService { } unfollow (follow: AccountFollow) { - return this.authHttp.delete(FollowService.BASE_APPLICATION_URL + '/following/' + follow.following.id) + return this.authHttp.delete(FollowService.BASE_APPLICATION_URL + '/following/' + follow.following.host) .map(this.restExtractor.extractDataBool) .catch(res => this.restExtractor.handleError(res)) } diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts index bf42757c5..5930bd5da 100644 --- a/server/helpers/custom-validators/activitypub/actor.ts +++ b/server/helpers/custom-validators/activitypub/actor.ts @@ -1,8 +1,5 @@ -import * as Bluebird from 'bluebird' -import { Response } from 'express' import * as validator from 'validator' import { CONSTRAINTS_FIELDS } from '../../../initializers' -import { ActorModel } from '../../../models/activitypub/actor' import { isAccountNameValid } from '../accounts' import { exists, isUUIDValid } from '../misc' import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' @@ -88,40 +85,6 @@ function isActorAcceptActivityValid (activity: any) { return isBaseActivityValid(activity, 'Accept') } -function isActorIdExist (id: number | string, res: Response) { - let promise: Bluebird - - if (validator.isInt('' + id)) { - promise = ActorModel.load(+id) - } else { // UUID - promise = ActorModel.loadByUUID('' + id) - } - - return isActorExist(promise, res) -} - -function isLocalActorNameExist (name: string, res: Response) { - const promise = ActorModel.loadLocalByName(name) - - return isActorExist(promise, res) -} - -async function isActorExist (p: Bluebird, res: Response) { - const actor = await p - - if (!actor) { - res.status(404) - .send({ error: 'Actor not found' }) - .end() - - return false - } - - res.locals.actor = actor - - return true -} - // --------------------------------------------------------------------------- export { @@ -137,8 +100,5 @@ export { isActorFollowActivityValid, isActorAcceptActivityValid, isActorDeleteActivityValid, - isActorIdExist, - isLocalActorNameExist, - isActorNameValid, - isActorExist + isActorNameValid } diff --git a/server/initializers/migrations/0130-video-channel-actor.ts b/server/initializers/migrations/0130-video-channel-actor.ts index 72a0daef7..0b665b0c7 100644 --- a/server/initializers/migrations/0130-video-channel-actor.ts +++ b/server/initializers/migrations/0130-video-channel-actor.ts @@ -167,12 +167,12 @@ async function up (utils: { const query1 = `UPDATE "actorFollow" SET "actorId" = - (SELECT "actorId" FROM account WHERE id = "actorFollow"."actorId")` + (SELECT "account"."actorId" FROM account WHERE "account"."id" = "actorFollow"."actorId")` await utils.sequelize.query(query1) const query2 = `UPDATE "actorFollow" SET "targetActorId" = - (SELECT "actorId" FROM account WHERE id = "actorFollow"."actorId")` + (SELECT "account"."actorId" FROM account WHERE "account"."id" = "actorFollow"."targetActorId")` await utils.sequelize.query(query2) } diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index ec7a331f3..bc02d5043 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts @@ -62,5 +62,5 @@ async function follow (actor: ActorModel, targetActorURL: string) { return sendAccept(actorFollow, t) }) - logger.info('Actor uuid %s is followed by actor %s.', actor.url, targetActorURL) + logger.info('Actor %s is followed by actor %s.', actor.url, targetActorURL) } -- 2.25.1