|
@@ -19,9 +19,11 @@ use App\Services\StatusService;
|
|
class SearchApiV2Service
|
|
class SearchApiV2Service
|
|
{
|
|
{
|
|
private $query;
|
|
private $query;
|
|
|
|
+ static $mastodonMode = false;
|
|
|
|
|
|
- public static function query($query)
|
|
|
|
|
|
+ public static function query($query, $mastodonMode = false)
|
|
{
|
|
{
|
|
|
|
+ self::$mastodonMode = $mastodonMode;
|
|
return (new self)->run($query);
|
|
return (new self)->run($query);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -81,6 +83,7 @@ class SearchApiV2Service
|
|
|
|
|
|
protected function accounts()
|
|
protected function accounts()
|
|
{
|
|
{
|
|
|
|
+ $mastodonMode = self::$mastodonMode;
|
|
$user = request()->user();
|
|
$user = request()->user();
|
|
$limit = $this->query->input('limit') ?? 20;
|
|
$limit = $this->query->input('limit') ?? 20;
|
|
$offset = $this->query->input('offset') ?? 0;
|
|
$offset = $this->query->input('offset') ?? 0;
|
|
@@ -93,6 +96,7 @@ class SearchApiV2Service
|
|
->where('followers.profile_id', $user->profile_id);
|
|
->where('followers.profile_id', $user->profile_id);
|
|
})
|
|
})
|
|
->where('username', 'like', $query)
|
|
->where('username', 'like', $query)
|
|
|
|
+ ->orderBy('domain')
|
|
->orderByDesc('profiles.followers_count')
|
|
->orderByDesc('profiles.followers_count')
|
|
->orderByDesc('followers.created_at')
|
|
->orderByDesc('followers.created_at')
|
|
->offset($offset)
|
|
->offset($offset)
|
|
@@ -101,8 +105,10 @@ class SearchApiV2Service
|
|
->filter(function($profile) use ($banned) {
|
|
->filter(function($profile) use ($banned) {
|
|
return in_array($profile->domain, $banned) == false;
|
|
return in_array($profile->domain, $banned) == false;
|
|
})
|
|
})
|
|
- ->map(function($res) {
|
|
|
|
- return AccountService::get($res['id']);
|
|
|
|
|
|
+ ->map(function($res) use($mastodonMode) {
|
|
|
|
+ return $mastodonMode ?
|
|
|
|
+ AccountService::getMastodon($res['id']) :
|
|
|
|
+ AccountService::get($res['id']);
|
|
})
|
|
})
|
|
->filter(function($account) {
|
|
->filter(function($account) {
|
|
return $account && isset($account['id']);
|
|
return $account && isset($account['id']);
|
|
@@ -114,6 +120,7 @@ class SearchApiV2Service
|
|
|
|
|
|
protected function hashtags()
|
|
protected function hashtags()
|
|
{
|
|
{
|
|
|
|
+ $mastodonMode = self::$mastodonMode;
|
|
$limit = $this->query->input('limit') ?? 20;
|
|
$limit = $this->query->input('limit') ?? 20;
|
|
$offset = $this->query->input('offset') ?? 0;
|
|
$offset = $this->query->input('offset') ?? 0;
|
|
$query = '%' . $this->query->input('q') . '%';
|
|
$query = '%' . $this->query->input('q') . '%';
|
|
@@ -122,13 +129,18 @@ class SearchApiV2Service
|
|
->offset($offset)
|
|
->offset($offset)
|
|
->limit($limit)
|
|
->limit($limit)
|
|
->get()
|
|
->get()
|
|
- ->map(function($tag) {
|
|
|
|
- return [
|
|
|
|
|
|
+ ->map(function($tag) use($mastodonMode) {
|
|
|
|
+ $res = [
|
|
'name' => $tag->name,
|
|
'name' => $tag->name,
|
|
- 'url' => $tag->url(),
|
|
|
|
- 'count' => HashtagService::count($tag->id),
|
|
|
|
- 'history' => []
|
|
|
|
|
|
+ 'url' => $tag->url()
|
|
];
|
|
];
|
|
|
|
+
|
|
|
|
+ if(!$mastodonMode) {
|
|
|
|
+ $res['history'] = [];
|
|
|
|
+ $res['count'] = HashtagService::count($tag->id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $res;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -140,6 +152,7 @@ class SearchApiV2Service
|
|
|
|
|
|
protected function statusesById()
|
|
protected function statusesById()
|
|
{
|
|
{
|
|
|
|
+ $mastodonMode = self::$mastodonMode;
|
|
$accountId = $this->query->input('account_id');
|
|
$accountId = $this->query->input('account_id');
|
|
$limit = $this->query->input('limit', 20);
|
|
$limit = $this->query->input('limit', 20);
|
|
$query = '%' . $this->query->input('q') . '%';
|
|
$query = '%' . $this->query->input('q') . '%';
|
|
@@ -147,8 +160,10 @@ class SearchApiV2Service
|
|
->whereProfileId($accountId)
|
|
->whereProfileId($accountId)
|
|
->limit($limit)
|
|
->limit($limit)
|
|
->get()
|
|
->get()
|
|
- ->map(function($status) {
|
|
|
|
- return StatusService::get($status->id);
|
|
|
|
|
|
+ ->map(function($status) use($mastodonMode) {
|
|
|
|
+ return $mastodonMode ?
|
|
|
|
+ StatusService::getMastodon($status->id) :
|
|
|
|
+ StatusService::get($status->id);
|
|
})
|
|
})
|
|
->filter(function($status) {
|
|
->filter(function($status) {
|
|
return $status && isset($status['account']);
|
|
return $status && isset($status['account']);
|
|
@@ -158,6 +173,7 @@ class SearchApiV2Service
|
|
|
|
|
|
protected function resolveQuery()
|
|
protected function resolveQuery()
|
|
{
|
|
{
|
|
|
|
+ $mastodonMode = self::$mastodonMode;
|
|
$query = urldecode($this->query->input('q'));
|
|
$query = urldecode($this->query->input('q'));
|
|
if(Helpers::validateLocalUrl($query)) {
|
|
if(Helpers::validateLocalUrl($query)) {
|
|
if(Str::contains($query, '/p/')) {
|
|
if(Str::contains($query, '/p/')) {
|
|
@@ -177,7 +193,7 @@ class SearchApiV2Service
|
|
|
|
|
|
if(Str::substrCount($query, '@') == 2) {
|
|
if(Str::substrCount($query, '@') == 2) {
|
|
try {
|
|
try {
|
|
- $res = WebfingerService::lookup($query);
|
|
|
|
|
|
+ $res = WebfingerService::lookup($query, $mastodonMode);
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
return $default;
|
|
return $default;
|
|
}
|
|
}
|
|
@@ -209,7 +225,9 @@ class SearchApiV2Service
|
|
if(!$obj || !isset($obj['id'])) {
|
|
if(!$obj || !isset($obj['id'])) {
|
|
return $default;
|
|
return $default;
|
|
}
|
|
}
|
|
- $note = StatusService::get($obj['id']);
|
|
|
|
|
|
+ $note = $mastodonMode ?
|
|
|
|
+ StatusService::getMastodon($obj['id']) :
|
|
|
|
+ StatusService::get($obj['id']);
|
|
if(!$note) {
|
|
if(!$note) {
|
|
return $default;
|
|
return $default;
|
|
}
|
|
}
|
|
@@ -225,7 +243,9 @@ class SearchApiV2Service
|
|
if(in_array($obj['domain'], $banned)) {
|
|
if(in_array($obj['domain'], $banned)) {
|
|
return $default;
|
|
return $default;
|
|
}
|
|
}
|
|
- $default['accounts'][] = AccountService::get($obj['id']);
|
|
|
|
|
|
+ $default['accounts'][] = $mastodonMode ?
|
|
|
|
+ AccountService::getMastodon($obj['id']) :
|
|
|
|
+ AccountService::get($obj['id']);
|
|
return $default;
|
|
return $default;
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -254,10 +274,7 @@ class SearchApiV2Service
|
|
{
|
|
{
|
|
$query = urldecode($this->query->input('q'));
|
|
$query = urldecode($this->query->input('q'));
|
|
$query = last(explode('/', $query));
|
|
$query = last(explode('/', $query));
|
|
- $status = Status::whereNull('uri')
|
|
|
|
- ->whereScope('public')
|
|
|
|
- ->find($query);
|
|
|
|
-
|
|
|
|
|
|
+ $status = StatusService::getMastodon($query);
|
|
if(!$status) {
|
|
if(!$status) {
|
|
return [
|
|
return [
|
|
'accounts' => [],
|
|
'accounts' => [],
|
|
@@ -266,14 +283,13 @@ class SearchApiV2Service
|
|
];
|
|
];
|
|
}
|
|
}
|
|
|
|
|
|
- $fractal = new Fractal\Manager();
|
|
|
|
- $fractal->setSerializer(new ArraySerializer());
|
|
|
|
- $resource = new Fractal\Resource\Item($status, new StatusTransformer());
|
|
|
|
- return [
|
|
|
|
|
|
+ $res = [
|
|
'accounts' => [],
|
|
'accounts' => [],
|
|
'hashtags' => [],
|
|
'hashtags' => [],
|
|
- 'statuses' => $fractal->createData($resource)->toArray()
|
|
|
|
|
|
+ 'statuses' => [$status]
|
|
];
|
|
];
|
|
|
|
+
|
|
|
|
+ return $res;
|
|
}
|
|
}
|
|
|
|
|
|
protected function resolveLocalProfile()
|
|
protected function resolveLocalProfile()
|