fix(reaction): don't include blocked/muted users' reaction to query

This commit is contained in:
オスカー、 2024-09-07 19:21:08 +09:00
parent 9c6ac47a5c
commit f30c95e51a
Signed by: SWREI
GPG Key ID: 139D6573F92DA9F7
3 changed files with 45 additions and 0 deletions

View File

@ -119,6 +119,26 @@ export class QueryService {
q.setParameters(blockingQuery.getParameters());
}
@bindThis
public generateBlockedUserQueryForReactions(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }): void {
const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking')
.select('blocking.blockerId')
.where('blocking.blockeeId = :blockeeId', { blockeeId: me.id });
q.andWhere(`note.userId NOT IN (${ blockingQuery.getQuery() })`);
q.setParameters(blockingQuery.getParameters());
}
@bindThis
public generateBlockingUserQueryForReactions(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }): void {
const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking')
.select('blocking.blockeeId')
.where('blocking.blockerId = :blockerId', { blockerId: me.id });
q.andWhere(`reaction.userId NOT IN (${ blockingQuery.getQuery() })`);
q.setParameters(blockingQuery.getParameters());
}
@bindThis
public generateBlockQueryForUsers(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }): void {
const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking')
@ -213,6 +233,20 @@ export class QueryService {
q.setParameters(mutingQuery.getParameters());
}
@bindThis
public generateMutedUserQueryForReactions(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }, exclude?: { id: MiUser['id'] }): void {
const mutingQuery = this.mutingsRepository.createQueryBuilder('muting')
.select('muting.muteeId')
.where('muting.muterId = :muterId', { muterId: me.id });
if (exclude) {
mutingQuery.andWhere('muting.muteeId != :excludeId', { excludeId: exclude.id });
}
q.andWhere(`reaction.userId NOT IN (${ mutingQuery.getQuery() })`);
q.setParameters(mutingQuery.getParameters());
}
@bindThis
public generateVisibilityQuery(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] } | null): void {
// This code must always be synchronized with the checks in Notes.isVisibleForMe.

View File

@ -74,6 +74,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
query.andWhere('reaction.reaction = :type', { type });
}
if (me) {
this.queryService.generateMutedUserQueryForReactions(query, me);
this.queryService.generateBlockingUserQueryForReactions(query, me);
this.queryService.generateBlockedUserQueryForReactions(query, me);
}
const reactions = await query.limit(ps.limit).getMany();
return await this.noteReactionEntityService.packMany(reactions, me);

View File

@ -104,6 +104,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
);
this.queryService.generateVisibilityQuery(query, me);
if (me) {
this.queryService.generateMutedUserQuery(query, me);
this.queryService.generateBlockingUserQuery(query, me);
this.queryService.generateBlockedUserQuery(query, me);
}
const reactions = await query
.limit(ps.limit)