From 9abb1267e1263b4e472bd2d34d32df6b4874065a Mon Sep 17 00:00:00 2001 From: Esurio Date: Fri, 9 Aug 2024 14:35:24 +0000 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20excludeNsfw=E3=82=92=E5=BE=A9?= =?UTF-8?q?=E6=B4=BB=E3=81=95=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/SearchService.ts | 6 ++++++ .../backend/src/server/api/endpoints/notes/search.ts | 4 ++-- packages/cherrypick-js/src/autogen/types.ts | 7 ++----- packages/frontend/src/pages/search.note.vue | 10 ++++++++++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts index 6b7c50ec2f..9a675b726e 100644 --- a/packages/backend/src/core/SearchService.ts +++ b/packages/backend/src/core/SearchService.ts @@ -60,6 +60,7 @@ export class SearchService { channelId?: MiNote['channelId'] | null; host?: string | null; fileOption?: string | null; + excludeNsfw?: boolean; }, pagination: { untilId?: MiNote['id']; sinceId?: MiNote['id']; @@ -91,6 +92,11 @@ export class SearchService { } } + if (opts.excludeNsfw) { + query.andWhere('note.cw IS NULL'); + query.andWhere('0 = (SELECT COUNT(*) FROM drive_file df WHERE df.id = ANY(note."fileIds") AND df."isSensitive" = TRUE )'); + } + /** * if (this.config.pgroonga) { * query.andWhere('note.text &@~ :q', { q: `%${sqlLikeEscape(q)}%` }); diff --git a/packages/backend/src/server/api/endpoints/notes/search.ts b/packages/backend/src/server/api/endpoints/notes/search.ts index e724294288..847cd65a68 100644 --- a/packages/backend/src/server/api/endpoints/notes/search.ts +++ b/packages/backend/src/server/api/endpoints/notes/search.ts @@ -41,7 +41,6 @@ export const paramDef = { sinceId: { type: 'string', format: 'misskey:id' }, untilId: { type: 'string', format: 'misskey:id' }, limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, - origin: { type: 'string', enum: ['local', 'remote', 'combined'], default: 'combined' }, offset: { type: 'integer', default: 0 }, host: { type: 'string', @@ -49,6 +48,7 @@ export const paramDef = { }, userId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, channelId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, + excludeNsfw: { type: 'boolean', default: false }, }, required: ['query'], } as const; @@ -72,7 +72,7 @@ export default class extends Endpoint { // eslint- userId: ps.userId, channelId: ps.channelId, host: ps.host, - origin: ps.origin, + excludeNsfw: ps.excludeNsfw, }, { untilId: ps.untilId, sinceId: ps.sinceId, diff --git a/packages/cherrypick-js/src/autogen/types.ts b/packages/cherrypick-js/src/autogen/types.ts index 2fa1db46f8..f086ac3286 100644 --- a/packages/cherrypick-js/src/autogen/types.ts +++ b/packages/cherrypick-js/src/autogen/types.ts @@ -23698,11 +23698,6 @@ export type operations = { untilId?: string; /** @default 10 */ limit?: number; - /** - * @default combined - * @enum {string} - */ - origin?: 'local' | 'remote' | 'combined'; /** @default 0 */ offset?: number; /** @description The local host is represented with `.`. */ @@ -23717,6 +23712,8 @@ export type operations = { * @default null */ channelId?: string | null; + /** @default false */ + excludeNsfw?: boolean; }; }; }; diff --git a/packages/frontend/src/pages/search.note.vue b/packages/frontend/src/pages/search.note.vue index e197da18e1..1289b9c6ec 100644 --- a/packages/frontend/src/pages/search.note.vue +++ b/packages/frontend/src/pages/search.note.vue @@ -36,6 +36,13 @@ SPDX-License-Identifier: AGPL-3.0-only + + + +
+ {{ i18n.ts._advancedSearch._searchOption.toggleCW }} +
+
@@ -66,6 +73,7 @@ import MkUserCardMini from '@/components/MkUserCardMini.vue'; import MkRadios from '@/components/MkRadios.vue'; import { $i } from '@/account.js'; import { instance } from '@/instance.js'; +import MkSwitch from '@/components/MkSwitch.vue'; const props = withDefaults(defineProps<{ query?: string; @@ -85,6 +93,7 @@ const searchQuery = ref(toRef(props, 'query').value); const notePagination = ref(); const user = ref(null); const hostInput = ref(toRef(props, 'host').value); +const excludeNsfw = ref(false); const noteSearchableScope = instance.noteSearchableScope ?? 'local'; @@ -198,6 +207,7 @@ async function search() { query: searchQuery.value, userId: user.value ? user.value.id : null, ...(searchHost.value ? { host: searchHost.value } : {}), + excludeNsfw: excludeNsfw.value, }, }; From f723c4348aff6dd88d9db99636534e112398438c Mon Sep 17 00:00:00 2001 From: Esurio Date: Fri, 9 Aug 2024 14:52:40 +0000 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E6=A4=9C=E7=B4=A2=E3=81=8B?= =?UTF-8?q?=E3=82=89Bot=E3=82=92=E9=99=A4=E5=A4=96=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=AA=E3=83=97=E3=82=B7=E3=83=A7=E3=83=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/SearchService.ts | 5 +++++ packages/backend/src/server/api/endpoints/notes/search.ts | 2 ++ packages/cherrypick-js/src/autogen/types.ts | 2 ++ packages/frontend/src/pages/search.note.vue | 2 ++ 4 files changed, 11 insertions(+) diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts index 9a675b726e..ff3897cc51 100644 --- a/packages/backend/src/core/SearchService.ts +++ b/packages/backend/src/core/SearchService.ts @@ -61,6 +61,7 @@ export class SearchService { host?: string | null; fileOption?: string | null; excludeNsfw?: boolean; + excludeBot?: boolean; }, pagination: { untilId?: MiNote['id']; sinceId?: MiNote['id']; @@ -97,6 +98,10 @@ export class SearchService { query.andWhere('0 = (SELECT COUNT(*) FROM drive_file df WHERE df.id = ANY(note."fileIds") AND df."isSensitive" = TRUE )'); } + if (opts.excludeBot) { + query.andWhere(' (SELECT "isBot" FROM "user" WHERE id = note."userId") = FALSE '); + } + /** * if (this.config.pgroonga) { * query.andWhere('note.text &@~ :q', { q: `%${sqlLikeEscape(q)}%` }); diff --git a/packages/backend/src/server/api/endpoints/notes/search.ts b/packages/backend/src/server/api/endpoints/notes/search.ts index 847cd65a68..f52942a857 100644 --- a/packages/backend/src/server/api/endpoints/notes/search.ts +++ b/packages/backend/src/server/api/endpoints/notes/search.ts @@ -49,6 +49,7 @@ export const paramDef = { userId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, channelId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, excludeNsfw: { type: 'boolean', default: false }, + excludeBot: { type: 'boolean', default: false }, }, required: ['query'], } as const; @@ -73,6 +74,7 @@ export default class extends Endpoint { // eslint- channelId: ps.channelId, host: ps.host, excludeNsfw: ps.excludeNsfw, + excludeBot: ps.excludeBot, }, { untilId: ps.untilId, sinceId: ps.sinceId, diff --git a/packages/cherrypick-js/src/autogen/types.ts b/packages/cherrypick-js/src/autogen/types.ts index f086ac3286..3898acfeb2 100644 --- a/packages/cherrypick-js/src/autogen/types.ts +++ b/packages/cherrypick-js/src/autogen/types.ts @@ -23714,6 +23714,8 @@ export type operations = { channelId?: string | null; /** @default false */ excludeNsfw?: boolean; + /** @default false */ + excludeBot?: boolean; }; }; }; diff --git a/packages/frontend/src/pages/search.note.vue b/packages/frontend/src/pages/search.note.vue index 1289b9c6ec..02f5cc892c 100644 --- a/packages/frontend/src/pages/search.note.vue +++ b/packages/frontend/src/pages/search.note.vue @@ -41,6 +41,7 @@ SPDX-License-Identifier: AGPL-3.0-only
{{ i18n.ts._advancedSearch._searchOption.toggleCW }} + {{ i18n.ts.antennaExcludeBots }}
@@ -94,6 +95,7 @@ const notePagination = ref(); const user = ref(null); const hostInput = ref(toRef(props, 'host').value); const excludeNsfw = ref(false); +const excludeBot = ref(false); const noteSearchableScope = instance.noteSearchableScope ?? 'local'; From 87e577ee833c384453ed1b0bc88da80f7a8294e4 Mon Sep 17 00:00:00 2001 From: Esurio Date: Fri, 9 Aug 2024 15:30:24 +0000 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=81=AE=E6=9C=89=E7=84=A1=E3=82=92=E3=83=95=E3=82=A3?= =?UTF-8?q?=E3=83=AB=E3=82=BF=E3=83=BC=E3=81=99=E3=82=8B=E6=A9=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/SearchService.ts | 8 ++++++++ packages/backend/src/server/api/endpoints/notes/search.ts | 2 ++ packages/cherrypick-js/src/autogen/types.ts | 5 +++++ packages/frontend/src/pages/search.note.vue | 8 ++++++++ 4 files changed, 23 insertions(+) diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts index ff3897cc51..748dae1867 100644 --- a/packages/backend/src/core/SearchService.ts +++ b/packages/backend/src/core/SearchService.ts @@ -93,6 +93,14 @@ export class SearchService { } } + if (opts.fileOption) { + if (opts.fileOption === 'fileOnly') { + query.andWhere('note.fileIds != \'{}\' ') + } else if (opts.fileOption === 'noFile') { + query.andWhere('note.fileIds = \'{}\' ') + } + } + if (opts.excludeNsfw) { query.andWhere('note.cw IS NULL'); query.andWhere('0 = (SELECT COUNT(*) FROM drive_file df WHERE df.id = ANY(note."fileIds") AND df."isSensitive" = TRUE )'); diff --git a/packages/backend/src/server/api/endpoints/notes/search.ts b/packages/backend/src/server/api/endpoints/notes/search.ts index f52942a857..e1d40d9233 100644 --- a/packages/backend/src/server/api/endpoints/notes/search.ts +++ b/packages/backend/src/server/api/endpoints/notes/search.ts @@ -48,6 +48,7 @@ export const paramDef = { }, userId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, channelId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, + fileOption: { type: 'string', enum: ['combined', 'fileOnly', 'noFile'], default: 'combined' }, excludeNsfw: { type: 'boolean', default: false }, excludeBot: { type: 'boolean', default: false }, }, @@ -73,6 +74,7 @@ export default class extends Endpoint { // eslint- userId: ps.userId, channelId: ps.channelId, host: ps.host, + fileOption: ps.fileOption, excludeNsfw: ps.excludeNsfw, excludeBot: ps.excludeBot, }, { diff --git a/packages/cherrypick-js/src/autogen/types.ts b/packages/cherrypick-js/src/autogen/types.ts index 3898acfeb2..2d9b491def 100644 --- a/packages/cherrypick-js/src/autogen/types.ts +++ b/packages/cherrypick-js/src/autogen/types.ts @@ -23712,6 +23712,11 @@ export type operations = { * @default null */ channelId?: string | null; + /** + * @default combined + * @enum {string} + */ + fileOption?: 'combined' | 'fileOnly' | 'noFile'; /** @default false */ excludeNsfw?: boolean; /** @default false */ diff --git a/packages/frontend/src/pages/search.note.vue b/packages/frontend/src/pages/search.note.vue index 02f5cc892c..d60bcaa74c 100644 --- a/packages/frontend/src/pages/search.note.vue +++ b/packages/frontend/src/pages/search.note.vue @@ -42,6 +42,11 @@ SPDX-License-Identifier: AGPL-3.0-only
{{ i18n.ts._advancedSearch._searchOption.toggleCW }} {{ i18n.ts.antennaExcludeBots }} + + + + +
@@ -96,6 +101,7 @@ const user = ref(null); const hostInput = ref(toRef(props, 'host').value); const excludeNsfw = ref(false); const excludeBot = ref(false); +const fileOption = ref('combined'); const noteSearchableScope = instance.noteSearchableScope ?? 'local'; @@ -210,6 +216,8 @@ async function search() { userId: user.value ? user.value.id : null, ...(searchHost.value ? { host: searchHost.value } : {}), excludeNsfw: excludeNsfw.value, + excludeBot: excludeBot.value, + fileOption: fileOption.value, }, }; From f61911d8816cd33a0d3908d2eb70b1bd65ee753d Mon Sep 17 00:00:00 2001 From: Esurio Date: Sat, 10 Aug 2024 13:42:40 +0000 Subject: [PATCH 4/4] update changelog --- CHANGELOG_engawa.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG_engawa.md b/CHANGELOG_engawa.md index e3f4dc2610..51cec6a22f 100644 --- a/CHANGELOG_engawa.md +++ b/CHANGELOG_engawa.md @@ -26,7 +26,7 @@ - 検索ウィジェットにオートフォーカスが当たらなくなりました ### Server -- +- 検索機能に新しいパラメータを追加( [1673beta/cherrypick#94](https://github.com/1673beta/cherrypick/issues/94) ) ### Misc