enhance(backend): 検索・ハイライト機能でミュート・ブロックが適用されるように (MisskeyIO#271)

This commit is contained in:
まっちゃとーにゅ 2023-12-04 02:54:50 +09:00 committed by GitHub
parent 61f3854c52
commit 3097bce214
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 11 deletions

View file

@ -10,6 +10,8 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { DI } from '@/di-symbols.js';
import { GetterService } from '@/server/api/GetterService.js';
import { CacheService } from '@/core/CacheService.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import { ApiError } from '../../error.js';
export const meta = {
@ -54,6 +56,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private noteEntityService: NoteEntityService,
private getterService: GetterService,
private cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
const note = await this.getterService.getNote(ps.noteId).catch(err => {
@ -61,13 +64,21 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw err;
});
const [
userIdsWhoMeMuting,
userIdsWhoBlockingMe,
] = me ? await Promise.all([
this.cacheService.userMutingsCache.fetch(me.id),
this.cacheService.userBlockedCache.fetch(me.id),
]) : [new Set<string>(), new Set<string>()];
const conversation: MiNote[] = [];
let i = 0;
const get = async (id: any) => {
i++;
const p = await this.notesRepository.findOneBy({ id });
if (p == null) return;
if (p == null || (me && (isUserRelated(note, userIdsWhoBlockingMe) || isUserRelated(note, userIdsWhoMeMuting)))) return;
if (i > ps.offset!) {
conversation.push(p);