diff options
Diffstat (limited to 'server/models/activitypub')
-rw-r--r-- | server/models/activitypub/actor-follow.ts | 26 |
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' | |||
23 | import { getServerActor } from '../../helpers/utils' | 23 | import { getServerActor } from '../../helpers/utils' |
24 | import { ACTOR_FOLLOW_SCORE, FOLLOW_STATES } from '../../initializers/constants' | 24 | import { ACTOR_FOLLOW_SCORE, FOLLOW_STATES } from '../../initializers/constants' |
25 | import { ServerModel } from '../server/server' | 25 | import { ServerModel } from '../server/server' |
26 | import { getSort } from '../utils' | 26 | import { createSafeIn, getSort } from '../utils' |
27 | import { ActorModel, unusedActorAttributesForAPI } from './actor' | 27 | import { ActorModel, unusedActorAttributesForAPI } from './actor' |
28 | import { VideoChannelModel } from '../video/video-channel' | 28 | import { VideoChannelModel } from '../video/video-channel' |
29 | import { AccountModel } from '../account/account' | 29 | import { 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[], |