diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/abuse/abuse.ts | 10 | ||||
-rw-r--r-- | server/models/abuse/video-comment-abuse.ts | 8 | ||||
-rw-r--r-- | server/models/account/user-notification.ts | 4 | ||||
-rw-r--r-- | server/models/video/video-comment.ts | 42 |
4 files changed, 10 insertions, 54 deletions
diff --git a/server/models/abuse/abuse.ts b/server/models/abuse/abuse.ts index 28ecf8253..dffd503b3 100644 --- a/server/models/abuse/abuse.ts +++ b/server/models/abuse/abuse.ts | |||
@@ -362,8 +362,8 @@ export class AbuseModel extends Model<AbuseModel> { | |||
362 | const countReportsForReporter = this.get('countReportsForReporter') as number | 362 | const countReportsForReporter = this.get('countReportsForReporter') as number |
363 | const countReportsForReportee = this.get('countReportsForReportee') as number | 363 | const countReportsForReportee = this.get('countReportsForReportee') as number |
364 | 364 | ||
365 | let video: VideoAbuse | 365 | let video: VideoAbuse = null |
366 | let comment: VideoCommentAbuse | 366 | let comment: VideoCommentAbuse = null |
367 | 367 | ||
368 | if (this.VideoAbuse) { | 368 | if (this.VideoAbuse) { |
369 | const abuseModel = this.VideoAbuse | 369 | const abuseModel = this.VideoAbuse |
@@ -391,13 +391,13 @@ export class AbuseModel extends Model<AbuseModel> { | |||
391 | 391 | ||
392 | if (this.VideoCommentAbuse) { | 392 | if (this.VideoCommentAbuse) { |
393 | const abuseModel = this.VideoCommentAbuse | 393 | const abuseModel = this.VideoCommentAbuse |
394 | const entity = abuseModel.VideoComment || abuseModel.deletedComment | 394 | const entity = abuseModel.VideoComment |
395 | 395 | ||
396 | comment = { | 396 | comment = { |
397 | id: entity.id, | 397 | id: entity.id, |
398 | text: entity.text, | 398 | text: entity.text ?? '', |
399 | 399 | ||
400 | deleted: !abuseModel.VideoComment, | 400 | deleted: entity.isDeleted(), |
401 | 401 | ||
402 | video: { | 402 | video: { |
403 | id: entity.Video.id, | 403 | id: entity.Video.id, |
diff --git a/server/models/abuse/video-comment-abuse.ts b/server/models/abuse/video-comment-abuse.ts index de9f4d5fd..8b34009b4 100644 --- a/server/models/abuse/video-comment-abuse.ts +++ b/server/models/abuse/video-comment-abuse.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { VideoComment } from '@shared/models' | ||
3 | import { VideoCommentModel } from '../video/video-comment' | 2 | import { VideoCommentModel } from '../video/video-comment' |
4 | import { AbuseModel } from './abuse' | 3 | import { AbuseModel } from './abuse' |
5 | 4 | ||
@@ -22,11 +21,6 @@ export class VideoCommentAbuseModel extends Model<VideoCommentAbuseModel> { | |||
22 | @UpdatedAt | 21 | @UpdatedAt |
23 | updatedAt: Date | 22 | updatedAt: Date |
24 | 23 | ||
25 | @AllowNull(true) | ||
26 | @Default(null) | ||
27 | @Column(DataType.JSONB) | ||
28 | deletedComment: VideoComment & { Video: { name: string, id: number, uuid: string }} | ||
29 | |||
30 | @ForeignKey(() => AbuseModel) | 24 | @ForeignKey(() => AbuseModel) |
31 | @Column | 25 | @Column |
32 | abuseId: number | 26 | abuseId: number |
diff --git a/server/models/account/user-notification.ts b/server/models/account/user-notification.ts index 07db5a2db..2945bf709 100644 --- a/server/models/account/user-notification.ts +++ b/server/models/account/user-notification.ts | |||
@@ -109,7 +109,7 @@ function buildAccountInclude (required: boolean, withActor = false) { | |||
109 | required: true, | 109 | required: true, |
110 | include: [ | 110 | include: [ |
111 | { | 111 | { |
112 | attributes: [ 'uuid' ], | 112 | attributes: [ 'id', 'name', 'uuid' ], |
113 | model: VideoModel.unscoped(), | 113 | model: VideoModel.unscoped(), |
114 | required: true | 114 | required: true |
115 | } | 115 | } |
@@ -492,6 +492,8 @@ export class UserNotificationModel extends Model<UserNotificationModel> { | |||
492 | threadId: abuse.VideoCommentAbuse.VideoComment.getThreadId(), | 492 | threadId: abuse.VideoCommentAbuse.VideoComment.getThreadId(), |
493 | 493 | ||
494 | video: { | 494 | video: { |
495 | id: abuse.VideoCommentAbuse.VideoComment.Video.id, | ||
496 | name: abuse.VideoCommentAbuse.VideoComment.Video.name, | ||
495 | uuid: abuse.VideoCommentAbuse.VideoComment.Video.uuid | 497 | uuid: abuse.VideoCommentAbuse.VideoComment.Video.uuid |
496 | } | 498 | } |
497 | } : undefined | 499 | } : undefined |
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index fb6078ed8..fa4d13c3b 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -3,7 +3,6 @@ import { uniq } from 'lodash' | |||
3 | import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' | 3 | import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' |
4 | import { | 4 | import { |
5 | AllowNull, | 5 | AllowNull, |
6 | BeforeDestroy, | ||
7 | BelongsTo, | 6 | BelongsTo, |
8 | Column, | 7 | Column, |
9 | CreatedAt, | 8 | CreatedAt, |
@@ -16,7 +15,6 @@ import { | |||
16 | Table, | 15 | Table, |
17 | UpdatedAt | 16 | UpdatedAt |
18 | } from 'sequelize-typescript' | 17 | } from 'sequelize-typescript' |
19 | import { logger } from '@server/helpers/logger' | ||
20 | import { getServerActor } from '@server/models/application/application' | 18 | import { getServerActor } from '@server/models/application/application' |
21 | import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' | 19 | import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' |
22 | import { VideoPrivacy } from '@shared/models' | 20 | import { VideoPrivacy } from '@shared/models' |
@@ -242,51 +240,13 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
242 | 240 | ||
243 | @HasMany(() => VideoCommentAbuseModel, { | 241 | @HasMany(() => VideoCommentAbuseModel, { |
244 | foreignKey: { | 242 | foreignKey: { |
245 | name: 'commentId', | 243 | name: 'videoCommentId', |
246 | allowNull: true | 244 | allowNull: true |
247 | }, | 245 | }, |
248 | onDelete: 'set null' | 246 | onDelete: 'set null' |
249 | }) | 247 | }) |
250 | CommentAbuses: VideoCommentAbuseModel[] | 248 | CommentAbuses: VideoCommentAbuseModel[] |
251 | 249 | ||
252 | @BeforeDestroy | ||
253 | static async saveEssentialDataToAbuses (instance: VideoCommentModel, options) { | ||
254 | const tasks: Promise<any>[] = [] | ||
255 | |||
256 | if (!Array.isArray(instance.CommentAbuses)) { | ||
257 | instance.CommentAbuses = await instance.$get('CommentAbuses') | ||
258 | |||
259 | if (instance.CommentAbuses.length === 0) return undefined | ||
260 | } | ||
261 | |||
262 | if (!instance.Video) { | ||
263 | instance.Video = await instance.$get('Video') | ||
264 | } | ||
265 | |||
266 | logger.info('Saving video comment %s for abuse.', instance.url) | ||
267 | |||
268 | const details = Object.assign(instance.toFormattedJSON(), { | ||
269 | Video: { | ||
270 | id: instance.Video.id, | ||
271 | name: instance.Video.name, | ||
272 | uuid: instance.Video.uuid | ||
273 | } | ||
274 | }) | ||
275 | |||
276 | for (const abuse of instance.CommentAbuses) { | ||
277 | abuse.deletedComment = details | ||
278 | |||
279 | tasks.push(abuse.save({ transaction: options.transaction })) | ||
280 | } | ||
281 | |||
282 | Promise.all(tasks) | ||
283 | .catch(err => { | ||
284 | logger.error('Some errors when saving details of comment %s in its abuses before destroy hook.', instance.url, { err }) | ||
285 | }) | ||
286 | |||
287 | return undefined | ||
288 | } | ||
289 | |||
290 | static loadById (id: number, t?: Transaction): Bluebird<MComment> { | 250 | static loadById (id: number, t?: Transaction): Bluebird<MComment> { |
291 | const query: FindOptions = { | 251 | const query: FindOptions = { |
292 | where: { | 252 | where: { |