filter silenced notes in many more places
This commit is contained in:
parent
64694be004
commit
16dedf7219
10 changed files with 51 additions and 21 deletions
|
|
@ -7,7 +7,6 @@ import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { Brackets, Not, WhereExpressionBuilder } from 'typeorm';
|
import { Brackets, Not, WhereExpressionBuilder } from 'typeorm';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import type { MiUser } from '@/models/User.js';
|
import type { MiUser } from '@/models/User.js';
|
||||||
import { MiInstance } from '@/models/Instance.js';
|
|
||||||
import type { UserProfilesRepository, FollowingsRepository, ChannelFollowingsRepository, BlockingsRepository, NoteThreadMutingsRepository, MutingsRepository, RenoteMutingsRepository, MiMeta, InstancesRepository } from '@/models/_.js';
|
import type { UserProfilesRepository, FollowingsRepository, ChannelFollowingsRepository, BlockingsRepository, NoteThreadMutingsRepository, MutingsRepository, RenoteMutingsRepository, MiMeta, InstancesRepository } from '@/models/_.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { IdService } from '@/core/IdService.js';
|
import { IdService } from '@/core/IdService.js';
|
||||||
|
|
@ -204,7 +203,7 @@ export class QueryService {
|
||||||
@bindThis
|
@bindThis
|
||||||
public generateBlockedHostQueryForNote<E extends ObjectLiteral>(q: SelectQueryBuilder<E>, excludeAuthor?: boolean): SelectQueryBuilder<E> {
|
public generateBlockedHostQueryForNote<E extends ObjectLiteral>(q: SelectQueryBuilder<E>, excludeAuthor?: boolean): SelectQueryBuilder<E> {
|
||||||
const checkFor = (key: 'user' | 'replyUser' | 'renoteUser') => this
|
const checkFor = (key: 'user' | 'replyUser' | 'renoteUser') => this
|
||||||
.leftJoinInstance(q, `note.${key}Instance`, `${key}Instance`)
|
.leftJoin(q, `note.${key}Instance`, `${key}Instance`)
|
||||||
.andWhere(new Brackets(qb => {
|
.andWhere(new Brackets(qb => {
|
||||||
qb
|
qb
|
||||||
.orWhere(`"${key}Instance" IS NULL`) // local
|
.orWhere(`"${key}Instance" IS NULL`) // local
|
||||||
|
|
@ -225,31 +224,53 @@ export class QueryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public generateSilencedUserQueryForNotes<E extends ObjectLiteral>(q: SelectQueryBuilder<E>, me?: { id: MiUser['id'] } | null): SelectQueryBuilder<E> {
|
public generateSilencedUserQueryForNotes<E extends ObjectLiteral>(q: SelectQueryBuilder<E>, me?: { id: MiUser['id'] } | null, excludeAuthor = false): SelectQueryBuilder<E> {
|
||||||
if (!me) {
|
const checkFor = (key: 'user' | 'replyUser' | 'renoteUser') => {
|
||||||
return q.andWhere('user.isSilenced = false');
|
// These are de-duplicated, since most call sites already provide some of them.
|
||||||
|
this.leftJoin(q, `note.${key}Instance`, `${key}Instance`); // note->instance
|
||||||
|
this.leftJoin(q, `note.${key}`, key); // note->user
|
||||||
|
|
||||||
|
q.andWhere(new Brackets(qb => {
|
||||||
|
// case 1: user does not exist (note is not reply/renote)
|
||||||
|
qb.orWhere(`note.${key}Id IS NULL`);
|
||||||
|
|
||||||
|
// case 2: user not silenced AND instance not silenced
|
||||||
|
qb.orWhere(new Brackets(qbb => qbb
|
||||||
|
.andWhere(new Brackets(qbbb => qbbb
|
||||||
|
.orWhere(`"${key}Instance"."isSilenced" = false`)
|
||||||
|
.orWhere(`"${key}Instance" IS NULL`)))
|
||||||
|
.andWhere(`"${key}"."isSilenced" = false`)));
|
||||||
|
|
||||||
|
if (me) {
|
||||||
|
// case 3: we are the author
|
||||||
|
qb.orWhere(`note.${key}Id = :meId`);
|
||||||
|
|
||||||
|
// case 4: we are following the user
|
||||||
|
this.orFollowingUser(qb, ':meId', `note.${key}Id`);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set parameters only once
|
||||||
|
if (me) {
|
||||||
|
q.setParameters({ meId: me.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
return this
|
if (!excludeAuthor) {
|
||||||
.leftJoinInstance(q, 'note.userInstance', 'userInstance')
|
checkFor('user');
|
||||||
.andWhere(new Brackets(qb => this
|
}
|
||||||
// case 1: we are following the user
|
checkFor('replyUser');
|
||||||
.orFollowingUser(qb, ':meId', 'note.userId')
|
checkFor('renoteUser');
|
||||||
// case 2: user not silenced AND instance not silenced
|
|
||||||
.orWhere(new Brackets(qbb => qbb
|
return q;
|
||||||
.andWhere(new Brackets(qbbb => qbbb
|
|
||||||
.orWhere('"userInstance"."isSilenced" = false')
|
|
||||||
.orWhere('"userInstance" IS NULL')))
|
|
||||||
.andWhere('user.isSilenced = false')))))
|
|
||||||
.setParameters({ meId: me.id });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Left-joins an instance in to the query with a given alias and optional condition.
|
* Left-joins a relation into the query with a given alias and optional condition.
|
||||||
* These calls are de-duplicated - multiple uses of the same alias are skipped.
|
* These calls are de-duplicated - multiple uses of the same relation+alias are skipped.
|
||||||
*/
|
*/
|
||||||
@bindThis
|
@bindThis
|
||||||
public leftJoinInstance<E extends ObjectLiteral>(q: SelectQueryBuilder<E>, relation: string | typeof MiInstance, alias: string, condition?: string): SelectQueryBuilder<E> {
|
public leftJoin<E extends ObjectLiteral>(q: SelectQueryBuilder<E>, relation: string, alias: string, condition?: string): SelectQueryBuilder<E> {
|
||||||
// Skip if it's already joined, otherwise we'll get an error
|
// Skip if it's already joined, otherwise we'll get an error
|
||||||
if (!q.expressionMap.joinAttributes.some(j => j.alias.name === alias)) {
|
if (!q.expressionMap.joinAttributes.some(j => j.alias.name === alias)) {
|
||||||
q.leftJoin(relation, alias, condition);
|
q.leftJoin(relation, alias, condition);
|
||||||
|
|
|
||||||
|
|
@ -302,6 +302,7 @@ export class SearchService {
|
||||||
this.queryService.generateVisibilityQuery(query, me);
|
this.queryService.generateVisibilityQuery(query, me);
|
||||||
this.queryService.generateBlockedHostQueryForNote(query);
|
this.queryService.generateBlockedHostQueryForNote(query);
|
||||||
this.queryService.generateSuspendedUserQueryForNote(query);
|
this.queryService.generateSuspendedUserQueryForNote(query);
|
||||||
|
this.queryService.generateSilencedUserQueryForNotes(query, me);
|
||||||
if (me) this.queryService.generateMutedUserQueryForNotes(query, me);
|
if (me) this.queryService.generateMutedUserQueryForNotes(query, me);
|
||||||
if (me) this.queryService.generateBlockedUserQueryForNotes(query, me);
|
if (me) this.queryService.generateBlockedUserQueryForNotes(query, me);
|
||||||
|
|
||||||
|
|
@ -380,6 +381,7 @@ export class SearchService {
|
||||||
|
|
||||||
this.queryService.generateBlockedHostQueryForNote(query);
|
this.queryService.generateBlockedHostQueryForNote(query);
|
||||||
this.queryService.generateSuspendedUserQueryForNote(query);
|
this.queryService.generateSuspendedUserQueryForNote(query);
|
||||||
|
this.queryService.generateSilencedUserQueryForNotes(query, me);
|
||||||
|
|
||||||
const notes = (await query.getMany()).filter(note => {
|
const notes = (await query.getMany()).filter(note => {
|
||||||
if (me && isUserRelated(note, userIdsWhoBlockingMe)) return false;
|
if (me && isUserRelated(note, userIdsWhoBlockingMe)) return false;
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
|
|
||||||
this.queryService.generateBlockedHostQueryForNote(query);
|
this.queryService.generateBlockedHostQueryForNote(query);
|
||||||
this.queryService.generateSuspendedUserQueryForNote(query);
|
this.queryService.generateSuspendedUserQueryForNote(query);
|
||||||
|
this.queryService.generateSilencedUserQueryForNotes(query, me);
|
||||||
this.queryService.generateVisibilityQuery(query, me);
|
this.queryService.generateVisibilityQuery(query, me);
|
||||||
this.queryService.generateMutedUserQueryForNotes(query, me);
|
this.queryService.generateMutedUserQueryForNotes(query, me);
|
||||||
this.queryService.generateBlockedUserQueryForNotes(query, me);
|
this.queryService.generateBlockedUserQueryForNotes(query, me);
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
.leftJoin('(select "host" from "instance" where "isBubbled" = true)', 'bubbleInstance', '"bubbleInstance"."host" = "note"."userHost"')
|
.leftJoin('(select "host" from "instance" where "isBubbled" = true)', 'bubbleInstance', '"bubbleInstance"."host" = "note"."userHost"')
|
||||||
.andWhere('"bubbleInstance" IS NOT NULL');
|
.andWhere('"bubbleInstance" IS NOT NULL');
|
||||||
this.queryService
|
this.queryService
|
||||||
.leftJoinInstance(query, 'note.userInstance', 'userInstance', '"userInstance"."host" = "bubbleInstance"."host"');
|
.leftJoin(query, 'note.userInstance', 'userInstance', '"userInstance"."host" = "bubbleInstance"."host"');
|
||||||
|
|
||||||
this.queryService.generateBlockedHostQueryForNote(query);
|
this.queryService.generateBlockedHostQueryForNote(query);
|
||||||
this.queryService.generateSilencedUserQueryForNotes(query, me);
|
this.queryService.generateSilencedUserQueryForNotes(query, me);
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
|
|
||||||
this.queryService.generateBlockedHostQueryForNote(query);
|
this.queryService.generateBlockedHostQueryForNote(query);
|
||||||
this.queryService.generateSuspendedUserQueryForNote(query);
|
this.queryService.generateSuspendedUserQueryForNote(query);
|
||||||
|
this.queryService.generateSilencedUserQueryForNotes(query, me);
|
||||||
|
|
||||||
const notes = (await query.getMany()).filter(note => {
|
const notes = (await query.getMany()).filter(note => {
|
||||||
if (me && isUserRelated(note, userIdsWhoBlockingMe)) return false;
|
if (me && isUserRelated(note, userIdsWhoBlockingMe)) return false;
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
this.queryService.generateVisibilityQuery(query, me);
|
this.queryService.generateVisibilityQuery(query, me);
|
||||||
this.queryService.generateBlockedHostQueryForNote(query);
|
this.queryService.generateBlockedHostQueryForNote(query);
|
||||||
this.queryService.generateSuspendedUserQueryForNote(query);
|
this.queryService.generateSuspendedUserQueryForNote(query);
|
||||||
|
this.queryService.generateSilencedUserQueryForNotes(query, me);
|
||||||
if (me) {
|
if (me) {
|
||||||
this.queryService.generateMutedUserQueryForNotes(query, me);
|
this.queryService.generateMutedUserQueryForNotes(query, me);
|
||||||
this.queryService.generateBlockedUserQueryForNotes(query, me);
|
this.queryService.generateBlockedUserQueryForNotes(query, me);
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
this.queryService.generateVisibilityQuery(query, me);
|
this.queryService.generateVisibilityQuery(query, me);
|
||||||
this.queryService.generateBlockedHostQueryForNote(query);
|
this.queryService.generateBlockedHostQueryForNote(query);
|
||||||
this.queryService.generateSuspendedUserQueryForNote(query);
|
this.queryService.generateSuspendedUserQueryForNote(query);
|
||||||
|
this.queryService.generateSilencedUserQueryForNotes(query, me, true);
|
||||||
this.queryService.generateMutedUserQueryForNotes(query, me);
|
this.queryService.generateMutedUserQueryForNotes(query, me);
|
||||||
this.queryService.generateBlockedUserQueryForNotes(query, me);
|
this.queryService.generateBlockedUserQueryForNotes(query, me);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
|
|
||||||
this.queryService.generateBlockedHostQueryForNote(query);
|
this.queryService.generateBlockedHostQueryForNote(query);
|
||||||
this.queryService.generateSuspendedUserQueryForNote(query);
|
this.queryService.generateSuspendedUserQueryForNote(query);
|
||||||
|
this.queryService.generateSilencedUserQueryForNotes(query, me, true);
|
||||||
|
|
||||||
const notes = (await query.getMany()).filter(note => {
|
const notes = (await query.getMany()).filter(note => {
|
||||||
if (me && isUserRelated(note, userIdsWhoBlockingMe, false)) return false;
|
if (me && isUserRelated(note, userIdsWhoBlockingMe, false)) return false;
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
this.queryService.generateVisibilityQuery(query, me);
|
this.queryService.generateVisibilityQuery(query, me);
|
||||||
this.queryService.generateBlockedHostQueryForNote(query, true);
|
this.queryService.generateBlockedHostQueryForNote(query, true);
|
||||||
this.queryService.generateSuspendedUserQueryForNote(query, true);
|
this.queryService.generateSuspendedUserQueryForNote(query, true);
|
||||||
|
this.queryService.generateSilencedUserQueryForNotes(query, me, true);
|
||||||
if (me) {
|
if (me) {
|
||||||
this.queryService.generateMutedUserQueryForNotes(query, me, { id: ps.userId });
|
this.queryService.generateMutedUserQueryForNotes(query, me, { id: ps.userId });
|
||||||
this.queryService.generateBlockedUserQueryForNotes(query, me);
|
this.queryService.generateBlockedUserQueryForNotes(query, me);
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
this.queryService.generateVisibilityQuery(query, me);
|
this.queryService.generateVisibilityQuery(query, me);
|
||||||
this.queryService.generateBlockedHostQueryForNote(query);
|
this.queryService.generateBlockedHostQueryForNote(query);
|
||||||
this.queryService.generateSuspendedUserQueryForNote(query);
|
this.queryService.generateSuspendedUserQueryForNote(query);
|
||||||
|
this.queryService.generateSilencedUserQueryForNotes(query, me, true);
|
||||||
if (me) {
|
if (me) {
|
||||||
this.queryService.generateMutedUserQueryForNotes(query, me);
|
this.queryService.generateMutedUserQueryForNotes(query, me);
|
||||||
this.queryService.generateBlockedUserQueryForNotes(query, me);
|
this.queryService.generateBlockedUserQueryForNotes(query, me);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue