From 927fa4b11f692174d6296aa096d7a74bacdeea8b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 26 Jul 2022 14:46:15 +0200 Subject: Add rejected state to follows Prevent reprocessing already rejected follows --- server/models/actor/actor-follow.ts | 40 +++++++++++++++++++++++-------------- server/models/actor/actor.ts | 2 +- 2 files changed, 26 insertions(+), 16 deletions(-) (limited to 'server/models') diff --git a/server/models/actor/actor-follow.ts b/server/models/actor/actor-follow.ts index 8870bec05..566bb5f31 100644 --- a/server/models/actor/actor-follow.ts +++ b/server/models/actor/actor-follow.ts @@ -1,5 +1,5 @@ import { difference, values } from 'lodash' -import { Includeable, IncludeOptions, Op, QueryTypes, Transaction } from 'sequelize' +import { Attributes, FindOptions, Includeable, IncludeOptions, Op, QueryTypes, Transaction, WhereAttributeHash } from 'sequelize' import { AfterCreate, AfterDestroy, @@ -209,7 +209,9 @@ export class ActorFollowModel extends Model { + static loadByActorAndTargetNameAndHostForAPI (options: { + actorId: number + targetName: string + targetHost: string + state?: FollowState + transaction?: Transaction + }): Promise { + const { actorId, targetHost, targetName, state, transaction } = options + const actorFollowingPartInclude: IncludeOptions = { model: ActorModel, required: true, @@ -271,10 +276,11 @@ export class ActorFollowModel extends Model> = { actorId} + if (state) where.state = state + + const query: FindOptions> = { + where, include: [ actorFollowingPartInclude, { @@ -283,7 +289,7 @@ export class ActorFollowModel extends Model>> { } return ActorModel.update({ - [columnToUpdate]: literal(`(SELECT COUNT(*) FROM "actorFollow" WHERE "${columnOfCount}" = ${sanitizedOfId})`) + [columnToUpdate]: literal(`(SELECT COUNT(*) FROM "actorFollow" WHERE "${columnOfCount}" = ${sanitizedOfId} AND "state" = 'accepted')`) }, { where, transaction }) } -- cgit v1.2.3