Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / notification / controller / PhabricatorNotificationIndividualController.php
blobbac429288e47f39729885266bd66386435613b82
1 <?php
3 final class PhabricatorNotificationIndividualController
4 extends PhabricatorNotificationController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
9 $stories = id(new PhabricatorNotificationQuery())
10 ->setViewer($viewer)
11 ->withUserPHIDs(array($viewer->getPHID()))
12 ->withKeys(array($request->getStr('key')))
13 ->execute();
15 if (!$stories) {
16 return $this->buildEmptyResponse();
19 $story = head($stories);
20 if ($story->getAuthorPHID() === $viewer->getPHID()) {
21 // Don't show the user individual notifications about their own
22 // actions. Primarily, this stops pages from showing notifications
23 // immediately after you click "Submit" on a comment form if the
24 // notification server returns faster than the web server.
26 // TODO: It would be nice to retain the "page updated" bubble on copies
27 // of the page that are open in other tabs, but there isn't an obvious
28 // way to do this easily.
30 return $this->buildEmptyResponse();
33 $builder = id(new PhabricatorNotificationBuilder(array($story)))
34 ->setUser($viewer)
35 ->setShowTimestamps(false);
37 $content = $builder->buildView()->render();
38 $dict = $builder->buildDict();
39 $data = $dict[0];
41 $response = $data + array(
42 'pertinent' => true,
43 'primaryObjectPHID' => $story->getPrimaryObjectPHID(),
44 'content' => hsprintf('%s', $content),
45 'uniqueID' => 'story/'.$story->getChronologicalKey(),
48 return id(new AphrontAjaxResponse())->setContent($response);
51 private function buildEmptyResponse() {
52 return id(new AphrontAjaxResponse())->setContent(
53 array(
54 'pertinent' => false,
55 ));