2022-09-17 18:27:08 +00:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { UserProfilesRepository, NoteReactionsRepository } from '@/models/index.js';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { QueryService } from '@/core/QueryService.js';
|
|
|
|
import { NoteReactionEntityService } from '@/core/entities/NoteReactionEntityService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-02-27 02:07:39 +00:00
|
|
|
import { ApiError } from '../../error.js';
|
2021-10-16 16:33:15 +00:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['users', 'reactions'],
|
|
|
|
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: false,
|
2021-10-16 16:33:15 +00:00
|
|
|
|
2022-06-10 05:25:20 +00:00
|
|
|
description: 'Show all reactions this user made.',
|
|
|
|
|
2021-10-16 16:33:15 +00:00
|
|
|
res: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2021-10-16 16:33:15 +00:00
|
|
|
items: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-10-16 16:33:15 +00:00
|
|
|
ref: 'NoteReaction',
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2021-10-16 16:33:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
2021-10-17 16:16:59 +00:00
|
|
|
reactionsNotPublic: {
|
|
|
|
message: 'Reactions of the user is not public.',
|
|
|
|
code: 'REACTIONS_NOT_PUBLIC',
|
2021-12-09 14:58:30 +00:00
|
|
|
id: '673a7dd2-6924-1093-e0c0-e68456ceae5c',
|
2021-10-17 16:16:59 +00:00
|
|
|
},
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2021-10-16 16:33:15 +00:00
|
|
|
|
2022-02-20 04:15:40 +00:00
|
|
|
export const paramDef = {
|
2022-02-19 05:05:32 +00:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
userId: { type: 'string', format: 'misskey:id' },
|
|
|
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
|
|
|
sinceId: { type: 'string', format: 'misskey:id' },
|
|
|
|
untilId: { type: 'string', format: 'misskey:id' },
|
|
|
|
sinceDate: { type: 'integer' },
|
|
|
|
untilDate: { type: 'integer' },
|
|
|
|
},
|
|
|
|
required: ['userId'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 17:12:50 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 18:27:08 +00:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.userProfilesRepository)
|
|
|
|
private userProfilesRepository: UserProfilesRepository,
|
2021-10-17 16:16:59 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
@Inject(DI.noteReactionsRepository)
|
|
|
|
private noteReactionsRepository: NoteReactionsRepository,
|
|
|
|
|
|
|
|
private noteReactionEntityService: NoteReactionEntityService,
|
|
|
|
private queryService: QueryService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: ps.userId });
|
2021-10-17 16:16:59 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
if (me == null || (me.id !== ps.userId && !profile.publicReactions)) {
|
|
|
|
throw new ApiError(meta.errors.reactionsNotPublic);
|
|
|
|
}
|
2021-10-16 16:33:15 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
const query = this.queryService.makePaginationQuery(this.noteReactionsRepository.createQueryBuilder('reaction'),
|
|
|
|
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
|
|
|
|
.andWhere('reaction.userId = :userId', { userId: ps.userId })
|
|
|
|
.leftJoinAndSelect('reaction.note', 'note');
|
2021-10-16 16:33:15 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
this.queryService.generateVisibilityQuery(query, me);
|
2021-10-16 16:33:15 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
const reactions = await query
|
|
|
|
.take(ps.limit)
|
|
|
|
.getMany();
|
|
|
|
|
|
|
|
return await Promise.all(reactions.map(reaction => this.noteReactionEntityService.pack(reaction, me, { withNote: true })));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|