2020-05-06 11:39:07 -04:00
|
|
|
import * as Bluebird from 'bluebird'
|
|
|
|
import { literal, Op } from 'sequelize'
|
2020-04-17 04:47:22 -04:00
|
|
|
import {
|
2020-05-06 11:39:07 -04:00
|
|
|
AllowNull,
|
|
|
|
BelongsTo,
|
|
|
|
Column,
|
|
|
|
CreatedAt,
|
|
|
|
DataType,
|
|
|
|
Default,
|
|
|
|
ForeignKey,
|
|
|
|
Is,
|
|
|
|
Model,
|
|
|
|
Scopes,
|
|
|
|
Table,
|
|
|
|
UpdatedAt
|
2020-04-17 04:47:22 -04:00
|
|
|
} from 'sequelize-typescript'
|
2020-05-06 11:39:07 -04:00
|
|
|
import { VideoAbuseVideoIs } from '@shared/models/videos/abuse/video-abuse-video-is.type'
|
2020-06-22 07:00:39 -04:00
|
|
|
import {
|
|
|
|
VideoAbuseState,
|
|
|
|
VideoDetails,
|
|
|
|
VideoAbusePredefinedReasons,
|
|
|
|
VideoAbusePredefinedReasonsString,
|
|
|
|
videoAbusePredefinedReasonsMap
|
|
|
|
} from '../../../shared'
|
2017-12-12 11:53:50 -05:00
|
|
|
import { VideoAbuseObject } from '../../../shared/models/activitypub/objects'
|
2018-03-12 06:29:46 -04:00
|
|
|
import { VideoAbuse } from '../../../shared/models/videos'
|
2018-08-10 10:54:01 -04:00
|
|
|
import {
|
|
|
|
isVideoAbuseModerationCommentValid,
|
|
|
|
isVideoAbuseReasonValid,
|
|
|
|
isVideoAbuseStateValid
|
|
|
|
} from '../../helpers/custom-validators/video-abuses'
|
2019-04-11 08:26:41 -04:00
|
|
|
import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
|
2020-06-18 04:45:25 -04:00
|
|
|
import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../types/models'
|
2020-05-06 11:39:07 -04:00
|
|
|
import { AccountModel } from '../account/account'
|
|
|
|
import { buildBlockedAccountSQL, getSort, searchAttribute, throwIfNotValid } from '../utils'
|
2020-04-17 04:47:22 -04:00
|
|
|
import { ThumbnailModel } from './thumbnail'
|
2020-05-06 11:39:07 -04:00
|
|
|
import { VideoModel } from './video'
|
2020-04-17 04:47:22 -04:00
|
|
|
import { VideoBlacklistModel } from './video-blacklist'
|
2020-04-19 08:11:40 -04:00
|
|
|
import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel'
|
2020-06-22 07:00:39 -04:00
|
|
|
import { invert } from 'lodash'
|
2017-12-12 11:53:50 -05:00
|
|
|
|
2020-04-18 04:00:19 -04:00
|
|
|
export enum ScopeNames {
|
|
|
|
FOR_API = 'FOR_API'
|
|
|
|
}
|
|
|
|
|
|
|
|
@Scopes(() => ({
|
|
|
|
[ScopeNames.FOR_API]: (options: {
|
2020-05-02 16:38:18 -04:00
|
|
|
// search
|
2020-04-18 04:00:19 -04:00
|
|
|
search?: string
|
|
|
|
searchReporter?: string
|
2020-05-02 16:38:18 -04:00
|
|
|
searchReportee?: string
|
2020-04-18 04:00:19 -04:00
|
|
|
searchVideo?: string
|
|
|
|
searchVideoChannel?: string
|
2020-05-06 04:31:52 -04:00
|
|
|
|
2020-05-02 16:38:18 -04:00
|
|
|
// filters
|
|
|
|
id?: number
|
2020-06-22 07:00:39 -04:00
|
|
|
predefinedReasonId?: number
|
2020-05-06 11:39:07 -04:00
|
|
|
|
2020-05-02 16:38:18 -04:00
|
|
|
state?: VideoAbuseState
|
2020-05-06 11:39:07 -04:00
|
|
|
videoIs?: VideoAbuseVideoIs
|
2020-05-06 04:31:52 -04:00
|
|
|
|
2020-05-02 16:38:18 -04:00
|
|
|
// accountIds
|
2020-04-18 04:00:19 -04:00
|
|
|
serverAccountId: number
|
2020-04-20 05:20:12 -04:00
|
|
|
userAccountId: number
|
2020-04-18 04:00:19 -04:00
|
|
|
}) => {
|
2020-05-06 11:39:07 -04:00
|
|
|
const where = {
|
2020-04-18 04:00:19 -04:00
|
|
|
reporterAccountId: {
|
2020-05-22 11:06:26 -04:00
|
|
|
[Op.notIn]: literal('(' + buildBlockedAccountSQL([ options.serverAccountId, options.userAccountId ]) + ')')
|
2020-04-18 04:00:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.search) {
|
2020-05-06 11:39:07 -04:00
|
|
|
Object.assign(where, {
|
2020-04-18 04:00:19 -04:00
|
|
|
[Op.or]: [
|
|
|
|
{
|
|
|
|
[Op.and]: [
|
|
|
|
{ videoId: { [Op.not]: null } },
|
2020-04-20 05:20:12 -04:00
|
|
|
searchAttribute(options.search, '$Video.name$')
|
2020-04-18 04:00:19 -04:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[Op.and]: [
|
|
|
|
{ videoId: { [Op.not]: null } },
|
2020-04-20 05:20:12 -04:00
|
|
|
searchAttribute(options.search, '$Video.VideoChannel.name$')
|
2020-04-18 04:00:19 -04:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[Op.and]: [
|
|
|
|
{ deletedVideo: { [Op.not]: null } },
|
2020-04-20 05:20:12 -04:00
|
|
|
{ deletedVideo: searchAttribute(options.search, 'name') }
|
2020-04-18 04:00:19 -04:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[Op.and]: [
|
|
|
|
{ deletedVideo: { [Op.not]: null } },
|
2020-04-20 05:20:12 -04:00
|
|
|
{ deletedVideo: { channel: searchAttribute(options.search, 'displayName') } }
|
2020-04-18 04:00:19 -04:00
|
|
|
]
|
|
|
|
},
|
2020-04-20 05:20:12 -04:00
|
|
|
searchAttribute(options.search, '$Account.name$')
|
2020-04-18 04:00:19 -04:00
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-06 11:39:07 -04:00
|
|
|
if (options.id) Object.assign(where, { id: options.id })
|
|
|
|
if (options.state) Object.assign(where, { state: options.state })
|
2020-05-02 16:38:18 -04:00
|
|
|
|
2020-05-06 11:39:07 -04:00
|
|
|
if (options.videoIs === 'deleted') {
|
|
|
|
Object.assign(where, {
|
|
|
|
deletedVideo: {
|
|
|
|
[Op.not]: null
|
|
|
|
}
|
2020-05-02 16:38:18 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-06-22 07:00:39 -04:00
|
|
|
if (options.predefinedReasonId) {
|
|
|
|
Object.assign(where, {
|
|
|
|
predefinedReasons: {
|
|
|
|
[Op.contains]: [ options.predefinedReasonId ]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-06 11:39:07 -04:00
|
|
|
const onlyBlacklisted = options.videoIs === 'blacklisted'
|
2020-05-02 16:38:18 -04:00
|
|
|
|
2020-04-18 04:00:19 -04:00
|
|
|
return {
|
2020-04-18 16:57:20 -04:00
|
|
|
attributes: {
|
|
|
|
include: [
|
|
|
|
[
|
2020-04-20 09:15:10 -04:00
|
|
|
// we don't care about this count for deleted videos, so there are not included
|
2020-04-18 16:57:20 -04:00
|
|
|
literal(
|
|
|
|
'(' +
|
2020-04-20 05:20:12 -04:00
|
|
|
'SELECT count(*) ' +
|
|
|
|
'FROM "videoAbuse" ' +
|
|
|
|
'WHERE "videoId" = "VideoAbuseModel"."videoId" ' +
|
2020-04-18 16:57:20 -04:00
|
|
|
')'
|
|
|
|
),
|
|
|
|
'countReportsForVideo'
|
|
|
|
],
|
|
|
|
[
|
2020-04-20 09:15:10 -04:00
|
|
|
// we don't care about this count for deleted videos, so there are not included
|
2020-04-18 16:57:20 -04:00
|
|
|
literal(
|
|
|
|
'(' +
|
|
|
|
'SELECT t.nth ' +
|
|
|
|
'FROM ( ' +
|
|
|
|
'SELECT id, ' +
|
|
|
|
'row_number() OVER (PARTITION BY "videoId" ORDER BY "createdAt") AS nth ' +
|
|
|
|
'FROM "videoAbuse" ' +
|
|
|
|
') t ' +
|
|
|
|
'WHERE t.id = "VideoAbuseModel".id ' +
|
|
|
|
')'
|
|
|
|
),
|
|
|
|
'nthReportForVideo'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
literal(
|
|
|
|
'(' +
|
|
|
|
'SELECT count("videoAbuse"."id") ' +
|
|
|
|
'FROM "videoAbuse" ' +
|
|
|
|
'INNER JOIN "video" ON "video"."id" = "videoAbuse"."videoId" ' +
|
|
|
|
'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
|
|
|
|
'INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ' +
|
|
|
|
'WHERE "account"."id" = "VideoAbuseModel"."reporterAccountId" ' +
|
|
|
|
')'
|
|
|
|
),
|
2020-04-20 09:15:10 -04:00
|
|
|
'countReportsForReporter__video'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
literal(
|
|
|
|
'(' +
|
|
|
|
'SELECT count(DISTINCT "videoAbuse"."id") ' +
|
|
|
|
'FROM "videoAbuse" ' +
|
|
|
|
`WHERE CAST("deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) = "VideoAbuseModel"."reporterAccountId" ` +
|
|
|
|
')'
|
|
|
|
),
|
|
|
|
'countReportsForReporter__deletedVideo'
|
2020-04-18 16:57:20 -04:00
|
|
|
],
|
|
|
|
[
|
|
|
|
literal(
|
|
|
|
'(' +
|
2020-04-20 05:20:12 -04:00
|
|
|
'SELECT count(DISTINCT "videoAbuse"."id") ' +
|
2020-04-18 16:57:20 -04:00
|
|
|
'FROM "videoAbuse" ' +
|
|
|
|
'INNER JOIN "video" ON "video"."id" = "videoAbuse"."videoId" ' +
|
|
|
|
'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
|
2020-04-20 09:15:10 -04:00
|
|
|
'INNER JOIN "account" ON ' +
|
|
|
|
'"videoChannel"."accountId" = "Video->VideoChannel"."accountId" ' +
|
|
|
|
`OR "videoChannel"."accountId" = CAST("VideoAbuseModel"."deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) ` +
|
|
|
|
')'
|
|
|
|
),
|
|
|
|
'countReportsForReportee__video'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
literal(
|
|
|
|
'(' +
|
|
|
|
'SELECT count(DISTINCT "videoAbuse"."id") ' +
|
|
|
|
'FROM "videoAbuse" ' +
|
|
|
|
`WHERE CAST("deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) = "Video->VideoChannel"."accountId" ` +
|
2020-04-20 09:28:16 -04:00
|
|
|
`OR CAST("deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) = ` +
|
|
|
|
`CAST("VideoAbuseModel"."deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) ` +
|
2020-04-18 16:57:20 -04:00
|
|
|
')'
|
|
|
|
),
|
2020-04-20 09:15:10 -04:00
|
|
|
'countReportsForReportee__deletedVideo'
|
2020-04-18 16:57:20 -04:00
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
2020-04-17 04:47:22 -04:00
|
|
|
include: [
|
|
|
|
{
|
2020-04-18 04:00:19 -04:00
|
|
|
model: AccountModel,
|
|
|
|
required: true,
|
2020-04-20 05:20:12 -04:00
|
|
|
where: searchAttribute(options.searchReporter, 'name')
|
2020-04-17 04:47:22 -04:00
|
|
|
},
|
|
|
|
{
|
2020-04-18 04:00:19 -04:00
|
|
|
model: VideoModel,
|
2020-05-06 11:39:07 -04:00
|
|
|
required: !!(onlyBlacklisted || options.searchVideo || options.searchReportee || options.searchVideoChannel),
|
2020-04-20 05:20:12 -04:00
|
|
|
where: searchAttribute(options.searchVideo, 'name'),
|
2020-04-17 04:47:22 -04:00
|
|
|
include: [
|
|
|
|
{
|
2020-04-18 04:00:19 -04:00
|
|
|
model: ThumbnailModel
|
|
|
|
},
|
|
|
|
{
|
2020-04-19 08:11:40 -04:00
|
|
|
model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, { withAccount: true } as SummaryOptions ] }),
|
2020-05-02 16:38:18 -04:00
|
|
|
where: searchAttribute(options.searchVideoChannel, 'name'),
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
model: AccountModel,
|
|
|
|
where: searchAttribute(options.searchReportee, 'name')
|
|
|
|
}
|
|
|
|
]
|
2020-04-18 04:00:19 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
attributes: [ 'id', 'reason', 'unfederated' ],
|
2020-05-03 10:16:10 -04:00
|
|
|
model: VideoBlacklistModel,
|
|
|
|
required: onlyBlacklisted
|
2020-04-17 04:47:22 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2020-04-18 04:00:19 -04:00
|
|
|
],
|
|
|
|
where
|
2020-04-17 04:47:22 -04:00
|
|
|
}
|
2020-04-18 04:00:19 -04:00
|
|
|
}
|
2020-04-17 04:47:22 -04:00
|
|
|
}))
|
2017-12-12 11:53:50 -05:00
|
|
|
@Table({
|
|
|
|
tableName: 'videoAbuse',
|
|
|
|
indexes: [
|
2017-01-04 14:59:23 -05:00
|
|
|
{
|
2017-12-12 11:53:50 -05:00
|
|
|
fields: [ 'videoId' ]
|
2017-01-04 14:59:23 -05:00
|
|
|
},
|
|
|
|
{
|
2017-12-12 11:53:50 -05:00
|
|
|
fields: [ 'reporterAccountId' ]
|
2017-01-04 14:59:23 -05:00
|
|
|
}
|
2017-05-22 14:58:25 -04:00
|
|
|
]
|
2017-12-12 11:53:50 -05:00
|
|
|
})
|
|
|
|
export class VideoAbuseModel extends Model<VideoAbuseModel> {
|
2017-05-22 14:58:25 -04:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
@AllowNull(false)
|
2019-01-14 10:48:38 -05:00
|
|
|
@Default(null)
|
2017-12-12 11:53:50 -05:00
|
|
|
@Is('VideoAbuseReason', value => throwIfNotValid(value, isVideoAbuseReasonValid, 'reason'))
|
2019-01-14 10:48:38 -05:00
|
|
|
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_ABUSES.REASON.max))
|
2017-12-12 11:53:50 -05:00
|
|
|
reason: string
|
2017-11-16 11:04:19 -05:00
|
|
|
|
2018-08-10 10:54:01 -04:00
|
|
|
@AllowNull(false)
|
|
|
|
@Default(null)
|
|
|
|
@Is('VideoAbuseState', value => throwIfNotValid(value, isVideoAbuseStateValid, 'state'))
|
|
|
|
@Column
|
|
|
|
state: VideoAbuseState
|
|
|
|
|
|
|
|
@AllowNull(true)
|
|
|
|
@Default(null)
|
2019-04-18 05:28:17 -04:00
|
|
|
@Is('VideoAbuseModerationComment', value => throwIfNotValid(value, isVideoAbuseModerationCommentValid, 'moderationComment', true))
|
2018-08-10 10:54:01 -04:00
|
|
|
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_ABUSES.MODERATION_COMMENT.max))
|
|
|
|
moderationComment: string
|
|
|
|
|
2020-04-16 08:22:27 -04:00
|
|
|
@AllowNull(true)
|
|
|
|
@Default(null)
|
|
|
|
@Column(DataType.JSONB)
|
2020-04-18 16:57:20 -04:00
|
|
|
deletedVideo: VideoDetails
|
2020-04-16 08:22:27 -04:00
|
|
|
|
2020-06-22 07:00:39 -04:00
|
|
|
@AllowNull(true)
|
|
|
|
@Default(null)
|
|
|
|
@Column(DataType.ARRAY(DataType.INTEGER))
|
|
|
|
predefinedReasons: VideoAbusePredefinedReasons[]
|
|
|
|
|
|
|
|
@AllowNull(true)
|
|
|
|
@Default(null)
|
|
|
|
@Column
|
|
|
|
startAt: number
|
|
|
|
|
|
|
|
@AllowNull(true)
|
|
|
|
@Default(null)
|
|
|
|
@Column
|
|
|
|
endAt: number
|
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
@CreatedAt
|
|
|
|
createdAt: Date
|
2017-11-16 11:04:19 -05:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
@UpdatedAt
|
|
|
|
updatedAt: Date
|
2017-05-22 14:58:25 -04:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
@ForeignKey(() => AccountModel)
|
|
|
|
@Column
|
|
|
|
reporterAccountId: number
|
2017-01-04 14:59:23 -05:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
@BelongsTo(() => AccountModel, {
|
2017-01-04 14:59:23 -05:00
|
|
|
foreignKey: {
|
2020-04-16 08:22:27 -04:00
|
|
|
allowNull: true
|
2017-01-04 14:59:23 -05:00
|
|
|
},
|
2020-04-16 08:22:27 -04:00
|
|
|
onDelete: 'set null'
|
2017-01-04 14:59:23 -05:00
|
|
|
})
|
2017-12-12 11:53:50 -05:00
|
|
|
Account: AccountModel
|
|
|
|
|
|
|
|
@ForeignKey(() => VideoModel)
|
|
|
|
@Column
|
|
|
|
videoId: number
|
2017-01-04 14:59:23 -05:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
@BelongsTo(() => VideoModel, {
|
2017-01-04 14:59:23 -05:00
|
|
|
foreignKey: {
|
2020-04-16 08:22:27 -04:00
|
|
|
allowNull: true
|
2017-01-04 14:59:23 -05:00
|
|
|
},
|
2020-04-16 08:22:27 -04:00
|
|
|
onDelete: 'set null'
|
2017-01-04 14:59:23 -05:00
|
|
|
})
|
2017-12-12 11:53:50 -05:00
|
|
|
Video: VideoModel
|
|
|
|
|
2020-04-16 08:22:27 -04:00
|
|
|
static loadByIdAndVideoId (id: number, videoId?: number, uuid?: string): Bluebird<MVideoAbuse> {
|
|
|
|
const videoAttributes = {}
|
|
|
|
if (videoId) videoAttributes['videoId'] = videoId
|
|
|
|
if (uuid) videoAttributes['deletedVideo'] = { uuid }
|
|
|
|
|
2018-08-10 10:54:01 -04:00
|
|
|
const query = {
|
|
|
|
where: {
|
|
|
|
id,
|
2020-04-16 08:22:27 -04:00
|
|
|
...videoAttributes
|
2018-08-10 10:54:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return VideoAbuseModel.findOne(query)
|
|
|
|
}
|
|
|
|
|
2019-08-29 08:31:04 -04:00
|
|
|
static listForApi (parameters: {
|
2020-01-31 10:56:52 -05:00
|
|
|
start: number
|
|
|
|
count: number
|
|
|
|
sort: string
|
2020-05-06 11:39:07 -04:00
|
|
|
|
2019-08-29 08:31:04 -04:00
|
|
|
serverAccountId: number
|
|
|
|
user?: MUserAccountId
|
2020-05-06 11:39:07 -04:00
|
|
|
|
|
|
|
id?: number
|
2020-06-22 07:00:39 -04:00
|
|
|
predefinedReason?: VideoAbusePredefinedReasonsString
|
2020-05-06 11:39:07 -04:00
|
|
|
state?: VideoAbuseState
|
|
|
|
videoIs?: VideoAbuseVideoIs
|
|
|
|
|
|
|
|
search?: string
|
|
|
|
searchReporter?: string
|
|
|
|
searchReportee?: string
|
|
|
|
searchVideo?: string
|
|
|
|
searchVideoChannel?: string
|
2019-08-29 08:31:04 -04:00
|
|
|
}) {
|
2020-05-06 11:39:07 -04:00
|
|
|
const {
|
|
|
|
start,
|
|
|
|
count,
|
|
|
|
sort,
|
|
|
|
search,
|
|
|
|
user,
|
|
|
|
serverAccountId,
|
|
|
|
state,
|
|
|
|
videoIs,
|
2020-06-22 07:00:39 -04:00
|
|
|
predefinedReason,
|
2020-05-06 11:39:07 -04:00
|
|
|
searchReportee,
|
|
|
|
searchVideo,
|
|
|
|
searchVideoChannel,
|
|
|
|
searchReporter,
|
|
|
|
id
|
|
|
|
} = parameters
|
|
|
|
|
2019-08-29 08:31:04 -04:00
|
|
|
const userAccountId = user ? user.Account.id : undefined
|
2020-06-22 07:00:39 -04:00
|
|
|
const predefinedReasonId = predefinedReason ? videoAbusePredefinedReasonsMap[predefinedReason] : undefined
|
2019-08-29 08:31:04 -04:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
const query = {
|
|
|
|
offset: start,
|
|
|
|
limit: count,
|
2018-02-19 03:41:03 -05:00
|
|
|
order: getSort(sort),
|
2020-04-17 04:47:22 -04:00
|
|
|
col: 'VideoAbuseModel.id',
|
|
|
|
distinct: true
|
2017-12-12 11:53:50 -05:00
|
|
|
}
|
2017-01-04 14:59:23 -05:00
|
|
|
|
2020-04-18 04:00:19 -04:00
|
|
|
const filters = {
|
2020-05-06 11:39:07 -04:00
|
|
|
id,
|
2020-06-22 07:00:39 -04:00
|
|
|
predefinedReasonId,
|
2020-05-06 11:39:07 -04:00
|
|
|
search,
|
|
|
|
state,
|
|
|
|
videoIs,
|
|
|
|
searchReportee,
|
|
|
|
searchVideo,
|
|
|
|
searchVideoChannel,
|
|
|
|
searchReporter,
|
2020-04-18 04:00:19 -04:00
|
|
|
serverAccountId,
|
|
|
|
userAccountId
|
|
|
|
}
|
|
|
|
|
|
|
|
return VideoAbuseModel
|
2020-06-22 07:00:39 -04:00
|
|
|
.scope([
|
|
|
|
{ method: [ ScopeNames.FOR_API, filters ] }
|
|
|
|
])
|
2020-04-18 04:00:19 -04:00
|
|
|
.findAndCountAll(query)
|
2017-12-12 11:53:50 -05:00
|
|
|
.then(({ rows, count }) => {
|
|
|
|
return { total: count, data: rows }
|
|
|
|
})
|
2017-01-04 14:59:23 -05:00
|
|
|
}
|
|
|
|
|
2019-08-20 13:05:31 -04:00
|
|
|
toFormattedJSON (this: MVideoAbuseFormattable): VideoAbuse {
|
2020-06-22 07:00:39 -04:00
|
|
|
const predefinedReasons = VideoAbuseModel.getPredefinedReasonsStrings(this.predefinedReasons)
|
2020-04-18 16:57:20 -04:00
|
|
|
const countReportsForVideo = this.get('countReportsForVideo') as number
|
|
|
|
const nthReportForVideo = this.get('nthReportForVideo') as number
|
2020-04-20 09:15:10 -04:00
|
|
|
const countReportsForReporterVideo = this.get('countReportsForReporter__video') as number
|
|
|
|
const countReportsForReporterDeletedVideo = this.get('countReportsForReporter__deletedVideo') as number
|
|
|
|
const countReportsForReporteeVideo = this.get('countReportsForReportee__video') as number
|
|
|
|
const countReportsForReporteeDeletedVideo = this.get('countReportsForReportee__deletedVideo') as number
|
2020-04-18 16:57:20 -04:00
|
|
|
|
2020-04-16 08:22:27 -04:00
|
|
|
const video = this.Video
|
|
|
|
? this.Video
|
|
|
|
: this.deletedVideo
|
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
reason: this.reason,
|
2020-06-22 07:00:39 -04:00
|
|
|
predefinedReasons,
|
2018-03-12 06:29:46 -04:00
|
|
|
reporterAccount: this.Account.toFormattedJSON(),
|
2018-08-10 10:54:01 -04:00
|
|
|
state: {
|
|
|
|
id: this.state,
|
|
|
|
label: VideoAbuseModel.getStateLabel(this.state)
|
|
|
|
},
|
|
|
|
moderationComment: this.moderationComment,
|
2018-03-12 06:29:46 -04:00
|
|
|
video: {
|
2020-04-16 08:22:27 -04:00
|
|
|
id: video.id,
|
|
|
|
uuid: video.uuid,
|
|
|
|
name: video.name,
|
|
|
|
nsfw: video.nsfw,
|
2020-04-17 04:47:22 -04:00
|
|
|
deleted: !this.Video,
|
2020-06-17 04:55:40 -04:00
|
|
|
blacklisted: this.Video?.isBlacklisted() || false,
|
2020-04-17 04:47:22 -04:00
|
|
|
thumbnailPath: this.Video?.getMiniatureStaticPath(),
|
2020-04-18 16:57:20 -04:00
|
|
|
channel: this.Video?.VideoChannel.toFormattedJSON() || this.deletedVideo?.channel
|
2018-03-12 06:29:46 -04:00
|
|
|
},
|
2020-04-18 16:57:20 -04:00
|
|
|
createdAt: this.createdAt,
|
|
|
|
updatedAt: this.updatedAt,
|
2020-06-22 07:00:39 -04:00
|
|
|
startAt: this.startAt,
|
|
|
|
endAt: this.endAt,
|
2020-04-18 16:57:20 -04:00
|
|
|
count: countReportsForVideo || 0,
|
|
|
|
nth: nthReportForVideo || 0,
|
2020-04-20 09:15:10 -04:00
|
|
|
countReportsForReporter: (countReportsForReporterVideo || 0) + (countReportsForReporterDeletedVideo || 0),
|
|
|
|
countReportsForReportee: (countReportsForReporteeVideo || 0) + (countReportsForReporteeDeletedVideo || 0)
|
2017-12-12 11:53:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
toActivityPubObject (this: MVideoAbuseVideo): VideoAbuseObject {
|
2020-06-22 07:00:39 -04:00
|
|
|
const predefinedReasons = VideoAbuseModel.getPredefinedReasonsStrings(this.predefinedReasons)
|
|
|
|
|
|
|
|
const startAt = this.startAt
|
|
|
|
const endAt = this.endAt
|
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
return {
|
|
|
|
type: 'Flag' as 'Flag',
|
|
|
|
content: this.reason,
|
2020-06-22 07:00:39 -04:00
|
|
|
object: this.Video.url,
|
|
|
|
tag: predefinedReasons.map(r => ({
|
|
|
|
type: 'Hashtag' as 'Hashtag',
|
|
|
|
name: r
|
|
|
|
})),
|
|
|
|
startAt,
|
|
|
|
endAt
|
2017-12-12 11:53:50 -05:00
|
|
|
}
|
|
|
|
}
|
2018-08-10 10:54:01 -04:00
|
|
|
|
|
|
|
private static getStateLabel (id: number) {
|
|
|
|
return VIDEO_ABUSE_STATES[id] || 'Unknown'
|
|
|
|
}
|
2020-06-22 07:00:39 -04:00
|
|
|
|
|
|
|
private static getPredefinedReasonsStrings (predefinedReasons: VideoAbusePredefinedReasons[]): VideoAbusePredefinedReasonsString[] {
|
|
|
|
return (predefinedReasons || [])
|
|
|
|
.filter(r => r in VideoAbusePredefinedReasons)
|
|
|
|
.map(r => invert(videoAbusePredefinedReasonsMap)[r] as VideoAbusePredefinedReasonsString)
|
|
|
|
}
|
2017-01-04 14:59:23 -05:00
|
|
|
}
|