Split types and typings
[oweals/peertube.git] / server / lib / notifier.ts
index 23f76a21a413684fda8cc3cd2d4fffb2d6d497cb..943a087d2e8315bb575b29803aa5b03403c3a813 100644 (file)
@@ -1,43 +1,47 @@
+import { getServerActor } from '@server/models/application/application'
+import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
+import {
+  MUser,
+  MUserAccount,
+  MUserDefault,
+  MUserNotifSettingAccount,
+  MUserWithNotificationSetting,
+  UserNotificationModelForApi
+} from '@server/types/models/user'
+import { MVideoImportVideo } from '@server/types/models/video/video-import'
 import { UserNotificationSettingValue, UserNotificationType, UserRight } from '../../shared/models/users'
+import { VideoAbuse, VideoPrivacy, VideoState } from '../../shared/models/videos'
 import { logger } from '../helpers/logger'
-import { VideoModel } from '../models/video/video'
-import { Emailer } from './emailer'
-import { UserNotificationModel } from '../models/account/user-notification'
-import { VideoCommentModel } from '../models/video/video-comment'
-import { UserModel } from '../models/account/user'
-import { PeerTubeSocket } from './peertube-socket'
 import { CONFIG } from '../initializers/config'
-import { VideoPrivacy, VideoState } from '../../shared/models/videos'
-import { VideoBlacklistModel } from '../models/video/video-blacklist'
-import * as Bluebird from 'bluebird'
-import { VideoImportModel } from '../models/video/video-import'
 import { AccountBlocklistModel } from '../models/account/account-blocklist'
