]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/activitypub/actor.ts
Only list unlisted/public videos in outbox
[github/Chocobozzz/PeerTube.git] / server / models / activitypub / actor.ts
index 408d4df23490cb793851333f47cbea6237ce97a7..c79bba96bb08b9be8a0add9d3489db7c210407b7 100644 (file)
@@ -167,17 +167,17 @@ export class ActorModel extends Model<ActorModel> {
     },
     onDelete: 'cascade'
   })
-  AccountFollowing: ActorFollowModel[]
+  ActorFollowing: ActorFollowModel[]
 
   @HasMany(() => ActorFollowModel, {
     foreignKey: {
       name: 'targetActorId',
       allowNull: false
     },
-    as: 'followers',
+    as: 'ActorFollowers',
     onDelete: 'cascade'
   })
-  AccountFollowers: ActorFollowModel[]
+  ActorFollowers: ActorFollowModel[]
 
   @ForeignKey(() => ServerModel)
   @Column
@@ -277,6 +277,45 @@ export class ActorModel extends Model<ActorModel> {
     })
   }
 
+  static async getActorsFollowerSharedInboxUrls (actors: ActorModel[], t: Sequelize.Transaction) {
+    const query = {
+      // attribute: [],
+      where: {
+        id: {
+          [Sequelize.Op.in]: actors.map(a => a.id)
+        }
+      },
+      include: [
+        {
+          // attributes: [ ],
+          model: ActorFollowModel.unscoped(),
+          required: true,
+          as: 'ActorFollowers',
+          where: {
+            state: 'accepted'
+          },
+          include: [
+            {
+              attributes: [ 'sharedInboxUrl' ],
+              model: ActorModel.unscoped(),
+              as: 'ActorFollower',
+              required: true
+            }
+          ]
+        }
+      ],
+      transaction: t
+    }
+
+    const hash: { [ id: number ]: string[] } = {}
+    const res = await ActorModel.findAll(query)
+    for (const actor of res) {
+      hash[actor.id] = actor.ActorFollowers.map(follow => follow.ActorFollower.sharedInboxUrl)
+    }
+
+    return hash
+  }
+
   toFormattedJSON () {
     let avatar: Avatar = null
     if (this.Avatar) {
@@ -347,10 +386,12 @@ export class ActorModel extends Model<ActorModel> {
       attributes: [ 'sharedInboxUrl' ],
       include: [
         {
-          model: ActorFollowModel,
+          attribute: [],
+          model: ActorFollowModel.unscoped(),
           required: true,
-          as: 'followers',
+          as: 'ActorFollowing',
           where: {
+            state: 'accepted',
             targetActorId: this.id
           }
         }