-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,
export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowModel>>> {
@AllowNull(false)
- @Column(DataType.ENUM(...values(FOLLOW_STATES)))
+ @Column(DataType.ENUM(...Object.values(FOLLOW_STATES)))
state: FollowState
@AllowNull(false)
}
static isFollowedBy (actorId: number, followerActorId: number) {
- const query = 'SELECT 1 FROM "actorFollow" WHERE "actorId" = $followerActorId AND "targetActorId" = $actorId LIMIT 1'
+ const query = `SELECT 1 FROM "actorFollow" ` +
+ `WHERE "actorId" = $followerActorId AND "targetActorId" = $actorId AND "state" = 'accepted' ` +
+ `LIMIT 1`
return doesExist(query, { actorId, followerActorId })
}
const query = {
where: {
actorId,
- targetActorId: targetActorId
+ targetActorId
},
include: [
{
return ActorFollowModel.findOne(query)
}
- static loadByActorAndTargetNameAndHostForAPI (
- actorId: number,
- targetName: string,
- targetHost: string,
- t?: Transaction
- ): Promise<MActorFollowActorsDefaultSubscription> {
+ static loadByActorAndTargetNameAndHostForAPI (options: {
+ actorId: number
+ targetName: string
+ targetHost: string
+ state?: FollowState
+ transaction?: Transaction
+ }): Promise<MActorFollowActorsDefaultSubscription> {
+ const { actorId, targetHost, targetName, state, transaction } = options
+
const actorFollowingPartInclude: IncludeOptions = {
model: ActorModel,
required: true,
})
}
- const query = {
- where: {
- actorId
- },
+ const where: WhereAttributeHash<Attributes<ActorFollowModel>> = { actorId }
+ if (state) where.state = state
+
+ const query: FindOptions<Attributes<ActorFollowModel>> = {
+ where,
include: [
actorFollowingPartInclude,
{
as: 'ActorFollower'
}
],
- transaction: t
+ transaction
}
return ActorFollowModel.findOne(query)
[Op.or]: whereTab
},
{
+ state: 'accepted',
actorId
}
]
}) {
const { actorId, start, count, sort } = options
const where = {
- actorId: actorId
+ state: 'accepted',
+ actorId
}
if (options.search) {
const totalInstanceFollowing = await ActorFollowModel.count({
where: {
- actorId: serverActor.id
+ actorId: serverActor.id,
+ state: 'accepted'
}
})
const totalInstanceFollowers = await ActorFollowModel.count({
where: {
- targetActorId: serverActor.id
+ targetActorId: serverActor.id,
+ state: 'accepted'
}
})