From 8aab828c65f432898a7844caf86d6732a3c758fc Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 22 Feb 2020 06:49:12 +0900 Subject: [PATCH] Better featured injection --- src/server/api/common/inject-featured.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/server/api/common/inject-featured.ts b/src/server/api/common/inject-featured.ts index 91b12cadc..92e1e3b39 100644 --- a/src/server/api/common/inject-featured.ts +++ b/src/server/api/common/inject-featured.ts @@ -1,7 +1,7 @@ import rndstr from 'rndstr'; import { Note } from '../../../models/entities/note'; import { User } from '../../../models/entities/user'; -import { Notes, UserProfiles } from '../../../models'; +import { Notes, UserProfiles, NoteReactions } from '../../../models'; import { generateMuteQuery } from './generate-mute-query'; import { ensure } from '../../../prelude/ensure'; @@ -26,9 +26,17 @@ export async function injectFeatured(timeline: Note[], user?: User | null) { .andWhere(`note.visibility = 'public'`) .leftJoinAndSelect('note.user', 'user'); - if (user) query.andWhere('note.userId != :userId', { userId: user.id }); + if (user) { + query.andWhere('note.userId != :userId', { userId: user.id }); - if (user) generateMuteQuery(query, user); + generateMuteQuery(query, user); + + const reactionQuery = NoteReactions.createQueryBuilder('reaction') + .select('reaction.noteId') + .where('reaction.userId = :userId', { userId: user.id }); + + query.andWhere(`note.id NOT IN (${ reactionQuery.getQuery() })`); + } const notes = await query .orderBy('note.score', 'DESC')