From 8adf0a767f0816465ac3a8f4a6c63f53dd05fe3d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 May 2020 10:48:50 +0200 Subject: Fix comments deleted display --- server/models/video/video-comment.ts | 52 +++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'server/models/video/video-comment.ts') diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 7c890ce6d..dfeb1c4e7 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -24,13 +24,14 @@ import { MCommentOwnerVideoReply } from '../../typings/models/video' import { AccountModel } from '../account/account' -import { ActorModel } from '../activitypub/actor' +import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor' import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' import { VideoChannelModel } from './video-channel' enum ScopeNames { WITH_ACCOUNT = 'WITH_ACCOUNT', + WITH_ACCOUNT_FOR_API = 'WITH_ACCOUNT_FOR_API', WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO', WITH_VIDEO = 'WITH_VIDEO', ATTRIBUTES_FOR_API = 'ATTRIBUTES_FOR_API' @@ -82,6 +83,22 @@ enum ScopeNames { } ] }, + [ScopeNames.WITH_ACCOUNT_FOR_API]: { + include: [ + { + model: AccountModel.unscoped(), + include: [ + { + attributes: { + exclude: unusedActorAttributesForAPI + }, + model: ActorModel, // Default scope includes avatar and server + required: true + } + ] + } + ] + }, [ScopeNames.WITH_IN_REPLY_TO]: { include: [ { @@ -275,18 +292,33 @@ export class VideoCommentModel extends Model { limit: count, order: getCommentSort(sort), where: { - videoId, - inReplyToCommentId: null, - accountId: { - [Op.notIn]: Sequelize.literal( - '(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')' - ) - } + [Op.and]: [ + { + videoId + }, + { + inReplyToCommentId: null + }, + { + [Op.or]: [ + { + accountId: { + [Op.notIn]: Sequelize.literal( + '(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')' + ) + } + }, + { + accountId: null + } + ] + } + ] } } const scopes: (string | ScopeOptions)[] = [ - ScopeNames.WITH_ACCOUNT, + ScopeNames.WITH_ACCOUNT_FOR_API, { method: [ ScopeNames.ATTRIBUTES_FOR_API, serverAccountId, userAccountId ] } @@ -328,7 +360,7 @@ export class VideoCommentModel extends Model { } const scopes: any[] = [ - ScopeNames.WITH_ACCOUNT, + ScopeNames.WITH_ACCOUNT_FOR_API, { method: [ ScopeNames.ATTRIBUTES_FOR_API, serverAccountId, userAccountId ] } -- cgit v1.2.3