]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/notifier/shared/blacklist/unblacklist-for-owner.ts
Add video edition finished notification
[github/Chocobozzz/PeerTube.git] / server / lib / notifier / shared / blacklist / unblacklist-for-owner.ts
CommitLineData
d26836cd
C
1import { logger } from '@server/helpers/logger'
2import { CONFIG } from '@server/initializers/config'
3import { WEBSERVER } from '@server/initializers/constants'
4import { UserModel } from '@server/models/user/user'
5import { UserNotificationModel } from '@server/models/user/user-notification'
6import { MUserDefault, MUserWithNotificationSetting, MVideoFullLight, UserNotificationModelForApi } from '@server/types/models'
7import { UserNotificationType } from '@shared/models'
8import { AbstractNotification } from '../common/abstract-notification'
9
10export class UnblacklistForOwner extends AbstractNotification <MVideoFullLight> {
11 private user: MUserDefault
12
13 async prepare () {
14 this.user = await UserModel.loadByVideoId(this.payload.id)
15 }
16
17 log () {
18 logger.info('Notifying user %s that its video %s has been unblacklisted.', this.user.username, this.payload.url)
19 }
20
21 getSetting (user: MUserWithNotificationSetting) {
22 return user.NotificationSetting.blacklistOnMyVideo
23 }
24
25 getTargetUsers () {
26 if (!this.user) return []
27
28 return [ this.user ]
29 }
30
31 async createNotification (user: MUserWithNotificationSetting) {
32 const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
33 type: UserNotificationType.UNBLACKLIST_ON_MY_VIDEO,
34 userId: user.id,
35 videoId: this.payload.id
36 })
37 notification.Video = this.payload
38
39 return notification
40 }
41
42 createEmail (to: string) {
43 const video = this.payload
44 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
45
46 return {
47 to,
48 subject: `Video ${video.name} unblacklisted`,
49 text: `Your video "${video.name}" (${videoUrl}) on ${CONFIG.INSTANCE.NAME} has been unblacklisted.`,
50 locals: {
51 title: 'Your video was unblacklisted'
52 }
53 }
54 }
55}