mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 18:07:31 -07:00
parent
d3f43fb649
commit
34079340db
2 changed files with 21 additions and 0 deletions
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 define from '../../define';
|
||||||
import { Users, Followings } from '../../../../models';
|
import { Users, Followings } from '../../../../models';
|
||||||
import { generateMuteQueryForUsers } from '../../common/generate-mute-query';
|
import { generateMuteQueryForUsers } from '../../common/generate-mute-query';
|
||||||
|
import { generateBlockQueryForUsers } from '../../common/generate-block-query';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -47,6 +48,7 @@ export default define(meta, async (ps, me) => {
|
||||||
.orderBy('user.followersCount', 'DESC');
|
.orderBy('user.followersCount', 'DESC');
|
||||||
|
|
||||||
generateMuteQueryForUsers(query, me);
|
generateMuteQueryForUsers(query, me);
|
||||||
|
generateBlockQueryForUsers(query, me);
|
||||||
|
|
||||||
const followingQuery = Followings.createQueryBuilder('following')
|
const followingQuery = Followings.createQueryBuilder('following')
|
||||||
.select('following.followeeId')
|
.select('following.followeeId')
|
||||||
|
|
Loading…
Reference in a new issue