From 90f8d8e575fadd60792514151610305bfb52a77b Mon Sep 17 00:00:00 2001 From: Marie Date: Thu, 21 Dec 2023 22:24:23 +0100 Subject: [PATCH] upd: fix tag view not respecting blocks and suspensions Closes #234 --- .../api/endpoints/notes/search-by-tag.ts | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) 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 bc33d6948..89e05fd57 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 @@ -13,6 +13,8 @@ import { QueryService } from '@/core/QueryService.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import { DI } from '@/di-symbols.js'; import { MetaService } from '@/core/MetaService.js'; +import { CacheService } from '@/core/CacheService.js'; +import { UtilityService } from '@/core/UtilityService.js'; export const meta = { tags: ['notes', 'hashtags'], @@ -73,23 +75,32 @@ export default class extends Endpoint { // eslint- private noteEntityService: NoteEntityService, private queryService: QueryService, private metaService: MetaService, + private cacheService: CacheService, + private utilityService: UtilityService, ) { super(meta, paramDef, async (ps, me) => { + const meta = await this.metaService.fetch(true); + const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId) + .andWhere('note.visibility = \'public\'') .innerJoinAndSelect('note.user', 'user') .leftJoinAndSelect('note.reply', 'reply') .leftJoinAndSelect('note.renote', 'renote') .leftJoinAndSelect('reply.user', 'replyUser') .leftJoinAndSelect('renote.user', 'renoteUser'); - const meta = await this.metaService.fetch(true); - if (!meta.enableBotTrending) query.andWhere('user.isBot = FALSE'); this.queryService.generateVisibilityQuery(query, me); if (me) this.queryService.generateMutedUserQuery(query, me); if (me) this.queryService.generateBlockedUserQuery(query, me); + const [ + followings, + ] = me ? await Promise.all([ + this.cacheService.userFollowingsCache.fetch(me.id), + ]) : [undefined]; + try { if (ps.tag) { if (!safeForSql(normalizeForSearch(ps.tag))) throw new Error('Injection'); @@ -140,7 +151,15 @@ export default class extends Endpoint { // eslint- } // Search notes - const notes = await query.limit(ps.limit).getMany(); + let notes = await query.limit(ps.limit).getMany(); + + notes = notes.filter(note => { + if (note.user?.isSilenced && me && followings && note.userId !== me.id && !followings[note.userId]) return false; + if (note.user?.isSuspended) return false; + if (this.utilityService.isBlockedHost(meta.blockedHosts, note.userHost)) return false; + if (this.utilityService.isSilencedHost(meta.silencedHosts, note.userHost)) return false; + return true; + }); return await this.noteEntityService.packMany(notes, me); });