+ private async notifyOwnedVideoHasBeenPublished (video: VideoModel) {
+ const user = await UserModel.loadByVideoId(video.id)
+ if (!user) return
+
+ logger.info('Notifying user %s of the publication of its video %s.', user.username, video.url)
+
+ function settingGetter (user: UserModel) {
+ return user.NotificationSetting.myVideoPublished
+ }
+
+ async function notificationCreator (user: UserModel) {
+ const notification = await UserNotificationModel.create({
+ type: UserNotificationType.MY_VIDEO_PUBLISHED,
+ userId: user.id,
+ videoId: video.id
+ })
+ notification.Video = video
+
+ return notification
+ }
+
+ function emailSender (emails: string[]) {
+ return Emailer.Instance.myVideoPublishedNotification(emails, video)
+ }
+
+ return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
+ }
+
+ private async notifyOwnerVideoImportIsFinished (videoImport: VideoImportModel, success: boolean) {
+ const user = await UserModel.loadByVideoImportId(videoImport.id)
+ if (!user) return
+
+ logger.info('Notifying user %s its video import %s is finished.', user.username, videoImport.getTargetIdentifier())
+
+ function settingGetter (user: UserModel) {
+ return user.NotificationSetting.myVideoImportFinished
+ }
+
+ async function notificationCreator (user: UserModel) {
+ const notification = await UserNotificationModel.create({
+ type: success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR,
+ userId: user.id,
+ videoImportId: videoImport.id
+ })
+ notification.VideoImport = videoImport
+
+ return notification
+ }
+
+ function emailSender (emails: string[]) {
+ return success
+ ? Emailer.Instance.myVideoImportSuccessNotification(emails, videoImport)
+ : Emailer.Instance.myVideoImportErrorNotification(emails, videoImport)
+ }
+
+ return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
+ }
+