From fadf619ad61a016c1c7fc53de5a8f398a4f77519 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 14 Dec 2017 11:18:49 +0100 Subject: Save --- server/models/video/video-channel.ts | 60 +++++++++++++++--------------------- 1 file changed, 25 insertions(+), 35 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 068c8029d..fe44d3d53 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -11,18 +11,16 @@ import { HasMany, Is, IsUUID, - Model, Scopes, + Model, + Scopes, Table, UpdatedAt } from 'sequelize-typescript' import { IFindOptions } from 'sequelize-typescript/lib/interfaces/IFindOptions' -import { activityPubCollection } from '../../helpers' -import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub' import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' -import { CONSTRAINTS_FIELDS } from '../../initializers' -import { getAnnounceActivityPubUrl } from '../../lib/activitypub' import { sendDeleteVideoChannel } from '../../lib/activitypub/send' import { AccountModel } from '../account/account' +import { ActorModel } from '../activitypub/actor' import { ServerModel } from '../server/server' import { getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' @@ -78,17 +76,24 @@ export class VideoChannelModel extends Model { @Column remote: boolean - @AllowNull(false) - @Is('VideoChannelUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) - @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_CHANNELS.URL.max)) - url: string - @CreatedAt createdAt: Date @UpdatedAt updatedAt: Date + @ForeignKey(() => ActorModel) + @Column + actorId: number + + @BelongsTo(() => ActorModel, { + foreignKey: { + allowNull: false + }, + onDelete: 'cascade' + }) + Actor: ActorModel + @ForeignKey(() => AccountModel) @Column accountId: number @@ -174,9 +179,15 @@ export class VideoChannelModel extends Model { static loadByUrl (url: string, t?: Sequelize.Transaction) { const query: IFindOptions = { - where: { - url - } + include: [ + { + model: ActorModel, + required: true, + where: { + url + } + } + ] } if (t !== undefined) query.transaction = t @@ -264,27 +275,6 @@ export class VideoChannelModel extends Model { } toActivityPubObject () { - let sharesObject - if (Array.isArray(this.VideoChannelShares)) { - const shares: string[] = [] - - for (const videoChannelShare of this.VideoChannelShares) { - const shareUrl = getAnnounceActivityPubUrl(this.url, videoChannelShare.Account) - shares.push(shareUrl) - } - - sharesObject = activityPubCollection(shares) - } - - return { - type: 'VideoChannel' as 'VideoChannel', - id: this.url, - uuid: this.uuid, - content: this.description, - name: this.name, - published: this.createdAt.toISOString(), - updated: this.updatedAt.toISOString(), - shares: sharesObject - } + return this.Actor.toActivityPubObject(this.name, this.uuid, 'VideoChannel') } } -- cgit v1.2.3