Differential D11275 Diff 27105 src/applications/notification/controller/PhabricatorNotificationIndividualController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/notification/controller/PhabricatorNotificationIndividualController.php
<?php | <?php | ||||
final class PhabricatorNotificationIndividualController | final class PhabricatorNotificationIndividualController | ||||
extends PhabricatorNotificationController { | extends PhabricatorNotificationController { | ||||
public function processRequest() { | public function processRequest() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $viewer = $request->getUser(); | ||||
$stories = id(new PhabricatorNotificationQuery()) | $stories = id(new PhabricatorNotificationQuery()) | ||||
->setViewer($user) | ->setViewer($viewer) | ||||
->withUserPHIDs(array($user->getPHID())) | ->withUserPHIDs(array($viewer->getPHID())) | ||||
->withKeys(array($request->getStr('key'))) | ->withKeys(array($request->getStr('key'))) | ||||
->execute(); | ->execute(); | ||||
if (!$stories) { | if (!$stories) { | ||||
return id(new AphrontAjaxResponse())->setContent( | return $this->buildEmptyResponse(); | ||||
array( | } | ||||
'pertinent' => false, | |||||
)); | $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($stories); | $builder = new PhabricatorNotificationBuilder(array($story)); | ||||
$content = $builder->buildView()->render(); | $content = $builder->buildView()->render(); | ||||
$response = array( | $response = array( | ||||
'pertinent' => true, | 'pertinent' => true, | ||||
'primaryObjectPHID' => head($stories)->getPrimaryObjectPHID(), | 'primaryObjectPHID' => $story->getPrimaryObjectPHID(), | ||||
'content' => hsprintf('%s', $content), | 'content' => hsprintf('%s', $content), | ||||
); | ); | ||||
return id(new AphrontAjaxResponse())->setContent($response); | return id(new AphrontAjaxResponse())->setContent($response); | ||||
} | } | ||||
private function buildEmptyResponse() { | |||||
return id(new AphrontAjaxResponse())->setContent( | |||||
array( | |||||
'pertinent' => false, | |||||
)); | |||||
} | |||||
} | } |