2020-07-28 05:12:16 -04:00
|
|
|
import { AccountModel } from '@server/models/account/account'
|
2020-05-22 11:06:26 -04:00
|
|
|
import { getServerActor } from '@server/models/application/application'
|
|
|
|
import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
|
|
|
|
import {
|
|
|
|
MUser,
|
|
|
|
MUserAccount,
|
|
|
|
MUserDefault,
|
|
|
|
MUserNotifSettingAccount,
|
|
|
|
MUserWithNotificationSetting,
|
|
|
|
UserNotificationModelForApi
|
2020-06-18 04:45:25 -04:00
|
|
|
} from '@server/types/models/user'
|
2020-07-01 10:05:30 -04:00
|
|
|
import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/models/video/video-blacklist'
|
2020-06-18 04:45:25 -04:00
|
|
|
import { MVideoImportVideo } from '@server/types/models/video/video-import'
|
2020-07-24 09:05:51 -04:00
|
|
|
import { UserAbuse } from '@shared/models'
|
2018-12-26 04:36:24 -05:00
|
|
|
import { UserNotificationSettingValue, UserNotificationType, UserRight } from '../../shared/models/users'
|
2020-07-01 10:05:30 -04:00
|
|
|
import { VideoPrivacy, VideoState } from '../../shared/models/videos'
|
2018-12-26 04:36:24 -05:00
|
|
|
import { logger } from '../helpers/logger'
|
2019-04-11 05:33:44 -04:00
|
|
|
import { CONFIG } from '../initializers/config'
|
2019-01-02 10:37:43 -05:00
|
|
|
import { AccountBlocklistModel } from '../models/account/account-blocklist'
|
2021-05-11 05:15:29 -04:00
|
|
|
import { UserModel } from '../models/user/user'
|
|
|
|
import { UserNotificationModel } from '../models/user/user-notification'
|
2021-03-11 10:54:52 -05:00
|
|
|
import { MAbuseFull, MAbuseMessage, MAccountServer, MActorFollowFull, MApplication, MPlugin } from '../types/models'
|
2020-07-01 10:05:30 -04:00
|
|
|
import { MCommentOwnerVideo, MVideoAccountLight, MVideoFullLight } from '../types/models/video'
|
2020-05-22 11:06:26 -04:00
|
|
|
import { isBlockedByServerOrAccount } from './blocklist'
|
|
|
|
import { Emailer } from './emailer'
|
|
|
|
import { PeerTubeSocket } from './peertube-socket'
|
2018-12-26 04:36:24 -05:00
|
|
|
|
|
|
|
class Notifier {
|
|
|
|
|
|
|
|
private static instance: Notifier
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
private constructor () {
|
|
|
|
}
|
2018-12-26 04:36:24 -05:00
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
notifyOnNewVideoIfNeeded (video: MVideoAccountLight): void {
|
2019-04-02 05:26:47 -04:00
|
|
|
// Only notify on public and published videos which are not blacklisted
|
2019-07-23 06:04:15 -04:00
|
|
|
if (video.privacy !== VideoPrivacy.PUBLIC || video.state !== VideoState.PUBLISHED || video.isBlacklisted()) return
|
2018-12-26 04:36:24 -05:00
|
|
|
|
|
|
|
this.notifySubscribersOfNewVideo(video)
|
2020-01-31 10:56:52 -05:00
|
|
|
.catch(err => logger.error('Cannot notify subscribers of new video %s.', video.url, { err }))
|
2018-12-26 04:36:24 -05:00
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
notifyOnVideoPublishedAfterTranscoding (video: MVideoFullLight): void {
|
2019-04-02 05:26:47 -04:00
|
|
|
// don't notify if didn't wait for transcoding or video is still blacklisted/waiting for scheduled update
|
|
|
|
if (!video.waitTranscoding || video.VideoBlacklist || video.ScheduleVideoUpdate) return
|
2019-01-02 10:37:43 -05:00
|
|
|
|
|
|
|
this.notifyOwnedVideoHasBeenPublished(video)
|
2019-04-02 05:26:47 -04:00
|
|
|
.catch(err => logger.error('Cannot notify owner that its video %s has been published after transcoding.', video.url, { err }))
|
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
notifyOnVideoPublishedAfterScheduledUpdate (video: MVideoFullLight): void {
|
2019-04-02 05:26:47 -04:00
|
|
|
// don't notify if video is still blacklisted or waiting for transcoding
|
|
|
|
if (video.VideoBlacklist || (video.waitTranscoding && video.state !== VideoState.PUBLISHED)) return
|
|
|
|
|
|
|
|
this.notifyOwnedVideoHasBeenPublished(video)
|
|
|
|
.catch(err => logger.error('Cannot notify owner that its video %s has been published after scheduled update.', video.url, { err }))
|
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
notifyOnVideoPublishedAfterRemovedFromAutoBlacklist (video: MVideoFullLight): void {
|
2019-04-02 05:26:47 -04:00
|
|
|
// don't notify if video is still waiting for transcoding or scheduled update
|
|
|
|
if (video.ScheduleVideoUpdate || (video.waitTranscoding && video.state !== VideoState.PUBLISHED)) return
|
|
|
|
|
|
|
|
this.notifyOwnedVideoHasBeenPublished(video)
|
2020-01-31 10:56:52 -05:00
|
|
|
.catch(err => {
|
|
|
|
logger.error('Cannot notify owner that its video %s has been published after removed from auto-blacklist.', video.url, { err })
|
|
|
|
})
|
2019-01-02 10:37:43 -05:00
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
notifyOnNewComment (comment: MCommentOwnerVideo): void {
|
2018-12-26 04:36:24 -05:00
|
|
|
this.notifyVideoOwnerOfNewComment(comment)
|
2019-01-04 02:56:20 -05:00
|
|
|
.catch(err => logger.error('Cannot notify video owner of new comment %s.', comment.url, { err }))
|
|
|
|
|
|
|
|
this.notifyOfCommentMention(comment)
|
|
|
|
.catch(err => logger.error('Cannot notify mentions of comment %s.', comment.url, { err }))
|
2018-12-26 04:36:24 -05:00
|
|
|
}
|
|
|
|
|
2020-07-24 09:05:51 -04:00
|
|
|
notifyOnNewAbuse (parameters: { abuse: UserAbuse, abuseInstance: MAbuseFull, reporter: string }): void {
|
2020-07-01 10:05:30 -04:00
|
|
|
this.notifyModeratorsOfNewAbuse(parameters)
|
|
|
|
.catch(err => logger.error('Cannot notify of new abuse %d.', parameters.abuseInstance.id, { err }))
|
2018-12-26 04:36:24 -05:00
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
notifyOnVideoAutoBlacklist (videoBlacklist: MVideoBlacklistLightVideo): void {
|
|
|
|
this.notifyModeratorsOfVideoAutoBlacklist(videoBlacklist)
|
2020-01-31 10:56:52 -05:00
|
|
|
.catch(err => logger.error('Cannot notify of auto-blacklist of video %s.', videoBlacklist.Video.url, { err }))
|
2019-04-02 05:26:47 -04:00
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
notifyOnVideoBlacklist (videoBlacklist: MVideoBlacklistVideo): void {
|
2018-12-26 04:36:24 -05:00
|
|
|
this.notifyVideoOwnerOfBlacklist(videoBlacklist)
|
2020-01-31 10:56:52 -05:00
|
|
|
.catch(err => logger.error('Cannot notify video owner of new video blacklist of %s.', videoBlacklist.Video.url, { err }))
|
2018-12-26 04:36:24 -05:00
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
notifyOnVideoUnblacklist (video: MVideoFullLight): void {
|
2018-12-26 04:36:24 -05:00
|
|
|
this.notifyVideoOwnerOfUnblacklist(video)
|
2019-04-02 05:26:47 -04:00
|
|
|
.catch(err => logger.error('Cannot notify video owner of unblacklist of %s.', video.url, { err }))
|
2018-12-26 04:36:24 -05:00
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
notifyOnFinishedVideoImport (videoImport: MVideoImportVideo, success: boolean): void {
|
2019-01-02 10:37:43 -05:00
|
|
|
this.notifyOwnerVideoImportIsFinished(videoImport, success)
|
2020-01-31 10:56:52 -05:00
|
|
|
.catch(err => logger.error('Cannot notify owner that its video import %s is finished.', videoImport.getTargetIdentifier(), { err }))
|
2019-01-02 10:37:43 -05:00
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
notifyOnNewUserRegistration (user: MUserDefault): void {
|
2019-01-04 02:56:20 -05:00
|
|
|
this.notifyModeratorsOfNewUserRegistration(user)
|
|
|
|
.catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err }))
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
notifyOfNewUserFollow (actorFollow: MActorFollowFull): void {
|
2019-01-04 02:56:20 -05:00
|
|
|
this.notifyUserOfNewActorFollow(actorFollow)
|
2020-01-31 10:56:52 -05:00
|
|
|
.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 }
|
|
|
|
)
|
|
|
|
})
|
2019-01-04 02:56:20 -05:00
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
notifyOfNewInstanceFollow (actorFollow: MActorFollowFull): void {
|
2019-04-08 11:26:01 -04:00
|
|
|
this.notifyAdminsOfNewInstanceFollow(actorFollow)
|
|
|
|
.catch(err => {
|
|
|
|
logger.error('Cannot notify administrators of new follower %s.', actorFollow.ActorFollower.url, { err })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
notifyOfAutoInstanceFollowing (actorFollow: MActorFollowFull): void {
|
|
|
|
this.notifyAdminsOfAutoInstanceFollowing(actorFollow)
|
|
|
|
.catch(err => {
|
|
|
|
logger.error('Cannot notify administrators of auto instance following %s.', actorFollow.ActorFollowing.url, { err })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-27 10:26:25 -04:00
|
|
|
notifyOnAbuseStateChange (abuse: MAbuseFull): void {
|
|
|
|
this.notifyReporterOfAbuseStateChange(abuse)
|
|
|
|
.catch(err => {
|
|
|
|
logger.error('Cannot notify reporter of abuse %d state change.', abuse.id, { err })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-28 03:57:16 -04:00
|
|
|
notifyOnAbuseMessage (abuse: MAbuseFull, message: MAbuseMessage): void {
|
2020-07-27 10:26:25 -04:00
|
|
|
this.notifyOfNewAbuseMessage(abuse, message)
|
|
|
|
.catch(err => {
|
|
|
|
logger.error('Cannot notify on new abuse %d message.', abuse.id, { err })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-03-11 10:54:52 -05:00
|
|
|
notifyOfNewPeerTubeVersion (application: MApplication, latestVersion: string) {
|
|
|
|
this.notifyAdminsOfNewPeerTubeVersion(application, latestVersion)
|
|
|
|
.catch(err => {
|
|
|
|
logger.error('Cannot notify on new PeerTubeb version %s.', latestVersion, { err })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
notifyOfNewPluginVersion (plugin: MPlugin) {
|
|
|
|
this.notifyAdminsOfNewPluginVersion(plugin)
|
|
|
|
.catch(err => {
|
|
|
|
logger.error('Cannot notify on new plugin version %s.', plugin.name, { err })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
private async notifySubscribersOfNewVideo (video: MVideoAccountLight) {
|
2018-12-26 04:36:24 -05:00
|
|
|
// List all followers that are users
|
|
|
|
const users = await UserModel.listUserSubscribersOf(video.VideoChannel.actorId)
|
|
|
|
|
|
|
|
logger.info('Notifying %d users of new video %s.', users.length, video.url)
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
2018-12-26 04:36:24 -05:00
|
|
|
return user.NotificationSetting.newVideoFromSubscription
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
2018-12-26 04:36:24 -05:00
|
|
|
type: UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION,
|
|
|
|
userId: user.id,
|
|
|
|
videoId: video.id
|
|
|
|
})
|
2019-08-30 10:50:12 -04:00
|
|
|
notification.Video = video
|
2018-12-26 04:36:24 -05:00
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.addNewVideoFromSubscriberNotification(emails, video)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users, settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
private async notifyVideoOwnerOfNewComment (comment: MCommentOwnerVideo) {
|
2019-01-04 02:56:20 -05:00
|
|
|
if (comment.Video.isOwned() === false) return
|
|
|
|
|
2018-12-26 04:36:24 -05:00
|
|
|
const user = await UserModel.loadByVideoId(comment.videoId)
|
|
|
|
|
|
|
|
// Not our user or user comments its own video
|
|
|
|
if (!user || comment.Account.userId === user.id) return
|
|
|
|
|
2020-05-22 11:06:26 -04:00
|
|
|
if (await this.isBlockedByServerOrUser(comment.Account, user)) return
|
2019-01-02 10:37:43 -05:00
|
|
|
|
2018-12-26 04:36:24 -05:00
|
|
|
logger.info('Notifying user %s of new comment %s.', user.username, comment.url)
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
2018-12-26 04:36:24 -05:00
|
|
|
return user.NotificationSetting.newCommentOnMyVideo
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
2018-12-26 04:36:24 -05:00
|
|
|
type: UserNotificationType.NEW_COMMENT_ON_MY_VIDEO,
|
|
|
|
userId: user.id,
|
|
|
|
commentId: comment.id
|
|
|
|
})
|
2019-08-30 10:50:12 -04:00
|
|
|
notification.Comment = comment
|
2018-12-26 04:36:24 -05:00
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.addNewCommentOnMyVideoNotification(emails, comment)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
private async notifyOfCommentMention (comment: MCommentOwnerVideo) {
|
2019-02-15 09:52:18 -05:00
|
|
|
const extractedUsernames = comment.extractMentions()
|
|
|
|
logger.debug(
|
|
|
|
'Extracted %d username from comment %s.', extractedUsernames.length, comment.url,
|
|
|
|
{ usernames: extractedUsernames, text: comment.text }
|
|
|
|
)
|
2019-02-14 05:04:50 -05:00
|
|
|
|
2019-02-15 09:52:18 -05:00
|
|
|
let users = await UserModel.listByUsernames(extractedUsernames)
|
2019-01-04 02:56:20 -05:00
|
|
|
|
|
|
|
if (comment.Video.isOwned()) {
|
|
|
|
const userException = await UserModel.loadByVideoId(comment.videoId)
|
|
|
|
users = users.filter(u => u.id !== userException.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't notify if I mentioned myself
|
|
|
|
users = users.filter(u => u.Account.id !== comment.accountId)
|
|
|
|
|
2018-12-26 04:36:24 -05:00
|
|
|
if (users.length === 0) return
|
|
|
|
|
2019-12-19 04:35:47 -05:00
|
|
|
const serverAccountId = (await getServerActor()).Account.id
|
|
|
|
const sourceAccounts = users.map(u => u.Account.id).concat([ serverAccountId ])
|
|
|
|
|
|
|
|
const accountMutedHash = await AccountBlocklistModel.isAccountMutedByMulti(sourceAccounts, comment.accountId)
|
|
|
|
const instanceMutedHash = await ServerBlocklistModel.isServerMutedByMulti(sourceAccounts, comment.Account.Actor.serverId)
|
2019-01-04 02:56:20 -05:00
|
|
|
|
|
|
|
logger.info('Notifying %d users of new comment %s.', users.length, comment.url)
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
function settingGetter (user: MUserNotifSettingAccount) {
|
2019-12-19 04:35:47 -05:00
|
|
|
const accountId = user.Account.id
|
|
|
|
if (
|
|
|
|
accountMutedHash[accountId] === true || instanceMutedHash[accountId] === true ||
|
|
|
|
accountMutedHash[serverAccountId] === true || instanceMutedHash[serverAccountId] === true
|
|
|
|
) {
|
|
|
|
return UserNotificationSettingValue.NONE
|
|
|
|
}
|
2019-01-04 02:56:20 -05:00
|
|
|
|
|
|
|
return user.NotificationSetting.commentMention
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
async function notificationCreator (user: MUserNotifSettingAccount) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
2019-01-04 02:56:20 -05:00
|
|
|
type: UserNotificationType.COMMENT_MENTION,
|
|
|
|
userId: user.id,
|
|
|
|
commentId: comment.id
|
|
|
|
})
|
2019-08-30 10:50:12 -04:00
|
|
|
notification.Comment = comment
|
2019-01-04 02:56:20 -05:00
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.addNewCommentMentionNotification(emails, comment)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users, settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
private async notifyUserOfNewActorFollow (actorFollow: MActorFollowFull) {
|
2019-01-04 02:56:20 -05:00
|
|
|
if (actorFollow.ActorFollowing.isOwned() === false) return
|
|
|
|
|
|
|
|
// Account follows one of our account?
|
|
|
|
let followType: 'account' | 'channel' = 'channel'
|
|
|
|
let user = await UserModel.loadByChannelActorId(actorFollow.ActorFollowing.id)
|
|
|
|
|
|
|
|
// Account follows one of our channel?
|
|
|
|
if (!user) {
|
|
|
|
user = await UserModel.loadByAccountActorId(actorFollow.ActorFollowing.id)
|
|
|
|
followType = 'account'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!user) return
|
|
|
|
|
|
|
|
const followerAccount = actorFollow.ActorFollower.Account
|
2019-12-19 04:35:47 -05:00
|
|
|
const followerAccountWithActor = Object.assign(followerAccount, { Actor: actorFollow.ActorFollower })
|
2019-01-04 02:56:20 -05:00
|
|
|
|
2020-05-22 11:06:26 -04:00
|
|
|
if (await this.isBlockedByServerOrUser(followerAccountWithActor, user)) return
|
2019-01-04 02:56:20 -05:00
|
|
|
|
|
|
|
logger.info('Notifying user %s of new follower: %s.', user.username, followerAccount.getDisplayName())
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
2019-01-04 02:56:20 -05:00
|
|
|
return user.NotificationSetting.newFollow
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
2019-01-04 02:56:20 -05:00
|
|
|
type: UserNotificationType.NEW_FOLLOW,
|
|
|
|
userId: user.id,
|
|
|
|
actorFollowId: actorFollow.id
|
|
|
|
})
|
2019-08-30 10:50:12 -04:00
|
|
|
notification.ActorFollow = actorFollow
|
2019-01-04 02:56:20 -05:00
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.addNewFollowNotification(emails, actorFollow, followType)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
private async notifyAdminsOfNewInstanceFollow (actorFollow: MActorFollowFull) {
|
2019-04-08 11:26:01 -04:00
|
|
|
const admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW)
|
|
|
|
|
2020-05-22 11:06:26 -04:00
|
|
|
const follower = Object.assign(actorFollow.ActorFollower.Account, { Actor: actorFollow.ActorFollower })
|
|
|
|
if (await this.isBlockedByServerOrUser(follower)) return
|
|
|
|
|
2019-04-08 11:26:01 -04:00
|
|
|
logger.info('Notifying %d administrators of new instance follower: %s.', admins.length, actorFollow.ActorFollower.url)
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
2019-04-08 11:26:01 -04:00
|
|
|
return user.NotificationSetting.newInstanceFollower
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
2019-04-08 11:26:01 -04:00
|
|
|
type: UserNotificationType.NEW_INSTANCE_FOLLOWER,
|
|
|
|
userId: user.id,
|
|
|
|
actorFollowId: actorFollow.id
|
|
|
|
})
|
2019-08-30 10:50:12 -04:00
|
|
|
notification.ActorFollow = actorFollow
|
2019-04-08 11:26:01 -04:00
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.addNewInstanceFollowerNotification(emails, actorFollow)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: admins, settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
private async notifyAdminsOfAutoInstanceFollowing (actorFollow: MActorFollowFull) {
|
|
|
|
const admins = await UserModel.listWithRight(UserRight.MANAGE_SERVER_FOLLOW)
|
|
|
|
|
|
|
|
logger.info('Notifying %d administrators of auto instance following: %s.', admins.length, actorFollow.ActorFollowing.url)
|
|
|
|
|
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
|
|
|
return user.NotificationSetting.autoInstanceFollowing
|
|
|
|
}
|
|
|
|
|
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
|
|
|
type: UserNotificationType.AUTO_INSTANCE_FOLLOWING,
|
|
|
|
userId: user.id,
|
|
|
|
actorFollowId: actorFollow.id
|
|
|
|
})
|
|
|
|
notification.ActorFollow = actorFollow
|
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.addAutoInstanceFollowingNotification(emails, actorFollow)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: admins, settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2020-07-01 10:05:30 -04:00
|
|
|
private async notifyModeratorsOfNewAbuse (parameters: {
|
2020-07-24 09:05:51 -04:00
|
|
|
abuse: UserAbuse
|
2020-07-01 10:05:30 -04:00
|
|
|
abuseInstance: MAbuseFull
|
2020-05-05 14:22:22 -04:00
|
|
|
reporter: string
|
|
|
|
}) {
|
2020-07-01 10:05:30 -04:00
|
|
|
const { abuse, abuseInstance } = parameters
|
|
|
|
|
|
|
|
const moderators = await UserModel.listWithRight(UserRight.MANAGE_ABUSES)
|
2019-01-04 02:56:20 -05:00
|
|
|
if (moderators.length === 0) return
|
|
|
|
|
2020-07-27 10:26:25 -04:00
|
|
|
const url = this.getAbuseUrl(abuseInstance)
|
2020-07-01 10:05:30 -04:00
|
|
|
|
|
|
|
logger.info('Notifying %s user/moderators of new abuse %s.', moderators.length, url)
|
2018-12-26 04:36:24 -05:00
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
2020-07-07 08:34:16 -04:00
|
|
|
return user.NotificationSetting.abuseAsModerator
|
2018-12-26 04:36:24 -05:00
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
2020-07-01 10:05:30 -04:00
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
2020-07-08 09:51:46 -04:00
|
|
|
type: UserNotificationType.NEW_ABUSE_FOR_MODERATORS,
|
2018-12-26 04:36:24 -05:00
|
|
|
userId: user.id,
|
2020-07-01 10:05:30 -04:00
|
|
|
abuseId: abuse.id
|
2018-12-26 04:36:24 -05:00
|
|
|
})
|
2020-07-01 10:05:30 -04:00
|
|
|
notification.Abuse = abuseInstance
|
2018-12-26 04:36:24 -05:00
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
2020-07-01 10:05:30 -04:00
|
|
|
return Emailer.Instance.addAbuseModeratorsNotification(emails, parameters)
|
2018-12-26 04:36:24 -05:00
|
|
|
}
|
|
|
|
|
2019-01-04 02:56:20 -05:00
|
|
|
return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender })
|
2018-12-26 04:36:24 -05:00
|
|
|
}
|
|
|
|
|
2020-07-27 10:26:25 -04:00
|
|
|
private async notifyReporterOfAbuseStateChange (abuse: MAbuseFull) {
|
|
|
|
// Only notify our users
|
|
|
|
if (abuse.ReporterAccount.isOwned() !== true) return
|
|
|
|
|
|
|
|
const url = this.getAbuseUrl(abuse)
|
|
|
|
|
|
|
|
logger.info('Notifying reporter of abuse % of state change.', url)
|
|
|
|
|
|
|
|
const reporter = await UserModel.loadByAccountActorId(abuse.ReporterAccount.actorId)
|
|
|
|
|
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
|
|
|
return user.NotificationSetting.abuseStateChange
|
|
|
|
}
|
|
|
|
|
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
|
|
|
type: UserNotificationType.ABUSE_STATE_CHANGE,
|
|
|
|
userId: user.id,
|
|
|
|
abuseId: abuse.id
|
|
|
|
})
|
|
|
|
notification.Abuse = abuse
|
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.addAbuseStateChangeNotification(emails, abuse)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: [ reporter ], settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
|
|
|
private async notifyOfNewAbuseMessage (abuse: MAbuseFull, message: MAbuseMessage) {
|
|
|
|
const url = this.getAbuseUrl(abuse)
|
|
|
|
logger.info('Notifying reporter and moderators of new abuse message on %s.', url)
|
|
|
|
|
2020-07-28 03:57:16 -04:00
|
|
|
const accountMessage = await AccountModel.load(message.accountId)
|
|
|
|
|
2020-07-27 10:26:25 -04:00
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
|
|
|
return user.NotificationSetting.abuseNewMessage
|
|
|
|
}
|
|
|
|
|
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
|
|
|
type: UserNotificationType.ABUSE_NEW_MESSAGE,
|
|
|
|
userId: user.id,
|
|
|
|
abuseId: abuse.id
|
|
|
|
})
|
|
|
|
notification.Abuse = abuse
|
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSenderReporter (emails: string[]) {
|
2020-07-28 03:57:16 -04:00
|
|
|
return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'reporter', abuse, message, accountMessage })
|
2020-07-27 10:26:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function emailSenderModerators (emails: string[]) {
|
2020-07-28 03:57:16 -04:00
|
|
|
return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'moderator', abuse, message, accountMessage })
|
2020-07-27 10:26:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function buildReporterOptions () {
|
|
|
|
// Only notify our users
|
2020-12-14 03:34:12 -05:00
|
|
|
if (abuse.ReporterAccount.isOwned() !== true) return undefined
|
2020-07-27 10:26:25 -04:00
|
|
|
|
|
|
|
const reporter = await UserModel.loadByAccountActorId(abuse.ReporterAccount.actorId)
|
|
|
|
// Don't notify my own message
|
2020-12-14 03:34:12 -05:00
|
|
|
if (reporter.Account.id === message.accountId) return undefined
|
2020-07-27 10:26:25 -04:00
|
|
|
|
|
|
|
return { users: [ reporter ], settingGetter, notificationCreator, emailSender: emailSenderReporter }
|
|
|
|
}
|
|
|
|
|
|
|
|
async function buildModeratorsOptions () {
|
|
|
|
let moderators = await UserModel.listWithRight(UserRight.MANAGE_ABUSES)
|
|
|
|
// Don't notify my own message
|
|
|
|
moderators = moderators.filter(m => m.Account.id !== message.accountId)
|
|
|
|
|
2020-12-14 03:34:12 -05:00
|
|
|
if (moderators.length === 0) return undefined
|
2020-07-27 10:26:25 -04:00
|
|
|
|
|
|
|
return { users: moderators, settingGetter, notificationCreator, emailSender: emailSenderModerators }
|
|
|
|
}
|
|
|
|
|
2020-12-11 00:53:30 -05:00
|
|
|
const options = await Promise.all([
|
2020-07-27 10:26:25 -04:00
|
|
|
buildReporterOptions(),
|
|
|
|
buildModeratorsOptions()
|
|
|
|
])
|
|
|
|
|
2020-12-11 00:53:30 -05:00
|
|
|
return Promise.all(
|
|
|
|
options
|
2020-12-14 03:34:12 -05:00
|
|
|
.filter(opt => !!opt)
|
|
|
|
.map(opt => this.notify(opt))
|
2020-12-11 00:53:30 -05:00
|
|
|
)
|
2020-07-27 10:26:25 -04:00
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
private async notifyModeratorsOfVideoAutoBlacklist (videoBlacklist: MVideoBlacklistLightVideo) {
|
2019-04-02 05:26:47 -04:00
|
|
|
const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_BLACKLIST)
|
|
|
|
if (moderators.length === 0) return
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
logger.info('Notifying %s moderators of video auto-blacklist %s.', moderators.length, videoBlacklist.Video.url)
|
2019-04-02 05:26:47 -04:00
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
2019-04-02 05:26:47 -04:00
|
|
|
return user.NotificationSetting.videoAutoBlacklistAsModerator
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
2019-04-02 05:26:47 -04:00
|
|
|
type: UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS,
|
|
|
|
userId: user.id,
|
2019-08-30 10:50:12 -04:00
|
|
|
videoBlacklistId: videoBlacklist.id
|
2019-04-02 05:26:47 -04:00
|
|
|
})
|
2019-08-30 10:50:12 -04:00
|
|
|
notification.VideoBlacklist = videoBlacklist
|
2019-04-02 05:26:47 -04:00
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
2019-08-30 10:50:12 -04:00
|
|
|
return Emailer.Instance.addVideoAutoBlacklistModeratorsNotification(emails, videoBlacklist)
|
2019-04-02 05:26:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
private async notifyVideoOwnerOfBlacklist (videoBlacklist: MVideoBlacklistVideo) {
|
2018-12-26 04:36:24 -05:00
|
|
|
const user = await UserModel.loadByVideoId(videoBlacklist.videoId)
|
|
|
|
if (!user) return
|
|
|
|
|
|
|
|
logger.info('Notifying user %s that its video %s has been blacklisted.', user.username, videoBlacklist.Video.url)
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
2018-12-26 04:36:24 -05:00
|
|
|
return user.NotificationSetting.blacklistOnMyVideo
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
2018-12-26 04:36:24 -05:00
|
|
|
type: UserNotificationType.BLACKLIST_ON_MY_VIDEO,
|
|
|
|
userId: user.id,
|
|
|
|
videoBlacklistId: videoBlacklist.id
|
|
|
|
})
|
2019-08-30 10:50:12 -04:00
|
|
|
notification.VideoBlacklist = videoBlacklist
|
2018-12-26 04:36:24 -05:00
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.addVideoBlacklistNotification(emails, videoBlacklist)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
private async notifyVideoOwnerOfUnblacklist (video: MVideoFullLight) {
|
2018-12-26 04:36:24 -05:00
|
|
|
const user = await UserModel.loadByVideoId(video.id)
|
|
|
|
if (!user) return
|
|
|
|
|
|
|
|
logger.info('Notifying user %s that its video %s has been unblacklisted.', user.username, video.url)
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
2018-12-26 04:36:24 -05:00
|
|
|
return user.NotificationSetting.blacklistOnMyVideo
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
2018-12-26 04:36:24 -05:00
|
|
|
type: UserNotificationType.UNBLACKLIST_ON_MY_VIDEO,
|
|
|
|
userId: user.id,
|
|
|
|
videoId: video.id
|
|
|
|
})
|
2019-08-30 10:50:12 -04:00
|
|
|
notification.Video = video
|
2018-12-26 04:36:24 -05:00
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.addVideoUnblacklistNotification(emails, video)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
private async notifyOwnedVideoHasBeenPublished (video: MVideoFullLight) {
|
2019-01-02 10:37:43 -05:00
|
|
|
const user = await UserModel.loadByVideoId(video.id)
|
|
|
|
if (!user) return
|
|
|
|
|
|
|
|
logger.info('Notifying user %s of the publication of its video %s.', user.username, video.url)
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
2019-01-02 10:37:43 -05:00
|
|
|
return user.NotificationSetting.myVideoPublished
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
2019-01-02 10:37:43 -05:00
|
|
|
type: UserNotificationType.MY_VIDEO_PUBLISHED,
|
|
|
|
userId: user.id,
|
|
|
|
videoId: video.id
|
|
|
|
})
|
2019-08-30 10:50:12 -04:00
|
|
|
notification.Video = video
|
2019-01-02 10:37:43 -05:00
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.myVideoPublishedNotification(emails, video)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
private async notifyOwnerVideoImportIsFinished (videoImport: MVideoImportVideo, success: boolean) {
|
2019-01-02 10:37:43 -05:00
|
|
|
const user = await UserModel.loadByVideoImportId(videoImport.id)
|
|
|
|
if (!user) return
|
|
|
|
|
|
|
|
logger.info('Notifying user %s its video import %s is finished.', user.username, videoImport.getTargetIdentifier())
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
2019-01-02 10:37:43 -05:00
|
|
|
return user.NotificationSetting.myVideoImportFinished
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
2019-01-02 10:37:43 -05:00
|
|
|
type: success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR,
|
|
|
|
userId: user.id,
|
|
|
|
videoImportId: videoImport.id
|
|
|
|
})
|
2019-08-30 10:50:12 -04:00
|
|
|
notification.VideoImport = videoImport
|
2019-01-02 10:37:43 -05:00
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return success
|
|
|
|
? Emailer.Instance.myVideoImportSuccessNotification(emails, videoImport)
|
|
|
|
: Emailer.Instance.myVideoImportErrorNotification(emails, videoImport)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: [ user ], settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
private async notifyModeratorsOfNewUserRegistration (registeredUser: MUserDefault) {
|
2019-01-04 02:56:20 -05:00
|
|
|
const moderators = await UserModel.listWithRight(UserRight.MANAGE_USERS)
|
|
|
|
if (moderators.length === 0) return
|
|
|
|
|
|
|
|
logger.info(
|
|
|
|
'Notifying %s moderators of new user registration of %s.',
|
2019-08-15 05:53:26 -04:00
|
|
|
moderators.length, registeredUser.username
|
2019-01-04 02:56:20 -05:00
|
|
|
)
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
2019-01-04 02:56:20 -05:00
|
|
|
return user.NotificationSetting.newUserRegistration
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:50:12 -04:00
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
2019-01-04 02:56:20 -05:00
|
|
|
type: UserNotificationType.NEW_USER_REGISTRATION,
|
|
|
|
userId: user.id,
|
|
|
|
accountId: registeredUser.Account.id
|
|
|
|
})
|
2019-08-30 10:50:12 -04:00
|
|
|
notification.Account = registeredUser.Account
|
2019-01-04 02:56:20 -05:00
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.addNewUserRegistrationNotification(emails, registeredUser)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2021-03-11 10:54:52 -05:00
|
|
|
private async notifyAdminsOfNewPeerTubeVersion (application: MApplication, latestVersion: string) {
|
|
|
|
// Use the debug right to know who is an administrator
|
|
|
|
const admins = await UserModel.listWithRight(UserRight.MANAGE_DEBUG)
|
|
|
|
if (admins.length === 0) return
|
|
|
|
|
|
|
|
logger.info('Notifying %s admins of new PeerTube version %s.', admins.length, latestVersion)
|
|
|
|
|
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
|
|
|
return user.NotificationSetting.newPeerTubeVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
|
|
|
type: UserNotificationType.NEW_PEERTUBE_VERSION,
|
|
|
|
userId: user.id,
|
|
|
|
applicationId: application.id
|
|
|
|
})
|
|
|
|
notification.Application = application
|
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.addNewPeerTubeVersionNotification(emails, latestVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: admins, settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
|
|
|
private async notifyAdminsOfNewPluginVersion (plugin: MPlugin) {
|
|
|
|
// Use the debug right to know who is an administrator
|
|
|
|
const admins = await UserModel.listWithRight(UserRight.MANAGE_DEBUG)
|
|
|
|
if (admins.length === 0) return
|
|
|
|
|
|
|
|
logger.info('Notifying %s admins of new plugin version %s@%s.', admins.length, plugin.name, plugin.latestVersion)
|
|
|
|
|
|
|
|
function settingGetter (user: MUserWithNotificationSetting) {
|
|
|
|
return user.NotificationSetting.newPluginVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
async function notificationCreator (user: MUserWithNotificationSetting) {
|
|
|
|
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
|
|
|
|
type: UserNotificationType.NEW_PLUGIN_VERSION,
|
|
|
|
userId: user.id,
|
|
|
|
pluginId: plugin.id
|
|
|
|
})
|
|
|
|
notification.Plugin = plugin
|
|
|
|
|
|
|
|
return notification
|
|
|
|
}
|
|
|
|
|
|
|
|
function emailSender (emails: string[]) {
|
|
|
|
return Emailer.Instance.addNewPlugionVersionNotification(emails, plugin)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.notify({ users: admins, settingGetter, notificationCreator, emailSender })
|
|
|
|
}
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
private async notify<T extends MUserWithNotificationSetting> (options: {
|
|
|
|
users: T[]
|
|
|
|
notificationCreator: (user: T) => Promise<UserNotificationModelForApi>
|
|
|
|
emailSender: (emails: string[]) => void
|
2019-08-30 10:50:12 -04:00
|
|
|
settingGetter: (user: T) => UserNotificationSettingValue
|
2018-12-26 04:36:24 -05:00
|
|
|
}) {
|
|
|
|
const emails: string[] = []
|
|
|
|
|
|
|
|
for (const user of options.users) {
|
|
|
|
if (this.isWebNotificationEnabled(options.settingGetter(user))) {
|
|
|
|
const notification = await options.notificationCreator(user)
|
|
|
|
|
|
|
|
PeerTubeSocket.Instance.sendNotification(user.id, notification)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isEmailEnabled(user, options.settingGetter(user))) {
|
|
|
|
emails.push(user.email)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (emails.length !== 0) {
|
2020-01-31 10:56:52 -05:00
|
|
|
options.emailSender(emails)
|
2018-12-26 04:36:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
private isEmailEnabled (user: MUser, value: UserNotificationSettingValue) {
|
2019-03-19 11:41:41 -04:00
|
|
|
if (CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION === true && user.emailVerified === false) return false
|
2018-12-26 04:36:24 -05:00
|
|
|
|
2019-01-08 05:26:41 -05:00
|
|
|
return value & UserNotificationSettingValue.EMAIL
|
2018-12-26 04:36:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private isWebNotificationEnabled (value: UserNotificationSettingValue) {
|
2019-01-08 05:26:41 -05:00
|
|
|
return value & UserNotificationSettingValue.WEB
|
2018-12-26 04:36:24 -05:00
|
|
|
}
|
|
|
|
|
2020-05-22 11:06:26 -04:00
|
|
|
private isBlockedByServerOrUser (targetAccount: MAccountServer, user?: MUserAccount) {
|
|
|
|
return isBlockedByServerOrAccount(targetAccount, user?.Account)
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
|
2020-07-27 10:26:25 -04:00
|
|
|
private getAbuseUrl (abuse: MAbuseFull) {
|
|
|
|
return abuse.VideoAbuse?.Video?.url ||
|
|
|
|
abuse.VideoCommentAbuse?.VideoComment?.url ||
|
|
|
|
abuse.FlaggedAccount.Actor.url
|
|
|
|
}
|
|
|
|
|
2018-12-26 04:36:24 -05:00
|
|
|
static get Instance () {
|
|
|
|
return this.instance || (this.instance = new this())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
Notifier
|
|
|
|
}
|