Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / conpherence / controller / ConpherenceNotificationPanelController.php
blob8458a9d5c4d16729906f1883603e51a065ce1774
1 <?php
3 final class ConpherenceNotificationPanelController
4 extends ConpherenceController {
6 public function handleRequest(AphrontRequest $request) {
7 $user = $request->getUser();
8 $conpherences = array();
9 require_celerity_resource('conpherence-notification-css');
11 $participant_data = id(new ConpherenceParticipantQuery())
12 ->withParticipantPHIDs(array($user->getPHID()))
13 ->setLimit(5)
14 ->execute();
15 $participant_data = mpull($participant_data, null, 'getConpherencePHID');
17 if ($participant_data) {
18 $conpherences = id(new ConpherenceThreadQuery())
19 ->setViewer($user)
20 ->withPHIDs(array_keys($participant_data))
21 ->needProfileImage(true)
22 ->needTransactions(true)
23 ->setTransactionLimit(100)
24 ->execute();
27 if ($conpherences) {
28 // re-order the conpherences based on participation data
29 $conpherences = array_select_keys(
30 $conpherences, array_keys($participant_data));
31 $view = new AphrontNullView();
32 foreach ($conpherences as $conpherence) {
33 $p_data = $participant_data[$conpherence->getPHID()];
34 $d_data = $conpherence->getDisplayData($user);
35 $classes = array(
36 'phabricator-notification',
37 'conpherence-notification',
40 if (!$p_data->isUpToDate($conpherence)) {
41 $classes[] = 'phabricator-notification-unread';
43 $uri = $this->getApplicationURI($conpherence->getID().'/');
44 $title = $d_data['title'];
45 $subtitle = $d_data['subtitle'];
46 $unread_count = $d_data['unread_count'];
47 $epoch = $d_data['epoch'];
48 $image = $d_data['image'];
50 $msg_view = id(new ConpherenceMenuItemView())
51 ->setUser($user)
52 ->setTitle($title)
53 ->setSubtitle($subtitle)
54 ->setHref($uri)
55 ->setEpoch($epoch)
56 ->setImageURI($image)
57 ->setUnreadCount($unread_count);
59 $view->appendChild(javelin_tag(
60 'div',
61 array(
62 'class' => implode(' ', $classes),
63 'sigil' => 'notification',
64 'meta' => array(
65 'href' => $uri,
68 $msg_view));
70 $content = $view->render();
71 } else {
72 $rooms_uri = phutil_tag(
73 'a',
74 array(
75 'href' => '/conpherence/',
76 'class' => 'no-room-notification',
78 pht('You have joined no rooms.'));
80 $content = phutil_tag_div(
81 'phabricator-notification no-notifications', $rooms_uri);
84 $content = hsprintf(
85 '<div class="phabricator-notification-header grouped">%s%s</div>'.
86 '%s',
87 phutil_tag(
88 'a',
89 array(
90 'href' => '/conpherence/',
92 pht('Rooms')),
93 $this->renderPersistentOption(),
94 $content);
96 $unread = id(new ConpherenceParticipantCountQuery())
97 ->withParticipantPHIDs(array($user->getPHID()))
98 ->withUnread(true)
99 ->execute();
100 $unread_count = idx($unread, $user->getPHID(), 0);
102 $json = array(
103 'content' => $content,
104 'number' => (int)$unread_count,
107 return id(new AphrontAjaxResponse())->setContent($json);
110 private function renderPersistentOption() {
111 $viewer = $this->getViewer();
112 $column_key = PhabricatorConpherenceColumnVisibleSetting::SETTINGKEY;
113 $show = (bool)$viewer->getUserSetting($column_key, false);
115 $view = phutil_tag(
116 'div',
117 array(
118 'class' => 'persistent-option',
120 array(
121 javelin_tag(
122 'input',
123 array(
124 'type' => 'checkbox',
125 'checked' => ($show) ? 'checked' : null,
126 'value' => !$show,
127 'sigil' => 'conpherence-persist-column',
129 phutil_tag(
130 'span',
131 array(),
132 pht('Persistent Chat')),
135 return $view;