planiverse

A minimalist, no-JS front-end for Mastodon.
git clone https://git.stjo.hn/planiverse
Log | Files | Refs | README | LICENSE

commit be9e3c3603d1958529c4261e359bce999aeec05b
parent 50bf84c4e46fade3d8c9b7fd2af7e06272609633
Author: St John Karp <stjohn@fuzzjunket.com>
Date:   Mon, 13 Aug 2018 21:31:20 -0700

Implement posting a status

Split the timeline views into home and public, and added a form
at the top of the home timeline for posting a new status.

Diffstat:
Mapp/Http/Controllers/TimelineController.php | 52+++++++++++++++++++++++++++++++++++++++++++++++-----
Mpublic/css/styles.css | 6++++++
Aresources/views/home_timeline.blade.php | 35+++++++++++++++++++++++++++++++++++
Aresources/views/public_timeline.blade.php | 28++++++++++++++++++++++++++++
Dresources/views/timeline.blade.php | 28----------------------------
Mroutes/web.php | 2++
6 files changed, 118 insertions(+), 33 deletions(-)

diff --git a/app/Http/Controllers/TimelineController.php b/app/Http/Controllers/TimelineController.php @@ -20,23 +20,23 @@ class TimelineController extends Controller $vars = [ 'statuses' => $timeline, 'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1], - 'timeline' => 'Public Timeline', 'links' => $this->compile_links('public') ]; - return view('timeline', $vars); + return view('public_timeline', $vars); } public function home_timeline(Request $request) { + # Check the user is logged in. if (!session()->has('user')) { return redirect()->route('login'); } + $user = session('user'); $params = $this->compile_params($request); - $user = session('user'); $timeline = Mastodon::domain(env('MASTODON_DOMAIN')) ->token($user->token) ->get('/timelines/home', $params); @@ -44,11 +44,53 @@ class TimelineController extends Controller $vars = [ 'statuses' => $timeline, 'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1], - 'timeline' => 'Timeline', 'links' => $this->compile_links('home') ]; - return view('timeline', $vars); + return view('home_timeline', $vars); + } + + public function post_status(Request $request) + { + # Check the user is logged in. + if (!session()->has('user')) + { + return redirect()->route('login'); + } + $user = session('user'); + + # Verify we have an actual status to post. + if (!$request->has('status')) + { + abort(400); + } + + $params = [ + 'status' => $request->status + ]; + + $inputs = [ + 'in_reply_to_id', + 'media_ids', + 'sensitive', + 'spoiler_text', + 'visibility', + 'language' + ]; + + foreach ($inputs as $input) + { + if ($request->has($input)) + { + $params[$input] = $request->input($input); + } + } + + $new_status = Mastodon::domain(env('MASTODON_DOMAIN')) + ->token($user->token) + ->post('/statuses', $params); + + return redirect()->route('home'); } private function compile_links(string $route) diff --git a/public/css/styles.css b/public/css/styles.css @@ -59,6 +59,12 @@ time { margin-left: 1em; } +input, textarea { + box-sizing: border-box; + padding: 0.5em; + width: 100%; +} + /* Tooltip container */ .tooltip { position: relative; diff --git a/resources/views/home_timeline.blade.php b/resources/views/home_timeline.blade.php @@ -0,0 +1,35 @@ +<!doctype html> +<html lang="{{ app()->getLocale() }}"> + <head> + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + + <title>{{ $mastodon_domain }} | Timeline</title> + + <link rel="stylesheet" href="/css/styles.css" /> + </head> + <body> + <h1>{{ $mastodon_domain }} | Timeline</h1> + + <form method="post" action="/timeline/home"> + <input type="text" name="spoiler_text" placeholder="Spoiler/Warning" /> + <textarea rows="4" name="status" placeholder="Status" required autofocus></textarea> + <input type="submit" value="Post" /> + {{ csrf_field() }} + </form> + + @foreach ($statuses as $status) + @component('status', ['status' => $status]) + @endcomponent + @endforeach + + @if ($links['prev'] !== null) + <span><a href="{{ $links['prev'] }}">Previous</a></span> + @endif + + @if ($links['next'] !== null) + <span><a href="{{ $links['next'] }}">Next</a></span> + @endif + </body> +</html> diff --git a/resources/views/public_timeline.blade.php b/resources/views/public_timeline.blade.php @@ -0,0 +1,28 @@ +<!doctype html> +<html lang="{{ app()->getLocale() }}"> + <head> + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + + <title>{{ $mastodon_domain }} | Public Timeline</title> + + <link rel="stylesheet" href="/css/styles.css" /> + </head> + <body> + <h1>{{ $mastodon_domain }} | Public Timeline</h1> + + @foreach ($statuses as $status) + @component('status', ['status' => $status]) + @endcomponent + @endforeach + + @if ($links['prev'] !== null) + <span><a href="{{ $links['prev'] }}">Previous</a></span> + @endif + + @if ($links['next'] !== null) + <span><a href="{{ $links['next'] }}">Next</a></span> + @endif + </body> +</html> diff --git a/resources/views/timeline.blade.php b/resources/views/timeline.blade.php @@ -1,28 +0,0 @@ -<!doctype html> -<html lang="{{ app()->getLocale() }}"> - <head> - <meta charset="utf-8"> - <meta http-equiv="X-UA-Compatible" content="IE=edge"> - <meta name="viewport" content="width=device-width, initial-scale=1"> - - <title>{{ $mastodon_domain }} | {{ $timeline }}</title> - - <link rel="stylesheet" href="/css/styles.css" /> - </head> - <body> - <h1>{{ $mastodon_domain }} | {{ $timeline }}</h1> - - @foreach ($statuses as $status) - @component('status', ['status' => $status]) - @endcomponent - @endforeach - - @if ($links['prev'] !== null) - <span><a href="{{ $links['prev'] }}">Previous</a></span> - @endif - - @if ($links['next'] !== null) - <span><a href="{{ $links['next'] }}">Next</a></span> - @endif - </body> -</html> diff --git a/routes/web.php b/routes/web.php @@ -28,6 +28,8 @@ Route::get('/timeline/public', 'TimelineController@public_timeline') Route::get('/timeline/home', 'TimelineController@home_timeline') ->name('home'); +Route::post('/timeline/home', 'TimelineController@post_status'); + Route::get('/login', 'LoginController@login') ->name('login');