mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Add some basic sound preferences
Summary: Ref T7567. This adds some constants (for adding new sounds), global setting for turning on and off sound (setting) and per thread preference for sound choice. Also specc'd out Mentions, if added. Test Plan: I tested all the preference wiring, but need to set up notifications locally to verify if this works. Feel free to test. Reviewers: epriestley Reviewed By: epriestley Subscribers: amckinley, Korvin Maniphest Tasks: T7567 Differential Revision: https://secure.phabricator.com/D17726
This commit is contained in:
parent
305966e748
commit
8e813f4f1f
4 changed files with 188 additions and 16 deletions
|
@ -311,6 +311,7 @@ phutil_register_library_map(array(
|
|||
'ConpherenceReplyHandler' => 'applications/conpherence/mail/ConpherenceReplyHandler.php',
|
||||
'ConpherenceRoomListController' => 'applications/conpherence/controller/ConpherenceRoomListController.php',
|
||||
'ConpherenceRoomPictureController' => 'applications/conpherence/controller/ConpherenceRoomPictureController.php',
|
||||
'ConpherenceRoomSettings' => 'applications/conpherence/constants/ConpherenceRoomSettings.php',
|
||||
'ConpherenceRoomTestCase' => 'applications/conpherence/__tests__/ConpherenceRoomTestCase.php',
|
||||
'ConpherenceSchemaSpec' => 'applications/conpherence/storage/ConpherenceSchemaSpec.php',
|
||||
'ConpherenceTestCase' => 'applications/conpherence/__tests__/ConpherenceTestCase.php',
|
||||
|
@ -2398,6 +2399,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorConpherenceNotificationsSetting' => 'applications/settings/setting/PhabricatorConpherenceNotificationsSetting.php',
|
||||
'PhabricatorConpherencePreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorConpherencePreferencesSettingsPanel.php',
|
||||
'PhabricatorConpherenceProfileMenuItem' => 'applications/search/menuitem/PhabricatorConpherenceProfileMenuItem.php',
|
||||
'PhabricatorConpherenceSoundSetting' => 'applications/settings/setting/PhabricatorConpherenceSoundSetting.php',
|
||||
'PhabricatorConpherenceThreadPHIDType' => 'applications/conpherence/phid/PhabricatorConpherenceThreadPHIDType.php',
|
||||
'PhabricatorConpherenceWidgetVisibleSetting' => 'applications/settings/setting/PhabricatorConpherenceWidgetVisibleSetting.php',
|
||||
'PhabricatorConsoleApplication' => 'applications/console/application/PhabricatorConsoleApplication.php',
|
||||
|
@ -5103,6 +5105,7 @@ phutil_register_library_map(array(
|
|||
'ConpherenceReplyHandler' => 'PhabricatorMailReplyHandler',
|
||||
'ConpherenceRoomListController' => 'ConpherenceController',
|
||||
'ConpherenceRoomPictureController' => 'ConpherenceController',
|
||||
'ConpherenceRoomSettings' => 'ConpherenceConstants',
|
||||
'ConpherenceRoomTestCase' => 'ConpherenceTestCase',
|
||||
'ConpherenceSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||
'ConpherenceTestCase' => 'PhabricatorTestCase',
|
||||
|
@ -7505,6 +7508,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorConpherenceNotificationsSetting' => 'PhabricatorSelectSetting',
|
||||
'PhabricatorConpherencePreferencesSettingsPanel' => 'PhabricatorEditEngineSettingsPanel',
|
||||
'PhabricatorConpherenceProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
||||
'PhabricatorConpherenceSoundSetting' => 'PhabricatorSelectSetting',
|
||||
'PhabricatorConpherenceThreadPHIDType' => 'PhabricatorPHIDType',
|
||||
'PhabricatorConpherenceWidgetVisibleSetting' => 'PhabricatorInternalSetting',
|
||||
'PhabricatorConsoleApplication' => 'PhabricatorApplication',
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
final class ConpherenceRoomSettings extends ConpherenceConstants {
|
||||
|
||||
const SOUND_RECEIVE = 'receive';
|
||||
const SOUND_MENTION = 'mention';
|
||||
|
||||
const DEFAULT_RECEIVE_SOUND = 'tap';
|
||||
const DEFAULT_MENTION_SOUND = 'tap'; // Upload a new sound
|
||||
const DEFAULT_NO_SOUND = 'none';
|
||||
|
||||
public static function getSoundMap() {
|
||||
return array(
|
||||
'none' => array(
|
||||
'name' => pht('No Sound'),
|
||||
'rsrc' => '',
|
||||
),
|
||||
'tap' => array(
|
||||
'name' => pht('Tap'),
|
||||
'rsrc' => celerity_get_resource_uri('/rsrc/audio/basic/tap.mp3'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public static function getDropdownSoundMap() {
|
||||
$map = self::getSoundMap();
|
||||
return ipull($map, 'name');
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -115,11 +115,13 @@ final class ConpherenceUpdateController
|
|||
break;
|
||||
case ConpherenceUpdateActions::NOTIFICATIONS:
|
||||
$notifications = $request->getStr('notifications');
|
||||
$sounds = $request->getArr('sounds');
|
||||
$participant = $conpherence->getParticipantIfExists($user->getPHID());
|
||||
if (!$participant) {
|
||||
return id(new Aphront404Response());
|
||||
}
|
||||
$participant->setSettings(array('notifications' => $notifications));
|
||||
$participant->setSettings(array('sounds' => $sounds));
|
||||
$participant->save();
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI('/'.$conpherence->getMonogram());
|
||||
|
@ -266,29 +268,53 @@ final class ConpherenceUpdateController
|
|||
$notification_key = PhabricatorConpherenceNotificationsSetting::SETTINGKEY;
|
||||
$notification_default = $user->getUserSetting($notification_key);
|
||||
|
||||
$sound_key = PhabricatorConpherenceSoundSetting::SETTINGKEY;
|
||||
$sound_default = $user->getUserSetting($sound_key);
|
||||
|
||||
$settings = $participant->getSettings();
|
||||
$notifications = idx(
|
||||
$settings,
|
||||
'notifications',
|
||||
$notification_default);
|
||||
$notifications = idx($settings, 'notifications', $notification_default);
|
||||
|
||||
$sounds = idx($settings, 'sounds', array());
|
||||
$map = PhabricatorConpherenceSoundSetting::getDefaultSound($sound_default);
|
||||
$receive = idx($sounds,
|
||||
ConpherenceRoomSettings::SOUND_RECEIVE,
|
||||
$map[ConpherenceRoomSettings::SOUND_RECEIVE]);
|
||||
$mention = idx($sounds,
|
||||
ConpherenceRoomSettings::SOUND_MENTION,
|
||||
$map[ConpherenceRoomSettings::SOUND_MENTION]);
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($user)
|
||||
->setFullWidth(true)
|
||||
->appendControl(
|
||||
id(new AphrontFormRadioButtonControl())
|
||||
->addButton(
|
||||
id(new AphrontFormRadioButtonControl())
|
||||
->setLabel(pht('Notify'))
|
||||
->addButton(
|
||||
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_EMAIL,
|
||||
PhabricatorConpherenceNotificationsSetting::getSettingLabel(
|
||||
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_EMAIL),
|
||||
'')
|
||||
->addButton(
|
||||
'')
|
||||
->addButton(
|
||||
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_NOTIFY,
|
||||
PhabricatorConpherenceNotificationsSetting::getSettingLabel(
|
||||
PhabricatorConpherenceNotificationsSetting::VALUE_CONPHERENCE_NOTIFY),
|
||||
'')
|
||||
->setName('notifications')
|
||||
->setValue($notifications));
|
||||
'')
|
||||
->setName('notifications')
|
||||
->setValue($notifications))
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel(pht('Message Received'))
|
||||
->setName('sounds['.ConpherenceRoomSettings::SOUND_RECEIVE.']')
|
||||
->setOptions(ConpherenceRoomSettings::getDropdownSoundMap())
|
||||
->setValue($receive));
|
||||
|
||||
// TODO: Future Adventure! Expansion Pack
|
||||
//
|
||||
// ->appendChild(
|
||||
// id(new AphrontFormSelectControl())
|
||||
// ->setLabel(pht('Username Mentioned'))
|
||||
// ->setName('sounds['.ConpherenceRoomSettings::SOUND_MENTION.']')
|
||||
// ->setOptions(ConpherenceRoomSettings::getDropdownSoundMap())
|
||||
// ->setValue($mention));
|
||||
|
||||
return id(new AphrontDialogView())
|
||||
->setTitle(pht('Room Preferences'))
|
||||
|
@ -496,6 +522,8 @@ final class ConpherenceUpdateController
|
|||
->executeOne();
|
||||
|
||||
$non_update = false;
|
||||
$participant = $conpherence->getParticipant($user->getPHID());
|
||||
|
||||
if ($need_transactions && $conpherence->getTransactions()) {
|
||||
$data = ConpherenceTransactionRenderer::renderTransactions(
|
||||
$user,
|
||||
|
@ -503,9 +531,7 @@ final class ConpherenceUpdateController
|
|||
$key = PhabricatorConpherenceColumnMinimizeSetting::SETTINGKEY;
|
||||
$minimized = $user->getUserSetting($key);
|
||||
if (!$minimized) {
|
||||
$participant_obj = $conpherence->getParticipant($user->getPHID());
|
||||
$participant_obj
|
||||
->markUpToDate($conpherence, $data['latest_transaction']);
|
||||
$participant->markUpToDate($conpherence, $data['latest_transaction']);
|
||||
}
|
||||
} else if ($need_transactions) {
|
||||
$non_update = true;
|
||||
|
@ -547,7 +573,9 @@ final class ConpherenceUpdateController
|
|||
->setViewer($user);
|
||||
$dropdown_query->execute();
|
||||
|
||||
$receive_sound = celerity_get_resource_uri('/rsrc/audio/basic/tap.mp3');
|
||||
$sounds = $this->getSoundForParticipant($user, $participant);
|
||||
$receive_sound = $sounds[ConpherenceRoomSettings::SOUND_RECEIVE];
|
||||
$mention_sound = $sounds[ConpherenceRoomSettings::SOUND_MENTION];
|
||||
|
||||
$content = array(
|
||||
'non_update' => $non_update,
|
||||
|
@ -564,10 +592,38 @@ final class ConpherenceUpdateController
|
|||
),
|
||||
'sound' => array(
|
||||
'receive' => $receive_sound,
|
||||
'mention' => $mention_sound,
|
||||
),
|
||||
);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function getSoundForParticipant(
|
||||
PhabricatorUser $user,
|
||||
ConpherenceParticipant $participant) {
|
||||
|
||||
$sound_key = PhabricatorConpherenceSoundSetting::SETTINGKEY;
|
||||
$sound_default = $user->getUserSetting($sound_key);
|
||||
|
||||
$settings = $participant->getSettings();
|
||||
$sounds = idx($settings, 'sounds', array());
|
||||
$map = PhabricatorConpherenceSoundSetting::getDefaultSound($sound_default);
|
||||
|
||||
$receive = idx($sounds,
|
||||
ConpherenceRoomSettings::SOUND_RECEIVE,
|
||||
$map[ConpherenceRoomSettings::SOUND_RECEIVE]);
|
||||
$mention = idx($sounds,
|
||||
ConpherenceRoomSettings::SOUND_MENTION,
|
||||
$map[ConpherenceRoomSettings::SOUND_MENTION]);
|
||||
|
||||
$sound_map = ConpherenceRoomSettings::getSoundMap();
|
||||
|
||||
return array(
|
||||
ConpherenceRoomSettings::SOUND_RECEIVE => $sound_map[$receive]['rsrc'],
|
||||
ConpherenceRoomSettings::SOUND_MENTION => $sound_map[$mention]['rsrc'],
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorConpherenceSoundSetting
|
||||
extends PhabricatorSelectSetting {
|
||||
|
||||
const SETTINGKEY = 'conpherence-sound';
|
||||
|
||||
const VALUE_CONPHERENCE_SILENT = '0';
|
||||
const VALUE_CONPHERENCE_MENTION = '1';
|
||||
const VALUE_CONPHERENCE_ALL = '2';
|
||||
|
||||
public function getSettingName() {
|
||||
return pht('Conpherence Sound');
|
||||
}
|
||||
|
||||
public function getSettingPanelKey() {
|
||||
return PhabricatorConpherencePreferencesSettingsPanel::PANELKEY;
|
||||
}
|
||||
|
||||
protected function getControlInstructions() {
|
||||
return pht(
|
||||
'Choose the default sound behavior for new Conpherence rooms.');
|
||||
}
|
||||
|
||||
protected function isEnabledForViewer(PhabricatorUser $viewer) {
|
||||
return PhabricatorApplication::isClassInstalledForViewer(
|
||||
'PhabricatorConpherenceApplication',
|
||||
$viewer);
|
||||
}
|
||||
|
||||
public function getSettingDefaultValue() {
|
||||
return self::VALUE_CONPHERENCE_ALL;
|
||||
}
|
||||
|
||||
protected function getSelectOptions() {
|
||||
return self::getOptionsMap();
|
||||
}
|
||||
|
||||
public static function getSettingLabel($key) {
|
||||
$labels = self::getOptionsMap();
|
||||
return idx($labels, $key, pht('Unknown ("%s")', $key));
|
||||
}
|
||||
|
||||
public static function getDefaultSound($value) {
|
||||
switch ($value) {
|
||||
case self::VALUE_CONPHERENCE_ALL:
|
||||
return array(
|
||||
ConpherenceRoomSettings::SOUND_RECEIVE =>
|
||||
ConpherenceRoomSettings::DEFAULT_RECEIVE_SOUND,
|
||||
ConpherenceRoomSettings::SOUND_MENTION =>
|
||||
ConpherenceRoomSettings::DEFAULT_MENTION_SOUND,
|
||||
);
|
||||
break;
|
||||
case self::VALUE_CONPHERENCE_MENTION:
|
||||
return array(
|
||||
ConpherenceRoomSettings::SOUND_RECEIVE =>
|
||||
ConpherenceRoomSettings::DEFAULT_NO_SOUND,
|
||||
ConpherenceRoomSettings::SOUND_MENTION =>
|
||||
ConpherenceRoomSettings::DEFAULT_MENTION_SOUND,
|
||||
);
|
||||
break;
|
||||
case self::VALUE_CONPHERENCE_SILENT:
|
||||
return array(
|
||||
ConpherenceRoomSettings::SOUND_RECEIVE =>
|
||||
ConpherenceRoomSettings::DEFAULT_NO_SOUND,
|
||||
ConpherenceRoomSettings::SOUND_MENTION =>
|
||||
ConpherenceRoomSettings::DEFAULT_NO_SOUND,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static function getOptionsMap() {
|
||||
return array(
|
||||
self::VALUE_CONPHERENCE_SILENT => pht('No Sounds'),
|
||||
// self::VALUE_CONPHERENCE_MENTION => pht('Mentions Only'),
|
||||
self::VALUE_CONPHERENCE_ALL => pht('All Messages'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue