From ca515d5a7ea164582c4917c0e1f01aa66c5b6a13 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 4 Oct 2023 16:43:24 +0900 Subject: [PATCH] tweak timelines --- packages/backend/src/misc/is-user-related.ts | 4 ++-- packages/backend/src/server/api/endpoints/users/notes.ts | 9 +++++++++ packages/backend/test/e2e/timelines.ts | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/misc/is-user-related.ts b/packages/backend/src/misc/is-user-related.ts index edd65a3c1c..ae8f4116cc 100644 --- a/packages/backend/src/misc/is-user-related.ts +++ b/packages/backend/src/misc/is-user-related.ts @@ -3,8 +3,8 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -export function isUserRelated(note: any, userIds: Set): boolean { - if (userIds.has(note.userId)) { +export function isUserRelated(note: any, userIds: Set, ignoreAuthor = false): boolean { + if (userIds.has(note.userId) && !ignoreAuthor) { return true; } diff --git a/packages/backend/src/server/api/endpoints/users/notes.ts b/packages/backend/src/server/api/endpoints/users/notes.ts index 6be391be4e..09adcf20aa 100644 --- a/packages/backend/src/server/api/endpoints/users/notes.ts +++ b/packages/backend/src/server/api/endpoints/users/notes.ts @@ -13,6 +13,7 @@ import { DI } from '@/di-symbols.js'; import { GetterService } from '@/server/api/GetterService.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 = { @@ -70,6 +71,12 @@ export default class extends Endpoint { // eslint- private idService: IdService, ) { super(meta, paramDef, async (ps, me) => { + const [ + userIdsWhoMeMuting, + ] = me ? await Promise.all([ + this.cacheService.userMutingsCache.fetch(me.id), + ]) : [new Set()]; + let timeline: MiNote[] = []; const limit = ps.limit + (ps.untilId ? 1 : 0); // untilIdに指定したものも含まれるため+1 @@ -118,6 +125,8 @@ export default class extends Endpoint { // eslint- timeline = await query.getMany(); timeline = timeline.filter(note => { + if (me && isUserRelated(note, userIdsWhoMeMuting, true)) return false; + if (note.renoteId) { if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) { if (ps.withRenotes === false) return false; diff --git a/packages/backend/test/e2e/timelines.ts b/packages/backend/test/e2e/timelines.ts index 08af5bf97a..d606c6729b 100644 --- a/packages/backend/test/e2e/timelines.ts +++ b/packages/backend/test/e2e/timelines.ts @@ -16,7 +16,7 @@ function genHost() { } function waitForPushToTl() { - return sleep(100); + return sleep(300); } let app: INestApplicationContext;