1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 17:02:41 +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', 'PhabricatorFeedStoryReference' => 'applications/feed/storage/PhabricatorFeedStoryReference.php',
'PhabricatorFeedStoryStatus' => 'applications/feed/story/PhabricatorFeedStoryStatus.php', 'PhabricatorFeedStoryStatus' => 'applications/feed/story/PhabricatorFeedStoryStatus.php',
'PhabricatorFeedStoryTypeConstants' => 'applications/feed/constants/PhabricatorFeedStoryTypeConstants.php', 'PhabricatorFeedStoryTypeConstants' => 'applications/feed/constants/PhabricatorFeedStoryTypeConstants.php',
'PhabricatorFeedStoryUnknown' => 'applications/feed/story/PhabricatorFeedStoryUnknown.php',
'PhabricatorFeedStoryView' => 'applications/feed/view/PhabricatorFeedStoryView.php', 'PhabricatorFeedStoryView' => 'applications/feed/view/PhabricatorFeedStoryView.php',
'PhabricatorFeedView' => 'applications/feed/view/PhabricatorFeedView.php', 'PhabricatorFeedView' => 'applications/feed/view/PhabricatorFeedView.php',
'PhabricatorFile' => 'applications/files/storage/PhabricatorFile.php', 'PhabricatorFile' => 'applications/files/storage/PhabricatorFile.php',
@ -872,8 +871,6 @@ phutil_register_library_map(array(
'PhabricatorNotificationPanelController' => 'applications/notification/controller/PhabricatorNotificationPanelController.php', 'PhabricatorNotificationPanelController' => 'applications/notification/controller/PhabricatorNotificationPanelController.php',
'PhabricatorNotificationQuery' => 'applications/notification/PhabricatorNotificationQuery.php', 'PhabricatorNotificationQuery' => 'applications/notification/PhabricatorNotificationQuery.php',
'PhabricatorNotificationStatusController' => 'applications/notification/controller/PhabricatorNotificationStatusController.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', 'PhabricatorOAuthClientAuthorization' => 'applications/oauthserver/storage/PhabricatorOAuthClientAuthorization.php',
'PhabricatorOAuthClientAuthorizationBaseController' => 'applications/oauthserver/controller/clientauthorization/PhabricatorOAuthClientAuthorizationBaseController.php', 'PhabricatorOAuthClientAuthorizationBaseController' => 'applications/oauthserver/controller/clientauthorization/PhabricatorOAuthClientAuthorizationBaseController.php',
'PhabricatorOAuthClientAuthorizationDeleteController' => 'applications/oauthserver/controller/clientauthorization/PhabricatorOAuthClientAuthorizationDeleteController.php', 'PhabricatorOAuthClientAuthorizationDeleteController' => 'applications/oauthserver/controller/clientauthorization/PhabricatorOAuthClientAuthorizationDeleteController.php',
@ -1986,7 +1983,6 @@ phutil_register_library_map(array(
'PhabricatorFeedStoryReference' => 'PhabricatorFeedDAO', 'PhabricatorFeedStoryReference' => 'PhabricatorFeedDAO',
'PhabricatorFeedStoryStatus' => 'PhabricatorFeedStory', 'PhabricatorFeedStoryStatus' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryTypeConstants' => 'PhabricatorFeedConstants', 'PhabricatorFeedStoryTypeConstants' => 'PhabricatorFeedConstants',
'PhabricatorFeedStoryUnknown' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryView' => 'PhabricatorFeedView', 'PhabricatorFeedStoryView' => 'PhabricatorFeedView',
'PhabricatorFeedView' => 'AphrontView', 'PhabricatorFeedView' => 'AphrontView',
'PhabricatorFile' => 'PhabricatorFile' =>
@ -2096,8 +2092,6 @@ phutil_register_library_map(array(
'PhabricatorNotificationPanelController' => 'PhabricatorNotificationController', 'PhabricatorNotificationPanelController' => 'PhabricatorNotificationController',
'PhabricatorNotificationQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorNotificationQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorNotificationStatusController' => 'PhabricatorNotificationController', 'PhabricatorNotificationStatusController' => 'PhabricatorNotificationController',
'PhabricatorNotificationStoryView' => 'PhabricatorNotificationView',
'PhabricatorNotificationView' => 'AphrontView',
'PhabricatorOAuthClientAuthorization' => 'PhabricatorOAuthServerDAO', 'PhabricatorOAuthClientAuthorization' => 'PhabricatorOAuthServerDAO',
'PhabricatorOAuthClientAuthorizationBaseController' => 'PhabricatorOAuthServerController', 'PhabricatorOAuthClientAuthorizationBaseController' => 'PhabricatorOAuthServerController',
'PhabricatorOAuthClientAuthorizationDeleteController' => 'PhabricatorOAuthClientAuthorizationBaseController', 'PhabricatorOAuthClientAuthorizationDeleteController' => 'PhabricatorOAuthClientAuthorizationBaseController',

View file

@ -149,12 +149,6 @@ abstract class PhabricatorFeedStory implements PhabricatorPolicyInterface {
abstract public function renderView(); 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() { public function getRequiredHandlePHIDs() {
return array(); return array();
} }

View file

@ -10,6 +10,7 @@ final class PhabricatorFeedStoryDifferential extends PhabricatorFeedStory {
$data = $this->getStoryData(); $data = $this->getStoryData();
$view = new PhabricatorFeedStoryView(); $view = new PhabricatorFeedStoryView();
$view->setViewed($this->getHasViewed());
$line = $this->getLineForData($data); $line = $this->getLineForData($data);
$view->setTitle($line); $view->setTitle($line);
@ -37,18 +38,6 @@ final class PhabricatorFeedStoryDifferential extends PhabricatorFeedStory {
return $view; 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) { private function getLineForData($data) {
$actor_phid = $data->getAuthorPHID(); $actor_phid = $data->getAuthorPHID();
$revision_phid = $data->getValue('revision_phid'); $revision_phid = $data->getValue('revision_phid');

View file

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

View file

@ -17,6 +17,7 @@ final class PhabricatorFeedStoryManiphest
$data = $this->getStoryData(); $data = $this->getStoryData();
$view = new PhabricatorFeedStoryView(); $view = new PhabricatorFeedStoryView();
$view->setViewed($this->getHasViewed());
$line = $this->getLineForData($data); $line = $this->getLineForData($data);
$view->setTitle($line); $view->setTitle($line);
@ -43,18 +44,6 @@ final class PhabricatorFeedStoryManiphest
return $view; 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) { private function getLineForData($data) {
$action = $data->getValue('action'); $action = $data->getValue('action');

View file

@ -4,11 +4,6 @@ final class PhabricatorFeedStoryManiphestAggregate
extends PhabricatorFeedStoryAggregate { extends PhabricatorFeedStoryAggregate {
public function renderView() { public function renderView() {
return null;
}
public function renderNotificationView() {
$data = $this->getStoryData(); $data = $this->getStoryData();
$task_link = $this->linkTo($data->getValue('taskPHID')); $task_link = $this->linkTo($data->getValue('taskPHID'));
@ -59,7 +54,7 @@ final class PhabricatorFeedStoryManiphestAggregate
break; break;
} }
$view = new PhabricatorNotificationStoryView(); $view = new PhabricatorFeedStoryView();
$view->setEpoch($this->getEpoch()); $view->setEpoch($this->getEpoch());
$view->setViewed($this->getHasViewed()); $view->setViewed($this->getHasViewed());
$view->setTitle($title); $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 $phid;
private $epoch; private $epoch;
private $viewer; private $viewer;
private $viewed;
private $oneLine; private $oneLine;
@ -35,6 +36,32 @@ final class PhabricatorFeedStoryView extends PhabricatorFeedView {
return $this; 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() { public function render() {
$head = phutil_render_tag( $head = phutil_render_tag(

View file

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

View file

@ -14,7 +14,8 @@ final class PhabricatorFeedStoryNotification extends PhabricatorFeedDAO {
) + parent::getConfiguration(); ) + parent::getConfiguration();
} }
static public function updateObjectNotificationViews(PhabricatorUser $user, static public function updateObjectNotificationViews(
PhabricatorUser $user,
$object_phid) { $object_phid) {
if (PhabricatorEnv::getEnvConfig('notification.enabled')) { 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( $conn = $this->establishConnection('r');
PhabricatorUser $user) {
$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( return $data['count'];
$conn,
"SELECT COUNT(*) as count
FROM %T
WHERE userPHID = %s
AND hasViewed=0",
$this->getTableName(),
$user->getPHID());
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 {
}