chore: formatting

This commit is contained in:
Kainoa Kanter 2023-04-07 22:46:10 -07:00
parent a624aeebe3
commit 437a6e29a5
21 changed files with 119 additions and 76 deletions

View File

@ -1,16 +1,22 @@
export class addRenoteMuting1665091090561 {
constructor() {
this.name = 'addRenoteMuting1665091090561';
this.name = "addRenoteMuting1665091090561";
}
async up(queryRunner) {
await queryRunner.query(`CREATE TABLE "renote_muting" ("id" character varying(32) NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "muteeId" character varying(32) NOT NULL, "muterId" character varying(32) NOT NULL, CONSTRAINT "PK_renoteMuting_id" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE INDEX "IDX_renote_muting_createdAt" ON "muting" ("createdAt") `);
await queryRunner.query(`CREATE INDEX "IDX_renote_muting_muteeId" ON "muting" ("muteeId") `);
await queryRunner.query(`CREATE INDEX "IDX_renote_muting_muterId" ON "muting" ("muterId") `);
await queryRunner.query(
`CREATE TABLE "renote_muting" ("id" character varying(32) NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "muteeId" character varying(32) NOT NULL, "muterId" character varying(32) NOT NULL, CONSTRAINT "PK_renoteMuting_id" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE INDEX "IDX_renote_muting_createdAt" ON "muting" ("createdAt") `,
);
await queryRunner.query(
`CREATE INDEX "IDX_renote_muting_muteeId" ON "muting" ("muteeId") `,
);
await queryRunner.query(
`CREATE INDEX "IDX_renote_muting_muterId" ON "muting" ("muterId") `,
);
}
async down(queryRunner) {
}
async down(queryRunner) {}
}

View File

@ -1,4 +1,11 @@
import { PrimaryColumn, Entity, Index, JoinColumn, Column, ManyToOne } from "typeorm";
import {
PrimaryColumn,
Entity,
Index,
JoinColumn,
Column,
ManyToOne,
} from "typeorm";
import { id } from "../id.js";
import { User } from "./user.js";

View File

