mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-05 11:36:56 +00:00
# Conflicts: # .github/workflows/api-misskey-js.yml # .github/workflows/changelog-check.yml # .github/workflows/check-misskey-js-autogen.yml # .github/workflows/get-api-diff.yml # .github/workflows/lint.yml # .github/workflows/locale.yml # .github/workflows/on-release-created.yml # .github/workflows/storybook.yml # .github/workflows/test-backend.yml # .github/workflows/test-federation.yml # .github/workflows/test-frontend.yml # .github/workflows/test-misskey-js.yml # .github/workflows/test-production.yml # .github/workflows/validate-api-json.yml # package.json # packages/backend/package.json # packages/backend/src/server/api/ApiCallService.ts # packages/backend/src/server/api/endpoints/drive/files/create.ts # packages/frontend-shared/js/url.ts # packages/frontend/package.json # packages/frontend/src/components/MkFileCaptionEditWindow.vue # packages/frontend/src/components/MkInfo.vue # packages/frontend/src/components/MkLink.vue # packages/frontend/src/components/MkNote.vue # packages/frontend/src/components/MkNotes.vue # packages/frontend/src/components/MkPageWindow.vue # packages/frontend/src/components/MkReactionsViewer.vue # packages/frontend/src/components/MkTimeline.vue # packages/frontend/src/components/MkUrlPreview.vue # packages/frontend/src/components/MkUserPopup.vue # packages/frontend/src/components/global/MkPageHeader.vue # packages/frontend/src/components/global/MkUrl.vue # packages/frontend/src/components/global/PageWithHeader.vue # packages/frontend/src/pages/about-misskey.vue # packages/frontend/src/pages/announcements.vue # packages/frontend/src/pages/antenna-timeline.vue # packages/frontend/src/pages/channel.vue # packages/frontend/src/pages/instance-info.vue # packages/frontend/src/pages/note.vue # packages/frontend/src/pages/page.vue # packages/frontend/src/pages/role.vue # packages/frontend/src/pages/tag.vue # packages/frontend/src/pages/timeline.vue # packages/frontend/src/pages/user-list-timeline.vue # packages/frontend/src/pages/user/followers.vue # packages/frontend/src/pages/user/following.vue # packages/frontend/src/pages/user/home.vue # packages/frontend/src/pages/user/index.vue # packages/frontend/src/ui/deck.vue # packages/misskey-js/generator/package.json # pnpm-lock.yaml # scripts/changelog-checker/package-lock.json # scripts/changelog-checker/package.json
126 lines
4.3 KiB
TypeScript
126 lines
4.3 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import type { UserProfilesRepository, NoteReactionsRepository } from '@/models/_.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';
|
|
import { CacheService } from '@/core/CacheService.js';
|
|
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
|
import { RoleService } from '@/core/RoleService.js';
|
|
import { isUserRelated } from '@/misc/is-user-related.js';
|
|
import { ApiError } from '../../error.js';
|
|
|
|
export const meta = {
|
|
tags: ['users', 'reactions'],
|
|
|
|
requireCredential: false,
|
|
|
|
description: 'Show all reactions this user made.',
|
|
|
|
res: {
|
|
type: 'array',
|
|
optional: false, nullable: false,
|
|
items: {
|
|
type: 'object',
|
|
optional: false, nullable: false,
|
|
ref: 'NoteReaction',
|
|
},
|
|
},
|
|
|
|
errors: {
|
|
reactionsNotPublic: {
|
|
message: 'Reactions of the user is not public.',
|
|
code: 'REACTIONS_NOT_PUBLIC',
|
|
id: '673a7dd2-6924-1093-e0c0-e68456ceae5c',
|
|
},
|
|
isRemoteUser: {
|
|
message: 'Currently unavailable to display reactions of remote users. See https://github.com/misskey-dev/misskey/issues/12964',
|
|
code: 'IS_REMOTE_USER',
|
|
id: '6b95fa98-8cf9-2350-e284-f0ffdb54a805',
|
|
},
|
|
},
|
|
|
|
// 5 calls per second
|
|
limit: {
|
|
duration: 1000,
|
|
max: 2,
|
|
},
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
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;
|
|
|
|
@Injectable()
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
|
constructor(
|
|
@Inject(DI.userProfilesRepository)
|
|
private userProfilesRepository: UserProfilesRepository,
|
|
|
|
@Inject(DI.noteReactionsRepository)
|
|
private noteReactionsRepository: NoteReactionsRepository,
|
|
|
|
private cacheService: CacheService,
|
|
private userEntityService: UserEntityService,
|
|
private noteReactionEntityService: NoteReactionEntityService,
|
|
private queryService: QueryService,
|
|
private roleService: RoleService,
|
|
) {
|
|
super(meta, paramDef, async (ps, me) => {
|
|
const userIdsWhoBlockingMe = me ? await this.cacheService.userBlockedCache.fetch(me.id) : new Set<string>();
|
|
const iAmModerator = me ? await this.roleService.isModerator(me) : false; // Moderators can see reactions of all users
|
|
if (!iAmModerator) {
|
|
const user = await this.cacheService.findUserById(ps.userId);
|
|
if (this.userEntityService.isRemoteUser(user)) {
|
|
throw new ApiError(meta.errors.isRemoteUser);
|
|
}
|
|
|
|
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: ps.userId });
|
|
if ((me == null || me.id !== ps.userId) && !profile.publicReactions) {
|
|
throw new ApiError(meta.errors.reactionsNotPublic);
|
|
}
|
|
|
|
// early return if me is blocked by requesting user
|
|
if (userIdsWhoBlockingMe.has(ps.userId)) {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
const userIdsWhoMeMuting = me ? await this.cacheService.userMutingsCache.fetch(me.id) : new Set<string>();
|
|
|
|
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');
|
|
|
|
this.queryService.generateVisibilityQuery(query, me);
|
|
this.queryService.generateBlockedHostQueryForNote(query);
|
|
|
|
const reactions = (await query
|
|
.limit(ps.limit)
|
|
.getMany()).filter(reaction => {
|
|
if (reaction.note?.userId === ps.userId) return true; // we can see reactions to note of requesting user
|
|
if (me && isUserRelated(reaction.note, userIdsWhoBlockingMe)) return false;
|
|
if (me && isUserRelated(reaction.note, userIdsWhoMeMuting)) return false;
|
|
|
|
return true;
|
|
});
|
|
|
|
return await this.noteReactionEntityService.packMany(reactions, me, { withNote: true });
|
|
});
|
|
}
|
|
}
|