1 import { logger } from '@server/helpers/logger'
2 import { UserModel } from '@server/models/user/user'
3 import { UserNotificationModel } from '@server/models/user/user-notification'
4 import { MApplication, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
5 import { UserNotificationType, UserRight } from '@shared/models'
6 import { AbstractNotification } from '../common/abstract-notification'
8 export type NewPeerTubeVersionForAdminsPayload = {
9 application: MApplication
13 export class NewPeerTubeVersionForAdmins extends AbstractNotification <NewPeerTubeVersionForAdminsPayload> {
14 private admins: MUserDefault[]
17 // Use the debug right to know who is an administrator
18 this.admins = await UserModel.listWithRight(UserRight.MANAGE_DEBUG)
22 logger.info('Notifying %s admins of new PeerTube version %s.', this.admins.length, this.payload.latestVersion)
25 getSetting (user: MUserWithNotificationSetting) {
26 return user.NotificationSetting.newPeerTubeVersion
33 async createNotification (user: MUserWithNotificationSetting) {
34 const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
35 type: UserNotificationType.NEW_PEERTUBE_VERSION,
37 applicationId: this.payload.application.id
39 notification.Application = this.payload.application
44 createEmail (to: string) {
47 template: 'peertube-version-new',
48 subject: `A new PeerTube version is available: ${this.payload.latestVersion}`,
50 latestVersion: this.payload.latestVersion