import * as Bluebird from 'bluebird'
import { values } from 'lodash'
-import * as Sequelize from 'sequelize'
import {
AfterCreate,
AfterDestroy,
import { getSort } from '../utils'
import { ActorModel, unusedActorAttributesForAPI } from './actor'
import { VideoChannelModel } from '../video/video-channel'
-import { IIncludeOptions } from '../../../node_modules/sequelize-typescript/lib/interfaces/IIncludeOptions'
import { AccountModel } from '../account/account'
+import { IncludeOptions, Op, Transaction, QueryTypes } from 'sequelize'
@Table({
tableName: 'actorFollow',
export class ActorFollowModel extends Model<ActorFollowModel> {
@AllowNull(false)
- @Column(DataType.ENUM(values(FOLLOW_STATES)))
+ @Column(DataType.ENUM(...values(FOLLOW_STATES)))
state: FollowState
@AllowNull(false)
if (numberOfActorFollowsRemoved) logger.info('Removed bad %d actor follows.', numberOfActorFollowsRemoved)
}
- static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Sequelize.Transaction) {
+ static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Transaction) {
const query = {
where: {
actorId,
return ActorFollowModel.findOne(query)
}
- static loadByActorAndTargetNameAndHostForAPI (actorId: number, targetName: string, targetHost: string, t?: Sequelize.Transaction) {
- const actorFollowingPartInclude: IIncludeOptions = {
+ static loadByActorAndTargetNameAndHostForAPI (actorId: number, targetName: string, targetHost: string, t?: Transaction) {
+ const actorFollowingPartInclude: IncludeOptions = {
model: ActorModel,
required: true,
as: 'ActorFollowing',
.map(t => {
if (t.host) {
return {
- [ Sequelize.Op.and ]: [
+ [ Op.and ]: [
{
'$preferredUsername$': t.name
},
}
return {
- [ Sequelize.Op.and ]: [
+ [ Op.and ]: [
{
'$preferredUsername$': t.name
},
const query = {
attributes: [],
where: {
- [ Sequelize.Op.and ]: [
+ [ Op.and ]: [
{
- [ Sequelize.Op.or ]: whereTab
+ [ Op.or ]: whereTab
},
{
actorId
required: true,
where: search ? {
host: {
- [Sequelize.Op.iLike]: '%' + search + '%'
+ [Op.iLike]: '%' + search + '%'
}
} : undefined
}
required: true,
where: search ? {
host: {
- [ Sequelize.Op.iLike ]: '%' + search + '%'
+ [ Op.iLike ]: '%' + search + '%'
}
} : undefined
}
})
}
- static listAcceptedFollowerUrlsForAP (actorIds: number[], t: Sequelize.Transaction, start?: number, count?: number) {
+ static listAcceptedFollowerUrlsForAP (actorIds: number[], t: Transaction, start?: number, count?: number) {
return ActorFollowModel.createListAcceptedFollowForApiQuery('followers', actorIds, t, start, count)
}
- static listAcceptedFollowerSharedInboxUrls (actorIds: number[], t: Sequelize.Transaction) {
+ static listAcceptedFollowerSharedInboxUrls (actorIds: number[], t: Transaction) {
return ActorFollowModel.createListAcceptedFollowForApiQuery(
'followers',
actorIds,
)
}
- static listAcceptedFollowingUrlsForApi (actorIds: number[], t: Sequelize.Transaction, start?: number, count?: number) {
+ static listAcceptedFollowingUrlsForApi (actorIds: number[], t: Transaction, start?: number, count?: number) {
return ActorFollowModel.createListAcceptedFollowForApiQuery('following', actorIds, t, start, count)
}
}
}
- static updateFollowScore (inboxUrl: string, value: number, t?: Sequelize.Transaction) {
+ static updateFollowScore (inboxUrl: string, value: number, t?: Transaction) {
const query = `UPDATE "actorFollow" SET "score" = LEAST("score" + ${value}, ${ACTOR_FOLLOW_SCORE.MAX}) ` +
'WHERE id IN (' +
'SELECT "actorFollow"."id" FROM "actorFollow" ' +
')'
const options = {
- type: Sequelize.QueryTypes.BULKUPDATE,
+ type: QueryTypes.BULKUPDATE,
transaction: t
}
private static async createListAcceptedFollowForApiQuery (
type: 'followers' | 'following',
actorIds: number[],
- t: Sequelize.Transaction,
+ t: Transaction,
start?: number,
count?: number,
columnUrl = 'url',
const options = {
bind: { actorIds },
- type: Sequelize.QueryTypes.SELECT,
+ type: QueryTypes.SELECT,
transaction: t
}
tasks.push(ActorFollowModel.sequelize.query(query, options))
const query = {
where: {
score: {
- [Sequelize.Op.lte]: 0
+ [Op.lte]: 0
}
},
logging: false