From 3dd3c693039e94eeddf38a7d0caa33400e42704a Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 1 Oct 2023 20:25:51 +0900 Subject: [PATCH] wip --- .../server/api/endpoints/notes/timeline.ts | 26 ++++++++-------- .../api/endpoints/notes/user-list-timeline.ts | 30 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/notes/timeline.ts b/packages/backend/src/server/api/endpoints/notes/timeline.ts index e7e796cd19..a261665ab8 100644 --- a/packages/backend/src/server/api/endpoints/notes/timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/timeline.ts @@ -14,6 +14,7 @@ import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import { DI } from '@/di-symbols.js'; import { IdService } from '@/core/IdService.js'; import { CacheService } from '@/core/CacheService.js'; +import { isUserRelated } from '@/misc/is-user-related.js'; export const meta = { tags: ['notes'], @@ -64,7 +65,13 @@ export default class extends Endpoint { // eslint- private cacheService: CacheService, ) { super(meta, paramDef, async (ps, me) => { - const mutings = await this.cacheService.userMutingsCache.fetch(me.id); + const [ + userIdsWhoMeMuting, + userIdsWhoMeMutingRenotes, + ] = await Promise.all([ + this.cacheService.userMutingsCache.fetch(me.id), + this.cacheService.renoteMutingsCache.fetch(me.id), + ]); let timeline: MiNote[] = []; @@ -99,22 +106,17 @@ export default class extends Endpoint { // eslint- // ミュート等考慮 timeline = timeline.filter(note => { // TODO: インスタンスミュートの考慮 - // TODO: リノートミュートの考慮 if (note.userId === me.id) { return true; } - if (note.renote) { - if (mutings.has(note.renote.userId)) return false; - } - - if (note.reply) { - if (mutings.has(note.reply.userId)) return false; - } - - if (ps.withRenotes === false) { - if (note.renoteId && note.text == null && note.fileIds.length === 0 && !note.hasPoll) return false; + if (isUserRelated(note, userIdsWhoMeMuting)) return false; + if (note.renoteId) { + if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) { + if (isUserRelated(note, userIdsWhoMeMutingRenotes)) return false; + if (ps.withRenotes === false) return false; + } } return true; diff --git a/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts b/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts index 1de94d268b..806b006f43 100644 --- a/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts @@ -14,6 +14,7 @@ import ActiveUsersChart from '@/core/chart/charts/active-users.js'; import { DI } from '@/di-symbols.js'; import { CacheService } from '@/core/CacheService.js'; import { IdService } from '@/core/IdService.js'; +import { isUserRelated } from '@/misc/is-user-related.js'; import { ApiError } from '../../error.js'; export const meta = { @@ -90,7 +91,13 @@ export default class extends Endpoint { // eslint- throw new ApiError(meta.errors.noSuchList); } - const mutings = await this.cacheService.userMutingsCache.fetch(me.id); + const [ + userIdsWhoMeMuting, + userIdsWhoMeMutingRenotes, + ] = await Promise.all([ + this.cacheService.userMutingsCache.fetch(me.id), + this.cacheService.renoteMutingsCache.fetch(me.id), + ]); let timeline: MiNote[] = []; @@ -125,22 +132,13 @@ export default class extends Endpoint { // eslint- // ミュート等考慮 timeline = timeline.filter(note => { // TODO: インスタンスミュートの考慮 - // TODO: リノートミュートの考慮 - if (note.userId === me.id) { - return true; - } - - if (note.renote) { - if (mutings.has(note.renote.userId)) return false; - } - - if (note.reply) { - if (mutings.has(note.reply.userId)) return false; - } - - if (ps.withRenotes === false) { - if (note.renoteId && note.text == null && note.fileIds.length === 0 && !note.hasPoll) return false; + if (isUserRelated(note, userIdsWhoMeMuting)) return false; + if (note.renoteId) { + if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) { + if (isUserRelated(note, userIdsWhoMeMutingRenotes)) return false; + if (ps.withRenotes === false) return false; + } } return true;