mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
Add notification on new instance follower (server side)
This commit is contained in:
parent
0dc6477758
commit
883993c81e
19 changed files with 212 additions and 21 deletions
|
@ -92,18 +92,25 @@ class Notifier {
|
|||
.catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err }))
|
||||
}
|
||||
|
||||
notifyOfNewFollow (actorFollow: ActorFollowModel): void {
|
||||
notifyOfNewUserFollow (actorFollow: ActorFollowModel): void {
|
||||
this.notifyUserOfNewActorFollow(actorFollow)
|
||||
.catch(err => {
|
||||
logger.error(
|
||||
'Cannot notify owner of channel %s of a new follow by %s.',
|
||||
actorFollow.ActorFollowing.VideoChannel.getDisplayName(),
|
||||
actorFollow.ActorFollower.Account.getDisplayName(),
|
||||
err
|
||||
{ err }
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
notifyOfNewInstanceFollow (actorFollow: ActorFollowModel): void {
|
||||
this.notifyAdminsOfNewInstanceFollow(actorFollow)
|
||||
.catch(err => {
|
||||
logger.error('Cannot notify administrators of new follower %s.', actorFollow.ActorFollower.url, { err })
|
||||
})
|
||||
}
|
||||
|
||||
private async notifySubscribersOfNewVideo (video: VideoModel) {
|
||||
// List all followers that are users
|
||||
const users = await UserModel.listUserSubscribersOf(video.VideoChannel.actorId)
|
||||
|
@ -261,6 +268,33 @@ class Notifier {
|
|||
return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
|
||||
}
|
||||
|
||||
private async notifyAdminsOfNewInstanceFollow (actorFollow: ActorFollowModel) {
|
||||
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: UserModel) {
|
||||
return user.NotificationSetting.newInstanceFollower
|
||||
}
|
||||
|
||||
async function notificationCreator (user: UserModel) {
|
||||
const notification = await UserNotificationModel.create({
|
||||
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 notifyModeratorsOfNewVideoAbuse (videoAbuse: VideoAbuseModel) {
|
||||
const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_ABUSES)
|
||||
if (moderators.length === 0) return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue