diff options
Diffstat (limited to 'server/lib/notifier')
4 files changed, 69 insertions, 2 deletions
diff --git a/server/lib/notifier/notifier.ts b/server/lib/notifier/notifier.ts index 8b68d2e69..e34a82603 100644 --- a/server/lib/notifier/notifier.ts +++ b/server/lib/notifier/notifier.ts | |||
@@ -12,6 +12,7 @@ import { | |||
12 | AbuseStateChangeForReporter, | 12 | AbuseStateChangeForReporter, |
13 | AutoFollowForInstance, | 13 | AutoFollowForInstance, |
14 | CommentMention, | 14 | CommentMention, |
15 | EditionFinishedForOwner, | ||
15 | FollowForInstance, | 16 | FollowForInstance, |
16 | FollowForUser, | 17 | FollowForUser, |
17 | ImportFinishedForOwner, | 18 | ImportFinishedForOwner, |
@@ -53,7 +54,8 @@ class Notifier { | |||
53 | abuseStateChange: [ AbuseStateChangeForReporter ], | 54 | abuseStateChange: [ AbuseStateChangeForReporter ], |
54 | newAbuseMessage: [ NewAbuseMessageForReporter, NewAbuseMessageForModerators ], | 55 | newAbuseMessage: [ NewAbuseMessageForReporter, NewAbuseMessageForModerators ], |
55 | newPeertubeVersion: [ NewPeerTubeVersionForAdmins ], | 56 | newPeertubeVersion: [ NewPeerTubeVersionForAdmins ], |
56 | newPluginVersion: [ NewPluginVersionForAdmins ] | 57 | newPluginVersion: [ NewPluginVersionForAdmins ], |
58 | videoEditionFinished: [ EditionFinishedForOwner ] | ||
57 | } | 59 | } |
58 | 60 | ||
59 | private static instance: Notifier | 61 | private static instance: Notifier |
@@ -198,6 +200,13 @@ class Notifier { | |||
198 | .catch(err => logger.error('Cannot notify on new plugin version %s.', plugin.name, { err })) | 200 | .catch(err => logger.error('Cannot notify on new plugin version %s.', plugin.name, { err })) |
199 | } | 201 | } |
200 | 202 | ||
203 | notifyOfFinishedVideoEdition (video: MVideoFullLight) { | ||
204 | const models = this.notificationModels.videoEditionFinished | ||
205 | |||
206 | this.sendNotifications(models, video) | ||
207 | .catch(err => logger.error('Cannot notify on finished edition %s.', video.url, { err })) | ||
208 | } | ||
209 | |||
201 | private async notify <T> (object: AbstractNotification<T>) { | 210 | private async notify <T> (object: AbstractNotification<T>) { |
202 | await object.prepare() | 211 | await object.prepare() |
203 | 212 | ||
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 | |||
46 | subject: `Your video ${this.payload.name} has been published`, | 46 | subject: `Your video ${this.payload.name} has been published`, |
47 | text: `Your video "${this.payload.name}" has been published.`, | 47 | text: `Your video "${this.payload.name}" has been published.`, |
48 | locals: { | 48 | locals: { |
49 | title: 'You video is live', | 49 | title: 'Your video is live', |
50 | action: { | 50 | action: { |
51 | text: 'View video', | 51 | text: 'View video', |
52 | url: videoUrl | 52 | 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 @@ | |||
1 | import { logger } from '@server/helpers/logger' | ||
2 | import { WEBSERVER } from '@server/initializers/constants' | ||
3 | import { UserModel } from '@server/models/user/user' | ||
4 | import { UserNotificationModel } from '@server/models/user/user-notification' | ||
5 | import { MUserDefault, MUserWithNotificationSetting, MVideoFullLight, UserNotificationModelForApi } from '@server/types/models' | ||
6 | import { UserNotificationType } from '@shared/models' | ||
7 | import { AbstractNotification } from '../common/abstract-notification' | ||
8 | |||
9 | export class EditionFinishedForOwner extends AbstractNotification <MVideoFullLight> { | ||
10 | private user: MUserDefault | ||
11 | |||
12 | async prepare () { | ||
13 | this.user = await UserModel.loadByVideoId(this.payload.id) | ||
14 | } | ||
15 | |||
16 | log () { | ||
17 | logger.info('Notifying user %s its video edition %s is finished.', this.user.username, this.payload.url) | ||
18 | } | ||
19 | |||
20 | getSetting (user: MUserWithNotificationSetting) { | ||
21 | return user.NotificationSetting.myVideoEditionFinished | ||
22 | } | ||
23 | |||
24 | getTargetUsers () { | ||
25 | if (!this.user) return [] | ||
26 | |||
27 | return [ this.user ] | ||
28 | } | ||
29 | |||
30 | async createNotification (user: MUserWithNotificationSetting) { | ||
31 | const notification = await UserNotificationModel.create<UserNotificationModelForApi>({ | ||
32 | type: UserNotificationType.MY_VIDEO_EDITION_FINISHED, | ||
33 | userId: user.id, | ||
34 | videoId: this.payload.id | ||
35 | }) | ||
36 | notification.Video = this.payload | ||
37 | |||
38 | return notification | ||
39 | } | ||
40 | |||
41 | createEmail (to: string) { | ||
42 | const videoUrl = WEBSERVER.URL + this.payload.getWatchStaticPath() | ||
43 | |||
44 | return { | ||
45 | to, | ||
46 | subject: `Edition of your video ${this.payload.name} has finished`, | ||
47 | text: `Edition of your video ${this.payload.name} has finished.`, | ||
48 | locals: { | ||
49 | title: 'Video edition has finished', | ||
50 | action: { | ||
51 | text: 'View video', | ||
52 | url: videoUrl | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | } | ||
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 @@ | |||
1 | export * from './new-video-for-subscribers' | 1 | export * from './new-video-for-subscribers' |
2 | export * from './edition-finished-for-owner' | ||
2 | export * from './import-finished-for-owner' | 3 | export * from './import-finished-for-owner' |
3 | export * from './owned-publication-after-auto-unblacklist' | 4 | export * from './owned-publication-after-auto-unblacklist' |
4 | export * from './owned-publication-after-schedule-update' | 5 | export * from './owned-publication-after-schedule-update' |