monkeeShark/packages/backend/src/server/api/common/generate-muted-note-thread-query.ts
syuilo 0e4a111f81 refactoring
Resolve #7779
2021-11-12 02:02:25 +09:00

17 lines
673 B
TypeScript

import { User } from '@/models/entities/user';
import { NoteThreadMutings } from '@/models/index';
import { Brackets, SelectQueryBuilder } from 'typeorm';
export function generateMutedNoteThreadQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
const mutedQuery = NoteThreadMutings.createQueryBuilder('threadMuted')
.select('threadMuted.threadId')
.where('threadMuted.userId = :userId', { userId: me.id });
q.andWhere(`note.id NOT IN (${ mutedQuery.getQuery() })`);
q.andWhere(new Brackets(qb => { qb
.where(`note.threadId IS NULL`)
.orWhere(`note.threadId NOT IN (${ mutedQuery.getQuery() })`);
}));
q.setParameters(mutedQuery.getParameters());
}