2021-07-30 16:51:27 +02:00
|
|
|
import { logger } from '@server/helpers/logger'
|
|
|
|
import { UserModel } from '@server/models/user/user'
|
|
|
|
import { UserNotificationModel } from '@server/models/user/user-notification'
|
|
|
|
import { MApplication, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
|
|
|
|
import { UserNotificationType, UserRight } from '@shared/models'
|
|
|
|
import { AbstractNotification } from '../common/abstract-notification'
|
|
|
|
|
|
|
|
export type NewPeerTubeVersionForAdminsPayload = {
|
|
|
|
application: MApplication
|
|
|
|
latestVersion: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export class NewPeerTubeVersionForAdmins extends AbstractNotification <NewPeerTubeVersionForAdminsPayload> {
|
|
|
|
private admins: MUserDefault[]
|
|
|
|
|
|
|
|
async prepare () {
|
|
|
|
// Use the debug right to know who is an administrator
|
|
|
|
this.admins = await UserModel.listWithRight(UserRight.MANAGE_DEBUG)
|
|
|
|
}
|
|
|
|
|
|
|
|
log () {
|
|
|
|
logger.info('Notifying %s admins of new PeerTube version %s.', this.admins.length, this.payload.latestVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
getSetting (user: MUserWithNotificationSetting) {
|
|
|
|
return user.NotificationSetting.newPeerTubeVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
getTargetUsers () {
|
|
|
|
return this.admins
|
|
|
|
}
|
|
|
|
|
2022-08-03 11:33:43 +02:00
|
|
|
createNotification (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
|
2021-07-30 16:51:27 +02:00
|
|
|
type: UserNotificationType.NEW_PEERTUBE_VERSION,
|
|
|
|
userId: user.id,
|
|
|
|
applicationId: this.payload.application.id
|
|
|
|
})
|
|
|
|
notification.Application = this.payload.application
|
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
2021-08-25 16:14:11 +02:00
|
|
|
createEmail (to: string) {
|
2021-07-30 16:51:27 +02:00
|
|
|
return {
|
|
|
|
to,
|
|
|
|
template: 'peertube-version-new',
|
|
|
|
subject: `A new PeerTube version is available: ${this.payload.latestVersion}`,
|
|
|
|
locals: {
|
|
|
|
latestVersion: this.payload.latestVersion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|