1 import { logger } from '@server/helpers/logger'
2 import { CONFIG } from '@server/initializers/config'
3 import { WEBSERVER } from '@server/initializers/constants'
4 import { UserModel } from '@server/models/user/user'
5 import { UserNotificationModel } from '@server/models/user/user-notification'
6 import { MUserDefault, MUserWithNotificationSetting, MVideoBlacklistVideo, UserNotificationModelForApi } from '@server/types/models'
7 import { UserNotificationType } from '@shared/models'
8 import { AbstractNotification } from '../common/abstract-notification'
10 export class NewBlacklistForOwner extends AbstractNotification <MVideoBlacklistVideo> {
11 private user: MUserDefault
14 this.user = await UserModel.loadByVideoId(this.payload.videoId)
18 logger.info('Notifying user %s that its video %s has been blacklisted.', this.user.username, this.payload.Video.url)
21 getSetting (user: MUserWithNotificationSetting) {
22 return user.NotificationSetting.blacklistOnMyVideo
26 if (!this.user) return []
31 createNotification (user: MUserWithNotificationSetting) {
32 const notification = UserNotificationModel.build<UserNotificationModelForApi>({
33 type: UserNotificationType.BLACKLIST_ON_MY_VIDEO,
35 videoBlacklistId: this.payload.id
37 notification.VideoBlacklist = this.payload
42 createEmail (to: string) {
43 const videoName = this.payload.Video.name
44 const videoUrl = WEBSERVER.URL + this.payload.Video.getWatchStaticPath()
46 const reasonString = this.payload.reason ? ` for the following reason: ${this.payload.reason}` : ''
47 const blockedString = `Your video ${videoName} (${videoUrl} on ${CONFIG.INSTANCE.NAME} has been blacklisted${reasonString}.`
51 subject: `Video ${videoName} blacklisted`,
54 title: 'Your video was blacklisted'