]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/activitypub/actor.ts
Keep displayName as valid playlist sort
[github/Chocobozzz/PeerTube.git] / server / models / activitypub / actor.ts
index 9e8303a7b0c9c2633e0151b880335dffd139a976..a2fee001282a8787b1e547dcfd88bf4d36de7277 100644 (file)
@@ -45,7 +45,7 @@ import {
   MActorServer,
   MActorSummaryFormattable, MActorUrl,
   MActorWithInboxes
-} from '../../typings/models'
+} from '../../types/models'
 import * as Bluebird from 'bluebird'
 import { Op, Transaction, literal } from 'sequelize'
 import { ModelCache } from '@server/models/model-cache'
@@ -62,7 +62,6 @@ export const unusedActorAttributesForAPI = [
   'sharedInboxUrl',
   'followersUrl',
   'followingUrl',
-  'url',
   'createdAt',
   'updatedAt'
 ]
@@ -123,13 +122,13 @@ export const unusedActorAttributesForAPI = [
         }
       }
     },
-    // {
-    //   fields: [ 'preferredUsername' ],
-    //   unique: true,
-    //   where: {
-    //     serverId: null
-    //   }
-    // },
+    {
+      fields: [ 'preferredUsername' ],
+      unique: true,
+      where: {
+        serverId: null
+      }
+    },
     {
       fields: [ 'inboxUrl', 'sharedInboxUrl' ]
     },
@@ -462,6 +461,36 @@ export class ActorModel extends Model<ActorModel> {
     }, { where, transaction })
   }
 
+  static loadAccountActorByVideoId (videoId: number): Bluebird<MActor> {
+    const query = {
+      include: [
+        {
+          attributes: [ 'id' ],
+          model: AccountModel.unscoped(),
+          required: true,
+          include: [
+            {
+              attributes: [ 'id', 'accountId' ],
+              model: VideoChannelModel.unscoped(),
+              required: true,
+              include: [
+                {
+                  attributes: [ 'id', 'channelId' ],
+                  model: VideoModel.unscoped(),
+                  where: {
+                    id: videoId
+                  }
+                }
+              ]
+            }
+          ]
+        }
+      ]
+    }
+
+    return ActorModel.unscoped().findOne(query)
+  }
+
   getSharedInbox (this: MActorWithInboxes) {
     return this.sharedInboxUrl || this.inboxUrl
   }