2022-10-06 23:20:38 +00:00
|
|
|
import { Brackets, SelectQueryBuilder } from 'typeorm';
|
|
|
|
import { User } from '@/models/entities/user.js';
|
|
|
|
import { RenoteMutings } from '@/models/index.js';
|
|
|
|
|
2022-10-10 08:19:30 +00:00
|
|
|
export function generateMutedRenotesQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }): void {
|
2022-10-06 23:20:38 +00:00
|
|
|
const mutingQuery = RenoteMutings.createQueryBuilder('renote_muting')
|
|
|
|
.select('renote_muting.muteeId')
|
|
|
|
.where('renote_muting.muterId = :muterId', { muterId: me.id });
|
|
|
|
|
|
|
|
q.andWhere(new Brackets(qb => {
|
|
|
|
qb
|
|
|
|
.where(new Brackets(qb => {
|
|
|
|
qb.where('note.renoteId IS NOT NULL');
|
|
|
|
qb.andWhere('note.text IS NULL');
|
|
|
|
qb.andWhere(`note.userId NOT IN (${ mutingQuery.getQuery() })`);
|
|
|
|
}))
|
|
|
|
.orWhere('note.renoteId IS NULL')
|
|
|
|
.orWhere('note.text IS NOT NULL');
|
|
|
|
}));
|
|
|
|
|
|
|
|
q.setParameters(mutingQuery.getParameters());
|
|
|
|
}
|