1 import { logger } from '@server/helpers/logger'
2 import { toSafeHtml } from '@server/helpers/markdown'
3 import { WEBSERVER } from '@server/initializers/constants'
4 import { isBlockedByServerOrAccount } from '@server/lib/blocklist'
5 import { UserModel } from '@server/models/user/user'
6 import { UserNotificationModel } from '@server/models/user/user-notification'
7 import { MCommentOwnerVideo, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
8 import { UserNotificationType } from '@shared/models'
9 import { AbstractNotification } from '../common/abstract-notification'
11 export class NewCommentForVideoOwner extends AbstractNotification <MCommentOwnerVideo> {
12 private user: MUserDefault
15 this.user = await UserModel.loadByVideoId(this.payload.videoId)
19 logger.info('Notifying owner of a video %s of new comment %s.', this.user.username, this.payload.url)
23 if (this.payload.Video.isOwned() === false) return true
25 // Not our user or user comments its own video
26 if (!this.user || this.payload.Account.userId === this.user.id) return true
28 return isBlockedByServerOrAccount(this.payload.Account, this.user.Account)
31 getSetting (user: MUserWithNotificationSetting) {
32 return user.NotificationSetting.newCommentOnMyVideo
36 if (!this.user) return []
41 async createNotification (user: MUserWithNotificationSetting) {
42 const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
43 type: UserNotificationType.NEW_COMMENT_ON_MY_VIDEO,
45 commentId: this.payload.id
47 notification.Comment = this.payload
52 createEmail (to: string) {
53 const video = this.payload.Video
54 const videoUrl = WEBSERVER.URL + this.payload.Video.getWatchStaticPath()
55 const commentUrl = WEBSERVER.URL + this.payload.getCommentStaticPath()
56 const commentHtml = toSafeHtml(this.payload.text)
59 template: 'video-comment-new',
61 subject: 'New comment on your video ' + video.name,
63 accountName: this.payload.Account.getDisplayName(),
64 accountUrl: this.payload.Account.Actor.url,
65 comment: this.payload,