mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 04:50:55 +01:00
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
This commit is contained in:
parent
6199e95577
commit
9d7c286252
9 changed files with 58 additions and 27 deletions
|
@ -2305,6 +2305,7 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDebugController' => 'PhabricatorController',
|
||||
'PhabricatorDefaultRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler',
|
||||
'PhabricatorDefaultSyntaxStyle' => 'PhabricatorSyntaxStyle',
|
||||
'PhabricatorDesktopNotificationsSetting' => 'PhabricatorInternalSetting',
|
||||
'PhabricatorDesktopNotificationsSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||
'PhabricatorDestructionEngine' => 'Phobject',
|
||||
'PhabricatorDestructionEngineExtension' => 'Phobject',
|
||||
|
|
|
@ -131,10 +131,14 @@ final class PhabricatorNotificationBuilder extends Phobject {
|
|||
$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 @@ final class PhabricatorNotificationBuilder extends Phobject {
|
|||
);
|
||||
} else if ($story instanceof PhabricatorNotificationTestFeedStory) {
|
||||
$dict[] = array(
|
||||
'desktopReady' => true,
|
||||
'desktopReady' => $desktop_enabled,
|
||||
'title' => pht('Test Notification'),
|
||||
'body' => $story->renderText(),
|
||||
'href' => null,
|
||||
|
|
|
@ -30,7 +30,9 @@ final class PhabricatorNotificationIndividualController
|
|||
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];
|
||||
|
|
|
@ -16,7 +16,9 @@ final class PhabricatorNotificationPanelController
|
|||
$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(
|
||||
|
|
|
@ -26,15 +26,19 @@ final class PhabricatorDesktopNotificationsSettingsPanel
|
|||
}
|
||||
|
||||
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 @@ final class PhabricatorDesktopNotificationsSettingsPanel
|
|||
);
|
||||
|
||||
$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'),
|
||||
|
|
|
@ -208,19 +208,8 @@ final class PhabricatorHomePreferencesSettingsPanel
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -235,4 +235,22 @@ abstract class PhabricatorSettingsPanel extends Phobject {
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDesktopNotificationsSetting
|
||||
extends PhabricatorInternalSetting {
|
||||
|
||||
const SETTINGKEY = 'desktop-notifications';
|
||||
|
||||
public function getSettingName() {
|
||||
return pht('Desktop Notifications');
|
||||
}
|
||||
|
||||
}
|
|
@ -14,8 +14,6 @@ final class PhabricatorUserPreferences
|
|||
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;
|
||||
|
|
Loading…
Reference in a new issue