2019-04-07 14:50:36 +02:00
|
|
|
import { SelectQueryBuilder, Brackets } from 'typeorm';
|
2022-06-25 07:23:59 +02:00
|
|
|
import { User } from '@/models/entities/user.js';
|
|
|
|
import { Mutings, UserProfiles } from '@/models/index.js';
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2021-03-24 03:05:37 +01:00
|
|
|
export function generateMutedUserQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }, exclude?: User) {
|
2019-04-07 14:50:36 +02:00
|
|
|
const mutingQuery = Mutings.createQueryBuilder('muting')
|
|
|
|
.select('muting.muteeId')
|
|
|
|
.where('muting.muterId = :muterId', { muterId: me.id });
|
|
|
|
|
2019-10-20 17:52:50 +02:00
|
|
|
if (exclude) {
|
|
|
|
mutingQuery.andWhere('muting.muteeId != :excludeId', { excludeId: exclude.id });
|
|
|
|
}
|
|
|
|
|
2022-06-25 07:23:59 +02:00
|
|
|
const mutingInstanceQuery = UserProfiles.createQueryBuilder('user_profile')
|
|
|
|
.select('user_profile.mutedInstances')
|
|
|
|
.where('user_profile.userId = :muterId', { muterId: me.id });
|
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
// 投稿の作者をミュートしていない かつ
|
|
|
|
// 投稿の返信先の作者をミュートしていない かつ
|
|
|
|
// 投稿の引用元の作者をミュートしていない
|
|
|
|
q
|
|
|
|
.andWhere(`note.userId NOT IN (${ mutingQuery.getQuery() })`)
|
|
|
|
.andWhere(new Brackets(qb => { qb
|
2022-06-25 07:23:59 +02:00
|
|
|
.where('note.replyUserId IS NULL')
|
2019-04-07 14:50:36 +02:00
|
|
|
.orWhere(`note.replyUserId NOT IN (${ mutingQuery.getQuery() })`);
|
|
|
|
}))
|
|
|
|
.andWhere(new Brackets(qb => { qb
|
2022-06-25 07:23:59 +02:00
|
|
|
.where('note.renoteUserId IS NULL')
|
2019-04-07 14:50:36 +02:00
|
|
|
.orWhere(`note.renoteUserId NOT IN (${ mutingQuery.getQuery() })`);
|
2022-06-25 07:23:59 +02:00
|
|
|
}))
|
|
|
|
// mute instances
|
|
|
|
.andWhere(new Brackets(qb => { qb
|
|
|
|
.andWhere('note.userHost IS NULL')
|
|
|
|
.orWhere(`NOT ((${ mutingInstanceQuery.getQuery() })::jsonb ? note.userHost)`);
|
|
|
|
}))
|
|
|
|
.andWhere(new Brackets(qb => { qb
|
|
|
|
.where('note.replyUserHost IS NULL')
|
|
|
|
.orWhere(`NOT ((${ mutingInstanceQuery.getQuery() })::jsonb ? note.replyUserHost)`);
|
|
|
|
}))
|
|
|
|
.andWhere(new Brackets(qb => { qb
|
|
|
|
.where('note.renoteUserHost IS NULL')
|
|
|
|
.orWhere(`NOT ((${ mutingInstanceQuery.getQuery() })::jsonb ? note.renoteUserHost)`);
|
2019-04-07 14:50:36 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
q.setParameters(mutingQuery.getParameters());
|
2022-06-25 07:23:59 +02:00
|
|
|
q.setParameters(mutingInstanceQuery.getParameters());
|
2019-04-07 14:50:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-24 03:05:37 +01:00
|
|
|
export function generateMutedUserQueryForUsers(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
|
2019-04-07 14:50:36 +02:00
|
|
|
const mutingQuery = Mutings.createQueryBuilder('muting')
|
|
|
|
.select('muting.muteeId')
|
|
|
|
.where('muting.muterId = :muterId', { muterId: me.id });
|
|
|
|
|
2022-06-30 08:36:09 +02:00
|
|
|
q.andWhere(`user.id NOT IN (${ mutingQuery.getQuery() })`);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
|
|
|
q.setParameters(mutingQuery.getParameters());
|
|
|
|
}
|