Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion lib/UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function getUserSetting($user, $method, $type) {
}

$defaultSetting = $this->getDefaultFromSetting($method, $type);
if (!$this->canModifySetting($method, $type)) {
return $defaultSetting;
}

if (is_bool($defaultSetting)) {
return (bool) $this->config->getUserValue(
$user,
Expand Down Expand Up @@ -149,12 +153,39 @@ protected function getDefaultFromSetting($method, $type) {
}
}

/**
* Get a good default setting for a preference
*
* @param string $method Should be one of 'stream', 'email' or 'setting'
* @param string $type One of the activity types, 'batchtime', 'self' or 'selfemail'
* @return bool
*/
protected function canModifySetting($method, $type) {
if ($method === 'setting') {
return true;
}

try {
$setting = $this->manager->getSettingById($type);
switch ($method) {
case 'email':
return $setting->canChangeMail();
case 'notification':
return $setting->canChangeNotification();
default:
return false;
}
} catch (\InvalidArgumentException $e) {
return false;
}
}

/**
* Get a list with all notification types
*/
public function getNotificationTypes() {
$settings = $this->manager->getSettings();

$return = array_map(function (ActivitySettings $setting) {
return $setting->getIdentifier();
}, $settings);
Expand Down