UpdatedAt
} from 'sequelize-typescript'
import { MAccountActor } from '@server/types/models'
-import { AttributesOnly } from '@shared/core-utils'
+import { AttributesOnly, pick } from '@shared/core-utils'
import { ActivityPubActor } from '../../../shared/models/activitypub'
import { VideoChannel, VideoChannelSummary } from '../../../shared/models/videos'
import {
actorId: number
search?: string
host?: string
- names?: string[]
+ handles?: string[]
}
type AvailableWithStatsOptions = {
})
}
- if (options.names) {
- whereActorAnd.push({
- preferredUsername: {
- [Op.in]: options.names
+ let rootWhere: WhereOptions
+ if (options.handles) {
+ const or: WhereOptions[] = []
+
+ for (const handle of options.handles || []) {
+ const [ preferredUsername, host ] = handle.split('@')
+
+ if (!host) {
+ or.push({
+ '$Actor.preferredUsername$': preferredUsername,
+ '$Actor.serverId$': null
+ })
+ } else {
+ or.push({
+ '$Actor.preferredUsername$': preferredUsername,
+ '$Actor.Server.host$': host
+ })
}
- })
+ }
+
+ rootWhere = {
+ [Op.or]: or
+ }
}
return {
+ where: rootWhere,
include: [
{
attributes: {
}
}
- static listForApi (parameters: {
- actorId: number
- start: number
- count: number
- sort: string
- }) {
- const { actorId } = parameters
-
- const query = {
- offset: parameters.start,
- limit: parameters.count,
- order: getSort(parameters.sort)
- }
-
- return VideoChannelModel
- .scope({
- method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ]
- })
- .findAndCountAll(query)
- .then(({ rows, count }) => {
- return { total: count, data: rows }
- })
- }
-
static listLocalsForSitemap (sort: string): Promise<MChannelActor[]> {
const query = {
attributes: [ ],
.findAll(query)
}
- static searchForApi (options: {
- actorId: number
- search?: string
+ static listForApi (parameters: Pick<AvailableForListOptions, 'actorId'> & {
start: number
count: number
sort: string
+ }) {
+ const { actorId } = parameters
+
+ const query = {
+ offset: parameters.start,
+ limit: parameters.count,
+ order: getSort(parameters.sort)
+ }
+
+ return VideoChannelModel
+ .scope({
+ method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ]
+ })
+ .findAndCountAll(query)
+ .then(({ rows, count }) => {
+ return { total: count, data: rows }
+ })
+ }
- host?: string
- names?: string[]
+ static searchForApi (options: Pick<AvailableForListOptions, 'actorId' | 'search' | 'host' | 'handles'> & {
+ start: number
+ count: number
+ sort: string
}) {
let attributesInclude: any[] = [ literal('0 as similarity') ]
let where: WhereOptions
return VideoChannelModel
.scope({
- method: [ ScopeNames.FOR_API, { actorId: options.actorId, host: options.host, names: options.names } as AvailableForListOptions ]
+ method: [ ScopeNames.FOR_API, pick(options, [ 'actorId', 'host', 'handles' ]) as AvailableForListOptions ]
})
.findAndCountAll(query)
.then(({ rows, count }) => {