+ 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: MUserNotifSettingAccount) {
+ const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ type: UserNotificationType.COMMENT_MENTION,
+ userId: user.id,
+ commentId: comment.id
+ })
+ notification.Comment = comment
+
+ return notification
+ }
+
+ function emailSender (emails: string[]) {
+ return Emailer.Instance.addNewCommentMentionNotification(emails, comment)
+ }
+
+ return this.notify({ users, settingGetter, notificationCreator, emailSender })
+ }
+
+ private async notifyUserOfNewActorFollow (actorFollow: MActorFollowFull) {
+ 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 followerAccountWithActor = Object.assign(followerAccount, { Actor: actorFollow.ActorFollower })
+
+ if (await this.isBlockedByServerOrAccount(user, followerAccountWithActor)) return
+
+ logger.info('Notifying user %s of new follower: %s.', user.username, followerAccount.getDisplayName())
+
+ function settingGetter (user: MUserWithNotificationSetting) {
+ return user.NotificationSetting.newFollow
+ }
+
+ async function notificationCreator (user: MUserWithNotificationSetting) {
+ const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
+ type: UserNotificationType.NEW_FOLLOW,
+ userId: user.id,
+ actorFollowId: actorFollow.id
+ })
+ notification.ActorFollow = actorFollow
+
+ 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: MActorFollowFull) {
+ 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: MUserWithNotificationSetting) {
+ return user.NotificationSetting.newInstanceFollower
+ }
+
+ 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
+
+ return notification
+ }
+
+ function emailSender (emails: string[]) {
+ return Emailer.Instance.addNewInstanceFollowerNotification(emails, actorFollow)
+ }
+
+ return this.notify({ users: admins, settingGetter, notificationCreator, emailSender })
+ }
+
+ 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, parameters.videoAbuseInstance.Video.url)
+
+ function settingGetter (user: MUserWithNotificationSetting) {