From e6d01e33e6b539dca784c5309158ae80836fac27 Mon Sep 17 00:00:00 2001 From: KanariKanaru <93921745+kanarikanaru@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:15:38 +0900 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E3=83=96=E3=83=AD=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=81=97=E3=81=9F=E7=9B=B8=E6=89=8B=E3=81=8B=E3=82=89?= =?UTF-8?q?=E8=87=AA=E5=88=86=E3=81=AE=E3=83=8E=E3=83=BC=E3=83=88=E3=81=8C?= =?UTF-8?q?=E8=A6=8B=E3=81=88=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?(/users/featured-notes,=20/users/notes)=20(#12511)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: ブロックした相手から自分のノートが見えないように(ユーザー,チャンネル) * Update CHANGELOG.md * /users/featured-notesでもブロックを考慮するように * cacheServiceを使うように * /channels/timeline.tsで必要のないnoteFilterを持たないように * Update CHANGELOG.md * FanoutTimelineEndpointServiceへの対応 - ブロックされている場合は、/users/notesでノートが表示されない - ミュートしている場合は、ノートが表示される --- CHANGELOG.md | 1 + .../src/core/FanoutTimelineEndpointService.ts | 3 ++- .../api/endpoints/users/featured-notes.ts | 21 ++++++++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cba7a05ae..7352db8fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ - Fix: ユーザのノート一覧にてインスタンスミュートが効かない問題 - Fix: チャンネルのノート一覧にてインスタンスミュートが効かない問題 - Fix: 「みつける」が年越し時に壊れる問題を修正 +- Fix: アカウントをブロックした際に、自身のユーザーのページでノートが相手に表示される問題を修正 ## 2023.11.1 diff --git a/packages/backend/src/core/FanoutTimelineEndpointService.ts b/packages/backend/src/core/FanoutTimelineEndpointService.ts index a5bf29727..11027960f 100644 --- a/packages/backend/src/core/FanoutTimelineEndpointService.ts +++ b/packages/backend/src/core/FanoutTimelineEndpointService.ts @@ -28,6 +28,7 @@ type TimelineOptions = { redisTimelines: FanoutTimelineName[], noteFilter?: (note: MiNote) => boolean, alwaysIncludeMyNotes?: boolean; + ignoreAuthorFromBlock?: boolean; ignoreAuthorFromMute?: boolean; excludeNoFiles?: boolean; excludeReplies?: boolean; @@ -113,7 +114,7 @@ export class FanoutTimelineEndpointService { const parentFilter = filter; filter = (note) => { - if (isUserRelated(note, userIdsWhoBlockingMe, ps.ignoreAuthorFromMute)) return false; + if (isUserRelated(note, userIdsWhoBlockingMe, ps.ignoreAuthorFromBlock)) return false; if (isUserRelated(note, userIdsWhoMeMuting, ps.ignoreAuthorFromMute)) return false; if (isPureRenote(note) && isUserRelated(note, userIdsWhoMeMutingRenotes, ps.ignoreAuthorFromMute)) return false; if (isInstanceMuted(note, userMutedInstances)) return false; diff --git a/packages/backend/src/server/api/endpoints/users/featured-notes.ts b/packages/backend/src/server/api/endpoints/users/featured-notes.ts index dec0b7a12..f84148d72 100644 --- a/packages/backend/src/server/api/endpoints/users/featured-notes.ts +++ b/packages/backend/src/server/api/endpoints/users/featured-notes.ts @@ -9,6 +9,8 @@ import { Endpoint } from '@/server/api/endpoint-base.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import { DI } from '@/di-symbols.js'; import { FeaturedService } from '@/core/FeaturedService.js'; +import { CacheService } from '@/core/CacheService.js'; +import { isUserRelated } from '@/misc/is-user-related.js'; export const meta = { tags: ['notes'], @@ -46,6 +48,7 @@ export default class extends Endpoint { // eslint- private noteEntityService: NoteEntityService, private featuredService: FeaturedService, + private cacheService: CacheService, ) { super(meta, paramDef, async (ps, me) => { let noteIds = await this.featuredService.getPerUserNotesRanking(ps.userId, 50); @@ -60,6 +63,14 @@ export default class extends Endpoint { // eslint- return []; } + const [ + userIdsWhoMeMuting, + userIdsWhoBlockingMe, + ] = me ? await Promise.all([ + this.cacheService.userMutingsCache.fetch(me.id), + this.cacheService.userBlockedCache.fetch(me.id), + ]) : [new Set(), new Set()]; + const query = this.notesRepository.createQueryBuilder('note') .where('note.id IN (:...noteIds)', { noteIds: noteIds }) .innerJoinAndSelect('note.user', 'user') @@ -69,10 +80,14 @@ export default class extends Endpoint { // eslint- .leftJoinAndSelect('renote.user', 'renoteUser') .leftJoinAndSelect('note.channel', 'channel'); - const notes = await query.getMany(); - notes.sort((a, b) => a.id > b.id ? -1 : 1); + const notes = (await query.getMany()).filter(note => { + if (me && isUserRelated(note, userIdsWhoBlockingMe, false)) return false; + if (me && isUserRelated(note, userIdsWhoMeMuting, true)) return false; - // TODO: ミュート等考慮 + return true; + }); + + notes.sort((a, b) => a.id > b.id ? -1 : 1); return await this.noteEntityService.packMany(notes, me); });