From 2fb2e523124119a13d045c95da98163b875a6f39 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Fri, 8 Nov 2024 09:55:26 -0500 Subject: [PATCH 1/3] add isPureRenotePacked --- packages/backend/src/misc/is-renote.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/backend/src/misc/is-renote.ts b/packages/backend/src/misc/is-renote.ts index c128fded14..f9209f05b3 100644 --- a/packages/backend/src/misc/is-renote.ts +++ b/packages/backend/src/misc/is-renote.ts @@ -69,6 +69,14 @@ type PackedQuote = fileIds: NonNullable['fileIds']> }); +type PurePackedRenote = PackedRenote & { + text: NonNullable['text']>; + cw: NonNullable['cw']>; + replyId: NonNullable['replyId']>; + poll: NonNullable['poll']>; + fileIds: NonNullable['fileIds']>; +} + export function isRenotePacked(note: Packed<'Note'>): note is PackedRenote { return note.renoteId != null; } @@ -80,3 +88,7 @@ export function isQuotePacked(note: PackedRenote): note is PackedQuote { note.poll != null || (note.fileIds != null && note.fileIds.length > 0); } + +export function isPureRenotePacked(note: Packed<'Note'>): note is PurePackedRenote { + return isRenotePacked(note) && !isQuotePacked(note); +} From faf1b3559a687853d2abd86136815c17b8ea79bc Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Fri, 8 Nov 2024 09:58:15 -0500 Subject: [PATCH 2/3] fix note hiding when renote and target have different visibility settings --- .../src/core/entities/NoteEntityService.ts | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/backend/src/core/entities/NoteEntityService.ts b/packages/backend/src/core/entities/NoteEntityService.ts index 985245aeb1..0d0262d28e 100644 --- a/packages/backend/src/core/entities/NoteEntityService.ts +++ b/packages/backend/src/core/entities/NoteEntityService.ts @@ -16,6 +16,7 @@ import { bindThis } from '@/decorators.js'; import { DebounceLoader } from '@/misc/loader.js'; import { IdService } from '@/core/IdService.js'; import { ReactionsBufferingService } from '@/core/ReactionsBufferingService.js'; +import { isPureRenotePacked } from '@/misc/is-renote.js'; import type { OnModuleInit } from '@nestjs/common'; import type { CacheService } from '../CacheService.js'; import type { CustomEmojiService } from '../CustomEmojiService.js'; @@ -122,29 +123,26 @@ export class NoteEntityService implements OnModuleInit { } else if (packedNote.renote && (meId === packedNote.renote.userId)) { hide = false; } else { - if (packedNote.renote) { - const isFollowing = await this.followingsRepository.exists({ - where: { - followeeId: packedNote.renote.userId, - followerId: meId, - }, - }); + // フォロワーかどうか + const isFollowing = await this.followingsRepository.exists({ + where: { + followeeId: packedNote.userId, + followerId: meId, + }, + }); - hide = !isFollowing; - } else { - // フォロワーかどうか - const isFollowing = await this.followingsRepository.exists({ - where: { - followeeId: packedNote.userId, - followerId: meId, - }, - }); - - hide = !isFollowing; - } + hide = !isFollowing; } } + // If this is a pure renote (boost), then we should *also* check the boosted note's visibility. + // Otherwise we can have empty notes on the timeline, which is not good. + // Notes are packed in depth-first order, so we can safely grab the "isHidden" property to avoid duplicated checks. + // This is pulled out to ensure that we check both the renote *and* the boosted note. + if (packedNote.renote?.isHidden && isPureRenotePacked(packedNote)) { + hide = true; + } + if (!hide && meId && packedNote.userId !== meId) { const isBlocked = (await this.cacheService.userBlockedCache.fetch(meId)).has(packedNote.userId); From 4b503f88e1ee882c3f80ce76f10f42592d646850 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sun, 17 Nov 2024 09:08:04 -0500 Subject: [PATCH 3/3] normalize naming of `isPackedPureRenote` and `PackedPureRenote` --- packages/backend/src/core/entities/NoteEntityService.ts | 4 ++-- packages/backend/src/misc/is-renote.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/core/entities/NoteEntityService.ts b/packages/backend/src/core/entities/NoteEntityService.ts index 0d0262d28e..0d3a0d15b9 100644 --- a/packages/backend/src/core/entities/NoteEntityService.ts +++ b/packages/backend/src/core/entities/NoteEntityService.ts @@ -16,7 +16,7 @@ import { bindThis } from '@/decorators.js'; import { DebounceLoader } from '@/misc/loader.js'; import { IdService } from '@/core/IdService.js'; import { ReactionsBufferingService } from '@/core/ReactionsBufferingService.js'; -import { isPureRenotePacked } from '@/misc/is-renote.js'; +import { isPackedPureRenote } from '@/misc/is-renote.js'; import type { OnModuleInit } from '@nestjs/common'; import type { CacheService } from '../CacheService.js'; import type { CustomEmojiService } from '../CustomEmojiService.js'; @@ -139,7 +139,7 @@ export class NoteEntityService implements OnModuleInit { // Otherwise we can have empty notes on the timeline, which is not good. // Notes are packed in depth-first order, so we can safely grab the "isHidden" property to avoid duplicated checks. // This is pulled out to ensure that we check both the renote *and* the boosted note. - if (packedNote.renote?.isHidden && isPureRenotePacked(packedNote)) { + if (packedNote.renote?.isHidden && isPackedPureRenote(packedNote)) { hide = true; } diff --git a/packages/backend/src/misc/is-renote.ts b/packages/backend/src/misc/is-renote.ts index f9209f05b3..99c755e38f 100644 --- a/packages/backend/src/misc/is-renote.ts +++ b/packages/backend/src/misc/is-renote.ts @@ -69,7 +69,7 @@ type PackedQuote = fileIds: NonNullable['fileIds']> }); -type PurePackedRenote = PackedRenote & { +type PackedPureRenote = PackedRenote & { text: NonNullable['text']>; cw: NonNullable['cw']>; replyId: NonNullable['replyId']>; @@ -89,6 +89,6 @@ export function isQuotePacked(note: PackedRenote): note is PackedQuote { (note.fileIds != null && note.fileIds.length > 0); } -export function isPureRenotePacked(note: Packed<'Note'>): note is PurePackedRenote { +export function isPackedPureRenote(note: Packed<'Note'>): note is PackedPureRenote { return isRenotePacked(note) && !isQuotePacked(note); }