Differential D10240 Diff 24643 src/applications/settings/panel/PhabricatorSettingsPanelEmailPreferences.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/panel/PhabricatorSettingsPanelEmailPreferences.php
Show All 17 Lines | final class PhabricatorSettingsPanelEmailPreferences | ||||
public function processRequest(AphrontRequest $request) { | public function processRequest(AphrontRequest $request) { | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
$preferences = $user->loadPreferences(); | $preferences = $user->loadPreferences(); | ||||
$pref_no_mail = PhabricatorUserPreferences::PREFERENCE_NO_MAIL; | $pref_no_mail = PhabricatorUserPreferences::PREFERENCE_NO_MAIL; | ||||
$pref_no_self_mail = PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL; | $pref_no_self_mail = PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL; | ||||
$value_email = PhabricatorUserPreferences::MAILTAG_PREFERENCE_EMAIL; | |||||
$errors = array(); | $errors = array(); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$preferences->setPreference( | $preferences->setPreference( | ||||
$pref_no_mail, | $pref_no_mail, | ||||
$request->getStr($pref_no_mail)); | $request->getStr($pref_no_mail)); | ||||
$preferences->setPreference( | $preferences->setPreference( | ||||
$pref_no_self_mail, | $pref_no_self_mail, | ||||
$request->getStr($pref_no_self_mail)); | $request->getStr($pref_no_self_mail)); | ||||
$new_tags = $request->getArr('mailtags'); | $new_tags = $request->getArr('mailtags'); | ||||
$mailtags = $preferences->getPreference('mailtags', array()); | $mailtags = $preferences->getPreference('mailtags', array()); | ||||
$all_tags = $this->getAllTags($user); | $all_tags = $this->getAllTags($user); | ||||
foreach ($all_tags as $key => $label) { | foreach ($all_tags as $key => $label) { | ||||
$mailtags[$key] = (bool)idx($new_tags, $key, false); | $mailtags[$key] = (int)idx($new_tags, $key, $value_email); | ||||
} | } | ||||
$preferences->setPreference('mailtags', $mailtags); | $preferences->setPreference('mailtags', $mailtags); | ||||
$preferences->save(); | $preferences->save(); | ||||
return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
->setURI($this->getPanelURI('?saved=true')); | ->setURI($this->getPanelURI('?saved=true')); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public function processRequest(AphrontRequest $request) { | ||||
$mailtags = $preferences->getPreference('mailtags', array()); | $mailtags = $preferences->getPreference('mailtags', array()); | ||||
$form->appendChild( | $form->appendChild( | ||||
id(new PHUIFormDividerControl())); | id(new PHUIFormDividerControl())); | ||||
$form->appendRemarkupInstructions( | $form->appendRemarkupInstructions( | ||||
pht( | pht( | ||||
'You can customize which kinds of events you receive email for '. | 'You can adjust **Application Settings** here to customize when '. | ||||
'here. If you turn off email for a certain type of event, you '. | 'you are emailed and notified.'. | ||||
'will receive an unread notification in Phabricator instead.'. | |||||
"\n\n". | "\n\n". | ||||
'Phabricator notifications (shown in the menu bar) which you receive '. | "| Setting | Effect\n". | ||||
'an email for are marked read by default in Phabricator. If you turn '. | "| ------- | -------\n". | ||||
'off email for a certain type of event, the corresponding '. | "| Email | You will receive an email and a notification, but the ". | ||||
'notification will not be marked read.'. | "notification will be marked \"read\".\n". | ||||
"| Notify | You will receive an unread notification only.\n". | |||||
"| Ignore | You will receive nothing.\n". | |||||
"\n\n". | "\n\n". | ||||
'Note that if an update makes several changes (like adding CCs to a '. | 'If an update makes several changes (like adding CCs to a task, '. | ||||
'task, closing it, and adding a comment) you will still receive '. | 'closing it, and adding a comment) you will receive the strongest '. | ||||
'an email as long as at least one of the changes is set to notify '. | 'notification any of the changes is configured to deliver.'. | ||||
'you.'. | |||||
"\n\n". | "\n\n". | ||||
'These preferences **only** apply to objects you are connected to '. | 'These preferences **only** apply to objects you are connected to '. | ||||
'(for example, Revisions where you are a reviewer or tasks you are '. | '(for example, Revisions where you are a reviewer or tasks you are '. | ||||
'CC\'d on). To receive email alerts when other objects are created, '. | 'CC\'d on). To receive email alerts when other objects are created, '. | ||||
'configure [[ /herald/ | Herald Rules ]].'. | 'configure [[ /herald/ | Herald Rules ]].')); | ||||
"\n\n". | |||||
'Phabricator will send an email to your primary account when:')); | |||||
$editors = $this->getAllEditorsWithTags($user); | $editors = $this->getAllEditorsWithTags($user); | ||||
// Find all the tags shared by more than one application, and put them | // Find all the tags shared by more than one application, and put them | ||||
// in a "common" group. | // in a "common" group. | ||||
$all_tags = array(); | $all_tags = array(); | ||||
foreach ($editors as $editor) { | foreach ($editors as $editor) { | ||||
foreach ($editor->getMailTagsMap() as $tag => $name) { | foreach ($editor->getMailTagsMap() as $tag => $name) { | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | private function getAllTags(PhabricatorUser $user) { | ||||
return $tags; | return $tags; | ||||
} | } | ||||
private function buildMailTagControl( | private function buildMailTagControl( | ||||
$control_label, | $control_label, | ||||
array $tags, | array $tags, | ||||
array $prefs) { | array $prefs) { | ||||
$control = new AphrontFormCheckboxControl(); | $value_email = PhabricatorUserPreferences::MAILTAG_PREFERENCE_EMAIL; | ||||
$control->setLabel($control_label); | $value_notify = PhabricatorUserPreferences::MAILTAG_PREFERENCE_NOTIFY; | ||||
$value_ignore = PhabricatorUserPreferences::MAILTAG_PREFERENCE_IGNORE; | |||||
$content = array(); | |||||
foreach ($tags as $key => $label) { | foreach ($tags as $key => $label) { | ||||
$control->addCheckbox( | $select = AphrontFormSelectControl::renderSelectTag( | ||||
'mailtags['.$key.']', | (int)idx($prefs, $key, $value_email), | ||||
1, | array( | ||||
$value_email => pht("\xE2\x9A\xAB Email"), | |||||
$value_notify => pht("\xE2\x97\x90 Notify"), | |||||
$value_ignore => pht("\xE2\x9A\xAA Ignore"), | |||||
), | |||||
array( | |||||
'name' => 'mailtags['.$key.']', | |||||
)); | |||||
$content[] = phutil_tag( | |||||
'div', | |||||
array( | |||||
'class' => 'psb', | |||||
), | |||||
array( | |||||
$select, | |||||
' ', | |||||
$label, | $label, | ||||
idx($prefs, $key, 1)); | )); | ||||
} | } | ||||
$control = new AphrontFormStaticControl(); | |||||
$control->setLabel($control_label); | |||||
$control->setValue($content); | |||||
return $control; | return $control; | ||||
} | } | ||||
} | } |