2022-09-17 21:27:08 +03: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 04:07:39 +02:00
|
|
|
import { ApiError } from '../../error.js';
|
2021-10-16 19:33:15 +03:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['users', 'reactions'],
|
|
|
|
|
2022-01-18 15:27:10 +02:00
|
|
|
requireCredential: false,
|
2021-10-16 19:33:15 +03:00
|
|
|
|
2022-06-10 08:25:20 +03:00
|
|
|
description: 'Show all reactions this user made.',
|
|
|
|
|
2021-10-16 19:33:15 +03:00
|
|
|
res: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2021-10-16 19:33:15 +03:00
|
|
|
items: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-10-16 19:33:15 +03:00
|
|
|
ref: 'NoteReaction',
|
2021-12-09 16:58:30 +02:00
|
|
|
},
|
2021-10-16 19:33:15 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
2021-10-17 19:16:59 +03:00
|
|
|
reactionsNotPublic: {
|
|
|
|
message: 'Reactions of the user is not public.',
|
|
|
|
code: 'REACTIONS_NOT_PUBLIC',
|
2021-12-09 16:58:30 +02:00
|
|
|
id: '673a7dd2-6924-1093-e0c0-e68456ceae5c',
|
2021-10-17 19:16:59 +03:00
|
|
|
},
|
2021-12-09 16:58:30 +02:00
|
|
|
},
|
2022-01-18 15:27:10 +02:00
|
|
|
} as const;
|
2021-10-16 19:33:15 +03:00
|
|
|
|
2022-02-20 06:15:40 +02:00
|
|
|
export const paramDef = {
|
2022-02-19 07:05:32 +02: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 19:12:50 +02:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 21:27:08 +03:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.userProfilesRepository)
|
|
|
|
private userProfilesRepository: UserProfilesRepository,
|
2021-10-17 19:16:59 +03:00
|
|
|
|
2022-09-17 21:27:08 +03: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 19:16:59 +03:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
if (me == null || (me.id !== ps.userId && !profile.publicReactions)) {
|
|
|
|
throw new ApiError(meta.errors.reactionsNotPublic);
|
|
|
|
}
|
2021-10-16 19:33:15 +03:00
|
|
|
|
2022-09-17 21:27:08 +03: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 19:33:15 +03:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
this.queryService.generateVisibilityQuery(query, me);
|
2021-10-16 19:33:15 +03:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
const reactions = await query
|
|
|
|
.take(ps.limit)
|
|
|
|
.getMany();
|
|
|
|
|
|
|
|
return await Promise.all(reactions.map(reaction => this.noteReactionEntityService.pack(reaction, me, { withNote: true })));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|