From 6d8524702874120a4667269a81a61e3c7c5e300d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 22 Dec 2017 09:14:50 +0100 Subject: Create comment on replied mastodon statutes --- server/models/video/video-comment.ts | 95 ++++++++++++++++++++++++++++++++++++ server/models/video/video.ts | 12 +++++ 2 files changed, 107 insertions(+) create mode 100644 server/models/video/video-comment.ts (limited to 'server/models') diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts new file mode 100644 index 000000000..92c0c6112 --- /dev/null +++ b/server/models/video/video-comment.ts @@ -0,0 +1,95 @@ +import * as Sequelize from 'sequelize' +import { + AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, IFindOptions, Is, IsUUID, Model, Table, + UpdatedAt +} from 'sequelize-typescript' +import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub' +import { CONSTRAINTS_FIELDS } from '../../initializers' +import { ActorModel } from '../activitypub/actor' +import { throwIfNotValid } from '../utils' +import { VideoModel } from './video' + +@Table({ + tableName: 'videoComment', + indexes: [ + { + fields: [ 'videoId' ] + } + ] +}) +export class VideoCommentModel extends Model { + @CreatedAt + createdAt: Date + + @UpdatedAt + updatedAt: Date + + @AllowNull(false) + @Is('VideoCommentUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) + @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max)) + url: string + + @AllowNull(false) + @Column(DataType.TEXT) + text: string + + @ForeignKey(() => VideoCommentModel) + @Column + originCommentId: number + + @BelongsTo(() => VideoCommentModel, { + foreignKey: { + allowNull: true + }, + onDelete: 'CASCADE' + }) + OriginVideoComment: VideoCommentModel + + @ForeignKey(() => VideoCommentModel) + @Column + inReplyToCommentId: number + + @BelongsTo(() => VideoCommentModel, { + foreignKey: { + allowNull: true + }, + onDelete: 'CASCADE' + }) + InReplyToVideoComment: VideoCommentModel + + @ForeignKey(() => VideoModel) + @Column + videoId: number + + @BelongsTo(() => VideoModel, { + foreignKey: { + allowNull: false + }, + onDelete: 'CASCADE' + }) + Video: VideoModel + + @ForeignKey(() => ActorModel) + @Column + actorId: number + + @BelongsTo(() => ActorModel, { + foreignKey: { + allowNull: false + }, + onDelete: 'CASCADE' + }) + Actor: ActorModel + + static loadByUrl (url: string, t?: Sequelize.Transaction) { + const query: IFindOptions = { + where: { + url + } + } + + if (t !== undefined) query.transaction = t + + return VideoCommentModel.findOne(query) + } +} diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 8c49bc3af..b6a2ce6b5 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -491,6 +491,18 @@ export class VideoModel extends Model { return VideoModel.findById(id) } + static loadByUrl (url: string, t?: Sequelize.Transaction) { + const query: IFindOptions = { + where: { + url + } + } + + if (t !== undefined) query.transaction = t + + return VideoModel.findOne(query) + } + static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) { const query: IFindOptions = { where: { -- cgit v1.2.3