X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-comment.ts;h=868d04ff9e0a7b381e78a63d8e05553d309d8001;hb=0776d83f2cf5825f5cd7915d1cf217572d560f1b;hp=fffa4bb57d060848bc929beb396f52ad2dcfbefa;hpb=2ccaeeb341ffe8c2609039bf4c6d8835b4650316;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index fffa4bb57..868d04ff9 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -1,6 +1,6 @@ import * as Sequelize from 'sequelize' import { - AfterDestroy, AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, IFindOptions, Is, Model, Scopes, Table, + AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DataType, ForeignKey, IFindOptions, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' import { ActivityTagObject } from '../../../shared/models/activitypub/objects/common-objects' @@ -104,6 +104,10 @@ enum ScopeNames { }, { fields: [ 'videoId', 'originCommentId' ] + }, + { + fields: [ 'url' ], + unique: true } ] }) @@ -175,10 +179,17 @@ export class VideoCommentModel extends Model { }) Account: AccountModel - @AfterDestroy - static async sendDeleteIfOwned (instance: VideoCommentModel) { + @BeforeDestroy + static async sendDeleteIfOwned (instance: VideoCommentModel, options) { + if (!instance.Account || !instance.Account.Actor) { + instance.Account = await instance.$get('Account', { + include: [ ActorModel ], + transaction: options.transaction + }) as AccountModel + } + if (instance.isOwned()) { - await sendDeleteVideoComment(instance, undefined) + await sendDeleteVideoComment(instance, options.transaction) } } @@ -253,7 +264,7 @@ export class VideoCommentModel extends Model { static listThreadCommentsForApi (videoId: number, threadId: number) { const query = { - order: [ [ 'createdAt', 'ASC' ] ], + order: [ [ 'createdAt', 'ASC' ], [ 'updatedAt', 'ASC' ] ], where: { videoId, [ Sequelize.Op.or ]: [