+import { UserModel } from '../models/account/user'
+import { UserNotificationModel } from '../models/account/user-notification'
+import { MAccountServer, MActorFollowFull } from '../types/models'
 import {
   MCommentOwnerVideo,
-  MVideo,
   MVideoAbuseVideo,
   MVideoAccountLight,
+  MVideoBlacklistLightVideo,
   MVideoBlacklistVideo,
   MVideoFullLight
-} from '../typings/models/video'
-import { MUser, MUserAccount, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/typings/models/user'
-import { MActorFollowActors, MActorFollowFull, MActorFollowFollowingFullFollowerAccount } from '../typings/models'
-import { ActorFollowModel } from '../models/activitypub/actor-follow'
-import { MVideoImportVideo } from '@server/typings/models/video/video-import'
-import { AccountModel } from '@server/models/account/account'
+} from '../types/models/video'
+import { isBlockedByServerOrAccount } from './blocklist'
+import { Emailer } from './emailer'
+import { PeerTubeSocket } from './peertube-socket'
 
 class Notifier {
 
   private static instance: Notifier
 
-  private constructor () {}
+  private constructor () {
+  }
 
   notifyOnNewVideoIfNeeded (video: MVideoAccountLight): void {
     // Only notify on public and published videos which are not blacklisted
     if (video.privacy !== VideoPrivacy.PUBLIC || video.state !== VideoState.PUBLISHED || video.isBlacklisted()) return
 
     this.notifySubscribersOfNewVideo(video)
-      .catch(err => logger.error('Cannot notify subscribers of new video %s.', video.url, { err }))
+        .catch(err => logger.error('Cannot notify subscribers of new video %s.', video.url, { err }))
   }
 
   notifyOnVideoPublishedAfterTranscoding (video: MVideoFullLight): void {
@@ -61,7 +65,9 @@ class Notifier {
     if (video.ScheduleVideoUpdate || (video.waitTranscoding && video.state !== VideoState.PUBLISHED)) return
 
     this.notifyOwnedVideoHasBeenPublished(video)
-        .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
+        .catch(err => {
+          logger.error('Cannot notify owner that its video %s has been published after removed from auto-blacklist.', video.url, { err })
+        })
   }
 
   notifyOnNewComment (comment: MCommentOwnerVideo): void {
@@ -72,72 +78,79 @@ class Notifier {
         .catch(err => logger.error('Cannot notify mentions of comment %s.', comment.url, { err }))
   }
 
-  notifyOnNewVideoAbuse (videoAbuse: MVideoAbuseVideo): void {
-    this.notifyModeratorsOfNewVideoAbuse(videoAbuse)
-      .catch(err => logger.error('Cannot notify of new video abuse of video %s.', videoAbuse.Video.url, { err }))
+  notifyOnNewVideoAbuse (parameters: { videoAbuse: VideoAbuse, videoAbuseInstance: MVideoAbuseVideo, reporter: string }): void {
+    this.notifyModeratorsOfNewVideoAbuse(parameters)
+        .catch(err => logger.error('Cannot notify of new video abuse of video %s.', parameters.videoAbuseInstance.Video.url, { err }))
   }
 
-  notifyOnVideoAutoBlacklist (video: MVideo): void {
-    this.notifyModeratorsOfVideoAutoBlacklist(video)
-      .catch(err => logger.error('Cannot notify of auto-blacklist of video %s.', video.url, { err }))
+  notifyOnVideoAutoBlacklist (videoBlacklist: MVideoBlacklistLightVideo): void {
+    this.notifyModeratorsOfVideoAutoBlacklist(videoBlacklist)
+        .catch(err => logger.error('Cannot notify of auto-blacklist of video %s.', videoBlacklist.Video.url, { err }))
   }
 
   notifyOnVideoBlacklist (videoBlacklist: MVideoBlacklistVideo): void {
     this.notifyVideoOwnerOfBlacklist(videoBlacklist)
-      .catch(err => logger.error('Cannot notify video owner of new video blacklist of %s.', videoBlacklist.Video.url, { err }))
+        .catch(err => logger.error('Cannot notify video owner of new video blacklist of %s.', videoBlacklist.Video.url, { err }))
   }
 
-  notifyOnVideoUnblacklist (video: MVideo): void {
+  notifyOnVideoUnblacklist (video: MVideoFullLight): void {
     this.notifyVideoOwnerOfUnblacklist(video)
         .catch(err => logger.error('Cannot notify video owner of unblacklist of %s.', video.url, { err }))
   }
 
   notifyOnFinishedVideoImport (videoImport: MVideoImportVideo, success: boolean): void {
     this.notifyOwnerVideoImportIsFinished(videoImport, success)
-      .catch(err => logger.error('Cannot notify owner that its video import %s is finished.', videoImport.getTargetIdentifier(), { err }))
+        .catch(err => logger.error('Cannot notify owner that its video import %s is finished.', videoImport.getTargetIdentifier(), { err }))
   }
 
-  notifyOnNewUserRegistration (user: MUserAccount): void {
+  notifyOnNewUserRegistration (user: MUserDefault): void {
     this.notifyModeratorsOfNewUserRegistration(user)
         .catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err }))
   }
 
-  notifyOfNewUserFollow (actorFollow: MActorFollowFollowingFullFollowerAccount): void {
+  notifyOfNewUserFollow (actorFollow: MActorFollowFull): void {
     this.notifyUserOfNewActorFollow(actorFollow)
-      .catch(err => {
-        logger.error(
-          'Cannot notify owner of channel %s of a new follow by %s.',
-          actorFollow.ActorFollowing.VideoChannel.getDisplayName(),
-          actorFollow.ActorFollower.Account.getDisplayName(),
-          { err }
-        )
-      })
+        .catch(err => {
+          logger.error(
+            'Cannot notify owner of channel %s of a new follow by %s.',
+            actorFollow.ActorFollowing.VideoChannel.getDisplayName(),
+            actorFollow.ActorFollower.Account.getDisplayName(),
+            { err }
+          )
+        })
   }
 
-  notifyOfNewInstanceFollow (actorFollow: MActorFollowActors): void {
+  notifyOfNewInstanceFollow (actorFollow: MActorFollowFull): void {
     this.notifyAdminsOfNewInstanceFollow(actorFollow)
         .catch(err => {
           logger.error('Cannot notify administrators of new follower %s.', actorFollow.ActorFollower.url, { err })
         })
   }
 
+  notifyOfAutoInstanceFollowing (actorFollow: MActorFollowFull): void {
+    this.notifyAdminsOfAutoInstanceFollowing(actorFollow)
+        .catch(err => {
+          logger.error('Cannot notify administrators of auto instance following %s.', actorFollow.ActorFollowing.url, { err })
+        })
+  }
+
   private async notifySubscribersOfNewVideo (video: MVideoAccountLight) {
     // List all followers that are users
     const users = await UserModel.listUserSubscribersOf(video.VideoChannel.actorId)
 
     logger.info('Notifying %d users of new video %s.', users.length, video.url)
 
-    function settingGetter (user: UserModel) {
+    function settingGetter (user: MUserWithNotificationSetting) {
       return user.NotificationSetting.newVideoFromSubscription
     }
 
-    async function notificationCreator (user: UserModel) {
-      const notification = await UserNotificationModel.create({
+    async function notificationCreator (user: MUserWithNotificationSetting) {
+      const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
         type: UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION,
         userId: user.id,
         videoId: video.id
       })
-      notification.Video = video as VideoModel
+      notification.Video = video
 
       return notification
     }
@@ -157,22 +170,21 @@ class Notifier {
     // Not our user or user comments its own video
     if (!user || comment.Account.userId === user.id) return
 
-    const accountMuted = await AccountBlocklistModel.isAccountMutedBy(user.Account.id, comment.accountId)
-    if (accountMuted) return
+    if (await this.isBlockedByServerOrUser(comment.Account, user)) return
 
     logger.info('Notifying user %s of new comment %s.', user.username, comment.url)
 
-    function settingGetter (user: UserModel) {
+    function settingGetter (user: MUserWithNotificationSetting) {
       return user.NotificationSetting.newCommentOnMyVideo
     }
 
-    async function notificationCreator (user: UserModel) {
-      const notification = await UserNotificationModel.create({
+    async function notificationCreator (user: MUserWithNotificationSetting) {
+      const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
         type: UserNotificationType.NEW_COMMENT_ON_MY_VIDEO,
         userId: user.id,
         commentId: comment.id
       })
-      notification.Comment = comment as VideoCommentModel
+      notification.Comment = comment
 
       return notification
     }
@@ -203,23 +215,33 @@ class Notifier {
 
     if (users.length === 0) return
 
-    const accountMutedHash = await AccountBlocklistModel.isAccountMutedByMulti(users.map(u => u.Account.id), comment.accountId)
+    const serverAccountId = (await getServerActor()).Account.id
+    const sourceAccounts = users.map(u => u.Account.id).concat([ serverAccountId ])
+
+    const accountMutedHash = await AccountBlocklistModel.isAccountMutedByMulti(sourceAccounts, comment.accountId)
+    const instanceMutedHash = await ServerBlocklistModel.isServerMutedByMulti(sourceAccounts, comment.Account.Actor.serverId)
 
     logger.info('Notifying %d users of new comment %s.', users.length, comment.url)
 
-    function settingGetter (user: UserModel) {
-      if (accountMutedHash[user.Account.id] === true) return UserNotificationSettingValue.NONE
+    function settingGetter (user: MUserNotifSettingAccount) {
+      const accountId = user.Account.id
+      if (
+        accountMutedHash[accountId] === true || instanceMutedHash[accountId] === true ||
+        accountMutedHash[serverAccountId] === true || instanceMutedHash[serverAccountId] === true
+      ) {
+        return UserNotificationSettingValue.NONE
+      }
 
       return user.NotificationSetting.commentMention
     }
 
-    async function notificationCreator (user: UserModel) {
-      const notification = await UserNotificationModel.create({
+    async function notificationCreator (user: MUserNotifSettingAccount) {
+      const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
         type: UserNotificationType.COMMENT_MENTION,
         userId: user.id,
         commentId: comment.id
       })
-      notification.Comment = comment as VideoCommentModel
+      notification.Comment = comment
 
       return notification
     }
@@ -231,7 +253,7 @@ class Notifier {
     return this.notify({ users, settingGetter, notificationCreator, emailSender })
   }
 
-  private async notifyUserOfNewActorFollow (actorFollow: MActorFollowFollowingFullFollowerAccount) {
+  private async notifyUserOfNewActorFollow (actorFollow: MActorFollowFull) {
     if (actorFollow.ActorFollowing.isOwned() === false) return
 
     // Account follows one of our account?
@@ -247,23 +269,23 @@ class Notifier {
     if (!user) return
 
     const followerAccount = actorFollow.ActorFollower.Account
+    const followerAccountWithActor = Object.assign(followerAccount, { Actor: actorFollow.ActorFollower })
 
-    const accountMuted = await AccountBlocklistModel.isAccountMutedBy(user.Account.id, followerAccount.id)
-    if (accountMuted) return
+    if (await this.isBlockedByServerOrUser(followerAccountWithActor, user)) return
 
     logger.info('Notifying user %s of new follower: %s.', user.username, followerAccount.getDisplayName())
 
-    function settingGetter (user: UserModel) {
+    function settingGetter (user: MUserWithNotificationSetting) {
       return user.NotificationSetting.newFollow
     }
 
-    async function notificationCreator (user: UserModel) {
-      const notification = await UserNotificationModel.create({
+    async function notificationCreator (user: MUserWithNotificationSetting) {
+      const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
         type: UserNotificationType.NEW_FOLLOW,
         userId: user.id,
         actorFollowId: actorFollow.id
       })
-      notification.ActorFollow = actorFollow as ActorFollowModel
+      notification.ActorFollow = actorFollow
 
       return notification
     }
@@ -275,22 +297,25 @@ class Notifier {
     return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
   }
 
-  private async notifyAdminsOfNewInstanceFollow (actorFollow: MActorFollowActors) {
+  private async notifyAdminsOfNewInstanceFollow (actorFollow: MActorFollowFull) {
     const admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW)
 
+    const follower = Object.assign(actorFollow.ActorFollower.Account, { Actor: actorFollow.ActorFollower })
+    if (await this.isBlockedByServerOrUser(follower)) return
+
     logger.info('Notifying %d administrators of new instance follower: %s.', admins.length, actorFollow.ActorFollower.url)
 
-    function settingGetter (user: UserModel) {
+    function settingGetter (user: MUserWithNotificationSetting) {
       return user.NotificationSetting.newInstanceFollower
     }
 
-    async function notificationCreator (user: UserModel) {
-      const notification = await UserNotificationModel.create({
+    async function notificationCreator (user: MUserWithNotificationSetting) {
+      const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
         type: UserNotificationType.NEW_INSTANCE_FOLLOWER,
         userId: user.id,
         actorFollowId: actorFollow.id
       })
-      notification.ActorFollow = actorFollow as ActorFollowModel
+      notification.ActorFollow = actorFollow
 
       return notification
     }
@@ -302,57 +327,88 @@ class Notifier {
     return this.notify({ users: admins, settingGetter, notificationCreator, emailSender })
   }
 
-  private async notifyModeratorsOfNewVideoAbuse (videoAbuse: MVideoAbuseVideo) {
+  private async notifyAdminsOfAutoInstanceFollowing (actorFollow: MActorFollowFull) {
+    const admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW)
+
+    logger.info('Notifying %d administrators of auto instance following: %s.', admins.length, actorFollow.ActorFollowing.url)
+
+    function settingGetter (user: MUserWithNotificationSetting) {
+      return user.NotificationSetting.autoInstanceFollowing
+    }
+
+    async function notificationCreator (user: MUserWithNotificationSetting) {
+      const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+        type: UserNotificationType.AUTO_INSTANCE_FOLLOWING,
+        userId: user.id,
+        actorFollowId: actorFollow.id
+      })
+      notification.ActorFollow = actorFollow
+
+      return notification
+    }
+
+    function emailSender (emails: string[]) {
+      return Emailer.Instance.addAutoInstanceFollowingNotification(emails, actorFollow)
+    }
+
+    return this.notify({ users: admins, settingGetter, notificationCreator, emailSender })
+  }
+
+  private async notifyModeratorsOfNewVideoAbuse (parameters: {
+    videoAbuse: VideoAbuse
+    videoAbuseInstance: MVideoAbuseVideo
+    reporter: string
+  }) {
     const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_ABUSES)
     if (moderators.length === 0) return
 
-    logger.info('Notifying %s user/moderators of new video abuse %s.', moderators.length, videoAbuse.Video.url)
+    logger.info('Notifying %s user/moderators of new video abuse %s.', moderators.length, parameters.videoAbuseInstance.Video.url)
 
-    function settingGetter (user: UserModel) {
+    function settingGetter (user: MUserWithNotificationSetting) {
       return user.NotificationSetting.videoAbuseAsModerator
     }
 
-    async function notificationCreator (user: UserModel) {
-      const notification: UserNotificationModelForApi = await UserNotificationModel.create({
+    async function notificationCreator (user: MUserWithNotificationSetting) {
+      const notification: UserNotificationModelForApi = await UserNotificationModel.create<UserNotificationModelForApi>({
         type: UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS,
         userId: user.id,
-        videoAbuseId: videoAbuse.id
+        videoAbuseId: parameters.videoAbuse.id
       })
-      notification.VideoAbuse = videoAbuse
+      notification.VideoAbuse = parameters.videoAbuseInstance
 
       return notification
     }
 
     function emailSender (emails: string[]) {
-      return Emailer.Instance.addVideoAbuseModeratorsNotification(emails, videoAbuse)
+      return Emailer.Instance.addVideoAbuseModeratorsNotification(emails, parameters)
     }
 
     return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender })
   }
 
-  private async notifyModeratorsOfVideoAutoBlacklist (video: MVideo) {
+  private async notifyModeratorsOfVideoAutoBlacklist (videoBlacklist: MVideoBlacklistLightVideo) {
     const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_BLACKLIST)
     if (moderators.length === 0) return
 
-    logger.info('Notifying %s moderators of video auto-blacklist %s.', moderators.length, video.url)
+    logger.info('Notifying %s moderators of video auto-blacklist %s.', moderators.length, videoBlacklist.Video.url)
 
-    function settingGetter (user: UserModel) {
+    function settingGetter (user: MUserWithNotificationSetting) {
       return user.NotificationSetting.videoAutoBlacklistAsModerator
     }
-    async function notificationCreator (user: UserModel) {
 
-      const notification = await UserNotificationModel.create({
+    async function notificationCreator (user: MUserWithNotificationSetting) {
+      const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
         type: UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS,
         userId: user.id,
-        videoId: video.id
+        videoBlacklistId: videoBlacklist.id
       })
-      notification.Video = video as VideoModel
+      notification.VideoBlacklist = videoBlacklist
 
       return notification
     }
 
     function emailSender (emails: string[]) {
-      return Emailer.Instance.addVideoAutoBlacklistModeratorsNotification(emails, video)
+      return Emailer.Instance.addVideoAutoBlacklistModeratorsNotification(emails, videoBlacklist)
     }
 
     return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender })
@@ -364,17 +420,17 @@ class Notifier {
 
     logger.info('Notifying user %s that its video %s has been blacklisted.', user.username, videoBlacklist.Video.url)
 
-    function settingGetter (user: UserModel) {
+    function settingGetter (user: MUserWithNotificationSetting) {
       return user.NotificationSetting.blacklistOnMyVideo
     }
 
-    async function notificationCreator (user: UserModel) {
-      const notification = await UserNotificationModel.create({
+    async function notificationCreator (user: MUserWithNotificationSetting) {
+      const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
         type: UserNotificationType.BLACKLIST_ON_MY_VIDEO,
         userId: user.id,
         videoBlacklistId: videoBlacklist.id
       })
-      notification.VideoBlacklist = videoBlacklist as VideoBlacklistModel
+      notification.VideoBlacklist = videoBlacklist
 
       return notification
     }
@@ -386,23 +442,23 @@ class Notifier {
     return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
   }
 
-  private async notifyVideoOwnerOfUnblacklist (video: MVideo) {
+  private async notifyVideoOwnerOfUnblacklist (video: MVideoFullLight) {
     const user = await UserModel.loadByVideoId(video.id)
     if (!user) return
 
     logger.info('Notifying user %s that its video %s has been unblacklisted.', user.username, video.url)
 
-    function settingGetter (user: UserModel) {
+    function settingGetter (user: MUserWithNotificationSetting) {
       return user.NotificationSetting.blacklistOnMyVideo
     }
 
-    async function notificationCreator (user: UserModel) {
-      const notification = await UserNotificationModel.create({
+    async function notificationCreator (user: MUserWithNotificationSetting) {
+      const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
         type: UserNotificationType.UNBLACKLIST_ON_MY_VIDEO,
         userId: user.id,
         videoId: video.id
       })
-      notification.Video = video as VideoModel
+      notification.Video = video
 
       return notification
     }
@@ -420,17 +476,17 @@ class Notifier {
 
     logger.info('Notifying user %s of the publication of its video %s.', user.username, video.url)
 
-    function settingGetter (user: UserModel) {
+    function settingGetter (user: MUserWithNotificationSetting) {
       return user.NotificationSetting.myVideoPublished
     }
 
-    async function notificationCreator (user: UserModel) {
-      const notification = await UserNotificationModel.create({
+    async function notificationCreator (user: MUserWithNotificationSetting) {
+      const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
         type: UserNotificationType.MY_VIDEO_PUBLISHED,
         userId: user.id,
         videoId: video.id
       })
-      notification.Video = video as VideoModel
+      notification.Video = video
 
       return notification
     }
@@ -448,17 +504,17 @@ class Notifier {
 
     logger.info('Notifying user %s its video import %s is finished.', user.username, videoImport.getTargetIdentifier())
 
-    function settingGetter (user: UserModel) {
+    function settingGetter (user: MUserWithNotificationSetting) {
       return user.NotificationSetting.myVideoImportFinished
     }
 
-    async function notificationCreator (user: UserModel) {
-      const notification = await UserNotificationModel.create({
+    async function notificationCreator (user: MUserWithNotificationSetting) {
+      const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
         type: success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR,
         userId: user.id,
         videoImportId: videoImport.id
       })
-      notification.VideoImport = videoImport as VideoImportModel
+      notification.VideoImport = videoImport
 
       return notification
     }
@@ -472,7 +528,7 @@ class Notifier {
     return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
   }
 
-  private async notifyModeratorsOfNewUserRegistration (registeredUser: MUserAccount) {
+  private async notifyModeratorsOfNewUserRegistration (registeredUser: MUserDefault) {
     const moderators = await UserModel.listWithRight(UserRight.MANAGE_USERS)
     if (moderators.length === 0) return
 
@@ -481,17 +537,17 @@ class Notifier {
       moderators.length, registeredUser.username
     )
 
-    function settingGetter (user: UserModel) {
+    function settingGetter (user: MUserWithNotificationSetting) {
       return user.NotificationSetting.newUserRegistration
     }
 
-    async function notificationCreator (user: UserModel) {
-      const notification = await UserNotificationModel.create({
+    async function notificationCreator (user: MUserWithNotificationSetting) {
+      const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
         type: UserNotificationType.NEW_USER_REGISTRATION,
         userId: user.id,
         accountId: registeredUser.Account.id
       })
-      notification.Account = registeredUser.Account as AccountModel
+      notification.Account = registeredUser.Account
 
       return notification
     }
@@ -503,11 +559,11 @@ class Notifier {
     return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender })
   }
 
-  private async notify (options: {
-    users: MUserWithNotificationSetting[],
-    notificationCreator: (user: MUserWithNotificationSetting) => Promise<UserNotificationModelForApi>,
-    emailSender: (emails: string[]) => Promise<any> | Bluebird<any>,
-    settingGetter: (user: MUserWithNotificationSetting) => UserNotificationSettingValue
+  private async notify<T extends MUserWithNotificationSetting> (options: {
+    users: T[]
+    notificationCreator: (user: T) => Promise<UserNotificationModelForApi>
+    emailSender: (emails: string[]) => void
+    settingGetter: (user: T) => UserNotificationSettingValue
   }) {
     const emails: string[] = []
 
@@ -524,7 +580,7 @@ class Notifier {
     }
 
     if (emails.length !== 0) {
-      await options.emailSender(emails)
+      options.emailSender(emails)
     }
   }
 
@@ -538,6 +594,10 @@ class Notifier {
     return value & UserNotificationSettingValue.WEB
   }
 
+  private isBlockedByServerOrUser (targetAccount: MAccountServer, user?: MUserAccount) {
+    return isBlockedByServerOrAccount(targetAccount, user?.Account)
+  }
+
   static get Instance () {
     return this.instance || (this.instance = new this())
   }