aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/notifier.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/notifier.ts')
-rw-r--r--server/lib/notifier.ts76
1 files changed, 76 insertions, 0 deletions
diff --git a/server/lib/notifier.ts b/server/lib/notifier.ts
index a21b50b2d..11b0937e9 100644
--- a/server/lib/notifier.ts
+++ b/server/lib/notifier.ts
@@ -11,6 +11,8 @@ import { VideoPrivacy, VideoState } from '../../shared/models/videos'
11import { VideoAbuseModel } from '../models/video/video-abuse' 11import { VideoAbuseModel } from '../models/video/video-abuse'
12import { VideoBlacklistModel } from '../models/video/video-blacklist' 12import { VideoBlacklistModel } from '../models/video/video-blacklist'
13import * as Bluebird from 'bluebird' 13import * as Bluebird from 'bluebird'
14import { VideoImportModel } from '../models/video/video-import'
15import { AccountBlocklistModel } from '../models/account/account-blocklist'
14 16
15class Notifier { 17class Notifier {
16 18
@@ -26,6 +28,14 @@ class Notifier {
26 .catch(err => logger.error('Cannot notify subscribers of new video %s.', video.url, { err })) 28 .catch(err => logger.error('Cannot notify subscribers of new video %s.', video.url, { err }))
27 } 29 }
28 30
31 notifyOnPendingVideoPublished (video: VideoModel): void {
32 // Only notify on public videos that has been published while the user waited transcoding/scheduled update
33 if (video.waitTranscoding === false && !video.ScheduleVideoUpdate) return
34
35 this.notifyOwnedVideoHasBeenPublished(video)
36 .catch(err => logger.error('Cannot notify owner that its video %s has been published.', video.url, { err }))
37 }
38
29 notifyOnNewComment (comment: VideoCommentModel): void { 39 notifyOnNewComment (comment: VideoCommentModel): void {
30 this.notifyVideoOwnerOfNewComment(comment) 40 this.notifyVideoOwnerOfNewComment(comment)
31 .catch(err => logger.error('Cannot notify of new comment %s.', comment.url, { err })) 41 .catch(err => logger.error('Cannot notify of new comment %s.', comment.url, { err }))
@@ -46,6 +56,11 @@ class Notifier {
46 .catch(err => logger.error('Cannot notify video owner of new video blacklist of %s.', video.url, { err })) 56 .catch(err => logger.error('Cannot notify video owner of new video blacklist of %s.', video.url, { err }))
47 } 57 }
48 58
59 notifyOnFinishedVideoImport (videoImport: VideoImportModel, success: boolean): void {
60 this.notifyOwnerVideoImportIsFinished(videoImport, success)
61 .catch(err => logger.error('Cannot notify owner that its video import %s is finished.', videoImport.getTargetIdentifier(), { err }))
62 }
63
49 private async notifySubscribersOfNewVideo (video: VideoModel) { 64 private async notifySubscribersOfNewVideo (video: VideoModel) {
50 // List all followers that are users 65 // List all followers that are users
51 const users = await UserModel.listUserSubscribersOf(video.VideoChannel.actorId) 66 const users = await UserModel.listUserSubscribersOf(video.VideoChannel.actorId)
@@ -80,6 +95,9 @@ class Notifier {
80 // Not our user or user comments its own video 95 // Not our user or user comments its own video
81 if (!user || comment.Account.userId === user.id) return 96 if (!user || comment.Account.userId === user.id) return
82 97
98 const accountMuted = await AccountBlocklistModel.isAccountMutedBy(user.Account.id, comment.accountId)
99 if (accountMuted) return
100
83 logger.info('Notifying user %s of new comment %s.', user.username, comment.url) 101 logger.info('Notifying user %s of new comment %s.', user.username, comment.url)
84 102
85 function settingGetter (user: UserModel) { 103 function settingGetter (user: UserModel) {
@@ -188,6 +206,64 @@ class Notifier {
188 return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) 206 return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
189 } 207 }
190 208
209 private async notifyOwnedVideoHasBeenPublished (video: VideoModel) {
210 const user = await UserModel.loadByVideoId(video.id)
211 if (!user) return
212
213 logger.info('Notifying user %s of the publication of its video %s.', user.username, video.url)
214
215 function settingGetter (user: UserModel) {
216 return user.NotificationSetting.myVideoPublished
217 }
218
219 async function notificationCreator (user: UserModel) {
220 const notification = await UserNotificationModel.create({
221 type: UserNotificationType.MY_VIDEO_PUBLISHED,
222 userId: user.id,
223 videoId: video.id
224 })
225 notification.Video = video
226
227 return notification
228 }
229
230 function emailSender (emails: string[]) {
231 return Emailer.Instance.myVideoPublishedNotification(emails, video)
232 }
233
234 return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
235 }
236
237 private async notifyOwnerVideoImportIsFinished (videoImport: VideoImportModel, success: boolean) {
238 const user = await UserModel.loadByVideoImportId(videoImport.id)
239 if (!user) return
240
241 logger.info('Notifying user %s its video import %s is finished.', user.username, videoImport.getTargetIdentifier())
242
243 function settingGetter (user: UserModel) {
244 return user.NotificationSetting.myVideoImportFinished
245 }
246
247 async function notificationCreator (user: UserModel) {
248 const notification = await UserNotificationModel.create({
249 type: success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR,
250 userId: user.id,
251 videoImportId: videoImport.id
252 })
253 notification.VideoImport = videoImport
254
255 return notification
256 }
257
258 function emailSender (emails: string[]) {
259 return success
260 ? Emailer.Instance.myVideoImportSuccessNotification(emails, videoImport)
261 : Emailer.Instance.myVideoImportErrorNotification(emails, videoImport)
262 }
263
264 return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
265 }
266
191 private async notify (options: { 267 private async notify (options: {
192 users: UserModel[], 268 users: UserModel[],
193 notificationCreator: (user: UserModel) => Promise<UserNotificationModel>, 269 notificationCreator: (user: UserModel) => Promise<UserNotificationModel>,