chore: allow specifying note column for note/block query

This commit is contained in:
anatawa12 2025-05-09 23:08:04 +09:00
parent 48c6659329
commit 7b8923b8a4
No known key found for this signature in database
GPG Key ID: 9CA909848B8E4EA6
1 changed files with 35 additions and 17 deletions

View File

@ -79,7 +79,15 @@ export class QueryService {
// ここでいうBlockedは被Blockedの意 // ここでいうBlockedは被Blockedの意
@bindThis @bindThis
public generateBlockedUserQueryForNotes(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }): void { public generateBlockedUserQueryForNotes(
q: SelectQueryBuilder<any>,
me: { id: MiUser['id'] },
{
noteColumn = 'note',
}: {
noteColumn?: string,
} = {},
): void {
const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking') const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking')
.select('blocking.blockerId') .select('blocking.blockerId')
.where('blocking.blockeeId = :blockeeId', { blockeeId: me.id }); .where('blocking.blockeeId = :blockeeId', { blockeeId: me.id });
@ -88,16 +96,20 @@ export class QueryService {
// 投稿の返信先の作者にブロックされていない かつ // 投稿の返信先の作者にブロックされていない かつ
// 投稿の引用元の作者にブロックされていない // 投稿の引用元の作者にブロックされていない
q q
.andWhere(`note.userId NOT IN (${ blockingQuery.getQuery() })`)
.andWhere(new Brackets(qb => { .andWhere(new Brackets(qb => {
qb qb
.where('note.replyUserId IS NULL') .where(`${noteColumn}.userId IS NULL`)
.orWhere(`note.replyUserId NOT IN (${ blockingQuery.getQuery() })`); .orWhere(`${noteColumn}.userId NOT IN (${ blockingQuery.getQuery() })`);
})) }))
.andWhere(new Brackets(qb => { .andWhere(new Brackets(qb => {
qb qb
.where('note.renoteUserId IS NULL') .where(`${noteColumn}.replyUserId IS NULL`)
.orWhere(`note.renoteUserId NOT IN (${ blockingQuery.getQuery() })`); .orWhere(`${noteColumn}.replyUserId NOT IN (${ blockingQuery.getQuery() })`);
}))
.andWhere(new Brackets(qb => {
qb
.where(`${noteColumn}.renoteUserId IS NULL`)
.orWhere(`${noteColumn}.renoteUserId NOT IN (${ blockingQuery.getQuery() })`);
})); }));
q.setParameters(blockingQuery.getParameters()); q.setParameters(blockingQuery.getParameters());
@ -142,8 +154,10 @@ export class QueryService {
me: { id: MiUser['id'] }, me: { id: MiUser['id'] },
{ {
excludeUserFromMute, excludeUserFromMute,
noteColumn = 'note',
}: { }: {
excludeUserFromMute?: MiUser['id'], excludeUserFromMute?: MiUser['id'],
noteColumn?: string,
} = {}, } = {},
): void { ): void {
const mutingQuery = this.mutingsRepository.createQueryBuilder('muting') const mutingQuery = this.mutingsRepository.createQueryBuilder('muting')
@ -162,32 +176,36 @@ export class QueryService {
// 投稿の返信先の作者をミュートしていない かつ // 投稿の返信先の作者をミュートしていない かつ
// 投稿の引用元の作者をミュートしていない // 投稿の引用元の作者をミュートしていない
q q
.andWhere(`note.userId NOT IN (${ mutingQuery.getQuery() })`)
.andWhere(new Brackets(qb => { .andWhere(new Brackets(qb => {
qb qb
.where('note.replyUserId IS NULL') .where(`${noteColumn}.userId IS NULL`)
.orWhere(`note.replyUserId NOT IN (${ mutingQuery.getQuery() })`); .orWhere(`${noteColumn}.userId NOT IN (${ mutingQuery.getQuery() })`);
})) }))
.andWhere(new Brackets(qb => { .andWhere(new Brackets(qb => {
qb qb
.where('note.renoteUserId IS NULL') .where(`${noteColumn}.replyUserId IS NULL`)
.orWhere(`note.renoteUserId NOT IN (${ mutingQuery.getQuery() })`); .orWhere(`${noteColumn}.replyUserId NOT IN (${ mutingQuery.getQuery() })`);
}))
.andWhere(new Brackets(qb => {
qb
.where(`${noteColumn}.renoteUserId IS NULL`)
.orWhere(`${noteColumn}.renoteUserId NOT IN (${ mutingQuery.getQuery() })`);
})) }))
// mute instances // mute instances
.andWhere(new Brackets(qb => { .andWhere(new Brackets(qb => {
qb qb
.andWhere('note.userHost IS NULL') .andWhere(`${noteColumn}.userHost IS NULL`)
.orWhere(`NOT ((${ mutingInstanceQuery.getQuery() })::jsonb ? note.userHost)`); .orWhere(`NOT ((${ mutingInstanceQuery.getQuery() })::jsonb ? ${noteColumn}.userHost)`);
})) }))
.andWhere(new Brackets(qb => { .andWhere(new Brackets(qb => {
qb qb
.where('note.replyUserHost IS NULL') .where(`${noteColumn}.replyUserHost IS NULL`)
.orWhere(`NOT ((${ mutingInstanceQuery.getQuery() })::jsonb ? note.replyUserHost)`); .orWhere(`NOT ((${ mutingInstanceQuery.getQuery() })::jsonb ? ${noteColumn}.replyUserHost)`);
})) }))
.andWhere(new Brackets(qb => { .andWhere(new Brackets(qb => {
qb qb
.where('note.renoteUserHost IS NULL') .where(`${noteColumn}.renoteUserHost IS NULL`)
.orWhere(`NOT ((${ mutingInstanceQuery.getQuery() })::jsonb ? note.renoteUserHost)`); .orWhere(`NOT ((${ mutingInstanceQuery.getQuery() })::jsonb ? ${noteColumn}.renoteUserHost)`);
})); }));
q.setParameters(mutingQuery.getParameters()); q.setParameters(mutingQuery.getParameters());