planiverse

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

commit 7fc59f1c58fa4a88273995970478833160670b50
parent 9a0fb86099e700629415fc8bdce2d9e098ea3e1e
Author: St John Karp <stjohn@fuzzjunket.com>
Date:   Sun, 24 Mar 2019 19:45:36 +0000

Fix #5 - Implement deleting statuses

Added a link (and a confirmation page) that allows a user to delete
their own Statuses.

Diffstat:
MREADME.md | 6+++---
Mapp/Http/Controllers/StatusController.php | 41+++++++++++++++++++++++++++++++++++++++++
Mpublic/css/styles.css | 8++++++++
Aresources/views/delete_status.blade.php | 25+++++++++++++++++++++++++
Mresources/views/status.blade.php | 9++++++++-
Mroutes/web.php | 4++++
6 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md @@ -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 diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php @@ -204,6 +204,47 @@ class StatusController extends Controller } /** + * + * 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. * * Show a Status in its thread of ancestors and descendants. diff --git a/public/css/styles.css b/public/css/styles.css @@ -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; +} diff --git a/resources/views/delete_status.blade.php b/resources/views/delete_status.blade.php @@ -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> diff --git a/resources/views/status.blade.php b/resources/views/status.blade.php @@ -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> diff --git a/routes/web.php b/routes/web.php @@ -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');