+ attributes: [ ],
+ offset: 0,
+ order: getSort(sort),
+ include: [
+ {
+ attributes: [ 'preferredUsername', 'serverId' ],
+ model: ActorModel.unscoped(),
+ where: {
+ serverId: null
+ }
+ }
+ ]
+ }
+
+ return VideoChannelModel
+ .unscoped()
+ .findAll(query)
+ }
+
+ static searchForApi (options: {
+ actorId: number
+ search: string
+ start: number
+ count: number
+ sort: string
+ }) {
+ const attributesInclude = []
+ const escapedSearch = VideoModel.sequelize.escape(options.search)
+ const escapedLikeSearch = VideoModel.sequelize.escape('%' + options.search + '%')
+ attributesInclude.push(createSimilarityAttribute('VideoChannelModel.name', options.search))
+
+ const query = {
+ attributes: {
+ include: attributesInclude
+ },
+ offset: options.start,
+ limit: options.count,
+ order: getSort(options.sort),
+ where: {
+ [Op.or]: [
+ Sequelize.literal(
+ 'lower(immutable_unaccent("VideoChannelModel"."name")) % lower(immutable_unaccent(' + escapedSearch + '))'
+ ),
+ Sequelize.literal(
+ 'lower(immutable_unaccent("VideoChannelModel"."name")) LIKE lower(immutable_unaccent(' + escapedLikeSearch + '))'
+ )
+ ]
+ }
+ }
+
+ const scopes = {
+ method: [ ScopeNames.FOR_API, { actorId: options.actorId } as AvailableForListOptions ]
+ }
+ return VideoChannelModel
+ .scope(scopes)
+ .findAndCountAll(query)
+ .then(({ rows, count }) => {
+ return { total: count, data: rows }
+ })
+ }
+
+ static listByAccount (options: {
+ accountId: number,
+ start: number,
+ count: number,
+ sort: string
+ }) {
+ const query = {
+ offset: options.start,
+ limit: options.count,
+ order: getSort(options.sort),