diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2305,6 +2305,7 @@ 'PhabricatorDebugController' => 'applications/system/controller/PhabricatorDebugController.php', 'PhabricatorDefaultRequestExceptionHandler' => 'aphront/handler/PhabricatorDefaultRequestExceptionHandler.php', 'PhabricatorDefaultSyntaxStyle' => 'infrastructure/syntax/PhabricatorDefaultSyntaxStyle.php', + 'PhabricatorDesktopNotificationsSetting' => 'applications/settings/setting/PhabricatorDesktopNotificationsSetting.php', 'PhabricatorDesktopNotificationsSettingsPanel' => 'applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php', 'PhabricatorDestructibleInterface' => 'applications/system/interface/PhabricatorDestructibleInterface.php', 'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.php', @@ -6885,6 +6886,7 @@ 'PhabricatorDebugController' => 'PhabricatorController', 'PhabricatorDefaultRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler', 'PhabricatorDefaultSyntaxStyle' => 'PhabricatorSyntaxStyle', + 'PhabricatorDesktopNotificationsSetting' => 'PhabricatorInternalSetting', 'PhabricatorDesktopNotificationsSettingsPanel' => 'PhabricatorSettingsPanel', 'PhabricatorDestructionEngine' => 'Phobject', 'PhabricatorDestructionEngineExtension' => 'Phobject', diff --git a/src/applications/notification/builder/PhabricatorNotificationBuilder.php b/src/applications/notification/builder/PhabricatorNotificationBuilder.php --- a/src/applications/notification/builder/PhabricatorNotificationBuilder.php +++ b/src/applications/notification/builder/PhabricatorNotificationBuilder.php @@ -131,10 +131,14 @@ $stories = $this->parseStories(); $dict = array(); + $viewer = $this->user; + $desktop_key = PhabricatorDesktopNotificationsSetting::SETTINGKEY; + $desktop_enabled = $viewer->getUserSetting($desktop_key); + foreach ($stories as $story) { if ($story instanceof PhabricatorApplicationTransactionFeedStory) { $dict[] = array( - 'desktopReady' => true, + 'desktopReady' => $desktop_enabled, 'title' => $story->renderText(), 'body' => $story->renderTextBody(), 'href' => $story->getURI(), @@ -142,7 +146,7 @@ ); } else if ($story instanceof PhabricatorNotificationTestFeedStory) { $dict[] = array( - 'desktopReady' => true, + 'desktopReady' => $desktop_enabled, 'title' => pht('Test Notification'), 'body' => $story->renderText(), 'href' => null, diff --git a/src/applications/notification/controller/PhabricatorNotificationIndividualController.php b/src/applications/notification/controller/PhabricatorNotificationIndividualController.php --- a/src/applications/notification/controller/PhabricatorNotificationIndividualController.php +++ b/src/applications/notification/controller/PhabricatorNotificationIndividualController.php @@ -30,7 +30,9 @@ return $this->buildEmptyResponse(); } - $builder = new PhabricatorNotificationBuilder(array($story)); + $builder = id(new PhabricatorNotificationBuilder(array($story))) + ->setUser($viewer); + $content = $builder->buildView()->render(); $dict = $builder->buildDict(); $data = $dict[0]; diff --git a/src/applications/notification/controller/PhabricatorNotificationPanelController.php b/src/applications/notification/controller/PhabricatorNotificationPanelController.php --- a/src/applications/notification/controller/PhabricatorNotificationPanelController.php +++ b/src/applications/notification/controller/PhabricatorNotificationPanelController.php @@ -16,7 +16,9 @@ $clear_ui_class = 'phabricator-notification-clear-all'; $clear_uri = id(new PhutilURI('/notification/clear/')); if ($stories) { - $builder = new PhabricatorNotificationBuilder($stories); + $builder = id(new PhabricatorNotificationBuilder($stories)) + ->setUser($viewer); + $notifications_view = $builder->buildView(); $content = $notifications_view->render(); $clear_uri->setQueryParam( diff --git a/src/applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php b/src/applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php --- a/src/applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php +++ b/src/applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php @@ -26,15 +26,19 @@ } public function processRequest(AphrontRequest $request) { - $user = $request->getUser(); - $preferences = $user->loadPreferences(); + $viewer = $this->getViewer(); + $preferences = $this->loadTargetPreferences(); - $pref = PhabricatorUserPreferences::PREFERENCE_DESKTOP_NOTIFICATIONS; + $notifications_key = PhabricatorDesktopNotificationsSetting::SETTINGKEY; + $notifications_value = $preferences->getSettingValue($notifications_key); if ($request->isFormPost()) { - $notifications = $request->getInt($pref); - $preferences->setPreference($pref, $notifications); - $preferences->save(); + + $this->writeSetting( + $preferences, + $notifications_key, + $request->getInt($notifications_key)); + return id(new AphrontRedirectResponse()) ->setURI($this->getPanelURI('?saved=true')); } @@ -106,13 +110,13 @@ ); $form = id(new AphrontFormView()) - ->setUser($user) + ->setUser($viewer) ->appendChild( id(new AphrontFormSelectControl()) ->setLabel($title) ->setControlID($control_id) - ->setName($pref) - ->setValue($preferences->getPreference($pref)) + ->setName($notifications_key) + ->setValue($notifications_value) ->setOptions( array( 1 => pht('Send Desktop Notifications Too'), diff --git a/src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php b/src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php --- a/src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php +++ b/src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php @@ -208,19 +208,8 @@ PhabricatorUserPreferences $preferences, $pinned) { - $viewer = $this->getViewer(); - $request = $this->getController()->getRequest(); $pinned_key = PhabricatorPinnedApplicationsSetting::SETTINGKEY; - - $editor = id(new PhabricatorUserPreferencesEditor()) - ->setActor($viewer) - ->setContentSourceFromRequest($request) - ->setContinueOnNoEffect(true) - ->setContinueOnMissingFields(true); - - $xactions = array(); - $xactions[] = $preferences->newTransaction($pinned_key, $pinned); - $editor->applyTransactions($preferences, $xactions); + $this->writeSetting($preferences, $pinned_key, $pinned); } } diff --git a/src/applications/settings/panel/PhabricatorSettingsPanel.php b/src/applications/settings/panel/PhabricatorSettingsPanel.php --- a/src/applications/settings/panel/PhabricatorSettingsPanel.php +++ b/src/applications/settings/panel/PhabricatorSettingsPanel.php @@ -235,4 +235,22 @@ return $this->getController()->newDialog(); } + protected function writeSetting( + PhabricatorUserPreferences $preferences, + $key, + $value) { + $viewer = $this->getViewer(); + $request = $this->getController()->getRequest(); + + $editor = id(new PhabricatorUserPreferencesEditor()) + ->setActor($viewer) + ->setContentSourceFromRequest($request) + ->setContinueOnNoEffect(true) + ->setContinueOnMissingFields(true); + + $xactions = array(); + $xactions[] = $preferences->newTransaction($key, $value); + $editor->applyTransactions($preferences, $xactions); + } + } diff --git a/src/applications/settings/setting/PhabricatorDesktopNotificationsSetting.php b/src/applications/settings/setting/PhabricatorDesktopNotificationsSetting.php new file mode 100644 --- /dev/null +++ b/src/applications/settings/setting/PhabricatorDesktopNotificationsSetting.php @@ -0,0 +1,12 @@ +<?php + +final class PhabricatorDesktopNotificationsSetting + extends PhabricatorInternalSetting { + + const SETTINGKEY = 'desktop-notifications'; + + public function getSettingName() { + return pht('Desktop Notifications'); + } + +} diff --git a/src/applications/settings/storage/PhabricatorUserPreferences.php b/src/applications/settings/storage/PhabricatorUserPreferences.php --- a/src/applications/settings/storage/PhabricatorUserPreferences.php +++ b/src/applications/settings/storage/PhabricatorUserPreferences.php @@ -14,8 +14,6 @@ const PREFERENCE_VARY_SUBJECT = 'vary-subject'; const PREFERENCE_HTML_EMAILS = 'html-emails'; - const PREFERENCE_DESKTOP_NOTIFICATIONS = 'desktop-notifications'; - // These are in an unusual order for historic reasons. const MAILTAG_PREFERENCE_NOTIFY = 0; const MAILTAG_PREFERENCE_EMAIL = 1;