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.ts69
1 files changed, 38 insertions, 31 deletions
diff --git a/server/lib/notifier.ts b/server/lib/notifier.ts
index 679b9bcf6..017739523 100644
--- a/server/lib/notifier.ts
+++ b/server/lib/notifier.ts
@@ -5,8 +5,7 @@ import { UserNotificationModel } from '../models/account/user-notification'
5import { UserModel } from '../models/account/user' 5import { UserModel } from '../models/account/user'
6import { PeerTubeSocket } from './peertube-socket' 6import { PeerTubeSocket } from './peertube-socket'
7import { CONFIG } from '../initializers/config' 7import { CONFIG } from '../initializers/config'
8import { VideoPrivacy, VideoState } from '../../shared/models/videos' 8import { VideoPrivacy, VideoState, VideoAbuse } from '../../shared/models/videos'
9import * as Bluebird from 'bluebird'
10import { AccountBlocklistModel } from '../models/account/account-blocklist' 9import { AccountBlocklistModel } from '../models/account/account-blocklist'
11import { 10import {
12 MCommentOwnerVideo, 11 MCommentOwnerVideo,
@@ -17,7 +16,8 @@ import {
17 MVideoFullLight 16 MVideoFullLight
18} from '../typings/models/video' 17} from '../typings/models/video'
19import { 18import {
20 MUser, MUserAccount, 19 MUser,
20 MUserAccount,
21 MUserDefault, 21 MUserDefault,
22 MUserNotifSettingAccount, 22 MUserNotifSettingAccount,
23 MUserWithNotificationSetting, 23 MUserWithNotificationSetting,
@@ -26,20 +26,21 @@ import {
26import { MAccountDefault, MActorFollowFull } from '../typings/models' 26import { MAccountDefault, MActorFollowFull } from '../typings/models'
27import { MVideoImportVideo } from '@server/typings/models/video/video-import' 27import { MVideoImportVideo } from '@server/typings/models/video/video-import'
28import { ServerBlocklistModel } from '@server/models/server/server-blocklist' 28import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
29import { getServerActor } from '@server/helpers/utils' 29import { getServerActor } from '@server/models/application/application'
30 30
31class Notifier { 31class Notifier {
32 32
33 private static instance: Notifier 33 private static instance: Notifier
34 34
35 private constructor () {} 35 private constructor () {
36 }
36 37
37 notifyOnNewVideoIfNeeded (video: MVideoAccountLight): void { 38 notifyOnNewVideoIfNeeded (video: MVideoAccountLight): void {
38 // Only notify on public and published videos which are not blacklisted 39 // Only notify on public and published videos which are not blacklisted
39 if (video.privacy !== VideoPrivacy.PUBLIC || video.state !== VideoState.PUBLISHED || video.isBlacklisted()) return 40 if (video.privacy !== VideoPrivacy.PUBLIC || video.state !== VideoState.PUBLISHED || video.isBlacklisted()) return
40 41
41 this.notifySubscribersOfNewVideo(video) 42 this.notifySubscribersOfNewVideo(video)
42 .catch(err => logger.error('Cannot notify subscribers of new video %s.', video.url, { err })) 43 .catch(err => logger.error('Cannot notify subscribers of new video %s.', video.url, { err }))
43 } 44 }
44 45
45 notifyOnVideoPublishedAfterTranscoding (video: MVideoFullLight): void { 46 notifyOnVideoPublishedAfterTranscoding (video: MVideoFullLight): void {
@@ -63,7 +64,9 @@ class Notifier {
63 if (video.ScheduleVideoUpdate || (video.waitTranscoding && video.state !== VideoState.PUBLISHED)) return 64 if (video.ScheduleVideoUpdate || (video.waitTranscoding && video.state !== VideoState.PUBLISHED)) return
64 65
65 this.notifyOwnedVideoHasBeenPublished(video) 66 this.notifyOwnedVideoHasBeenPublished(video)
66 .catch(err => logger.error('Cannot notify owner that its video %s has been published after removed from auto-blacklist.', video.url, { err })) // tslint:disable-line:max-line-length 67 .catch(err => {
68 logger.error('Cannot notify owner that its video %s has been published after removed from auto-blacklist.', video.url, { err })
69 })
67 } 70 }
68 71
69 notifyOnNewComment (comment: MCommentOwnerVideo): void { 72 notifyOnNewComment (comment: MCommentOwnerVideo): void {
@@ -74,19 +77,19 @@ class Notifier {
74 .catch(err => logger.error('Cannot notify mentions of comment %s.', comment.url, { err })) 77 .catch(err => logger.error('Cannot notify mentions of comment %s.', comment.url, { err }))
75 } 78 }
76 79
77 notifyOnNewVideoAbuse (videoAbuse: MVideoAbuseVideo): void { 80 notifyOnNewVideoAbuse (parameters: { videoAbuse: VideoAbuse, videoAbuseInstance: MVideoAbuseVideo, reporter: string }): void {
78 this.notifyModeratorsOfNewVideoAbuse(videoAbuse) 81 this.notifyModeratorsOfNewVideoAbuse(parameters)
79 .catch(err => logger.error('Cannot notify of new video abuse of video %s.', videoAbuse.Video.url, { err })) 82 .catch(err => logger.error('Cannot notify of new video abuse of video %s.', parameters.videoAbuseInstance.Video.url, { err }))
80 } 83 }
81 84
82 notifyOnVideoAutoBlacklist (videoBlacklist: MVideoBlacklistLightVideo): void { 85 notifyOnVideoAutoBlacklist (videoBlacklist: MVideoBlacklistLightVideo): void {
83 this.notifyModeratorsOfVideoAutoBlacklist(videoBlacklist) 86 this.notifyModeratorsOfVideoAutoBlacklist(videoBlacklist)
84 .catch(err => logger.error('Cannot notify of auto-blacklist of video %s.', videoBlacklist.Video.url, { err })) 87 .catch(err => logger.error('Cannot notify of auto-blacklist of video %s.', videoBlacklist.Video.url, { err }))
85 } 88 }
86 89
87 notifyOnVideoBlacklist (videoBlacklist: MVideoBlacklistVideo): void { 90 notifyOnVideoBlacklist (videoBlacklist: MVideoBlacklistVideo): void {
88 this.notifyVideoOwnerOfBlacklist(videoBlacklist) 91 this.notifyVideoOwnerOfBlacklist(videoBlacklist)
89 .catch(err => logger.error('Cannot notify video owner of new video blacklist of %s.', videoBlacklist.Video.url, { err })) 92 .catch(err => logger.error('Cannot notify video owner of new video blacklist of %s.', videoBlacklist.Video.url, { err }))
90 } 93 }
91 94
92 notifyOnVideoUnblacklist (video: MVideoFullLight): void { 95 notifyOnVideoUnblacklist (video: MVideoFullLight): void {
@@ -96,7 +99,7 @@ class Notifier {
96 99
97 notifyOnFinishedVideoImport (videoImport: MVideoImportVideo, success: boolean): void { 100 notifyOnFinishedVideoImport (videoImport: MVideoImportVideo, success: boolean): void {
98 this.notifyOwnerVideoImportIsFinished(videoImport, success) 101 this.notifyOwnerVideoImportIsFinished(videoImport, success)
99 .catch(err => logger.error('Cannot notify owner that its video import %s is finished.', videoImport.getTargetIdentifier(), { err })) 102 .catch(err => logger.error('Cannot notify owner that its video import %s is finished.', videoImport.getTargetIdentifier(), { err }))
100 } 103 }
101 104
102 notifyOnNewUserRegistration (user: MUserDefault): void { 105 notifyOnNewUserRegistration (user: MUserDefault): void {
@@ -106,14 +109,14 @@ class Notifier {
106 109
107 notifyOfNewUserFollow (actorFollow: MActorFollowFull): void { 110 notifyOfNewUserFollow (actorFollow: MActorFollowFull): void {
108 this.notifyUserOfNewActorFollow(actorFollow) 111 this.notifyUserOfNewActorFollow(actorFollow)
109 .catch(err => { 112 .catch(err => {
110 logger.error( 113 logger.error(
111 'Cannot notify owner of channel %s of a new follow by %s.', 114 'Cannot notify owner of channel %s of a new follow by %s.',
112 actorFollow.ActorFollowing.VideoChannel.getDisplayName(), 115 actorFollow.ActorFollowing.VideoChannel.getDisplayName(),
113 actorFollow.ActorFollower.Account.getDisplayName(), 116 actorFollow.ActorFollower.Account.getDisplayName(),
114 { err } 117 { err }
115 ) 118 )
116 }) 119 })
117 } 120 }
118 121
119 notifyOfNewInstanceFollow (actorFollow: MActorFollowFull): void { 122 notifyOfNewInstanceFollow (actorFollow: MActorFollowFull): void {
@@ -347,11 +350,15 @@ class Notifier {
347 return this.notify({ users: admins, settingGetter, notificationCreator, emailSender }) 350 return this.notify({ users: admins, settingGetter, notificationCreator, emailSender })
348 } 351 }
349 352
350 private async notifyModeratorsOfNewVideoAbuse (videoAbuse: MVideoAbuseVideo) { 353 private async notifyModeratorsOfNewVideoAbuse (parameters: {
354 videoAbuse: VideoAbuse
355 videoAbuseInstance: MVideoAbuseVideo
356 reporter: string
357 }) {
351 const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_ABUSES) 358 const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_ABUSES)
352 if (moderators.length === 0) return 359 if (moderators.length === 0) return
353 360
354 logger.info('Notifying %s user/moderators of new video abuse %s.', moderators.length, videoAbuse.Video.url) 361 logger.info('Notifying %s user/moderators of new video abuse %s.', moderators.length, parameters.videoAbuseInstance.Video.url)
355 362
356 function settingGetter (user: MUserWithNotificationSetting) { 363 function settingGetter (user: MUserWithNotificationSetting) {
357 return user.NotificationSetting.videoAbuseAsModerator 364 return user.NotificationSetting.videoAbuseAsModerator
@@ -361,15 +368,15 @@ class Notifier {
361 const notification: UserNotificationModelForApi = await UserNotificationModel.create<UserNotificationModelForApi>({ 368 const notification: UserNotificationModelForApi = await UserNotificationModel.create<UserNotificationModelForApi>({
362 type: UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS, 369 type: UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS,
363 userId: user.id, 370 userId: user.id,
364 videoAbuseId: videoAbuse.id 371 videoAbuseId: parameters.videoAbuse.id
365 }) 372 })
366 notification.VideoAbuse = videoAbuse 373 notification.VideoAbuse = parameters.videoAbuseInstance
367 374
368 return notification 375 return notification
369 } 376 }
370 377
371 function emailSender (emails: string[]) { 378 function emailSender (emails: string[]) {
372 return Emailer.Instance.addVideoAbuseModeratorsNotification(emails, videoAbuse) 379 return Emailer.Instance.addVideoAbuseModeratorsNotification(emails, parameters)
373 } 380 }
374 381
375 return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender }) 382 return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender })
@@ -548,10 +555,10 @@ class Notifier {
548 return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender }) 555 return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender })
549 } 556 }
550 557
551 private async notify <T extends MUserWithNotificationSetting> (options: { 558 private async notify<T extends MUserWithNotificationSetting> (options: {
552 users: T[], 559 users: T[]
553 notificationCreator: (user: T) => Promise<UserNotificationModelForApi>, 560 notificationCreator: (user: T) => Promise<UserNotificationModelForApi>
554 emailSender: (emails: string[]) => Promise<any> | Bluebird<any>, 561 emailSender: (emails: string[]) => void
555 settingGetter: (user: T) => UserNotificationSettingValue 562 settingGetter: (user: T) => UserNotificationSettingValue
556 }) { 563 }) {
557 const emails: string[] = [] 564 const emails: string[] = []
@@ -569,7 +576,7 @@ class Notifier {
569 } 576 }
570 577
571 if (emails.length !== 0) { 578 if (emails.length !== 0) {
572 await options.emailSender(emails) 579 options.emailSender(emails)
573 } 580 }
574 } 581 }
575 582