From 6b9c966f6428c9e47bead3410a0401e8ebd744bf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Aug 2019 17:19:53 +0200 Subject: Automatically remove bad followings --- server/models/utils.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'server/models/utils.ts') diff --git a/server/models/utils.ts b/server/models/utils.ts index 30de91e1d..24890f961 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -1,7 +1,7 @@ import { Model, Sequelize } from 'sequelize-typescript' import * as validator from 'validator' import { Col } from 'sequelize/types/lib/utils' -import { OrderItem } from 'sequelize/types' +import { OrderItem, literal } from 'sequelize' type SortType = { sortModel: any, sortValue: string } @@ -129,16 +129,30 @@ function parseAggregateResult (result: any) { return total } -const createSafeIn = (model: typeof Model, stringArr: string[]) => { - return stringArr.map(t => model.sequelize.escape(t)) +const createSafeIn = (model: typeof Model, stringArr: (string | number)[]) => { + return stringArr.map(t => model.sequelize.escape('' + t)) .join(', ') } +function buildLocalAccountIdsIn () { + return literal( + '(SELECT "account"."id" FROM "account" INNER JOIN "actor" ON "actor"."id" = "account"."actorId" AND "actor"."serverId" IS NULL)' + ) +} + +function buildLocalActorIdsIn () { + return literal( + '(SELECT "actor"."id" FROM "actor" WHERE "actor"."serverId" IS NULL)' + ) +} + // --------------------------------------------------------------------------- export { buildBlockedAccountSQL, + buildLocalActorIdsIn, SortType, + buildLocalAccountIdsIn, getSort, getVideoSort, getSortOnModel, -- cgit v1.2.3