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'
+import { createSafeIn, getFollowsSort, getSort, searchAttribute } from '../utils'
import { ActorModel, unusedActorAttributesForAPI } from './actor'
import { VideoChannelModel } from '../video/video-channel'
import { AccountModel } from '../account/account'
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',
})
}
- static listSubscriptionsForApi (actorId: number, start: number, count: number, sort: string) {
+ static listSubscriptionsForApi (options: {
+ actorId: number
+ start: number
+ count: number
+ sort: string
+ search?: string
+ }) {
+ const { actorId, start, count, sort } = options
+ const where = {
+ actorId: actorId
+ }
+
+ if (options.search) {
+ Object.assign(where, {
+ [Op.or]: [
+ searchAttribute(options.search, '$ActorFollowing.preferredUsername$'),
+ searchAttribute(options.search, '$ActorFollowing.VideoChannel.name$')
+ ]
+ })
+ }
+
const query = {
attributes: [],
distinct: true,
offset: start,
limit: count,
order: getSort(sort),
- where: {
- actorId: actorId
- },
+ where,
include: [
{
attributes: [ 'id' ],