2022-03-22 14:35:04 +01:00
|
|
|
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> {
|
2022-03-22 14:35:04 +01:00
|
|
|
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)
|
2022-03-22 14:35:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getSetting (user: MUserWithNotificationSetting) {
|
2022-03-22 16:58:49 +01:00
|
|
|
return user.NotificationSetting.myVideoStudioEditionFinished
|
2022-03-22 14:35:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2022-03-22 14:35:04 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|