public function getActivity(Request $request)
 {
     $me = GitHub::me()->show();
     $lastEventId = $request->session()->get('last_notification_id', false);
     $activity = [];
     $interval = 60;
     if ($lastEventId) {
         list($interval, $activity) = $this->findNewActivity($me['login'], $lastEventId);
         if ($activity) {
             $request->session()->set('last_notification_id', $activity[0]['id']);
             // Mark as read
             try {
                 GitHub::notification()->markRead();
             } catch (\Exception $e) {
                 // Github returns empty string for this endpoint but the API library tries to parse it as json
             }
             foreach ($activity as &$notice) {
                 $notice['html_url'] = $this->getRelatedHtmlUrl($notice['subject']);
             }
         }
     }
     $html = view('notifications.live', ['me' => $me, 'activity' => $activity]);
     $data = ['activity' => $html->render(), 'interval' => (int) $interval * 1000, 'count' => count($activity)];
     $response = \Illuminate\Support\Facades\Response::make(json_encode($data), 200);
     $response->header('Content-Type', 'application/json');
     return $response;
 }
 public function showIndex(Request $request, $page = 1)
 {
     $me = GitHub::me()->show();
     /** @var Response $response */
     $activity = GitHub::notification()->all();
     // Save the latest activity ID for live fetching
     if (count($activity)) {
         $request->session()->put('last_notification_id', $activity[0]['id']);
         // Mark as read
         try {
             GitHub::notification()->markRead();
         } catch (\Exception $e) {
             // Github returns empty string for this endpoint but the API library tries to parse it as json
         }
         foreach ($activity as &$notice) {
             $notice['html_url'] = $this->getRelatedHtmlUrl($notice['subject']);
         }
     }
     // Get the interval Github allows for polling
     $response = GitHub::connection()->getHttpClient()->getLastResponse();
     $interval = $response->hasHeader('X-Poll-Interval') ? (string) $response->getHeader('X-Poll-Interval') : 60;
     return view('notifications.index', ['me' => $me, 'activity' => $activity, 'page' => $page, 'interval' => (int) $interval * 1000]);
 }