mirror of
https://github.com/misskey-dev/misskey.git
synced 2025-01-24 03:00:48 +09:00
7015df37e3
* enhance(server): Improve user block
* Update CHANGELOG.md
* ユーザーリスト対応
* 相手から見れなくなるように
* Update 1629004542760-chart-reindex.ts
2365761ba5 (commitcomment-54919821)
* update test
* add test
* add todos
* Update 1629004542760-chart-reindex.ts
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
import { User } from '../../../models/entities/user';
|
|
import { Blockings } from '../../../models';
|
|
import { Brackets, SelectQueryBuilder } from 'typeorm';
|
|
|
|
// ここでいうBlockedは被Blockedの意
|
|
export function generateBlockedUserQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
|
|
const blockingQuery = Blockings.createQueryBuilder('blocking')
|
|
.select('blocking.blockerId')
|
|
.where('blocking.blockeeId = :blockeeId', { blockeeId: me.id });
|
|
|
|
// 投稿の作者にブロックされていない かつ
|
|
// 投稿の返信先の作者にブロックされていない かつ
|
|
// 投稿の引用元の作者にブロックされていない
|
|
q
|
|
.andWhere(`note.userId NOT IN (${ blockingQuery.getQuery() })`)
|
|
.andWhere(new Brackets(qb => { qb
|
|
.where(`note.replyUserId IS NULL`)
|
|
.orWhere(`note.replyUserId NOT IN (${ blockingQuery.getQuery() })`);
|
|
}))
|
|
.andWhere(new Brackets(qb => { qb
|
|
.where(`note.renoteUserId IS NULL`)
|
|
.orWhere(`note.renoteUserId NOT IN (${ blockingQuery.getQuery() })`);
|
|
}));
|
|
|
|
q.setParameters(blockingQuery.getParameters());
|
|
}
|
|
|
|
export function generateBlockQueryForUsers(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
|
|
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());
|
|
}
|