MUserNotifSettingAccount,
MUserWithNotificationSetting,
UserNotificationModelForApi
-} from '@server/typings/models/user'
-import { MVideoImportVideo } from '@server/typings/models/video/video-import'
+} from '@server/types/models/user'
+import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/models/video/video-blacklist'
+import { MVideoImportVideo } from '@server/types/models/video/video-import'
+import { Abuse } from '@shared/models'
import { UserNotificationSettingValue, UserNotificationType, UserRight } from '../../shared/models/users'
-import { VideoAbuse, VideoPrivacy, VideoState } from '../../shared/models/videos'
+import { VideoPrivacy, VideoState } from '../../shared/models/videos'
import { logger } from '../helpers/logger'
import { CONFIG } from '../initializers/config'
import { AccountBlocklistModel } from '../models/account/account-blocklist'
import { UserModel } from '../models/account/user'
import { UserNotificationModel } from '../models/account/user-notification'
-import { MAccountServer, MActorFollowFull } from '../typings/models'
-import {
- MCommentOwnerVideo,
- MVideoAbuseVideo,
- MVideoAccountLight,
- MVideoBlacklistLightVideo,
- MVideoBlacklistVideo,
- MVideoFullLight
-} from '../typings/models/video'
+import { MAbuseFull, MAbuseVideo, MAccountServer, MActorFollowFull } from '../types/models'
+import { MCommentOwnerVideo, MVideoAccountLight, MVideoFullLight } from '../types/models/video'
import { isBlockedByServerOrAccount } from './blocklist'
import { Emailer } from './emailer'
import { PeerTubeSocket } from './peertube-socket'
.catch(err => logger.error('Cannot notify mentions of comment %s.', comment.url, { err }))
}
- notifyOnNewVideoAbuse (parameters: { videoAbuse: VideoAbuse, videoAbuseInstance: MVideoAbuseVideo, reporter: string }): void {
- this.notifyModeratorsOfNewVideoAbuse(parameters)
- .catch(err => logger.error('Cannot notify of new video abuse of video %s.', parameters.videoAbuseInstance.Video.url, { err }))
+ notifyOnNewAbuse (parameters: { abuse: Abuse, abuseInstance: MAbuseFull, reporter: string }): void {
+ this.notifyModeratorsOfNewAbuse(parameters)
+ .catch(err => logger.error('Cannot notify of new abuse %d.', parameters.abuseInstance.id, { err }))
}
notifyOnVideoAutoBlacklist (videoBlacklist: MVideoBlacklistLightVideo): void {
return this.notify({ users: admins, settingGetter, notificationCreator, emailSender })
}
- private async notifyModeratorsOfNewVideoAbuse (parameters: {
- videoAbuse: VideoAbuse
- videoAbuseInstance: MVideoAbuseVideo
+ private async notifyModeratorsOfNewAbuse (parameters: {
+ abuse: Abuse
+ abuseInstance: MAbuseFull
reporter: string
}) {
- const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_ABUSES)
+ const { abuse, abuseInstance } = parameters
+
+ const moderators = await UserModel.listWithRight(UserRight.MANAGE_ABUSES)
if (moderators.length === 0) return
- logger.info('Notifying %s user/moderators of new video abuse %s.', moderators.length, parameters.videoAbuseInstance.Video.url)
+ const url = abuseInstance.VideoAbuse?.Video?.url || abuseInstance.VideoCommentAbuse?.VideoComment?.url
+
+ logger.info('Notifying %s user/moderators of new abuse %s.', moderators.length, url)
function settingGetter (user: MUserWithNotificationSetting) {
return user.NotificationSetting.videoAbuseAsModerator
}
async function notificationCreator (user: MUserWithNotificationSetting) {
- const notification: UserNotificationModelForApi = await UserNotificationModel.create<UserNotificationModelForApi>({
+ const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
type: UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS,
userId: user.id,
- videoAbuseId: parameters.videoAbuse.id
+ abuseId: abuse.id
})
- notification.VideoAbuse = parameters.videoAbuseInstance
+ notification.Abuse = abuseInstance
return notification
}
function emailSender (emails: string[]) {
- return Emailer.Instance.addVideoAbuseModeratorsNotification(emails, parameters)
+ return Emailer.Instance.addAbuseModeratorsNotification(emails, parameters)
}
return this.notify({ users: moderators, settingGetter, notificationCreator, emailSender })
}
private async notifyModeratorsOfVideoAutoBlacklist (videoBlacklist: MVideoBlacklistLightVideo) {
- const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_BLOCKS)
+ const moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_BLACKLIST)
if (moderators.length === 0) return
logger.info('Notifying %s moderators of video auto-blacklist %s.', moderators.length, videoBlacklist.Video.url)
async function notificationCreator (user: MUserWithNotificationSetting) {
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
- type: UserNotificationType.VIDEO_AUTO_BLOCK_FOR_MODERATORS,
+ type: UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS,
userId: user.id,
videoBlacklistId: videoBlacklist.id
})
async function notificationCreator (user: MUserWithNotificationSetting) {
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
- type: UserNotificationType.BLOCK_ON_MY_VIDEO,
+ type: UserNotificationType.BLACKLIST_ON_MY_VIDEO,
userId: user.id,
videoBlacklistId: videoBlacklist.id
})
async function notificationCreator (user: MUserWithNotificationSetting) {
const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
- type: UserNotificationType.UNBLOCK_ON_MY_VIDEO,
+ type: UserNotificationType.UNBLACKLIST_ON_MY_VIDEO,
userId: user.id,
videoId: video.id
})