mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #12821, improvements to search bar and search logic
- Entering a webfinger handle in search bar will override default `searchIn` to `users` - When an activitypub uri is entered, it is fetched and its `type` is checked. If `type` is `user`, a user search is conducted instead. If `type` is not post-like or user-like, a regular full-text search is performed (prior, it just threw an exception!)
This commit is contained in:
@@ -26,6 +26,7 @@ define('search', [
|
||||
|
||||
const quickSearchContainer = searchFields.find('#quick-search-container');
|
||||
const toggleVisibility = searchFields.hasClass('hidden');
|
||||
const webfingerRegex = /^(@|acct:)?[\w-]+@.+$/; // should match src/activitypub/helpers.js
|
||||
|
||||
if (toggleVisibility) {
|
||||
searchInput.off('blur').on('blur', function dismissSearch() {
|
||||
@@ -70,6 +71,12 @@ define('search', [
|
||||
const data = Search.getSearchPreferences();
|
||||
data.term = input.val();
|
||||
data.in = searchOptions.in;
|
||||
|
||||
// Override search target if webfinger handle entered
|
||||
if (webfingerRegex.test(data.term)) {
|
||||
data.in = 'users';
|
||||
}
|
||||
|
||||
hooks.fire('action:search.submit', {
|
||||
searchOptions: data,
|
||||
searchElements: searchElements,
|
||||
|
||||
@@ -92,7 +92,14 @@ async function searchInContent(data) {
|
||||
if (local.type === 'post') {
|
||||
result = [[local.id], []];
|
||||
} else {
|
||||
result = await fetchRemoteObject(data.uid, data.query);
|
||||
try {
|
||||
result = await fetchRemoteObject(data);
|
||||
if (result.hasOwnProperty('users')) {
|
||||
return result;
|
||||
}
|
||||
} catch (e) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +153,9 @@ async function searchInContent(data) {
|
||||
return Object.assign(returnData, metadata);
|
||||
}
|
||||
|
||||
async function fetchRemoteObject(uid, uri) {
|
||||
async function fetchRemoteObject(data) {
|
||||
const { uid, query: uri } = data;
|
||||
|
||||
try {
|
||||
let id = uri;
|
||||
let exists = await posts.exists(id);
|
||||
@@ -161,6 +170,9 @@ async function fetchRemoteObject(uid, uri) {
|
||||
} else {
|
||||
tid = await posts.getPostField(id, 'tid');
|
||||
}
|
||||
} else if (activitypub._constants.acceptableActorTypes.has(type)) {
|
||||
data.searchIn = 'users';
|
||||
return await user.search(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user