From 8a2135ba281fe0236514d6b6cabc5f8c97cdd3e6 Mon Sep 17 00:00:00 2001 From: naskya Date: Sun, 7 May 2023 08:05:18 +0900 Subject: [PATCH] format --- .../src/remote/activitypub/renderer/note.ts | 2 +- packages/backend/src/server/api/endpoints.ts | 4 +- .../server/api/endpoints/channels/search.ts | 81 +++++++++++-------- packages/backend/src/services/note/create.ts | 3 +- .../src/services/note/reaction/create.ts | 5 +- .../client/src/components/MkChannelList.vue | 56 +++++++------ .../client/src/components/MkRenoteButton.vue | 9 ++- packages/client/src/pages/channels.vue | 70 +++++++++++----- 8 files changed, 141 insertions(+), 89 deletions(-) diff --git a/packages/backend/src/remote/activitypub/renderer/note.ts b/packages/backend/src/remote/activitypub/renderer/note.ts index 5fe59b3ab7..280205eaf8 100644 --- a/packages/backend/src/remote/activitypub/renderer/note.ts +++ b/packages/backend/src/remote/activitypub/renderer/note.ts @@ -16,7 +16,7 @@ export default async function renderNote( dive = true, isTalk = false, ): Promise> { - note.visibility = note.visibility === "hidden" ? "home" : note.visibility; + note.visibility = note.visibility === "hidden" ? "home" : note.visibility; const getPromisedFiles = async (ids: string[]) => { if (!ids || ids.length === 0) return []; const items = await DriveFiles.findBy({ id: In(ids) }); diff --git a/packages/backend/src/server/api/endpoints.ts b/packages/backend/src/server/api/endpoints.ts index 3baa560a10..e6f8f7ee6a 100644 --- a/packages/backend/src/server/api/endpoints.ts +++ b/packages/backend/src/server/api/endpoints.ts @@ -89,7 +89,7 @@ import * as ep___channels_featured from "./endpoints/channels/featured.js"; import * as ep___channels_follow from "./endpoints/channels/follow.js"; import * as ep___channels_followed from "./endpoints/channels/followed.js"; import * as ep___channels_owned from "./endpoints/channels/owned.js"; -import * as ep___channels_search from './endpoints/channels/search.js'; +import * as ep___channels_search from "./endpoints/channels/search.js"; import * as ep___channels_show from "./endpoints/channels/show.js"; import * as ep___channels_timeline from "./endpoints/channels/timeline.js"; import * as ep___channels_unfollow from "./endpoints/channels/unfollow.js"; @@ -439,7 +439,7 @@ const eps = [ ["channels/follow", ep___channels_follow], ["channels/followed", ep___channels_followed], ["channels/owned", ep___channels_owned], - ['channels/search', ep___channels_search], + ["channels/search", ep___channels_search], ["channels/show", ep___channels_show], ["channels/timeline", ep___channels_timeline], ["channels/unfollow", ep___channels_unfollow], diff --git a/packages/backend/src/server/api/endpoints/channels/search.ts b/packages/backend/src/server/api/endpoints/channels/search.ts index a954ba224c..5527adb9b4 100644 --- a/packages/backend/src/server/api/endpoints/channels/search.ts +++ b/packages/backend/src/server/api/endpoints/channels/search.ts @@ -1,38 +1,44 @@ -import { Inject, Injectable } from '@nestjs/common'; -import { Brackets } from 'typeorm'; -import { Endpoint } from '@/server/api/endpoint-base.js'; -import { QueryService } from '@/core/QueryService.js'; -import type { ChannelsRepository } from '@/models/index.js'; -import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js'; -import { DI } from '@/di-symbols.js'; -import { sqlLikeEscape } from '@/misc/sql-like-escape.js'; +import { Inject, Injectable } from "@nestjs/common"; +import { Brackets } from "typeorm"; +import { Endpoint } from "@/server/api/endpoint-base.js"; +import { QueryService } from "@/core/QueryService.js"; +import type { ChannelsRepository } from "@/models/index.js"; +import { ChannelEntityService } from "@/core/entities/ChannelEntityService.js"; +import { DI } from "@/di-symbols.js"; +import { sqlLikeEscape } from "@/misc/sql-like-escape.js"; export const meta = { - tags: ['channels'], + tags: ["channels"], requireCredential: false, res: { - type: 'array', - optional: false, nullable: false, + type: "array", + optional: false, + nullable: false, items: { - type: 'object', - optional: false, nullable: false, - ref: 'Channel', + type: "object", + optional: false, + nullable: false, + ref: "Channel", }, }, } as const; export const paramDef = { - type: 'object', + type: "object", properties: { - query: { type: 'string' }, - type: { type: 'string', enum: ['nameAndDescription', 'nameOnly'], default: 'nameAndDescription' }, - sinceId: { type: 'string', format: 'misskey:id' }, - untilId: { type: 'string', format: 'misskey:id' }, - limit: { type: 'integer', minimum: 1, maximum: 100, default: 5 }, + query: { type: "string" }, + type: { + type: "string", + enum: ["nameAndDescription", "nameOnly"], + default: "nameAndDescription", + }, + sinceId: { type: "string", format: "misskey:id" }, + untilId: { type: "string", format: "misskey:id" }, + limit: { type: "integer", minimum: 1, maximum: 100, default: 5 }, }, - required: ['query'], + required: ["query"], } as const; // eslint-disable-next-line import/no-default-export @@ -46,22 +52,33 @@ export default class extends Endpoint { private queryService: QueryService, ) { super(meta, paramDef, async (ps, me) => { - const query = this.queryService.makePaginationQuery(this.channelsRepository.createQueryBuilder('channel'), ps.sinceId, ps.untilId); + const query = this.queryService.makePaginationQuery( + this.channelsRepository.createQueryBuilder("channel"), + ps.sinceId, + ps.untilId, + ); - if (ps.type === 'nameAndDescription') { - query.andWhere(new Brackets(qb => { qb - .where('channel.name ILIKE :q', { q: `%${ sqlLikeEscape(ps.query) }%` }) - .orWhere('channel.description ILIKE :q', { q: `%${ sqlLikeEscape(ps.query) }%` }); - })); + if (ps.type === "nameAndDescription") { + query.andWhere( + new Brackets((qb) => { + qb.where("channel.name ILIKE :q", { + q: `%${sqlLikeEscape(ps.query)}%`, + }).orWhere("channel.description ILIKE :q", { + q: `%${sqlLikeEscape(ps.query)}%`, + }); + }), + ); } else { - query.andWhere('channel.name ILIKE :q', { q: `%${ sqlLikeEscape(ps.query) }%` }); + query.andWhere("channel.name ILIKE :q", { + q: `%${sqlLikeEscape(ps.query)}%`, + }); } - const channels = await query - .take(ps.limit) - .getMany(); + const channels = await query.take(ps.limit).getMany(); - return await Promise.all(channels.map(x => this.channelEntityService.pack(x, me))); + return await Promise.all( + channels.map((x) => this.channelEntityService.pack(x, me)), + ); }); } } diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 2a7b00b0fb..721147dd6b 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -606,8 +606,7 @@ export default async ( }); async function renderNoteOrRenoteActivity(data: Option, note: Note) { - if (data.localOnly || - note.visibility !== "hidden") return null; + if (data.localOnly || note.visibility !== "hidden") return null; const content = data.renote && diff --git a/packages/backend/src/services/note/reaction/create.ts b/packages/backend/src/services/note/reaction/create.ts index 9f4ed1375b..277393eb41 100644 --- a/packages/backend/src/services/note/reaction/create.ts +++ b/packages/backend/src/services/note/reaction/create.ts @@ -144,10 +144,7 @@ export default async ( }); //#region deliver - if ( - Users.isLocalUser(user) && - !note.localOnly - ) { + if (Users.isLocalUser(user) && !note.localOnly) { const content = renderActivity(await renderLike(record, note)); const dm = new DeliverManager(user, content); if (note.userHost !== null) { diff --git a/packages/client/src/components/MkChannelList.vue b/packages/client/src/components/MkChannelList.vue index 408eab7399..e73ecb8b9a 100644 --- a/packages/client/src/components/MkChannelList.vue +++ b/packages/client/src/components/MkChannelList.vue @@ -1,31 +1,41 @@ - + diff --git a/packages/client/src/components/MkRenoteButton.vue b/packages/client/src/components/MkRenoteButton.vue index ea01fcdc0a..b70edda7d5 100644 --- a/packages/client/src/components/MkRenoteButton.vue +++ b/packages/client/src/components/MkRenoteButton.vue @@ -35,7 +35,7 @@ const buttonRef = ref(); const canRenote = computed( () => - ["public", "home","hidden"].includes(props.note.visibility) || + ["public", "home", "hidden"].includes(props.note.visibility) || props.note.userId === $i.id ); @@ -75,7 +75,10 @@ const renote = async (viaKeyboard = false, ev?: MouseEvent) => { let buttonActions = []; - if (props.note.visibility === "public" || props.note.visibility === "hidden") { + if ( + props.note.visibility === "public" || + props.note.visibility === "hidden" + ) { buttonActions.push({ text: i18n.ts.renote, textStyle: "font-weight: bold", @@ -102,7 +105,7 @@ const renote = async (viaKeyboard = false, ev?: MouseEvent) => { }); } - if (["public", "home","hidden"].includes(props.note.visibility)) { + if (["public", "home", "hidden"].includes(props.note.visibility)) { buttonActions.push({ text: `${i18n.ts.renote} (${i18n.ts._visibility.home})`, icon: "ph-house ph-bold ph-lg", diff --git a/packages/client/src/pages/channels.vue b/packages/client/src/pages/channels.vue index f243f93459..3fcda33d4d 100644 --- a/packages/client/src/pages/channels.vue +++ b/packages/client/src/pages/channels.vue @@ -23,18 +23,44 @@ @@ -96,12 +122,12 @@ import { computed, onMounted, defineComponent, inject, watch } from "vue"; import { Virtual } from "swiper"; import { Swiper, SwiperSlide } from "swiper/vue"; import MkChannelPreview from "@/components/MkChannelPreview.vue"; -import MkChannelList from '@/components/MkChannelList.vue'; +import MkChannelList from "@/components/MkChannelList.vue"; import MkPagination from "@/components/MkPagination.vue"; -import MkInput from '@/components/MkInput.vue'; -import MkRadios from '@/components/MkRadios.vue'; +import MkInput from "@/components/MkInput.vue"; +import MkRadios from "@/components/MkRadios.vue"; import MkButton from "@/components/MkButton.vue"; -import MkFoldableSection from '@/components/MkFoldableSection.vue'; +import MkFoldableSection from "@/components/MkFoldableSection.vue"; import { useRouter } from "@/router"; import { definePageMetadata } from "@/scripts/page-metadata"; import { deviceKind } from "@/scripts/device-kind"; @@ -120,14 +146,14 @@ const props = defineProps<{ query: string; type?: string; }>(); -let key = $ref(''); -let tab = $ref('search'); -let searchQuery = $ref(''); -let searchType = $ref('nameAndDescription'); +let key = $ref(""); +let tab = $ref("search"); +let searchQuery = $ref(""); +let searchType = $ref("nameAndDescription"); let channelPagination = $ref(); onMounted(() => { - searchQuery = props.query ?? ''; - searchType = props.type ?? 'nameAndDescription'; + searchQuery = props.query ?? ""; + searchType = props.type ?? "nameAndDescription"; }); const featuredPagination = { @@ -146,10 +172,10 @@ const ownedPagination = { async function search() { const query = searchQuery.toString().trim(); - if (query == null || query === '') return; + if (query == null || query === "") return; const type = searchType.toString().trim(); channelPagination = { - endpoint: 'channels/search', + endpoint: "channels/search", limit: 10, params: { query: searchQuery, @@ -173,9 +199,9 @@ const headerActions = $computed(() => [ const headerTabs = $computed(() => [ { - key: 'search', + key: "search", title: i18n.ts.search, - icon: 'ti ti-search', + icon: "ti ti-search", }, { key: "featured",