diff --git a/locales/en-US.yml b/locales/en-US.yml index 1ade50c7f2..f34855fcd9 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -1283,6 +1283,8 @@ _channel: following: "Followed" usersCount: "{n} Participants" notesCount: "{n} Posts" + nameAndDescription: "Name and description" + nameOnly: "Name only" _messaging: dms: "Private" groups: "Groups" diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index cb01fb564b..0eb17e5afb 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1147,6 +1147,8 @@ _channel: following: "フォロー中" usersCount: "{n}人が参加中" notesCount: "{n}投稿があります" + nameAndDescription: "名前と説明" + nameOnly: "名前のみ" _messaging: dms: "プライベート" groups: "グループ" diff --git a/locales/zh-CN.yml b/locales/zh-CN.yml index 645f11f568..8ca19e5969 100644 --- a/locales/zh-CN.yml +++ b/locales/zh-CN.yml @@ -1070,6 +1070,8 @@ _channel: following: "正在关注" usersCount: "有{n}人参与" notesCount: "有{n}个帖子" + nameAndDescription: "名称与描述" + nameOnly: "仅名称" _menuDisplay: sideFull: "横向" sideIcon: "横向(图标)" diff --git a/locales/zh-TW.yml b/locales/zh-TW.yml index 477b8ceb3c..42fec8279d 100644 --- a/locales/zh-TW.yml +++ b/locales/zh-TW.yml @@ -1073,6 +1073,8 @@ _channel: following: "關注中" usersCount: "有{n}人參與" notesCount: "有{n}個貼文" + nameAndDescription: "名稱與說明" + nameOnly: "僅名稱" _menuDisplay: sideFull: "側向" sideIcon: "側向(圖示)" diff --git a/packages/backend/src/misc/sql-like-escape.ts b/packages/backend/src/misc/sql-like-escape.ts new file mode 100644 index 0000000000..453947d6ec --- /dev/null +++ b/packages/backend/src/misc/sql-like-escape.ts @@ -0,0 +1,3 @@ +export function sqlLikeEscape(s: string) { + return s.replace(/([%_])/g, "\\$1"); +} diff --git a/packages/backend/src/server/api/endpoints.ts b/packages/backend/src/server/api/endpoints.ts index 3f82eb7a73..e6f8f7ee6a 100644 --- a/packages/backend/src/server/api/endpoints.ts +++ b/packages/backend/src/server/api/endpoints.ts @@ -89,6 +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_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"; @@ -438,6 +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/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 new file mode 100644 index 0000000000..b21fa76206 --- /dev/null +++ b/packages/backend/src/server/api/endpoints/channels/search.ts @@ -0,0 +1,69 @@ +import define from "../../define.js"; +import { Brackets } from "typeorm"; +import { Endpoint } from "@/server/api/endpoint-base.js"; +import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js"; +import { Channels } from "@/models/index.js"; +import { DI } from "@/di-symbols.js"; +import { sqlLikeEscape } from "@/misc/sql-like-escape.js"; + +export const meta = { + tags: ["channels"], + + requireCredential: false, + + res: { + type: "array", + optional: false, + nullable: false, + items: { + type: "object", + optional: false, + nullable: false, + ref: "Channel", + }, + }, +} as const; + +export const paramDef = { + 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 }, + }, + required: ["query"], +} as const; + +export default define(meta, paramDef, async (ps, me) => { + const query = makePaginationQuery( + Channels.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)}%`, + }); + }), + ); + } else { + query.andWhere("channel.name ILIKE :q", { + q: `%${sqlLikeEscape(ps.query)}%`, + }); + } + + const channels = await query.take(ps.limit).getMany(); + + return await Promise.all(channels.map((x) => Channels.pack(x, me))); +}); diff --git a/packages/client/src/components/MkChannelList.vue b/packages/client/src/components/MkChannelList.vue new file mode 100644 index 0000000000..0379c81034 --- /dev/null +++ b/packages/client/src/components/MkChannelList.vue @@ -0,0 +1,42 @@ + + + + + + {{ i18n.ts.notFound }} + + + + + + + + + + + + diff --git a/packages/client/src/pages/channels.vue b/packages/client/src/pages/channels.vue index 2d8eeefcfc..705b996710 100644 --- a/packages/client/src/pages/channels.vue +++ b/packages/client/src/pages/channels.vue @@ -20,6 +20,52 @@ @swiper="setSwiperRef" @slide-change="onSlideChange" > + + + + + + + + {{ i18n.ts._channel.nameAndDescription }} + + + {{ i18n.ts._channel.nameOnly }} + + + {{ i18n.ts.search }} + + {{ + i18n.ts.searchResult + }} + + + +