planiverse

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

TimelineController.php (2090B)


      1 <?php
      2 
      3 namespace App\Http\Controllers;
      4 
      5 use App\Http\Controllers\Controller;
      6 use Mastodon;
      7 use Illuminate\Http\Request;
      8 
      9 use App\Helpers\Links;
     10 use App\Helpers\PaginationParameters;
     11 
     12 /**
     13  * Controller for the public and user timelines.
     14  */
     15 class TimelineController extends Controller
     16 {
     17 
     18     /**
     19      * Show the public timeline.
     20      *
     21      * The user does not have to be logged in to see this.
     22      *
     23      * @param Request $request The request containing pagination parameters.
     24      *
     25      * @return Illuminate\View\View The public timeline.
     26      */
     27     public function public_timeline(Request $request)
     28     {
     29         $params = (new PaginationParameters($request))
     30             ->to_array();
     31         $params['local'] = true;
     32 
     33         # Query for the public timeline.
     34         $timeline = Mastodon::domain(env('MASTODON_DOMAIN'))
     35             ->get('/timelines/public', $params);
     36 
     37         $vars = [
     38             'statuses' => $timeline,
     39             'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1],
     40             'links' => new Links(
     41                 Mastodon::getResponse()->getHeader('link'),
     42                 'public'
     43            	)
     44         ];
     45 
     46         return view('public_timeline', $vars);
     47     }
     48 
     49     /**
     50      * Show the home timeline.
     51      *
     52      * @param Request $request The request containing pagination parameters.
     53      *
     54      * @return Illuminate\View\View The user's home timeline.
     55      */
     56     public function home_timeline(Request $request)
     57     {
     58         $user = session('user');
     59 
     60         $params = (new PaginationParameters($request))
     61             ->to_array();
     62 
     63         # Query for the user's timeline.
     64         $timeline = Mastodon::domain(env('MASTODON_DOMAIN'))
     65             ->token($user->token)
     66             ->get('/timelines/home', $params);
     67 
     68         $vars = [
     69             'statuses' => $timeline,
     70             'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1],
     71             'links' => new Links(
     72                 Mastodon::getResponse()->getHeader('link'),
     73                 'home'
     74            	)
     75         ];
     76 
     77         return view('home_timeline', $vars);
     78     }
     79 }