blob: 6b5ac808a0b47ff8ca7a0c48a9a21b39b380e085 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
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
}
async createNotification (user: MUserWithNotificationSetting) {
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
type: UserNotificationType.NEW_PEERTUBE_VERSION,
userId: user.id,
applicationId: this.payload.application.id
})
notification.Application = this.payload.application
return notification
}
createEmail (to: string) {
return {
to,
template: 'peertube-version-new',
subject: `A new PeerTube version is available: ${this.payload.latestVersion}`,
locals: {
latestVersion: this.payload.latestVersion
}
}
}
}
|