コード例 #1
0
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $query = id(new PhabricatorNotificationQuery())->setViewer($user)->withUserPHIDs(array($user->getPHID()))->setLimit(15);
     $stories = $query->execute();
     $clear_ui_class = 'phabricator-notification-clear-all';
     $clear_uri = id(new PhutilURI('/notification/clear/'));
     if ($stories) {
         $builder = new PhabricatorNotificationBuilder($stories);
         $notifications_view = $builder->buildView();
         $content = $notifications_view->render();
         $clear_uri->setQueryParam('chronoKey', head($stories)->getChronologicalKey());
     } else {
         $content = phutil_tag_div('phabricator-notification no-notifications', pht('You have no notifications.'));
         $clear_ui_class .= ' disabled';
     }
     $clear_ui = javelin_tag('a', array('sigil' => 'workflow', 'href' => (string) $clear_uri, 'class' => $clear_ui_class), pht('Mark All Read'));
     $notifications_link = phutil_tag('a', array('href' => '/notification/'), pht('Notifications'));
     if (PhabricatorEnv::getEnvConfig('notification.enabled')) {
         $connection_status = new PhabricatorNotificationStatusView();
     } else {
         $connection_status = phutil_tag('a', array('href' => PhabricatorEnv::getDoclink('Notifications User Guide: Setup and Configuration')), pht('Notification Server not enabled.'));
     }
     $connection_ui = phutil_tag('div', array('class' => 'phabricator-notification-footer'), $connection_status);
     $header = phutil_tag('div', array('class' => 'phabricator-notification-header'), array($notifications_link, $clear_ui));
     $content = hsprintf('%s%s%s', $header, $content, $connection_ui);
     $unread_count = id(new PhabricatorFeedStoryNotification())->countUnread($user);
     $json = array('content' => $content, 'number' => (int) $unread_count);
     return id(new AphrontAjaxResponse())->setContent($json);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $stories = id(new PhabricatorNotificationQuery())->setViewer($viewer)->withUserPHIDs(array($viewer->getPHID()))->withKeys(array($request->getStr('key')))->execute();
     if (!$stories) {
         return $this->buildEmptyResponse();
     }
     $story = head($stories);
     if ($story->getAuthorPHID() === $viewer->getPHID()) {
         // Don't show the user individual notifications about their own
         // actions. Primarily, this stops pages from showing notifications
         // immediately after you click "Submit" on a comment form if the
         // notification server returns faster than the web server.
         // TODO: It would be nice to retain the "page updated" bubble on copies
         // of the page that are open in other tabs, but there isn't an obvious
         // way to do this easily.
         return $this->buildEmptyResponse();
     }
     $builder = new PhabricatorNotificationBuilder(array($story));
     $content = $builder->buildView()->render();
     $dict = $builder->buildDict();
     $data = $dict[0];
     $response = array('pertinent' => true, 'primaryObjectPHID' => $story->getPrimaryObjectPHID(), 'desktopReady' => $data['desktopReady'], 'href' => $data['href'], 'icon' => $data['icon'], 'title' => $data['title'], 'body' => $data['body'], 'content' => hsprintf('%s', $content));
     return id(new AphrontAjaxResponse())->setContent($response);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $stories = id(new PhabricatorNotificationQuery())->setUserPHID($user->getPHID())->withKeys(array($request->getStr('key')))->execute();
     if (!$stories) {
         return id(new AphrontAjaxResponse())->setContent(array('pertinent' => false));
     }
     $builder = new PhabricatorNotificationBuilder($stories);
     $content = $builder->buildView()->render();
     $response = array('pertinent' => true, 'primaryObjectPHID' => head($stories)->getPrimaryObjectPHID(), 'content' => $content);
     return id(new AphrontAjaxResponse())->setContent($response);
 }
コード例 #4
0
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $nav = new AphrontSideNavFilterView();
     $nav->setBaseURI(new PhutilURI('/notification/'));
     $nav->addFilter('all', 'All Notifications');
     $nav->addFilter('unread', 'Unread Notifications');
     $filter = $nav->selectFilter($this->filter, 'all');
     $pager = new AphrontPagerView();
     $pager->setURI($request->getRequestURI(), 'offset');
     $pager->setOffset($request->getInt('offset'));
     $query = new PhabricatorNotificationQuery();
     $query->setUserPHID($user->getPHID());
     switch ($filter) {
         case 'unread':
             $query->withUnread(true);
             $header = pht('Unread Notifications');
             $no_data = pht('You have no unread notifications.');
             break;
         default:
             $header = pht('Notifications');
             $no_data = pht('You have no notifications.');
             break;
     }
     $notifications = $query->executeWithOffsetPager($pager);
     if ($notifications) {
         $builder = new PhabricatorNotificationBuilder($notifications);
         $view = $builder->buildView();
     } else {
         $view = '<div class="phabricator-notification no-notifications">' . $no_data . '</div>';
     }
     $view = array('<div class="phabricator-notification-list">', $view, '</div>');
     $panel = new AphrontPanelView();
     $panel->setHeader($header);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->addButton(javelin_render_tag('a', array('href' => '/notification/clear/', 'class' => 'button', 'sigil' => 'workflow'), 'Mark All Read'));
     $panel->appendChild($view);
     $panel->appendChild($pager);
     $nav->appendChild($panel);
     return $this->buildStandardPageResponse($nav, array('title' => 'Notifications'));
 }
コード例 #5
0
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $query = new PhabricatorNotificationQuery();
     $query->setUserPHID($user->getPHID());
     $query->setLimit(15);
     $stories = $query->execute();
     if ($stories) {
         $builder = new PhabricatorNotificationBuilder($stories);
         $notifications_view = $builder->buildView();
         $content = $notifications_view->render();
     } else {
         $content = '<div class="phabricator-notification no-notifications">' . 'You have no notifications.' . '</div>';
     }
     $content .= '<div class="phabricator-notification view-all-notifications">' . phutil_render_tag('a', array('href' => '/notification/'), 'View All Notifications') . '</div>';
     $unread_count = id(new PhabricatorFeedStoryNotification())->countUnread($user);
     $json = array('content' => $content, 'number' => $unread_count);
     return id(new AphrontAjaxResponse())->setContent($json);
 }