X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=server%2Fmodels%2Factivitypub%2Factor-follow.ts;h=3e85cc329e9569b2a0226602056782c7d4d11778;hb=26d6bf6533023326fa017812cf31bbe20c752d36;hp=27643704e152275ed7cfb02af43390a1db207058;hpb=4c1def5fd8e9f483238eb38e221f555e2e6bbf07;p=oweals%2Fpeertube.git diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts index 27643704e..3e85cc329 100644 --- a/server/models/activitypub/actor-follow.ts +++ b/server/models/activitypub/actor-follow.ts @@ -20,7 +20,6 @@ import { import { FollowState } from '../../../shared/models/actors' import { ActorFollow } from '../../../shared/models/actors/follow.model' import { logger } from '../../helpers/logger' -import { getServerActor } from '../../helpers/utils' import { ACTOR_FOLLOW_SCORE, FOLLOW_STATES, SERVER_ACTOR_NAME } from '../../initializers/constants' import { ServerModel } from '../server/server' import { createSafeIn, getFollowsSort, getSort } from '../utils' @@ -34,8 +33,10 @@ import { MActorFollowFollowingHost, MActorFollowFormattable, MActorFollowSubscriptions -} from '@server/typings/models' +} from '@server/types/models' import { ActivityPubActorType } from '@shared/models' +import { VideoModel } from '@server/models/video/video' +import { getServerActor } from '@server/models/application/application' @Table({ tableName: 'actorFollow', @@ -151,6 +152,18 @@ export class ActorFollowModel extends Model { if (numberOfActorFollowsRemoved) logger.info('Removed bad %d actor follows.', numberOfActorFollowsRemoved) } + static isFollowedBy (actorId: number, followerActorId: number) { + const query = 'SELECT 1 FROM "actorFollow" WHERE "actorId" = $followerActorId AND "targetActorId" = $actorId LIMIT 1' + const options = { + type: QueryTypes.SELECT as QueryTypes.SELECT, + bind: { actorId, followerActorId }, + raw: true + } + + return VideoModel.sequelize.query(query, options) + .then(results => results.length === 1) + } + static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Transaction): Bluebird { const query = { where: {