aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/activitypub/actor-follow.ts51
1 files changed, 38 insertions, 13 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index 09bc6853d..c3c4d61ab 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -27,7 +27,7 @@ import { 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'
30import { IncludeOptions, Op, QueryTypes, Transaction } from 'sequelize' 30import { IncludeOptions, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
31import { 31import {
32 MActorFollowActorsDefault, 32 MActorFollowActorsDefault,
33 MActorFollowActorsDefaultSubscription, 33 MActorFollowActorsDefaultSubscription,
@@ -35,6 +35,7 @@ import {
35 MActorFollowFormattable, 35 MActorFollowFormattable,
36 MActorFollowSubscriptions 36 MActorFollowSubscriptions
37} from '@server/typings/models' 37} from '@server/typings/models'
38import { ActivityPubActorType } from '@shared/models'
38 39
39@Table({ 40@Table({
40 tableName: 'actorFollow', 41 tableName: 'actorFollow',
@@ -298,11 +299,26 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
298 count: number, 299 count: number,
299 sort: string, 300 sort: string,
300 state?: FollowState, 301 state?: FollowState,
302 actorType?: ActivityPubActorType,
301 search?: string 303 search?: string
302 }) { 304 }) {
303 const { id, start, count, sort, search, state } = options 305 const { id, start, count, sort, search, state, actorType } = options
304 306
305 const followWhere = state ? { state } : {} 307 const followWhere = state ? { state } : {}
308 const followingWhere: WhereOptions = {}
309 const followingServerWhere: WhereOptions = {}
310
311 if (search) {
312 Object.assign(followingServerWhere, {
313 host: {
314 [ Op.iLike ]: '%' + search + '%'
315 }
316 })
317 }
318
319 if (actorType) {
320 Object.assign(followingWhere, { type: actorType })
321 }
306 322
307 const query = { 323 const query = {
308 distinct: true, 324 distinct: true,
@@ -323,15 +339,12 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
323 model: ActorModel, 339 model: ActorModel,
324 as: 'ActorFollowing', 340 as: 'ActorFollowing',
325 required: true, 341 required: true,
342 where: followingWhere,
326 include: [ 343 include: [
327 { 344 {
328 model: ServerModel, 345 model: ServerModel,
329 required: true, 346 required: true,
330 where: search ? { 347 where: followingServerWhere
331 host: {
332 [Op.iLike]: '%' + search + '%'
333 }
334 } : undefined
335 } 348 }
336 ] 349 ]
337 } 350 }
@@ -353,11 +366,26 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
353 count: number, 366 count: number,
354 sort: string, 367 sort: string,
355 state?: FollowState, 368 state?: FollowState,
369 actorType?: ActivityPubActorType,
356 search?: string 370 search?: string
357 }) { 371 }) {
358 const { actorId, start, count, sort, search, state } = options 372 const { actorId, start, count, sort, search, state, actorType } = options
359 373
360 const followWhere = state ? { state } : {} 374 const followWhere = state ? { state } : {}
375 const followerWhere: WhereOptions = {}
376 const followerServerWhere: WhereOptions = {}
377
378 if (search) {
379 Object.assign(followerServerWhere, {
380 host: {
381 [ Op.iLike ]: '%' + search + '%'
382 }
383 })
384 }
385
386 if (actorType) {
387 Object.assign(followerWhere, { type: actorType })
388 }
361 389
362 const query = { 390 const query = {
363 distinct: true, 391 distinct: true,
@@ -370,15 +398,12 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
370 model: ActorModel, 398 model: ActorModel,
371 required: true, 399 required: true,
372 as: 'ActorFollower', 400 as: 'ActorFollower',
401 where: followerWhere,
373 include: [ 402 include: [
374 { 403 {
375 model: ServerModel, 404 model: ServerModel,
376 required: true, 405 required: true,
377 where: search ? { 406 where: followerServerWhere
378 host: {
379 [ Op.iLike ]: '%' + search + '%'
380 }
381 } : undefined
382 } 407 }
383 ] 408 ]
384 }, 409 },