aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/video-comment.ts84
1 files changed, 46 insertions, 38 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 70aed75d6..ed4a345eb 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -323,14 +323,8 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
323 }) { 323 }) {
324 const { start, count, sort, isLocal, search, searchAccount, searchVideo } = parameters 324 const { start, count, sort, isLocal, search, searchAccount, searchVideo } = parameters
325 325
326 const query: FindAndCountOptions = {
327 offset: start,
328 limit: count,
329 order: getCommentSort(sort)
330 }
331
332 const where: WhereOptions = { 326 const where: WhereOptions = {
333 isDeleted: false 327 deletedAt: null
334 } 328 }
335 329
336 const whereAccount: WhereOptions = {} 330 const whereAccount: WhereOptions = {}
@@ -338,11 +332,11 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
338 const whereVideo: WhereOptions = {} 332 const whereVideo: WhereOptions = {}
339 333
340 if (isLocal === true) { 334 if (isLocal === true) {
341 Object.assign(where, { 335 Object.assign(whereActor, {
342 serverId: null 336 serverId: null
343 }) 337 })
344 } else if (isLocal === false) { 338 } else if (isLocal === false) {
345 Object.assign(where, { 339 Object.assign(whereActor, {
346 serverId: { 340 serverId: {
347 [Op.ne]: null 341 [Op.ne]: null
348 } 342 }
@@ -350,43 +344,57 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
350 } 344 }
351 345
352 if (search) { 346 if (search) {
353 Object.assign(where, searchAttribute(search, 'text')) 347 Object.assign(where, {
354 Object.assign(whereActor, searchAttribute(search, 'preferredUsername')) 348 [Op.or]: [
355 Object.assign(whereAccount, searchAttribute(search, 'name')) 349 searchAttribute(search, 'text'),
356 Object.assign(whereVideo, searchAttribute(search, 'name')) 350 searchAttribute(search, '$Account.Actor.preferredUsername$'),
351 searchAttribute(search, '$Account.name$'),
352 searchAttribute(search, '$Video.name$')
353 ]
354 })
357 } 355 }
358 356
359 if (searchAccount) { 357 if (searchAccount) {
360 Object.assign(whereActor, searchAttribute(search, 'preferredUsername')) 358 Object.assign(whereActor, {
361 Object.assign(whereAccount, searchAttribute(search, 'name')) 359 [Op.or]: [
360 searchAttribute(searchAccount, '$Account.Actor.preferredUsername$'),
361 searchAttribute(searchAccount, '$Account.name$')
362 ]
363 })
362 } 364 }
363 365
364 if (searchVideo) { 366 if (searchVideo) {
365 Object.assign(whereVideo, searchAttribute(search, 'name')) 367 Object.assign(whereVideo, searchAttribute(searchVideo, 'name'))
366 } 368 }
367 369
368 query.include = [ 370 const query: FindAndCountOptions = {
369 { 371 offset: start,
370 model: AccountModel.unscoped(), 372 limit: count,
371 required: !!searchAccount, 373 order: getCommentSort(sort),
372 where: whereAccount, 374 where,
373 include: [ 375 include: [
374 { 376 {
375 attributes: { 377 model: AccountModel.unscoped(),
376 exclude: unusedActorAttributesForAPI 378 required: true,
377 }, 379 where: whereAccount,
378 model: ActorModel, // Default scope includes avatar and server 380 include: [
379 required: true, 381 {
380 where: whereActor 382 attributes: {
381 } 383 exclude: unusedActorAttributesForAPI
382 ] 384 },
383 }, 385 model: ActorModel, // Default scope includes avatar and server
384 { 386 required: true,
385 model: VideoModel.unscoped(), 387 where: whereActor
386 required: true, 388 }
387 where: whereVideo 389 ]
388 } 390 },
389 ] 391 {
392 model: VideoModel.unscoped(),
393 required: true,
394 where: whereVideo
395 }
396 ]
397 }
390 398
391 return VideoCommentModel 399 return VideoCommentModel
392 .findAndCountAll(query) 400 .findAndCountAll(query)