From 0ae9085ad8d0588ded395b33c70df699e40616de Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 27 Nov 2023 17:29:30 +0900 Subject: [PATCH 1/3] fix: user note and blocking is not working for featured --- .../server/api/endpoints/notes/featured.ts | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/notes/featured.ts b/packages/backend/src/server/api/endpoints/notes/featured.ts index c2f78e687b51..3ab5b6c0d9dc 100644 --- a/packages/backend/src/server/api/endpoints/notes/featured.ts +++ b/packages/backend/src/server/api/endpoints/notes/featured.ts @@ -10,6 +10,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 { isUserRelated } from '@/misc/is-user-related.js'; +import { CacheService } from '@/core/CacheService.js'; export const meta = { tags: ['notes'], @@ -50,6 +52,7 @@ export default class extends Endpoint { // eslint- private noteEntityService: NoteEntityService, private featuredService: FeaturedService, + private cacheService: CacheService, ) { super(meta, paramDef, async (ps, me) => { let noteIds: string[]; @@ -84,10 +87,32 @@ 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); + let notes = await query.getMany(); + + if (me != null) { + // user mute and blocking + const [ + userIdsWhoMeMuting, + userIdsWhoBlockingMe, + ] = await Promise.all([ + this.cacheService.userMutingsCache.fetch(me.id), + this.cacheService.userBlockedCache.fetch(me.id), + ]); + + notes = notes.filter(note => { + if (note.userId === me.id) { + return true; + } + if (isUserRelated(note, userIdsWhoBlockingMe)) return false; + if (isUserRelated(note, userIdsWhoMeMuting)) return false; + + return true; + }); - // TODO: ミュート等考慮 + // Get next page if notes is empty? + } + + notes.sort((a, b) => a.id > b.id ? -1 : 1); return await this.noteEntityService.packMany(notes, me); }); From 38093d733c4b19a7a100d2792032108dacc6bcb0 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 27 Nov 2023 17:35:18 +0900 Subject: [PATCH 2/3] fix: user note and blocking is not working for user featured --- .../server/api/endpoints/notes/featured.ts | 10 ++---- .../api/endpoints/users/featured-notes.ts | 31 +++++++++++++++++-- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/notes/featured.ts b/packages/backend/src/server/api/endpoints/notes/featured.ts index 3ab5b6c0d9dc..1dce89248627 100644 --- a/packages/backend/src/server/api/endpoints/notes/featured.ts +++ b/packages/backend/src/server/api/endpoints/notes/featured.ts @@ -93,23 +93,17 @@ export default class extends Endpoint { // eslint- // user mute and blocking const [ userIdsWhoMeMuting, - userIdsWhoBlockingMe, ] = await Promise.all([ this.cacheService.userMutingsCache.fetch(me.id), - this.cacheService.userBlockedCache.fetch(me.id), ]); notes = notes.filter(note => { - if (note.userId === me.id) { - return true; - } - if (isUserRelated(note, userIdsWhoBlockingMe)) return false; - if (isUserRelated(note, userIdsWhoMeMuting)) return false; + if (isUserRelated(note, userIdsWhoMeMuting, true)) return false; return true; }); - // Get next page if notes is empty? + // TODO: フィルタで件数が減った場合の埋め合わせ処理 } notes.sort((a, b) => a.id > b.id ? -1 : 1); 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 dec0b7a122e8..df8fa53e762e 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 { isUserRelated } from '@/misc/is-user-related.js'; +import { CacheService } from '@/core/CacheService.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); @@ -69,10 +72,32 @@ 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); + let notes = await query.getMany(); + + if (me != null) { + // user mute and blocking + const [ + userIdsWhoMeMuting, + userIdsWhoBlockingMe, + ] = await Promise.all([ + this.cacheService.userMutingsCache.fetch(me.id), + this.cacheService.userBlockedCache.fetch(me.id), + ]); + + notes = notes.filter(note => { + if (note.userId === me.id) { + return true; + } + if (isUserRelated(note, userIdsWhoBlockingMe, true)) return false; + if (isUserRelated(note, userIdsWhoMeMuting, true)) return false; + + return true; + }); - // TODO: ミュート等考慮 + // Get next page if notes is empty? + } + + notes.sort((a, b) => a.id > b.id ? -1 : 1); return await this.noteEntityService.packMany(notes, me); }); From 8608e2116990c0f75c6f0177eb456fafeea59239 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 27 Nov 2023 17:44:34 +0900 Subject: [PATCH 3/3] =?UTF-8?q?docs(changelog):=20Fix:=20=E3=83=8F?= =?UTF-8?q?=E3=82=A4=E3=83=A9=E3=82=A4=E3=83=88=E3=81=A7=E3=83=A6=E3=83=BC?= =?UTF-8?q?=E3=82=B6=E3=83=9F=E3=83=A5=E3=83=BC=E3=83=88=E3=81=8C=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=81=97=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26c23f5f58dc..b119cc608c54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ ### General - こんにりらみすきー部がハイライトから除外されるようになりました +- Fix: ハイライトでユーザミュートが機能しない問題 ### Client - Fix: ハードミュートにノート引っかかるとエラーが発生しTLが更新されないことがある問題