Newer
Older
/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Brackets, type FindOptionsWhere } from 'typeorm';
import type { NoteReactionsRepository } from '@/models/_.js';
import type { MiNoteReaction } from '@/models/NoteReaction.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { NoteReactionEntityService } from '@/core/entities/NoteReactionEntityService.js';
import { DI } from '@/di-symbols.js';
import { QueryService } from '@/core/QueryService.js';
type: 'array',
optional: false, nullable: false,
type: 'object',
optional: false, nullable: false,
errors: {
noSuchNote: {
message: 'No such note.',
code: 'NO_SUCH_NOTE',
type: 'object',
properties: {
noteId: { type: 'string', format: 'misskey:id' },
type: { type: 'string', nullable: true },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
},
required: ['noteId'],
} as const;
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
@Inject(DI.noteReactionsRepository)
private noteReactionsRepository: NoteReactionsRepository,
private queryService: QueryService,
const query = this.queryService.makePaginationQuery(this.noteReactionsRepository.createQueryBuilder('reaction'), ps.sinceId, ps.untilId)
.andWhere('reaction.noteId = :noteId', { noteId: ps.noteId })
.leftJoinAndSelect('reaction.user', 'user')
.leftJoinAndSelect('reaction.note', 'note');
if (ps.type) {
// ローカルリアクションはホスト名が . とされているが
// DB 上ではそうではないので、必要に応じて変換
const suffix = '@.:';
const type = ps.type.endsWith(suffix) ? ps.type.slice(0, ps.type.length - suffix.length) + ':' : ps.type;
query.andWhere('reaction.reaction = :type', { type });
const reactions = await query.limit(ps.limit).getMany();