aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-08-06 17:19:53 +0200
committerChocobozzz <me@florianbigard.com>2019-08-06 17:26:51 +0200
commit6b9c966f6428c9e47bead3410a0401e8ebd744bf (patch)
tree282218ec56725b0e2e878b0471cd08a54fd91998 /server/models/activitypub
parent466e3f20a537f1eff4b4fd03297df11ba371d049 (diff)
downloadPeerTube-6b9c966f6428c9e47bead3410a0401e8ebd744bf.tar.gz
PeerTube-6b9c966f6428c9e47bead3410a0401e8ebd744bf.tar.zst
PeerTube-6b9c966f6428c9e47bead3410a0401e8ebd744bf.zip
Automatically remove bad followings
Diffstat (limited to 'server/models/activitypub')
-rw-r--r--server/models/activitypub/actor-follow.ts26
1 files changed, 24 insertions, 2 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index 3039b90c7..99a5fd117 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -23,7 +23,7 @@ import { logger } from '../../helpers/logger'
23import { getServerActor } from '../../helpers/utils' 23import { getServerActor } from '../../helpers/utils'
24import { ACTOR_FOLLOW_SCORE, FOLLOW_STATES } from '../../initializers/constants' 24import { ACTOR_FOLLOW_SCORE, FOLLOW_STATES } from '../../initializers/constants'
25import { ServerModel } from '../server/server' 25import { ServerModel } from '../server/server'
26import { getSort } from '../utils' 26import { createSafeIn, getSort } from '../utils'
27import { ActorModel, unusedActorAttributesForAPI } from './actor' 27import { ActorModel, unusedActorAttributesForAPI } from './actor'
28import { VideoChannelModel } from '../video/video-channel' 28import { VideoChannelModel } from '../video/video-channel'
29import { AccountModel } from '../account/account' 29import { AccountModel } from '../account/account'
@@ -464,7 +464,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
464 } 464 }
465 } 465 }
466 466
467 static updateFollowScore (inboxUrl: string, value: number, t?: Transaction) { 467 static updateScore (inboxUrl: string, value: number, t?: Transaction) {
468 const query = `UPDATE "actorFollow" SET "score" = LEAST("score" + ${value}, ${ACTOR_FOLLOW_SCORE.MAX}) ` + 468 const query = `UPDATE "actorFollow" SET "score" = LEAST("score" + ${value}, ${ACTOR_FOLLOW_SCORE.MAX}) ` +
469 'WHERE id IN (' + 469 'WHERE id IN (' +
470 'SELECT "actorFollow"."id" FROM "actorFollow" ' + 470 'SELECT "actorFollow"."id" FROM "actorFollow" ' +
@@ -480,6 +480,28 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
480 return ActorFollowModel.sequelize.query(query, options) 480 return ActorFollowModel.sequelize.query(query, options)
481 } 481 }
482 482
483 static async updateScoreByFollowingServers (serverIds: number[], value: number, t?: Transaction) {
484 if (serverIds.length === 0) return
485
486 const me = await getServerActor()
487 const serverIdsString = createSafeIn(ActorFollowModel, serverIds)
488
489 const query = `UPDATE "actorFollow" SET "score" = "score" + ${value} ` +
490 'WHERE id IN (' +
491 'SELECT "actorFollow"."id" FROM "actorFollow" ' +
492 'INNER JOIN "actor" ON "actor"."id" = "actorFollow"."targetActorId" ' +
493 `WHERE "actorFollow"."actorId" = ${me.Account.actorId} ` + // I'm the follower
494 `AND "actor"."serverId" IN (${serverIdsString})` + // Criteria on followings
495 ')'
496
497 const options = {
498 type: QueryTypes.BULKUPDATE,
499 transaction: t
500 }
501
502 return ActorFollowModel.sequelize.query(query, options)
503 }
504
483 private static async createListAcceptedFollowForApiQuery ( 505 private static async createListAcceptedFollowForApiQuery (
484 type: 'followers' | 'following', 506 type: 'followers' | 'following',
485 actorIds: number[], 507 actorIds: number[],