Signed-off-by: Joas Schilling <coding@schilljs.com>tags/v11.0RC2
@@ -0,0 +1,123 @@ | |||
<?php | |||
/** | |||
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OC\Activity; | |||
use OCP\Activity\ISetting; | |||
class LegacySetting implements ISetting { | |||
/** @var string */ | |||
protected $identifier; | |||
/** @var string */ | |||
protected $name; | |||
/** @var bool */ | |||
protected $canChangeStream; | |||
/** @var bool */ | |||
protected $isDefaultEnabledStream; | |||
/** @var bool */ | |||
protected $canChangeMail; | |||
/** @var bool */ | |||
protected $isDefaultEnabledMail; | |||
/** | |||
* LegacySetting constructor. | |||
* | |||
* @param string $identifier | |||
* @param string $name | |||
* @param bool $canChangeStream | |||
* @param bool $isDefaultEnabledStream | |||
* @param bool $canChangeMail | |||
* @param bool $isDefaultEnabledMail | |||
*/ | |||
public function __construct($identifier, | |||
$name, | |||
$canChangeStream, | |||
$isDefaultEnabledStream, | |||
$canChangeMail, | |||
$isDefaultEnabledMail) { | |||
$this->identifier = $identifier; | |||
$this->name = $name; | |||
$this->canChangeStream = $canChangeStream; | |||
$this->isDefaultEnabledStream = $isDefaultEnabledStream; | |||
$this->canChangeMail = $canChangeMail; | |||
$this->isDefaultEnabledMail = $isDefaultEnabledMail; | |||
} | |||
/** | |||
* @return string Lowercase a-z and underscore only identifier | |||
* @since 9.2.0 | |||
*/ | |||
public function getIdentifier() { | |||
return $this->identifier; | |||
} | |||
/** | |||
* @return string A translated string | |||
* @since 9.2.0 | |||
*/ | |||
public function getName() { | |||
return $this->name; | |||
} | |||
/** | |||
* @return int whether the filter should be rather on the top or bottom of | |||
* the admin section. The filters are arranged in ascending order of the | |||
* priority values. It is required to return a value between 0 and 100. | |||
* @since 9.2.0 | |||
*/ | |||
public function getPriority() { | |||
return 70; | |||
} | |||
/** | |||
* @return bool True when the option can be changed for the stream | |||
* @since 9.2.0 | |||
*/ | |||
public function canChangeStream() { | |||
return $this->canChangeStream; | |||
} | |||
/** | |||
* @return bool True when the option can be changed for the stream | |||
* @since 9.2.0 | |||
*/ | |||
public function isDefaultEnabledStream() { | |||
return $this->isDefaultEnabledStream; | |||
} | |||
/** | |||
* @return bool True when the option can be changed for the mail | |||
* @since 9.2.0 | |||
*/ | |||
public function canChangeMail() { | |||
return $this->canChangeMail; | |||
} | |||
/** | |||
* @return bool True when the option can be changed for the stream | |||
* @since 9.2.0 | |||
*/ | |||
public function isDefaultEnabledMail() { | |||
return $this->isDefaultEnabledMail; | |||
} | |||
} | |||
@@ -29,6 +29,7 @@ use OCP\Activity\IEvent; | |||
use OCP\Activity\IExtension; | |||
use OCP\Activity\IFilter; | |||
use OCP\Activity\IManager; | |||
use OCP\Activity\ISetting; | |||
use OCP\IConfig; | |||
use OCP\IRequest; | |||
use OCP\IUser; | |||
@@ -246,7 +247,7 @@ class Manager implements IManager { | |||
$this->extensions = []; | |||
} | |||
/** @var IFilter[] */ | |||
/** @var string[] */ | |||
protected $filterClasses; | |||
/** @var IFilter[] */ | |||
@@ -316,49 +317,82 @@ class Manager implements IManager { | |||
throw new \InvalidArgumentException('Requested filter does not exist'); | |||
} | |||
/** @var string[] */ | |||
protected $settingsClasses; | |||
/** @var ISetting[] */ | |||
protected $settings; | |||
/** @var bool */ | |||
protected $loadedLegacyTypes = false; | |||
/** | |||
* Will return additional notification types as specified by other apps | |||
* | |||
* @param string $languageCode | |||
* @return array | |||
* @param string $setting Class must implement OCA\Activity\ISetting | |||
* @return void | |||
*/ | |||
public function getNotificationTypes($languageCode) { | |||
$filesNotificationTypes = []; | |||
$sharingNotificationTypes = []; | |||
public function registerSetting($setting) { | |||
$this->settingsClasses[$setting] = false; | |||
} | |||
$notificationTypes = array(); | |||
foreach ($this->getExtensions() as $c) { | |||
$result = $c->getNotificationTypes($languageCode); | |||
if (is_array($result)) { | |||
if (class_exists('\OCA\Files\Activity', false) && $c instanceof \OCA\Files\Activity) { | |||
$filesNotificationTypes = $result; | |||
continue; | |||
} | |||
if (class_exists('\OCA\Files_Sharing\Activity', false) && $c instanceof \OCA\Files_Sharing\Activity) { | |||
$sharingNotificationTypes = $result; | |||
continue; | |||
/** | |||
* @return ISetting[] | |||
* @throws \InvalidArgumentException | |||
*/ | |||
public function getSettings() { | |||
if (!$this->loadedLegacyTypes) { | |||
$l = \OC::$server->getL10N('core'); | |||
$legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); | |||
$streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); | |||
$mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); | |||
foreach ($legacyTypes as $type => $data) { | |||
if (is_string($data)) { | |||
$desc = $data; | |||
$canChangeStream = true; | |||
$canChangeMail = true; | |||
} else { | |||
$desc = $data['desc']; | |||
$canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); | |||
$canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); | |||
} | |||
$notificationTypes = array_merge($notificationTypes, $result); | |||
$this->settings[$type] = new LegacySetting( | |||
$type, $desc, | |||
$canChangeStream, in_array($type, $streamTypes), | |||
$canChangeMail, in_array($type, $mailTypes) | |||
); | |||
} | |||
$this->loadedLegacyTypes = true; | |||
} | |||
return array_merge($filesNotificationTypes, $sharingNotificationTypes, $notificationTypes); | |||
foreach ($this->settingsClasses as $class => $false) { | |||
/** @var ISetting $setting */ | |||
$setting = \OC::$server->query($class); | |||
if (!$setting instanceof ISetting) { | |||
throw new \InvalidArgumentException('Invalid activity filter registered'); | |||
} | |||
$this->settings[$setting->getIdentifier()] = $setting; | |||
unset($this->settingsClasses[$class]); | |||
} | |||
return $this->settings; | |||
} | |||
/** | |||
* @param string $method | |||
* @return array | |||
* @param string $id | |||
* @return ISetting | |||
* @throws \InvalidArgumentException when the setting was not found | |||
* @since 9.2.0 | |||
*/ | |||
public function getDefaultTypes($method) { | |||
$defaultTypes = array(); | |||
foreach ($this->getExtensions() as $c) { | |||
$types = $c->getDefaultTypes($method); | |||
if (is_array($types)) { | |||
$defaultTypes = array_merge($types, $defaultTypes); | |||
} | |||
public function getSettingById($id) { | |||
$settings = $this->getSettings(); | |||
if (isset($settings[$id])) { | |||
return $settings[$id]; | |||
} | |||
return $defaultTypes; | |||
throw new \InvalidArgumentException('Requested setting does not exist'); | |||
} | |||
/** | |||
@@ -606,4 +640,44 @@ class Manager implements IManager { | |||
return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); | |||
} | |||
/** | |||
* Will return additional notification types as specified by other apps | |||
* | |||
* @param string $languageCode | |||
* @return array | |||
* @deprecated 9.2.0 - Use getSettings() instead | |||
*/ | |||
public function getNotificationTypes($languageCode) { | |||
$notificationTypes = $sharingNotificationTypes = []; | |||
foreach ($this->getExtensions() as $c) { | |||
$result = $c->getNotificationTypes($languageCode); | |||
if (is_array($result)) { | |||
if (class_exists('\OCA\Files_Sharing\Activity', false) && $c instanceof \OCA\Files_Sharing\Activity) { | |||
$sharingNotificationTypes = $result; | |||
continue; | |||
} | |||
$notificationTypes = array_merge($notificationTypes, $result); | |||
} | |||
} | |||
return array_merge($sharingNotificationTypes, $notificationTypes); | |||
} | |||
/** | |||
* @param string $method | |||
* @return array | |||
* @deprecated 9.2.0 - Use getSettings()->isDefaulEnabled<method>() instead | |||
*/ | |||
public function getDefaultTypes($method) { | |||
$defaultTypes = array(); | |||
foreach ($this->getExtensions() as $c) { | |||
$types = $c->getDefaultTypes($method); | |||
if (is_array($types)) { | |||
$defaultTypes = array_merge($types, $defaultTypes); | |||
} | |||
} | |||
return $defaultTypes; | |||
} | |||
} |
@@ -116,6 +116,9 @@ class InfoParser { | |||
if (!array_key_exists('filters', $array['activity'])) { | |||
$array['activity']['filters'] = []; | |||
} | |||
if (!array_key_exists('settings', $array['activity'])) { | |||
$array['activity']['settings'] = []; | |||
} | |||
if (array_key_exists('types', $array)) { | |||
if (is_array($array['types'])) { | |||
@@ -153,6 +156,9 @@ class InfoParser { | |||
if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { | |||
$array['activity']['filters'] = $array['activity']['filters']['filter']; | |||
} | |||
if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { | |||
$array['activity']['settings'] = $array['activity']['settings']['setting']; | |||
} | |||
if(!is_null($this->cache)) { | |||
$this->cache->set($fileCacheKey, json_encode($array)); |
@@ -169,6 +169,11 @@ class OC_App { | |||
\OC::$server->getActivityManager()->registerFilter($filter); | |||
} | |||
} | |||
if (!empty($info['activity']['settings'])) { | |||
foreach ($info['activity']['settings'] as $setting) { | |||
\OC::$server->getActivityManager()->registerSetting($setting); | |||
} | |||
} | |||
} | |||
/** |
@@ -131,6 +131,27 @@ interface IManager { | |||
*/ | |||
public function getFilterById($id); | |||
/** | |||
* @param string $setting Class must implement OCA\Activity\ISetting | |||
* @return void | |||
* @since 9.2.0 | |||
*/ | |||
public function registerSetting($setting); | |||
/** | |||
* @return ISetting[] | |||
* @since 9.2.0 | |||
*/ | |||
public function getSettings(); | |||
/** | |||
* @param string $id | |||
* @return ISetting | |||
* @throws \InvalidArgumentException when the setting was not found | |||
* @since 9.2.0 | |||
*/ | |||
public function getSettingById($id); | |||
/** | |||
* Will return additional notification types as specified by other apps | |||
* | |||
@@ -141,6 +162,7 @@ interface IManager { | |||
* 'methods' => [\OCP\Activity\IExtension::METHOD_*], | |||
* ] | |||
* @since 8.0.0 - 8.2.0: Added support to allow limiting notifications to certain methods | |||
* @deprecated 9.2.0 - Use getSettings() instead | |||
*/ | |||
public function getNotificationTypes($languageCode); | |||
@@ -148,6 +170,7 @@ interface IManager { | |||
* @param string $method | |||
* @return array | |||
* @since 8.0.0 | |||
* @deprecated 9.2.0 - Use getSettings()->isDefaulEnabled<method>() instead | |||
*/ | |||
public function getDefaultTypes($method); | |||
@@ -0,0 +1,76 @@ | |||
<?php | |||
/** | |||
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OCP\Activity; | |||
/** | |||
* Interface ISetting | |||
* | |||
* @package OCP\Activity | |||
* @since 9.2.0 | |||
*/ | |||
interface ISetting { | |||
/** | |||
* @return string Lowercase a-z and underscore only identifier | |||
* @since 9.2.0 | |||
*/ | |||
public function getIdentifier(); | |||
/** | |||
* @return string A translated string | |||
* @since 9.2.0 | |||
*/ | |||
public function getName(); | |||
/** | |||
* @return int whether the filter should be rather on the top or bottom of | |||
* the admin section. The filters are arranged in ascending order of the | |||
* priority values. It is required to return a value between 0 and 100. | |||
* @since 9.2.0 | |||
*/ | |||
public function getPriority(); | |||
/** | |||
* @return bool True when the option can be changed for the stream | |||
* @since 9.2.0 | |||
*/ | |||
public function canChangeStream(); | |||
/** | |||
* @return bool True when the option can be changed for the stream | |||
* @since 9.2.0 | |||
*/ | |||
public function isDefaultEnabledStream(); | |||
/** | |||
* @return bool True when the option can be changed for the mail | |||
* @since 9.2.0 | |||
*/ | |||
public function canChangeMail(); | |||
/** | |||
* @return bool True when the option can be changed for the stream | |||
* @since 9.2.0 | |||
*/ | |||
public function isDefaultEnabledMail(); | |||
} | |||