From 8aeabf530c4f203bd6e7a68d961d4173c0e76191 Mon Sep 17 00:00:00 2001 From: Oni-Men Date: Sun, 21 Jul 2019 22:27:36 +0900 Subject: [PATCH] Patch #5060 (#5205) * fix #5060 * forgot ";" :p --- src/server/api/common/generate-block-query.ts | 19 +++++++++++++++++++ .../api/endpoints/users/recommendation.ts | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 src/server/api/common/generate-block-query.ts diff --git a/src/server/api/common/generate-block-query.ts b/src/server/api/common/generate-block-query.ts new file mode 100644 index 000000000..363641048 --- /dev/null +++ b/src/server/api/common/generate-block-query.ts @@ -0,0 +1,19 @@ +import { User } from '../../../models/entities/user'; +import { Blockings } from '../../../models'; +import { SelectQueryBuilder } from 'typeorm'; + +export function generateBlockQueryForUsers(q: SelectQueryBuilder, me: User) { + const blockingQuery = Blockings.createQueryBuilder('blocking') + .select('blocking.blockeeId') + .where('blocking.blockerId = :blockerId', { blockerId: me.id }); + + const blockedQuery = Blockings.createQueryBuilder('blocking') + .select('blocking.blockerId') + .where('blocking.blockeeId = :blockeeId', { blockeeId: me.id }); + + q.andWhere(`user.id NOT IN (${ blockingQuery.getQuery() })`); + q.setParameters(blockingQuery.getParameters()); + + q.andWhere(`user.id NOT IN (${ blockedQuery.getQuery() })`); + q.setParameters(blockedQuery.getParameters()); +} diff --git a/src/server/api/endpoints/users/recommendation.ts b/src/server/api/endpoints/users/recommendation.ts index 73d8fe620..5f7f287fe 100644 --- a/src/server/api/endpoints/users/recommendation.ts +++ b/src/server/api/endpoints/users/recommendation.ts @@ -3,6 +3,7 @@ import $ from 'cafy'; import define from '../../define'; import { Users, Followings } from '../../../../models'; import { generateMuteQueryForUsers } from '../../common/generate-mute-query'; +import { generateBlockQueryForUsers } from '../../common/generate-block-query'; export const meta = { desc: { @@ -47,6 +48,7 @@ export default define(meta, async (ps, me) => { .orderBy('user.followersCount', 'DESC'); generateMuteQueryForUsers(query, me); + generateBlockQueryForUsers(query, me); const followingQuery = Followings.createQueryBuilder('following') .select('following.followeeId')