2023-07-27 07:31:52 +02:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2023-09-23 03:00:38 +02:00
|
|
|
import { Brackets, type FindOptionsWhere } from 'typeorm';
|
2023-09-15 07:28:29 +02:00
|
|
|
import type { NoteReactionsRepository } from '@/models/_.js';
|
2023-09-20 04:33:36 +02:00
|
|
|
import type { MiNoteReaction } from '@/models/NoteReaction.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { NoteReactionEntityService } from '@/core/entities/NoteReactionEntityService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-09-23 03:00:38 +02:00
|
|
|
import { QueryService } from '@/core/QueryService.js';
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2018-07-16 21:36:44 +02:00
|
|
|
export const meta = {
|
2019-02-23 03:20:58 +01:00
|
|
|
tags: ['notes', 'reactions'],
|
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: false,
|
2018-07-16 21:36:44 +02:00
|
|
|
|
2022-07-05 12:16:21 +02:00
|
|
|
allowGet: true,
|
|
|
|
cacheSec: 60,
|
|
|
|
|
2019-02-26 21:08:42 +01:00
|
|
|
res: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2019-02-26 21:08:42 +01:00
|
|
|
items: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-04-23 15:35:26 +02:00
|
|
|
ref: 'NoteReaction',
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
2019-02-26 21:08:42 +01:00
|
|
|
},
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
errors: {
|
|
|
|
noSuchNote: {
|
|
|
|
message: 'No such note.',
|
|
|
|
code: 'NO_SUCH_NOTE',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: '263fff3d-d0e1-4af4-bea7-8408059b451a',
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2022-02-19 06:05:32 +01:00
|
|
|
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;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
@Injectable()
|
2023-08-17 14:20:58 +02:00
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
2022-09-17 20:27:08 +02:00
|
|
|
constructor(
|
|
|
|
@Inject(DI.noteReactionsRepository)
|
|
|
|
private noteReactionsRepository: NoteReactionsRepository,
|
2019-09-03 00:25:02 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
private noteReactionEntityService: NoteReactionEntityService,
|
2023-09-23 03:00:38 +02:00
|
|
|
private queryService: QueryService,
|
2022-09-17 20:27:08 +02:00
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
2023-09-23 03:00:38 +02:00
|
|
|
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');
|
2018-10-29 02:52:36 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
if (ps.type) {
|
|
|
|
// ローカルリアクションはホスト名が . とされているが
|
|
|
|
// DB 上ではそうではないので、必要に応じて変換
|
|
|
|
const suffix = '@.:';
|
|
|
|
const type = ps.type.endsWith(suffix) ? ps.type.slice(0, ps.type.length - suffix.length) + ':' : ps.type;
|
2023-09-23 03:00:38 +02:00
|
|
|
query.andWhere('reaction.reaction = :type', { type });
|
2022-09-17 20:27:08 +02:00
|
|
|
}
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2023-09-23 03:00:38 +02:00
|
|
|
const reactions = await query.limit(ps.limit).getMany();
|
2022-09-17 20:27:08 +02:00
|
|
|
|
|
|
|
return await Promise.all(reactions.map(reaction => this.noteReactionEntityService.pack(reaction, me)));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|