Differential D18133 Diff 43631 src/applications/notification/controller/PhabricatorNotificationClearController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/notification/controller/PhabricatorNotificationClearController.php
| <?php | <?php | ||||
| final class PhabricatorNotificationClearController | final class PhabricatorNotificationClearController | ||||
| extends PhabricatorNotificationController { | extends PhabricatorNotificationController { | ||||
| public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
| $viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
| $chrono_key = $request->getStr('chronoKey'); | $chrono_key = $request->getStr('chronoKey'); | ||||
| $redirect = $request->getBool('redirect'); | |||||
| if ($request->isDialogFormPost()) { | |||||
| $table = new PhabricatorFeedStoryNotification(); | $table = new PhabricatorFeedStoryNotification(); | ||||
| queryfx( | queryfx( | ||||
| $table->establishConnection('w'), | $table->establishConnection('w'), | ||||
| 'UPDATE %T SET hasViewed = 1 '. | 'UPDATE %T SET hasViewed = 1 '. | ||||
| 'WHERE userPHID = %s AND hasViewed = 0 and chronologicalKey <= %s', | 'WHERE userPHID = %s AND hasViewed = 0 and chronologicalKey <= %s', | ||||
| $table->getTableName(), | $table->getTableName(), | ||||
| $viewer->getPHID(), | $viewer->getPHID(), | ||||
| $chrono_key); | $chrono_key); | ||||
| PhabricatorUserCache::clearCache( | PhabricatorUserCache::clearCache( | ||||
| PhabricatorUserNotificationCountCacheType::KEY_COUNT, | PhabricatorUserNotificationCountCacheType::KEY_COUNT, | ||||
| $viewer->getPHID()); | $viewer->getPHID()); | ||||
| // Redirect back to page if on ApplicationSearch | |||||
| if ($redirect) { | |||||
| return id(new AphrontReloadResponse()) | return id(new AphrontReloadResponse()) | ||||
| ->setURI('/notification/'); | ->setURI('/notification/'); | ||||
| } | } | ||||
| $dialog = new AphrontDialogView(); | return id(new AphrontAjaxResponse())->setContent(array()); | ||||
| $dialog->setUser($viewer); | |||||
| $dialog->addCancelButton('/notification/'); | |||||
| if ($chrono_key) { | |||||
| $dialog->setTitle(pht('Really mark all notifications as read?')); | |||||
| $dialog->addHiddenInput('chronoKey', $chrono_key); | |||||
| $is_serious = | |||||
| PhabricatorEnv::getEnvConfig('phabricator.serious-business'); | |||||
| if ($is_serious) { | |||||
| $dialog->appendChild( | |||||
| pht( | |||||
| 'All unread notifications will be marked as read. You can not '. | |||||
| 'undo this action.')); | |||||
| } else { | |||||
| $dialog->appendChild( | |||||
| pht( | |||||
| "You can't ignore your problems forever, you know.")); | |||||
| } | |||||
| $dialog->addSubmitButton(pht('Mark All Read')); | |||||
| } else { | |||||
| $dialog->setTitle(pht('No notifications to mark as read.')); | |||||
| $dialog->appendChild(pht('You have no unread notifications.')); | |||||
| } | |||||
| return id(new AphrontDialogResponse())->setDialog($dialog); | |||||
| } | } | ||||
| } | } | ||||