Fix #5 - Implement deleting statuses

Added a link (and a confirmation page) that allows a user to delete
their own Statuses.
This commit is contained in:
St John Karp 2019-03-24 19:45:36 +00:00
parent 9a0fb86099
commit 7fc59f1c58
6 changed files with 89 additions and 4 deletions

View File

@ -20,7 +20,9 @@ Currently implemented features are:
* pagination
* posting, favouriting, reblogging, and replying to statuses
* posting and deleting statuses
* favouriting, reblogging, and replying to statuses
* spoiler/content warnings
@ -40,8 +42,6 @@ Currently implemented features are:
Features still to be implemented include:
* deleting statuses
* muting/blocking accounts
* uploading attachments

View File

@ -203,6 +203,47 @@ class StatusController extends Controller
return redirect()->route('home');
}
/**
*
* Delete a Status.
*
* @param string $status_id The ID of the Status to be deleted.
*
* @return Illuminate\Routing\Redirector Redirect to the home timeline page.
*/
public function delete_status(string $status_id)
{
$user = session('user');
if (session()->has('delete_status') && session('delete_status') === $status_id)
{
# The user has confirmed the deletion, so go ahead and delete the Status.
Mastodon::domain(env('MASTODON_DOMAIN'))
->token($user->token)
->call('DELETE', '/statuses/' . $status_id);
return redirect()->route('home');
}
else
{
# Render the confirmation page.
session()->flash('delete_status', $status_id);
$status = Mastodon::domain(env('MASTODON_DOMAIN'))
->token(session('user')->token)
->get('/statuses/' . $status_id);
$vars = [
'status' => $status,
'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1]
];
}
return view('delete_status', $vars);
}
/**
* Show the context of a Status.
*

View File

@ -71,6 +71,10 @@ div.actions span.reblogged a {
color: green;
}
span#delete {
font-size: smaller;
}
time, span.event-indicators {
font-size: smaller;
margin-left: 1em;
@ -96,3 +100,7 @@ nav ul li {
display: inline;
margin-top: 0;
}
p.warning {
color: red;
}

View File

@ -0,0 +1,25 @@
<!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 }} | Delete Status</title>
<link rel="stylesheet" href="{{ url('css/styles.css') }}" />
</head>
<body>
<h1>{{ $mastodon_domain }} | Delete Status</h1>
@component('navigation')
@endcomponent
<p class="warning">Are you sure you want to delete this status? Click the delete link again to confirm.</p>
<ul>
@component('status', ['status' => $status])
@endcomponent
</ul>
</body>
</html>

View File

@ -54,6 +54,13 @@
<a href="{{ route('favourite', ['status_id' => $status['id']]) }}">&#9734;</a>
@endif
{{ $status['favourites_count'] }}
</span>
</span>
<!-- Delete -->
@if (Session::has('user') && Session::get('user')->id === $status['account']['id'])
<span title="Delete" id="delete">
<a href="{{ route('delete', ['status_id' => $status['id']]) }}">&#128473;</a>
</span>
@endif
</div>
</article></li>

View File

@ -48,6 +48,10 @@ Route::get('/status/{status_id}/unfavourite', 'StatusController@unfavourite_stat
->name('unfavourite')
->middleware('authorize');
Route::get('/status/{status_id}/delete', 'StatusController@delete_status')
->name('delete')
->middleware('authorize');
Route::get('/status/{status_id}/thread', 'StatusController@context')
->name('thread');