From 1808a1f8e4b7b102823492a2007a46929aebf189 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 22 Mar 2022 14:35:04 +0100 Subject: Add video edition finished notification --- .../abstract-owned-video-publication.ts | 2 +- .../edition-finished-for-owner.ts | 57 ++++++++++++++++++++++ .../lib/notifier/shared/video-publication/index.ts | 1 + 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 server/lib/notifier/shared/video-publication/edition-finished-for-owner.ts (limited to 'server/lib/notifier/shared/video-publication') diff --git a/server/lib/notifier/shared/video-publication/abstract-owned-video-publication.ts b/server/lib/notifier/shared/video-publication/abstract-owned-video-publication.ts index fd06e080d..37435f898 100644 --- a/server/lib/notifier/shared/video-publication/abstract-owned-video-publication.ts +++ b/server/lib/notifier/shared/video-publication/abstract-owned-video-publication.ts @@ -46,7 +46,7 @@ export abstract class AbstractOwnedVideoPublication extends AbstractNotification subject: `Your video ${this.payload.name} has been published`, text: `Your video "${this.payload.name}" has been published.`, locals: { - title: 'You video is live', + title: 'Your video is live', action: { text: 'View video', url: videoUrl diff --git a/server/lib/notifier/shared/video-publication/edition-finished-for-owner.ts b/server/lib/notifier/shared/video-publication/edition-finished-for-owner.ts new file mode 100644 index 000000000..dec91f574 --- /dev/null +++ b/server/lib/notifier/shared/video-publication/edition-finished-for-owner.ts @@ -0,0 +1,57 @@ +import { logger } from '@server/helpers/logger' +import { WEBSERVER } from '@server/initializers/constants' +import { UserModel } from '@server/models/user/user' +import { UserNotificationModel } from '@server/models/user/user-notification' +import { MUserDefault, MUserWithNotificationSetting, MVideoFullLight, UserNotificationModelForApi } from '@server/types/models' +import { UserNotificationType } from '@shared/models' +import { AbstractNotification } from '../common/abstract-notification' + +export class EditionFinishedForOwner extends AbstractNotification { + private user: MUserDefault + + async prepare () { + this.user = await UserModel.loadByVideoId(this.payload.id) + } + + log () { + logger.info('Notifying user %s its video edition %s is finished.', this.user.username, this.payload.url) + } + + getSetting (user: MUserWithNotificationSetting) { + return user.NotificationSetting.myVideoEditionFinished + } + + getTargetUsers () { + if (!this.user) return [] + + return [ this.user ] + } + + async createNotification (user: MUserWithNotificationSetting) { + const notification = await UserNotificationModel.create({ + type: UserNotificationType.MY_VIDEO_EDITION_FINISHED, + userId: user.id, + videoId: this.payload.id + }) + notification.Video = this.payload + + return notification + } + + createEmail (to: string) { + const videoUrl = WEBSERVER.URL + this.payload.getWatchStaticPath() + + return { + to, + subject: `Edition of your video ${this.payload.name} has finished`, + text: `Edition of your video ${this.payload.name} has finished.`, + locals: { + title: 'Video edition has finished', + action: { + text: 'View video', + url: videoUrl + } + } + } + } +} diff --git a/server/lib/notifier/shared/video-publication/index.ts b/server/lib/notifier/shared/video-publication/index.ts index 940774504..57f3443b9 100644 --- a/server/lib/notifier/shared/video-publication/index.ts +++ b/server/lib/notifier/shared/video-publication/index.ts @@ -1,4 +1,5 @@ export * from './new-video-for-subscribers' +export * from './edition-finished-for-owner' export * from './import-finished-for-owner' export * from './owned-publication-after-auto-unblacklist' export * from './owned-publication-after-schedule-update' -- cgit v1.2.3