mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Update ComposeController, add autocomplete apis for hashtags and mentions
This commit is contained in:
parent
001d410579
commit
f0e48a09a3
2 changed files with 69 additions and 0 deletions
|
@ -7,6 +7,7 @@ use Auth, Cache, Storage, URL;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use App\{
|
use App\{
|
||||||
Avatar,
|
Avatar,
|
||||||
|
Hashtag,
|
||||||
Like,
|
Like,
|
||||||
Media,
|
Media,
|
||||||
MediaTag,
|
MediaTag,
|
||||||
|
@ -304,6 +305,72 @@ class ComposeController extends Controller
|
||||||
return $places;
|
return $places;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function searchMentionAutocomplete(Request $request)
|
||||||
|
{
|
||||||
|
abort_if(!$request->user(), 403);
|
||||||
|
|
||||||
|
$this->validate($request, [
|
||||||
|
'q' => 'required|string|min:2|max:50'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$q = $request->input('q');
|
||||||
|
|
||||||
|
if(Str::of($q)->startsWith('@')) {
|
||||||
|
if(strlen($q) < 3) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$blocked = UserFilter::whereFilterableType('App\Profile')
|
||||||
|
->whereFilterType('block')
|
||||||
|
->whereFilterableId($request->user()->profile_id)
|
||||||
|
->pluck('user_id');
|
||||||
|
|
||||||
|
$blocked->push($request->user()->profile_id);
|
||||||
|
|
||||||
|
$results = Profile::select('id','domain','username')
|
||||||
|
->whereNotIn('id', $blocked)
|
||||||
|
->where('username','like','%'.$q.'%')
|
||||||
|
->groupBy('domain')
|
||||||
|
->limit(15)
|
||||||
|
->get()
|
||||||
|
->map(function($profile) {
|
||||||
|
$username = $profile->domain ? substr($profile->username, 1) : $profile->username;
|
||||||
|
return [
|
||||||
|
'key' => '@' . str_limit($username, 30),
|
||||||
|
'value' => $username,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchHashtagAutocomplete(Request $request)
|
||||||
|
{
|
||||||
|
abort_if(!$request->user(), 403);
|
||||||
|
|
||||||
|
$this->validate($request, [
|
||||||
|
'q' => 'required|string|min:2|max:50'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$q = $request->input('q');
|
||||||
|
|
||||||
|
$results = Hashtag::select('slug')
|
||||||
|
->where('slug', 'like', '%'.$q.'%')
|
||||||
|
->whereIsNsfw(false)
|
||||||
|
->whereIsBanned(false)
|
||||||
|
->limit(5)
|
||||||
|
->get()
|
||||||
|
->map(function($tag) {
|
||||||
|
return [
|
||||||
|
'key' => '#' . $tag->slug,
|
||||||
|
'value' => $tag->slug
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
|
|
|
@ -113,6 +113,8 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
|
||||||
Route::delete('/media/delete', 'ComposeController@mediaDelete');
|
Route::delete('/media/delete', 'ComposeController@mediaDelete');
|
||||||
Route::get('/search/tag', 'ComposeController@searchTag');
|
Route::get('/search/tag', 'ComposeController@searchTag');
|
||||||
Route::get('/search/location', 'ComposeController@searchLocation');
|
Route::get('/search/location', 'ComposeController@searchLocation');
|
||||||
|
Route::get('/search/mention', 'ComposeController@searchMentionAutocomplete');
|
||||||
|
Route::get('/search/hashtag', 'ComposeController@searchHashtagAutocomplete');
|
||||||
|
|
||||||
Route::post('/publish', 'ComposeController@store')
|
Route::post('/publish', 'ComposeController@store')
|
||||||
->middleware('throttle:maxPostsPerHour,60')
|
->middleware('throttle:maxPostsPerHour,60')
|
||||||
|
|
Loading…
Reference in a new issue