aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-29 10:27:24 +0200
committerChocobozzz <me@florianbigard.com>2021-07-29 10:27:24 +0200
commitb033851fb54241bb703f86add025229e68cc6f59 (patch)
treed60dac1499a95bf9dc902dee24f325fe0f8b6acb /server/models/video
parentfbd67e7f386504e50f2504cb6386700a58906f16 (diff)
downloadPeerTube-b033851fb54241bb703f86add025229e68cc6f59.tar.gz
PeerTube-b033851fb54241bb703f86add025229e68cc6f59.tar.zst
PeerTube-b033851fb54241bb703f86add025229e68cc6f59.zip
Search channels against handles and not names
Diffstat (limited to 'server/models/video')
-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 }) => {