aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/actor/actor-follow.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/actor/actor-follow.ts')
-rw-r--r--server/models/actor/actor-follow.ts36
1 files changed, 14 insertions, 22 deletions
diff --git a/server/models/actor/actor-follow.ts b/server/models/actor/actor-follow.ts
index 3a09e51d6..283856d3f 100644
--- a/server/models/actor/actor-follow.ts
+++ b/server/models/actor/actor-follow.ts
@@ -20,7 +20,6 @@ import {
20} from 'sequelize-typescript' 20} from 'sequelize-typescript'
21import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' 21import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
22import { getServerActor } from '@server/models/application/application' 22import { getServerActor } from '@server/models/application/application'
23import { VideoModel } from '@server/models/video/video'
24import { 23import {
25 MActorFollowActorsDefault, 24 MActorFollowActorsDefault,
26 MActorFollowActorsDefaultSubscription, 25 MActorFollowActorsDefaultSubscription,
@@ -36,6 +35,7 @@ import { logger } from '../../helpers/logger'
36import { ACTOR_FOLLOW_SCORE, CONSTRAINTS_FIELDS, FOLLOW_STATES, SERVER_ACTOR_NAME } from '../../initializers/constants' 35import { ACTOR_FOLLOW_SCORE, CONSTRAINTS_FIELDS, FOLLOW_STATES, SERVER_ACTOR_NAME } from '../../initializers/constants'
37import { AccountModel } from '../account/account' 36import { AccountModel } from '../account/account'
38import { ServerModel } from '../server/server' 37import { ServerModel } from '../server/server'
38import { doesExist } from '../shared/query'
39import { createSafeIn, getFollowsSort, getSort, searchAttribute, throwIfNotValid } from '../utils' 39import { createSafeIn, getFollowsSort, getSort, searchAttribute, throwIfNotValid } from '../utils'
40import { VideoChannelModel } from '../video/video-channel' 40import { VideoChannelModel } from '../video/video-channel'
41import { ActorModel, unusedActorAttributesForAPI } from './actor' 41import { ActorModel, unusedActorAttributesForAPI } from './actor'
@@ -166,14 +166,8 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo
166 166
167 static isFollowedBy (actorId: number, followerActorId: number) { 167 static isFollowedBy (actorId: number, followerActorId: number) {
168 const query = 'SELECT 1 FROM "actorFollow" WHERE "actorId" = $followerActorId AND "targetActorId" = $actorId LIMIT 1' 168 const query = 'SELECT 1 FROM "actorFollow" WHERE "actorId" = $followerActorId AND "targetActorId" = $actorId LIMIT 1'
169 const options = {
170 type: QueryTypes.SELECT as QueryTypes.SELECT,
171 bind: { actorId, followerActorId },
172 raw: true
173 }
174 169
175 return VideoModel.sequelize.query(query, options) 170 return doesExist(query, { actorId, followerActorId })
176 .then(results => results.length === 1)
177 } 171 }
178 172
179 static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Transaction): Promise<MActorFollowActorsDefault> { 173 static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Transaction): Promise<MActorFollowActorsDefault> {
@@ -324,13 +318,13 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo
324 318
325 const followWhere = state ? { state } : {} 319 const followWhere = state ? { state } : {}
326 const followingWhere: WhereOptions = {} 320 const followingWhere: WhereOptions = {}
327 const followingServerWhere: WhereOptions = {}
328 321
329 if (search) { 322 if (search) {
330 Object.assign(followingServerWhere, { 323 Object.assign(followWhere, {
331 host: { 324 [Op.or]: [
332 [Op.iLike]: '%' + search + '%' 325 searchAttribute(options.search, '$ActorFollowing.preferredUsername$'),
333 } 326 searchAttribute(options.search, '$ActorFollowing.Server.host$')
327 ]
334 }) 328 })
335 } 329 }
336 330
@@ -361,8 +355,7 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo
361 include: [ 355 include: [
362 { 356 {
363 model: ServerModel, 357 model: ServerModel,
364 required: true, 358 required: true
365 where: followingServerWhere
366 } 359 }
367 ] 360 ]
368 } 361 }
@@ -391,13 +384,13 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo
391 384
392 const followWhere = state ? { state } : {} 385 const followWhere = state ? { state } : {}
393 const followerWhere: WhereOptions = {} 386 const followerWhere: WhereOptions = {}
394 const followerServerWhere: WhereOptions = {}
395 387
396 if (search) { 388 if (search) {
397 Object.assign(followerServerWhere, { 389 Object.assign(followWhere, {
398 host: { 390 [Op.or]: [
399 [Op.iLike]: '%' + search + '%' 391 searchAttribute(search, '$ActorFollower.preferredUsername$'),
400 } 392 searchAttribute(search, '$ActorFollower.Server.host$')
393 ]
401 }) 394 })
402 } 395 }
403 396
@@ -420,8 +413,7 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo
420 include: [ 413 include: [
421 { 414 {
422 model: ServerModel, 415 model: ServerModel,
423 required: true, 416 required: true
424 where: followerServerWhere
425 } 417 }
426 ] 418 ]
427 }, 419 },