forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConpherenceNotificationPanelController.php
138 lines (121 loc) · 3.85 KB
/
ConpherenceNotificationPanelController.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
final class ConpherenceNotificationPanelController
extends ConpherenceController {
public function handleRequest(AphrontRequest $request) {
$user = $request->getUser();
$conpherences = array();
require_celerity_resource('conpherence-notification-css');
$participant_data = id(new ConpherenceParticipantQuery())
->withParticipantPHIDs(array($user->getPHID()))
->setLimit(5)
->execute();
$participant_data = mpull($participant_data, null, 'getConpherencePHID');
if ($participant_data) {
$conpherences = id(new ConpherenceThreadQuery())
->setViewer($user)
->withPHIDs(array_keys($participant_data))
->needProfileImage(true)
->needTransactions(true)
->setTransactionLimit(100)
->execute();
}
if ($conpherences) {
// re-order the conpherences based on participation data
$conpherences = array_select_keys(
$conpherences, array_keys($participant_data));
$view = new AphrontNullView();
foreach ($conpherences as $conpherence) {
$p_data = $participant_data[$conpherence->getPHID()];
$d_data = $conpherence->getDisplayData($user);
$classes = array(
'phabricator-notification',
'conpherence-notification',
);
if (!$p_data->isUpToDate($conpherence)) {
$classes[] = 'phabricator-notification-unread';
}
$uri = $this->getApplicationURI($conpherence->getID().'/');
$title = $d_data['title'];
$subtitle = $d_data['subtitle'];
$unread_count = $d_data['unread_count'];
$epoch = $d_data['epoch'];
$image = $d_data['image'];
$msg_view = id(new ConpherenceMenuItemView())
->setUser($user)
->setTitle($title)
->setSubtitle($subtitle)
->setHref($uri)
->setEpoch($epoch)
->setImageURI($image)
->setUnreadCount($unread_count);
$view->appendChild(javelin_tag(
'div',
array(
'class' => implode(' ', $classes),
'sigil' => 'notification',
'meta' => array(
'href' => $uri,
),
),
$msg_view));
}
$content = $view->render();
} else {
$rooms_uri = phutil_tag(
'a',
array(
'href' => '/conpherence/',
'class' => 'no-room-notification',
),
pht('You have joined no rooms.'));
$content = phutil_tag_div(
'phabricator-notification no-notifications', $rooms_uri);
}
$content = hsprintf(
'<div class="phabricator-notification-header grouped">%s%s</div>'.
'%s',
phutil_tag(
'a',
array(
'href' => '/conpherence/',
),
pht('Rooms')),
$this->renderPersistentOption(),
$content);
$unread = id(new ConpherenceParticipantCountQuery())
->withParticipantPHIDs(array($user->getPHID()))
->withUnread(true)
->execute();
$unread_count = idx($unread, $user->getPHID(), 0);
$json = array(
'content' => $content,
'number' => (int)$unread_count,
);
return id(new AphrontAjaxResponse())->setContent($json);
}
private function renderPersistentOption() {
$viewer = $this->getViewer();
$column_key = PhabricatorConpherenceColumnVisibleSetting::SETTINGKEY;
$show = (bool)$viewer->getUserSetting($column_key, false);
$view = phutil_tag(
'div',
array(
'class' => 'persistent-option',
),
array(
javelin_tag(
'input',
array(
'type' => 'checkbox',
'checked' => ($show) ? 'checked' : null,
'value' => !$show,
'sigil' => 'conpherence-persist-column',
)),
phutil_tag(
'span',
array(),
pht('Persistent Chat')),
));
return $view;
}
}