]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/server/server.ts
Fix socket notification with multiple user tabs
[github/Chocobozzz/PeerTube.git] / server / models / server / server.ts
index 300d7093808c568b76e3520ef8304fafa7fc7522..1d211f1e06b2619bd6a4142c31bfd0852d3b0792 100644 (file)
@@ -2,6 +2,8 @@ import { AllowNull, Column, CreatedAt, Default, HasMany, Is, Model, Table, Updat
 import { isHostValid } from '../../helpers/custom-validators/servers'
 import { ActorModel } from '../activitypub/actor'
 import { throwIfNotValid } from '../utils'
+import { AccountBlocklistModel } from '../account/account-blocklist'
+import { ServerBlocklistModel } from './server-blocklist'
 
 @Table({
   tableName: 'server',
@@ -40,6 +42,14 @@ export class ServerModel extends Model<ServerModel> {
   })
   Actors: ActorModel[]
 
+  @HasMany(() => ServerBlocklistModel, {
+    foreignKey: {
+      allowNull: false
+    },
+    onDelete: 'CASCADE'
+  })
+  BlockedByAccounts: ServerBlocklistModel[]
+
   static loadByHost (host: string) {
     const query = {
       where: {
@@ -50,6 +60,10 @@ export class ServerModel extends Model<ServerModel> {
     return ServerModel.findOne(query)
   }
 
+  isBlocked () {
+    return this.BlockedByAccounts && this.BlockedByAccounts.length !== 0
+  }
+
   toFormattedJSON () {
     return {
       host: this.host