1 import { logger } from '@server/helpers/logger'
2 import { UserModel } from '@server/models/user/user'
3 import { UserNotificationModel } from '@server/models/user/user-notification'
4 import { MActorFollowFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
5 import { UserNotificationType, UserRight } from '@shared/models'
6 import { AbstractNotification } from '../common/abstract-notification'
8 export class AutoFollowForInstance extends AbstractNotification <MActorFollowFull> {
9 private admins: MUserDefault[]
12 this.admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW)
16 logger.info('Notifying %d administrators of auto instance following: %s.', this.admins.length, this.actorFollow.ActorFollowing.url)
19 getSetting (user: MUserWithNotificationSetting) {
20 return user.NotificationSetting.autoInstanceFollowing
27 createNotification (user: MUserWithNotificationSetting) {
28 const notification = UserNotificationModel.build<UserNotificationModelForApi>({
29 type: UserNotificationType.AUTO_INSTANCE_FOLLOWING,
31 actorFollowId: this.actorFollow.id
33 notification.ActorFollow = this.actorFollow
38 createEmail (to: string) {
39 const instanceUrl = this.actorFollow.ActorFollowing.url
43 subject: 'Auto instance following',
44 text: `Your instance automatically followed a new instance: <a href="${instanceUrl}">${instanceUrl}</a>.`
48 private get actorFollow () {