mirror of https://git.stjo.hn/planiverse
Tidy up some of the status routing
Status routes were a bit of a mess and involved redirects, which is only going to slow things down. I've amalgamated them into one route and used query parameters to determine any actions being performed.
This commit is contained in:
parent
d8f88af21b
commit
eb513faf9b
|
@ -9,19 +9,31 @@ use Illuminate\Http\Request;
|
|||
|
||||
class StatusController extends Controller
|
||||
{
|
||||
public function show_status(string $status_id)
|
||||
public function show_status(Request $request, string $status_id)
|
||||
{
|
||||
if (session()->has('return_status'))
|
||||
// The user has a session and may be here to favourite/unfavourite
|
||||
// a status.
|
||||
if (session()->has('user'))
|
||||
{
|
||||
// This route can be called as a redirect after favouriting, etc.,
|
||||
// in which case the status returned by the API will have been stored
|
||||
// in the user's session.
|
||||
$status = session('return_status');
|
||||
session()->forget('return_status');
|
||||
$user = session('user');
|
||||
if ($request->action === 'favourite')
|
||||
{
|
||||
$status = Mastodon::domain(env('MASTODON_DOMAIN'))
|
||||
->token($user->token)
|
||||
->post('/statuses/' . $status_id . '/favourite');
|
||||
}
|
||||
elseif ($request->action === 'unfavourite')
|
||||
{
|
||||
$status = Mastodon::domain(env('MASTODON_DOMAIN'))
|
||||
->token($user->token)
|
||||
->post('/statuses/' . $status_id . '/unfavourite');
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
// If the status hasn't been returned from performing an action on it,
|
||||
// we need to query for it.
|
||||
if (!isset($session))
|
||||
{
|
||||
// If the status isn't in the session, we need to query for it.
|
||||
$status = Mastodon::domain(env('MASTODON_DOMAIN'))
|
||||
->get('/statuses/' . $status_id);
|
||||
}
|
||||
|
@ -34,30 +46,4 @@ class StatusController extends Controller
|
|||
|
||||
return view('show_status', $vars);
|
||||
}
|
||||
|
||||
public function favourite_status(string $status_id)
|
||||
{
|
||||
$user = session('user');
|
||||
|
||||
$status = Mastodon::domain(env('MASTODON_DOMAIN'))
|
||||
->token($user->token)
|
||||
->post('/statuses/' . $status_id . '/favourite');
|
||||
|
||||
session(['return_status' => $status]);
|
||||
|
||||
return redirect()->route('status', ['status_id' => $status_id]);
|
||||
}
|
||||
|
||||
public function unfavourite_status(string $status_id)
|
||||
{
|
||||
$user = session('user');
|
||||
|
||||
$status = Mastodon::domain(env('MASTODON_DOMAIN'))
|
||||
->token($user->token)
|
||||
->post('/statuses/' . $status_id . '/unfavourite');
|
||||
|
||||
session(['return_status' => $status]);
|
||||
|
||||
return redirect()->route('status', ['status_id' => $status_id]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ div.status img.avatar {
|
|||
color: goldenrod;
|
||||
}
|
||||
|
||||
div.actions span {
|
||||
div.actions > span {
|
||||
margin-right: 1em;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,9 +54,9 @@
|
|||
<!-- Favourite -->
|
||||
<span>
|
||||
@if ($status['favourited'])
|
||||
<span class="favourited"><a href="/status/{{ $status['id'] }}/unfavourite">★</a></span>
|
||||
<span class="favourited"><a href="/status/{{ $status['id'] }}?action=unfavourite">★</a></span>
|
||||
@else
|
||||
<a href="/status/{{ $status['id'] }}/favourite">☆</a>
|
||||
<a href="/status/{{ $status['id'] }}?action=favourite">☆</a>
|
||||
@endif
|
||||
{{ $status['favourites_count'] }}
|
||||
</span>
|
||||
|
|
|
@ -35,12 +35,6 @@ Route::post('/timeline/home', 'TimelineController@post_status')
|
|||
Route::get('/status/{status_id}', 'StatusController@show_status')
|
||||
->name('status');
|
||||
|
||||
Route::get('/status/{status_id}/favourite', 'StatusController@favourite_status')
|
||||
->middleware('authorize');
|
||||
|
||||
Route::get('/status/{status_id}/unfavourite', 'StatusController@unfavourite_status')
|
||||
->middleware('authorize');
|
||||
|
||||
Route::get('/login', 'LoginController@login')
|
||||
->name('login');
|
||||
|
||||
|
|
Loading…
Reference in New Issue