X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Faccount%2Faccount.ts;h=3ff59887d4ab93d6d04fddfb1959c23a9d7bbee3;hb=9a4a9b6c4e193739d542f73ee85cd305067f2aea;hp=d8f305c376814fc306a4314256274684a09dec36;hpb=2422c46b27790d94fd29a7092170cee5a1b56008;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/account/account.ts b/server/models/account/account.ts index d8f305c37..3ff59887d 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -157,7 +157,6 @@ export class AccountModel extends Model { static loadLocalByName (name: string) { const query = { where: { - name, [ Sequelize.Op.or ]: [ { userId: { @@ -170,7 +169,41 @@ export class AccountModel extends Model { } } ] - } + }, + include: [ + { + model: ActorModel, + required: true, + where: { + preferredUsername: name + } + } + ] + } + + return AccountModel.findOne(query) + } + + static loadLocalByNameAndHost (name: string, host: string) { + const query = { + include: [ + { + model: ActorModel, + required: true, + where: { + preferredUsername: name + }, + include: [ + { + model: ServerModel, + required: true, + where: { + host + } + } + ] + } + ] } return AccountModel.findOne(query) @@ -197,7 +230,7 @@ export class AccountModel extends Model { const query = { offset: start, limit: count, - order: [ getSort(sort) ] + order: getSort(sort) } return AccountModel.findAndCountAll(query) @@ -213,7 +246,7 @@ export class AccountModel extends Model { const actor = this.Actor.toFormattedJSON() const account = { id: this.id, - displayName: this.name, + displayName: this.getDisplayName(), description: this.description, createdAt: this.createdAt, updatedAt: this.updatedAt @@ -233,4 +266,8 @@ export class AccountModel extends Model { isOwned () { return this.Actor.isOwned() } + + getDisplayName () { + return this.name + } }