/**
  * Return paginated status updates by user
  *
  * @param User $user
  * @param integer $page
  * @param integer $per_page
  * @return array
  */
 function paginateByUser($user, $page = 1, $per_page = 30)
 {
     return StatusUpdates::paginateByUserIds(array($user->getId()), $page, $per_page);
 }
 /**
  * Index page action
  * 
  * @param void
  * @return void
  */
 function index()
 {
     UserConfigOptions::setValue('status_update_last_visited', new DateTimeValue(), $this->logged_user);
     // Popup
     if ($this->request->isAsyncCall()) {
         $this->skip_layout = true;
         $this->setTemplate(array('template' => 'popup', 'controller' => 'status', 'module' => STATUS_MODULE));
         $last_visit = UserConfigOptions::getValue('status_update_last_visited', $this->logged_user);
         $new_messages_count = StatusUpdates::countNewMessagesForUser($this->logged_user, $last_visit);
         $limit = $new_messages_count > 10 ? $new_messages_count : 10;
         $latest_status_updates = StatusUpdates::findVisibleForUser($this->logged_user, $limit);
         $this->smarty->assign(array('status_updates' => $latest_status_updates, "rss_url" => assemble_url('status_updates_rss', array('token' => $this->logged_user->getToken(true)))));
         // Archive
     } else {
         $this->setTemplate(array('template' => 'messages', 'controller' => 'status', 'module' => STATUS_MODULE));
         $visible_users = $this->logged_user->visibleUserIds();
         // We'll need them in several places
         $selected_user_id = $this->request->getId('user_id');
         if ($selected_user_id) {
             if (!in_array($selected_user_id, $visible_users)) {
                 $this->httpError(HTTP_ERR_FORBIDDEN);
             }
             // if
             $selected_user = Users::findById($selected_user_id);
             if (!instance_of($selected_user, 'User')) {
                 $this->httpError(HTTP_ERR_NOT_FOUND);
             }
             // if
         } else {
             $selected_user = null;
         }
         // if
         if ($this->request->isApiCall()) {
             if ($selected_user) {
                 $this->serveData(StatusUpdates::findByUser($selected_user), 'messages');
             } else {
                 $this->serveData(StatusUpdates::findVisibleForUser($this->logged_user, 50), 'messages');
             }
             // if
         } else {
             $per_page = 15;
             // Messages per page
             $page = $this->request->getPage();
             if ($selected_user) {
                 $rss_url = assemble_url('status_updates_rss', array('user_id' => $selected_user_id, 'token' => $this->logged_user->getToken(true)));
                 $rss_title = clean($selected_user->getDisplayName()) . ': ' . lang('Status Updates');
                 list($status_updates, $pagination) = StatusUpdates::paginateByUser($selected_user, $page, $per_page);
                 $this->smarty->assign(array('selected_user' => $selected_user, 'rss_url' => $rss_url));
             } else {
                 $rss_url = assemble_url('status_updates_rss', array('token' => $this->logged_user->getToken(true)));
                 $rss_title = lang('Status Updates');
                 list($status_updates, $pagination) = StatusUpdates::paginateByUserIds($visible_users, $page, $per_page);
                 $this->smarty->assign(array('rss_url' => $rss_url));
             }
             // if
             $this->wireframe->addRssFeed($rss_title, $rss_url, FEED_RSS);
             $this->smarty->assign(array('visible_users' => Users::findUsersDetails($visible_users), 'status_updates' => $status_updates, 'pagination' => $pagination));
         }
         // if
     }
     // if
 }