diff --git a/app/Helpers/Pagination.php b/app/Helpers/Pagination.php new file mode 100644 index 0000000..0737433 --- /dev/null +++ b/app/Helpers/Pagination.php @@ -0,0 +1,62 @@ + null, + 'prev' => null + ]; + + # Parse out the links header returned from the Mastodon API. + $links_header = Mastodon::getResponse()->getHeader('link'); + foreach (Psr7\parse_header($links_header) as $link) + { + # Find the prev and next links. + if ($link['rel'] === 'prev' || $link['rel'] === 'next') + { + $url = parse_url(trim($link[0], '<>')); + foreach (explode('&', $url['query']) as $query_param) + { + # Grab the ID query parameters from the link. + if (strpos($query_param, 'max_id=') === 0 + || strpos($query_param, 'since_id=') === 0) + { + # Construct new links with the correct offset. + $links[$link['rel']] = route($route) . '?' . $query_param; + } + } + } + } + + return $links; + } + + public static function compile_params(Request $request) + { + $params = []; + + if ($request->has('max_id') && $request->has('since_id')) + { + # This scenario makes no sense. Someone's trying to dicker with the URL. + abort(400); + } + elseif ($request->has('max_id')) + { + $params['max_id'] = $request->max_id; + } + elseif ($request->has('since_id')) + { + $params['since_id'] = $request->since_id; + } + + return $params; + } +} diff --git a/app/Http/Controllers/NotificationsController.php b/app/Http/Controllers/NotificationsController.php new file mode 100644 index 0000000..3a75443 --- /dev/null +++ b/app/Http/Controllers/NotificationsController.php @@ -0,0 +1,29 @@ +token($user->token) + ->get('/notifications', $params); + + $vars = [ + 'notifications' => $notifications, + 'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1], + 'links' => Pagination::compile_links('notifications') + ]; + + return view('notifications', $vars); + } +} diff --git a/app/Http/Controllers/TimelineController.php b/app/Http/Controllers/TimelineController.php index 20d46dd..961f10b 100644 --- a/app/Http/Controllers/TimelineController.php +++ b/app/Http/Controllers/TimelineController.php @@ -4,14 +4,14 @@ namespace App\Http\Controllers; use App\Http\Controllers\Controller; use Mastodon; -use GuzzleHttp\Psr7; use Illuminate\Http\Request; +use App\Helpers\Pagination; class TimelineController extends Controller { public function public_timeline(Request $request) { - $params = $this->compile_params($request); + $params = Pagination::compile_params($request); $params['local'] = true; $timeline = Mastodon::domain(env('MASTODON_DOMAIN')) @@ -20,7 +20,7 @@ class TimelineController extends Controller $vars = [ 'statuses' => $timeline, 'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1], - 'links' => $this->compile_links('public') + 'links' => Pagination::compile_links('public') ]; return view('public_timeline', $vars); @@ -30,7 +30,7 @@ class TimelineController extends Controller { $user = session('user'); - $params = $this->compile_params($request); + $params = Pagination::compile_params($request); $timeline = Mastodon::domain(env('MASTODON_DOMAIN')) ->token($user->token) @@ -39,7 +39,7 @@ class TimelineController extends Controller $vars = [ 'statuses' => $timeline, 'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1], - 'links' => $this->compile_links('home') + 'links' => Pagination::compile_links('home') ]; return view('home_timeline', $vars); @@ -82,56 +82,4 @@ class TimelineController extends Controller return redirect()->route('home'); } - - private function compile_links(string $route) - { - $links = [ - 'next' => null, - 'prev' => null - ]; - - # Parse out the links header returned from the Mastodon API. - $links_header = Mastodon::getResponse()->getHeader('link'); - foreach (Psr7\parse_header($links_header) as $link) - { - # Find the prev and next links. - if ($link['rel'] === 'prev' || $link['rel'] === 'next') - { - $url = parse_url(trim($link[0], '<>')); - foreach (explode('&', $url['query']) as $query_param) - { - # Grab the ID query parameters from the link. - if (strpos($query_param, 'max_id=') === 0 - || strpos($query_param, 'since_id=') === 0) - { - # Construct new links with the correct offset. - $links[$link['rel']] = route($route) . '?' . $query_param; - } - } - } - } - - return $links; - } - - private function compile_params(Request $request) - { - $params = []; - - if ($request->has('max_id') && $request->has('since_id')) - { - # This scenario makes no sense. Someone's trying to dicker with the URL. - abort(400); - } - elseif ($request->has('max_id')) - { - $params['max_id'] = $request->max_id; - } - elseif ($request->has('since_id')) - { - $params['since_id'] = $request->since_id; - } - - return $params; - } } diff --git a/public/css/styles.css b/public/css/styles.css index 4d86626..a4afede 100644 --- a/public/css/styles.css +++ b/public/css/styles.css @@ -71,7 +71,7 @@ div.actions span.reblogged a { color: green; } -time { +time, span.action-notification { font-size: smaller; margin-left: 1em; } diff --git a/resources/views/account_time_info.blade.php b/resources/views/account_time_info.blade.php new file mode 100644 index 0000000..0de9f38 --- /dev/null +++ b/resources/views/account_time_info.blade.php @@ -0,0 +1,19 @@ + + + + {{ $account['display_name'] }} + + + diff --git a/resources/views/navigation.blade.php b/resources/views/navigation.blade.php index fde3d05..6c648d8 100644 --- a/resources/views/navigation.blade.php +++ b/resources/views/navigation.blade.php @@ -2,5 +2,6 @@
diff --git a/resources/views/notification.blade.php b/resources/views/notification.blade.php new file mode 100644 index 0000000..0c1b9f2 --- /dev/null +++ b/resources/views/notification.blade.php @@ -0,0 +1,24 @@ +