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'
},
{
fields: [ 'videoId', 'originCommentId' ]
+ },
+ {
+ fields: [ 'url' ],
+ unique: true
}
]
})
})
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)
}
}
static listThreadCommentsForApi (videoId: number, threadId: number) {
const query = {
- order: [ [ 'createdAt', 'ASC' ] ],
+ order: [ [ 'createdAt', 'ASC' ], [ 'updatedAt', 'ASC' ] ],
where: {
videoId,
[ Sequelize.Op.or ]: [