+ if (accountMutedHash[user.Account.id] === true) return UserNotificationSettingValue.NONE
+
+ return user.NotificationSetting.commentMention
+ }
+
+ async function notificationCreator (user: UserModel) {
+ const notification = await UserNotificationModel.create({
+ type: UserNotificationType.COMMENT_MENTION,
+ userId: user.id,
+ commentId: comment.id
+ })
+ notification.Comment = comment as VideoCommentModel
+
+ return notification
+ }
+
+ function emailSender (emails: string[]) {
+ return Emailer.Instance.addNewCommentMentionNotification(emails, comment)
+ }
+
+ return this.notify({ users, settingGetter, notificationCreator, emailSender })
+ }
+
+ private async notifyUserOfNewActorFollow (actorFollow: MActorFollowFollowingFullFollowerAccount) {
+ if (actorFollow.ActorFollowing.isOwned() === false) return
+
+ // Account follows one of our account?
+ let followType: 'account' | 'channel' = 'channel'
+ let user = await UserModel.loadByChannelActorId(actorFollow.ActorFollowing.id)
+
+ // Account follows one of our channel?
+ if (!user) {
+ user = await UserModel.loadByAccountActorId(actorFollow.ActorFollowing.id)
+ followType = 'account'
+ }
+
+ if (!user) return
+
+ const followerAccount = actorFollow.ActorFollower.Account
+
+ const accountMuted = await AccountBlocklistModel.isAccountMutedBy(user.Account.id, followerAccount.id)
+ if (accountMuted) return
+
+ logger.info('Notifying user %s of new follower: %s.', user.username, followerAccount.getDisplayName())
+
+ function settingGetter (user: UserModel) {
+ return user.NotificationSetting.newFollow
+ }
+
+ async function notificationCreator (user: UserModel) {
+ const notification = await UserNotificationModel.create({
+ type: UserNotificationType.NEW_FOLLOW,
+ userId: user.id,
+ actorFollowId: actorFollow.id
+ })
+ notification.ActorFollow = actorFollow as ActorFollowModel
+
+ return notification
+ }
+
+ function emailSender (emails: string[]) {
+ return Emailer.Instance.addNewFollowNotification(emails, actorFollow, followType)
+ }
+
+ return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
+ }
+
+ private async notifyAdminsOfNewInstanceFollow (actorFollow: MActorFollowActors) {
+ const admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW)
+
+ logger.info('Notifying %d administrators of new instance follower: %s.', admins.length, actorFollow.ActorFollower.url)
+
+ function settingGetter (user: UserModel) {
+ return user.NotificationSetting.newInstanceFollower