Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/notification/controller/PhabricatorNotificationClearController.php
12256 views
1
<?php
2
3
final class PhabricatorNotificationClearController
4
extends PhabricatorNotificationController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $request->getViewer();
8
$chrono_key = $request->getStr('chronoKey');
9
10
if ($request->isDialogFormPost()) {
11
$should_clear = true;
12
} else {
13
$should_clear = $request->hasCSRF();
14
}
15
16
if ($should_clear) {
17
$table = new PhabricatorFeedStoryNotification();
18
19
queryfx(
20
$table->establishConnection('w'),
21
'UPDATE %T SET hasViewed = 1 '.
22
'WHERE userPHID = %s AND hasViewed = 0 and chronologicalKey <= %s',
23
$table->getTableName(),
24
$viewer->getPHID(),
25
$chrono_key);
26
27
PhabricatorUserCache::clearCache(
28
PhabricatorUserNotificationCountCacheType::KEY_COUNT,
29
$viewer->getPHID());
30
31
return id(new AphrontReloadResponse())
32
->setURI('/notification/');
33
}
34
35
$dialog = new AphrontDialogView();
36
$dialog->setUser($viewer);
37
$dialog->addCancelButton('/notification/');
38
if ($chrono_key) {
39
$dialog->setTitle(pht('Really mark all notifications as read?'));
40
$dialog->addHiddenInput('chronoKey', $chrono_key);
41
42
$is_serious =
43
PhabricatorEnv::getEnvConfig('phabricator.serious-business');
44
if ($is_serious) {
45
$dialog->appendChild(
46
pht(
47
'All unread notifications will be marked as read. You can not '.
48
'undo this action.'));
49
} else {
50
$dialog->appendChild(
51
pht(
52
"You can't ignore your problems forever, you know."));
53
}
54
55
$dialog->addSubmitButton(pht('Mark All Read'));
56
} else {
57
$dialog->setTitle(pht('No notifications to mark as read.'));
58
$dialog->appendChild(pht('You have no unread notifications.'));
59
}
60
61
return id(new AphrontDialogResponse())->setDialog($dialog);
62
}
63
}
64
65