1 import * as Sequelize from 'sequelize'
15 } from 'sequelize-typescript'
16 import { isUserUsernameValid } from '../../helpers/custom-validators/users'
17 import { sendDeleteActor } from '../../lib/activitypub/send'
18 import { ActorModel } from '../activitypub/actor'
19 import { ApplicationModel } from '../application/application'
20 import { ServerModel } from '../server/server'
21 import { throwIfNotValid } from '../utils'
22 import { VideoChannelModel } from '../video/video-channel'
23 import { UserModel } from './user'
28 model: () => ActorModel,
32 model: () => ServerModel,
42 export class AccountModel extends Model<AccountModel> {
45 @Is('AccountName', value => throwIfNotValid(value, isUserUsernameValid, 'account name'))
55 @ForeignKey(() => ActorModel)
59 @BelongsTo(() => ActorModel, {
67 @ForeignKey(() => UserModel)
71 @BelongsTo(() => UserModel, {
79 @ForeignKey(() => ApplicationModel)
83 @BelongsTo(() => ApplicationModel, {
89 Account: ApplicationModel
91 @HasMany(() => VideoChannelModel, {
98 VideoChannels: VideoChannelModel[]
101 static sendDeleteIfOwned (instance: AccountModel) {
102 if (instance.isOwned()) {
103 return sendDeleteActor(instance.Actor, undefined)
109 static load (id: number) {
110 return AccountModel.findById(id)
113 static loadByUUID (uuid: string) {
126 return AccountModel.findOne(query)
129 static loadLocalByName (name: string) {
133 [ Sequelize.Op.or ]: [
136 [ Sequelize.Op.ne ]: null
141 [ Sequelize.Op.ne ]: null
148 return AccountModel.findOne(query)
151 static loadByUrl (url: string, transaction?: Sequelize.Transaction) {
165 return AccountModel.findOne(query)
169 const actor = this.Actor.toFormattedJSON()
173 createdAt: this.createdAt,
174 updatedAt: this.updatedAt
177 return Object.assign(actor, account)
180 toActivityPubObject () {
181 return this.Actor.toActivityPubObject(this.name, 'Account')
185 return this.Actor.isOwned()