Skip to content

Commit

Permalink
upd: fix tag view not respecting blocks and suspensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Marie authored and Marie committed Dec 21, 2023
1 parent beded1c commit 90f8d8e
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/backend/src/server/api/endpoints/notes/search-by-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -73,23 +75,32 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // 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');
Expand Down Expand Up @@ -140,7 +151,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // 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);
});
Expand Down

0 comments on commit 90f8d8e

Please sign in to comment.