]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/account/account.ts
Cleanup model types
[github/Chocobozzz/PeerTube.git] / server / models / account / account.ts
index 28014946f34b23df7dcee7694fe28a55feb0a525..4cc731075dcb9730c1b968ebc3d88a08a6b8e1ce 100644 (file)
@@ -3,7 +3,8 @@ import {
   BeforeDestroy,
   BelongsTo,
   Column,
-  CreatedAt, DataType,
+  CreatedAt,
+  DataType,
   Default,
   DefaultScope,
   ForeignKey,
@@ -30,6 +31,9 @@ import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
 import { FindOptions, IncludeOptions, Op, Transaction, WhereOptions } from 'sequelize'
 import { AccountBlocklistModel } from './account-blocklist'
 import { ServerBlocklistModel } from '../server/server-blocklist'
+import { ActorFollowModel } from '../activitypub/actor-follow'
+import { MAccountActor, MAccountDefault } from '../../typings/models'
+import * as Bluebird from 'bluebird'
 
 export enum ScopeNames {
   SUMMARY = 'SUMMARY'
@@ -220,6 +224,7 @@ export class AccountModel extends Model<AccountModel> {
       instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
     }
 
+    await ActorFollowModel.removeFollowsOf(instance.Actor.id, options.transaction)
     if (instance.isOwned()) {
       return sendDeleteActor(instance.Actor, options.transaction)
     }
@@ -227,11 +232,11 @@ export class AccountModel extends Model<AccountModel> {
     return undefined
   }
 
-  static load (id: number, transaction?: Transaction) {
+  static load (id: number, transaction?: Transaction): Bluebird<MAccountDefault> {
     return AccountModel.findByPk(id, { transaction })
   }
 
-  static loadByNameWithHost (nameWithHost: string) {
+  static loadByNameWithHost (nameWithHost: string): Bluebird<MAccountDefault> {
     const [ accountName, host ] = nameWithHost.split('@')
 
     if (!host || host === WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName)
@@ -239,7 +244,7 @@ export class AccountModel extends Model<AccountModel> {
     return AccountModel.loadByNameAndHost(accountName, host)
   }
 
-  static loadLocalByName (name: string) {
+  static loadLocalByName (name: string): Bluebird<MAccountDefault> {
     const query = {
       where: {
         [ Op.or ]: [
@@ -269,7 +274,7 @@ export class AccountModel extends Model<AccountModel> {
     return AccountModel.findOne(query)
   }
 
-  static loadByNameAndHost (name: string, host: string) {
+  static loadByNameAndHost (name: string, host: string): Bluebird<MAccountDefault> {
     const query = {
       include: [
         {
@@ -294,7 +299,7 @@ export class AccountModel extends Model<AccountModel> {
     return AccountModel.findOne(query)
   }
 
-  static loadByUrl (url: string, transaction?: Transaction) {
+  static loadByUrl (url: string, transaction?: Transaction): Bluebird<MAccountDefault> {
     const query = {
       include: [
         {
@@ -327,7 +332,7 @@ export class AccountModel extends Model<AccountModel> {
       })
   }
 
-  static listLocalsForSitemap (sort: string) {
+  static listLocalsForSitemap (sort: string): Bluebird<MAccountActor[]> {
     const query = {
       attributes: [ ],
       offset: 0,