From 2e55c292bfe4b742df11cb7f3222da2d479963f6 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 28 Dec 2023 17:21:02 +0000 Subject: [PATCH] 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 d9853e7700..596f4da711 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 c114707b23..0106df9c49 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,