@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow users to turn off desktop notifications

Summary: Fixes T8846. Ref T4103. I just took the shortest reasonable path here, this panel could use some attention on the next Conpherence iteration.

Test Plan: Turned on/off desktop notifications. Observed corresponding behavior in test notifications.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4103, T8846

Differential Revision: https://secure.phabricator.com/D16036

+58 -27
+2
src/__phutil_library_map__.php
··· 2305 2305 'PhabricatorDebugController' => 'applications/system/controller/PhabricatorDebugController.php', 2306 2306 'PhabricatorDefaultRequestExceptionHandler' => 'aphront/handler/PhabricatorDefaultRequestExceptionHandler.php', 2307 2307 'PhabricatorDefaultSyntaxStyle' => 'infrastructure/syntax/PhabricatorDefaultSyntaxStyle.php', 2308 + 'PhabricatorDesktopNotificationsSetting' => 'applications/settings/setting/PhabricatorDesktopNotificationsSetting.php', 2308 2309 'PhabricatorDesktopNotificationsSettingsPanel' => 'applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php', 2309 2310 'PhabricatorDestructibleInterface' => 'applications/system/interface/PhabricatorDestructibleInterface.php', 2310 2311 'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.php', ··· 6885 6886 'PhabricatorDebugController' => 'PhabricatorController', 6886 6887 'PhabricatorDefaultRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler', 6887 6888 'PhabricatorDefaultSyntaxStyle' => 'PhabricatorSyntaxStyle', 6889 + 'PhabricatorDesktopNotificationsSetting' => 'PhabricatorInternalSetting', 6888 6890 'PhabricatorDesktopNotificationsSettingsPanel' => 'PhabricatorSettingsPanel', 6889 6891 'PhabricatorDestructionEngine' => 'Phobject', 6890 6892 'PhabricatorDestructionEngineExtension' => 'Phobject',
+6 -2
src/applications/notification/builder/PhabricatorNotificationBuilder.php
··· 131 131 $stories = $this->parseStories(); 132 132 $dict = array(); 133 133 134 + $viewer = $this->user; 135 + $desktop_key = PhabricatorDesktopNotificationsSetting::SETTINGKEY; 136 + $desktop_enabled = $viewer->getUserSetting($desktop_key); 137 + 134 138 foreach ($stories as $story) { 135 139 if ($story instanceof PhabricatorApplicationTransactionFeedStory) { 136 140 $dict[] = array( 137 - 'desktopReady' => true, 141 + 'desktopReady' => $desktop_enabled, 138 142 'title' => $story->renderText(), 139 143 'body' => $story->renderTextBody(), 140 144 'href' => $story->getURI(), ··· 142 146 ); 143 147 } else if ($story instanceof PhabricatorNotificationTestFeedStory) { 144 148 $dict[] = array( 145 - 'desktopReady' => true, 149 + 'desktopReady' => $desktop_enabled, 146 150 'title' => pht('Test Notification'), 147 151 'body' => $story->renderText(), 148 152 'href' => null,
+3 -1
src/applications/notification/controller/PhabricatorNotificationIndividualController.php
··· 30 30 return $this->buildEmptyResponse(); 31 31 } 32 32 33 - $builder = new PhabricatorNotificationBuilder(array($story)); 33 + $builder = id(new PhabricatorNotificationBuilder(array($story))) 34 + ->setUser($viewer); 35 + 34 36 $content = $builder->buildView()->render(); 35 37 $dict = $builder->buildDict(); 36 38 $data = $dict[0];
+3 -1
src/applications/notification/controller/PhabricatorNotificationPanelController.php
··· 16 16 $clear_ui_class = 'phabricator-notification-clear-all'; 17 17 $clear_uri = id(new PhutilURI('/notification/clear/')); 18 18 if ($stories) { 19 - $builder = new PhabricatorNotificationBuilder($stories); 19 + $builder = id(new PhabricatorNotificationBuilder($stories)) 20 + ->setUser($viewer); 21 + 20 22 $notifications_view = $builder->buildView(); 21 23 $content = $notifications_view->render(); 22 24 $clear_uri->setQueryParam(
+13 -9
src/applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php
··· 26 26 } 27 27 28 28 public function processRequest(AphrontRequest $request) { 29 - $user = $request->getUser(); 30 - $preferences = $user->loadPreferences(); 29 + $viewer = $this->getViewer(); 30 + $preferences = $this->loadTargetPreferences(); 31 31 32 - $pref = PhabricatorUserPreferences::PREFERENCE_DESKTOP_NOTIFICATIONS; 32 + $notifications_key = PhabricatorDesktopNotificationsSetting::SETTINGKEY; 33 + $notifications_value = $preferences->getSettingValue($notifications_key); 33 34 34 35 if ($request->isFormPost()) { 35 - $notifications = $request->getInt($pref); 36 - $preferences->setPreference($pref, $notifications); 37 - $preferences->save(); 36 + 37 + $this->writeSetting( 38 + $preferences, 39 + $notifications_key, 40 + $request->getInt($notifications_key)); 41 + 38 42 return id(new AphrontRedirectResponse()) 39 43 ->setURI($this->getPanelURI('?saved=true')); 40 44 } ··· 106 110 ); 107 111 108 112 $form = id(new AphrontFormView()) 109 - ->setUser($user) 113 + ->setUser($viewer) 110 114 ->appendChild( 111 115 id(new AphrontFormSelectControl()) 112 116 ->setLabel($title) 113 117 ->setControlID($control_id) 114 - ->setName($pref) 115 - ->setValue($preferences->getPreference($pref)) 118 + ->setName($notifications_key) 119 + ->setValue($notifications_value) 116 120 ->setOptions( 117 121 array( 118 122 1 => pht('Send Desktop Notifications Too'),
+1 -12
src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php
··· 208 208 PhabricatorUserPreferences $preferences, 209 209 $pinned) { 210 210 211 - $viewer = $this->getViewer(); 212 - $request = $this->getController()->getRequest(); 213 211 $pinned_key = PhabricatorPinnedApplicationsSetting::SETTINGKEY; 214 - 215 - $editor = id(new PhabricatorUserPreferencesEditor()) 216 - ->setActor($viewer) 217 - ->setContentSourceFromRequest($request) 218 - ->setContinueOnNoEffect(true) 219 - ->setContinueOnMissingFields(true); 220 - 221 - $xactions = array(); 222 - $xactions[] = $preferences->newTransaction($pinned_key, $pinned); 223 - $editor->applyTransactions($preferences, $xactions); 212 + $this->writeSetting($preferences, $pinned_key, $pinned); 224 213 } 225 214 226 215 }
+18
src/applications/settings/panel/PhabricatorSettingsPanel.php
··· 235 235 return $this->getController()->newDialog(); 236 236 } 237 237 238 + protected function writeSetting( 239 + PhabricatorUserPreferences $preferences, 240 + $key, 241 + $value) { 242 + $viewer = $this->getViewer(); 243 + $request = $this->getController()->getRequest(); 244 + 245 + $editor = id(new PhabricatorUserPreferencesEditor()) 246 + ->setActor($viewer) 247 + ->setContentSourceFromRequest($request) 248 + ->setContinueOnNoEffect(true) 249 + ->setContinueOnMissingFields(true); 250 + 251 + $xactions = array(); 252 + $xactions[] = $preferences->newTransaction($key, $value); 253 + $editor->applyTransactions($preferences, $xactions); 254 + } 255 + 238 256 }
+12
src/applications/settings/setting/PhabricatorDesktopNotificationsSetting.php
··· 1 + <?php 2 + 3 + final class PhabricatorDesktopNotificationsSetting 4 + extends PhabricatorInternalSetting { 5 + 6 + const SETTINGKEY = 'desktop-notifications'; 7 + 8 + public function getSettingName() { 9 + return pht('Desktop Notifications'); 10 + } 11 + 12 + }
-2
src/applications/settings/storage/PhabricatorUserPreferences.php
··· 14 14 const PREFERENCE_VARY_SUBJECT = 'vary-subject'; 15 15 const PREFERENCE_HTML_EMAILS = 'html-emails'; 16 16 17 - const PREFERENCE_DESKTOP_NOTIFICATIONS = 'desktop-notifications'; 18 - 19 17 // These are in an unusual order for historic reasons. 20 18 const MAILTAG_PREFERENCE_NOTIFY = 0; 21 19 const MAILTAG_PREFERENCE_EMAIL = 1;