X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Factivitypub%2Factor.ts;h=f8bb593239dbbe47792f193ad66766d394f9f945;hb=d1a63fc7ac58a1db00d8ca4f43aadba02eb9b084;hp=2abf4071373ff4504b993fc214a181018f3384c6;hpb=8a19bee1a1ee39f973bb37429e4f73c3f2873cdb;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 2abf40713..f8bb59323 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts @@ -42,6 +42,19 @@ enum ScopeNames { FULL = 'FULL' } +export const unusedActorAttributesForAPI = [ + 'publicKey', + 'privateKey', + 'inboxUrl', + 'outboxUrl', + 'sharedInboxUrl', + 'followersUrl', + 'followingUrl', + 'url', + 'createdAt', + 'updatedAt' +] + @DefaultScope({ include: [ { @@ -63,7 +76,13 @@ enum ScopeNames { }, { model: () => VideoChannelModel.unscoped(), - required: false + required: false, + include: [ + { + model: () => AccountModel, + required: true + } + ] }, { model: () => ServerModel, @@ -247,6 +266,18 @@ export class ActorModel extends Model { 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: { @@ -292,6 +323,29 @@ export class ActorModel extends Model { } 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 @@ -312,45 +366,6 @@ export class ActorModel extends Model { }) } - 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) { @@ -363,6 +378,7 @@ export class ActorModel extends Model { uuid: this.uuid, name: this.preferredUsername, host: this.getHost(), + hostRedundancyAllowed: this.getRedundancyAllowed(), followingCount: this.followingCount, followersCount: this.followersCount, avatar, @@ -466,6 +482,10 @@ export class ActorModel extends Model { return this.Server ? this.Server.host : CONFIG.WEBSERVER.HOST } + getRedundancyAllowed () { + return this.Server ? this.Server.redundancyAllowed : false + } + getAvatarUrl () { if (!this.avatarId) return undefined