1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Add new plugin/peertube version notifs

This commit is contained in:
Chocobozzz 2021-03-11 16:54:52 +01:00
parent 3fbc697433
commit 32a18cbf33
No known key found for this signature in database
GPG key ID: 583A612D890159BE
44 changed files with 808 additions and 37 deletions

View file

@ -19,7 +19,7 @@ import { CONFIG } from '../initializers/config'
import { AccountBlocklistModel } from '../models/account/account-blocklist'
import { UserModel } from '../models/account/user'
import { UserNotificationModel } from '../models/account/user-notification'
import { MAbuseFull, MAbuseMessage, MAccountServer, MActorFollowFull } from '../types/models'
import { MAbuseFull, MAbuseMessage, MAccountServer, MActorFollowFull, MApplication, MPlugin } from '../types/models'
import { MCommentOwnerVideo, MVideoAccountLight, MVideoFullLight } from '../types/models/video'
import { isBlockedByServerOrAccount } from './blocklist'
import { Emailer } from './emailer'
@ -144,6 +144,20 @@ class Notifier {
})
}
notifyOfNewPeerTubeVersion (application: MApplication, latestVersion: string) {
this.notifyAdminsOfNewPeerTubeVersion(application, latestVersion)
.catch(err => {
logger.error('Cannot notify on new PeerTubeb version %s.', latestVersion, { err })
})
}
notifyOfNewPluginVersion (plugin: MPlugin) {
this.notifyAdminsOfNewPluginVersion(plugin)
.catch(err => {
logger.error('Cannot notify on new plugin version %s.', plugin.name, { err })
})
}
private async notifySubscribersOfNewVideo (video: MVideoAccountLight) {
// List all followers that are users
const users = await UserModel.listUserSubscribersOf(video.VideoChannel.actorId)
@ -667,6 +681,64 @@ class Notifier {
return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender })
}
private async notifyAdminsOfNewPeerTubeVersion (application: MApplication, latestVersion: string) {
// Use the debug right to know who is an administrator
const admins = await UserModel.listWithRight(UserRight.MANAGE_DEBUG)
if (admins.length === 0) return
logger.info('Notifying %s admins of new PeerTube version %s.', admins.length, latestVersion)
function settingGetter (user: MUserWithNotificationSetting) {
return user.NotificationSetting.newPeerTubeVersion
}
async function notificationCreator (user: MUserWithNotificationSetting) {
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
type: UserNotificationType.NEW_PEERTUBE_VERSION,
userId: user.id,
applicationId: application.id
})
notification.Application = application
return notification
}
function emailSender (emails: string[]) {
return Emailer.Instance.addNewPeerTubeVersionNotification(emails, latestVersion)
}
return this.notify({ users: admins, settingGetter, notificationCreator, emailSender })
}
private async notifyAdminsOfNewPluginVersion (plugin: MPlugin) {
// Use the debug right to know who is an administrator
const admins = await UserModel.listWithRight(UserRight.MANAGE_DEBUG)
if (admins.length === 0) return
logger.info('Notifying %s admins of new plugin version %s@%s.', admins.length, plugin.name, plugin.latestVersion)
function settingGetter (user: MUserWithNotificationSetting) {
return user.NotificationSetting.newPluginVersion
}
async function notificationCreator (user: MUserWithNotificationSetting) {
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
type: UserNotificationType.NEW_PLUGIN_VERSION,
userId: user.id,
pluginId: plugin.id
})
notification.Plugin = plugin
return notification
}
function emailSender (emails: string[]) {
return Emailer.Instance.addNewPlugionVersionNotification(emails, plugin)
}
return this.notify({ users: admins, settingGetter, notificationCreator, emailSender })
}
private async notify<T extends MUserWithNotificationSetting> (options: {
users: T[]
notificationCreator: (user: T) => Promise<UserNotificationModelForApi>