diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index be506ea4e..332b679fb 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -61,6 +61,10 @@ class SearchController extends Controller $this->webfingerSearch(); break; + case 'remote': + $this->remoteLookupSearch(); + break; + default: break; } @@ -179,24 +183,15 @@ class SearchController extends Controller 'following' => $item->followedBy(Auth::user()->profile), 'follow_request' => $item->hasFollowRequestById(Auth::user()->profile_id), 'thumb' => $item->avatarUrl(), - 'local' => (bool) !$item->domain + 'local' => (bool) !$item->domain, + 'post_count' => $item->statuses()->count() ] ]]; return $tokens; }); } } - // elseif( Str::containsAll($tag, ['@', '.']) - // config('federation.activitypub.enabled') == true && - // config('federation.activitypub.remoteFollow') == true - // ) { - // if(substr_count($tag, '@') == 2) { - // $domain = last(explode('@', sub_str($u, 1))); - // } else { - // $domain = last(explode('@', $u)); - // } - // } else { $this->tokens['profiles'] = Cache::remember($key, $ttl, function() use($tag) { $users = Profile::select('domain', 'username', 'name', 'id') @@ -268,4 +263,53 @@ class SearchController extends Controller ]; return; } + + protected function remotePostLookup() + { + $tag = $this->term; + $hash = hash('sha256', $tag); + $local = Helpers::validateLocalUrl($tag); + $valid = Helpers::validateUrl($tag); + + if($valid == false || $local == true) { + return; + } + + if(Status::whereUri($tag)->whereLocal(false)->exists()) { + $item = Status::whereUri($tag)->first(); + $this->tokens['posts'] = [[ + 'count' => 0, + 'url' => "/i/web/post/_/$item->profile_id/$item->id", + 'type' => 'status', + 'username' => $item->profile->username, + 'caption' => $item->rendered ?? $item->caption, + 'thumb' => $item->firstMedia()->remote_url, + 'timestamp' => $item->created_at->diffForHumans() + ]]; + } + + $remote = Helpers::fetchFromUrl($tag); + + if(isset($remote['type']) && $remote['type'] == 'Note') { + $item = Helpers::statusFetch($tag); + $this->tokens['posts'] = [[ + 'count' => 0, + 'url' => "/i/web/post/_/$item->profile_id/$item->id", + 'type' => 'status', + 'username' => $item->profile->username, + 'caption' => $item->rendered ?? $item->caption, + 'thumb' => $item->firstMedia()->remote_url, + 'timestamp' => $item->created_at->diffForHumans() + ]]; + } + } + + protected function remoteLookupSearch() + { + if(!Helpers::validateUrl($this->term)) { + return; + } + $this->getProfiles(); + $this->remotePostLookup(); + } } \ No newline at end of file diff --git a/resources/assets/js/components/SearchResults.vue b/resources/assets/js/components/SearchResults.vue index 9922ef131..347e324b9 100644 --- a/resources/assets/js/components/SearchResults.vue +++ b/resources/assets/js/components/SearchResults.vue @@ -175,6 +175,82 @@ +
+
+

Showing results for {{query}}

+
+
+
+ + + +
+
+ + + +
+
+
+
+

Showing results for {{query}}

+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ + +
+

{{status.username}}

+
+
+

{{status.timestamp}}

+
+
+
+

+ + +
+ +
+
+
+
No results found
+
+
+

No results found

@@ -232,6 +308,14 @@ export default { }, fetchSearchResults() { + if(this.analysis == 'remote') { + let term = this.query; + let parsed = new URL(term); + if(parsed.host === window.location.host) { + window.location.href = term; + return; + } + } this.searchContext(this.analysis); }, @@ -320,6 +404,34 @@ export default { }); break; + case 'remote': + axios.get('/api/search', { + params: { + 'q': this.query, + 'src': 'metro', + 'v': 1, + 'scope': 'remote' + } + }).then(res => { + let results = res.data; + this.results.hashtags = results.hashtags ? results.hashtags : []; + this.results.profiles = results.profiles ? results.profiles : []; + this.results.statuses = results.posts ? results.posts : []; + + if(this.results.profiles.length) { + this.analysis = 'profile'; + } + if(this.results.statuses.length) { + this.analysis = 'remotePost'; + } + this.loading = false; + }).catch(err => { + this.loading = false; + console.log(err); + this.networkError = true; + }); + break; + case 'hashtag': axios.get('/api/search', { params: {