X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Factor%2Factor-follow.ts;h=71ce9fa6fb2887d298cecd999ac6e2bfb6e9c692;hb=64aa66c4a61e1c6aa83a775e7af498e288ea82e4;hp=af1d85e9f8befbb44573edd2a8076452c898d83f;hpb=69c1f3c25622500e0956127a2493bba54fce97f8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/actor/actor-follow.ts b/server/models/actor/actor-follow.ts index af1d85e9f..71ce9fa6f 100644 --- a/server/models/actor/actor-follow.ts +++ b/server/models/actor/actor-follow.ts @@ -1,5 +1,5 @@ -import { difference, values } from 'lodash' -import { Includeable, IncludeOptions, Op, QueryTypes, Transaction } from 'sequelize' +import { difference } from 'lodash' +import { Attributes, FindOptions, Includeable, IncludeOptions, Op, QueryTypes, Transaction, WhereAttributeHash } from 'sequelize' import { AfterCreate, AfterDestroy, @@ -37,8 +37,8 @@ import { logger } from '../../helpers/logger' import { ACTOR_FOLLOW_SCORE, CONSTRAINTS_FIELDS, FOLLOW_STATES, SERVER_ACTOR_NAME, SORTABLE_COLUMNS } from '../../initializers/constants' import { AccountModel } from '../account/account' import { ServerModel } from '../server/server' +import { buildSQLAttributes, createSafeIn, getSort, searchAttribute, throwIfNotValid } from '../shared' import { doesExist } from '../shared/query' -import { createSafeIn, getSort, searchAttribute, throwIfNotValid } from '../utils' import { VideoChannelModel } from '../video/video-channel' import { ActorModel, unusedActorAttributesForAPI } from './actor' import { InstanceListFollowersQueryBuilder, ListFollowersOptions } from './sql/instance-list-followers-query-builder' @@ -69,7 +69,7 @@ import { InstanceListFollowingQueryBuilder, ListFollowingOptions } from './sql/i export class ActorFollowModel extends Model>> { @AllowNull(false) - @Column(DataType.ENUM(...values(FOLLOW_STATES))) + @Column(DataType.ENUM(...Object.values(FOLLOW_STATES))) state: FollowState @AllowNull(false) @@ -140,6 +140,18 @@ export class ActorFollowModel extends Model { const query = { where: { actorId, - targetActorId: targetActorId + targetActorId }, include: [ { @@ -238,19 +252,20 @@ export class ActorFollowModel extends Model { + static loadByActorAndTargetNameAndHostForAPI (options: { + actorId: number + targetName: string + targetHost: string + state?: FollowState + transaction?: Transaction + }): Promise { + const { actorId, targetHost, targetName, state, transaction } = options + const actorFollowingPartInclude: IncludeOptions = { model: ActorModel, required: true, as: 'ActorFollowing', - where: { - preferredUsername: targetName - }, + where: ActorModel.wherePreferredUsername(targetName), include: [ { model: VideoChannelModel.unscoped(), @@ -271,10 +286,11 @@ export class ActorFollowModel extends Model> = { actorId } + if (state) where.state = state + + const query: FindOptions> = { + where, include: [ actorFollowingPartInclude, { @@ -283,7 +299,7 @@ export class ActorFollowModel extends Model