aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/video-channel.ts36
1 files changed, 27 insertions, 9 deletions
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 327f49304..e4b12c517 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -18,7 +18,7 @@ import {
18 UpdatedAt 18 UpdatedAt
19} from 'sequelize-typescript' 19} from 'sequelize-typescript'
20import { MAccountActor } from '@server/types/models' 20import { MAccountActor } from '@server/types/models'
21import { AttributesOnly } from '@shared/core-utils' 21import { AttributesOnly, pick } from '@shared/core-utils'
22import { ActivityPubActor } from '../../../shared/models/activitypub' 22import { ActivityPubActor } from '../../../shared/models/activitypub'
23import { VideoChannel, VideoChannelSummary } from '../../../shared/models/videos' 23import { VideoChannel, VideoChannelSummary } from '../../../shared/models/videos'
24import { 24import {
@@ -59,7 +59,7 @@ type AvailableForListOptions = {
59 actorId: number 59 actorId: number
60 search?: string 60 search?: string
61 host?: string 61 host?: string
62 names?: string[] 62 handles?: string[]
63} 63}
64 64
65type AvailableWithStatsOptions = { 65type AvailableWithStatsOptions = {
@@ -114,15 +114,33 @@ export type SummaryOptions = {
114 }) 114 })
115 } 115 }
116 116
117 if (options.names) { 117 let rootWhere: WhereOptions
118 whereActorAnd.push({ 118 if (options.handles) {
119 preferredUsername: { 119 const or: WhereOptions[] = []
120 [Op.in]: options.names 120
121 for (const handle of options.handles || []) {
122 const [ preferredUsername, host ] = handle.split('@')
123
124 if (!host) {
125 or.push({
126 '$Actor.preferredUsername$': preferredUsername,
127 '$Actor.serverId$': null
128 })
129 } else {
130 or.push({
131 '$Actor.preferredUsername$': preferredUsername,
132 '$Actor.Server.host$': host
133 })
121 } 134 }
122 }) 135 }
136
137 rootWhere = {
138 [Op.or]: or
139 }
123 } 140 }
124 141
125 return { 142 return {
143 where: rootWhere,
126 include: [ 144 include: [
127 { 145 {
128 attributes: { 146 attributes: {
@@ -473,7 +491,7 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"`
473 sort: string 491 sort: string
474 492
475 host?: string 493 host?: string
476 names?: string[] 494 handles?: string[]
477 }) { 495 }) {
478 let attributesInclude: any[] = [ literal('0 as similarity') ] 496 let attributesInclude: any[] = [ literal('0 as similarity') ]
479 let where: WhereOptions 497 let where: WhereOptions
@@ -507,7 +525,7 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"`
507 525
508 return VideoChannelModel 526 return VideoChannelModel
509 .scope({ 527 .scope({
510 method: [ ScopeNames.FOR_API, { actorId: options.actorId, host: options.host, names: options.names } as AvailableForListOptions ] 528 method: [ ScopeNames.FOR_API, pick(options, [ 'actorId', 'host', 'handles' ]) as AvailableForListOptions ]
511 }) 529 })
512 .findAndCountAll(query) 530 .findAndCountAll(query)
513 .then(({ rows, count }) => { 531 .then(({ rows, count }) => {