1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Refactor notifier

This commit is contained in:
Chocobozzz 2021-07-30 16:51:27 +02:00
parent 2bee9db56a
commit d26836cd95
No known key found for this signature in database
GPG key ID: 583A612D890159BE
37 changed files with 1627 additions and 1231 deletions

View file

@ -0,0 +1,51 @@
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
}
async createNotification (user: MUserWithNotificationSetting) {
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
type: UserNotificationType.AUTO_INSTANCE_FOLLOWING,
userId: user.id,
actorFollowId: this.actorFollow.id
})
notification.ActorFollow = this.actorFollow
return notification
}
async createEmail (to: string) {
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
}
}