X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-abuse.ts;h=a6319bb79186314d8304fb416b88aae2079b412f;hb=28be89161aab245526d64f6fb7dd29391a97fe0a;hp=182971c4e018a2aa8aa0735d94a71940814c0d2e;hpb=50d6de9c286abcb34ff4234d56d9cbb803db7665;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index 182971c4e..a6319bb79 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts @@ -1,7 +1,8 @@ -import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' +import { VideoAbuse } from '../../../shared/models/videos' import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos' -import { CONFIG } from '../../initializers' +import { Emailer } from '../../lib/emailer' import { AccountModel } from '../account/account' import { getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' @@ -54,11 +55,16 @@ export class VideoAbuseModel extends Model { }) Video: VideoModel + @AfterCreate + static sendEmailNotification (instance: VideoAbuseModel) { + return Emailer.Instance.addVideoAbuseReport(instance.videoId) + } + static listForApi (start: number, count: number, sort: string) { const query = { offset: start, limit: count, - order: [ getSort(sort) ], + order: getSort(sort), include: [ { model: AccountModel, @@ -77,24 +83,17 @@ export class VideoAbuseModel extends Model { }) } - toFormattedJSON () { - let reporterServerHost - - if (this.Account.Actor.Server) { - reporterServerHost = this.Account.Actor.Server.host - } else { - // It means it's our video - reporterServerHost = CONFIG.WEBSERVER.HOST - } - + toFormattedJSON (): VideoAbuse { return { id: this.id, reason: this.reason, - reporterUsername: this.Account.name, - reporterServerHost, - videoId: this.Video.id, - videoUUID: this.Video.uuid, - videoName: this.Video.name, + reporterAccount: this.Account.toFormattedJSON(), + video: { + id: this.Video.id, + uuid: this.Video.uuid, + url: this.Video.url, + name: this.Video.name + }, createdAt: this.createdAt } }