Merge pull request #13798 from nextcloud/remove-legacy-activity-stuff
Remove legacy activity stuff
This commit is contained in:
commit
f746d36a4a
|
@ -407,8 +407,6 @@ return array(
|
|||
'OC\\Accounts\\Hooks' => $baseDir . '/lib/private/Accounts/Hooks.php',
|
||||
'OC\\Activity\\Event' => $baseDir . '/lib/private/Activity/Event.php',
|
||||
'OC\\Activity\\EventMerger' => $baseDir . '/lib/private/Activity/EventMerger.php',
|
||||
'OC\\Activity\\LegacyFilter' => $baseDir . '/lib/private/Activity/LegacyFilter.php',
|
||||
'OC\\Activity\\LegacySetting' => $baseDir . '/lib/private/Activity/LegacySetting.php',
|
||||
'OC\\Activity\\Manager' => $baseDir . '/lib/private/Activity/Manager.php',
|
||||
'OC\\AllConfig' => $baseDir . '/lib/private/AllConfig.php',
|
||||
'OC\\AppConfig' => $baseDir . '/lib/private/AppConfig.php',
|
||||
|
|
|
@ -437,8 +437,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
|||
'OC\\Accounts\\Hooks' => __DIR__ . '/../../..' . '/lib/private/Accounts/Hooks.php',
|
||||
'OC\\Activity\\Event' => __DIR__ . '/../../..' . '/lib/private/Activity/Event.php',
|
||||
'OC\\Activity\\EventMerger' => __DIR__ . '/../../..' . '/lib/private/Activity/EventMerger.php',
|
||||
'OC\\Activity\\LegacyFilter' => __DIR__ . '/../../..' . '/lib/private/Activity/LegacyFilter.php',
|
||||
'OC\\Activity\\LegacySetting' => __DIR__ . '/../../..' . '/lib/private/Activity/LegacySetting.php',
|
||||
'OC\\Activity\\Manager' => __DIR__ . '/../../..' . '/lib/private/Activity/Manager.php',
|
||||
'OC\\AllConfig' => __DIR__ . '/../../..' . '/lib/private/AllConfig.php',
|
||||
'OC\\AppConfig' => __DIR__ . '/../../..' . '/lib/private/AppConfig.php',
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author 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\IFilter;
|
||||
use OCP\Activity\IManager;
|
||||
|
||||
class LegacyFilter implements IFilter {
|
||||
|
||||
/** @var IManager */
|
||||
protected $manager;
|
||||
/** @var string */
|
||||
protected $identifier;
|
||||
/** @var string */
|
||||
protected $name;
|
||||
/** @var bool */
|
||||
protected $isTopFilter;
|
||||
|
||||
/**
|
||||
* LegacySetting constructor.
|
||||
*
|
||||
* @param IManager $manager
|
||||
* @param string $identifier
|
||||
* @param string $name
|
||||
* @param bool $isTopFilter
|
||||
*/
|
||||
public function __construct(IManager $manager,
|
||||
$identifier,
|
||||
$name,
|
||||
$isTopFilter) {
|
||||
$this->manager = $manager;
|
||||
$this->identifier = $identifier;
|
||||
$this->name = $name;
|
||||
$this->isTopFilter = $isTopFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Lowercase a-z and underscore only identifier
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getIdentifier() {
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string A translated string
|
||||
* @since 11.0.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 11.0.0
|
||||
*/
|
||||
public function getPriority() {
|
||||
return $this->isTopFilter ? 40 : 50;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Full URL to an icon, empty string when none is given
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getIcon() {
|
||||
// Old API was CSS class, so we can not use this...
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $types
|
||||
* @return string[] An array of allowed apps from which activities should be displayed
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function filterTypes(array $types) {
|
||||
return $this->manager->filterNotificationTypes($types, $this->getIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] An array of allowed apps from which activities should be displayed
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function allowedApps() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author 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 11.0.0
|
||||
*/
|
||||
public function getIdentifier() {
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string A translated string
|
||||
* @since 11.0.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 11.0.0
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 70;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool True when the option can be changed for the stream
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function canChangeStream() {
|
||||
return $this->canChangeStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool True when the option can be changed for the stream
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function isDefaultEnabledStream() {
|
||||
return $this->isDefaultEnabledStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool True when the option can be changed for the mail
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function canChangeMail() {
|
||||
return $this->canChangeMail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool True when the option can be changed for the stream
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function isDefaultEnabledMail() {
|
||||
return $this->isDefaultEnabledMail;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,6 @@ namespace OC\Activity;
|
|||
|
||||
use OCP\Activity\IConsumer;
|
||||
use OCP\Activity\IEvent;
|
||||
use OCP\Activity\IExtension;
|
||||
use OCP\Activity\IFilter;
|
||||
use OCP\Activity\IManager;
|
||||
use OCP\Activity\IProvider;
|
||||
|
@ -64,14 +63,6 @@ class Manager implements IManager {
|
|||
/** @var string */
|
||||
protected $currentUserId;
|
||||
|
||||
/**
|
||||
* constructor of the controller
|
||||
*
|
||||
* @param IRequest $request
|
||||
* @param IUserSession $session
|
||||
* @param IConfig $config
|
||||
* @param IValidator $validator
|
||||
*/
|
||||
public function __construct(IRequest $request,
|
||||
IUserSession $session,
|
||||
IConfig $config,
|
||||
|
@ -88,29 +79,10 @@ class Manager implements IManager {
|
|||
/** @var IConsumer[] */
|
||||
private $consumers = array();
|
||||
|
||||
/** @var \Closure[] */
|
||||
private $extensionsClosures = array();
|
||||
|
||||
/** @var IExtension[] */
|
||||
private $extensions = array();
|
||||
|
||||
/** @var array list of filters "name" => "is valid" */
|
||||
protected $validFilters = array(
|
||||
'all' => true,
|
||||
'by' => true,
|
||||
'self' => true,
|
||||
);
|
||||
|
||||
/** @var array list of type icons "type" => "css class" */
|
||||
protected $typeIcons = array();
|
||||
|
||||
/** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */
|
||||
protected $specialParameters = array();
|
||||
|
||||
/**
|
||||
* @return \OCP\Activity\IConsumer[]
|
||||
*/
|
||||
protected function getConsumers() {
|
||||
protected function getConsumers(): array {
|
||||
if (!empty($this->consumers)) {
|
||||
return $this->consumers;
|
||||
}
|
||||
|
@ -128,27 +100,6 @@ class Manager implements IManager {
|
|||
return $this->consumers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \OCP\Activity\IExtension[]
|
||||
*/
|
||||
protected function getExtensions() {
|
||||
if (!empty($this->extensions)) {
|
||||
return $this->extensions;
|
||||
}
|
||||
|
||||
$this->extensions = [];
|
||||
foreach($this->extensionsClosures as $extension) {
|
||||
$e = $extension();
|
||||
if ($e instanceof IExtension) {
|
||||
$this->extensions[] = $e;
|
||||
} else {
|
||||
throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new IEvent object
|
||||
*
|
||||
|
@ -161,7 +112,7 @@ class Manager implements IManager {
|
|||
*
|
||||
* @return IEvent
|
||||
*/
|
||||
public function generateEvent() {
|
||||
public function generateEvent(): IEvent {
|
||||
return new Event($this->validator);
|
||||
}
|
||||
|
||||
|
@ -177,7 +128,7 @@ class Manager implements IManager {
|
|||
* @param IEvent $event
|
||||
* @throws \BadMethodCallException if required values have not been set
|
||||
*/
|
||||
public function publish(IEvent $event) {
|
||||
public function publish(IEvent $event): void {
|
||||
if ($event->getAuthor() === '') {
|
||||
if ($this->session->getUser() instanceof IUser) {
|
||||
$event->setAuthor($this->session->getUser()->getUID());
|
||||
|
@ -205,38 +156,22 @@ class Manager implements IManager {
|
|||
*
|
||||
* @param \Closure $callable
|
||||
*/
|
||||
public function registerConsumer(\Closure $callable) {
|
||||
public function registerConsumer(\Closure $callable): void {
|
||||
$this->consumersClosures[] = $callable;
|
||||
$this->consumers = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* In order to improve lazy loading a closure can be registered which will be called in case
|
||||
* activity consumers are actually requested
|
||||
*
|
||||
* $callable has to return an instance of OCA\Activity\IExtension
|
||||
*
|
||||
* @param \Closure $callable
|
||||
*/
|
||||
public function registerExtension(\Closure $callable) {
|
||||
$this->extensionsClosures[] = $callable;
|
||||
$this->extensions = [];
|
||||
}
|
||||
|
||||
/** @var string[] */
|
||||
protected $filterClasses = [];
|
||||
|
||||
/** @var IFilter[] */
|
||||
protected $filters = [];
|
||||
|
||||
/** @var bool */
|
||||
protected $loadedLegacyFilters = false;
|
||||
|
||||
/**
|
||||
* @param string $filter Class must implement OCA\Activity\IFilter
|
||||
* @return void
|
||||
*/
|
||||
public function registerFilter($filter) {
|
||||
public function registerFilter(string $filter): void {
|
||||
$this->filterClasses[$filter] = false;
|
||||
}
|
||||
|
||||
|
@ -244,24 +179,7 @@ class Manager implements IManager {
|
|||
* @return IFilter[]
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getFilters() {
|
||||
if (!$this->loadedLegacyFilters) {
|
||||
$legacyFilters = $this->getNavigation();
|
||||
|
||||
foreach ($legacyFilters['top'] as $filter => $data) {
|
||||
$this->filters[$filter] = new LegacyFilter(
|
||||
$this, $filter, $data['name'], true
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($legacyFilters['apps'] as $filter => $data) {
|
||||
$this->filters[$filter] = new LegacyFilter(
|
||||
$this, $filter, $data['name'], false
|
||||
);
|
||||
}
|
||||
$this->loadedLegacyFilters = true;
|
||||
}
|
||||
|
||||
public function getFilters(): array {
|
||||
foreach ($this->filterClasses as $class => $false) {
|
||||
/** @var IFilter $filter */
|
||||
$filter = \OC::$server->query($class);
|
||||
|
@ -283,7 +201,7 @@ class Manager implements IManager {
|
|||
* @throws \InvalidArgumentException when the filter was not found
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getFilterById($id) {
|
||||
public function getFilterById(string $id): IFilter {
|
||||
$filters = $this->getFilters();
|
||||
|
||||
if (isset($filters[$id])) {
|
||||
|
@ -303,7 +221,7 @@ class Manager implements IManager {
|
|||
* @param string $provider Class must implement OCA\Activity\IProvider
|
||||
* @return void
|
||||
*/
|
||||
public function registerProvider($provider) {
|
||||
public function registerProvider(string $provider): void {
|
||||
$this->providerClasses[$provider] = false;
|
||||
}
|
||||
|
||||
|
@ -311,7 +229,7 @@ class Manager implements IManager {
|
|||
* @return IProvider[]
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getProviders() {
|
||||
public function getProviders(): array {
|
||||
foreach ($this->providerClasses as $class => $false) {
|
||||
/** @var IProvider $provider */
|
||||
$provider = \OC::$server->query($class);
|
||||
|
@ -333,14 +251,11 @@ class Manager implements IManager {
|
|||
/** @var ISetting[] */
|
||||
protected $settings = [];
|
||||
|
||||
/** @var bool */
|
||||
protected $loadedLegacyTypes = false;
|
||||
|
||||
/**
|
||||
* @param string $setting Class must implement OCA\Activity\ISetting
|
||||
* @return void
|
||||
*/
|
||||
public function registerSetting($setting) {
|
||||
public function registerSetting(string $setting): void {
|
||||
$this->settingsClasses[$setting] = false;
|
||||
}
|
||||
|
||||
|
@ -348,32 +263,7 @@ class Manager implements IManager {
|
|||
* @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']);
|
||||
}
|
||||
|
||||
$this->settings[$type] = new LegacySetting(
|
||||
$type, $desc,
|
||||
$canChangeStream, in_array($type, $streamTypes),
|
||||
$canChangeMail, in_array($type, $mailTypes)
|
||||
);
|
||||
}
|
||||
$this->loadedLegacyTypes = true;
|
||||
}
|
||||
|
||||
public function getSettings(): array {
|
||||
foreach ($this->settingsClasses as $class => $false) {
|
||||
/** @var ISetting $setting */
|
||||
$setting = \OC::$server->query($class);
|
||||
|
@ -395,7 +285,7 @@ class Manager implements IManager {
|
|||
* @throws \InvalidArgumentException when the setting was not found
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getSettingById($id) {
|
||||
public function getSettingById(string $id): ISetting {
|
||||
$settings = $this->getSettings();
|
||||
|
||||
if (isset($settings[$id])) {
|
||||
|
@ -405,127 +295,46 @@ class Manager implements IManager {
|
|||
throw new \InvalidArgumentException('Requested setting does not exist');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function getTypeIcon($type) {
|
||||
if (isset($this->typeIcons[$type])) {
|
||||
return $this->typeIcons[$type];
|
||||
}
|
||||
|
||||
foreach ($this->getExtensions() as $c) {
|
||||
$icon = $c->getTypeIcon($type);
|
||||
if (is_string($icon)) {
|
||||
$this->typeIcons[$type] = $icon;
|
||||
return $icon;
|
||||
}
|
||||
}
|
||||
|
||||
$this->typeIcons[$type] = '';
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param int $id
|
||||
*/
|
||||
public function setFormattingObject($type, $id) {
|
||||
public function setFormattingObject(string $type, int $id): void {
|
||||
$this->formattingObjectType = $type;
|
||||
$this->formattingObjectId = (string) $id;
|
||||
$this->formattingObjectId = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isFormattingFilteredObject() {
|
||||
public function isFormattingFilteredObject(): bool {
|
||||
return $this->formattingObjectType !== null && $this->formattingObjectId !== null
|
||||
&& $this->formattingObjectType === $this->request->getParam('object_type')
|
||||
&& $this->formattingObjectId === $this->request->getParam('object_id');
|
||||
&& $this->formattingObjectId === (int) $this->request->getParam('object_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $status Set to true, when parsing events should not use SVG icons
|
||||
*/
|
||||
public function setRequirePNG($status) {
|
||||
public function setRequirePNG(bool $status): void {
|
||||
$this->requirePNG = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getRequirePNG() {
|
||||
public function getRequirePNG(): bool {
|
||||
return $this->requirePNG;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $app
|
||||
* @param string $text
|
||||
* @param array $params
|
||||
* @param boolean $stripPath
|
||||
* @param boolean $highlightParams
|
||||
* @param string $languageCode
|
||||
* @return string|false
|
||||
*/
|
||||
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
|
||||
foreach ($this->getExtensions() as $c) {
|
||||
$translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode);
|
||||
if (is_string($translation)) {
|
||||
return $translation;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $app
|
||||
* @param string $text
|
||||
* @return array|false
|
||||
*/
|
||||
public function getSpecialParameterList($app, $text) {
|
||||
if (isset($this->specialParameters[$app][$text])) {
|
||||
return $this->specialParameters[$app][$text];
|
||||
}
|
||||
|
||||
if (!isset($this->specialParameters[$app])) {
|
||||
$this->specialParameters[$app] = array();
|
||||
}
|
||||
|
||||
foreach ($this->getExtensions() as $c) {
|
||||
$specialParameter = $c->getSpecialParameterList($app, $text);
|
||||
if (is_array($specialParameter)) {
|
||||
$this->specialParameters[$app][$text] = $specialParameter;
|
||||
return $specialParameter;
|
||||
}
|
||||
}
|
||||
|
||||
$this->specialParameters[$app][$text] = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $activity
|
||||
* @return integer|false
|
||||
*/
|
||||
public function getGroupParameter($activity) {
|
||||
foreach ($this->getExtensions() as $c) {
|
||||
$parameter = $c->getGroupParameter($activity);
|
||||
if ($parameter !== false) {
|
||||
return $parameter;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user we need to use
|
||||
*
|
||||
* @param string|null $currentUserId
|
||||
* @throws \UnexpectedValueException If the user is invalid
|
||||
*/
|
||||
public function setCurrentUserId($currentUserId) {
|
||||
public function setCurrentUserId(string $currentUserId = null): void {
|
||||
if (!is_string($currentUserId) && $currentUserId !== null) {
|
||||
throw new \UnexpectedValueException('The given current user is invalid');
|
||||
}
|
||||
|
@ -540,14 +349,16 @@ class Manager implements IManager {
|
|||
* @return string
|
||||
* @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
|
||||
*/
|
||||
public function getCurrentUserId() {
|
||||
public function getCurrentUserId(): string {
|
||||
if ($this->currentUserId !== null) {
|
||||
return $this->currentUserId;
|
||||
} else if (!$this->session->isLoggedIn()) {
|
||||
return $this->getUserFromToken();
|
||||
} else {
|
||||
return $this->session->getUser()->getUID();
|
||||
}
|
||||
|
||||
if (!$this->session->isLoggedIn()) {
|
||||
return $this->getUserFromToken();
|
||||
}
|
||||
|
||||
return $this->session->getUser()->getUID();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -556,7 +367,7 @@ class Manager implements IManager {
|
|||
* @return string
|
||||
* @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
|
||||
*/
|
||||
protected function getUserFromToken() {
|
||||
protected function getUserFromToken(): string {
|
||||
$token = (string) $this->request->getParam('token', '');
|
||||
if (strlen($token) !== 30) {
|
||||
throw new \UnexpectedValueException('The token is invalid');
|
||||
|
@ -573,130 +384,4 @@ class Manager implements IManager {
|
|||
return array_shift($users);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @deprecated 11.0.0 - Use getFilters() instead
|
||||
*/
|
||||
public function getNavigation() {
|
||||
$entries = array(
|
||||
'apps' => array(),
|
||||
'top' => array(),
|
||||
);
|
||||
foreach ($this->getExtensions() as $c) {
|
||||
$additionalEntries = $c->getNavigation();
|
||||
if (is_array($additionalEntries)) {
|
||||
$entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']);
|
||||
$entries['top'] = array_merge($entries['top'], $additionalEntries['top']);
|
||||
}
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filterValue
|
||||
* @return boolean
|
||||
* @deprecated 11.0.0 - Use getFilterById() instead
|
||||
*/
|
||||
public function isFilterValid($filterValue) {
|
||||
if (isset($this->validFilters[$filterValue])) {
|
||||
return $this->validFilters[$filterValue];
|
||||
}
|
||||
|
||||
foreach ($this->getExtensions() as $c) {
|
||||
if ($c->isFilterValid($filterValue) === true) {
|
||||
$this->validFilters[$filterValue] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->validFilters[$filterValue] = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param string $filter
|
||||
* @return array
|
||||
* @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead
|
||||
*/
|
||||
public function filterNotificationTypes($types, $filter) {
|
||||
if (!$this->isFilterValid($filter)) {
|
||||
return $types;
|
||||
}
|
||||
|
||||
foreach ($this->getExtensions() as $c) {
|
||||
$result = $c->filterNotificationTypes($types, $filter);
|
||||
if (is_array($result)) {
|
||||
$types = $result;
|
||||
}
|
||||
}
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filter
|
||||
* @return array
|
||||
* @deprecated 11.0.0 - Use getFilterById() instead
|
||||
*/
|
||||
public function getQueryForFilter($filter) {
|
||||
if (!$this->isFilterValid($filter)) {
|
||||
return [null, null];
|
||||
}
|
||||
|
||||
$conditions = array();
|
||||
$parameters = array();
|
||||
|
||||
foreach ($this->getExtensions() as $c) {
|
||||
$result = $c->getQueryForFilter($filter);
|
||||
if (is_array($result)) {
|
||||
list($condition, $parameter) = $result;
|
||||
if ($condition && is_array($parameter)) {
|
||||
$conditions[] = $condition;
|
||||
$parameters = array_merge($parameters, $parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($conditions)) {
|
||||
return array(null, null);
|
||||
}
|
||||
|
||||
return array(' and ((' . implode(') or (', $conditions) . '))', $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return additional notification types as specified by other apps
|
||||
*
|
||||
* @param string $languageCode
|
||||
* @return array
|
||||
* @deprecated 11.0.0 - Use getSettings() instead
|
||||
*/
|
||||
public function getNotificationTypes($languageCode) {
|
||||
$notificationTypes = $sharingNotificationTypes = [];
|
||||
foreach ($this->getExtensions() as $c) {
|
||||
$result = $c->getNotificationTypes($languageCode);
|
||||
if (is_array($result)) {
|
||||
$notificationTypes = array_merge($notificationTypes, $result);
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($sharingNotificationTypes, $notificationTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @return array
|
||||
* @deprecated 11.0.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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,13 +24,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Public interface of ownCloud for apps to use.
|
||||
* Activity/IExtension interface
|
||||
*/
|
||||
|
||||
// use OCP namespace for all classes that are considered public.
|
||||
// This means that they should be used by apps instead of the internal ownCloud classes
|
||||
namespace OCP\Activity;
|
||||
|
||||
/**
|
||||
|
@ -48,124 +41,4 @@ interface IExtension {
|
|||
const PRIORITY_MEDIUM = 30;
|
||||
const PRIORITY_HIGH = 40;
|
||||
const PRIORITY_VERYHIGH = 50;
|
||||
|
||||
/**
|
||||
* The extension can return an array of additional notification types.
|
||||
* If no additional types are to be added false is to be returned
|
||||
*
|
||||
* @param string $languageCode
|
||||
* @return array|false Array "stringID of the type" => "translated string description for the setting"
|
||||
* or Array "stringID of the type" => [
|
||||
* 'desc' => "translated string description for the setting"
|
||||
* 'methods' => [self::METHOD_*],
|
||||
* ]
|
||||
* @since 8.0.0 - 8.2.0: Added support to allow limiting notifications to certain methods
|
||||
*/
|
||||
public function getNotificationTypes($languageCode);
|
||||
|
||||
/**
|
||||
* For a given method additional types to be displayed in the settings can be returned.
|
||||
* In case no additional types are to be added false is to be returned.
|
||||
*
|
||||
* @param string $method
|
||||
* @return array|false
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function getDefaultTypes($method);
|
||||
|
||||
/**
|
||||
* A string naming the css class for the icon to be used can be returned.
|
||||
* If no icon is known for the given type false is to be returned.
|
||||
*
|
||||
* @param string $type
|
||||
* @return string|false
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function getTypeIcon($type);
|
||||
|
||||
/**
|
||||
* The extension can translate a given message to the requested languages.
|
||||
* If no translation is available false is to be returned.
|
||||
*
|
||||
* @param string $app
|
||||
* @param string $text
|
||||
* @param array $params
|
||||
* @param boolean $stripPath
|
||||
* @param boolean $highlightParams
|
||||
* @param string $languageCode
|
||||
* @return string|false
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode);
|
||||
|
||||
/**
|
||||
* The extension can define the type of parameters for translation
|
||||
*
|
||||
* Currently known types are:
|
||||
* * file => will strip away the path of the file and add a tooltip with it
|
||||
* * username => will add the avatar of the user
|
||||
* * email => will add a mailto link
|
||||
*
|
||||
* @param string $app
|
||||
* @param string $text
|
||||
* @return array|false
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function getSpecialParameterList($app, $text);
|
||||
|
||||
/**
|
||||
* The extension can define the parameter grouping by returning the index as integer.
|
||||
* In case no grouping is required false is to be returned.
|
||||
*
|
||||
* @param array $activity
|
||||
* @return integer|false
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function getGroupParameter($activity);
|
||||
|
||||
/**
|
||||
* The extension can define additional navigation entries. The array returned has to contain two keys 'top'
|
||||
* and 'apps' which hold arrays with the relevant entries.
|
||||
* If no further entries are to be added false is no be returned.
|
||||
*
|
||||
* @return array|false
|
||||
* @since 8.0.0
|
||||
* @deprecated 11.0.0 - Register an IFilter instead
|
||||
*/
|
||||
public function getNavigation();
|
||||
|
||||
/**
|
||||
* The extension can check if a customer filter (given by a query string like filter=abc) is valid or not.
|
||||
*
|
||||
* @param string $filterValue
|
||||
* @return boolean
|
||||
* @since 8.0.0
|
||||
* @deprecated 11.0.0 - Register an IFilter instead
|
||||
*/
|
||||
public function isFilterValid($filterValue);
|
||||
|
||||
/**
|
||||
* The extension can filter the types based on the filter if required.
|
||||
* In case no filter is to be applied false is to be returned unchanged.
|
||||
*
|
||||
* @param array $types
|
||||
* @param string $filter
|
||||
* @return array|false
|
||||
* @since 8.0.0
|
||||
* @deprecated 11.0.0 - Register an IFilter instead
|
||||
*/
|
||||
public function filterNotificationTypes($types, $filter);
|
||||
|
||||
/**
|
||||
* For a given filter the extension can specify the sql query conditions including parameters for that query.
|
||||
* In case the extension does not know the filter false is to be returned.
|
||||
* The query condition and the parameters are to be returned as array with two elements.
|
||||
* E.g. return array('`app` = ? and `message` like ?', array('mail', 'ownCloud%'));
|
||||
*
|
||||
* @param string $filter
|
||||
* @return array|false
|
||||
* @since 8.0.0
|
||||
* @deprecated 11.0.0 - Register an IFilter instead
|
||||
*/
|
||||
public function getQueryForFilter($filter);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
|
@ -24,13 +25,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Public interface of ownCloud for apps to use.
|
||||
* Activity/IManager interface
|
||||
*/
|
||||
|
||||
// use OCP namespace for all classes that are considered public.
|
||||
// This means that they should be used by apps instead of the internal ownCloud classes
|
||||
namespace OCP\Activity;
|
||||
|
||||
/**
|
||||
|
@ -53,7 +47,7 @@ interface IManager {
|
|||
* @return IEvent
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function generateEvent();
|
||||
public function generateEvent(): IEvent;
|
||||
|
||||
/**
|
||||
* Publish an event to the activity consumers
|
||||
|
@ -68,7 +62,7 @@ interface IManager {
|
|||
* @throws \BadMethodCallException if required values have not been set
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function publish(IEvent $event);
|
||||
public function publish(IEvent $event): void;
|
||||
|
||||
/**
|
||||
* In order to improve lazy loading a closure can be registered which will be called in case
|
||||
|
@ -77,35 +71,21 @@ interface IManager {
|
|||
* $callable has to return an instance of \OCP\Activity\IConsumer
|
||||
*
|
||||
* @param \Closure $callable
|
||||
* @return void
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public function registerConsumer(\Closure $callable);
|
||||
|
||||
/**
|
||||
* In order to improve lazy loading a closure can be registered which will be called in case
|
||||
* activity consumers are actually requested
|
||||
*
|
||||
* $callable has to return an instance of \OCP\Activity\IExtension
|
||||
*
|
||||
* @param \Closure $callable
|
||||
* @return void
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function registerExtension(\Closure $callable);
|
||||
public function registerConsumer(\Closure $callable): void;
|
||||
|
||||
/**
|
||||
* @param string $filter Class must implement OCA\Activity\IFilter
|
||||
* @return void
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function registerFilter($filter);
|
||||
public function registerFilter(string $filter): void;
|
||||
|
||||
/**
|
||||
* @return IFilter[]
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getFilters();
|
||||
public function getFilters(): array;
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
|
@ -113,33 +93,31 @@ interface IManager {
|
|||
* @throws \InvalidArgumentException when the filter was not found
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getFilterById($id);
|
||||
public function getFilterById(string $id): IFilter;
|
||||
|
||||
/**
|
||||
* @param string $setting Class must implement OCA\Activity\ISetting
|
||||
* @return void
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function registerSetting($setting);
|
||||
public function registerSetting(string $setting): void;
|
||||
|
||||
/**
|
||||
* @return ISetting[]
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getSettings();
|
||||
public function getSettings(): array;
|
||||
|
||||
/**
|
||||
* @param string $provider Class must implement OCA\Activity\IProvider
|
||||
* @return void
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function registerProvider($provider);
|
||||
public function registerProvider(string $provider): void;
|
||||
|
||||
/**
|
||||
* @return IProvider[]
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getProviders();
|
||||
public function getProviders(): array;
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
|
@ -147,89 +125,32 @@ interface IManager {
|
|||
* @throws \InvalidArgumentException when the setting was not found
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getSettingById($id);
|
||||
|
||||
/**
|
||||
* Will return additional notification types as specified by other apps
|
||||
*
|
||||
* @param string $languageCode
|
||||
* @return array Array "stringID of the type" => "translated string description for the setting"
|
||||
* or Array "stringID of the type" => [
|
||||
* 'desc' => "translated string description for the setting"
|
||||
* 'methods' => [\OCP\Activity\IExtension::METHOD_*],
|
||||
* ]
|
||||
* @since 8.0.0 - 8.2.0: Added support to allow limiting notifications to certain methods
|
||||
* @deprecated 11.0.0 - Use getSettings() instead
|
||||
*/
|
||||
public function getNotificationTypes($languageCode);
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @return array
|
||||
* @since 8.0.0
|
||||
* @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead
|
||||
*/
|
||||
public function getDefaultTypes($method);
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return string
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function getTypeIcon($type);
|
||||
public function getSettingById(string $id): ISetting;
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param int $id
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function setFormattingObject($type, $id);
|
||||
public function setFormattingObject(string $type, int $id): void;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function isFormattingFilteredObject();
|
||||
public function isFormattingFilteredObject(): bool;
|
||||
|
||||
/**
|
||||
* @param bool $status Set to true, when parsing events should not use SVG icons
|
||||
* @since 12.0.1
|
||||
*/
|
||||
public function setRequirePNG($status);
|
||||
public function setRequirePNG(bool $status): void;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @since 12.0.1
|
||||
*/
|
||||
public function getRequirePNG();
|
||||
|
||||
/**
|
||||
* @param string $app
|
||||
* @param string $text
|
||||
* @param array $params
|
||||
* @param boolean $stripPath
|
||||
* @param boolean $highlightParams
|
||||
* @param string $languageCode
|
||||
* @return string|false
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode);
|
||||
|
||||
/**
|
||||
* @param string $app
|
||||
* @param string $text
|
||||
* @return array|false
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function getSpecialParameterList($app, $text);
|
||||
|
||||
/**
|
||||
* @param array $activity
|
||||
* @return integer|false
|
||||
* @since 8.0.0
|
||||
*/
|
||||
public function getGroupParameter($activity);
|
||||
|
||||
public function getRequirePNG(): bool;
|
||||
|
||||
/**
|
||||
* Set the user we need to use
|
||||
|
@ -238,7 +159,7 @@ interface IManager {
|
|||
* @throws \UnexpectedValueException If the user is invalid
|
||||
* @since 9.0.1
|
||||
*/
|
||||
public function setCurrentUserId($currentUserId);
|
||||
public function setCurrentUserId(string $currentUserId = null): void;
|
||||
|
||||
/**
|
||||
* Get the user we need to use
|
||||
|
@ -249,37 +170,5 @@ interface IManager {
|
|||
* @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
|
||||
* @since 8.1.0
|
||||
*/
|
||||
public function getCurrentUserId();
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @since 8.0.0
|
||||
* @deprecated 11.0.0 - Use getFilters() instead
|
||||
*/
|
||||
public function getNavigation();
|
||||
|
||||
/**
|
||||
* @param string $filterValue
|
||||
* @return boolean
|
||||
* @since 8.0.0
|
||||
* @deprecated 11.0.0 - Use getFilterById() instead
|
||||
*/
|
||||
public function isFilterValid($filterValue);
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param string $filter
|
||||
* @return array
|
||||
* @since 8.0.0
|
||||
* @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead
|
||||
*/
|
||||
public function filterNotificationTypes($types, $filter);
|
||||
|
||||
/**
|
||||
* @param string $filter
|
||||
* @return array
|
||||
* @since 8.0.0
|
||||
* @deprecated 11.0.0 - Use getFilterById() instead
|
||||
*/
|
||||
public function getQueryForFilter($filter);
|
||||
public function getCurrentUserId(): string;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,23 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
* @copyright Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
|
||||
* @copyright Copyright (c) 2019 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -46,27 +59,18 @@ class ManagerTest extends TestCase {
|
|||
$this->validator
|
||||
);
|
||||
|
||||
$this->assertSame([], $this->invokePrivate($this->activityManager, 'getConsumers'));
|
||||
$this->assertSame([], $this->invokePrivate($this->activityManager, 'getExtensions'));
|
||||
$this->assertSame([], self::invokePrivate($this->activityManager, 'getConsumers'));
|
||||
|
||||
$this->activityManager->registerConsumer(function() {
|
||||
return new NoOpConsumer();
|
||||
});
|
||||
$this->activityManager->registerExtension(function() {
|
||||
return new NoOpExtension();
|
||||
});
|
||||
$this->activityManager->registerExtension(function() {
|
||||
return new SimpleExtension();
|
||||
});
|
||||
|
||||
$this->assertNotEmpty($this->invokePrivate($this->activityManager, 'getConsumers'));
|
||||
$this->assertNotEmpty($this->invokePrivate($this->activityManager, 'getConsumers'));
|
||||
$this->assertNotEmpty($this->invokePrivate($this->activityManager, 'getExtensions'));
|
||||
$this->assertNotEmpty($this->invokePrivate($this->activityManager, 'getExtensions'));
|
||||
$this->assertNotEmpty(self::invokePrivate($this->activityManager, 'getConsumers'));
|
||||
$this->assertNotEmpty(self::invokePrivate($this->activityManager, 'getConsumers'));
|
||||
}
|
||||
|
||||
public function testGetConsumers() {
|
||||
$consumers = $this->invokePrivate($this->activityManager, 'getConsumers');
|
||||
$consumers = self::invokePrivate($this->activityManager, 'getConsumers');
|
||||
|
||||
$this->assertNotEmpty($consumers);
|
||||
}
|
||||
|
@ -79,111 +83,7 @@ class ManagerTest extends TestCase {
|
|||
return new \stdClass();
|
||||
});
|
||||
|
||||
$this->invokePrivate($this->activityManager, 'getConsumers');
|
||||
}
|
||||
|
||||
public function testGetExtensions() {
|
||||
$extensions = $this->invokePrivate($this->activityManager, 'getExtensions');
|
||||
|
||||
$this->assertNotEmpty($extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testGetExtensionsInvalidExtension() {
|
||||
$this->activityManager->registerExtension(function() {
|
||||
return new \stdClass();
|
||||
});
|
||||
|
||||
$this->invokePrivate($this->activityManager, 'getExtensions');
|
||||
}
|
||||
|
||||
public function testNotificationTypes() {
|
||||
$result = $this->activityManager->getNotificationTypes('en');
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEquals(2, sizeof($result));
|
||||
}
|
||||
|
||||
public function testDefaultTypes() {
|
||||
$result = $this->activityManager->getDefaultTypes('stream');
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEquals(1, sizeof($result));
|
||||
|
||||
$result = $this->activityManager->getDefaultTypes('email');
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEquals(0, sizeof($result));
|
||||
}
|
||||
|
||||
public function testTypeIcon() {
|
||||
$result = $this->activityManager->getTypeIcon('NT1');
|
||||
$this->assertEquals('icon-nt-one', $result);
|
||||
|
||||
$result = $this->activityManager->getTypeIcon('NT2');
|
||||
$this->assertEquals('', $result);
|
||||
}
|
||||
|
||||
public function testTranslate() {
|
||||
$result = $this->activityManager->translate('APP0', '', array(), false, false, 'en');
|
||||
$this->assertEquals('Stupid translation', $result);
|
||||
|
||||
$result = $this->activityManager->translate('APP1', '', array(), false, false, 'en');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testGetSpecialParameterList() {
|
||||
$result = $this->activityManager->getSpecialParameterList('APP0', '');
|
||||
$this->assertEquals(array(0 => 'file', 1 => 'username'), $result);
|
||||
|
||||
$result = $this->activityManager->getSpecialParameterList('APP1', '');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testGroupParameter() {
|
||||
$result = $this->activityManager->getGroupParameter(array());
|
||||
$this->assertEquals(5, $result);
|
||||
}
|
||||
|
||||
public function testNavigation() {
|
||||
$result = $this->activityManager->getNavigation();
|
||||
$this->assertEquals(4, sizeof($result['apps']));
|
||||
$this->assertEquals(2, sizeof($result['top']));
|
||||
}
|
||||
|
||||
public function testIsFilterValid() {
|
||||
$result = $this->activityManager->isFilterValid('fv01');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->activityManager->isFilterValid('InvalidFilter');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testFilterNotificationTypes() {
|
||||
$result = $this->activityManager->filterNotificationTypes(array('NT0', 'NT1', 'NT2', 'NT3'), 'fv01');
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEquals(3, sizeof($result));
|
||||
|
||||
$result = $this->activityManager->filterNotificationTypes(array('NT0', 'NT1', 'NT2', 'NT3'), 'InvalidFilter');
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEquals(4, sizeof($result));
|
||||
}
|
||||
|
||||
public function testQueryForFilter() {
|
||||
// Register twice, to test the created sql part
|
||||
$this->activityManager->registerExtension(function() {
|
||||
return new SimpleExtension();
|
||||
});
|
||||
|
||||
$result = $this->activityManager->getQueryForFilter('fv01');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
' and ((`app` = ? and `message` like ?) or (`app` = ? and `message` like ?))',
|
||||
array('mail', 'ownCloud%', 'mail', 'ownCloud%')
|
||||
), $result
|
||||
);
|
||||
|
||||
$result = $this->activityManager->getQueryForFilter('InvalidFilter');
|
||||
$this->assertEquals(array(null, null), $result);
|
||||
self::invokePrivate($this->activityManager, 'getConsumers');
|
||||
}
|
||||
|
||||
public function getUserFromTokenThrowInvalidTokenData() {
|
||||
|
@ -392,121 +292,6 @@ class ManagerTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
class SimpleExtension implements \OCP\Activity\IExtension {
|
||||
|
||||
public function getNotificationTypes($languageCode) {
|
||||
return array('NT1', 'NT2');
|
||||
}
|
||||
|
||||
public function getDefaultTypes($method) {
|
||||
if ($method === 'stream') {
|
||||
return array('DT0');
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getTypeIcon($type) {
|
||||
if ($type === 'NT1') {
|
||||
return 'icon-nt-one';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
|
||||
if ($app === 'APP0') {
|
||||
return "Stupid translation";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getSpecialParameterList($app, $text) {
|
||||
if ($app === 'APP0') {
|
||||
return array(0 => 'file', 1 => 'username');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getGroupParameter($activity) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function getNavigation() {
|
||||
return array(
|
||||
'apps' => array('nav1', 'nav2', 'nav3', 'nav4'),
|
||||
'top' => array('top1', 'top2')
|
||||
);
|
||||
}
|
||||
|
||||
public function isFilterValid($filterValue) {
|
||||
if ($filterValue === 'fv01') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function filterNotificationTypes($types, $filter) {
|
||||
if ($filter === 'fv01') {
|
||||
unset($types[0]);
|
||||
}
|
||||
return $types;
|
||||
}
|
||||
|
||||
public function getQueryForFilter($filter) {
|
||||
if ($filter === 'fv01') {
|
||||
return array('`app` = ? and `message` like ?', array('mail', 'ownCloud%'));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class NoOpExtension implements \OCP\Activity\IExtension {
|
||||
|
||||
public function getNotificationTypes($languageCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDefaultTypes($method) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getTypeIcon($type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getSpecialParameterList($app, $text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getGroupParameter($activity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getNavigation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isFilterValid($filterValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function filterNotificationTypes($types, $filter) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getQueryForFilter($filter) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class NoOpConsumer implements \OCP\Activity\IConsumer {
|
||||
|
||||
public function receive(\OCP\Activity\IEvent $event) {
|
||||
|
|
Loading…
Reference in New Issue