]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/activitypub/actor.ts
Infinite scroll to list our subscriptions
[github/Chocobozzz/PeerTube.git] / server / models / activitypub / actor.ts
index 38a689fea5da9ac7481d3c5480c5b188077bdfd8..e16bd5d7943de0b36e55cba50e56c64ea58e7516 100644 (file)
@@ -42,6 +42,17 @@ enum ScopeNames {
   FULL = 'FULL'
 }
 
+export const unusedActorAttributesForAPI = [
+  'publicKey',
+  'privateKey',
+  'inboxUrl',
+  'outboxUrl',
+  'sharedInboxUrl',
+  'followersUrl',
+  'followingUrl',
+  'url'
+]
+
 @DefaultScope({
   include: [
     {
@@ -80,7 +91,8 @@ enum ScopeNames {
   tableName: 'actor',
   indexes: [
     {
-      fields: [ 'url' ]
+      fields: [ 'url' ],
+      unique: true
     },
     {
       fields: [ 'preferredUsername', 'serverId' ],
@@ -89,11 +101,21 @@ enum ScopeNames {
     {
       fields: [ 'inboxUrl', 'sharedInboxUrl' ]
     },
+    {
+      fields: [ 'sharedInboxUrl' ]
+    },
     {
       fields: [ 'serverId' ]
     },
     {
       fields: [ 'avatarId' ]
+    },
+    {
+      fields: [ 'uuid' ],
+      unique: true
+    },
+    {
+      fields: [ 'followersUrl' ]
     }
   ]
 })
@@ -249,12 +271,13 @@ export class ActorModel extends Model<ActorModel> {
     return ActorModel.scope(ScopeNames.FULL).findAll(query)
   }
 
-  static loadLocalByName (preferredUsername: string) {
+  static loadLocalByName (preferredUsername: string, transaction?: Sequelize.Transaction) {
     const query = {
       where: {
         preferredUsername,
         serverId: null
-      }
+      },
+      transaction
     }
 
     return ActorModel.scope(ScopeNames.FULL).findOne(query)
@@ -300,45 +323,6 @@ 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) {
@@ -446,6 +430,10 @@ export class ActorModel extends Model<ActorModel> {
     return 'acct:' + this.preferredUsername + '@' + this.getHost()
   }
 
+  getIdentifier () {
+    return this.Server ? `${this.preferredUsername}@${this.Server.host}` : this.preferredUsername
+  }
+
   getHost () {
     return this.Server ? this.Server.host : CONFIG.WEBSERVER.HOST
   }