From 86521a67b2edb06a139b095e489c205457eaba8f Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Fri, 17 Apr 2020 10:47:22 +0200 Subject: Add video channel and video thumbnail, rework video appearance in row --- server/models/video/video-abuse.ts | 54 +++++++++++++++++++++++++++++--------- server/models/video/video.ts | 2 +- 2 files changed, 43 insertions(+), 13 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index ea9856213..ea943ffdf 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts @@ -1,4 +1,6 @@ -import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { + AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt, DefaultScope +} from 'sequelize-typescript' import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' import { VideoAbuse } from '../../../shared/models/videos' import { @@ -14,7 +16,40 @@ import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/const import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models' import * as Bluebird from 'bluebird' import { literal, Op } from 'sequelize' +import { ThumbnailModel } from './thumbnail' +import { VideoChannelModel } from './video-channel' +import { ActorModel } from '../activitypub/actor' +import { VideoBlacklistModel } from './video-blacklist' +@DefaultScope(() => ({ + include: [ + { + model: AccountModel, + required: true + }, + { + model: VideoModel, + required: false, + include: [ + { + model: ThumbnailModel + }, + { + model: VideoChannelModel.unscoped(), + include: [ + { + model: ActorModel + } + ] + }, + { + attributes: [ 'id', 'reason', 'unfederated' ], + model: VideoBlacklistModel + } + ] + } + ] +})) @Table({ tableName: 'videoAbuse', indexes: [ @@ -114,16 +149,8 @@ export class VideoAbuseModel extends Model { [Op.notIn]: literal('(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')') } }, - include: [ - { - model: AccountModel, - required: true - }, - { - model: VideoModel, - required: false - } - ] + col: 'VideoAbuseModel.id', + distinct: true } return VideoAbuseModel.findAndCountAll(query) @@ -151,7 +178,10 @@ export class VideoAbuseModel extends Model { uuid: video.uuid, name: video.name, nsfw: video.nsfw, - deleted: !this.Video + deleted: !this.Video, + blacklisted: this.Video && this.Video.isBlacklisted(), + thumbnailPath: this.Video?.getMiniatureStaticPath(), + channel: this.Video?.VideoChannel.toFormattedSummaryJSON() || this.deletedVideo?.channel }, createdAt: this.createdAt } diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 2636ebd8e..f32216e90 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -810,7 +810,7 @@ export class VideoModel extends Model { if (instance.VideoAbuses.length === 0) return undefined } - const details = instance.toFormattedJSON() + const details = instance.toFormattedDetailsJSON() for (const abuse of instance.VideoAbuses) { tasks.push((_ => { -- cgit v1.2.3