forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPhabricatorNotificationIndividualController.php
59 lines (47 loc) · 1.84 KB
/
PhabricatorNotificationIndividualController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
final class PhabricatorNotificationIndividualController
extends PhabricatorNotificationController {
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);
}
private function buildEmptyResponse() {
return id(new AphrontAjaxResponse())->setContent(
array(
'pertinent' => false,
));
}
}