@ -10,7 +10,8 @@ export const RenoteMutingRepository = db.getRepository(RenoteMuting).extend({
src: RenoteMuting["id"] | RenoteMuting,
me?: { id: User["id"] } | null | undefined,
): Promise<Packed<"RenoteMuting">> {
const muting = typeof src === "object" ? src : await this.findOneByOrFail({ id: src });
const muting =
typeof src === "object" ? src : await this.findOneByOrFail({ id: src });
return await awaitAll({
id: muting.id,
@ -22,10 +23,7 @@ export const RenoteMutingRepository = db.getRepository(RenoteMuting).extend({
});
},
packMany(
mutings: any[],
me: { id: User["id"] },
) {
return Promise.all(mutings.map(x => this.pack(x, me)));
packMany(mutings: any[], me: { id: User["id"] }) {
return Promise.all(mutings.map((x) => this.pack(x, me)));
},
});

View File

@ -3,23 +3,27 @@ export const packedRenoteMutingSchema = {
properties: {
id: {
type: "string",
optional: false, nullable: false,
optional: false,
nullable: false,
format: "id",
example: "xxxxxxxxxx",
},
createdAt: {
type: "string",
optional: false, nullable: false,
optional: false,
nullable: false,
format: "date-time",
},
muteeId: {
type: "string",
optional: false, nullable: false,
optional: false,
nullable: false,
format: "id",
},
mutee: {
type: "object",
optional: false, nullable: false,
optional: false,
nullable: false,
ref: "UserDetailed",
},
},

View File

@ -337,7 +337,8 @@ export const packedUserDetailedNotMeOnlySchema = {
},
isRenoteMuted: {
type: "boolean",
nullable: false, optional: true,
nullable: false,
optional: true,
},
//#endregion
},

View File

@ -2,21 +2,27 @@ import { Brackets, SelectQueryBuilder } from "typeorm";
import { User } from "@/models/entities/user.js";
import { RenoteMutings } from "@/models/index.js";
export function generateMutedUserRenotesQueryForNotes(q: SelectQueryBuilder<any>, me: { id: User["id"] }): void {
export function generateMutedUserRenotesQueryForNotes(
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.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

@ -51,8 +51,9 @@ export default define(meta, paramDef, async (ps, user) => {
}
// Get mutee
const mutee = await getUser(ps.userId).catch(e => {
if (e.id === "15348ddd-432d-49c2-8a5a-8069753becff") throw new ApiError(meta.errors.noSuchUser);
const mutee = await getUser(ps.userId).catch((e) => {
if (e.id === "15348ddd-432d-49c2-8a5a-8069753becff")
throw new ApiError(meta.errors.noSuchUser);
throw e;
});

View File

@ -49,8 +49,9 @@ export default define(meta, paramDef, async (ps, user) => {
}
// Get mutee
const mutee = await getUser(ps.userId).catch(e => {
if (e.id === "15348ddd-432d-49c2-8a5a-8069753becff") throw new ApiError(meta.errors.noSuchUser);
const mutee = await getUser(ps.userId).catch((e) => {
if (e.id === "15348ddd-432d-49c2-8a5a-8069753becff")
throw new ApiError(meta.errors.noSuchUser);
throw e;
});

View File

@ -11,10 +11,12 @@ export const meta = {
res: {
type: "array",
optional: false, nullable: false,
optional: false,
nullable: false,
items: {
type: "object",
optional: false, nullable: false,
optional: false,
nullable: false,
ref: "RenoteMuting",
},
},
@ -32,12 +34,13 @@ export const paramDef = {
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me) => {
const query = makePaginationQuery(RenoteMutings.createQueryBuilder("muting"), ps.sinceId, ps.untilId)
.andWhere("muting.muterId = :meId", { meId: me.id });
const query = makePaginationQuery(
RenoteMutings.createQueryBuilder("muting"),
ps.sinceId,
ps.untilId,
).andWhere("muting.muterId = :meId", { meId: me.id });
const mutings = await query
.take(ps.limit)
.getMany();
const mutings = await query.take(ps.limit).getMany();
return await RenoteMutings.packMany(mutings, me);
});

View File

@ -59,7 +59,8 @@ export const meta = {
},
isRenoteMuted: {
type: "boolean",
optional: false, nullable: false,
optional: false,
nullable: false,
},
},
},
@ -113,7 +114,8 @@ export const meta = {
},
isRenoteMuted: {
type: "boolean",
optional: false, nullable: false,
optional: false,
nullable: false,
},
},
},

View File

@ -34,7 +34,8 @@ export default class extends Channel {
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
if (isUserRelated(note, this.blocking)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting))
return;
this.connection.cacheNote(note);

View File

@ -36,7 +36,8 @@ export default class extends Channel {
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
if (isUserRelated(note, this.blocking)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting))
return;
this.connection.cacheNote(note);

View File

@ -56,7 +56,8 @@ export default class extends Channel {
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
if (isUserRelated(note, this.blocking)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting))
return;
// 流れてきたNoteがミュートすべきNoteだったら無視する
// TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある)

View File

@ -36,8 +36,9 @@ export default class extends Channel {
if (isUserRelated(note, this.muting)) return;
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
if (isUserRelated(note, this.blocking)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting))
return;
this.connection.cacheNote(note);

View File

@ -54,7 +54,8 @@ export default class extends Channel {
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
if (isUserRelated(note, this.blocking)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting))
return;
// 流れてきたNoteがミュートすべきNoteだったら無視する
// TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある)

View File

@ -71,7 +71,8 @@ export default class extends Channel {
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
if (isUserRelated(note, this.blocking)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting))
return;
// 流れてきたNoteがミュートすべきNoteだったら無視する
// TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある)

View File

@ -48,7 +48,8 @@ export default class extends Channel {
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
if (isUserRelated(note, this.blocking)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting))
return;
// 流れてきたNoteがミュートすべきNoteだったら無視する
// TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある)

View File

@ -56,7 +56,8 @@ export default class extends Channel {
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
if (isUserRelated(note, this.blocking)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting)) return;
if (note.renote && !note.text && isUserRelated(note, this.renoteMuting))
return;
this.send("note", note);
}

View File

@ -765,9 +765,9 @@ export type Endpoints = {
"mute/create": { req: TODO; res: TODO };
"mute/delete": { req: { userId: User["id"] }; res: null };
"mute/list": { req: TODO; res: TODO };
"renote-mute/create": { req: TODO; res: TODO; };
"renote-mute/delete": { req: { userId: User['id'] }; res: null; };
"renote-mute/list": { req: TODO; res: TODO; };
"renote-mute/create": { req: TODO; res: TODO };
"renote-mute/delete": { req: { userId: User["id"] }; res: null };
"renote-mute/list": { req: TODO; res: TODO };
// my
"my/apps": { req: TODO; res: TODO };

View File

@ -7,36 +7,39 @@
<FormSuspense :p="init">
<FormTextarea v-model="hiddenTags" class="_formBlock">
<span>{{ i18n.ts.hiddenTags }}</span>
<template #caption>{{ i18n.ts.hiddenTagsDescription }}</template>
<template #caption>{{
i18n.ts.hiddenTagsDescription
}}</template>
</FormTextarea>
<FormButton primary class="_formBlock" @click="save"><i
class="ph-floppy-disk-back ph-bold ph-lg"></i>
{{ i18n.ts.save }}</FormButton>
<FormButton primary class="_formBlock" @click="save"
><i class="ph-floppy-disk-back ph-bold ph-lg"></i>
{{ i18n.ts.save }}</FormButton
>
</FormSuspense>
</MkSpacer>
</MkStickyContainer>
</template>
<script lang="ts" setup>
import { } from 'vue';
import FormButton from '@/components/MkButton.vue';
import FormTextarea from '@/components/form/textarea.vue';
import FormSuspense from '@/components/form/suspense.vue';
import * as os from '@/os';
import { fetchInstance } from '@/instance';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';
import {} from "vue";
import FormButton from "@/components/MkButton.vue";
import FormTextarea from "@/components/form/textarea.vue";
import FormSuspense from "@/components/form/suspense.vue";
import * as os from "@/os";
import { fetchInstance } from "@/instance";
import { i18n } from "@/i18n";
import { definePageMetadata } from "@/scripts/page-metadata";
let hiddenTags: string = $ref('');
let hiddenTags: string = $ref("");
async function init() {
const meta = await os.api('admin/meta');
const meta = await os.api("admin/meta");
hiddenTags = meta.hiddenTags.join("\n");
}
function save() {
os.apiWithDialog('admin/update-meta', {
os.apiWithDialog("admin/update-meta", {
hiddenTags: hiddenTags.split("\n").map((h: string) => h.trim()) || [],
}).then(() => {
fetchInstance();
@ -49,6 +52,6 @@ const headerTabs = $computed(() => []);
definePageMetadata({
title: i18n.ts.hiddenTags,
icon: 'ph-hash ph-bold ph-lg',
icon: "ph-hash ph-bold ph-lg",
});
</script>

View File

@ -118,9 +118,12 @@ export function getUserMenu(user, router: Router = mainRouter) {
}
async function toggleRenoteMute(): Promise<void> {
os.apiWithDialog(user.isRenoteMuted ? "renote-mute/delete" : "renote-mute/create", {
userId: user.id,
}).then(() => {
os.apiWithDialog(
user.isRenoteMuted ? "renote-mute/delete" : "renote-mute/create",
{
userId: user.id,
},
).then(() => {
user.isRenoteMuted = !user.isRenoteMuted;
});
}