1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

Simplify notification code

Summary:
Currently we have two different feed story classes, one for notifications and one for feed stories. However, we never actually do anything different with them -- the notification is always the same as the feed story, just shown differently. Delete the notification special case to reduce the amount of code we have supporting feed and notifications.

This is a precursor to @chad's notification designs.

Test Plan: Viewed notifications and feed, saw exactly the same result before and after the patch (but less, simpler code).

Reviewers: btrahan

Reviewed By: btrahan

CC: chad, aran

Differential Revision: https://secure.phabricator.com/D4114
This commit is contained in:
epriestley 2012-12-07 16:25:23 -08:00
parent 75e8ff26f5
commit 0bd3f3c53e
12 changed files with 46 additions and 151 deletions

View file

@ -745,7 +745,6 @@ phutil_register_library_map(array(
'PhabricatorFeedStoryReference' => 'applications/feed/storage/PhabricatorFeedStoryReference.php',
'PhabricatorFeedStoryStatus' => 'applications/feed/story/PhabricatorFeedStoryStatus.php',
'PhabricatorFeedStoryTypeConstants' => 'applications/feed/constants/PhabricatorFeedStoryTypeConstants.php',
'PhabricatorFeedStoryUnknown' => 'applications/feed/story/PhabricatorFeedStoryUnknown.php',
'PhabricatorFeedStoryView' => 'applications/feed/view/PhabricatorFeedStoryView.php',
'PhabricatorFeedView' => 'applications/feed/view/PhabricatorFeedView.php',
'PhabricatorFile' => 'applications/files/storage/PhabricatorFile.php',
@ -872,8 +871,6 @@ phutil_register_library_map(array(
'PhabricatorNotificationPanelController' => 'applications/notification/controller/PhabricatorNotificationPanelController.php',
'PhabricatorNotificationQuery' => 'applications/notification/PhabricatorNotificationQuery.php',
'PhabricatorNotificationStatusController' => 'applications/notification/controller/PhabricatorNotificationStatusController.php',
'PhabricatorNotificationStoryView' => 'applications/notification/view/PhabricatorNotificationStoryView.php',
'PhabricatorNotificationView' => 'applications/notification/view/PhabricatorNotificationView.php',
'PhabricatorOAuthClientAuthorization' => 'applications/oauthserver/storage/PhabricatorOAuthClientAuthorization.php',
'PhabricatorOAuthClientAuthorizationBaseController' => 'applications/oauthserver/controller/clientauthorization/PhabricatorOAuthClientAuthorizationBaseController.php',
'PhabricatorOAuthClientAuthorizationDeleteController' => 'applications/oauthserver/controller/clientauthorization/PhabricatorOAuthClientAuthorizationDeleteController.php',
@ -1986,7 +1983,6 @@ phutil_register_library_map(array(
'PhabricatorFeedStoryReference' => 'PhabricatorFeedDAO',
'PhabricatorFeedStoryStatus' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryTypeConstants' => 'PhabricatorFeedConstants',
'PhabricatorFeedStoryUnknown' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryView' => 'PhabricatorFeedView',
'PhabricatorFeedView' => 'AphrontView',
'PhabricatorFile' =>
@ -2096,8 +2092,6 @@ phutil_register_library_map(array(
'PhabricatorNotificationPanelController' => 'PhabricatorNotificationController',
'PhabricatorNotificationQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorNotificationStatusController' => 'PhabricatorNotificationController',
'PhabricatorNotificationStoryView' => 'PhabricatorNotificationView',
'PhabricatorNotificationView' => 'AphrontView',
'PhabricatorOAuthClientAuthorization' => 'PhabricatorOAuthServerDAO',
'PhabricatorOAuthClientAuthorizationBaseController' => 'PhabricatorOAuthServerController',
'PhabricatorOAuthClientAuthorizationDeleteController' => 'PhabricatorOAuthClientAuthorizationBaseController',

View file

@ -149,12 +149,6 @@ abstract class PhabricatorFeedStory implements PhabricatorPolicyInterface {
abstract public function renderView();
// TODO: Make abstract once all subclasses implement it.
public function renderNotificationView() {
return id(new PhabricatorFeedStoryUnknown($this->data))
->renderNotificationView();
}
public function getRequiredHandlePHIDs() {
return array();
}

View file

@ -10,6 +10,7 @@ final class PhabricatorFeedStoryDifferential extends PhabricatorFeedStory {
$data = $this->getStoryData();
$view = new PhabricatorFeedStoryView();
$view->setViewed($this->getHasViewed());
$line = $this->getLineForData($data);
$view->setTitle($line);
@ -37,18 +38,6 @@ final class PhabricatorFeedStoryDifferential extends PhabricatorFeedStory {
return $view;
}
public function renderNotificationView() {
$data = $this->getStoryData();
$view = new PhabricatorNotificationStoryView();
$view->setTitle($this->getLineForData($data));
$view->setEpoch($data->getEpoch());
$view->setViewed($this->getHasViewed());
return $view;
}
private function getLineForData($data) {
$actor_phid = $data->getAuthorPHID();
$revision_phid = $data->getValue('revision_phid');

View file

@ -4,11 +4,6 @@ final class PhabricatorFeedStoryDifferentialAggregate
extends PhabricatorFeedStoryAggregate {
public function renderView() {
return null;
}
public function renderNotificationView() {
$data = $this->getStoryData();
$task_link = $this->linkTo($data->getValue('revision_phid'));
@ -59,7 +54,7 @@ final class PhabricatorFeedStoryDifferentialAggregate
break;
}
$view = new PhabricatorNotificationStoryView();
$view = new PhabricatorFeedStoryView();
$view->setEpoch($this->getEpoch());
$view->setViewed($this->getHasViewed());
$view->setTitle($title);

View file

@ -17,6 +17,7 @@ final class PhabricatorFeedStoryManiphest
$data = $this->getStoryData();
$view = new PhabricatorFeedStoryView();
$view->setViewed($this->getHasViewed());
$line = $this->getLineForData($data);
$view->setTitle($line);
@ -43,18 +44,6 @@ final class PhabricatorFeedStoryManiphest
return $view;
}
public function renderNotificationView() {
$data = $this->getStoryData();
$view = new PhabricatorNotificationStoryView();
$view->setTitle($this->getLineForData($data));
$view->setEpoch($data->getEpoch());
$view->setViewed($this->getHasViewed());
return $view;
}
private function getLineForData($data) {
$action = $data->getValue('action');

View file

@ -4,11 +4,6 @@ final class PhabricatorFeedStoryManiphestAggregate
extends PhabricatorFeedStoryAggregate {
public function renderView() {
return null;
}
public function renderNotificationView() {
$data = $this->getStoryData();
$task_link = $this->linkTo($data->getValue('taskPHID'));
@ -59,7 +54,7 @@ final class PhabricatorFeedStoryManiphestAggregate
break;
}
$view = new PhabricatorNotificationStoryView();
$view = new PhabricatorFeedStoryView();
$view->setEpoch($this->getEpoch());
$view->setViewed($this->getHasViewed());
$view->setTitle($title);

View file

@ -1,38 +0,0 @@
<?php
final class PhabricatorFeedStoryUnknown extends PhabricatorFeedStory {
public function renderView() {
$data = $this->getStoryData();
$view = new PhabricatorFeedStoryView();
$view->setTitle('Unknown Story');
$view->setEpoch($data->getEpoch());
$view->appendChild(
'This is an unrenderable feed story of type '.
'"'.phutil_escape_html($data->getStoryType()).'".');
return $view;
}
public function renderNotificationView() {
$data = $this->getStoryData();
$view = new PhabricatorNotificationStoryView();
$view->setTitle('A wild notifcation appeared!');
$view->setEpoch($data->getEpoch());
$view->appendChild(
'This is an unrenderable feed story of type '.
'"'.phutil_escape_html($data->getStoryType()).'".');
return $view;
}
}

View file

@ -7,6 +7,7 @@ final class PhabricatorFeedStoryView extends PhabricatorFeedView {
private $phid;
private $epoch;
private $viewer;
private $viewed;
private $oneLine;
@ -35,6 +36,32 @@ final class PhabricatorFeedStoryView extends PhabricatorFeedView {
return $this;
}
public function setViewed($viewed) {
$this->viewed = $viewed;
return $this;
}
public function getViewed() {
return $this->viewed;
}
public function renderNotification() {
$classes = array(
'phabricator-notification',
);
if (!$this->viewed) {
$classes[] = 'phabricator-notification-unread';
}
return phutil_render_tag(
'div',
array(
'class' => implode(' ', $classes),
),
$this->title);
}
public function render() {
$head = phutil_render_tag(

View file

@ -123,8 +123,9 @@ final class PhabricatorNotificationBuilder {
$null_view = new AphrontNullView();
foreach ($stories as $story) {
$view = $story->renderNotificationView();
$null_view->appendChild($view);
$view = $story->renderView();
$null_view->appendChild($view->renderNotification());
}
return $null_view;

View file

@ -14,7 +14,8 @@ final class PhabricatorFeedStoryNotification extends PhabricatorFeedDAO {
) + parent::getConfiguration();
}
static public function updateObjectNotificationViews(PhabricatorUser $user,
static public function updateObjectNotificationViews(
PhabricatorUser $user,
$object_phid) {
if (PhabricatorEnv::getEnvConfig('notification.enabled')) {
@ -38,22 +39,18 @@ final class PhabricatorFeedStoryNotification extends PhabricatorFeedDAO {
}
}
/* should only be called when notifications are enabled */
public function countUnread(
PhabricatorUser $user) {
public function countUnread(PhabricatorUser $user) {
$conn = $this->establishConnection('r');
$conn = $this->establishConnection('r');
$data = queryfx_one(
$conn,
'SELECT COUNT(*) as count
FROM %T
WHERE userPHID = %s AND hasViewed = 0',
$this->getTableName(),
$user->getPHID());
$data = queryfx_one(
$conn,
"SELECT COUNT(*) as count
FROM %T
WHERE userPHID = %s
AND hasViewed=0",
$this->getTableName(),
$user->getPHID());
return $data['count'];
return $data['count'];
}
}

View file

@ -1,43 +0,0 @@
<?php
final class PhabricatorNotificationStoryView
extends PhabricatorNotificationView {
private $title;
private $phid;
private $epoch;
private $viewed;
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function setEpoch($epoch) {
$this->epoch = $epoch;
return $this;
}
public function setViewed($viewed) {
$this->viewed = $viewed;
}
public function render() {
$classes = array(
'phabricator-notification',
);
if (!$this->viewed) {
$classes[] = 'phabricator-notification-unread';
}
return phutil_render_tag(
'div',
array(
'class' => implode(' ', $classes),
),
$this->title);
}
}

View file

@ -1,5 +0,0 @@
<?php
abstract class PhabricatorNotificationView extends AphrontView {
}