+ 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 })
+ }
+