From f03ac4417a1c8bb235b76eebd241d2a8872f574a Mon Sep 17 00:00:00 2001 From: atsu1125 Date: Sun, 20 Nov 2022 14:47:38 +0900 Subject: [PATCH] Change: Only moderators can show blocked user's post --- packages/backend/src/server/api/common/inject-featured.ts | 2 ++ packages/backend/src/server/api/endpoints/notes/children.ts | 4 +++- packages/backend/src/server/api/endpoints/notes/featured.ts | 4 +++- .../src/server/api/endpoints/notes/global-timeline.ts | 4 ++++ .../src/server/api/endpoints/notes/hybrid-timeline.ts | 5 ++++- .../backend/src/server/api/endpoints/notes/local-timeline.ts | 4 ++++ packages/backend/src/server/api/endpoints/notes/renotes.ts | 4 +++- packages/backend/src/server/api/endpoints/notes/replies.ts | 4 +++- .../backend/src/server/api/endpoints/notes/search-by-tag.ts | 4 +++- packages/backend/src/server/api/endpoints/notes/search.ts | 4 +++- packages/backend/src/server/api/endpoints/users/notes.ts | 4 ++++ .../src/server/api/stream/channels/global-timeline.ts | 3 +++ .../src/server/api/stream/channels/hybrid-timeline.ts | 2 +- .../backend/src/server/api/stream/channels/local-timeline.ts | 2 ++ 14 files changed, 42 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/server/api/common/inject-featured.ts b/packages/backend/src/server/api/common/inject-featured.ts index 1dc13c83ef4e..46b9d174383b 100644 --- a/packages/backend/src/server/api/common/inject-featured.ts +++ b/packages/backend/src/server/api/common/inject-featured.ts @@ -30,7 +30,9 @@ export async function injectFeatured(timeline: Note[], user?: User | null) { query.andWhere('note.userId != :userId', { userId: user.id }); generateMutedUserQuery(query, user); + if (!user.isAdmin && !user.isModerator) { generateBlockedUserQuery(query, user); + } const reactionQuery = NoteReactions.createQueryBuilder('reaction') .select('reaction.noteId') diff --git a/packages/backend/src/server/api/endpoints/notes/children.ts b/packages/backend/src/server/api/endpoints/notes/children.ts index 088ef65e9602..cb4720651bed 100644 --- a/packages/backend/src/server/api/endpoints/notes/children.ts +++ b/packages/backend/src/server/api/endpoints/notes/children.ts @@ -66,7 +66,9 @@ export default define(meta, async (ps, user) => { generateVisibilityQuery(query, user); if (user) generateMutedUserQuery(query, user); - if (user) generateBlockedUserQuery(query, user); + if (user && !user.isAdmin && !user.isModerator) { + generateBlockedUserQuery(query, user); + } if (user) generateMutedInstanceQuery(query, user); const notes = await query.take(ps.limit!).getMany(); diff --git a/packages/backend/src/server/api/endpoints/notes/featured.ts b/packages/backend/src/server/api/endpoints/notes/featured.ts index 5a47fb9e080c..281e307f8761 100644 --- a/packages/backend/src/server/api/endpoints/notes/featured.ts +++ b/packages/backend/src/server/api/endpoints/notes/featured.ts @@ -50,7 +50,9 @@ export default define(meta, async (ps, user) => { .leftJoinAndSelect('renote.user', 'renoteUser'); if (user) generateMutedUserQuery(query, user); - if (user) generateBlockedUserQuery(query, user); + if (user && !user.isAdmin && !user.isModerator) { + generateBlockedUserQuery(query, user); + } let notes = await query .orderBy('note.score', 'DESC') diff --git a/packages/backend/src/server/api/endpoints/notes/global-timeline.ts b/packages/backend/src/server/api/endpoints/notes/global-timeline.ts index d0c3d043a09c..5f03dc27045b 100644 --- a/packages/backend/src/server/api/endpoints/notes/global-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/global-timeline.ts @@ -86,6 +86,10 @@ export default define(meta, async (ps, user) => { if (user) generateMutedNoteQuery(query, user); if (user) generateMutedInstanceQuery(query, user); + if (user && !user.isAdmin && !user.isModerator) { + generateBlockedUserQuery(query, user); + } + if (ps.withFiles) { query.andWhere('note.fileIds != \'{}\''); } diff --git a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts index 9683df4611e5..00a5bbc131ea 100644 --- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts @@ -112,7 +112,10 @@ export default define(meta, async (ps, user) => { generateMutedUserQuery(query, user); generateMutedInstanceQuery(query, user); generateMutedNoteQuery(query, user); - generateBlockedUserQuery(query, user); + + if (!user.isAdmin && !user.isModerator) { + generateBlockedUserQuery(query, user); + } if (ps.includeMyRenotes === false) { query.andWhere(new Brackets(qb => { diff --git a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts index a6d22b2ee864..ec83fa50856a 100644 --- a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts @@ -97,6 +97,10 @@ export default define(meta, async (ps, user) => { if (user) generateMutedUserQuery(query, user); if (user) generateMutedNoteQuery(query, user); + if (user && !user.isAdmin && !user.isModerator) { + generateBlockedUserQuery(query, user); + } + if (ps.withFiles) { query.andWhere('note.fileIds != \'{}\''); } diff --git a/packages/backend/src/server/api/endpoints/notes/renotes.ts b/packages/backend/src/server/api/endpoints/notes/renotes.ts index f71d23146a31..2f8aaeabfa55 100644 --- a/packages/backend/src/server/api/endpoints/notes/renotes.ts +++ b/packages/backend/src/server/api/endpoints/notes/renotes.ts @@ -69,7 +69,9 @@ export default define(meta, async (ps, user) => { generateVisibilityQuery(query, user); if (user) generateMutedUserQuery(query, user); - if (user) generateBlockedUserQuery(query, user); + if (user && !user.isAdmin && !user.isModerator) { + generateBlockedUserQuery(query, me); + } const renotes = await query.take(ps.limit!).getMany(); diff --git a/packages/backend/src/server/api/endpoints/notes/replies.ts b/packages/backend/src/server/api/endpoints/notes/replies.ts index 62c56534e100..3e3eb30a76ff 100644 --- a/packages/backend/src/server/api/endpoints/notes/replies.ts +++ b/packages/backend/src/server/api/endpoints/notes/replies.ts @@ -54,7 +54,9 @@ export default define(meta, async (ps, user) => { generateVisibilityQuery(query, user); if (user) generateMutedUserQuery(query, user); - if (user) generateBlockedUserQuery(query, user); + if (user && !user.isAdmin && !user.isModerator) { + generateBlockedUserQuery(query, user); + } const timeline = await query.take(ps.limit!).getMany(); diff --git a/packages/backend/src/server/api/endpoints/notes/search-by-tag.ts b/packages/backend/src/server/api/endpoints/notes/search-by-tag.ts index 87eaffe2f10d..c4bbfe194bf8 100644 --- a/packages/backend/src/server/api/endpoints/notes/search-by-tag.ts +++ b/packages/backend/src/server/api/endpoints/notes/search-by-tag.ts @@ -77,7 +77,9 @@ export default define(meta, async (ps, me) => { generateVisibilityQuery(query, me); if (me) generateMutedUserQuery(query, me); - if (me) generateBlockedUserQuery(query, me); + if (me && !me.isAdmin && !me.isModerator) { + generateBlockedUserQuery(query, me); + } try { if (ps.tag) { diff --git a/packages/backend/src/server/api/endpoints/notes/search.ts b/packages/backend/src/server/api/endpoints/notes/search.ts index e75212b14ba1..313a966a19f0 100644 --- a/packages/backend/src/server/api/endpoints/notes/search.ts +++ b/packages/backend/src/server/api/endpoints/notes/search.ts @@ -84,7 +84,9 @@ export default define(meta, async (ps, me) => { generateVisibilityQuery(query, me); if (me) generateMutedUserQuery(query, me); - if (me) generateBlockedUserQuery(query, me); + if (me && !me.isAdmin && !me.isModerator) { + generateBlockedUserQuery(query, me); + } const notes = await query.take(ps.limit!).getMany(); diff --git a/packages/backend/src/server/api/endpoints/users/notes.ts b/packages/backend/src/server/api/endpoints/users/notes.ts index 1c51d6b6aeab..4c23027dd234 100644 --- a/packages/backend/src/server/api/endpoints/users/notes.ts +++ b/packages/backend/src/server/api/endpoints/users/notes.ts @@ -105,6 +105,10 @@ export default define(meta, async (ps, me) => { if (me) generateMutedUserQuery(query, me, user); if (me) generateMutedInstanceQuery(query, me); + if (me && !me.isAdmin && !me.isModerator) { + generateBlockedUserQuery(query, me); + } + if (ps.withFiles) { query.andWhere('note.fileIds != \'{}\''); } diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts index 960c8e5a7a3c..755696bb1e15 100644 --- a/packages/backend/src/server/api/stream/channels/global-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts @@ -55,6 +55,9 @@ export default class extends Channel { // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する if (isMutedUserRelated(note, this.muting)) return; + // 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する + if (!this.user.isAdmin && !this.user.isModerator && isBlockerUserRelated(note, this.blocking)) return; + // 流れてきたNoteがミュートすべきNoteだったら無視する // TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある) // 現状では、ワードミュートにおけるMutedNoteレコードの追加処理はストリーミングに流す処理と並列で行われるため、 diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts index 0ae19aa7ce85..15a89098a1f2 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -71,7 +71,7 @@ export default class extends Channel { // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する if (isMutedUserRelated(note, this.muting)) return; // 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する - if (isBlockerUserRelated(note, this.blocking)) return; + if (!this.user.isAdmin && !this.user.isModerator && isBlockerUserRelated(note, this.blocking)) return; // 流れてきたNoteがミュートすべきNoteだったら無視する // TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある) diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts index ff1300812291..3f88b59811a0 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -51,6 +51,8 @@ export default class extends Channel { // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する if (isMutedUserRelated(note, this.muting)) return; + // 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する + if (!this.user.isAdmin && !this.user.isModerator && isBlockerUserRelated(note, this.blocking)) return; // 流れてきたNoteがミュートすべきNoteだったら無視する // TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある)