From c8a667f20efa9a23d011adab2525424158c0aeb8 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jan 2022 23:15:45 -0700 Subject: [PATCH 1/3] Update SearchApiV2Service, resolve remote queries --- app/Services/SearchApiV2Service.php | 88 ++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 14 deletions(-) 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; } } From e61dc66a360e17a5344d294cd76649baf840b30f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jan 2022 23:27:13 -0700 Subject: [PATCH 2/3] Update compiled assets --- public/css/spa.css | Bin 3378 -> 3441 bytes public/js/spa.js | Bin 1718692 -> 1722106 bytes public/mix-manifest.json | Bin 1983 -> 1983 bytes 3 files changed, 0 insertions(+), 0 deletions(-) diff --git a/public/css/spa.css b/public/css/spa.css index 5013f20b2e0bad09b287546093840e5d1a2a4fbc..24143c60d8e7259cf651554c230740a414dae1a6 100644 GIT binary patch delta 69 zcmdla^-*er1TUYCUQ$V(Zb4CIZemfT-ef^uMJ*H&s7!ToeolUom2z5Inqp>dL4Hw5 IVqQrt08Kv`E&u=k delta 11 Scmew;wMlA&1n*>BUMT<@Bm)^pzW%|Kc6IJY^^IA@Y zH>%9F@ZJ%pOJ}Oht@et0db``a7+&SfJ@E1eE&-gMvMfYu%mc8g%w>fa4!YfN=#v^B zI9=v$X#BpzUZ;_q91}I{m%?H!rsQPJ_-euC2<+c02(Z#+t{5J7ao~Kqnlr#0EWcCZ z1o^y|gBypdEimpf2P#)fIFCxkJtdeQf^o%V8Eo~K^;VB%$4Gfkc1sGlh`HV}SB-qh z7Z@BpZJ|;@#Y)9S#ZIM?N|io(y4ruI+%QAGd7S-IS>YE(PqHJh;4Ev=voEuAnc_TE z4i$faE?o=L@7C^zeWzF_T)10%Y!YyX%(;hkwhR986Sk!1KCeBZcb;J%p1i^3v+T7Z z?5T_FI{nT$wy!k34f9jr!fW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^3XWwo3TI0M-r%gNsR?yfS0z&` zNQI}V6|1!b_Fpm^&MnwE+W5fQ)l4TVaTx;@?KTHI80LIX{xp7{9dx_l`4Q3p$L^yV z+FylRI5_G2VKo!NA2IwLT($~!Xg;Ca3boTF-uZ&rDfzw)o*|HNe5C|0ql z6sQQaZM3lEFPIoEETTW1B54C`dj{`4lddq(C(n^PTG*4a`aoV+kLyCpx~%#KRG5| b8!ImNvzhB2c%<3R)u|tc(+ywyiyQv|P#ltl diff --git a/public/mix-manifest.json b/public/mix-manifest.json index db5be1c7516404a238b199664ea390d3a4471422..941242a6f6d22257dd2f330eef981b5e5e781fb4 100644 GIT binary patch delta 59 zcmdnbzn_1DER%?#d6Gq%sd1u#MOtD~s*$;cp;7W?L#8Yikrb1(loS)o#N-sq#1tdb OR0C7fyVp6KPX_A43iD8O?rGZhRk)h>gL#8Yi5rb4ClhjnhBvZ>&a|=_0 Oq*O~|)6MJI1Q-G9rw{7@ From c68e18aecf1d538f4b9f7010a095dd3381edba4b Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 9 Jan 2022 23:27:57 -0700 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) 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)