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.ts38
1 files changed, 36 insertions, 2 deletions
diff --git a/server/lib/notifier.ts b/server/lib/notifier.ts
index 9fe93ec0d..91b71cc64 100644
--- a/server/lib/notifier.ts
+++ b/server/lib/notifier.ts
@@ -92,18 +92,25 @@ class Notifier {
92 .catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err })) 92 .catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err }))
93 } 93 }
94 94
95 notifyOfNewFollow (actorFollow: ActorFollowModel): void { 95 notifyOfNewUserFollow (actorFollow: ActorFollowModel): void {
96 this.notifyUserOfNewActorFollow(actorFollow) 96 this.notifyUserOfNewActorFollow(actorFollow)
97 .catch(err => { 97 .catch(err => {
98 logger.error( 98 logger.error(
99 'Cannot notify owner of channel %s of a new follow by %s.', 99 'Cannot notify owner of channel %s of a new follow by %s.',
100 actorFollow.ActorFollowing.VideoChannel.getDisplayName(), 100 actorFollow.ActorFollowing.VideoChannel.getDisplayName(),
101 actorFollow.ActorFollower.Account.getDisplayName(), 101 actorFollow.ActorFollower.Account.getDisplayName(),
102 err 102 { err }
103 ) 103 )
104 }) 104 })
105 } 105 }
106 106
107 notifyOfNewInstanceFollow (actorFollow: ActorFollowModel): void {
108 this.notifyAdminsOfNewInstanceFollow(actorFollow)
109 .catch(err => {
110 logger.error('Cannot notify administrators of new follower %s.', actorFollow.ActorFollower.url, { err })
111 })
112 }
113
107 private async notifySubscribersOfNewVideo (video: VideoModel) { 114 private async notifySubscribersOfNewVideo (video: VideoModel) {
108 // List all followers that are users 115 // List all followers that are users
109 const users = await UserModel.listUserSubscribersOf(video.VideoChannel.actorId) 116 const users = await UserModel.listUserSubscribersOf(video.VideoChannel.actorId)
@@ -261,6 +268,33 @@ class Notifier {
261 return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender }) 268 return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
262 } 269 }
263 270
271 private async notifyAdminsOfNewInstanceFollow (actorFollow: ActorFollowModel) {
272 const admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW)
273
274 logger.info('Notifying %d administrators of new instance follower: %s.', admins.length, actorFollow.ActorFollower.url)
275
276 function settingGetter (user: UserModel) {
277 return user.NotificationSetting.newInstanceFollower
278 }
279
280 async function notificationCreator (user: UserModel) {
281 const notification = await UserNotificationModel.create({
282 type: UserNotificationType.NEW_INSTANCE_FOLLOWER,
283 userId: user.id,
284 actorFollowId: actorFollow.id
285 })
286 notification.ActorFollow = actorFollow
287
288 return notification
289 }
290
291 function emailSender (emails: string[]) {
292 return Emailer.Instance.addNewInstanceFollowerNotification(emails, actorFollow)
293 }
294
295 return this.notify({ users: admins, settingGetter, notificationCreator, emailSender })
296 }
297
264 private async notifyModeratorsOfNewVideoAbuse (videoAbuse: VideoAbuseModel) { 298 private async notifyModeratorsOfNewVideoAbuse (videoAbuse: VideoAbuseModel) {
265 const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_ABUSES) 299 const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_ABUSES)
266 if (moderators.length === 0) return 300 if (moderators.length === 0) return