diff --git a/CHANGELOG.md b/CHANGELOG.md index cd6f88457..77e026a95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ - Added UI Settings modal and fixed height media previews setting ([f2467e71](https://github.com/pixelfed/pixelfed/commit/f2467e71)) - Set max-width of 1440px for larger screens ([af68872a](https://github.com/pixelfed/pixelfed/commit/af68872a)) - Add link to sidebar profile card ([85964510](https://github.com/pixelfed/pixelfed/commit/85964510)) +- Improved search bar, now resolves (and imports) remote accounts and posts, including webfinger addresses ([c8a667f2](https://github.com/pixelfed/pixelfed/commit/c8a667f2)) +- Added user facing changelog at `/i/web/whats-new` ([e61dc66a](https://github.com/pixelfed/pixelfed/commit/e61dc66a)) ### Configuration - Enable network timeline by default ([b95aec12](https://github.com/pixelfed/pixelfed/commit/b95aec12)) @@ -95,6 +97,7 @@ - Updated ApiV1Controller, fix home timeline entities. ([6fc0dcb3](https://github.com/pixelfed/pixelfed/commit/6fc0dcb3)) - Updated ApiV1Controller, fix favourites endpoints ([d6d99385](https://github.com/pixelfed/pixelfed/commit/d6d99385)) - Updated ApiV1Controller, fix reblogs endpoints ([de42d84c](https://github.com/pixelfed/pixelfed/commit/de42d84c)) +- Updated SearchApiV2Service, resolve remote queries. ([c8a667f2](https://github.com/pixelfed/pixelfed/commit/c8a667f2)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.1 (2021-09-07)](https://github.com/pixelfed/pixelfed/compare/v0.11.0...v0.11.1) diff --git a/app/Services/SearchApiV2Service.php b/app/Services/SearchApiV2Service.php index f3633481c..41487f175 100644 --- a/app/Services/SearchApiV2Service.php +++ b/app/Services/SearchApiV2Service.php @@ -28,12 +28,14 @@ class SearchApiV2Service protected function run($query) { $this->query = $query; + $q = urldecode($query->input('q')); if($query->has('resolve') && $query->resolve == true && - Helpers::validateUrl(urldecode($query->input('q'))) + ( Str::startsWith($q, 'https://') || + Str::substrCount($q, '@') == 2) ) { - return $this->resolve(); + return $this->resolveQuery(); } if($query->has('type')) { @@ -77,16 +79,6 @@ class SearchApiV2Service ]; } - protected function resolve() - { - $query = urldecode($this->query->input('q')); - if(Str::startsWith($query, '@') == true) { - return WebfingerService::lookup($this->query->input('q')); - } else if (Str::startsWith($query, 'https://') == true) { - return $this->resolveQuery(); - } - } - protected function accounts() { $user = request()->user(); @@ -163,11 +155,79 @@ class SearchApiV2Service return $this->resolveLocalProfile(); } } else { - return [ + $default = [ 'accounts' => [], 'hashtags' => [], - 'statuses' => [] + 'statuses' => [], ]; + if(!Helpers::validateUrl($query) && strpos($query, '@') == -1) { + return $default; + } + + if(Str::substrCount($query, '@') == 2) { + try { + $res = WebfingerService::lookup($query); + } catch (\Exception $e) { + return $default; + } + if($res && isset($res['id'])) { + $default['accounts'][] = $res; + return $default; + } else { + return $default; + } + } + + try { + $res = ActivityPubFetchService::get($query); + if($res) { + $json = json_decode($res, true); + + if(!$json || !isset($json['@context']) || !isset($json['type']) || !in_array($json['type'], ['Note', 'Person'])) { + return [ + 'accounts' => [], + 'hashtags' => [], + 'statuses' => [], + ]; + } + + switch($json['type']) { + case 'Note': + $obj = Helpers::statusFetch($query); + if(!$obj) { + return $default; + } + $default['statuses'][] = StatusService::get($obj['id']); + return $default; + break; + + case 'Person': + $obj = Helpers::profileFetch($query); + if(!$obj) { + return $default; + } + $default['accounts'][] = AccountService::get($obj['id']); + return $default; + break; + + default: + return [ + 'accounts' => [], + 'hashtags' => [], + 'statuses' => [], + ]; + break; + } + } + } catch (\Exception $e) { + return [ + 'accounts' => [], + 'hashtags' => [], + 'statuses' => [], + ]; + } + + return $default; } } diff --git a/public/css/spa.css b/public/css/spa.css index 5013f20b2..24143c60d 100644 Binary files a/public/css/spa.css and b/public/css/spa.css differ diff --git a/public/js/spa.js b/public/js/spa.js index 8ba87fe82..bfa1f3cba 100644 Binary files a/public/js/spa.js and b/public/js/spa.js differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index db5be1c75..941242a6f 100644 Binary files a/public/mix-manifest.json and b/public/mix-manifest.json differ