From 2e55c292bfe4b742df11cb7f3222da2d479963f6 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 28 Dec 2023 17:21:02 +0000 Subject: [PATCH 1/2] special-case full usernames is search #264 this should be enough "merging" of lookup&search: * partial usernames are searched as part of notes from the widget, and as part of known usernames in "search users" * tags are searched as part of notes from the widget and the "search notes" page * full usernames always navigate to the profile page of that user (which will fetch the profile if possible) as an extra nicety, if "search notes" is disabled, the search widget handles hashtags like the lookup function does --- packages/frontend/src/pages/search.user.vue | 5 +++++ packages/frontend/src/widgets/WidgetSearch.vue | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/frontend/src/pages/search.user.vue b/packages/frontend/src/pages/search.user.vue index d9853e770..596f4da71 100644 --- a/packages/frontend/src/pages/search.user.vue +++ b/packages/frontend/src/pages/search.user.vue @@ -65,6 +65,11 @@ async function search() { return; } + if (query.match(/^@[a-z0-9_.-]+@[a-z0-9_.-]+$/i)) { + router.push(`/${query}`); + return; + } + userPagination.value = { endpoint: 'users/search', limit: 10, diff --git a/packages/frontend/src/widgets/WidgetSearch.vue b/packages/frontend/src/widgets/WidgetSearch.vue index c114707b2..0106df9c4 100644 --- a/packages/frontend/src/widgets/WidgetSearch.vue +++ b/packages/frontend/src/widgets/WidgetSearch.vue @@ -23,6 +23,8 @@ import { i18n } from '@/i18n.js'; import * as os from '@/os.js'; import { useRouter } from '@/router.js'; import { GetFormResultType } from '@/scripts/form.js'; +import { $i } from '@/account.js'; +import { instance } from '@/instance.js'; const name = 'search'; @@ -60,6 +62,7 @@ let notePagination = ref(); let isLocalOnly = ref(false); let order = ref(true); let filetype = ref(null); +const notesSearchAvailable = (($i == null && instance.policies.canSearchNotes) || ($i != null && $i.policies.canSearchNotes)); function options(ev) { os.popupMenu([{ @@ -117,6 +120,19 @@ async function search() { return; } + if (query.match(/^@[a-z0-9_.-]+@[a-z0-9_.-]+$/i)) { + router.push(`/${query}`); + return; + } + + if (!notesSearchAvailable && query.startsWith('#')) { + // can't really search, at least try handling hashtags + router.push(`/tags/${encodeURIComponent(query.substring(1))}`); + return; + } + + // TODO: if !notesSearchAvailable pop up an error message + notePagination.value = { endpoint: 'notes/search', limit: 10, From cd8ba4b634cbaf1656a2631eaf02f0e5dcdf397d Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 29 Dec 2023 14:54:01 +0000 Subject: [PATCH 2/2] always go to tag page from widget #264 --- packages/frontend/src/widgets/WidgetSearch.vue | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/frontend/src/widgets/WidgetSearch.vue b/packages/frontend/src/widgets/WidgetSearch.vue index 0106df9c4..999913977 100644 --- a/packages/frontend/src/widgets/WidgetSearch.vue +++ b/packages/frontend/src/widgets/WidgetSearch.vue @@ -23,8 +23,6 @@ import { i18n } from '@/i18n.js'; import * as os from '@/os.js'; import { useRouter } from '@/router.js'; import { GetFormResultType } from '@/scripts/form.js'; -import { $i } from '@/account.js'; -import { instance } from '@/instance.js'; const name = 'search'; @@ -62,7 +60,6 @@ let notePagination = ref(); let isLocalOnly = ref(false); let order = ref(true); let filetype = ref(null); -const notesSearchAvailable = (($i == null && instance.policies.canSearchNotes) || ($i != null && $i.policies.canSearchNotes)); function options(ev) { os.popupMenu([{ @@ -125,14 +122,11 @@ async function search() { return; } - if (!notesSearchAvailable && query.startsWith('#')) { - // can't really search, at least try handling hashtags + if (query.startsWith('#')) { router.push(`/tags/${encodeURIComponent(query.substring(1))}`); return; } - // TODO: if !notesSearchAvailable pop up an error message - notePagination.value = { endpoint: 'notes/search', limit: 10,