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.
This commit is contained in:
St John Karp 2018-08-13 21:31:20 -07:00
parent 50bf84c4e4
commit be9e3c3603
5 changed files with 92 additions and 7 deletions

View File

@ -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)

View File

@ -59,6 +59,12 @@ time {
margin-left: 1em;
}
input, textarea {
box-sizing: border-box;
padding: 0.5em;
width: 100%;
}
/* Tooltip container */
.tooltip {
position: relative;

View File

@ -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>

View File

@ -5,12 +5,12 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ $mastodon_domain }} | {{ $timeline }}</title>
<title>{{ $mastodon_domain }} | Public Timeline</title>
<link rel="stylesheet" href="/css/styles.css" />
</head>
<body>
<h1>{{ $mastodon_domain }} | {{ $timeline }}</h1>
<h1>{{ $mastodon_domain }} | Public Timeline</h1>
@foreach ($statuses as $status)
@component('status', ['status' => $status])

View File

@ -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');