forked from mirror/misskey
parent
6fbf1cfc28
commit
8aeabf530c
19
src/server/api/common/generate-block-query.ts
Normal file
19
src/server/api/common/generate-block-query.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { User } from '../../../models/entities/user';
|
||||
import { Blockings } from '../../../models';
|
||||
import { SelectQueryBuilder } from 'typeorm';
|
||||
|
||||
export function generateBlockQueryForUsers(q: SelectQueryBuilder<any>, 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());
|
||||
}
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user