]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/activitypub/actor.ts
Fix videos list user NSFW policy
[github/Chocobozzz/PeerTube.git] / server / models / activitypub / actor.ts
index 119d0c1da1bba13c2a09c5afc2643975f78b5ab9..f8bb593239dbbe47792f193ad66766d394f9f945 100644 (file)
@@ -76,7 +76,13 @@ export const unusedActorAttributesForAPI = [
       },
       {
         model: () => VideoChannelModel.unscoped(),
-        required: false
+        required: false,
+        include: [
+          {
+            model: () => AccountModel,
+            required: true
+          }
+        ]
       },
       {
         model: () => ServerModel,
@@ -260,6 +266,18 @@ export class ActorModel extends Model<ActorModel> {
     return ActorModel.unscoped().findById(id)
   }
 
+  static isActorUrlExist (url: string) {
+    const query = {
+      raw: true,
+      where: {
+        url
+      }
+    }
+
+    return ActorModel.unscoped().findOne(query)
+      .then(a => !!a)
+  }
+
   static listByFollowersUrls (followersUrls: string[], transaction?: Sequelize.Transaction) {
     const query = {
       where: {
@@ -305,6 +323,29 @@ export class ActorModel extends Model<ActorModel> {
   }
 
   static loadByUrl (url: string, transaction?: Sequelize.Transaction) {
+    const query = {
+      where: {
+        url
+      },
+      transaction,
+      include: [
+        {
+          attributes: [ 'id' ],
+          model: AccountModel.unscoped(),
+          required: false
+        },
+        {
+          attributes: [ 'id' ],
+          model: VideoChannelModel.unscoped(),
+          required: false
+        }
+      ]
+    }
+
+    return ActorModel.unscoped().findOne(query)
+  }
+
+  static loadByUrlAndPopulateAccountAndChannel (url: string, transaction?: Sequelize.Transaction) {
     const query = {
       where: {
         url
@@ -337,6 +378,7 @@ export class ActorModel extends Model<ActorModel> {
       uuid: this.uuid,
       name: this.preferredUsername,
       host: this.getHost(),
+      hostRedundancyAllowed: this.getRedundancyAllowed(),
       followingCount: this.followingCount,
       followersCount: this.followersCount,
       avatar,
@@ -440,6 +482,10 @@ export class ActorModel extends Model<ActorModel> {
     return this.Server ? this.Server.host : CONFIG.WEBSERVER.HOST
   }
 
+  getRedundancyAllowed () {
+    return this.Server ? this.Server.redundancyAllowed : false
+  }
+
   getAvatarUrl () {
     if (!this.avatarId) return undefined