PeerTube/server/lib/notifier/shared/video-publication/studio-edition-finished-for...

58 lines
1.8 KiB
TypeScript
Raw Normal View History

import { logger } from '@server/helpers/logger'
import { WEBSERVER } from '@server/initializers/constants'
import { UserModel } from '@server/models/user/user'
import { UserNotificationModel } from '@server/models/user/user-notification'
import { MUserDefault, MUserWithNotificationSetting, MVideoFullLight, UserNotificationModelForApi } from '@server/types/models'
import { UserNotificationType } from '@shared/models'
import { AbstractNotification } from '../common/abstract-notification'
2022-03-22 16:58:49 +01:00
export class StudioEditionFinishedForOwner extends AbstractNotification <MVideoFullLight> {
private user: MUserDefault
async prepare () {
this.user = await UserModel.loadByVideoId(this.payload.id)
}
log () {
2022-03-22 16:58:49 +01:00
logger.info('Notifying user %s its video studio edition %s is finished.', this.user.username, this.payload.url)
}
getSetting (user: MUserWithNotificationSetting) {
2022-03-22 16:58:49 +01:00
return user.NotificationSetting.myVideoStudioEditionFinished
}
getTargetUsers () {
if (!this.user) return []
return [ this.user ]
}
2022-08-03 11:33:43 +02:00
createNotification (user: MUserWithNotificationSetting) {
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
2022-03-22 16:58:49 +01:00
type: UserNotificationType.MY_VIDEO_STUDIO_EDITION_FINISHED,
userId: user.id,
videoId: this.payload.id
})
notification.Video = this.payload
return notification
}
createEmail (to: string) {
const videoUrl = WEBSERVER.URL + this.payload.getWatchStaticPath()
return {
to,
subject: `Edition of your video ${this.payload.name} has finished`,
text: `Edition of your video ${this.payload.name} has finished.`,
locals: {
title: 'Video edition has finished',
action: {
text: 'View video',
url: videoUrl
}
}
}
}
}