1 import { logger } from '@server/helpers/logger'
2 import { WEBSERVER } from '@server/initializers/constants'
3 import { isBlockedByServerOrAccount } from '@server/lib/blocklist'
4 import { UserModel } from '@server/models/user/user'
5 import { UserNotificationModel } from '@server/models/user/user-notification'
6 import { MActorFollowFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
7 import { UserNotificationType, UserRight } from '@shared/models'
8 import { AbstractNotification } from '../common/abstract-notification'
10 export class FollowForInstance extends AbstractNotification <MActorFollowFull> {
11 private admins: MUserDefault[]
14 this.admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW)
18 const follower = Object.assign(this.actorFollow.ActorFollower.Account, { Actor: this.actorFollow.ActorFollower })
20 return isBlockedByServerOrAccount(follower)
24 logger.info('Notifying %d administrators of new instance follower: %s.', this.admins.length, this.actorFollow.ActorFollower.url)
27 getSetting (user: MUserWithNotificationSetting) {
28 return user.NotificationSetting.newInstanceFollower
35 createNotification (user: MUserWithNotificationSetting) {
36 const notification = UserNotificationModel.build<UserNotificationModelForApi>({
37 type: UserNotificationType.NEW_INSTANCE_FOLLOWER,
39 actorFollowId: this.actorFollow.id
41 notification.ActorFollow = this.actorFollow
46 createEmail (to: string) {
47 const awaitingApproval = this.actorFollow.state === 'pending'
48 ? ' awaiting manual approval.'
53 subject: 'New instance follower',
54 text: `Your instance has a new follower: ${this.actorFollow.ActorFollower.url}${awaitingApproval}.`,
56 title: 'New instance follower',
58 text: 'Review followers',
59 url: WEBSERVER.URL + '/admin/follows/followers-list'
65 private get actorFollow () {