PeerTube/server/lib/notifier/shared/follow/auto-follow-for-instance.ts

52 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-07-30 09:51:27 -05:00
import { logger } from '@server/helpers/logger'
import { UserModel } from '@server/models/user/user'
import { UserNotificationModel } from '@server/models/user/user-notification'
import { MActorFollowFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
import { UserNotificationType, UserRight } from '@shared/models'
import { AbstractNotification } from '../common/abstract-notification'
export class AutoFollowForInstance extends AbstractNotification <MActorFollowFull> {
private admins: MUserDefault[]
async prepare () {
this.admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW)
}
log () {
logger.info('Notifying %d administrators of auto instance following: %s.', this.admins.length, this.actorFollow.ActorFollowing.url)
}
getSetting (user: MUserWithNotificationSetting) {
return user.NotificationSetting.autoInstanceFollowing
}
getTargetUsers () {
return this.admins
}
2022-08-03 04:33:43 -05:00
createNotification (user: MUserWithNotificationSetting) {
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
2021-07-30 09:51:27 -05:00
type: UserNotificationType.AUTO_INSTANCE_FOLLOWING,
userId: user.id,
actorFollowId: this.actorFollow.id
})
notification.ActorFollow = this.actorFollow
return notification
}
2021-08-25 09:14:11 -05:00
createEmail (to: string) {
2021-07-30 09:51:27 -05:00
const instanceUrl = this.actorFollow.ActorFollowing.url
return {
to,
subject: 'Auto instance following',
text: `Your instance automatically followed a new instance: <a href="${instanceUrl}">${instanceUrl}</a>.`
}
}
private get actorFollow () {
return this.payload
}
}