summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/common
diff options
context:
space:
mode:
authorJohann150 <johann.galle@protonmail.com>2022-06-25 07:23:59 +0200
committerGitHub <noreply@github.com>2022-06-25 14:23:59 +0900
commit5728350267faa95e171840b7573d767617ce5491 (patch)
tree8fb51bb847adc8ae70d8124b5a09254d1c032834 /packages/backend/src/server/api/common
parentchore(deps): bump jpeg-js from 0.4.1 to 0.4.4 in /packages/backend (#8843) (diff)
downloadsharkey-5728350267faa95e171840b7573d767617ce5491.tar.gz
sharkey-5728350267faa95e171840b7573d767617ce5491.tar.bz2
sharkey-5728350267faa95e171840b7573d767617ce5491.zip
fix: always respect instance mutes (#8854)
* fix: muted user query also checks instances This way it can be ensured that the instance mute is used everywhere it is required without checking the whole codebase again. Muted users and muted instances should be used together anyways. * fix lint
Diffstat (limited to 'packages/backend/src/server/api/common')
-rw-r--r--packages/backend/src/server/api/common/generate-muted-instance-query.ts40
-rw-r--r--packages/backend/src/server/api/common/generate-muted-user-query.ts46
2 files changed, 41 insertions, 45 deletions
diff --git a/packages/backend/src/server/api/common/generate-muted-instance-query.ts b/packages/backend/src/server/api/common/generate-muted-instance-query.ts
deleted file mode 100644
index 72a6fec68f..0000000000
--- a/packages/backend/src/server/api/common/generate-muted-instance-query.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import { User } from '@/models/entities/user.js';
-import { id } from '@/models/id.js';
-import { UserProfiles } from '@/models/index.js';
-import { SelectQueryBuilder, Brackets } from 'typeorm';
-
-function createMutesQuery(id: string) {
- return UserProfiles.createQueryBuilder('user_profile')
- .select('user_profile.mutedInstances')
- .where('user_profile.userId = :muterId', { muterId: id });
-}
-
-export function generateMutedInstanceQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
- const mutingQuery = createMutesQuery(me.id);
-
- q
- .andWhere(new Brackets(qb => { qb
- .andWhere('note.userHost IS NULL')
- .orWhere(`NOT((${ mutingQuery.getQuery() })::jsonb ? note.userHost)`);
- }))
- .andWhere(new Brackets(qb => { qb
- .where(`note.replyUserHost IS NULL`)
- .orWhere(`NOT ((${ mutingQuery.getQuery() })::jsonb ? note.replyUserHost)`);
- }))
- .andWhere(new Brackets(qb => { qb
- .where(`note.renoteUserHost IS NULL`)
- .orWhere(`NOT ((${ mutingQuery.getQuery() })::jsonb ? note.renoteUserHost)`);
- }));
- q.setParameters(mutingQuery.getParameters());
-}
-
-export function generateMutedInstanceNotificationQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
- const mutingQuery = createMutesQuery(me.id);
-
- q.andWhere(new Brackets(qb => { qb
- .andWhere('notifier.host IS NULL')
- .orWhere(`NOT (( ${mutingQuery.getQuery()} )::jsonb ? notifier.host)`);
- }));
-
- q.setParameters(mutingQuery.getParameters());
-}
diff --git a/packages/backend/src/server/api/common/generate-muted-user-query.ts b/packages/backend/src/server/api/common/generate-muted-user-query.ts
index 79cb3ff894..e276ff2bd5 100644
--- a/packages/backend/src/server/api/common/generate-muted-user-query.ts
+++ b/packages/backend/src/server/api/common/generate-muted-user-query.ts
@@ -1,6 +1,6 @@
-import { User } from '@/models/entities/user.js';
-import { Mutings } from '@/models/index.js';
import { SelectQueryBuilder, Brackets } from 'typeorm';
+import { User } from '@/models/entities/user.js';
+import { Mutings, UserProfiles } from '@/models/index.js';
export function generateMutedUserQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }, exclude?: User) {
const mutingQuery = Mutings.createQueryBuilder('muting')
@@ -11,21 +11,39 @@ export function generateMutedUserQuery(q: SelectQueryBuilder<any>, me: { id: Use
mutingQuery.andWhere('muting.muteeId != :excludeId', { excludeId: exclude.id });
}
+ const mutingInstanceQuery = UserProfiles.createQueryBuilder('user_profile')
+ .select('user_profile.mutedInstances')
+ .where('user_profile.userId = :muterId', { muterId: me.id });
+
// 投稿の作者をミュートしていない かつ
// 投稿の返信先の作者をミュートしていない かつ
// 投稿の引用元の作者をミュートしていない
q
.andWhere(`note.userId NOT IN (${ mutingQuery.getQuery() })`)
.andWhere(new Brackets(qb => { qb
- .where(`note.replyUserId IS NULL`)
+ .where('note.replyUserId IS NULL')
.orWhere(`note.replyUserId NOT IN (${ mutingQuery.getQuery() })`);
}))
.andWhere(new Brackets(qb => { qb
- .where(`note.renoteUserId IS NULL`)
+ .where('note.renoteUserId IS NULL')
.orWhere(`note.renoteUserId NOT IN (${ mutingQuery.getQuery() })`);
+ }))
+ // 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)`);
}));
q.setParameters(mutingQuery.getParameters());
+ q.setParameters(mutingInstanceQuery.getParameters());
}
export function generateMutedUserQueryForUsers(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
@@ -33,8 +51,26 @@ export function generateMutedUserQueryForUsers(q: SelectQueryBuilder<any>, me: {
.select('muting.muteeId')
.where('muting.muterId = :muterId', { muterId: me.id });
+ const mutingInstanceQuery = UserProfiles.createQueryBuilder('user_profile')
+ .select('user_profile.mutedInstances')
+ .where('user_profile.userId = :muterId', { muterId: me.id });
+
q
- .andWhere(`user.id NOT IN (${ mutingQuery.getQuery() })`);
+ .andWhere(`user.id NOT IN (${ mutingQuery.getQuery() })`)
+ // 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)`);
+ }));
q.setParameters(mutingQuery.getParameters());
+ q.setParameters(mutingInstanceQuery.getParameters());
}