fixup: muted-renotes review round 1

This commit is contained in:
Chloe Kudryavtsev 2022-10-10 04:19:30 -04:00 committed by ThatOneCalculator
parent f1feebefc0
commit 8520be65c7
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
7 changed files with 80 additions and 48 deletions

View File

@ -0,0 +1,22 @@
import { Brackets, SelectQueryBuilder } from 'typeorm';
import { User } from '@/models/entities/user.js';
import { RenoteMutings } from '@/models/index.js';
export function generateMutedRenotesQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }): void {
const mutingQuery = RenoteMutings.createQueryBuilder('renote_muting')
.select('renote_muting.muteeId')
.where('renote_muting.muterId = :muterId', { muterId: me.id });
q.andWhere(new Brackets(qb => {
qb
.where(new Brackets(qb => {
qb.where('note.renoteId IS NOT NULL');
qb.andWhere('note.text IS NULL');
qb.andWhere(`note.userId NOT IN (${ mutingQuery.getQuery() })`);
}))
.orWhere('note.renoteId IS NULL')
.orWhere('note.text IS NOT NULL');
}));
q.setParameters(mutingQuery.getParameters());
}

View File

@ -1,13 +1,14 @@
import { fetchMeta } from "@/misc/fetch-meta.js"; import { fetchMeta } from '@/misc/fetch-meta.js';
import { Notes } from "@/models/index.js"; import { Notes } from '@/models/index.js';
import { activeUsersChart } from "@/services/chart/index.js"; import { activeUsersChart } from '@/services/chart/index.js';
import define from "../../define.js"; import define from '../../define.js';
import { ApiError } from "../../error.js"; import { ApiError } from '../../error.js';
import { makePaginationQuery } from "../../common/make-pagination-query.js"; import { makePaginationQuery } from '../../common/make-pagination-query.js';
import { generateMutedUserQuery } from "../../common/generate-muted-user-query.js"; import { generateMutedUserQuery } from '../../common/generate-muted-user-query.js';
import { generateRepliesQuery } from "../../common/generate-replies-query.js"; import { generateRepliesQuery } from '../../common/generate-replies-query.js';
import { generateMutedNoteQuery } from "../../common/generate-muted-note-query.js"; import { generateMutedNoteQuery } from '../../common/generate-muted-note-query.js';
import { generateBlockedUserQuery } from "../../common/generate-block-query.js"; import { generateBlockedUserQuery } from '../../common/generate-block-query.js';
import { generateMutedRenotesQuery } from '../../common/generated-muted-renote-query.js';
export const meta = { export const meta = {
tags: ["notes"], tags: ["notes"],
@ -86,6 +87,7 @@ export default define(meta, paramDef, async (ps, user) => {
generateMutedUserQuery(query, user); generateMutedUserQuery(query, user);
generateMutedNoteQuery(query, user); generateMutedNoteQuery(query, user);
generateBlockedUserQuery(query, user); generateBlockedUserQuery(query, user);
generateMutedRenotesQuery(query, user);
} }
if (ps.withFiles) { if (ps.withFiles) {

View File

@ -1,16 +1,17 @@
import { Brackets } from "typeorm"; import { Brackets } from 'typeorm';
import { fetchMeta } from "@/misc/fetch-meta.js"; import { fetchMeta } from '@/misc/fetch-meta.js';
import { Followings, Notes } from "@/models/index.js"; import { Followings, Notes } from '@/models/index.js';
import { activeUsersChart } from "@/services/chart/index.js"; import { activeUsersChart } from '@/services/chart/index.js';
import define from "../../define.js"; import define from '../../define.js';
import { ApiError } from "../../error.js"; import { ApiError } from '../../error.js';
import { makePaginationQuery } from "../../common/make-pagination-query.js"; import { makePaginationQuery } from '../../common/make-pagination-query.js';
import { generateVisibilityQuery } from "../../common/generate-visibility-query.js"; import { generateVisibilityQuery } from '../../common/generate-visibility-query.js';
import { generateMutedUserQuery } from "../../common/generate-muted-user-query.js"; import { generateMutedUserQuery } from '../../common/generate-muted-user-query.js';
import { generateRepliesQuery } from "../../common/generate-replies-query.js"; import { generateRepliesQuery } from '../../common/generate-replies-query.js';
import { generateMutedNoteQuery } from "../../common/generate-muted-note-query.js"; import { generateMutedNoteQuery } from '../../common/generate-muted-note-query.js';
import { generateChannelQuery } from "../../common/generate-channel-query.js"; import { generateChannelQuery } from '../../common/generate-channel-query.js';
import { generateBlockedUserQuery } from "../../common/generate-block-query.js"; import { generateBlockedUserQuery } from '../../common/generate-block-query.js';
import { generateMutedRenotesQuery } from '../../common/generated-muted-renote-query.js';
export const meta = { export const meta = {
tags: ["notes"], tags: ["notes"],
@ -103,6 +104,7 @@ export default define(meta, paramDef, async (ps, user) => {
generateMutedUserQuery(query, user); generateMutedUserQuery(query, user);
generateMutedNoteQuery(query, user); generateMutedNoteQuery(query, user);
generateBlockedUserQuery(query, user); generateBlockedUserQuery(query, user);
generateMutedRenotesQuery(query, user);
if (ps.includeMyRenotes === false) { if (ps.includeMyRenotes === false) {
query.andWhere( query.andWhere(

View File

@ -1,16 +1,17 @@
import { Brackets } from "typeorm"; import { Brackets } from 'typeorm';
import { fetchMeta } from "@/misc/fetch-meta.js"; import { fetchMeta } from '@/misc/fetch-meta.js';
import { Notes, Users } from "@/models/index.js"; import { Notes } from '@/models/index.js';
import { activeUsersChart } from "@/services/chart/index.js"; import { activeUsersChart } from '@/services/chart/index.js';
import define from "../../define.js"; import define from '../../define.js';
import { ApiError } from "../../error.js"; import { ApiError } from '../../error.js';
import { generateMutedUserQuery } from "../../common/generate-muted-user-query.js"; import { generateMutedUserQuery } from '../../common/generate-muted-user-query.js';
import { makePaginationQuery } from "../../common/make-pagination-query.js"; import { makePaginationQuery } from '../../common/make-pagination-query.js';
import { generateVisibilityQuery } from "../../common/generate-visibility-query.js"; import { generateVisibilityQuery } from '../../common/generate-visibility-query.js';
import { generateRepliesQuery } from "../../common/generate-replies-query.js"; import { generateRepliesQuery } from '../../common/generate-replies-query.js';
import { generateMutedNoteQuery } from "../../common/generate-muted-note-query.js"; import { generateMutedNoteQuery } from '../../common/generate-muted-note-query.js';
import { generateChannelQuery } from "../../common/generate-channel-query.js"; import { generateChannelQuery } from '../../common/generate-channel-query.js';
import { generateBlockedUserQuery } from "../../common/generate-block-query.js"; import { generateBlockedUserQuery } from '../../common/generate-block-query.js';
import { generateMutedRenotesQuery } from '../../common/generated-muted-renote-query.js';
export const meta = { export const meta = {
tags: ["notes"], tags: ["notes"],
@ -96,6 +97,7 @@ export default define(meta, paramDef, async (ps, user) => {
if (user) generateMutedUserQuery(query, user); if (user) generateMutedUserQuery(query, user);
if (user) generateMutedNoteQuery(query, user); if (user) generateMutedNoteQuery(query, user);
if (user) generateBlockedUserQuery(query, user); if (user) generateBlockedUserQuery(query, user);
if (user) generateMutedRenotesQuery(query, user);
if (ps.withFiles) { if (ps.withFiles) {
query.andWhere("note.fileIds != '{}'"); query.andWhere("note.fileIds != '{}'");

View File

@ -11,6 +11,7 @@ import { generateRepliesQuery } from "../../common/generate-replies-query.js";
import { generateMutedNoteQuery } from "../../common/generate-muted-note-query.js"; import { generateMutedNoteQuery } from "../../common/generate-muted-note-query.js";
import { generateChannelQuery } from "../../common/generate-channel-query.js"; import { generateChannelQuery } from "../../common/generate-channel-query.js";
import { generateBlockedUserQuery } from "../../common/generate-block-query.js"; import { generateBlockedUserQuery } from "../../common/generate-block-query.js";
import { generateMutedRenotesQuery } from '../../common/generated-muted-renote-query.js';
export const meta = { export const meta = {
tags: ["notes"], tags: ["notes"],
@ -99,6 +100,7 @@ export default define(meta, paramDef, async (ps, user) => {
if (user) generateMutedUserQuery(query, user); if (user) generateMutedUserQuery(query, user);
if (user) generateMutedNoteQuery(query, user); if (user) generateMutedNoteQuery(query, user);
if (user) generateBlockedUserQuery(query, user); if (user) generateBlockedUserQuery(query, user);
if (user) generateMutedRenotesQuery(query, user);
if (ps.withFiles) { if (ps.withFiles) {
query.andWhere("note.fileIds != '{}'"); query.andWhere("note.fileIds != '{}'");

View File

@ -1,14 +1,15 @@
import { Brackets } from "typeorm"; import { Brackets } from 'typeorm';
import { Notes, Followings } from "@/models/index.js"; import { Notes, Followings } from '@/models/index.js';
import { activeUsersChart } from "@/services/chart/index.js"; import { activeUsersChart } from '@/services/chart/index.js';
import define from "../../define.js"; import define from '../../define.js';
import { makePaginationQuery } from "../../common/make-pagination-query.js"; import { makePaginationQuery } from '../../common/make-pagination-query.js';
import { generateVisibilityQuery } from "../../common/generate-visibility-query.js"; import { generateVisibilityQuery } from '../../common/generate-visibility-query.js';
import { generateMutedUserQuery } from "../../common/generate-muted-user-query.js"; import { generateMutedUserQuery } from '../../common/generate-muted-user-query.js';
import { generateRepliesQuery } from "../../common/generate-replies-query.js"; import { generateRepliesQuery } from '../../common/generate-replies-query.js';
import { generateMutedNoteQuery } from "../../common/generate-muted-note-query.js"; import { generateMutedNoteQuery } from '../../common/generate-muted-note-query.js';
import { generateChannelQuery } from "../../common/generate-channel-query.js"; import { generateChannelQuery } from '../../common/generate-channel-query.js';
import { generateBlockedUserQuery } from "../../common/generate-block-query.js"; import { generateBlockedUserQuery } from '../../common/generate-block-query.js';
import { generateMutedRenotesQuery } from '../../common/generated-muted-renote-query.js';
export const meta = { export const meta = {
tags: ["notes"], tags: ["notes"],
@ -95,6 +96,7 @@ export default define(meta, paramDef, async (ps, user) => {
generateMutedUserQuery(query, user); generateMutedUserQuery(query, user);
generateMutedNoteQuery(query, user); generateMutedNoteQuery(query, user);
generateBlockedUserQuery(query, user); generateBlockedUserQuery(query, user);
generateMutedRenotesQuery(query, user);
if (ps.includeMyRenotes === false) { if (ps.includeMyRenotes === false) {
query.andWhere( query.andWhere(

View File

@ -46,7 +46,7 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, user) => { export default define(meta, paramDef, async (ps, user) => {
const muter = user; const muter = user;
// 自分自身 // Check if the mutee is yourself
if (user.id === ps.userId) { if (user.id === ps.userId) {
throw new ApiError(meta.errors.muteeIsYourself); throw new ApiError(meta.errors.muteeIsYourself);
} }