]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-abuse.ts
Add reason when banning a user
[github/Chocobozzz/PeerTube.git] / server / models / video / video-abuse.ts
index 65b734442564c667940dd8686b39ad4dd5860c1e..39f0c2cb2c6ae605e733d8d70b8762b4f110f0c9 100644 (file)
@@ -1,7 +1,7 @@
 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'
@@ -57,7 +57,7 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
 
   @AfterCreate
   static sendEmailNotification (instance: VideoAbuseModel) {
-    return Emailer.Instance.addVideoAbuseReport(instance.videoId)
+    return Emailer.Instance.addVideoAbuseReportJob(instance.videoId)
   }
 
   static listForApi (start: number, count: number, sort: string) {
@@ -83,24 +83,17 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
       })
   }
 
-  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
     }
   }