X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Factivitypub%2Factor.ts;h=71db44b2f8948163c46e45241f61dac6b806c8fc;hb=f27a885a4368776ffb8158c917c6e3f3d21ef670;hp=fb4327e4f6f44fe5efb95d350852bd80bbcd2337;hpb=b5fecbf44192144d1ca27c23a0b53922de288c10;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index fb4327e4f..71db44b2f 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts @@ -1,6 +1,5 @@ import { values } from 'lodash' import { extname } from 'path' -import * as Sequelize from 'sequelize' import { AllowNull, BelongsTo, @@ -43,11 +42,12 @@ import { MActorFormattable, MActorFull, MActorHost, - MActorRedundancyAllowedOpt, MActorServer, - MActorSummaryFormattable + MActorSummaryFormattable, + MActorWithInboxes } from '../../typings/models' import * as Bluebird from 'bluebird' +import { Op, Transaction } from 'sequelize' enum ScopeNames { FULL = 'FULL' @@ -115,8 +115,20 @@ export const unusedActorAttributesForAPI = [ }, { fields: [ 'preferredUsername', 'serverId' ], - unique: true + unique: true, + where: { + serverId: { + [Op.ne]: null + } + } }, + // { + // fields: [ 'preferredUsername' ], + // unique: true, + // where: { + // serverId: null + // } + // }, { fields: [ 'inboxUrl', 'sharedInboxUrl' ] }, @@ -175,23 +187,23 @@ export class ActorModel extends Model { @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max)) inboxUrl: string - @AllowNull(false) - @Is('ActorOutboxUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'outbox url')) + @AllowNull(true) + @Is('ActorOutboxUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'outbox url', true)) @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max)) outboxUrl: string - @AllowNull(false) - @Is('ActorSharedInboxUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'shared inbox url')) + @AllowNull(true) + @Is('ActorSharedInboxUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'shared inbox url', true)) @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max)) sharedInboxUrl: string - @AllowNull(false) - @Is('ActorFollowersUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'followers url')) + @AllowNull(true) + @Is('ActorFollowersUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'followers url', true)) @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max)) followersUrl: string - @AllowNull(false) - @Is('ActorFollowingUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'following url')) + @AllowNull(true) + @Is('ActorFollowingUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'following url', true)) @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max)) followingUrl: string @@ -272,7 +284,7 @@ export class ActorModel extends Model { return ActorModel.scope(ScopeNames.FULL).findByPk(id) } - static loadFromAccountByVideoId (videoId: number, transaction: Sequelize.Transaction): Bluebird { + static loadFromAccountByVideoId (videoId: number, transaction: Transaction): Bluebird { const query = { include: [ { @@ -316,11 +328,11 @@ export class ActorModel extends Model { .then(a => !!a) } - static listByFollowersUrls (followersUrls: string[], transaction?: Sequelize.Transaction): Bluebird { + static listByFollowersUrls (followersUrls: string[], transaction?: Transaction): Bluebird { const query = { where: { followersUrl: { - [ Sequelize.Op.in ]: followersUrls + [ Op.in ]: followersUrls } }, transaction @@ -329,7 +341,7 @@ export class ActorModel extends Model { return ActorModel.scope(ScopeNames.FULL).findAll(query) } - static loadLocalByName (preferredUsername: string, transaction?: Sequelize.Transaction): Bluebird { + static loadLocalByName (preferredUsername: string, transaction?: Transaction): Bluebird { const query = { where: { preferredUsername, @@ -360,7 +372,7 @@ export class ActorModel extends Model { return ActorModel.scope(ScopeNames.FULL).findOne(query) } - static loadByUrl (url: string, transaction?: Sequelize.Transaction): Bluebird { + static loadByUrl (url: string, transaction?: Transaction): Bluebird { const query = { where: { url @@ -383,7 +395,7 @@ export class ActorModel extends Model { return ActorModel.unscoped().findOne(query) } - static loadByUrlAndPopulateAccountAndChannel (url: string, transaction?: Sequelize.Transaction): Bluebird { + static loadByUrlAndPopulateAccountAndChannel (url: string, transaction?: Transaction): Bluebird { const query = { where: { url @@ -403,6 +415,10 @@ export class ActorModel extends Model { }) } + getSharedInbox (this: MActorWithInboxes) { + return this.sharedInboxUrl || this.inboxUrl + } + toFormattedSummaryJSON (this: MActorSummaryFormattable) { let avatar: Avatar = null if (this.Avatar) { @@ -430,16 +446,7 @@ export class ActorModel extends Model { }) } - toActivityPubObject (this: MActorAP, name: string, type: 'Account' | 'Application' | 'VideoChannel') { - let activityPubType - if (type === 'Account') { - activityPubType = 'Person' as 'Person' - } else if (type === 'Application') { - activityPubType = 'Application' as 'Application' - } else { // VideoChannel - activityPubType = 'Group' as 'Group' - } - + toActivityPubObject (this: MActorAP, name: string) { let icon = undefined if (this.avatarId) { const extension = extname(this.Avatar.filename) @@ -451,7 +458,7 @@ export class ActorModel extends Model { } const json = { - type: activityPubType, + type: this.type, id: this.url, following: this.getFollowingUrl(), followers: this.getFollowersUrl(), @@ -475,7 +482,7 @@ export class ActorModel extends Model { return activityPubContextify(json) } - getFollowerSharedInboxUrls (t: Sequelize.Transaction) { + getFollowerSharedInboxUrls (t: Transaction) { const query = { attributes: [ 'sharedInboxUrl' ], include: [