From 594d3e48d8a887bbf48ce4cc594c1c36c9640fb1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 27 Jul 2020 16:26:25 +0200 Subject: Add abuse messages/states notifications --- server/models/abuse/abuse.ts | 54 ++++++++++++++++++++-- server/models/account/user-notification-setting.ts | 30 ++++++++++-- server/models/account/user-notification.ts | 3 +- server/models/video/video-comment.ts | 2 +- 4 files changed, 78 insertions(+), 11 deletions(-) (limited to 'server/models') diff --git a/server/models/abuse/abuse.ts b/server/models/abuse/abuse.ts index 3353e9e41..1b599db62 100644 --- a/server/models/abuse/abuse.ts +++ b/server/models/abuse/abuse.ts @@ -32,14 +32,14 @@ import { UserVideoAbuse } from '@shared/models' import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants' -import { MAbuse, MAbuseAdminFormattable, MAbuseAP, MAbuseReporter, MAbuseUserFormattable, MUserAccountId } from '../../types/models' +import { MAbuseAdminFormattable, MAbuseAP, MAbuseFull, MAbuseReporter, MAbuseUserFormattable, MUserAccountId } from '../../types/models' import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account' import { getSort, throwIfNotValid } from '../utils' import { ThumbnailModel } from '../video/thumbnail' -import { VideoModel } from '../video/video' +import { ScopeNames as VideoScopeNames, VideoModel } from '../video/video' import { VideoBlacklistModel } from '../video/video-blacklist' import { ScopeNames as VideoChannelScopeNames, SummaryOptions as ChannelSummaryOptions, VideoChannelModel } from '../video/video-channel' -import { VideoCommentModel } from '../video/video-comment' +import { ScopeNames as CommentScopeNames, VideoCommentModel } from '../video/video-comment' import { buildAbuseListQuery, BuildAbusesQueryOptions } from './abuse-query-builder' import { VideoAbuseModel } from './video-abuse' import { VideoCommentAbuseModel } from './video-comment-abuse' @@ -307,6 +307,52 @@ export class AbuseModel extends Model { return AbuseModel.findOne(query) } + static loadFull (id: number): Bluebird { + const query = { + where: { + id + }, + include: [ + { + model: AccountModel.scope(AccountScopeNames.SUMMARY), + required: false, + as: 'ReporterAccount' + }, + { + model: AccountModel.scope(AccountScopeNames.SUMMARY), + as: 'FlaggedAccount' + }, + { + model: VideoAbuseModel, + required: false, + include: [ + { + model: VideoModel.scope([ VideoScopeNames.WITH_ACCOUNT_DETAILS ]) + } + ] + }, + { + model: VideoCommentAbuseModel, + required: false, + include: [ + { + model: VideoCommentModel.scope([ + CommentScopeNames.WITH_ACCOUNT + ]), + include: [ + { + model: VideoModel + } + ] + } + ] + } + ] + } + + return AbuseModel.findOne(query) + } + static async listForAdminApi (parameters: { start: number count: number @@ -455,7 +501,7 @@ export class AbuseModel extends Model { blacklisted: abuseModel.Video?.isBlacklisted() || false, thumbnailPath: abuseModel.Video?.getMiniatureStaticPath(), - channel: abuseModel.Video?.VideoChannel.toFormattedJSON() || abuseModel.deletedVideo?.channel, + channel: abuseModel.Video?.VideoChannel.toFormattedJSON() || abuseModel.deletedVideo?.channel } } diff --git a/server/models/account/user-notification-setting.ts b/server/models/account/user-notification-setting.ts index d8f3f13da..acc192d53 100644 --- a/server/models/account/user-notification-setting.ts +++ b/server/models/account/user-notification-setting.ts @@ -12,12 +12,12 @@ import { Table, UpdatedAt } from 'sequelize-typescript' -import { throwIfNotValid } from '../utils' -import { UserModel } from './user' -import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' +import { MNotificationSettingFormattable } from '@server/types/models' import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model' +import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' import { clearCacheByUserId } from '../../lib/oauth-model' -import { MNotificationSettingFormattable } from '@server/types/models' +import { throwIfNotValid } from '../utils' +import { UserModel } from './user' @Table({ tableName: 'userNotificationSetting', @@ -138,6 +138,24 @@ export class UserNotificationSettingModel extends Model throwIfNotValid(value, isUserNotificationSettingValid, 'abuseStateChange') + ) + @Column + abuseStateChange: UserNotificationSettingValue + + @AllowNull(false) + @Default(null) + @Is( + 'UserNotificationSettingAbuseNewMessage', + value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseNewMessage') + ) + @Column + abuseNewMessage: UserNotificationSettingValue + @ForeignKey(() => UserModel) @Column userId: number @@ -175,7 +193,9 @@ export class UserNotificationSettingModel extends Model { return { id: abuse.id, + state: abuse.state, video: videoAbuse, comment: commentAbuse, account: accountAbuse diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 75b914b8c..1d5c7280d 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -44,7 +44,7 @@ import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIf import { VideoModel } from './video' import { VideoChannelModel } from './video-channel' -enum ScopeNames { +export enum ScopeNames { WITH_ACCOUNT = 'WITH_ACCOUNT', WITH_ACCOUNT_FOR_API = 'WITH_ACCOUNT_FOR_API', WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO', -- cgit v1.2.3