Unfollow with host

This commit is contained in:
Chocobozzz 2017-12-15 17:38:48 +01:00
parent a7d647c440
commit 39fdb3c032
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 5 additions and 45 deletions

View File

@ -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))
}

View File

@ -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<ActorModel>
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<ActorModel>, 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
}

View File

@ -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)
}

View File

@ -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)
}