From 71db51e5ef4d1b0a6d8ba851d0ea2d7a6c592239 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 25 Jul 2019 10:44:58 -0100 Subject: [PATCH 01/16] implementing Stratos Manager Signed-off-by: Maxence Lange autoload Signed-off-by: Maxence Lange some more Signed-off-by: Maxence Lange autoload Signed-off-by: Maxence Lange events Signed-off-by: Maxence Lange --- lib/composer/composer/autoload_classmap.php | 10 + lib/composer/composer/autoload_static.php | 10 + lib/private/Server.php | 3 + lib/private/Stratos/Model/StratosEvent.php | 61 +++++ lib/private/Stratos/Model/StratosMessage.php | 189 +++++++++++++ lib/private/Stratos/Model/StratosStream.php | 249 ++++++++++++++++++ lib/private/Stratos/StratosManager.php | 111 ++++++++ .../FullTextSearch/Model/ISearchResult.php | 55 ++-- .../Exceptions/StratosInstallException.php | 41 +++ lib/public/Stratos/IStratosManager.php | 76 ++++++ lib/public/Stratos/Model/IStratosEvent.php | 44 ++++ lib/public/Stratos/Model/IStratosMessage.php | 116 ++++++++ lib/public/Stratos/Model/IStratosStream.php | 151 +++++++++++ .../Stratos/Service/IStratosService.php | 52 ++++ 14 files changed, 1145 insertions(+), 23 deletions(-) create mode 100644 lib/private/Stratos/Model/StratosEvent.php create mode 100644 lib/private/Stratos/Model/StratosMessage.php create mode 100644 lib/private/Stratos/Model/StratosStream.php create mode 100644 lib/private/Stratos/StratosManager.php create mode 100644 lib/public/Stratos/Exceptions/StratosInstallException.php create mode 100644 lib/public/Stratos/IStratosManager.php create mode 100644 lib/public/Stratos/Model/IStratosEvent.php create mode 100644 lib/public/Stratos/Model/IStratosMessage.php create mode 100644 lib/public/Stratos/Model/IStratosStream.php create mode 100644 lib/public/Stratos/Service/IStratosService.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 52dab1ddf3f74..690a134482902 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -406,6 +406,12 @@ 'OCP\\Share_Backend' => $baseDir . '/lib/public/Share_Backend.php', 'OCP\\Share_Backend_Collection' => $baseDir . '/lib/public/Share_Backend_Collection.php', 'OCP\\Share_Backend_File_Dependent' => $baseDir . '/lib/public/Share_Backend_File_Dependent.php', + 'OCP\\Stratos\\Exceptions\\StratosInstallException' => $baseDir . '/lib/public/Stratos/Exceptions/StratosInstallException.php', + 'OCP\\Stratos\\IStratosManager' => $baseDir . '/lib/public/Stratos/IStratosManager.php', + 'OCP\\Stratos\\Model\\IStratosEvent' => $baseDir . '/lib/public/Stratos/Model/IStratosEvent.php', + 'OCP\\Stratos\\Model\\IStratosMessage' => $baseDir . '/lib/public/Stratos/Model/IStratosMessage.php', + 'OCP\\Stratos\\Model\\IStratosStream' => $baseDir . '/lib/public/Stratos/Model/IStratosStream.php', + 'OCP\\Stratos\\Service\\IStratosService' => $baseDir . '/lib/public/Stratos/Service/IStratosService.php', 'OCP\\Support\\CrashReport\\ICollectBreadcrumbs' => $baseDir . '/lib/public/Support/CrashReport/ICollectBreadcrumbs.php', 'OCP\\Support\\CrashReport\\IMessageReporter' => $baseDir . '/lib/public/Support/CrashReport/IMessageReporter.php', 'OCP\\Support\\CrashReport\\IRegistry' => $baseDir . '/lib/public/Support/CrashReport/IRegistry.php', @@ -1190,6 +1196,10 @@ 'OC\\Share\\Helper' => $baseDir . '/lib/private/Share/Helper.php', 'OC\\Share\\SearchResultSorter' => $baseDir . '/lib/private/Share/SearchResultSorter.php', 'OC\\Share\\Share' => $baseDir . '/lib/private/Share/Share.php', + 'OC\\Stratos\\StratosEvent' => $baseDir . '/lib/private/Stratos/Model/StratosEvent.php', + 'OC\\Stratos\\StratosManager' => $baseDir . '/lib/private/Stratos/StratosManager.php', + 'OC\\Stratos\\StratosMessage' => $baseDir . '/lib/private/Stratos/Model/StratosMessage.php', + 'OC\\Stratos\\StratosStream' => $baseDir . '/lib/private/Stratos/Model/StratosStream.php', 'OC\\Streamer' => $baseDir . '/lib/private/Streamer.php', 'OC\\SubAdmin' => $baseDir . '/lib/private/SubAdmin.php', 'OC\\Support\\CrashReport\\Registry' => $baseDir . '/lib/private/Support/CrashReport/Registry.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index b4d564af319b7..c998ddd347d8f 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -440,6 +440,12 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Share_Backend' => __DIR__ . '/../../..' . '/lib/public/Share_Backend.php', 'OCP\\Share_Backend_Collection' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_Collection.php', 'OCP\\Share_Backend_File_Dependent' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_File_Dependent.php', + 'OCP\\Stratos\\Exceptions\\StratosInstallException' => __DIR__ . '/../../..' . '/lib/public/Stratos/Exceptions/StratosInstallException.php', + 'OCP\\Stratos\\IStratosManager' => __DIR__ . '/../../..' . '/lib/public/Stratos/IStratosManager.php', + 'OCP\\Stratos\\Model\\IStratosEvent' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosEvent.php', + 'OCP\\Stratos\\Model\\IStratosMessage' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosMessage.php', + 'OCP\\Stratos\\Model\\IStratosStream' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosStream.php', + 'OCP\\Stratos\\Service\\IStratosService' => __DIR__ . '/../../..' . '/lib/public/Stratos/Service/IStratosService.php', 'OCP\\Support\\CrashReport\\ICollectBreadcrumbs' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/ICollectBreadcrumbs.php', 'OCP\\Support\\CrashReport\\IMessageReporter' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/IMessageReporter.php', 'OCP\\Support\\CrashReport\\IRegistry' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/IRegistry.php', @@ -1224,6 +1230,10 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Share\\Helper' => __DIR__ . '/../../..' . '/lib/private/Share/Helper.php', 'OC\\Share\\SearchResultSorter' => __DIR__ . '/../../..' . '/lib/private/Share/SearchResultSorter.php', 'OC\\Share\\Share' => __DIR__ . '/../../..' . '/lib/private/Share/Share.php', + 'OC\\Stratos\\StratosEvent' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosEvent.php', + 'OC\\Stratos\\StratosManager' => __DIR__ . '/../../..' . '/lib/private/Stratos/StratosManager.php', + 'OC\\Stratos\\StratosMessage' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosMessage.php', + 'OC\\Stratos\\StratosStream' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosStream.php', 'OC\\Streamer' => __DIR__ . '/../../..' . '/lib/private/Streamer.php', 'OC\\SubAdmin' => __DIR__ . '/../../..' . '/lib/private/SubAdmin.php', 'OC\\Support\\CrashReport\\Registry' => __DIR__ . '/../../..' . '/lib/private/Support/CrashReport/Registry.php', diff --git a/lib/private/Server.php b/lib/private/Server.php index bce4f0feaef69..442407e983982 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -119,6 +119,7 @@ use OC\Session\CryptoWrapper; use OC\Share20\ProviderFactory; use OC\Share20\ShareHelper; +use OC\Stratos\StratosManager; use OC\SystemTag\ManagerFactory as SystemTagManagerFactory; use OC\Tagging\TagMapper; use OC\Template\IconsCacher; @@ -158,6 +159,7 @@ use OCP\RichObjectStrings\IValidator; use OCP\Security\IContentSecurityPolicyManager; use OCP\Share\IShareHelper; +use OCP\Stratos\IStratosManager; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; @@ -1185,6 +1187,7 @@ public function __construct($webRoot, \OC\Config $config) { $this->registerAlias(IDashboardManager::class, DashboardManager::class); $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); + $this->registerAlias(IStratosManager::class, StratosManager::class); $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) { return new \OC\Security\IdentityProof\Manager( diff --git a/lib/private/Stratos/Model/StratosEvent.php b/lib/private/Stratos/Model/StratosEvent.php new file mode 100644 index 0000000000000..bdd7a3ba86bd5 --- /dev/null +++ b/lib/private/Stratos/Model/StratosEvent.php @@ -0,0 +1,61 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Stratos; + + +use JsonSerializable; +use OCP\Stratos\Model\IStratosEvent; + + +/** + * Class StratosEvent + * + * @package OC\Stratos + */ +class StratosEvent extends StratosStream implements IStratosEvent, JsonSerializable { + + + const TYPE = 'Event'; + + + /** + * @return array + */ + public function jsonSerialize(): array { + return array_merge( + parent::jsonSerialize(), + [ + ] + ); + } + +} + diff --git a/lib/private/Stratos/Model/StratosMessage.php b/lib/private/Stratos/Model/StratosMessage.php new file mode 100644 index 0000000000000..cdb1075508260 --- /dev/null +++ b/lib/private/Stratos/Model/StratosMessage.php @@ -0,0 +1,189 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Stratos; + + +use JsonSerializable; +use OCP\Stratos\Model\IStratosMessage; + + +/** + * Class StratosManager + * + * @package OC\Stratos + */ +class StratosMessage extends StratosStream implements IStratosMessage, JsonSerializable { + + + const TYPE = 'Message'; + + + /** @var int */ + private $messageType = 0; + + /** @var string */ + private $title = ''; + + /** @var string */ + private $content = ''; + + /** @var string */ + private $detail = ''; + + /** @var string */ + private $link = ''; + + + /** + * StratosMessage constructor. + * + * @param string $app + * @param string $source + */ + public function __construct(string $app = '', string $source = '') { + parent::__construct($app, $source); + + $this->setType(StratosMessage::TYPE); + } + + + /** + * @return int + */ + public function getMessageType(): int { + return $this->messageType; + } + + /** + * @param int $messageType + * + * @return IStratosMessage + */ + public function setMessageType(int $messageType): IStratosMessage { + $this->messageType = $messageType; + + return $this; + } + + + /** + * @return string + */ + public function getTitle(): string { + return $this->title; + } + + /** + * @param string $title + * + * @return IStratosMessage + */ + public function setTitle(string $title): IStratosMessage { + $this->title = $title; + + return $this; + } + + + /** + * @return string + */ + public function getContent(): string { + return $this->content; + } + + /** + * @param string $content + * + * @return IStratosMessage + */ + public function setContent(string $content): IStratosMessage { + $this->content = $content; + + return $this; + } + + + /** + * @return string + */ + public function getDetail(): string { + return $this->detail; + } + + /** + * @param string $detail + * + * @return IStratosMessage + */ + public function setDetail(string $detail): IStratosMessage { + $this->detail = $detail; + + return $this; + } + + + /** + * @return string + */ + public function getLink(): string { + return $this->link; + } + + /** + * @param string $link + * + * @return IStratosMessage + */ + public function setLink(string $link): IStratosMessage { + $this->link = $link; + + return $this; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return array_merge( + parent::jsonSerialize(), + [ + 'message_type' => $this->getMessageType(), + 'title' => $this->getTitle(), + 'content' => $this->getContent(), + 'link' => $this->getLink() + ] + ); + } + +} + diff --git a/lib/private/Stratos/Model/StratosStream.php b/lib/private/Stratos/Model/StratosStream.php new file mode 100644 index 0000000000000..75802d4c04474 --- /dev/null +++ b/lib/private/Stratos/Model/StratosStream.php @@ -0,0 +1,249 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Stratos; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use JsonSerializable; +use OCP\Stratos\Model\IStratosStream; + + +/** + * Class StratosManager + * + * @package OC\Stratos + */ +class StratosStream implements IStratosStream, JsonSerializable { + + + use TArrayTools; + + /** @var int */ + private $id = 0; + + /** @var string */ + private $type = ''; + + /** @var string */ + private $ttl = ''; + + /** @var string */ + private $app = ''; + + /** @var string */ + private $source = ''; + + /** @var string */ + private $recipient = ''; + + /** @var int */ + private $creation = 0; + + + /** + * StratosMessage constructor. + * + * @param string $app + * @param string $source + */ + public function __construct(string $app = '', string $source = '') { + $this->app = $app; + $this->source = $source; + } + + + /** + * @return int + */ + public function getId(): int { + return $this->id; + } + + /** + * @param int $id + * + * @return IStratosStream + */ + public function setId(int $id): IStratosStream { + $this->id = $id; + + return $this; + } + + + /** + * @return string + */ + public function getType(): string { + return $this->type; + } + + /** + * @param string $type + * + * @return IStratosStream + */ + public function setType(string $type): IStratosStream { + $this->type = $type; + + return $this; + } + + + /** + * @return string + */ + public function getTtl(): string { + return $this->ttl; + } + + /** + * @param string $ttl + * + * @return IStratosStream + */ + public function setTtl(string $ttl): IStratosStream { + $this->ttl = $ttl; + + return $this; + } + + + /** + * @return string + */ + public function getApp(): string { + return $this->app; + } + + /** + * @param string $app + * + * @return IStratosStream + */ + public function setApp(string $app): IStratosStream { + $this->app = $app; + + return $this; + } + + + /** + * @return string + */ + public function getSource(): string { + return $this->source; + } + + /** + * @param string $source + * + * @return IStratosStream + */ + public function setSource(string $source): IStratosStream { + $this->source = $source; + + return $this; + } + + + /** + * @return string + */ + public function getRecipient(): string { + return $this->recipient; + } + + /** + * @param string $recipient + * + * @return IStratosStream + */ + public function setRecipient(string $recipient): IStratosStream { + $this->recipient = $recipient; + + return $this; + } + + + /** + * @return int + */ + public function getCreation(): int { + return $this->creation; + } + + /** + * @param int $timestamp + * + * @return IStratosStream + */ + public function setCreation(int $timestamp): IStratosStream { + $this->creation = $timestamp; + + return $this; + } + + + /** + * @param array $import + * + * @return IStratosStream + */ + public function import(array $import): IStratosStream { + $this->setType($this->get('type', $import)); + $this->setApp($this->get('app', $import)); + $this->setTtl($this->get('ttl', $import)); + $this->setRecipient($this->get('recipient', $import)); + $this->setSource($this->get('source', $import)); + $this->setCreation($this->getInt('creation', $import)); + + return $this; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return [ + 'id' => $this->getId(), + 'ttl' => $this->getTtl(), + 'app' => $this->getApp(), + 'source' => $this->getSource(), + 'type' => $this->getType(), + 'recipient' => $this->getRecipient(), + 'creation' => $this->getCreation() + ]; + } + +} + diff --git a/lib/private/Stratos/StratosManager.php b/lib/private/Stratos/StratosManager.php new file mode 100644 index 0000000000000..e2c7b1cf88d81 --- /dev/null +++ b/lib/private/Stratos/StratosManager.php @@ -0,0 +1,111 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Stratos; + + +use OCP\Stratos\Exceptions\StratosInstallException; +use OCP\Stratos\IStratosManager; +use OCP\Stratos\Service\IStratosService; + + +/** + * Class StratosManager + * + * @package OC\Stratos + */ +class StratosManager implements IStratosManager { + + + /** @var IStratosService */ + private $stratosService; + + + /** + * @param IStratosService $stratosService + * + * @since 18.0.0 + */ + public function registerStratosService(IStratosService $stratosService) { + $this->stratosService = $stratosService; + } + + + /** + * @return bool + */ + public function isAvailable(): bool { + try { + $this->checkRegistration(); + + return true; + } catch (StratosInstallException $e) { + } + + return false; + } + + + /** + * @return IStratosService + * @throws StratosInstallException + */ + public function getStratosService(): IStratosService { + $this->checkRegistration(); + + return $this->stratosService; + } + + + /** + * @param string $test + */ + public function test(string $test) { + try { + $this->checkRegistration(); + } catch (StratosInstallException $e) { + return; + } + + $this->stratosService->test($test); + } + + + /** + * @throws StratosInstallException + */ + private function checkRegistration() { + if ($this->stratosService === null) { + throw new StratosInstallException('stratosService is not registered'); + } + } + +} + diff --git a/lib/public/FullTextSearch/Model/ISearchResult.php b/lib/public/FullTextSearch/Model/ISearchResult.php index 2ca61c2f37b3e..d5ee12382c90c 100644 --- a/lib/public/FullTextSearch/Model/ISearchResult.php +++ b/lib/public/FullTextSearch/Model/ISearchResult.php @@ -59,20 +59,20 @@ interface ISearchResult { /** * Get the original SearchRequest. * - * @see ISearchRequest - * + * @return ISearchRequest * @since 15.0.0 * - * @return ISearchRequest + * @see ISearchRequest + * */ public function getRequest(): ISearchRequest; /** * Get the targeted Content Provider. * + * @return IFullTextSearchProvider * @since 15.0.0 * - * @return IFullTextSearchProvider */ public function getProvider(): IFullTextSearchProvider; @@ -80,56 +80,65 @@ public function getProvider(): IFullTextSearchProvider; /** * Add an IIndexDocument as one of the result of the search request. * - * @since 15.0.0 - * * @param IIndexDocument $document * * @return ISearchResult + * @since 15.0.0 + * */ public function addDocument(IIndexDocument $document): ISearchResult; /** * Returns all result of the search request, in an array of IIndexDocument. * + * @return IIndexDocument[] * @since 15.0.0 * - * @return IIndexDocument[] */ public function getDocuments(): array; /** * Set an array of IIndexDocument as the result of the search request. * - * @since 15.0.0 - * * @param IIndexDocument[] $documents * * @return ISearchResult + * @since 15.0.0 + * */ public function setDocuments(array $documents): ISearchResult; + + + public function addInfo(string $k, string $value): ISearchResult; + + public function getInfo(string $k): string; + + public function getInfosAll(): array; + + /** * Add an aggregation to the result. * - * @since 15.0.0 - * * @param string $category * @param string $value * @param int $count * * @return ISearchResult + * @since 15.0.0 + * */ public function addAggregation(string $category, string $value, int $count): ISearchResult; /** * Get all aggregations. * - * @since 15.0.0 - * * @param string $category * * @return array + * @since 15.0.0 + * */ public function getAggregations(string $category): array; @@ -137,11 +146,11 @@ public function getAggregations(string $category): array; /** * Set the raw result of the request. * - * @since 15.0.0 - * * @param string $result * * @return ISearchResult + * @since 15.0.0 + * */ public function setRawResult(string $result): ISearchResult; @@ -150,11 +159,11 @@ public function setRawResult(string $result): ISearchResult; * Set the total number of results for the search request. * Used by pagination. * - * @since 15.0.0 - * * @param int $total * * @return ISearchResult + * @since 15.0.0 + * */ public function setTotal(int $total): ISearchResult; @@ -162,11 +171,11 @@ public function setTotal(int $total): ISearchResult; /** * Set the top score for the search request. * - * @since 15.0.0 - * * @param int $score * * @return ISearchResult + * @since 15.0.0 + * */ public function setMaxScore(int $score): ISearchResult; @@ -174,11 +183,11 @@ public function setMaxScore(int $score): ISearchResult; /** * Set the time spent by the request to perform the search. * - * @since 15.0.0 - * * @param int $time * * @return ISearchResult + * @since 15.0.0 + * */ public function setTime(int $time): ISearchResult; @@ -186,11 +195,11 @@ public function setTime(int $time): ISearchResult; /** * Set to true if the request timed out. * - * @since 15.0.0 - * * @param bool $timedOut * * @return ISearchResult + * @since 15.0.0 + * */ public function setTimedOut(bool $timedOut): ISearchResult; diff --git a/lib/public/Stratos/Exceptions/StratosInstallException.php b/lib/public/Stratos/Exceptions/StratosInstallException.php new file mode 100644 index 0000000000000..9a852b19491f0 --- /dev/null +++ b/lib/public/Stratos/Exceptions/StratosInstallException.php @@ -0,0 +1,41 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Stratos\Exceptions; + +/** + * @since 18.0.0 + * + * Class StratosInstallException + * + * @package OCP\Stratos\Exceptions + */ +class StratosInstallException extends \Exception { +} + diff --git a/lib/public/Stratos/IStratosManager.php b/lib/public/Stratos/IStratosManager.php new file mode 100644 index 0000000000000..1cd11f24d1f11 --- /dev/null +++ b/lib/public/Stratos/IStratosManager.php @@ -0,0 +1,76 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Stratos; + + +use OCP\Stratos\Service\IStratosService; + + +/** + * Interface IStratosManager + * + * @since 18.0.0 + * + * @package OCP\Stratos + */ +interface IStratosManager { + + + /** + * Register a IStratosService. + * + * @param IStratosService $stratosService + * + * @since 18.0.0 + * + */ + public function registerStratosService(IStratosService $stratosService); + + + /** + * @return bool + */ + public function isAvailable(): bool; + + + /** + * @return IStratosService + */ + public function getStratosService(): IStratosService; + + + /** + * @param string $test + */ + public function test(string $test); + +} + diff --git a/lib/public/Stratos/Model/IStratosEvent.php b/lib/public/Stratos/Model/IStratosEvent.php new file mode 100644 index 0000000000000..81fb07aa7f740 --- /dev/null +++ b/lib/public/Stratos/Model/IStratosEvent.php @@ -0,0 +1,44 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Stratos\Model; + + +/** + * Interface IStratosMessage + * + * @since 18.0.0 + * + * @package OCP\Stratos + */ +interface IStratosEvent { + +} + diff --git a/lib/public/Stratos/Model/IStratosMessage.php b/lib/public/Stratos/Model/IStratosMessage.php new file mode 100644 index 0000000000000..3f620e636612a --- /dev/null +++ b/lib/public/Stratos/Model/IStratosMessage.php @@ -0,0 +1,116 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Stratos\Model; + + +/** + * Interface IStratosMessage + * + * @since 18.0.0 + * + * @package OCP\Stratos + */ +interface IStratosMessage extends IStratosStream { + + + const TYPE_CONFIRMATION = 1; + const TYPE_NOTE = 2; + const TYPE_STATUS = 3; + const TYPE_WARNING = 4; + const TYPE_ERROR = 5; + + + /** + * @param int $type + * + * @return IStratosMessage + */ + public function setMessageType(int $type): IStratosMessage; + + /** + * @return int + */ + public function getMessageType(): int; + + + /** + * @param string $title + * + * @return IStratosMessage + */ + public function setTitle(string $title): IStratosMessage; + + /** + * @return string + */ + public function getTitle(): string; + + + /** + * @param string $content + * + * @return IStratosMessage + */ + public function setContent(string $content): IStratosMessage; + + /** + * @return string + */ + public function getContent(): string; + + + /** + * @return string + */ + public function getDetail(): string; + + /** + * @param string $detail + * + * @return IStratosMessage + */ + public function setDetail(string $detail): IStratosMessage; + + + /** + * @param string $link + * + * @return IStratosMessage + */ + public function setLink(string $link): IStratosMessage; + + /** + * @return string + */ + public function getLink(): string; + +} + diff --git a/lib/public/Stratos/Model/IStratosStream.php b/lib/public/Stratos/Model/IStratosStream.php new file mode 100644 index 0000000000000..d52119d8dca2d --- /dev/null +++ b/lib/public/Stratos/Model/IStratosStream.php @@ -0,0 +1,151 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Stratos\Model; + + +/** + * Interface IStratosStream + * + * @since 18.0.0 + * + * @package OCP\Stratos + */ +interface IStratosStream { + + + const TTL_SHORT = 'short'; + const TTL_FEW_MINUTES = 'few_minutes'; + const TTL_FEW_HOURS = 'few_hours'; + const TTL_DAY = 'day'; + const TTL_LONG = 'long'; + const TTL_GODLIKE = 'godlike'; + + + /** + * @return int + */ + public function getId(): int; + + /** + * @param int $id + * + * @return IStratosStream + */ + public function setId(int $id): IStratosStream; + + + /** + * @return string + */ + public function getApp(): string; + + /** + * @param string $app + * + * @return IStratosStream + */ + public function setApp(string $app): IStratosStream; + + + /** + * @return string + */ + public function getSource(): string; + + /** + * @param string $source + * + * @return IStratosStream + */ + public function setSource(string $source): IStratosStream; + + + /** + * @return string + */ + public function getType(): string; + + /** + * @param string $type + * + * @return IStratosStream + */ + public function setType(string $type): IStratosStream; + + + /** + * @return string + */ + public function getTtl(): string; + + /** + * @param string $ttl + * + * @return IStratosStream + */ + public function setTtl(string $ttl): IStratosStream; + + + /** + * @return string + */ + public function getRecipient(): string; + + /** + * @param string $recipient + * + * @return IStratosStream + */ + public function setRecipient(string $recipient): IStratosStream; + + + /** + * @param array $import + * + * @return IStratosStream + */ + public function import(array $import): IStratosStream; + + + /** + * @param int $timestamp + * + * @return IStratosStream + */ + public function setCreation(int $timestamp): IStratosStream; + + /** + * @return int + */ + public function getCreation(): int; + +} + diff --git a/lib/public/Stratos/Service/IStratosService.php b/lib/public/Stratos/Service/IStratosService.php new file mode 100644 index 0000000000000..2d25cf05d9e2e --- /dev/null +++ b/lib/public/Stratos/Service/IStratosService.php @@ -0,0 +1,52 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Stratos\Service; + + +use OCP\Stratos\Model\IStratosStream; + + +/** + * Interface IStratosService + * + * @since 18.0.0 + * + * @package OCP\Stratos\Service + */ +interface IStratosService { + + + public function test(string $test); + + public function sendStreamToUser(IStratosStream $stream); + +} + From 8845677dc0d666123f36e69faa1260406df9efbd Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 2 Aug 2019 12:20:13 -0100 Subject: [PATCH 02/16] switch ttl to integer Signed-off-by: Maxence Lange --- lib/private/Stratos/Model/StratosStream.php | 14 +++++++------- lib/public/Stratos/Model/IStratosStream.php | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/private/Stratos/Model/StratosStream.php b/lib/private/Stratos/Model/StratosStream.php index 75802d4c04474..4fa29f1e924a2 100644 --- a/lib/private/Stratos/Model/StratosStream.php +++ b/lib/private/Stratos/Model/StratosStream.php @@ -52,8 +52,8 @@ class StratosStream implements IStratosStream, JsonSerializable { /** @var string */ private $type = ''; - /** @var string */ - private $ttl = ''; + /** @var int */ + private $ttl = 0; /** @var string */ private $app = ''; @@ -119,18 +119,18 @@ public function setType(string $type): IStratosStream { /** - * @return string + * @return int */ - public function getTtl(): string { + public function getTtl(): int { return $this->ttl; } /** - * @param string $ttl + * @param int $ttl * * @return IStratosStream */ - public function setTtl(string $ttl): IStratosStream { + public function setTtl(int $ttl): IStratosStream { $this->ttl = $ttl; return $this; @@ -221,7 +221,7 @@ public function setCreation(int $timestamp): IStratosStream { public function import(array $import): IStratosStream { $this->setType($this->get('type', $import)); $this->setApp($this->get('app', $import)); - $this->setTtl($this->get('ttl', $import)); + $this->setTtl($this->getInt('ttl', $import)); $this->setRecipient($this->get('recipient', $import)); $this->setSource($this->get('source', $import)); $this->setCreation($this->getInt('creation', $import)); diff --git a/lib/public/Stratos/Model/IStratosStream.php b/lib/public/Stratos/Model/IStratosStream.php index d52119d8dca2d..edc317947968a 100644 --- a/lib/public/Stratos/Model/IStratosStream.php +++ b/lib/public/Stratos/Model/IStratosStream.php @@ -41,12 +41,12 @@ interface IStratosStream { - const TTL_SHORT = 'short'; - const TTL_FEW_MINUTES = 'few_minutes'; - const TTL_FEW_HOURS = 'few_hours'; - const TTL_DAY = 'day'; - const TTL_LONG = 'long'; - const TTL_GODLIKE = 'godlike'; + const TTL_SHORT = 10; + const TTL_FEW_MINUTES = 180; + const TTL_FEW_HOURS = 7200; + const TTL_DAY = 24*3600; + const TTL_LONG = 24*3600*8; + const TTL_GODLIKE = 0; /** @@ -102,16 +102,16 @@ public function setType(string $type): IStratosStream; /** - * @return string + * @return int */ - public function getTtl(): string; + public function getTtl(): int; /** - * @param string $ttl + * @param int $ttl * * @return IStratosStream */ - public function setTtl(string $ttl): IStratosStream; + public function setTtl(int $ttl): IStratosStream; /** From e60d7f5ff062505fb49d76f05f094dcd8fd42eaf Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 9 Aug 2019 13:02:10 -0100 Subject: [PATCH 03/16] rework on models, +helper Signed-off-by: Maxence Lange --- lib/composer/composer/autoload_classmap.php | 15 +- lib/composer/composer/autoload_static.php | 15 +- .../Stratos/Model/Helper/StratosEvent.php | 141 +++++++++++++++ .../StratosNotification.php} | 119 +++++++------ .../{StratosStream.php => StratosItem.php} | 164 ++++++++++-------- lib/private/Stratos/Model/StratosWrapper.php | 153 ++++++++++++++++ lib/private/Stratos/StratosManager.php | 26 +-- lib/public/Stratos/Helper/IStratosHelper.php | 93 ++++++++++ lib/public/Stratos/IStratosManager.php | 12 +- .../Model/{ => Helper}/IStratosEvent.php | 41 ++++- .../IStratosNotification.php} | 74 ++++---- .../{IStratosStream.php => IStratosItem.php} | 79 +++++---- .../Stratos/Model/IStratosWrapper.php} | 63 +++++-- .../Stratos/Service/IStratosService.php | 7 +- 14 files changed, 766 insertions(+), 236 deletions(-) create mode 100644 lib/private/Stratos/Model/Helper/StratosEvent.php rename lib/private/Stratos/Model/{StratosMessage.php => Helper/StratosNotification.php} (50%) rename lib/private/Stratos/Model/{StratosStream.php => StratosItem.php} (56%) create mode 100644 lib/private/Stratos/Model/StratosWrapper.php create mode 100644 lib/public/Stratos/Helper/IStratosHelper.php rename lib/public/Stratos/Model/{ => Helper}/IStratosEvent.php (67%) rename lib/public/Stratos/Model/{IStratosMessage.php => Helper/IStratosNotification.php} (63%) rename lib/public/Stratos/Model/{IStratosStream.php => IStratosItem.php} (67%) rename lib/{private/Stratos/Model/StratosEvent.php => public/Stratos/Model/IStratosWrapper.php} (54%) diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 690a134482902..ea83d0da1ed22 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -407,10 +407,12 @@ 'OCP\\Share_Backend_Collection' => $baseDir . '/lib/public/Share_Backend_Collection.php', 'OCP\\Share_Backend_File_Dependent' => $baseDir . '/lib/public/Share_Backend_File_Dependent.php', 'OCP\\Stratos\\Exceptions\\StratosInstallException' => $baseDir . '/lib/public/Stratos/Exceptions/StratosInstallException.php', + 'OCP\\Stratos\\Helper\\IStratosHelper' => $baseDir . '/lib/public/Stratos/Helper/IStratosHelper.php', 'OCP\\Stratos\\IStratosManager' => $baseDir . '/lib/public/Stratos/IStratosManager.php', - 'OCP\\Stratos\\Model\\IStratosEvent' => $baseDir . '/lib/public/Stratos/Model/IStratosEvent.php', - 'OCP\\Stratos\\Model\\IStratosMessage' => $baseDir . '/lib/public/Stratos/Model/IStratosMessage.php', - 'OCP\\Stratos\\Model\\IStratosStream' => $baseDir . '/lib/public/Stratos/Model/IStratosStream.php', + 'OCP\\Stratos\\Model\\IStratosEvent' => $baseDir . '/lib/public/Stratos/Model/Helper/IStratosEvent.php', + 'OCP\\Stratos\\Model\\IStratosItem' => $baseDir . '/lib/public/Stratos/Model/IStratosItem.php', + 'OCP\\Stratos\\Model\\IStratosNotification' => $baseDir . '/lib/public/Stratos/Model/Helper/IStratosNotification.php', + 'OCP\\Stratos\\Model\\IStratosWrapper' => $baseDir . '/lib/public/Stratos/Model/IStratosWrapper.php', 'OCP\\Stratos\\Service\\IStratosService' => $baseDir . '/lib/public/Stratos/Service/IStratosService.php', 'OCP\\Support\\CrashReport\\ICollectBreadcrumbs' => $baseDir . '/lib/public/Support/CrashReport/ICollectBreadcrumbs.php', 'OCP\\Support\\CrashReport\\IMessageReporter' => $baseDir . '/lib/public/Support/CrashReport/IMessageReporter.php', @@ -1196,10 +1198,11 @@ 'OC\\Share\\Helper' => $baseDir . '/lib/private/Share/Helper.php', 'OC\\Share\\SearchResultSorter' => $baseDir . '/lib/private/Share/SearchResultSorter.php', 'OC\\Share\\Share' => $baseDir . '/lib/private/Share/Share.php', - 'OC\\Stratos\\StratosEvent' => $baseDir . '/lib/private/Stratos/Model/StratosEvent.php', + 'OC\\Stratos\\Model\\Helper\\StratosEvent' => $baseDir . '/lib/private/Stratos/Model/Helper/StratosEvent.php', + 'OC\\Stratos\\Model\\Helper\\StratosNotification' => $baseDir . '/lib/private/Stratos/Model/Helper/StratosNotification.php', + 'OC\\Stratos\\Model\\StratosItem' => $baseDir . '/lib/private/Stratos/Model/StratosItem.php', + 'OC\\Stratos\\Model\\StratosWrapper' => $baseDir . '/lib/private/Stratos/Model/StratosWrapper.php', 'OC\\Stratos\\StratosManager' => $baseDir . '/lib/private/Stratos/StratosManager.php', - 'OC\\Stratos\\StratosMessage' => $baseDir . '/lib/private/Stratos/Model/StratosMessage.php', - 'OC\\Stratos\\StratosStream' => $baseDir . '/lib/private/Stratos/Model/StratosStream.php', 'OC\\Streamer' => $baseDir . '/lib/private/Streamer.php', 'OC\\SubAdmin' => $baseDir . '/lib/private/SubAdmin.php', 'OC\\Support\\CrashReport\\Registry' => $baseDir . '/lib/private/Support/CrashReport/Registry.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index c998ddd347d8f..a934f59f9efb8 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -441,10 +441,12 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Share_Backend_Collection' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_Collection.php', 'OCP\\Share_Backend_File_Dependent' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_File_Dependent.php', 'OCP\\Stratos\\Exceptions\\StratosInstallException' => __DIR__ . '/../../..' . '/lib/public/Stratos/Exceptions/StratosInstallException.php', + 'OCP\\Stratos\\Helper\\IStratosHelper' => __DIR__ . '/../../..' . '/lib/public/Stratos/Helper/IStratosHelper.php', 'OCP\\Stratos\\IStratosManager' => __DIR__ . '/../../..' . '/lib/public/Stratos/IStratosManager.php', - 'OCP\\Stratos\\Model\\IStratosEvent' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosEvent.php', - 'OCP\\Stratos\\Model\\IStratosMessage' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosMessage.php', - 'OCP\\Stratos\\Model\\IStratosStream' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosStream.php', + 'OCP\\Stratos\\Model\\IStratosEvent' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/Helper/IStratosEvent.php', + 'OCP\\Stratos\\Model\\IStratosItem' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosItem.php', + 'OCP\\Stratos\\Model\\IStratosNotification' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/Helper/IStratosNotification.php', + 'OCP\\Stratos\\Model\\IStratosWrapper' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosWrapper.php', 'OCP\\Stratos\\Service\\IStratosService' => __DIR__ . '/../../..' . '/lib/public/Stratos/Service/IStratosService.php', 'OCP\\Support\\CrashReport\\ICollectBreadcrumbs' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/ICollectBreadcrumbs.php', 'OCP\\Support\\CrashReport\\IMessageReporter' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/IMessageReporter.php', @@ -1230,10 +1232,11 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Share\\Helper' => __DIR__ . '/../../..' . '/lib/private/Share/Helper.php', 'OC\\Share\\SearchResultSorter' => __DIR__ . '/../../..' . '/lib/private/Share/SearchResultSorter.php', 'OC\\Share\\Share' => __DIR__ . '/../../..' . '/lib/private/Share/Share.php', - 'OC\\Stratos\\StratosEvent' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosEvent.php', + 'OC\\Stratos\\Model\\Helper\\StratosEvent' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/Helper/StratosEvent.php', + 'OC\\Stratos\\Model\\Helper\\StratosNotification' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/Helper/StratosNotification.php', + 'OC\\Stratos\\Model\\StratosItem' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosItem.php', + 'OC\\Stratos\\Model\\StratosWrapper' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosWrapper.php', 'OC\\Stratos\\StratosManager' => __DIR__ . '/../../..' . '/lib/private/Stratos/StratosManager.php', - 'OC\\Stratos\\StratosMessage' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosMessage.php', - 'OC\\Stratos\\StratosStream' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosStream.php', 'OC\\Streamer' => __DIR__ . '/../../..' . '/lib/private/Streamer.php', 'OC\\SubAdmin' => __DIR__ . '/../../..' . '/lib/private/SubAdmin.php', 'OC\\Support\\CrashReport\\Registry' => __DIR__ . '/../../..' . '/lib/private/Support/CrashReport/Registry.php', diff --git a/lib/private/Stratos/Model/Helper/StratosEvent.php b/lib/private/Stratos/Model/Helper/StratosEvent.php new file mode 100644 index 0000000000000..713995f9548e8 --- /dev/null +++ b/lib/private/Stratos/Model/Helper/StratosEvent.php @@ -0,0 +1,141 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Stratos\Model\Helper; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use JsonSerializable; +use OCP\Stratos\Model\IStratosEvent; + + +/** + * Class StratosEvent + * + * @package OC\Stratos\Model\Helper + */ +class StratosEvent implements IStratosEvent, JsonSerializable { + + + use TArrayTools; + + + /** @var string */ + private $app = ''; + + /** @var string */ + private $command = ''; + + /** @var array */ + private $payload = []; + + + /** + * StratosEvent constructor. + * + * @param string $app + * @param string $command + */ + public function __construct($app = '', $command = '') { + $this->app = $app; + $this->command = $command; + } + + + /** + * @return string + */ + public function getApp(): string { + return $this->app; + } + + /** + * @param string $app + * + * @return IStratosEvent + */ + public function setApp(string $app): IStratosEvent { + $this->app = $app; + + return $this; + } + + + /** + * @return string + */ + public function getCommand(): string { + return $this->command; + } + + /** + * @param string $command + * + * @return IStratosEvent + */ + public function setCommand(string $command): IStratosEvent { + $this->command = $command; + + return $this; + } + + + /** + * @return array + */ + public function getPayload(): array { + return $this->payload; + } + + /** + * @param array $payload + * + * @return IStratosEvent + */ + public function setPayload(array $payload): IStratosEvent { + $this->payload = $payload; + + return $this; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return [ + 'app' => $this->getApp(), + 'command' => $this->getCommand(), + 'payload' => $this->getPayload() + ]; + } + +} + diff --git a/lib/private/Stratos/Model/StratosMessage.php b/lib/private/Stratos/Model/Helper/StratosNotification.php similarity index 50% rename from lib/private/Stratos/Model/StratosMessage.php rename to lib/private/Stratos/Model/Helper/StratosNotification.php index cdb1075508260..80d94f50e81ea 100644 --- a/lib/private/Stratos/Model/StratosMessage.php +++ b/lib/private/Stratos/Model/Helper/StratosNotification.php @@ -28,72 +28,75 @@ */ -namespace OC\Stratos; +namespace OC\Stratos\Model\Helper; +use daita\NcSmallPhpTools\Traits\TArrayTools; use JsonSerializable; -use OCP\Stratos\Model\IStratosMessage; +use OCP\Stratos\Model\IStratosItem; +use OCP\Stratos\Model\IStratosNotification; /** - * Class StratosManager + * Class StratosNotification * - * @package OC\Stratos + * @package OC\Stratos\Model\Helper */ -class StratosMessage extends StratosStream implements IStratosMessage, JsonSerializable { +class StratosNotification implements IStratosNotification, JsonSerializable { - const TYPE = 'Message'; + use TArrayTools; - /** @var int */ - private $messageType = 0; + /** @var string */ + private $app = ''; /** @var string */ private $title = ''; /** @var string */ - private $content = ''; + private $message = ''; /** @var string */ - private $detail = ''; + private $level = ''; /** @var string */ private $link = ''; + /** @var int */ + private $ttl = -1; + /** - * StratosMessage constructor. + * StratosNotification constructor. * * @param string $app - * @param string $source + * @param int $ttl */ - public function __construct(string $app = '', string $source = '') { - parent::__construct($app, $source); - - $this->setType(StratosMessage::TYPE); + public function __construct($app = '', $ttl = IStratosItem::TTL_INSTANT) { + $this->app = $app; + $this->ttl = $ttl; } /** - * @return int + * @return string */ - public function getMessageType(): int { - return $this->messageType; + public function getApp(): string { + return $this->app; } /** - * @param int $messageType + * @param string $app * - * @return IStratosMessage + * @return IStratosNotification */ - public function setMessageType(int $messageType): IStratosMessage { - $this->messageType = $messageType; + public function setApp(string $app): IStratosNotification { + $this->app = $app; return $this; } - /** * @return string */ @@ -104,9 +107,9 @@ public function getTitle(): string { /** * @param string $title * - * @return IStratosMessage + * @return IStratosNotification */ - public function setTitle(string $title): IStratosMessage { + public function setTitle(string $title): IStratosNotification { $this->title = $title; return $this; @@ -116,17 +119,17 @@ public function setTitle(string $title): IStratosMessage { /** * @return string */ - public function getContent(): string { - return $this->content; + public function getMessage(): string { + return $this->message; } /** - * @param string $content + * @param string $message * - * @return IStratosMessage + * @return IStratosNotification */ - public function setContent(string $content): IStratosMessage { - $this->content = $content; + public function setMessage(string $message): IStratosNotification { + $this->message = $message; return $this; } @@ -135,17 +138,17 @@ public function setContent(string $content): IStratosMessage { /** * @return string */ - public function getDetail(): string { - return $this->detail; + public function getLevel(): string { + return $this->level; } /** - * @param string $detail + * @param string $level * - * @return IStratosMessage + * @return IStratosNotification */ - public function setDetail(string $detail): IStratosMessage { - $this->detail = $detail; + public function setLevel(string $level): IStratosNotification { + $this->level = $level; return $this; } @@ -161,28 +164,46 @@ public function getLink(): string { /** * @param string $link * - * @return IStratosMessage + * @return IStratosNotification */ - public function setLink(string $link): IStratosMessage { + public function setLink(string $link): IStratosNotification { $this->link = $link; return $this; } + /** + * @return int + */ + public function getTtl(): int { + return $this->ttl; + } + + /** + * @param int $ttl + * + * @return IStratosNotification + */ + public function setTtl(int $ttl): IStratosNotification { + $this->ttl = $ttl; + + return $this; + } + + /** * @return array */ public function jsonSerialize(): array { - return array_merge( - parent::jsonSerialize(), - [ - 'message_type' => $this->getMessageType(), - 'title' => $this->getTitle(), - 'content' => $this->getContent(), - 'link' => $this->getLink() - ] - ); + return [ + 'app' => $this->getApp(), + 'title' => $this->getTitle(), + 'type' => $this->getMessage(), + 'source' => $this->getLevel(), + 'link' => $this->getLink(), + 'ttl' => $this->getTtl() + ]; } } diff --git a/lib/private/Stratos/Model/StratosStream.php b/lib/private/Stratos/Model/StratosItem.php similarity index 56% rename from lib/private/Stratos/Model/StratosStream.php rename to lib/private/Stratos/Model/StratosItem.php index 4fa29f1e924a2..42cc82e9a5659 100644 --- a/lib/private/Stratos/Model/StratosStream.php +++ b/lib/private/Stratos/Model/StratosItem.php @@ -28,32 +28,31 @@ */ -namespace OC\Stratos; +namespace OC\Stratos\Model; use daita\NcSmallPhpTools\Traits\TArrayTools; +use daita\NcSmallPhpTools\Traits\TStringTools; use JsonSerializable; -use OCP\Stratos\Model\IStratosStream; +use OCP\Stratos\Model\IStratosItem; /** - * Class StratosManager + * Class StratosItem * - * @package OC\Stratos + * @package OC\Stratos\Model */ -class StratosStream implements IStratosStream, JsonSerializable { +class StratosItem implements IStratosItem, JsonSerializable { use TArrayTools; + use TStringTools; /** @var int */ private $id = 0; /** @var string */ - private $type = ''; - - /** @var int */ - private $ttl = 0; + private $token = ''; /** @var string */ private $app = ''; @@ -61,25 +60,44 @@ class StratosStream implements IStratosStream, JsonSerializable { /** @var string */ private $source = ''; + /** @var array */ + private $payload = []; + /** @var string */ - private $recipient = ''; + private $type = ''; + + /** @var int */ + private $ttl = -1; /** @var int */ private $creation = 0; /** - * StratosMessage constructor. + * StratosItem constructor. * * @param string $app - * @param string $source + * @param string $type */ - public function __construct(string $app = '', string $source = '') { + public function __construct($app = '', $type = '') { $this->app = $app; - $this->source = $source; + $this->type = $type; + + $this->token = $this->uuid(11); } + /** + * @param int $id + * + * @return StratosItem + */ + public function setId(int $id): IStratosItem { + $this->id = $id; + + return $this; + } + /** * @return int */ @@ -87,13 +105,21 @@ public function getId(): int { return $this->id; } + /** - * @param int $id + * @return string + */ + public function getToken(): string { + return $this->token; + } + + /** + * @param string $token * - * @return IStratosStream + * @return StratosItem */ - public function setId(int $id): IStratosStream { - $this->id = $id; + public function setToken(string $token): IStratosItem { + $this->token = $token; return $this; } @@ -102,55 +128,55 @@ public function setId(int $id): IStratosStream { /** * @return string */ - public function getType(): string { - return $this->type; + public function getApp(): string { + return $this->app; } /** - * @param string $type + * @param string $app * - * @return IStratosStream + * @return IStratosItem */ - public function setType(string $type): IStratosStream { - $this->type = $type; + public function setApp(string $app): IStratosItem { + $this->app = $app; return $this; } /** - * @return int + * @return string */ - public function getTtl(): int { - return $this->ttl; + public function getSource(): string { + return $this->source; } /** - * @param int $ttl + * @param string $source * - * @return IStratosStream + * @return IStratosItem */ - public function setTtl(int $ttl): IStratosStream { - $this->ttl = $ttl; + public function setSource(string $source): IStratosItem { + $this->source = $source; return $this; } /** - * @return string + * @return array */ - public function getApp(): string { - return $this->app; + public function getPayload(): array { + return $this->payload; } /** - * @param string $app + * @param array $payload * - * @return IStratosStream + * @return StratosItem */ - public function setApp(string $app): IStratosStream { - $this->app = $app; + public function setPayload(array $payload): IStratosItem { + $this->payload = $payload; return $this; } @@ -159,36 +185,36 @@ public function setApp(string $app): IStratosStream { /** * @return string */ - public function getSource(): string { - return $this->source; + public function getType(): string { + return $this->type; } /** - * @param string $source + * @param string $type * - * @return IStratosStream + * @return StratosItem */ - public function setSource(string $source): IStratosStream { - $this->source = $source; + public function setType(string $type): IStratosItem { + $this->type = $type; return $this; } /** - * @return string + * @return int */ - public function getRecipient(): string { - return $this->recipient; + public function getTtl(): int { + return $this->ttl; } /** - * @param string $recipient + * @param int $ttl * - * @return IStratosStream + * @return StratosItem */ - public function setRecipient(string $recipient): IStratosStream { - $this->recipient = $recipient; + public function setTtl(int $ttl): IStratosItem { + $this->ttl = $ttl; return $this; } @@ -202,12 +228,12 @@ public function getCreation(): int { } /** - * @param int $timestamp + * @param int $creation * - * @return IStratosStream + * @return StratosItem */ - public function setCreation(int $timestamp): IStratosStream { - $this->creation = $timestamp; + public function setCreation(int $creation): IStratosItem { + $this->creation = $creation; return $this; } @@ -216,13 +242,15 @@ public function setCreation(int $timestamp): IStratosStream { /** * @param array $import * - * @return IStratosStream + * @return IStratosItem */ - public function import(array $import): IStratosStream { - $this->setType($this->get('type', $import)); - $this->setApp($this->get('app', $import)); - $this->setTtl($this->getInt('ttl', $import)); - $this->setRecipient($this->get('recipient', $import)); + public function import(array $import): IStratosItem { + $this->setId($this->getInt('id', $import, 0)); + $this->setToken($this->get('token', $import, '')); + $this->setType($this->get('type', $import, '')); + $this->setApp($this->get('app', $import, '')); + $this->setTtl($this->getInt('ttl', $import, -1)); + $this->setPayload($this->getArray('payload', $import, [])); $this->setSource($this->get('source', $import)); $this->setCreation($this->getInt('creation', $import)); @@ -235,13 +263,13 @@ public function import(array $import): IStratosStream { */ public function jsonSerialize(): array { return [ - 'id' => $this->getId(), - 'ttl' => $this->getTtl(), - 'app' => $this->getApp(), - 'source' => $this->getSource(), - 'type' => $this->getType(), - 'recipient' => $this->getRecipient(), - 'creation' => $this->getCreation() + 'token' => $this->getToken(), + 'app' => $this->getApp(), + 'type' => $this->getType(), + 'source' => $this->getSource(), + 'payload' => $this->getPayload(), + 'ttl' => $this->getTtl(), + 'creation' => $this->getCreation() ]; } diff --git a/lib/private/Stratos/Model/StratosWrapper.php b/lib/private/Stratos/Model/StratosWrapper.php new file mode 100644 index 0000000000000..1871f6f8fe61b --- /dev/null +++ b/lib/private/Stratos/Model/StratosWrapper.php @@ -0,0 +1,153 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Stratos\Model; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use JsonSerializable; +use OCP\Stratos\Model\IStratosItem; +use OCP\Stratos\Model\IStratosWrapper; + + +/** + * Class StratosManager + * + * @package OC\Stratos\Model + */ +class StratosWrapper implements IStratosWrapper, JsonSerializable { + + + use TArrayTools; + + + /** @var IStratosItem */ + private $item; + + /** @var array */ + private $recipients = []; + + /** @var int */ + private $creation = 0; + + + public function __construct(array $recipients = []) { + $this->recipients = $recipients; + + return $this; + } + + + /** + * @return bool + */ + public function hasItem(): bool { + return ($this->item !== null); + } + + /** + * @return IStratosItem + */ + public function getItem(): IStratosItem { + return $this->item; + } + + /** + * @param IStratosItem $item + * + * @return IStratosWrapper + */ + public function setItem(IStratosItem $item): IStratosWrapper { + $this->item = $item; + + return $this; + } + + + /** + * @return array + */ + public function getRecipients(): array { + return $this->recipients; + } + + /** + * @param array $recipients + * + * @return IStratosWrapper + */ + public function setRecipients(array $recipients): IStratosWrapper { + $this->recipients = $recipients; + + return $this; + } + + /** + * @param string $recipient + * + * @return IStratosWrapper + */ + public function addRecipient(string $recipient): IStratosWrapper { + if (!in_array($recipient, $this->recipients)) { + $this->recipients[] = $recipient; + } + + return $this; + } + + + /** + * @param array $import + * + * @return self + */ + public function import(array $import): IStratosWrapper { + $item = new StratosItem(); + $item->import($this->getArray('item', $import, [])); + + $this->setItem($item); + $this->setRecipients($this->getArray('recipients', $import, [])); + + return $this; + } + + + /** + * @return mixed|void + */ + public function jsonSerialize(): array { + return [ + 'item' => ($this->hasItem()) ? $this->getItem() : null, + 'recipients' => $this->getRecipients() + ]; + } + +} + diff --git a/lib/private/Stratos/StratosManager.php b/lib/private/Stratos/StratosManager.php index e2c7b1cf88d81..82d8bf20e32ec 100644 --- a/lib/private/Stratos/StratosManager.php +++ b/lib/private/Stratos/StratosManager.php @@ -32,6 +32,7 @@ use OCP\Stratos\Exceptions\StratosInstallException; +use OCP\Stratos\Helper\IStratosHelper; use OCP\Stratos\IStratosManager; use OCP\Stratos\Service\IStratosService; @@ -47,14 +48,20 @@ class StratosManager implements IStratosManager { /** @var IStratosService */ private $stratosService; + /** @var IStratosHelper */ + private $stratosHelper; + /** * @param IStratosService $stratosService + * @param IStratosHelper $stratosHelper * * @since 18.0.0 */ - public function registerStratosService(IStratosService $stratosService) { + public function registerStratos(IStratosService $stratosService, IStratosHelper $stratosHelper + ) { $this->stratosService = $stratosService; + $this->stratosHelper = $stratosHelper; } @@ -85,16 +92,13 @@ public function getStratosService(): IStratosService { /** - * @param string $test + * @return IStratosHelper + * @throws StratosInstallException */ - public function test(string $test) { - try { - $this->checkRegistration(); - } catch (StratosInstallException $e) { - return; - } + public function getStratosHelper(): IStratosHelper { + $this->checkRegistration(); - $this->stratosService->test($test); + return $this->stratosHelper; } @@ -102,8 +106,8 @@ public function test(string $test) { * @throws StratosInstallException */ private function checkRegistration() { - if ($this->stratosService === null) { - throw new StratosInstallException('stratosService is not registered'); + if ($this->stratosService === null || $this->stratosHelper === null) { + throw new StratosInstallException('Stratos is not available. Please check the Stratos App is installed and enabled'); } } diff --git a/lib/public/Stratos/Helper/IStratosHelper.php b/lib/public/Stratos/Helper/IStratosHelper.php new file mode 100644 index 0000000000000..1a18350715aad --- /dev/null +++ b/lib/public/Stratos/Helper/IStratosHelper.php @@ -0,0 +1,93 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Stratos\Helper; + + +use OCP\Stratos\Model\IStratosEvent; +use OCP\Stratos\Model\IStratosNotification; +use OCP\Stratos\Model\IStratosWrapper; + + +/** + * Interface IStratosHelper + * + * @since 18.0.0 + * + * @package OCP\Stratos\Helper + */ +interface IStratosHelper { + + + /** + * @param string $userId + * + * @return IStratosWrapper + */ + public function test(string $userId): IStratosWrapper; + + + /** + * @param IStratosNotification $notification + * @param string $userId + * + * @return IStratosWrapper + */ + public function pushNotification(IStratosNotification $notification, string $userId + ): IStratosWrapper; + + /** + * @param IStratosNotification $notification + * @param array $users + * + * @return IStratosWrapper + */ + public function pushNotifications(IStratosNotification $notification, array $users + ): IStratosWrapper; + + + /** + * @param IStratosEvent $event + * @param string $userId + * + * @return IStratosWrapper + */ + public function broadcastEvent(IStratosEvent $event, string $userId): IStratosWrapper; + + /** + * @param IStratosEvent $event + * @param array $users + * + * @return IStratosWrapper + */ + public function broadcastEvents(IStratosEvent $event, array $users): IStratosWrapper; + +} + diff --git a/lib/public/Stratos/IStratosManager.php b/lib/public/Stratos/IStratosManager.php index 1cd11f24d1f11..3ec10a87afa45 100644 --- a/lib/public/Stratos/IStratosManager.php +++ b/lib/public/Stratos/IStratosManager.php @@ -31,6 +31,8 @@ namespace OCP\Stratos; +use OCP\Stratos\Exceptions\StratosInstallException; +use OCP\Stratos\Helper\IStratosHelper; use OCP\Stratos\Service\IStratosService; @@ -48,11 +50,11 @@ interface IStratosManager { * Register a IStratosService. * * @param IStratosService $stratosService + * @param IStratosHelper $stratosHelper * * @since 18.0.0 - * */ - public function registerStratosService(IStratosService $stratosService); + public function registerStratos(IStratosService $stratosService, IStratosHelper $stratosHelper); /** @@ -63,14 +65,16 @@ public function isAvailable(): bool; /** * @return IStratosService + * @throws StratosInstallException */ public function getStratosService(): IStratosService; /** - * @param string $test + * @return IStratosHelper + * @throws StratosInstallException */ - public function test(string $test); + public function getStratosHelper(): IStratosHelper; } diff --git a/lib/public/Stratos/Model/IStratosEvent.php b/lib/public/Stratos/Model/Helper/IStratosEvent.php similarity index 67% rename from lib/public/Stratos/Model/IStratosEvent.php rename to lib/public/Stratos/Model/Helper/IStratosEvent.php index 81fb07aa7f740..9a2cfbc7a3a1a 100644 --- a/lib/public/Stratos/Model/IStratosEvent.php +++ b/lib/public/Stratos/Model/Helper/IStratosEvent.php @@ -32,7 +32,7 @@ /** - * Interface IStratosMessage + * Interface IStratosEvent * * @since 18.0.0 * @@ -40,5 +40,44 @@ */ interface IStratosEvent { + + /** + * @return string + */ + public function getApp(): string; + + /** + * @param string $app + * + * @return self + */ + public function setApp(string $app): self; + + + /** + * @return string + */ + public function getCommand(): string; + + /** + * @param string $title + * + * @return self + */ + public function setCommand(string $title): self; + + + /** + * @return array + */ + public function getPayload(): array; + + /** + * @param array $payload + * + * @return self + */ + public function setPayload(array $payload): self; + } diff --git a/lib/public/Stratos/Model/IStratosMessage.php b/lib/public/Stratos/Model/Helper/IStratosNotification.php similarity index 63% rename from lib/public/Stratos/Model/IStratosMessage.php rename to lib/public/Stratos/Model/Helper/IStratosNotification.php index 3f620e636612a..281f5f370da2d 100644 --- a/lib/public/Stratos/Model/IStratosMessage.php +++ b/lib/public/Stratos/Model/Helper/IStratosNotification.php @@ -32,85 +32,97 @@ /** - * Interface IStratosMessage + * Interface IStratosNotification * * @since 18.0.0 * * @package OCP\Stratos */ -interface IStratosMessage extends IStratosStream { +interface IStratosNotification { - const TYPE_CONFIRMATION = 1; - const TYPE_NOTE = 2; - const TYPE_STATUS = 3; - const TYPE_WARNING = 4; - const TYPE_ERROR = 5; + const LEVEL_SUCCESS = 'success'; + const LEVEL_MESSAGE = 'message'; + const LEVEL_WARNING = 'warning'; + const LEVEL_ERROR = 'error'; /** - * @param int $type - * - * @return IStratosMessage + * @return string */ - public function setMessageType(int $type): IStratosMessage; + public function getApp(): string; /** - * @return int + * @param string $app + * + * @return self */ - public function getMessageType(): int; + public function setApp(string $app): self; + /** + * @return string + */ + public function getTitle(): string; + /** * @param string $title * - * @return IStratosMessage + * @return self */ - public function setTitle(string $title): IStratosMessage; + public function setTitle(string $title): self; + /** * @return string */ - public function getTitle(): string; - + public function getMessage(): string; /** - * @param string $content + * @param string $message * - * @return IStratosMessage + * @return self */ - public function setContent(string $content): IStratosMessage; + public function setMessage(string $message): self; + /** * @return string */ - public function getContent(): string; + public function getLink(): string; + + /** + * @param string $link + * + * @return self + */ + public function setLink(string $link): self; /** * @return string */ - public function getDetail(): string; + public function getLevel(): string; /** - * @param string $detail + * @param string $level * - * @return IStratosMessage + * @return self */ - public function setDetail(string $detail): IStratosMessage; + public function setLevel(string $level): self; /** - * @param string $link - * - * @return IStratosMessage + * @return int */ - public function setLink(string $link): IStratosMessage; + public function getTtl(): int; /** - * @return string + * @param int $ttl + * + * @return self */ - public function getLink(): string; + public function setTtl(int $ttl): self; } diff --git a/lib/public/Stratos/Model/IStratosStream.php b/lib/public/Stratos/Model/IStratosItem.php similarity index 67% rename from lib/public/Stratos/Model/IStratosStream.php rename to lib/public/Stratos/Model/IStratosItem.php index edc317947968a..6aa233ad29d13 100644 --- a/lib/public/Stratos/Model/IStratosStream.php +++ b/lib/public/Stratos/Model/IStratosItem.php @@ -32,34 +32,37 @@ /** - * Interface IStratosStream + * Interface IStratosItem * * @since 18.0.0 * * @package OCP\Stratos */ -interface IStratosStream { +interface IStratosItem { - const TTL_SHORT = 10; + const TTL_INSTANT = 15; const TTL_FEW_MINUTES = 180; const TTL_FEW_HOURS = 7200; - const TTL_DAY = 24*3600; - const TTL_LONG = 24*3600*8; + const TTL_DAY = 24 * 3600; + const TTL_LONG = 24 * 3600 * 8; const TTL_GODLIKE = 0; + const TYPE_NOTIFICATION = 'Notification'; + const TYPE_EVENT = 'Event'; + const TYPE_WHATSNEW = 'WhatsNew'; + /** * @return int */ public function getId(): int; + /** - * @param int $id - * - * @return IStratosStream + * @return string */ - public function setId(int $id): IStratosStream; + public function getToken(): string; /** @@ -70,9 +73,9 @@ public function getApp(): string; /** * @param string $app * - * @return IStratosStream + * @return self */ - public function setApp(string $app): IStratosStream; + public function setApp(string $app): self; /** @@ -83,69 +86,69 @@ public function getSource(): string; /** * @param string $source * - * @return IStratosStream + * @return self */ - public function setSource(string $source): IStratosStream; + public function setSource(string $source): self; /** - * @return string + * @return array */ - public function getType(): string; + public function getPayload(): array; /** - * @param string $type + * @param array $payload * - * @return IStratosStream + * @return self */ - public function setType(string $type): IStratosStream; + public function setPayload(array $payload): self; /** - * @return int + * @return string */ - public function getTtl(): int; + public function getType(): string; /** - * @param int $ttl + * @param string $type * - * @return IStratosStream + * @return self */ - public function setTtl(int $ttl): IStratosStream; + public function setType(string $type): self; /** - * @return string - */ - public function getRecipient(): string; - - /** - * @param string $recipient - * - * @return IStratosStream + * @return int */ - public function setRecipient(string $recipient): IStratosStream; - + public function getTtl(): int; /** - * @param array $import + * @param int $ttl * - * @return IStratosStream + * @return self */ - public function import(array $import): IStratosStream; + public function setTtl(int $ttl): self; /** * @param int $timestamp * - * @return IStratosStream + * @return self */ - public function setCreation(int $timestamp): IStratosStream; + public function setCreation(int $timestamp): self; /** * @return int */ public function getCreation(): int; + + /** + * @param array $import + * + * @return self + */ + public function import(array $import): self; + } diff --git a/lib/private/Stratos/Model/StratosEvent.php b/lib/public/Stratos/Model/IStratosWrapper.php similarity index 54% rename from lib/private/Stratos/Model/StratosEvent.php rename to lib/public/Stratos/Model/IStratosWrapper.php index bdd7a3ba86bd5..5b4daa91c3f05 100644 --- a/lib/private/Stratos/Model/StratosEvent.php +++ b/lib/public/Stratos/Model/IStratosWrapper.php @@ -9,7 +9,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2019, Maxence Lange + * @copyright 2018, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -28,34 +28,63 @@ */ -namespace OC\Stratos; - - -use JsonSerializable; -use OCP\Stratos\Model\IStratosEvent; +namespace OCP\Stratos\Model; /** - * Class StratosEvent + * Interface IStratosWrapper + * + * @since 18.0.0 * - * @package OC\Stratos + * @package OCP\Stratos */ -class StratosEvent extends StratosStream implements IStratosEvent, JsonSerializable { +interface IStratosWrapper { - const TYPE = 'Event'; + /** + * @return bool + */ + public function hasItem(): bool; + + /** + * @return IStratosItem + */ + public function getItem(): IStratosItem; + + /** + * @param IStratosItem $item + * + * @return IStratosWrapper + */ + public function setItem(IStratosItem $item): self; /** * @return array */ - public function jsonSerialize(): array { - return array_merge( - parent::jsonSerialize(), - [ - ] - ); - } + public function getRecipients(): array; + + /** + * @param array $recipients + * + * @return self + */ + public function setRecipients(array $recipients): self; + + /** + * @param string $recipient + * + * @return IStratosWrapper + */ + public function addRecipient(string $recipient): self; + + + /** + * @param array $import + * + * @return self + */ + public function import(array $import): self; } diff --git a/lib/public/Stratos/Service/IStratosService.php b/lib/public/Stratos/Service/IStratosService.php index 2d25cf05d9e2e..248bcf6346aba 100644 --- a/lib/public/Stratos/Service/IStratosService.php +++ b/lib/public/Stratos/Service/IStratosService.php @@ -31,7 +31,7 @@ namespace OCP\Stratos\Service; -use OCP\Stratos\Model\IStratosStream; +use OCP\Stratos\Model\IStratosItem; /** @@ -43,10 +43,7 @@ */ interface IStratosService { - - public function test(string $test); - - public function sendStreamToUser(IStratosStream $stream); + public function pushItemToUser(IStratosItem $stream, string $userId); } From c46a0bb1454387f4403f9c3f396b0f50c337e1c7 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 9 Aug 2019 19:14:06 -0100 Subject: [PATCH 04/16] switching to IStratosRecipients Signed-off-by: Maxence Lange --- lib/composer/composer/autoload_classmap.php | 6 +- lib/composer/composer/autoload_static.php | 6 +- .../Stratos/Model/Helper/StratosEvent.php | 19 ++- .../Model/Helper/StratosNotification.php | 23 ++-- .../Stratos/Model/StratosRecipients.php | 121 ++++++++++++++++++ lib/private/Stratos/Model/StratosWrapper.php | 26 +++- lib/public/Stratos/Helper/IStratosHelper.php | 18 +-- .../Stratos/Model/Helper/IStratosEvent.php | 9 +- .../Model/Helper/IStratosNotification.php | 9 +- .../Stratos/Model/IStratosRecipients.php | 82 ++++++++++++ lib/public/Stratos/Model/IStratosWrapper.php | 8 ++ .../Stratos/Service/IStratosService.php | 15 ++- 12 files changed, 298 insertions(+), 44 deletions(-) create mode 100644 lib/private/Stratos/Model/StratosRecipients.php create mode 100644 lib/public/Stratos/Model/IStratosRecipients.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index ea83d0da1ed22..ee3ef98f37354 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -409,9 +409,10 @@ 'OCP\\Stratos\\Exceptions\\StratosInstallException' => $baseDir . '/lib/public/Stratos/Exceptions/StratosInstallException.php', 'OCP\\Stratos\\Helper\\IStratosHelper' => $baseDir . '/lib/public/Stratos/Helper/IStratosHelper.php', 'OCP\\Stratos\\IStratosManager' => $baseDir . '/lib/public/Stratos/IStratosManager.php', - 'OCP\\Stratos\\Model\\IStratosEvent' => $baseDir . '/lib/public/Stratos/Model/Helper/IStratosEvent.php', + 'OCP\\Stratos\\Model\\Helper\\IStratosEvent' => $baseDir . '/lib/public/Stratos/Model/Helper/IStratosEvent.php', + 'OCP\\Stratos\\Model\\Helper\\IStratosNotification' => $baseDir . '/lib/public/Stratos/Model/Helper/IStratosNotification.php', 'OCP\\Stratos\\Model\\IStratosItem' => $baseDir . '/lib/public/Stratos/Model/IStratosItem.php', - 'OCP\\Stratos\\Model\\IStratosNotification' => $baseDir . '/lib/public/Stratos/Model/Helper/IStratosNotification.php', + 'OCP\\Stratos\\Model\\IStratosRecipients' => $baseDir . '/lib/public/Stratos/Model/IStratosRecipients.php', 'OCP\\Stratos\\Model\\IStratosWrapper' => $baseDir . '/lib/public/Stratos/Model/IStratosWrapper.php', 'OCP\\Stratos\\Service\\IStratosService' => $baseDir . '/lib/public/Stratos/Service/IStratosService.php', 'OCP\\Support\\CrashReport\\ICollectBreadcrumbs' => $baseDir . '/lib/public/Support/CrashReport/ICollectBreadcrumbs.php', @@ -1201,6 +1202,7 @@ 'OC\\Stratos\\Model\\Helper\\StratosEvent' => $baseDir . '/lib/private/Stratos/Model/Helper/StratosEvent.php', 'OC\\Stratos\\Model\\Helper\\StratosNotification' => $baseDir . '/lib/private/Stratos/Model/Helper/StratosNotification.php', 'OC\\Stratos\\Model\\StratosItem' => $baseDir . '/lib/private/Stratos/Model/StratosItem.php', + 'OC\\Stratos\\Model\\StratosRecipients' => $baseDir . '/lib/private/Stratos/Model/StratosRecipients.php', 'OC\\Stratos\\Model\\StratosWrapper' => $baseDir . '/lib/private/Stratos/Model/StratosWrapper.php', 'OC\\Stratos\\StratosManager' => $baseDir . '/lib/private/Stratos/StratosManager.php', 'OC\\Streamer' => $baseDir . '/lib/private/Streamer.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index a934f59f9efb8..929a0a77c06d4 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -443,9 +443,10 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Stratos\\Exceptions\\StratosInstallException' => __DIR__ . '/../../..' . '/lib/public/Stratos/Exceptions/StratosInstallException.php', 'OCP\\Stratos\\Helper\\IStratosHelper' => __DIR__ . '/../../..' . '/lib/public/Stratos/Helper/IStratosHelper.php', 'OCP\\Stratos\\IStratosManager' => __DIR__ . '/../../..' . '/lib/public/Stratos/IStratosManager.php', - 'OCP\\Stratos\\Model\\IStratosEvent' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/Helper/IStratosEvent.php', + 'OCP\\Stratos\\Model\\Helper\\IStratosEvent' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/Helper/IStratosEvent.php', + 'OCP\\Stratos\\Model\\Helper\\IStratosNotification' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/Helper/IStratosNotification.php', 'OCP\\Stratos\\Model\\IStratosItem' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosItem.php', - 'OCP\\Stratos\\Model\\IStratosNotification' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/Helper/IStratosNotification.php', + 'OCP\\Stratos\\Model\\IStratosRecipients' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosRecipients.php', 'OCP\\Stratos\\Model\\IStratosWrapper' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosWrapper.php', 'OCP\\Stratos\\Service\\IStratosService' => __DIR__ . '/../../..' . '/lib/public/Stratos/Service/IStratosService.php', 'OCP\\Support\\CrashReport\\ICollectBreadcrumbs' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/ICollectBreadcrumbs.php', @@ -1235,6 +1236,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Stratos\\Model\\Helper\\StratosEvent' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/Helper/StratosEvent.php', 'OC\\Stratos\\Model\\Helper\\StratosNotification' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/Helper/StratosNotification.php', 'OC\\Stratos\\Model\\StratosItem' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosItem.php', + 'OC\\Stratos\\Model\\StratosRecipients' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosRecipients.php', 'OC\\Stratos\\Model\\StratosWrapper' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosWrapper.php', 'OC\\Stratos\\StratosManager' => __DIR__ . '/../../..' . '/lib/private/Stratos/StratosManager.php', 'OC\\Streamer' => __DIR__ . '/../../..' . '/lib/private/Streamer.php', diff --git a/lib/private/Stratos/Model/Helper/StratosEvent.php b/lib/private/Stratos/Model/Helper/StratosEvent.php index 713995f9548e8..a77c6cc0ef91e 100644 --- a/lib/private/Stratos/Model/Helper/StratosEvent.php +++ b/lib/private/Stratos/Model/Helper/StratosEvent.php @@ -33,7 +33,8 @@ use daita\NcSmallPhpTools\Traits\TArrayTools; use JsonSerializable; -use OCP\Stratos\Model\IStratosEvent; +use OC\Stratos\Model\StratosRecipients; +use OCP\Stratos\Model\Helper\IStratosEvent; /** @@ -41,7 +42,7 @@ * * @package OC\Stratos\Model\Helper */ -class StratosEvent implements IStratosEvent, JsonSerializable { +class StratosEvent extends StratosRecipients implements IStratosEvent, JsonSerializable { use TArrayTools; @@ -130,11 +131,15 @@ public function setPayload(array $payload): IStratosEvent { * @return array */ public function jsonSerialize(): array { - return [ - 'app' => $this->getApp(), - 'command' => $this->getCommand(), - 'payload' => $this->getPayload() - ]; + return array_merge( + parent::jsonSerialize(), + [ + + 'app' => $this->getApp(), + 'command' => $this->getCommand(), + 'payload' => $this->getPayload() + ] + ); } } diff --git a/lib/private/Stratos/Model/Helper/StratosNotification.php b/lib/private/Stratos/Model/Helper/StratosNotification.php index 80d94f50e81ea..be3c1cd7ed129 100644 --- a/lib/private/Stratos/Model/Helper/StratosNotification.php +++ b/lib/private/Stratos/Model/Helper/StratosNotification.php @@ -34,7 +34,8 @@ use daita\NcSmallPhpTools\Traits\TArrayTools; use JsonSerializable; use OCP\Stratos\Model\IStratosItem; -use OCP\Stratos\Model\IStratosNotification; +use OCP\Stratos\Model\Helper\IStratosNotification; +use OC\Stratos\Model\StratosRecipients; /** @@ -42,7 +43,7 @@ * * @package OC\Stratos\Model\Helper */ -class StratosNotification implements IStratosNotification, JsonSerializable { +class StratosNotification extends StratosRecipients implements IStratosNotification, JsonSerializable { use TArrayTools; @@ -196,14 +197,16 @@ public function setTtl(int $ttl): IStratosNotification { * @return array */ public function jsonSerialize(): array { - return [ - 'app' => $this->getApp(), - 'title' => $this->getTitle(), - 'type' => $this->getMessage(), - 'source' => $this->getLevel(), - 'link' => $this->getLink(), - 'ttl' => $this->getTtl() - ]; + return array_merge( + parent::jsonSerialize(), + [ + 'app' => $this->getApp(), + 'title' => $this->getTitle(), + 'type' => $this->getMessage(), + 'source' => $this->getLevel(), + 'link' => $this->getLink(), + 'ttl' => $this->getTtl() + ]); } } diff --git a/lib/private/Stratos/Model/StratosRecipients.php b/lib/private/Stratos/Model/StratosRecipients.php new file mode 100644 index 0000000000000..accb106e04d59 --- /dev/null +++ b/lib/private/Stratos/Model/StratosRecipients.php @@ -0,0 +1,121 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Stratos\Model; + + +use JsonSerializable; +use OCP\Stratos\Model\IStratosRecipients; + + +/** + * Class StratosNotification + * + * @package OC\Stratos\Model\Helper + */ +class StratosRecipients implements IStratosRecipients, JsonSerializable { + + + private $users = []; + private $groups = []; + + + /** + * @param string $user + * + * @return IStratosRecipients + */ + public function addUser(string $user): IStratosRecipients { + $this->users[] = $user; + + return $this; + } + + /** + * @param array $users + * + * @return IStratosRecipients + */ + public function addUsers(array $users): IStratosRecipients { + $this->users = array_merge($this->users, $users); + + return $this; + } + + /** + * @param string $group + * + * @return IStratosRecipients + */ + public function addGroup(string $group): IStratosRecipients { + $this->groups[] = $group; + + return $this; + } + + /** + * @param array $groups + * + * @return IStratosRecipients + */ + public function addGroups(array $groups): IStratosRecipients { + $this->groups = array_merge($this->groups, $groups); + + return $this; + } + + + /** + * @return string[] + */ + public function getUsers(): array { + return $this->users; + } + + /** + * @return string[] + */ + public function getGroups(): array { + return $this->groups; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return [ + '_users' => $this->getUsers(), + '_groups' => $this->getGroups() + ]; + } + +} + diff --git a/lib/private/Stratos/Model/StratosWrapper.php b/lib/private/Stratos/Model/StratosWrapper.php index 1871f6f8fe61b..1074d5b392bc5 100644 --- a/lib/private/Stratos/Model/StratosWrapper.php +++ b/lib/private/Stratos/Model/StratosWrapper.php @@ -58,8 +58,15 @@ class StratosWrapper implements IStratosWrapper, JsonSerializable { private $creation = 0; - public function __construct(array $recipients = []) { - $this->recipients = $recipients; + /** + * StratosWrapper constructor. + * + * @param IStratosItem $item + */ + public function __construct($item = null) { + if ($user !== null && $item instanceof IStratosItem) { + $this->item = $item; + } return $this; } @@ -92,7 +99,7 @@ public function setItem(IStratosItem $item): IStratosWrapper { /** - * @return array + * @return string[] */ public function getRecipients(): array { return $this->recipients; @@ -122,6 +129,19 @@ public function addRecipient(string $recipient): IStratosWrapper { return $this; } + /** + * @param string $recipient + * + * @return IStratosWrapper + */ + public function addRecipients(array $recipients): IStratosWrapper { + foreach ($recipients as $recipient) { + $this->addRecipient($recipient); + } + + return $this; + } + /** * @param array $import diff --git a/lib/public/Stratos/Helper/IStratosHelper.php b/lib/public/Stratos/Helper/IStratosHelper.php index 1a18350715aad..a2b15d9eac40d 100644 --- a/lib/public/Stratos/Helper/IStratosHelper.php +++ b/lib/public/Stratos/Helper/IStratosHelper.php @@ -31,8 +31,8 @@ namespace OCP\Stratos\Helper; -use OCP\Stratos\Model\IStratosEvent; -use OCP\Stratos\Model\IStratosNotification; +use OCP\Stratos\Model\Helper\IStratosEvent; +use OCP\Stratos\Model\Helper\IStratosNotification; use OCP\Stratos\Model\IStratosWrapper; @@ -60,34 +60,28 @@ public function test(string $userId): IStratosWrapper; * * @return IStratosWrapper */ - public function pushNotification(IStratosNotification $notification, string $userId - ): IStratosWrapper; + public function pushNotification(IStratosNotification $notification): IStratosWrapper; /** * @param IStratosNotification $notification - * @param array $users * * @return IStratosWrapper */ - public function pushNotifications(IStratosNotification $notification, array $users - ): IStratosWrapper; + public function generateFromNotification(IStratosNotification $notification): IStratosWrapper; /** * @param IStratosEvent $event - * @param string $userId * * @return IStratosWrapper */ - public function broadcastEvent(IStratosEvent $event, string $userId): IStratosWrapper; + public function broadcastEvent(IStratosEvent $event): IStratosWrapper; /** * @param IStratosEvent $event - * @param array $users * * @return IStratosWrapper */ - public function broadcastEvents(IStratosEvent $event, array $users): IStratosWrapper; + public function generateFromEvent(IStratosEvent $event): IStratosWrapper; } - diff --git a/lib/public/Stratos/Model/Helper/IStratosEvent.php b/lib/public/Stratos/Model/Helper/IStratosEvent.php index 9a2cfbc7a3a1a..26498605d41f1 100644 --- a/lib/public/Stratos/Model/Helper/IStratosEvent.php +++ b/lib/public/Stratos/Model/Helper/IStratosEvent.php @@ -28,7 +28,10 @@ */ -namespace OCP\Stratos\Model; +namespace OCP\Stratos\Model\Helper; + + +use OCP\Stratos\Model\IStratosRecipients; /** @@ -36,9 +39,9 @@ * * @since 18.0.0 * - * @package OCP\Stratos + * @package OCP\Stratos\Helper */ -interface IStratosEvent { +interface IStratosEvent extends IStratosRecipients { /** diff --git a/lib/public/Stratos/Model/Helper/IStratosNotification.php b/lib/public/Stratos/Model/Helper/IStratosNotification.php index 281f5f370da2d..d804975b38457 100644 --- a/lib/public/Stratos/Model/Helper/IStratosNotification.php +++ b/lib/public/Stratos/Model/Helper/IStratosNotification.php @@ -28,7 +28,10 @@ */ -namespace OCP\Stratos\Model; +namespace OCP\Stratos\Model\Helper; + + +use OCP\Stratos\Model\IStratosRecipients; /** @@ -36,9 +39,9 @@ * * @since 18.0.0 * - * @package OCP\Stratos + * @package OCP\Stratos\Helper */ -interface IStratosNotification { +interface IStratosNotification extends IStratosRecipients { const LEVEL_SUCCESS = 'success'; diff --git a/lib/public/Stratos/Model/IStratosRecipients.php b/lib/public/Stratos/Model/IStratosRecipients.php new file mode 100644 index 0000000000000..9ba3e9c7bfef9 --- /dev/null +++ b/lib/public/Stratos/Model/IStratosRecipients.php @@ -0,0 +1,82 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Stratos\Model; + + +/** + * Interface IStratosRecipients + * + * @since 18.0.0 + * + * @package OCP\Stratos + */ +interface IStratosRecipients { + + /** + * @param string $user + * + * @return IStratosRecipients + */ + public function addUser(string $user): self; + + /** + * @param array $users + * + * @return IStratosRecipients + */ + public function addUsers(array $users): self; + + /** + * @param string $group + * + * @return IStratosRecipients + */ + public function addGroup(string $group): self; + + /** + * @param array $groups + * + * @return IStratosRecipients + */ + public function addGroups(array $groups): self; + + /** + * @return string[] + */ + public function getUsers(): array; + + /** + * @return string[] + */ + public function getGroups(): array; + +} + diff --git a/lib/public/Stratos/Model/IStratosWrapper.php b/lib/public/Stratos/Model/IStratosWrapper.php index 5b4daa91c3f05..30f1ea926cb8b 100644 --- a/lib/public/Stratos/Model/IStratosWrapper.php +++ b/lib/public/Stratos/Model/IStratosWrapper.php @@ -79,6 +79,14 @@ public function setRecipients(array $recipients): self; public function addRecipient(string $recipient): self; + /** + * @param array $recipients + * + * @return IStratosWrapper + */ + public function addRecipients(array $recipients): self; + + /** * @param array $import * diff --git a/lib/public/Stratos/Service/IStratosService.php b/lib/public/Stratos/Service/IStratosService.php index 248bcf6346aba..63dd382fc423b 100644 --- a/lib/public/Stratos/Service/IStratosService.php +++ b/lib/public/Stratos/Service/IStratosService.php @@ -31,7 +31,8 @@ namespace OCP\Stratos\Service; -use OCP\Stratos\Model\IStratosItem; +use OCP\Stratos\Model\IStratosRecipients; +use OCP\Stratos\Model\IStratosWrapper; /** @@ -43,7 +44,17 @@ */ interface IStratosService { - public function pushItemToUser(IStratosItem $stream, string $userId); + + public function push(IStratosWrapper $wrapper); + + + /** + * @param IStratosWrapper $wrapper + * @param IStratosRecipients $recipients + * + * @return mixed + */ + public function fillRecipients(IStratosWrapper $wrapper, IStratosRecipients $recipients); } From 87f3bf1f28c8be1a0b6daf24613c2479766b8346 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Mon, 12 Aug 2019 11:29:57 -0100 Subject: [PATCH 05/16] syntax Signed-off-by: Maxence Lange --- lib/private/Stratos/Model/StratosWrapper.php | 4 ++-- lib/public/Stratos/Model/IStratosWrapper.php | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/private/Stratos/Model/StratosWrapper.php b/lib/private/Stratos/Model/StratosWrapper.php index 1074d5b392bc5..15e1b2f191495 100644 --- a/lib/private/Stratos/Model/StratosWrapper.php +++ b/lib/private/Stratos/Model/StratosWrapper.php @@ -64,7 +64,7 @@ class StratosWrapper implements IStratosWrapper, JsonSerializable { * @param IStratosItem $item */ public function __construct($item = null) { - if ($user !== null && $item instanceof IStratosItem) { + if ($item !== null && $item instanceof IStratosItem) { $this->item = $item; } @@ -130,7 +130,7 @@ public function addRecipient(string $recipient): IStratosWrapper { } /** - * @param string $recipient + * @param array $recipients * * @return IStratosWrapper */ diff --git a/lib/public/Stratos/Model/IStratosWrapper.php b/lib/public/Stratos/Model/IStratosWrapper.php index 30f1ea926cb8b..c171ac4f9eceb 100644 --- a/lib/public/Stratos/Model/IStratosWrapper.php +++ b/lib/public/Stratos/Model/IStratosWrapper.php @@ -77,8 +77,7 @@ public function setRecipients(array $recipients): self; * @return IStratosWrapper */ public function addRecipient(string $recipient): self; - - + /** * @param array $recipients * From f9824ce6e74a96374eee8620814cb51ef66295db Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Mon, 12 Aug 2019 17:22:20 -0100 Subject: [PATCH 06/16] serializable payload Signed-off-by: Maxence Lange --- lib/private/Stratos/Model/Helper/StratosEvent.php | 11 +++++++++++ lib/public/Stratos/Model/Helper/IStratosEvent.php | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/private/Stratos/Model/Helper/StratosEvent.php b/lib/private/Stratos/Model/Helper/StratosEvent.php index a77c6cc0ef91e..4291ef2bed52d 100644 --- a/lib/private/Stratos/Model/Helper/StratosEvent.php +++ b/lib/private/Stratos/Model/Helper/StratosEvent.php @@ -126,6 +126,17 @@ public function setPayload(array $payload): IStratosEvent { return $this; } + /** + * @param JsonSerializable $payload + * + * @return IStratosEvent + */ + public function setPayloadSerializable(JsonSerializable $payload): IStratosEvent { + $this->payload = $payload->jsonSerialize(); + + return $this; + } + /** * @return array diff --git a/lib/public/Stratos/Model/Helper/IStratosEvent.php b/lib/public/Stratos/Model/Helper/IStratosEvent.php index 26498605d41f1..9c343ff704911 100644 --- a/lib/public/Stratos/Model/Helper/IStratosEvent.php +++ b/lib/public/Stratos/Model/Helper/IStratosEvent.php @@ -31,6 +31,7 @@ namespace OCP\Stratos\Model\Helper; +use JsonSerializable; use OCP\Stratos\Model\IStratosRecipients; @@ -82,5 +83,12 @@ public function getPayload(): array; */ public function setPayload(array $payload): self; + /** + * @param JsonSerializable $payload + * + * @return self + */ + public function setPayloadSerializable (JsonSerializable $payload): self; + } From acac4365451e50d26c3406c5633e6329fbc6a1e0 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 15 Aug 2019 01:03:59 -0100 Subject: [PATCH 07/16] +IStratosCallback Signed-off-by: Maxence Lange --- lib/composer/composer/autoload_classmap.php | 2 + lib/composer/composer/autoload_static.php | 2 + .../Stratos/Model/Helper/StratosCallback.php | 160 ++++++++++++++++++ .../Stratos/Model/Helper/StratosEvent.php | 5 +- .../Model/Helper/StratosNotification.php | 3 +- lib/private/Stratos/Model/StratosItem.php | 18 +- lib/public/Stratos/Helper/IStratosHelper.php | 19 ++- .../Stratos/Model/Helper/IStratosCallback.php | 97 +++++++++++ .../Stratos/Model/Helper/IStratosEvent.php | 5 +- .../Model/Helper/IStratosNotification.php | 2 + lib/public/Stratos/Model/IStratosItem.php | 13 +- 11 files changed, 317 insertions(+), 9 deletions(-) create mode 100644 lib/private/Stratos/Model/Helper/StratosCallback.php create mode 100644 lib/public/Stratos/Model/Helper/IStratosCallback.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index ee3ef98f37354..149448da79ab4 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -409,6 +409,7 @@ 'OCP\\Stratos\\Exceptions\\StratosInstallException' => $baseDir . '/lib/public/Stratos/Exceptions/StratosInstallException.php', 'OCP\\Stratos\\Helper\\IStratosHelper' => $baseDir . '/lib/public/Stratos/Helper/IStratosHelper.php', 'OCP\\Stratos\\IStratosManager' => $baseDir . '/lib/public/Stratos/IStratosManager.php', + 'OCP\\Stratos\\Model\\Helper\\IStratosCallback' => $baseDir . '/lib/public/Stratos/Model/Helper/IStratosCallback.php', 'OCP\\Stratos\\Model\\Helper\\IStratosEvent' => $baseDir . '/lib/public/Stratos/Model/Helper/IStratosEvent.php', 'OCP\\Stratos\\Model\\Helper\\IStratosNotification' => $baseDir . '/lib/public/Stratos/Model/Helper/IStratosNotification.php', 'OCP\\Stratos\\Model\\IStratosItem' => $baseDir . '/lib/public/Stratos/Model/IStratosItem.php', @@ -1199,6 +1200,7 @@ 'OC\\Share\\Helper' => $baseDir . '/lib/private/Share/Helper.php', 'OC\\Share\\SearchResultSorter' => $baseDir . '/lib/private/Share/SearchResultSorter.php', 'OC\\Share\\Share' => $baseDir . '/lib/private/Share/Share.php', + 'OC\\Stratos\\Model\\Helper\\StratosCallback' => $baseDir . '/lib/private/Stratos/Model/Helper/StratosCallback.php', 'OC\\Stratos\\Model\\Helper\\StratosEvent' => $baseDir . '/lib/private/Stratos/Model/Helper/StratosEvent.php', 'OC\\Stratos\\Model\\Helper\\StratosNotification' => $baseDir . '/lib/private/Stratos/Model/Helper/StratosNotification.php', 'OC\\Stratos\\Model\\StratosItem' => $baseDir . '/lib/private/Stratos/Model/StratosItem.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 929a0a77c06d4..3bc5b4938865f 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -443,6 +443,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Stratos\\Exceptions\\StratosInstallException' => __DIR__ . '/../../..' . '/lib/public/Stratos/Exceptions/StratosInstallException.php', 'OCP\\Stratos\\Helper\\IStratosHelper' => __DIR__ . '/../../..' . '/lib/public/Stratos/Helper/IStratosHelper.php', 'OCP\\Stratos\\IStratosManager' => __DIR__ . '/../../..' . '/lib/public/Stratos/IStratosManager.php', + 'OCP\\Stratos\\Model\\Helper\\IStratosCallback' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/Helper/IStratosCallback.php', 'OCP\\Stratos\\Model\\Helper\\IStratosEvent' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/Helper/IStratosEvent.php', 'OCP\\Stratos\\Model\\Helper\\IStratosNotification' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/Helper/IStratosNotification.php', 'OCP\\Stratos\\Model\\IStratosItem' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosItem.php', @@ -1233,6 +1234,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Share\\Helper' => __DIR__ . '/../../..' . '/lib/private/Share/Helper.php', 'OC\\Share\\SearchResultSorter' => __DIR__ . '/../../..' . '/lib/private/Share/SearchResultSorter.php', 'OC\\Share\\Share' => __DIR__ . '/../../..' . '/lib/private/Share/Share.php', + 'OC\\Stratos\\Model\\Helper\\StratosCallback' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/Helper/StratosCallback.php', 'OC\\Stratos\\Model\\Helper\\StratosEvent' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/Helper/StratosEvent.php', 'OC\\Stratos\\Model\\Helper\\StratosNotification' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/Helper/StratosNotification.php', 'OC\\Stratos\\Model\\StratosItem' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosItem.php', diff --git a/lib/private/Stratos/Model/Helper/StratosCallback.php b/lib/private/Stratos/Model/Helper/StratosCallback.php new file mode 100644 index 0000000000000..7d5777723dc6a --- /dev/null +++ b/lib/private/Stratos/Model/Helper/StratosCallback.php @@ -0,0 +1,160 @@ + + * @copyright 2019, Maxence Lange + * @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 . + * + */ + + +namespace OC\Stratos\Model\Helper; + + +use daita\NcSmallPhpTools\Traits\TArrayTools; +use JsonSerializable; +use OC\Stratos\Model\StratosRecipients; +use OCP\Stratos\Model\Helper\IStratosCallback; + + +/** + * Class StratosCallback + * + * @package OC\Stratos\Model\Helper + */ +class StratosCallback extends StratosRecipients implements IStratosCallback, JsonSerializable { + + + use TArrayTools; + + + /** @var string */ + private $app = ''; + + /** @var string */ + private $source = ''; + + /** @var array */ + private $payload = ''; + + + /** + * StratosCallback constructor. + * + * @param string $app + * @param $source + */ + public function __construct($app = '', $source = '') { + $this->app = $app; + $this->source = $source; + } + + + /** + * @return string + */ + public function getApp(): string { + return $this->app; + } + + /** + * @param string $app + * + * @return IStratosCallback + */ + public function setApp(string $app): IStratosCallback { + $this->app = $app; + + return $this; + } + + + /** + * @return string + */ + public function getSource(): string { + return $this->source; + } + + /** + * @param string $source + * + * @return IStratosCallback + */ + public function setSource(string $source): IStratosCallback { + $this->source = $source; + + return $this; + } + + + /** + * @return array + */ + public function getPayload(): array { + if ($this->payload instanceof JsonSerializable) { + return json_decode($this->payload, true); + } + + return $this->payload; + } + + /** + * @param array $payload + * + * @return IStratosCallback + */ + public function setPayload(array $payload): IStratosCallback { + $this->payload = $payload; + + return $this; + } + + /** + * @param JsonSerializable $payload + * + * @return self + */ + public function setPayloadSerializable(JsonSerializable $payload): IStratosCallback { + $this->payload = $payload; + + return $this; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return array_merge( + parent::jsonSerialize(), + [ + 'app' => $this->getApp(), + 'id' => $this->getId(), + 'payload' => $this->payload + ] + ); + } + +} + diff --git a/lib/private/Stratos/Model/Helper/StratosEvent.php b/lib/private/Stratos/Model/Helper/StratosEvent.php index 4291ef2bed52d..dfff8bd419a4c 100644 --- a/lib/private/Stratos/Model/Helper/StratosEvent.php +++ b/lib/private/Stratos/Model/Helper/StratosEvent.php @@ -112,6 +112,10 @@ public function setCommand(string $command): IStratosEvent { * @return array */ public function getPayload(): array { + if ($this->payload instanceof JsonSerializable) { + return json_decode($this->payload, true); + } + return $this->payload; } @@ -145,7 +149,6 @@ public function jsonSerialize(): array { return array_merge( parent::jsonSerialize(), [ - 'app' => $this->getApp(), 'command' => $this->getCommand(), 'payload' => $this->getPayload() diff --git a/lib/private/Stratos/Model/Helper/StratosNotification.php b/lib/private/Stratos/Model/Helper/StratosNotification.php index be3c1cd7ed129..623c8881bc8b6 100644 --- a/lib/private/Stratos/Model/Helper/StratosNotification.php +++ b/lib/private/Stratos/Model/Helper/StratosNotification.php @@ -206,7 +206,8 @@ public function jsonSerialize(): array { 'source' => $this->getLevel(), 'link' => $this->getLink(), 'ttl' => $this->getTtl() - ]); + ] + ); } } diff --git a/lib/private/Stratos/Model/StratosItem.php b/lib/private/Stratos/Model/StratosItem.php index 42cc82e9a5659..bdca27bb57601 100644 --- a/lib/private/Stratos/Model/StratosItem.php +++ b/lib/private/Stratos/Model/StratosItem.php @@ -167,13 +167,17 @@ public function setSource(string $source): IStratosItem { * @return array */ public function getPayload(): array { + if ($this->payload instanceof JsonSerializable) { + return json_decode($this->payload, true); + } + return $this->payload; } /** * @param array $payload * - * @return StratosItem + * @return IStratosItem */ public function setPayload(array $payload): IStratosItem { $this->payload = $payload; @@ -181,6 +185,18 @@ public function setPayload(array $payload): IStratosItem { return $this; } + /** + * @param JsonSerializable $payload + * + * @return IStratosItem + */ + public function setPayloadSerializable(JsonSerializable $payload): IStratosItem { + $this->payload = $payload; + + return $this; + } + + /** * @return string diff --git a/lib/public/Stratos/Helper/IStratosHelper.php b/lib/public/Stratos/Helper/IStratosHelper.php index a2b15d9eac40d..8a018d4c19889 100644 --- a/lib/public/Stratos/Helper/IStratosHelper.php +++ b/lib/public/Stratos/Helper/IStratosHelper.php @@ -31,6 +31,7 @@ namespace OCP\Stratos\Helper; +use OCP\Stratos\Model\Helper\IStratosCallback; use OCP\Stratos\Model\Helper\IStratosEvent; use OCP\Stratos\Model\Helper\IStratosNotification; use OCP\Stratos\Model\IStratosWrapper; @@ -54,9 +55,25 @@ interface IStratosHelper { public function test(string $userId): IStratosWrapper; + /** + * @param IStratosCallback $callback + * + * @return IStratosWrapper + */ + public function toCallback(IStratosCallback $callback): IStratosWrapper; + + /** + * @param IStratosCallback $callback + * + * @return IStratosWrapper + */ + public function generateFromCallback(IStratosCallback $callback): IStratosWrapper; + + + + /** * @param IStratosNotification $notification - * @param string $userId * * @return IStratosWrapper */ diff --git a/lib/public/Stratos/Model/Helper/IStratosCallback.php b/lib/public/Stratos/Model/Helper/IStratosCallback.php new file mode 100644 index 0000000000000..166a8457a98de --- /dev/null +++ b/lib/public/Stratos/Model/Helper/IStratosCallback.php @@ -0,0 +1,97 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Stratos\Model\Helper; + + +use JsonSerializable; +use OCP\Stratos\Model\IStratosRecipients; + + +/** + * Interface IStratosCallback + * + * @since 18.0.0 + * + * @package OCP\Stratos\Helper + */ +interface IStratosCallback extends IStratosRecipients { + + + const TYPE = 'Callback'; + + + /** + * @return string + */ + public function getApp(): string; + + /** + * @param string $app + * + * @return self + */ + public function setApp(string $app): self; + + + /** + * @return string + */ + public function getSource(): string; + + /** + * @param string $source + * + * @return self + */ + public function setSource(string $source): self; + + + /** + * @return array + */ + public function getPayload(): array; + + /** + * @param array $payload + * + * @return self + */ + public function setPayload(array $payload): self; + + /** + * @param JsonSerializable $payload + * + * @return self + */ + public function setPayloadSerializable(JsonSerializable $payload): self; + +} + diff --git a/lib/public/Stratos/Model/Helper/IStratosEvent.php b/lib/public/Stratos/Model/Helper/IStratosEvent.php index 9c343ff704911..a71a343b78885 100644 --- a/lib/public/Stratos/Model/Helper/IStratosEvent.php +++ b/lib/public/Stratos/Model/Helper/IStratosEvent.php @@ -45,6 +45,9 @@ interface IStratosEvent extends IStratosRecipients { + const TYPE = 'Event'; + + /** * @return string */ @@ -88,7 +91,7 @@ public function setPayload(array $payload): self; * * @return self */ - public function setPayloadSerializable (JsonSerializable $payload): self; + public function setPayloadSerializable(JsonSerializable $payload): self; } diff --git a/lib/public/Stratos/Model/Helper/IStratosNotification.php b/lib/public/Stratos/Model/Helper/IStratosNotification.php index d804975b38457..e01a85a4f4eae 100644 --- a/lib/public/Stratos/Model/Helper/IStratosNotification.php +++ b/lib/public/Stratos/Model/Helper/IStratosNotification.php @@ -44,6 +44,8 @@ interface IStratosNotification extends IStratosRecipients { + const TYPE = 'Notification'; + const LEVEL_SUCCESS = 'success'; const LEVEL_MESSAGE = 'message'; const LEVEL_WARNING = 'warning'; diff --git a/lib/public/Stratos/Model/IStratosItem.php b/lib/public/Stratos/Model/IStratosItem.php index 6aa233ad29d13..b2fd734b5a275 100644 --- a/lib/public/Stratos/Model/IStratosItem.php +++ b/lib/public/Stratos/Model/IStratosItem.php @@ -31,6 +31,8 @@ namespace OCP\Stratos\Model; +use JsonSerializable; + /** * Interface IStratosItem * @@ -48,10 +50,6 @@ interface IStratosItem { const TTL_LONG = 24 * 3600 * 8; const TTL_GODLIKE = 0; - const TYPE_NOTIFICATION = 'Notification'; - const TYPE_EVENT = 'Event'; - const TYPE_WHATSNEW = 'WhatsNew'; - /** * @return int @@ -103,6 +101,13 @@ public function getPayload(): array; */ public function setPayload(array $payload): self; + /** + * @param JsonSerializable $payload + * + * @return IStratosItem + */ + public function setPayloadSerializable(JsonSerializable $payload): self; + /** * @return string From 3e34e0745b18188ec09bfb63ddda243d09c1e52e Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 15 Aug 2019 01:30:51 -0100 Subject: [PATCH 08/16] fixing Signed-off-by: Maxence Lange --- lib/private/Stratos/Model/Helper/StratosCallback.php | 2 +- lib/private/Stratos/Model/Helper/StratosEvent.php | 2 +- lib/private/Stratos/Model/StratosItem.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/Stratos/Model/Helper/StratosCallback.php b/lib/private/Stratos/Model/Helper/StratosCallback.php index 7d5777723dc6a..f78c036cd9e3d 100644 --- a/lib/private/Stratos/Model/Helper/StratosCallback.php +++ b/lib/private/Stratos/Model/Helper/StratosCallback.php @@ -113,7 +113,7 @@ public function setSource(string $source): IStratosCallback { */ public function getPayload(): array { if ($this->payload instanceof JsonSerializable) { - return json_decode($this->payload, true); + return $this->payload->jsonSerialize(); } return $this->payload; diff --git a/lib/private/Stratos/Model/Helper/StratosEvent.php b/lib/private/Stratos/Model/Helper/StratosEvent.php index dfff8bd419a4c..46f963276f363 100644 --- a/lib/private/Stratos/Model/Helper/StratosEvent.php +++ b/lib/private/Stratos/Model/Helper/StratosEvent.php @@ -113,7 +113,7 @@ public function setCommand(string $command): IStratosEvent { */ public function getPayload(): array { if ($this->payload instanceof JsonSerializable) { - return json_decode($this->payload, true); + return $this->payload->jsonSerialize(); } return $this->payload; diff --git a/lib/private/Stratos/Model/StratosItem.php b/lib/private/Stratos/Model/StratosItem.php index bdca27bb57601..ef9489e2cb2e0 100644 --- a/lib/private/Stratos/Model/StratosItem.php +++ b/lib/private/Stratos/Model/StratosItem.php @@ -168,7 +168,7 @@ public function setSource(string $source): IStratosItem { */ public function getPayload(): array { if ($this->payload instanceof JsonSerializable) { - return json_decode($this->payload, true); + return $this->payload->jsonSerialize(); } return $this->payload; From ed981f2b00c58873ddf85d1fb04500f5ed985e4b Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 15 Aug 2019 14:20:50 -0100 Subject: [PATCH 09/16] fix Signed-off-by: Maxence Lange --- lib/private/Stratos/Model/Helper/StratosCallback.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Stratos/Model/Helper/StratosCallback.php b/lib/private/Stratos/Model/Helper/StratosCallback.php index f78c036cd9e3d..8da49741ada67 100644 --- a/lib/private/Stratos/Model/Helper/StratosCallback.php +++ b/lib/private/Stratos/Model/Helper/StratosCallback.php @@ -150,7 +150,7 @@ public function jsonSerialize(): array { parent::jsonSerialize(), [ 'app' => $this->getApp(), - 'id' => $this->getId(), + 'source' => $this->getSource(), 'payload' => $this->payload ] ); From 8e2fd5f7cce6f50d8f56ba96ec34a53ec616d275 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 16 Aug 2019 11:07:35 -0100 Subject: [PATCH 10/16] remove users/groups from recipients Signed-off-by: Maxence Lange --- .../Stratos/Model/StratosRecipients.php | 73 ++++++++++++++++++- lib/private/Stratos/Model/StratosWrapper.php | 3 +- .../Stratos/Model/IStratosRecipients.php | 42 +++++++++++ 3 files changed, 115 insertions(+), 3 deletions(-) diff --git a/lib/private/Stratos/Model/StratosRecipients.php b/lib/private/Stratos/Model/StratosRecipients.php index accb106e04d59..1e13bcb35eb92 100644 --- a/lib/private/Stratos/Model/StratosRecipients.php +++ b/lib/private/Stratos/Model/StratosRecipients.php @@ -43,9 +43,18 @@ class StratosRecipients implements IStratosRecipients, JsonSerializable { + /** @var array */ private $users = []; + + /** @var array */ + private $removedUsers = []; + + /** @var array */ private $groups = []; + /** @var array */ + private $removedGroups = []; + /** * @param string $user @@ -53,7 +62,7 @@ class StratosRecipients implements IStratosRecipients, JsonSerializable { * @return IStratosRecipients */ public function addUser(string $user): IStratosRecipients { - $this->users[] = $user; + array_push($this->users, $user); return $this; } @@ -69,13 +78,36 @@ public function addUsers(array $users): IStratosRecipients { return $this; } + /** + * @param string $user + * + * @return IStratosRecipients + */ + public function removeUser(string $user): IStratosRecipients { + $this->removeUsers([$user]); + + return $this; + } + + /** + * @param array $users + * + * @return IStratosRecipients + */ + public function removeUsers(array $users): IStratosRecipients { + $this->removedUsers = array_merge($this->removedUsers, $users); + + return $this; + } + + /** * @param string $group * * @return IStratosRecipients */ public function addGroup(string $group): IStratosRecipients { - $this->groups[] = $group; + array_push($this->groups, $group); return $this; } @@ -91,6 +123,28 @@ public function addGroups(array $groups): IStratosRecipients { return $this; } + /** + * @param string $group + * + * @return IStratosRecipients + */ + public function removeGroup(string $group): IStratosRecipients { + $this->removeGroups([$group]); + + return $this; + } + + /** + * @param array $groups + * + * @return IStratosRecipients + */ + public function removeGroups(array $groups): IStratosRecipients { + $this->removedGroups = array_merge($this->removedGroups, $groups); + + return $this; + } + /** * @return string[] @@ -107,6 +161,21 @@ public function getGroups(): array { } + /** + * @return string[] + */ + public function getRemovedUsers(): array { + return $this->removedUsers; + } + + /** + * @return string[] + */ + public function getRemovedGroups(): array { + return $this->removedGroups; + } + + /** * @return array */ diff --git a/lib/private/Stratos/Model/StratosWrapper.php b/lib/private/Stratos/Model/StratosWrapper.php index 15e1b2f191495..d9a97bc926ab8 100644 --- a/lib/private/Stratos/Model/StratosWrapper.php +++ b/lib/private/Stratos/Model/StratosWrapper.php @@ -111,7 +111,8 @@ public function getRecipients(): array { * @return IStratosWrapper */ public function setRecipients(array $recipients): IStratosWrapper { - $this->recipients = $recipients; + $this->recipients = []; + $this->addRecipients($recipients); return $this; } diff --git a/lib/public/Stratos/Model/IStratosRecipients.php b/lib/public/Stratos/Model/IStratosRecipients.php index 9ba3e9c7bfef9..93989a237869d 100644 --- a/lib/public/Stratos/Model/IStratosRecipients.php +++ b/lib/public/Stratos/Model/IStratosRecipients.php @@ -54,6 +54,22 @@ public function addUser(string $user): self; */ public function addUsers(array $users): self; + /** + * @param string $user + * + * @return IStratosRecipients + */ + public function removeUser(string $user): self; + + /** + * @param array $users + * + * @return IStratosRecipients + */ + + public function removeUsers(array $users): self; + + /** * @param string $group * @@ -68,6 +84,22 @@ public function addGroup(string $group): self; */ public function addGroups(array $groups): self; + /** + * @param string $group + * + * @return IStratosRecipients + */ + public function removeGroup(string $group): self; + + /** + * @param array $groups + * + * @return IStratosRecipients + */ + + public function removeGroups(array $groups): self; + + /** * @return string[] */ @@ -78,5 +110,15 @@ public function getUsers(): array; */ public function getGroups(): array; + /** + * @return string[] + */ + public function getRemovedUsers(): array; + + /** + * @return string[] + */ + public function getRemovedGroups(): array; + } From 548fb5e4d423bdbfc5194062f79791ecb340ff9a Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Mon, 19 Aug 2019 08:22:41 -0100 Subject: [PATCH 11/16] meta on item, filters on app Signed-off-by: Maxence Lange --- lib/private/Stratos/Model/StratosItem.php | 49 ++++++++++- .../Stratos/Model/StratosRecipients.php | 86 ++++++++++++++++--- lib/private/Stratos/Model/StratosWrapper.php | 2 +- lib/public/Stratos/Model/IStratosItem.php | 30 +++++++ .../Stratos/Model/IStratosRecipients.php | 40 +++++++++ lib/public/Stratos/Model/IStratosWrapper.php | 2 +- 6 files changed, 194 insertions(+), 15 deletions(-) diff --git a/lib/private/Stratos/Model/StratosItem.php b/lib/private/Stratos/Model/StratosItem.php index ef9489e2cb2e0..d83162a1eaebc 100644 --- a/lib/private/Stratos/Model/StratosItem.php +++ b/lib/private/Stratos/Model/StratosItem.php @@ -63,6 +63,9 @@ class StratosItem implements IStratosItem, JsonSerializable { /** @var array */ private $payload = []; + /** @var array */ + private $meta = []; + /** @var string */ private $type = ''; @@ -197,7 +200,6 @@ public function setPayloadSerializable(JsonSerializable $payload): IStratosItem } - /** * @return string */ @@ -236,6 +238,49 @@ public function setTtl(int $ttl): IStratosItem { } + /** + * @param array $meta + * + * @return IStratosItem + */ + public function setMeta(array $meta): IStratosItem { + $this->meta = $meta; + + return $this; + } + + /** + * @param string $k + * @param string $v + * + * @return IStratosItem + */ + public function addMeta(string $k, string $v): IStratosItem { + $this->meta[$k] = $v; + + return $this; + } + + /** + * @param string $k + * @param array $v + * + * @return IStratosItem + */ + public function addMetaArray(string $k, array $v): IStratosItem { + $this->meta[$k] = $v; + + return $this; + } + + /** + * @return array + */ + public function getMeta(): array { + return $this->meta; + } + + /** * @return int */ @@ -268,6 +313,7 @@ public function import(array $import): IStratosItem { $this->setTtl($this->getInt('ttl', $import, -1)); $this->setPayload($this->getArray('payload', $import, [])); $this->setSource($this->get('source', $import)); + $this->setMeta($this->getArray('meta', $import)); $this->setCreation($this->getInt('creation', $import)); return $this; @@ -284,6 +330,7 @@ public function jsonSerialize(): array { 'type' => $this->getType(), 'source' => $this->getSource(), 'payload' => $this->getPayload(), + 'meta' => $this->getMeta(), 'ttl' => $this->getTtl(), 'creation' => $this->getCreation() ]; diff --git a/lib/private/Stratos/Model/StratosRecipients.php b/lib/private/Stratos/Model/StratosRecipients.php index 1e13bcb35eb92..2d981bf16cfef 100644 --- a/lib/private/Stratos/Model/StratosRecipients.php +++ b/lib/private/Stratos/Model/StratosRecipients.php @@ -55,6 +55,12 @@ class StratosRecipients implements IStratosRecipients, JsonSerializable { /** @var array */ private $removedGroups = []; + /** @var array */ + private $filteredApps = []; + + /** @var array */ + private $limitToApps = []; + /** * @param string $user @@ -68,7 +74,7 @@ public function addUser(string $user): IStratosRecipients { } /** - * @param array $users + * @param string[] $users * * @return IStratosRecipients */ @@ -84,13 +90,11 @@ public function addUsers(array $users): IStratosRecipients { * @return IStratosRecipients */ public function removeUser(string $user): IStratosRecipients { - $this->removeUsers([$user]); - - return $this; + return $this->removeUsers([$user]); } /** - * @param array $users + * @param string[] $users * * @return IStratosRecipients */ @@ -113,7 +117,7 @@ public function addGroup(string $group): IStratosRecipients { } /** - * @param array $groups + * @param string[] $groups * * @return IStratosRecipients */ @@ -129,13 +133,11 @@ public function addGroups(array $groups): IStratosRecipients { * @return IStratosRecipients */ public function removeGroup(string $group): IStratosRecipients { - $this->removeGroups([$group]); - - return $this; + return $this->removeGroups([$group]); } /** - * @param array $groups + * @param string[] $groups * * @return IStratosRecipients */ @@ -176,13 +178,73 @@ public function getRemovedGroups(): array { } + /** + * @param string $app + * + * @return IStratosRecipients + */ + public function filterApp(string $app): IStratosRecipients { + return $this->filterApps([$app]); + } + + /** + * @param string[] $apps + * + * @return IStratosRecipients + */ + public function filterApps(array $apps): IStratosRecipients { + $this->filteredApps = array_merge($this->filteredApps, $apps); + + return $this; + } + + /** + * @return string[] + */ + public function getFilteredApps(): array { + return $this->filteredApps; + } + + + /** + * @param string $app + * + * @return IStratosRecipients + */ + public function limitToApp(string $app): IStratosRecipients { + return $this->limitToApps([$app]); + } + + /** + * @param string[] $apps + * + * @return IStratosRecipients + */ + public function limitToApps(array $apps): IStratosRecipients { + $this->limitToApps = array_merge($this->limitToApps, $apps); + + return $this; + } + + /** + * @return string[] + */ + public function getLimitedToApps(): array { + return $this->limitToApps; + } + + /** * @return array */ public function jsonSerialize(): array { return [ - '_users' => $this->getUsers(), - '_groups' => $this->getGroups() + '_users' => $this->getUsers(), + '_groups' => $this->getGroups(), + '_removedUsers' => $this->getRemovedUsers(), + '_removedGroups' => $this->getRemovedGroups(), + '_filteredApps' => $this->getFilteredApps(), + '_limitToApps' => $this->getLimitedToApps() ]; } diff --git a/lib/private/Stratos/Model/StratosWrapper.php b/lib/private/Stratos/Model/StratosWrapper.php index d9a97bc926ab8..e15b6e072d11f 100644 --- a/lib/private/Stratos/Model/StratosWrapper.php +++ b/lib/private/Stratos/Model/StratosWrapper.php @@ -161,7 +161,7 @@ public function import(array $import): IStratosWrapper { /** - * @return mixed|void + * @return array */ public function jsonSerialize(): array { return [ diff --git a/lib/public/Stratos/Model/IStratosItem.php b/lib/public/Stratos/Model/IStratosItem.php index b2fd734b5a275..15d74c33ad318 100644 --- a/lib/public/Stratos/Model/IStratosItem.php +++ b/lib/public/Stratos/Model/IStratosItem.php @@ -135,6 +135,36 @@ public function getTtl(): int; public function setTtl(int $ttl): self; + /** + * @param array $meta + * + * @return IStratosItem + */ + public function setMeta(array $meta): self; + + /** + * @param string $k + * @param string $v + * + * @return IStratosItem + */ + public function addMeta(string $k, string $v): self; + + /** + * @param string $k + * @param array $v + * + * @return IStratosItem + */ + public function addMetaArray(string $k, array $v): self; + + /** + * @return array + */ + public function getMeta(): array; + + + /** * @param int $timestamp * diff --git a/lib/public/Stratos/Model/IStratosRecipients.php b/lib/public/Stratos/Model/IStratosRecipients.php index 93989a237869d..0182d83025c0f 100644 --- a/lib/public/Stratos/Model/IStratosRecipients.php +++ b/lib/public/Stratos/Model/IStratosRecipients.php @@ -120,5 +120,45 @@ public function getRemovedUsers(): array; */ public function getRemovedGroups(): array; + + /** + * @param string $app + * + * @return IStratosRecipients + */ + public function filterApp(string $app): self; + + /** + * @param string[] $apps + * + * @return IStratosRecipients + */ + public function filterApps(array $apps): self; + + /** + * @return string[] + */ + public function getFilteredApps(): array; + + + /** + * @param string $app + * + * @return IStratosRecipients + */ + public function limitToApp(string $app): self; + + /** + * @param string[] $apps + * + * @return IStratosRecipients + */ + public function limitToApps(array $apps): self; + + /** + * @return string[] + */ + public function getLimitedToApps(): array; + } diff --git a/lib/public/Stratos/Model/IStratosWrapper.php b/lib/public/Stratos/Model/IStratosWrapper.php index c171ac4f9eceb..790a2a7c6268b 100644 --- a/lib/public/Stratos/Model/IStratosWrapper.php +++ b/lib/public/Stratos/Model/IStratosWrapper.php @@ -77,7 +77,7 @@ public function setRecipients(array $recipients): self; * @return IStratosWrapper */ public function addRecipient(string $recipient): self; - + /** * @param array $recipients * From bc35b2917f0a1dde161078e358ce41eae3a71b84 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 22 Aug 2019 10:43:44 -0100 Subject: [PATCH 12/16] renaming Nextcloud Push Signed-off-by: Maxence Lange --- lib/composer/composer/autoload_classmap.php | 34 +++--- lib/composer/composer/autoload_static.php | 34 +++--- .../Model/Helper/PushCallback.php} | 30 ++--- .../Model/Helper/PushEvent.php} | 32 +++--- .../Model/Helper/PushNotification.php} | 44 ++++---- .../Model/PushItem.php} | 66 +++++------ .../Model/PushRecipients.php} | 60 +++++----- .../Model/PushWrapper.php} | 48 ++++---- .../PushManager.php} | 62 ++++++----- lib/private/Server.php | 6 +- .../Exceptions/PushInstallException.php} | 10 +- lib/public/Push/Helper/IPushHelper.php | 104 ++++++++++++++++++ .../IPushManager.php} | 36 +++--- .../Model/Helper/IPushCallback.php} | 12 +- .../Model/Helper/IPushEvent.php} | 12 +- .../Model/Helper/IPushNotification.php} | 12 +- .../Model/IPushItem.php} | 18 +-- .../Model/IPushRecipients.php} | 34 +++--- .../Model/IPushWrapper.php} | 24 ++-- .../Service/IPushService.php} | 22 ++-- lib/public/Stratos/Helper/IStratosHelper.php | 104 ------------------ 21 files changed, 403 insertions(+), 401 deletions(-) rename lib/private/{Stratos/Model/Helper/StratosCallback.php => Push/Model/Helper/PushCallback.php} (79%) rename lib/private/{Stratos/Model/Helper/StratosEvent.php => Push/Model/Helper/PushEvent.php} (79%) rename lib/private/{Stratos/Model/Helper/StratosNotification.php => Push/Model/Helper/PushNotification.php} (73%) rename lib/private/{Stratos/Model/StratosItem.php => Push/Model/PushItem.php} (78%) rename lib/private/{Stratos/Model/StratosRecipients.php => Push/Model/PushRecipients.php} (72%) rename lib/private/{Stratos/Model/StratosWrapper.php => Push/Model/PushWrapper.php} (71%) rename lib/private/{Stratos/StratosManager.php => Push/PushManager.php} (52%) rename lib/public/{Stratos/Exceptions/StratosInstallException.php => Push/Exceptions/PushInstallException.php} (84%) create mode 100644 lib/public/Push/Helper/IPushHelper.php rename lib/public/{Stratos/IStratosManager.php => Push/IPushManager.php} (62%) rename lib/public/{Stratos/Model/Helper/IStratosCallback.php => Push/Model/Helper/IPushCallback.php} (88%) rename lib/public/{Stratos/Model/Helper/IStratosEvent.php => Push/Model/Helper/IPushEvent.php} (88%) rename lib/public/{Stratos/Model/Helper/IStratosNotification.php => Push/Model/Helper/IPushNotification.php} (90%) rename lib/public/{Stratos/Model/IStratosItem.php => Push/Model/IPushItem.php} (92%) rename lib/public/{Stratos/Model/IStratosRecipients.php => Push/Model/IPushRecipients.php} (83%) rename lib/public/{Stratos/Model/IStratosWrapper.php => Push/Model/IPushWrapper.php} (81%) rename lib/public/{Stratos/Service/IStratosService.php => Push/Service/IPushService.php} (70%) delete mode 100644 lib/public/Stratos/Helper/IStratosHelper.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 149448da79ab4..18d0206554070 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -363,6 +363,16 @@ 'OCP\\Preview\\IProvider' => $baseDir . '/lib/public/Preview/IProvider.php', 'OCP\\Preview\\IProviderV2' => $baseDir . '/lib/public/Preview/IProviderV2.php', 'OCP\\Preview\\IVersionedPreviewFile' => $baseDir . '/lib/public/Preview/IVersionedPreviewFile.php', + 'OCP\\Push\\Exceptions\\PushInstallException' => $baseDir . '/lib/public/Push/Exceptions/PushInstallException.php', + 'OCP\\Push\\Helper\\IPushHelper' => $baseDir . '/lib/public/Push/Helper/IPushHelper.php', + 'OCP\\Push\\IPushManager' => $baseDir . '/lib/public/Push/IPushManager.php', + 'OCP\\Push\\Model\\Helper\\IPushCallback' => $baseDir . '/lib/public/Push/Model/Helper/IPushCallback.php', + 'OCP\\Push\\Model\\Helper\\IPushEvent' => $baseDir . '/lib/public/Push/Model/Helper/IPushEvent.php', + 'OCP\\Push\\Model\\Helper\\IPushNotification' => $baseDir . '/lib/public/Push/Model/Helper/IPushNotification.php', + 'OCP\\Push\\Model\\IPushItem' => $baseDir . '/lib/public/Push/Model/IPushItem.php', + 'OCP\\Push\\Model\\IPushRecipients' => $baseDir . '/lib/public/Push/Model/IPushRecipients.php', + 'OCP\\Push\\Model\\IPushWrapper' => $baseDir . '/lib/public/Push/Model/IPushWrapper.php', + 'OCP\\Push\\Service\\IPushService' => $baseDir . '/lib/public/Push/Service/IPushService.php', 'OCP\\Remote\\Api\\IApiCollection' => $baseDir . '/lib/public/Remote/Api/IApiCollection.php', 'OCP\\Remote\\Api\\IApiFactory' => $baseDir . '/lib/public/Remote/Api/IApiFactory.php', 'OCP\\Remote\\Api\\ICapabilitiesApi' => $baseDir . '/lib/public/Remote/Api/ICapabilitiesApi.php', @@ -406,16 +416,6 @@ 'OCP\\Share_Backend' => $baseDir . '/lib/public/Share_Backend.php', 'OCP\\Share_Backend_Collection' => $baseDir . '/lib/public/Share_Backend_Collection.php', 'OCP\\Share_Backend_File_Dependent' => $baseDir . '/lib/public/Share_Backend_File_Dependent.php', - 'OCP\\Stratos\\Exceptions\\StratosInstallException' => $baseDir . '/lib/public/Stratos/Exceptions/StratosInstallException.php', - 'OCP\\Stratos\\Helper\\IStratosHelper' => $baseDir . '/lib/public/Stratos/Helper/IStratosHelper.php', - 'OCP\\Stratos\\IStratosManager' => $baseDir . '/lib/public/Stratos/IStratosManager.php', - 'OCP\\Stratos\\Model\\Helper\\IStratosCallback' => $baseDir . '/lib/public/Stratos/Model/Helper/IStratosCallback.php', - 'OCP\\Stratos\\Model\\Helper\\IStratosEvent' => $baseDir . '/lib/public/Stratos/Model/Helper/IStratosEvent.php', - 'OCP\\Stratos\\Model\\Helper\\IStratosNotification' => $baseDir . '/lib/public/Stratos/Model/Helper/IStratosNotification.php', - 'OCP\\Stratos\\Model\\IStratosItem' => $baseDir . '/lib/public/Stratos/Model/IStratosItem.php', - 'OCP\\Stratos\\Model\\IStratosRecipients' => $baseDir . '/lib/public/Stratos/Model/IStratosRecipients.php', - 'OCP\\Stratos\\Model\\IStratosWrapper' => $baseDir . '/lib/public/Stratos/Model/IStratosWrapper.php', - 'OCP\\Stratos\\Service\\IStratosService' => $baseDir . '/lib/public/Stratos/Service/IStratosService.php', 'OCP\\Support\\CrashReport\\ICollectBreadcrumbs' => $baseDir . '/lib/public/Support/CrashReport/ICollectBreadcrumbs.php', 'OCP\\Support\\CrashReport\\IMessageReporter' => $baseDir . '/lib/public/Support/CrashReport/IMessageReporter.php', 'OCP\\Support\\CrashReport\\IRegistry' => $baseDir . '/lib/public/Support/CrashReport/IRegistry.php', @@ -1066,6 +1066,13 @@ 'OC\\Preview\\Watcher' => $baseDir . '/lib/private/Preview/Watcher.php', 'OC\\Preview\\WatcherConnector' => $baseDir . '/lib/private/Preview/WatcherConnector.php', 'OC\\Preview\\XBitmap' => $baseDir . '/lib/private/Preview/XBitmap.php', + 'OC\\Push\\Model\\Helper\\PushCallback' => $baseDir . '/lib/private/Push/Model/Helper/PushCallback.php', + 'OC\\Push\\Model\\Helper\\PushEvent' => $baseDir . '/lib/private/Push/Model/Helper/PushEvent.php', + 'OC\\Push\\Model\\Helper\\PushNotification' => $baseDir . '/lib/private/Push/Model/Helper/PushNotification.php', + 'OC\\Push\\Model\\PushItem' => $baseDir . '/lib/private/Push/Model/PushItem.php', + 'OC\\Push\\Model\\PushRecipients' => $baseDir . '/lib/private/Push/Model/PushRecipients.php', + 'OC\\Push\\Model\\PushWrapper' => $baseDir . '/lib/private/Push/Model/PushWrapper.php', + 'OC\\Push\\PushManager' => $baseDir . '/lib/private/Push/PushManager.php', 'OC\\RedisFactory' => $baseDir . '/lib/private/RedisFactory.php', 'OC\\Remote\\Api\\ApiBase' => $baseDir . '/lib/private/Remote/Api/ApiBase.php', 'OC\\Remote\\Api\\ApiCollection' => $baseDir . '/lib/private/Remote/Api/ApiCollection.php', @@ -1200,13 +1207,6 @@ 'OC\\Share\\Helper' => $baseDir . '/lib/private/Share/Helper.php', 'OC\\Share\\SearchResultSorter' => $baseDir . '/lib/private/Share/SearchResultSorter.php', 'OC\\Share\\Share' => $baseDir . '/lib/private/Share/Share.php', - 'OC\\Stratos\\Model\\Helper\\StratosCallback' => $baseDir . '/lib/private/Stratos/Model/Helper/StratosCallback.php', - 'OC\\Stratos\\Model\\Helper\\StratosEvent' => $baseDir . '/lib/private/Stratos/Model/Helper/StratosEvent.php', - 'OC\\Stratos\\Model\\Helper\\StratosNotification' => $baseDir . '/lib/private/Stratos/Model/Helper/StratosNotification.php', - 'OC\\Stratos\\Model\\StratosItem' => $baseDir . '/lib/private/Stratos/Model/StratosItem.php', - 'OC\\Stratos\\Model\\StratosRecipients' => $baseDir . '/lib/private/Stratos/Model/StratosRecipients.php', - 'OC\\Stratos\\Model\\StratosWrapper' => $baseDir . '/lib/private/Stratos/Model/StratosWrapper.php', - 'OC\\Stratos\\StratosManager' => $baseDir . '/lib/private/Stratos/StratosManager.php', 'OC\\Streamer' => $baseDir . '/lib/private/Streamer.php', 'OC\\SubAdmin' => $baseDir . '/lib/private/SubAdmin.php', 'OC\\Support\\CrashReport\\Registry' => $baseDir . '/lib/private/Support/CrashReport/Registry.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 3bc5b4938865f..dda59b9c9641a 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -397,6 +397,16 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Preview\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Preview/IProvider.php', 'OCP\\Preview\\IProviderV2' => __DIR__ . '/../../..' . '/lib/public/Preview/IProviderV2.php', 'OCP\\Preview\\IVersionedPreviewFile' => __DIR__ . '/../../..' . '/lib/public/Preview/IVersionedPreviewFile.php', + 'OCP\\Push\\Exceptions\\PushInstallException' => __DIR__ . '/../../..' . '/lib/public/Push/Exceptions/PushInstallException.php', + 'OCP\\Push\\Helper\\IPushHelper' => __DIR__ . '/../../..' . '/lib/public/Push/Helper/IPushHelper.php', + 'OCP\\Push\\IPushManager' => __DIR__ . '/../../..' . '/lib/public/Push/IPushManager.php', + 'OCP\\Push\\Model\\Helper\\IPushCallback' => __DIR__ . '/../../..' . '/lib/public/Push/Model/Helper/IPushCallback.php', + 'OCP\\Push\\Model\\Helper\\IPushEvent' => __DIR__ . '/../../..' . '/lib/public/Push/Model/Helper/IPushEvent.php', + 'OCP\\Push\\Model\\Helper\\IPushNotification' => __DIR__ . '/../../..' . '/lib/public/Push/Model/Helper/IPushNotification.php', + 'OCP\\Push\\Model\\IPushItem' => __DIR__ . '/../../..' . '/lib/public/Push/Model/IPushItem.php', + 'OCP\\Push\\Model\\IPushRecipients' => __DIR__ . '/../../..' . '/lib/public/Push/Model/IPushRecipients.php', + 'OCP\\Push\\Model\\IPushWrapper' => __DIR__ . '/../../..' . '/lib/public/Push/Model/IPushWrapper.php', + 'OCP\\Push\\Service\\IPushService' => __DIR__ . '/../../..' . '/lib/public/Push/Service/IPushService.php', 'OCP\\Remote\\Api\\IApiCollection' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/IApiCollection.php', 'OCP\\Remote\\Api\\IApiFactory' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/IApiFactory.php', 'OCP\\Remote\\Api\\ICapabilitiesApi' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/ICapabilitiesApi.php', @@ -440,16 +450,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Share_Backend' => __DIR__ . '/../../..' . '/lib/public/Share_Backend.php', 'OCP\\Share_Backend_Collection' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_Collection.php', 'OCP\\Share_Backend_File_Dependent' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_File_Dependent.php', - 'OCP\\Stratos\\Exceptions\\StratosInstallException' => __DIR__ . '/../../..' . '/lib/public/Stratos/Exceptions/StratosInstallException.php', - 'OCP\\Stratos\\Helper\\IStratosHelper' => __DIR__ . '/../../..' . '/lib/public/Stratos/Helper/IStratosHelper.php', - 'OCP\\Stratos\\IStratosManager' => __DIR__ . '/../../..' . '/lib/public/Stratos/IStratosManager.php', - 'OCP\\Stratos\\Model\\Helper\\IStratosCallback' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/Helper/IStratosCallback.php', - 'OCP\\Stratos\\Model\\Helper\\IStratosEvent' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/Helper/IStratosEvent.php', - 'OCP\\Stratos\\Model\\Helper\\IStratosNotification' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/Helper/IStratosNotification.php', - 'OCP\\Stratos\\Model\\IStratosItem' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosItem.php', - 'OCP\\Stratos\\Model\\IStratosRecipients' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosRecipients.php', - 'OCP\\Stratos\\Model\\IStratosWrapper' => __DIR__ . '/../../..' . '/lib/public/Stratos/Model/IStratosWrapper.php', - 'OCP\\Stratos\\Service\\IStratosService' => __DIR__ . '/../../..' . '/lib/public/Stratos/Service/IStratosService.php', 'OCP\\Support\\CrashReport\\ICollectBreadcrumbs' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/ICollectBreadcrumbs.php', 'OCP\\Support\\CrashReport\\IMessageReporter' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/IMessageReporter.php', 'OCP\\Support\\CrashReport\\IRegistry' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/IRegistry.php', @@ -1100,6 +1100,13 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Preview\\Watcher' => __DIR__ . '/../../..' . '/lib/private/Preview/Watcher.php', 'OC\\Preview\\WatcherConnector' => __DIR__ . '/../../..' . '/lib/private/Preview/WatcherConnector.php', 'OC\\Preview\\XBitmap' => __DIR__ . '/../../..' . '/lib/private/Preview/XBitmap.php', + 'OC\\Push\\Model\\Helper\\PushCallback' => __DIR__ . '/../../..' . '/lib/private/Push/Model/Helper/PushCallback.php', + 'OC\\Push\\Model\\Helper\\PushEvent' => __DIR__ . '/../../..' . '/lib/private/Push/Model/Helper/PushEvent.php', + 'OC\\Push\\Model\\Helper\\PushNotification' => __DIR__ . '/../../..' . '/lib/private/Push/Model/Helper/PushNotification.php', + 'OC\\Push\\Model\\PushItem' => __DIR__ . '/../../..' . '/lib/private/Push/Model/PushItem.php', + 'OC\\Push\\Model\\PushRecipients' => __DIR__ . '/../../..' . '/lib/private/Push/Model/PushRecipients.php', + 'OC\\Push\\Model\\PushWrapper' => __DIR__ . '/../../..' . '/lib/private/Push/Model/PushWrapper.php', + 'OC\\Push\\PushManager' => __DIR__ . '/../../..' . '/lib/private/Push/PushManager.php', 'OC\\RedisFactory' => __DIR__ . '/../../..' . '/lib/private/RedisFactory.php', 'OC\\Remote\\Api\\ApiBase' => __DIR__ . '/../../..' . '/lib/private/Remote/Api/ApiBase.php', 'OC\\Remote\\Api\\ApiCollection' => __DIR__ . '/../../..' . '/lib/private/Remote/Api/ApiCollection.php', @@ -1234,13 +1241,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Share\\Helper' => __DIR__ . '/../../..' . '/lib/private/Share/Helper.php', 'OC\\Share\\SearchResultSorter' => __DIR__ . '/../../..' . '/lib/private/Share/SearchResultSorter.php', 'OC\\Share\\Share' => __DIR__ . '/../../..' . '/lib/private/Share/Share.php', - 'OC\\Stratos\\Model\\Helper\\StratosCallback' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/Helper/StratosCallback.php', - 'OC\\Stratos\\Model\\Helper\\StratosEvent' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/Helper/StratosEvent.php', - 'OC\\Stratos\\Model\\Helper\\StratosNotification' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/Helper/StratosNotification.php', - 'OC\\Stratos\\Model\\StratosItem' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosItem.php', - 'OC\\Stratos\\Model\\StratosRecipients' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosRecipients.php', - 'OC\\Stratos\\Model\\StratosWrapper' => __DIR__ . '/../../..' . '/lib/private/Stratos/Model/StratosWrapper.php', - 'OC\\Stratos\\StratosManager' => __DIR__ . '/../../..' . '/lib/private/Stratos/StratosManager.php', 'OC\\Streamer' => __DIR__ . '/../../..' . '/lib/private/Streamer.php', 'OC\\SubAdmin' => __DIR__ . '/../../..' . '/lib/private/SubAdmin.php', 'OC\\Support\\CrashReport\\Registry' => __DIR__ . '/../../..' . '/lib/private/Support/CrashReport/Registry.php', diff --git a/lib/private/Stratos/Model/Helper/StratosCallback.php b/lib/private/Push/Model/Helper/PushCallback.php similarity index 79% rename from lib/private/Stratos/Model/Helper/StratosCallback.php rename to lib/private/Push/Model/Helper/PushCallback.php index 8da49741ada67..081e3c5614417 100644 --- a/lib/private/Stratos/Model/Helper/StratosCallback.php +++ b/lib/private/Push/Model/Helper/PushCallback.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,21 +28,21 @@ */ -namespace OC\Stratos\Model\Helper; +namespace OC\Push\Model\Helper; use daita\NcSmallPhpTools\Traits\TArrayTools; use JsonSerializable; -use OC\Stratos\Model\StratosRecipients; -use OCP\Stratos\Model\Helper\IStratosCallback; +use OC\Push\Model\PushRecipients; +use OCP\Push\Model\Helper\IPushCallback; /** - * Class StratosCallback + * Class PushCallback * - * @package OC\Stratos\Model\Helper + * @package OC\Push\Model\Helper */ -class StratosCallback extends StratosRecipients implements IStratosCallback, JsonSerializable { +class PushCallback extends PushRecipients implements IPushCallback, JsonSerializable { use TArrayTools; @@ -59,7 +59,7 @@ class StratosCallback extends StratosRecipients implements IStratosCallback, Jso /** - * StratosCallback constructor. + * PushCallback constructor. * * @param string $app * @param $source @@ -80,9 +80,9 @@ public function getApp(): string { /** * @param string $app * - * @return IStratosCallback + * @return IPushCallback */ - public function setApp(string $app): IStratosCallback { + public function setApp(string $app): IPushCallback { $this->app = $app; return $this; @@ -99,9 +99,9 @@ public function getSource(): string { /** * @param string $source * - * @return IStratosCallback + * @return IPushCallback */ - public function setSource(string $source): IStratosCallback { + public function setSource(string $source): IPushCallback { $this->source = $source; return $this; @@ -122,9 +122,9 @@ public function getPayload(): array { /** * @param array $payload * - * @return IStratosCallback + * @return IPushCallback */ - public function setPayload(array $payload): IStratosCallback { + public function setPayload(array $payload): IPushCallback { $this->payload = $payload; return $this; @@ -135,7 +135,7 @@ public function setPayload(array $payload): IStratosCallback { * * @return self */ - public function setPayloadSerializable(JsonSerializable $payload): IStratosCallback { + public function setPayloadSerializable(JsonSerializable $payload): IPushCallback { $this->payload = $payload; return $this; diff --git a/lib/private/Stratos/Model/Helper/StratosEvent.php b/lib/private/Push/Model/Helper/PushEvent.php similarity index 79% rename from lib/private/Stratos/Model/Helper/StratosEvent.php rename to lib/private/Push/Model/Helper/PushEvent.php index 46f963276f363..e10c5dbce5123 100644 --- a/lib/private/Stratos/Model/Helper/StratosEvent.php +++ b/lib/private/Push/Model/Helper/PushEvent.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,21 +28,21 @@ */ -namespace OC\Stratos\Model\Helper; +namespace OC\Push\Model\Helper; use daita\NcSmallPhpTools\Traits\TArrayTools; use JsonSerializable; -use OC\Stratos\Model\StratosRecipients; -use OCP\Stratos\Model\Helper\IStratosEvent; +use OC\Push\Model\PushRecipients; +use OCP\Push\Model\Helper\IPushEvent; /** - * Class StratosEvent + * Class PushEvent * - * @package OC\Stratos\Model\Helper + * @package OC\Push\Model\Helper */ -class StratosEvent extends StratosRecipients implements IStratosEvent, JsonSerializable { +class PushEvent extends PushRecipients implements IPushEvent, JsonSerializable { use TArrayTools; @@ -59,7 +59,7 @@ class StratosEvent extends StratosRecipients implements IStratosEvent, JsonSeria /** - * StratosEvent constructor. + * PushEvent constructor. * * @param string $app * @param string $command @@ -80,9 +80,9 @@ public function getApp(): string { /** * @param string $app * - * @return IStratosEvent + * @return IPushEvent */ - public function setApp(string $app): IStratosEvent { + public function setApp(string $app): IPushEvent { $this->app = $app; return $this; @@ -99,9 +99,9 @@ public function getCommand(): string { /** * @param string $command * - * @return IStratosEvent + * @return IPushEvent */ - public function setCommand(string $command): IStratosEvent { + public function setCommand(string $command): IPushEvent { $this->command = $command; return $this; @@ -122,9 +122,9 @@ public function getPayload(): array { /** * @param array $payload * - * @return IStratosEvent + * @return IPushEvent */ - public function setPayload(array $payload): IStratosEvent { + public function setPayload(array $payload): IPushEvent { $this->payload = $payload; return $this; @@ -133,9 +133,9 @@ public function setPayload(array $payload): IStratosEvent { /** * @param JsonSerializable $payload * - * @return IStratosEvent + * @return IPushEvent */ - public function setPayloadSerializable(JsonSerializable $payload): IStratosEvent { + public function setPayloadSerializable(JsonSerializable $payload): IPushEvent { $this->payload = $payload->jsonSerialize(); return $this; diff --git a/lib/private/Stratos/Model/Helper/StratosNotification.php b/lib/private/Push/Model/Helper/PushNotification.php similarity index 73% rename from lib/private/Stratos/Model/Helper/StratosNotification.php rename to lib/private/Push/Model/Helper/PushNotification.php index 623c8881bc8b6..9d5017fe4bc1e 100644 --- a/lib/private/Stratos/Model/Helper/StratosNotification.php +++ b/lib/private/Push/Model/Helper/PushNotification.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,22 +28,22 @@ */ -namespace OC\Stratos\Model\Helper; +namespace OC\Push\Model\Helper; use daita\NcSmallPhpTools\Traits\TArrayTools; use JsonSerializable; -use OCP\Stratos\Model\IStratosItem; -use OCP\Stratos\Model\Helper\IStratosNotification; -use OC\Stratos\Model\StratosRecipients; +use OC\Push\Model\PushRecipients; +use OCP\Push\Model\Helper\IPushNotification; +use OCP\Push\Model\IPushItem; /** - * Class StratosNotification + * Class PushNotification * - * @package OC\Stratos\Model\Helper + * @package OC\Push\Model\Helper */ -class StratosNotification extends StratosRecipients implements IStratosNotification, JsonSerializable { +class PushNotification extends PushRecipients implements IPushNotification, JsonSerializable { use TArrayTools; @@ -69,12 +69,12 @@ class StratosNotification extends StratosRecipients implements IStratosNotificat /** - * StratosNotification constructor. + * PushNotification constructor. * * @param string $app * @param int $ttl */ - public function __construct($app = '', $ttl = IStratosItem::TTL_INSTANT) { + public function __construct($app = '', $ttl = IPushItem::TTL_INSTANT) { $this->app = $app; $this->ttl = $ttl; } @@ -90,9 +90,9 @@ public function getApp(): string { /** * @param string $app * - * @return IStratosNotification + * @return IPushNotification */ - public function setApp(string $app): IStratosNotification { + public function setApp(string $app): IPushNotification { $this->app = $app; return $this; @@ -108,9 +108,9 @@ public function getTitle(): string { /** * @param string $title * - * @return IStratosNotification + * @return IPushNotification */ - public function setTitle(string $title): IStratosNotification { + public function setTitle(string $title): IPushNotification { $this->title = $title; return $this; @@ -127,9 +127,9 @@ public function getMessage(): string { /** * @param string $message * - * @return IStratosNotification + * @return IPushNotification */ - public function setMessage(string $message): IStratosNotification { + public function setMessage(string $message): IPushNotification { $this->message = $message; return $this; @@ -146,9 +146,9 @@ public function getLevel(): string { /** * @param string $level * - * @return IStratosNotification + * @return IPushNotification */ - public function setLevel(string $level): IStratosNotification { + public function setLevel(string $level): IPushNotification { $this->level = $level; return $this; @@ -165,9 +165,9 @@ public function getLink(): string { /** * @param string $link * - * @return IStratosNotification + * @return IPushNotification */ - public function setLink(string $link): IStratosNotification { + public function setLink(string $link): IPushNotification { $this->link = $link; return $this; @@ -184,9 +184,9 @@ public function getTtl(): int { /** * @param int $ttl * - * @return IStratosNotification + * @return IPushNotification */ - public function setTtl(int $ttl): IStratosNotification { + public function setTtl(int $ttl): IPushNotification { $this->ttl = $ttl; return $this; diff --git a/lib/private/Stratos/Model/StratosItem.php b/lib/private/Push/Model/PushItem.php similarity index 78% rename from lib/private/Stratos/Model/StratosItem.php rename to lib/private/Push/Model/PushItem.php index d83162a1eaebc..ade1570bbfc32 100644 --- a/lib/private/Stratos/Model/StratosItem.php +++ b/lib/private/Push/Model/PushItem.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,21 +28,21 @@ */ -namespace OC\Stratos\Model; +namespace OC\Push\Model; use daita\NcSmallPhpTools\Traits\TArrayTools; use daita\NcSmallPhpTools\Traits\TStringTools; use JsonSerializable; -use OCP\Stratos\Model\IStratosItem; +use OCP\Push\Model\IPushItem; /** - * Class StratosItem + * Class PushItem * - * @package OC\Stratos\Model + * @package OC\Push\Model */ -class StratosItem implements IStratosItem, JsonSerializable { +class PushItem implements IPushItem, JsonSerializable { use TArrayTools; @@ -77,7 +77,7 @@ class StratosItem implements IStratosItem, JsonSerializable { /** - * StratosItem constructor. + * PushItem constructor. * * @param string $app * @param string $type @@ -93,9 +93,9 @@ public function __construct($app = '', $type = '') { /** * @param int $id * - * @return StratosItem + * @return PushItem */ - public function setId(int $id): IStratosItem { + public function setId(int $id): IPushItem { $this->id = $id; return $this; @@ -119,9 +119,9 @@ public function getToken(): string { /** * @param string $token * - * @return StratosItem + * @return PushItem */ - public function setToken(string $token): IStratosItem { + public function setToken(string $token): IPushItem { $this->token = $token; return $this; @@ -138,9 +138,9 @@ public function getApp(): string { /** * @param string $app * - * @return IStratosItem + * @return IPushItem */ - public function setApp(string $app): IStratosItem { + public function setApp(string $app): IPushItem { $this->app = $app; return $this; @@ -157,9 +157,9 @@ public function getSource(): string { /** * @param string $source * - * @return IStratosItem + * @return IPushItem */ - public function setSource(string $source): IStratosItem { + public function setSource(string $source): IPushItem { $this->source = $source; return $this; @@ -180,9 +180,9 @@ public function getPayload(): array { /** * @param array $payload * - * @return IStratosItem + * @return IPushItem */ - public function setPayload(array $payload): IStratosItem { + public function setPayload(array $payload): IPushItem { $this->payload = $payload; return $this; @@ -191,9 +191,9 @@ public function setPayload(array $payload): IStratosItem { /** * @param JsonSerializable $payload * - * @return IStratosItem + * @return IPushItem */ - public function setPayloadSerializable(JsonSerializable $payload): IStratosItem { + public function setPayloadSerializable(JsonSerializable $payload): IPushItem { $this->payload = $payload; return $this; @@ -210,9 +210,9 @@ public function getType(): string { /** * @param string $type * - * @return StratosItem + * @return PushItem */ - public function setType(string $type): IStratosItem { + public function setType(string $type): IPushItem { $this->type = $type; return $this; @@ -229,9 +229,9 @@ public function getTtl(): int { /** * @param int $ttl * - * @return StratosItem + * @return PushItem */ - public function setTtl(int $ttl): IStratosItem { + public function setTtl(int $ttl): IPushItem { $this->ttl = $ttl; return $this; @@ -241,9 +241,9 @@ public function setTtl(int $ttl): IStratosItem { /** * @param array $meta * - * @return IStratosItem + * @return IPushItem */ - public function setMeta(array $meta): IStratosItem { + public function setMeta(array $meta): IPushItem { $this->meta = $meta; return $this; @@ -253,9 +253,9 @@ public function setMeta(array $meta): IStratosItem { * @param string $k * @param string $v * - * @return IStratosItem + * @return IPushItem */ - public function addMeta(string $k, string $v): IStratosItem { + public function addMeta(string $k, string $v): IPushItem { $this->meta[$k] = $v; return $this; @@ -265,9 +265,9 @@ public function addMeta(string $k, string $v): IStratosItem { * @param string $k * @param array $v * - * @return IStratosItem + * @return IPushItem */ - public function addMetaArray(string $k, array $v): IStratosItem { + public function addMetaArray(string $k, array $v): IPushItem { $this->meta[$k] = $v; return $this; @@ -291,9 +291,9 @@ public function getCreation(): int { /** * @param int $creation * - * @return StratosItem + * @return PushItem */ - public function setCreation(int $creation): IStratosItem { + public function setCreation(int $creation): IPushItem { $this->creation = $creation; return $this; @@ -303,9 +303,9 @@ public function setCreation(int $creation): IStratosItem { /** * @param array $import * - * @return IStratosItem + * @return IPushItem */ - public function import(array $import): IStratosItem { + public function import(array $import): IPushItem { $this->setId($this->getInt('id', $import, 0)); $this->setToken($this->get('token', $import, '')); $this->setType($this->get('type', $import, '')); diff --git a/lib/private/Stratos/Model/StratosRecipients.php b/lib/private/Push/Model/PushRecipients.php similarity index 72% rename from lib/private/Stratos/Model/StratosRecipients.php rename to lib/private/Push/Model/PushRecipients.php index 2d981bf16cfef..a156f08064a50 100644 --- a/lib/private/Stratos/Model/StratosRecipients.php +++ b/lib/private/Push/Model/PushRecipients.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,19 +28,19 @@ */ -namespace OC\Stratos\Model; +namespace OC\Push\Model; use JsonSerializable; -use OCP\Stratos\Model\IStratosRecipients; +use OCP\Push\Model\IPushRecipients; /** - * Class StratosNotification + * Class PushRecipients * - * @package OC\Stratos\Model\Helper + * @package OC\Push\Model\Helper */ -class StratosRecipients implements IStratosRecipients, JsonSerializable { +class PushRecipients implements IPushRecipients, JsonSerializable { /** @var array */ @@ -65,9 +65,9 @@ class StratosRecipients implements IStratosRecipients, JsonSerializable { /** * @param string $user * - * @return IStratosRecipients + * @return IPushRecipients */ - public function addUser(string $user): IStratosRecipients { + public function addUser(string $user): IPushRecipients { array_push($this->users, $user); return $this; @@ -76,9 +76,9 @@ public function addUser(string $user): IStratosRecipients { /** * @param string[] $users * - * @return IStratosRecipients + * @return IPushRecipients */ - public function addUsers(array $users): IStratosRecipients { + public function addUsers(array $users): IPushRecipients { $this->users = array_merge($this->users, $users); return $this; @@ -87,18 +87,18 @@ public function addUsers(array $users): IStratosRecipients { /** * @param string $user * - * @return IStratosRecipients + * @return IPushRecipients */ - public function removeUser(string $user): IStratosRecipients { + public function removeUser(string $user): IPushRecipients { return $this->removeUsers([$user]); } /** * @param string[] $users * - * @return IStratosRecipients + * @return IPushRecipients */ - public function removeUsers(array $users): IStratosRecipients { + public function removeUsers(array $users): IPushRecipients { $this->removedUsers = array_merge($this->removedUsers, $users); return $this; @@ -108,9 +108,9 @@ public function removeUsers(array $users): IStratosRecipients { /** * @param string $group * - * @return IStratosRecipients + * @return IPushRecipients */ - public function addGroup(string $group): IStratosRecipients { + public function addGroup(string $group): IPushRecipients { array_push($this->groups, $group); return $this; @@ -119,9 +119,9 @@ public function addGroup(string $group): IStratosRecipients { /** * @param string[] $groups * - * @return IStratosRecipients + * @return IPushRecipients */ - public function addGroups(array $groups): IStratosRecipients { + public function addGroups(array $groups): IPushRecipients { $this->groups = array_merge($this->groups, $groups); return $this; @@ -130,18 +130,18 @@ public function addGroups(array $groups): IStratosRecipients { /** * @param string $group * - * @return IStratosRecipients + * @return IPushRecipients */ - public function removeGroup(string $group): IStratosRecipients { + public function removeGroup(string $group): IPushRecipients { return $this->removeGroups([$group]); } /** * @param string[] $groups * - * @return IStratosRecipients + * @return IPushRecipients */ - public function removeGroups(array $groups): IStratosRecipients { + public function removeGroups(array $groups): IPushRecipients { $this->removedGroups = array_merge($this->removedGroups, $groups); return $this; @@ -181,18 +181,18 @@ public function getRemovedGroups(): array { /** * @param string $app * - * @return IStratosRecipients + * @return IPushRecipients */ - public function filterApp(string $app): IStratosRecipients { + public function filterApp(string $app): IPushRecipients { return $this->filterApps([$app]); } /** * @param string[] $apps * - * @return IStratosRecipients + * @return IPushRecipients */ - public function filterApps(array $apps): IStratosRecipients { + public function filterApps(array $apps): IPushRecipients { $this->filteredApps = array_merge($this->filteredApps, $apps); return $this; @@ -209,18 +209,18 @@ public function getFilteredApps(): array { /** * @param string $app * - * @return IStratosRecipients + * @return IPushRecipients */ - public function limitToApp(string $app): IStratosRecipients { + public function limitToApp(string $app): IPushRecipients { return $this->limitToApps([$app]); } /** * @param string[] $apps * - * @return IStratosRecipients + * @return IPushRecipients */ - public function limitToApps(array $apps): IStratosRecipients { + public function limitToApps(array $apps): IPushRecipients { $this->limitToApps = array_merge($this->limitToApps, $apps); return $this; diff --git a/lib/private/Stratos/Model/StratosWrapper.php b/lib/private/Push/Model/PushWrapper.php similarity index 71% rename from lib/private/Stratos/Model/StratosWrapper.php rename to lib/private/Push/Model/PushWrapper.php index e15b6e072d11f..c0e30021f1667 100644 --- a/lib/private/Stratos/Model/StratosWrapper.php +++ b/lib/private/Push/Model/PushWrapper.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,27 +28,27 @@ */ -namespace OC\Stratos\Model; +namespace OC\Push\Model; use daita\NcSmallPhpTools\Traits\TArrayTools; use JsonSerializable; -use OCP\Stratos\Model\IStratosItem; -use OCP\Stratos\Model\IStratosWrapper; +use OCP\Push\Model\IPushItem; +use OCP\Push\Model\IPushWrapper; /** - * Class StratosManager + * Class PushManager * - * @package OC\Stratos\Model + * @package OC\Push\Model */ -class StratosWrapper implements IStratosWrapper, JsonSerializable { +class PushWrapper implements IPushWrapper, JsonSerializable { use TArrayTools; - /** @var IStratosItem */ + /** @var IPushItem */ private $item; /** @var array */ @@ -59,12 +59,12 @@ class StratosWrapper implements IStratosWrapper, JsonSerializable { /** - * StratosWrapper constructor. + * PushWrapper constructor. * - * @param IStratosItem $item + * @param IPushItem $item */ public function __construct($item = null) { - if ($item !== null && $item instanceof IStratosItem) { + if ($item !== null && $item instanceof IPushItem) { $this->item = $item; } @@ -80,18 +80,18 @@ public function hasItem(): bool { } /** - * @return IStratosItem + * @return IPushItem */ - public function getItem(): IStratosItem { + public function getItem(): IPushItem { return $this->item; } /** - * @param IStratosItem $item + * @param IPushItem $item * - * @return IStratosWrapper + * @return IPushWrapper */ - public function setItem(IStratosItem $item): IStratosWrapper { + public function setItem(IPushItem $item): IPushWrapper { $this->item = $item; return $this; @@ -108,9 +108,9 @@ public function getRecipients(): array { /** * @param array $recipients * - * @return IStratosWrapper + * @return IPushWrapper */ - public function setRecipients(array $recipients): IStratosWrapper { + public function setRecipients(array $recipients): IPushWrapper { $this->recipients = []; $this->addRecipients($recipients); @@ -120,9 +120,9 @@ public function setRecipients(array $recipients): IStratosWrapper { /** * @param string $recipient * - * @return IStratosWrapper + * @return IPushWrapper */ - public function addRecipient(string $recipient): IStratosWrapper { + public function addRecipient(string $recipient): IPushWrapper { if (!in_array($recipient, $this->recipients)) { $this->recipients[] = $recipient; } @@ -133,9 +133,9 @@ public function addRecipient(string $recipient): IStratosWrapper { /** * @param array $recipients * - * @return IStratosWrapper + * @return IPushWrapper */ - public function addRecipients(array $recipients): IStratosWrapper { + public function addRecipients(array $recipients): IPushWrapper { foreach ($recipients as $recipient) { $this->addRecipient($recipient); } @@ -149,8 +149,8 @@ public function addRecipients(array $recipients): IStratosWrapper { * * @return self */ - public function import(array $import): IStratosWrapper { - $item = new StratosItem(); + public function import(array $import): IPushWrapper { + $item = new PushItem(); $item->import($this->getArray('item', $import, [])); $this->setItem($item); diff --git a/lib/private/Stratos/StratosManager.php b/lib/private/Push/PushManager.php similarity index 52% rename from lib/private/Stratos/StratosManager.php rename to lib/private/Push/PushManager.php index 82d8bf20e32ec..0608dfa3d6d64 100644 --- a/lib/private/Stratos/StratosManager.php +++ b/lib/private/Push/PushManager.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,40 +28,40 @@ */ -namespace OC\Stratos; +namespace OC\Push; -use OCP\Stratos\Exceptions\StratosInstallException; -use OCP\Stratos\Helper\IStratosHelper; -use OCP\Stratos\IStratosManager; -use OCP\Stratos\Service\IStratosService; +use OCP\Push\Exceptions\PushInstallException; +use OCP\Push\Helper\IPushHelper; +use OCP\Push\IPushManager; +use OCP\Push\Service\IPushService; /** - * Class StratosManager + * Class PushManager * - * @package OC\Stratos + * @package OC\Push */ -class StratosManager implements IStratosManager { +class PushManager implements IPushManager { - /** @var IStratosService */ - private $stratosService; + /** @var IPushService */ + private $pushService; - /** @var IStratosHelper */ - private $stratosHelper; + /** @var IPushHelper */ + private $pushHelper; /** - * @param IStratosService $stratosService - * @param IStratosHelper $stratosHelper + * @param IPushService $pushService + * @param IPushHelper $pushHelper * * @since 18.0.0 */ - public function registerStratos(IStratosService $stratosService, IStratosHelper $stratosHelper + public function registerPushApp(IPushService $pushService, IPushHelper $pushHelper ) { - $this->stratosService = $stratosService; - $this->stratosHelper = $stratosHelper; + $this->pushService = $pushService; + $this->pushHelper = $pushHelper; } @@ -73,7 +73,7 @@ public function isAvailable(): bool { $this->checkRegistration(); return true; - } catch (StratosInstallException $e) { + } catch (PushInstallException $e) { } return false; @@ -81,33 +81,35 @@ public function isAvailable(): bool { /** - * @return IStratosService - * @throws StratosInstallException + * @return IPushService + * @throws PushInstallException */ - public function getStratosService(): IStratosService { + public function getPushService(): IPushService { $this->checkRegistration(); - return $this->stratosService; + return $this->pushService; } /** - * @return IStratosHelper - * @throws StratosInstallException + * @return IPushHelper + * @throws PushInstallException */ - public function getStratosHelper(): IStratosHelper { + public function getPushHelper(): IPushHelper { $this->checkRegistration(); - return $this->stratosHelper; + return $this->pushHelper; } /** - * @throws StratosInstallException + * @throws PushInstallException */ private function checkRegistration() { - if ($this->stratosService === null || $this->stratosHelper === null) { - throw new StratosInstallException('Stratos is not available. Please check the Stratos App is installed and enabled'); + if ($this->pushService === null || $this->pushHelper === null) { + throw new PushInstallException( + 'Nextcloud Push is not available. Please check the Nextcloud Push App is installed and enabled' + ); } } diff --git a/lib/private/Server.php b/lib/private/Server.php index 442407e983982..f055836a8657f 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -101,6 +101,7 @@ use OC\Notification\Manager; use OC\OCS\DiscoveryService; use OC\Preview\GeneratorHelper; +use OC\Push\PushManager; use OC\Remote\Api\ApiFactory; use OC\Remote\InstanceFactory; use OC\RichObjectStrings\Validator; @@ -119,7 +120,6 @@ use OC\Session\CryptoWrapper; use OC\Share20\ProviderFactory; use OC\Share20\ShareHelper; -use OC\Stratos\StratosManager; use OC\SystemTag\ManagerFactory as SystemTagManagerFactory; use OC\Tagging\TagMapper; use OC\Template\IconsCacher; @@ -159,7 +159,7 @@ use OCP\RichObjectStrings\IValidator; use OCP\Security\IContentSecurityPolicyManager; use OCP\Share\IShareHelper; -use OCP\Stratos\IStratosManager; +use OCP\Push\IPushManager; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; @@ -1187,7 +1187,7 @@ public function __construct($webRoot, \OC\Config $config) { $this->registerAlias(IDashboardManager::class, DashboardManager::class); $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); - $this->registerAlias(IStratosManager::class, StratosManager::class); + $this->registerAlias(IPushManager::class, PushManager::class); $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) { return new \OC\Security\IdentityProof\Manager( diff --git a/lib/public/Stratos/Exceptions/StratosInstallException.php b/lib/public/Push/Exceptions/PushInstallException.php similarity index 84% rename from lib/public/Stratos/Exceptions/StratosInstallException.php rename to lib/public/Push/Exceptions/PushInstallException.php index 9a852b19491f0..541796c17e346 100644 --- a/lib/public/Stratos/Exceptions/StratosInstallException.php +++ b/lib/public/Push/Exceptions/PushInstallException.php @@ -2,7 +2,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -27,15 +27,15 @@ */ -namespace OCP\Stratos\Exceptions; +namespace OCP\Push\Exceptions; /** * @since 18.0.0 * - * Class StratosInstallException + * Class PushInstallException * - * @package OCP\Stratos\Exceptions + * @package OCP\Push\Exceptions */ -class StratosInstallException extends \Exception { +class PushInstallException extends \Exception { } diff --git a/lib/public/Push/Helper/IPushHelper.php b/lib/public/Push/Helper/IPushHelper.php new file mode 100644 index 0000000000000..0840de2df97d4 --- /dev/null +++ b/lib/public/Push/Helper/IPushHelper.php @@ -0,0 +1,104 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Push\Helper; + + +use OCP\Push\Model\Helper\IPushCallback; +use OCP\Push\Model\Helper\IPushEvent; +use OCP\Push\Model\Helper\IPushNotification; +use OCP\Push\Model\IPushWrapper; + + +/** + * Interface IPushHelper + * + * @since 18.0.0 + * + * @package OCP\Push\Helper + */ +interface IPushHelper { + + + /** + * @param string $userId + * + * @return IPushWrapper + */ + public function test(string $userId): IPushWrapper; + + + /** + * @param IPushCallback $callback + * + * @return IPushWrapper + */ + public function toCallback(IPushCallback $callback): IPushWrapper; + + /** + * @param IPushCallback $callback + * + * @return IPushWrapper + */ + public function generateFromCallback(IPushCallback $callback): IPushWrapper; + + + + + /** + * @param IPushNotification $notification + * + * @return IPushWrapper + */ + public function pushNotification(IPushNotification $notification): IPushWrapper; + + /** + * @param IPushNotification $notification + * + * @return IPushWrapper + */ + public function generateFromNotification(IPushNotification $notification): IPushWrapper; + + + /** + * @param IPushEvent $event + * + * @return IPushWrapper + */ + public function broadcastEvent(IPushEvent $event): IPushWrapper; + + /** + * @param IPushEvent $event + * + * @return IPushWrapper + */ + public function generateFromEvent(IPushEvent $event): IPushWrapper; + +} diff --git a/lib/public/Stratos/IStratosManager.php b/lib/public/Push/IPushManager.php similarity index 62% rename from lib/public/Stratos/IStratosManager.php rename to lib/public/Push/IPushManager.php index 3ec10a87afa45..1e4d5784f6ff7 100644 --- a/lib/public/Stratos/IStratosManager.php +++ b/lib/public/Push/IPushManager.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,33 +28,33 @@ */ -namespace OCP\Stratos; +namespace OCP\Push; -use OCP\Stratos\Exceptions\StratosInstallException; -use OCP\Stratos\Helper\IStratosHelper; -use OCP\Stratos\Service\IStratosService; +use OCP\Push\Exceptions\PushInstallException; +use OCP\Push\Helper\IPushHelper; +use OCP\Push\Service\IPushService; /** - * Interface IStratosManager + * Interface IPushManager * * @since 18.0.0 * - * @package OCP\Stratos + * @package OCP\Push */ -interface IStratosManager { +interface IPushManager { /** - * Register a IStratosService. + * Register a IPushService. * - * @param IStratosService $stratosService - * @param IStratosHelper $stratosHelper + * @param IPushService $pushService + * @param IPushHelper $pushHelper * * @since 18.0.0 */ - public function registerStratos(IStratosService $stratosService, IStratosHelper $stratosHelper); + public function registerPushApp(IPushService $pushService, IPushHelper $pushHelper); /** @@ -64,17 +64,17 @@ public function isAvailable(): bool; /** - * @return IStratosService - * @throws StratosInstallException + * @return IPushService + * @throws PushInstallException */ - public function getStratosService(): IStratosService; + public function getPushService(): IPushService; /** - * @return IStratosHelper - * @throws StratosInstallException + * @return IPushHelper + * @throws PushInstallException */ - public function getStratosHelper(): IStratosHelper; + public function getPushHelper(): IPushHelper; } diff --git a/lib/public/Stratos/Model/Helper/IStratosCallback.php b/lib/public/Push/Model/Helper/IPushCallback.php similarity index 88% rename from lib/public/Stratos/Model/Helper/IStratosCallback.php rename to lib/public/Push/Model/Helper/IPushCallback.php index 166a8457a98de..ea2b81d1458ff 100644 --- a/lib/public/Stratos/Model/Helper/IStratosCallback.php +++ b/lib/public/Push/Model/Helper/IPushCallback.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,21 +28,21 @@ */ -namespace OCP\Stratos\Model\Helper; +namespace OCP\Push\Model\Helper; use JsonSerializable; -use OCP\Stratos\Model\IStratosRecipients; +use OCP\Push\Model\IPushRecipients; /** - * Interface IStratosCallback + * Interface IPushCallback * * @since 18.0.0 * - * @package OCP\Stratos\Helper + * @package OCP\Push\Helper */ -interface IStratosCallback extends IStratosRecipients { +interface IPushCallback extends IPushRecipients { const TYPE = 'Callback'; diff --git a/lib/public/Stratos/Model/Helper/IStratosEvent.php b/lib/public/Push/Model/Helper/IPushEvent.php similarity index 88% rename from lib/public/Stratos/Model/Helper/IStratosEvent.php rename to lib/public/Push/Model/Helper/IPushEvent.php index a71a343b78885..921d576b1c505 100644 --- a/lib/public/Stratos/Model/Helper/IStratosEvent.php +++ b/lib/public/Push/Model/Helper/IPushEvent.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,21 +28,21 @@ */ -namespace OCP\Stratos\Model\Helper; +namespace OCP\Push\Model\Helper; use JsonSerializable; -use OCP\Stratos\Model\IStratosRecipients; +use OCP\Push\Model\IPushRecipients; /** - * Interface IStratosEvent + * Interface IPushEvent * * @since 18.0.0 * - * @package OCP\Stratos\Helper + * @package OCP\Push\Helper */ -interface IStratosEvent extends IStratosRecipients { +interface IPushEvent extends IPushRecipients { const TYPE = 'Event'; diff --git a/lib/public/Stratos/Model/Helper/IStratosNotification.php b/lib/public/Push/Model/Helper/IPushNotification.php similarity index 90% rename from lib/public/Stratos/Model/Helper/IStratosNotification.php rename to lib/public/Push/Model/Helper/IPushNotification.php index e01a85a4f4eae..d05c88faab6d0 100644 --- a/lib/public/Stratos/Model/Helper/IStratosNotification.php +++ b/lib/public/Push/Model/Helper/IPushNotification.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,20 +28,20 @@ */ -namespace OCP\Stratos\Model\Helper; +namespace OCP\Push\Model\Helper; -use OCP\Stratos\Model\IStratosRecipients; +use OCP\Push\Model\IPushRecipients; /** - * Interface IStratosNotification + * Interface IPushNotification * * @since 18.0.0 * - * @package OCP\Stratos\Helper + * @package OCP\Push\Helper */ -interface IStratosNotification extends IStratosRecipients { +interface IPushNotification extends IPushRecipients { const TYPE = 'Notification'; diff --git a/lib/public/Stratos/Model/IStratosItem.php b/lib/public/Push/Model/IPushItem.php similarity index 92% rename from lib/public/Stratos/Model/IStratosItem.php rename to lib/public/Push/Model/IPushItem.php index 15d74c33ad318..92d774aa33547 100644 --- a/lib/public/Stratos/Model/IStratosItem.php +++ b/lib/public/Push/Model/IPushItem.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,19 +28,19 @@ */ -namespace OCP\Stratos\Model; +namespace OCP\Push\Model; use JsonSerializable; /** - * Interface IStratosItem + * Interface IPushItem * * @since 18.0.0 * - * @package OCP\Stratos + * @package OCP\Push */ -interface IStratosItem { +interface IPushItem { const TTL_INSTANT = 15; @@ -104,7 +104,7 @@ public function setPayload(array $payload): self; /** * @param JsonSerializable $payload * - * @return IStratosItem + * @return IPushItem */ public function setPayloadSerializable(JsonSerializable $payload): self; @@ -138,7 +138,7 @@ public function setTtl(int $ttl): self; /** * @param array $meta * - * @return IStratosItem + * @return IPushItem */ public function setMeta(array $meta): self; @@ -146,7 +146,7 @@ public function setMeta(array $meta): self; * @param string $k * @param string $v * - * @return IStratosItem + * @return IPushItem */ public function addMeta(string $k, string $v): self; @@ -154,7 +154,7 @@ public function addMeta(string $k, string $v): self; * @param string $k * @param array $v * - * @return IStratosItem + * @return IPushItem */ public function addMetaArray(string $k, array $v): self; diff --git a/lib/public/Stratos/Model/IStratosRecipients.php b/lib/public/Push/Model/IPushRecipients.php similarity index 83% rename from lib/public/Stratos/Model/IStratosRecipients.php rename to lib/public/Push/Model/IPushRecipients.php index 0182d83025c0f..1b0c74da62c79 100644 --- a/lib/public/Stratos/Model/IStratosRecipients.php +++ b/lib/public/Push/Model/IPushRecipients.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,43 +28,43 @@ */ -namespace OCP\Stratos\Model; +namespace OCP\Push\Model; /** - * Interface IStratosRecipients + * Interface IPushRecipients * * @since 18.0.0 * - * @package OCP\Stratos + * @package OCP\Push */ -interface IStratosRecipients { +interface IPushRecipients { /** * @param string $user * - * @return IStratosRecipients + * @return IPushRecipients */ public function addUser(string $user): self; /** * @param array $users * - * @return IStratosRecipients + * @return IPushRecipients */ public function addUsers(array $users): self; /** * @param string $user * - * @return IStratosRecipients + * @return IPushRecipients */ public function removeUser(string $user): self; /** * @param array $users * - * @return IStratosRecipients + * @return IPushRecipients */ public function removeUsers(array $users): self; @@ -73,28 +73,28 @@ public function removeUsers(array $users): self; /** * @param string $group * - * @return IStratosRecipients + * @return IPushRecipients */ public function addGroup(string $group): self; /** * @param array $groups * - * @return IStratosRecipients + * @return IPushRecipients */ public function addGroups(array $groups): self; /** * @param string $group * - * @return IStratosRecipients + * @return IPushRecipients */ public function removeGroup(string $group): self; /** * @param array $groups * - * @return IStratosRecipients + * @return IPushRecipients */ public function removeGroups(array $groups): self; @@ -124,14 +124,14 @@ public function getRemovedGroups(): array; /** * @param string $app * - * @return IStratosRecipients + * @return IPushRecipients */ public function filterApp(string $app): self; /** * @param string[] $apps * - * @return IStratosRecipients + * @return IPushRecipients */ public function filterApps(array $apps): self; @@ -144,14 +144,14 @@ public function getFilteredApps(): array; /** * @param string $app * - * @return IStratosRecipients + * @return IPushRecipients */ public function limitToApp(string $app): self; /** * @param string[] $apps * - * @return IStratosRecipients + * @return IPushRecipients */ public function limitToApps(array $apps): self; diff --git a/lib/public/Stratos/Model/IStratosWrapper.php b/lib/public/Push/Model/IPushWrapper.php similarity index 81% rename from lib/public/Stratos/Model/IStratosWrapper.php rename to lib/public/Push/Model/IPushWrapper.php index 790a2a7c6268b..d946a8f89601d 100644 --- a/lib/public/Stratos/Model/IStratosWrapper.php +++ b/lib/public/Push/Model/IPushWrapper.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,17 +28,17 @@ */ -namespace OCP\Stratos\Model; +namespace OCP\Push\Model; /** - * Interface IStratosWrapper + * Interface IPushWrapper * * @since 18.0.0 * - * @package OCP\Stratos + * @package OCP\Push */ -interface IStratosWrapper { +interface IPushWrapper { /** @@ -47,16 +47,16 @@ interface IStratosWrapper { public function hasItem(): bool; /** - * @return IStratosItem + * @return IPushItem */ - public function getItem(): IStratosItem; + public function getItem(): IPushItem; /** - * @param IStratosItem $item + * @param IPushItem $item * - * @return IStratosWrapper + * @return IPushWrapper */ - public function setItem(IStratosItem $item): self; + public function setItem(IPushItem $item): self; /** @@ -74,14 +74,14 @@ public function setRecipients(array $recipients): self; /** * @param string $recipient * - * @return IStratosWrapper + * @return IPushWrapper */ public function addRecipient(string $recipient): self; /** * @param array $recipients * - * @return IStratosWrapper + * @return IPushWrapper */ public function addRecipients(array $recipients): self; diff --git a/lib/public/Stratos/Service/IStratosService.php b/lib/public/Push/Service/IPushService.php similarity index 70% rename from lib/public/Stratos/Service/IStratosService.php rename to lib/public/Push/Service/IPushService.php index 63dd382fc423b..01146986ccce5 100644 --- a/lib/public/Stratos/Service/IStratosService.php +++ b/lib/public/Push/Service/IPushService.php @@ -3,7 +3,7 @@ /** - * Stratos - above your cloud + * Push - Nextcloud Push Service * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -28,33 +28,33 @@ */ -namespace OCP\Stratos\Service; +namespace OCP\Push\Service; -use OCP\Stratos\Model\IStratosRecipients; -use OCP\Stratos\Model\IStratosWrapper; +use OCP\Push\Model\IPushRecipients; +use OCP\Push\Model\IPushWrapper; /** - * Interface IStratosService + * Interface IPushService * * @since 18.0.0 * - * @package OCP\Stratos\Service + * @package OCP\Push\Service */ -interface IStratosService { +interface IPushService { - public function push(IStratosWrapper $wrapper); + public function push(IPushWrapper $wrapper); /** - * @param IStratosWrapper $wrapper - * @param IStratosRecipients $recipients + * @param IPushWrapper $wrapper + * @param IPushRecipients $recipients * * @return mixed */ - public function fillRecipients(IStratosWrapper $wrapper, IStratosRecipients $recipients); + public function fillRecipients(IPushWrapper $wrapper, IPushRecipients $recipients); } diff --git a/lib/public/Stratos/Helper/IStratosHelper.php b/lib/public/Stratos/Helper/IStratosHelper.php deleted file mode 100644 index 8a018d4c19889..0000000000000 --- a/lib/public/Stratos/Helper/IStratosHelper.php +++ /dev/null @@ -1,104 +0,0 @@ - - * @copyright 2018, Maxence Lange - * @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 . - * - */ - - -namespace OCP\Stratos\Helper; - - -use OCP\Stratos\Model\Helper\IStratosCallback; -use OCP\Stratos\Model\Helper\IStratosEvent; -use OCP\Stratos\Model\Helper\IStratosNotification; -use OCP\Stratos\Model\IStratosWrapper; - - -/** - * Interface IStratosHelper - * - * @since 18.0.0 - * - * @package OCP\Stratos\Helper - */ -interface IStratosHelper { - - - /** - * @param string $userId - * - * @return IStratosWrapper - */ - public function test(string $userId): IStratosWrapper; - - - /** - * @param IStratosCallback $callback - * - * @return IStratosWrapper - */ - public function toCallback(IStratosCallback $callback): IStratosWrapper; - - /** - * @param IStratosCallback $callback - * - * @return IStratosWrapper - */ - public function generateFromCallback(IStratosCallback $callback): IStratosWrapper; - - - - - /** - * @param IStratosNotification $notification - * - * @return IStratosWrapper - */ - public function pushNotification(IStratosNotification $notification): IStratosWrapper; - - /** - * @param IStratosNotification $notification - * - * @return IStratosWrapper - */ - public function generateFromNotification(IStratosNotification $notification): IStratosWrapper; - - - /** - * @param IStratosEvent $event - * - * @return IStratosWrapper - */ - public function broadcastEvent(IStratosEvent $event): IStratosWrapper; - - /** - * @param IStratosEvent $event - * - * @return IStratosWrapper - */ - public function generateFromEvent(IStratosEvent $event): IStratosWrapper; - -} From 82fa45a9516d26ce744488db4f5414e0d7eafbf1 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 5 Sep 2019 09:17:41 -0100 Subject: [PATCH 13/16] include 3rdparty Signed-off-by: Maxence Lange --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 49ccfbb28661b..b87afe46ba2aa 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 49ccfbb28661b9ef7743c1725cd2571259215929 +Subproject commit b87afe46ba2aafd64df7c61419bffac4065c165d From 286e7b995242585de3ad8152887d6eb3b68e1f35 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 6 Sep 2019 10:05:18 -0100 Subject: [PATCH 14/16] keywords Signed-off-by: Maxence Lange --- lib/composer/composer/autoload_classmap.php | 2 + lib/composer/composer/autoload_static.php | 2 + .../Push/Model/Helper/PushCallback.php | 48 +----- lib/private/Push/Model/Helper/PushEvent.php | 25 +-- .../Push/Model/Helper/PushNotification.php | 30 +--- lib/private/Push/Model/PushItem.php | 69 ++++++++ lib/private/Push/Model/PushRecipients.php | 156 ++++++++++++++++++ lib/private/Push/Model/PushWrapper.php | 2 +- .../Push/Exceptions/ItemNotFoundException.php | 44 +++++ .../Push/Exceptions/PushInstallException.php | 5 +- .../Exceptions/UnknownStreamTypeException.php | 45 +++++ .../Push/Model/Helper/IPushCallback.php | 26 --- lib/public/Push/Model/Helper/IPushEvent.php | 13 -- .../Push/Model/Helper/IPushNotification.php | 13 -- lib/public/Push/Model/IPushItem.php | 39 ++++- lib/public/Push/Model/IPushRecipients.php | 93 +++++++++++ lib/public/Push/Service/IPushService.php | 31 +++- 17 files changed, 489 insertions(+), 154 deletions(-) create mode 100644 lib/public/Push/Exceptions/ItemNotFoundException.php create mode 100644 lib/public/Push/Exceptions/UnknownStreamTypeException.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 18d0206554070..e9615acedd5e3 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -363,7 +363,9 @@ 'OCP\\Preview\\IProvider' => $baseDir . '/lib/public/Preview/IProvider.php', 'OCP\\Preview\\IProviderV2' => $baseDir . '/lib/public/Preview/IProviderV2.php', 'OCP\\Preview\\IVersionedPreviewFile' => $baseDir . '/lib/public/Preview/IVersionedPreviewFile.php', + 'OCP\\Push\\Exceptions\\ItemNotFoundException' => $baseDir . '/lib/public/Push/Exceptions/ItemNotFoundException.php', 'OCP\\Push\\Exceptions\\PushInstallException' => $baseDir . '/lib/public/Push/Exceptions/PushInstallException.php', + 'OCP\\Push\\Exceptions\\UnknownStreamTypeException' => $baseDir . '/lib/public/Push/Exceptions/UnknownStreamTypeException.php', 'OCP\\Push\\Helper\\IPushHelper' => $baseDir . '/lib/public/Push/Helper/IPushHelper.php', 'OCP\\Push\\IPushManager' => $baseDir . '/lib/public/Push/IPushManager.php', 'OCP\\Push\\Model\\Helper\\IPushCallback' => $baseDir . '/lib/public/Push/Model/Helper/IPushCallback.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index dda59b9c9641a..e08c7348530a6 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -397,7 +397,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Preview\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Preview/IProvider.php', 'OCP\\Preview\\IProviderV2' => __DIR__ . '/../../..' . '/lib/public/Preview/IProviderV2.php', 'OCP\\Preview\\IVersionedPreviewFile' => __DIR__ . '/../../..' . '/lib/public/Preview/IVersionedPreviewFile.php', + 'OCP\\Push\\Exceptions\\ItemNotFoundException' => __DIR__ . '/../../..' . '/lib/public/Push/Exceptions/ItemNotFoundException.php', 'OCP\\Push\\Exceptions\\PushInstallException' => __DIR__ . '/../../..' . '/lib/public/Push/Exceptions/PushInstallException.php', + 'OCP\\Push\\Exceptions\\UnknownStreamTypeException' => __DIR__ . '/../../..' . '/lib/public/Push/Exceptions/UnknownStreamTypeException.php', 'OCP\\Push\\Helper\\IPushHelper' => __DIR__ . '/../../..' . '/lib/public/Push/Helper/IPushHelper.php', 'OCP\\Push\\IPushManager' => __DIR__ . '/../../..' . '/lib/public/Push/IPushManager.php', 'OCP\\Push\\Model\\Helper\\IPushCallback' => __DIR__ . '/../../..' . '/lib/public/Push/Model/Helper/IPushCallback.php', diff --git a/lib/private/Push/Model/Helper/PushCallback.php b/lib/private/Push/Model/Helper/PushCallback.php index 081e3c5614417..05b7dac756715 100644 --- a/lib/private/Push/Model/Helper/PushCallback.php +++ b/lib/private/Push/Model/Helper/PushCallback.php @@ -48,12 +48,6 @@ class PushCallback extends PushRecipients implements IPushCallback, JsonSerializ use TArrayTools; - /** @var string */ - private $app = ''; - - /** @var string */ - private $source = ''; - /** @var array */ private $payload = ''; @@ -65,46 +59,8 @@ class PushCallback extends PushRecipients implements IPushCallback, JsonSerializ * @param $source */ public function __construct($app = '', $source = '') { - $this->app = $app; - $this->source = $source; - } - - - /** - * @return string - */ - public function getApp(): string { - return $this->app; - } - - /** - * @param string $app - * - * @return IPushCallback - */ - public function setApp(string $app): IPushCallback { - $this->app = $app; - - return $this; - } - - - /** - * @return string - */ - public function getSource(): string { - return $this->source; - } - - /** - * @param string $source - * - * @return IPushCallback - */ - public function setSource(string $source): IPushCallback { - $this->source = $source; - - return $this; + $this->setApp($app); + $this->setSource($source); } diff --git a/lib/private/Push/Model/Helper/PushEvent.php b/lib/private/Push/Model/Helper/PushEvent.php index e10c5dbce5123..05b78bd6092de 100644 --- a/lib/private/Push/Model/Helper/PushEvent.php +++ b/lib/private/Push/Model/Helper/PushEvent.php @@ -47,10 +47,6 @@ class PushEvent extends PushRecipients implements IPushEvent, JsonSerializable { use TArrayTools; - - /** @var string */ - private $app = ''; - /** @var string */ private $command = ''; @@ -65,30 +61,11 @@ class PushEvent extends PushRecipients implements IPushEvent, JsonSerializable { * @param string $command */ public function __construct($app = '', $command = '') { - $this->app = $app; + $this->setApp($app); $this->command = $command; } - /** - * @return string - */ - public function getApp(): string { - return $this->app; - } - - /** - * @param string $app - * - * @return IPushEvent - */ - public function setApp(string $app): IPushEvent { - $this->app = $app; - - return $this; - } - - /** * @return string */ diff --git a/lib/private/Push/Model/Helper/PushNotification.php b/lib/private/Push/Model/Helper/PushNotification.php index 9d5017fe4bc1e..b0b7cffefb964 100644 --- a/lib/private/Push/Model/Helper/PushNotification.php +++ b/lib/private/Push/Model/Helper/PushNotification.php @@ -49,12 +49,6 @@ class PushNotification extends PushRecipients implements IPushNotification, Json use TArrayTools; - /** @var string */ - private $app = ''; - - /** @var string */ - private $title = ''; - /** @var string */ private $message = ''; @@ -75,34 +69,16 @@ class PushNotification extends PushRecipients implements IPushNotification, Json * @param int $ttl */ public function __construct($app = '', $ttl = IPushItem::TTL_INSTANT) { - $this->app = $app; + $this->setApp($app); $this->ttl = $ttl; } - /** - * @return string - */ - public function getApp(): string { - return $this->app; - } - - /** - * @param string $app - * - * @return IPushNotification - */ - public function setApp(string $app): IPushNotification { - $this->app = $app; - - return $this; - } - /** * @return string */ public function getTitle(): string { - return $this->title; + return $this->getSource(); } /** @@ -111,7 +87,7 @@ public function getTitle(): string { * @return IPushNotification */ public function setTitle(string $title): IPushNotification { - $this->title = $title; + $this->setSource($title); return $this; } diff --git a/lib/private/Push/Model/PushItem.php b/lib/private/Push/Model/PushItem.php index ade1570bbfc32..755547c87ea34 100644 --- a/lib/private/Push/Model/PushItem.php +++ b/lib/private/Push/Model/PushItem.php @@ -48,6 +48,7 @@ class PushItem implements IPushItem, JsonSerializable { use TArrayTools; use TStringTools; + /** @var int */ private $id = 0; @@ -60,6 +61,9 @@ class PushItem implements IPushItem, JsonSerializable { /** @var string */ private $source = ''; + /** @var string */ + private $keyword = ''; + /** @var array */ private $payload = []; @@ -166,6 +170,25 @@ public function setSource(string $source): IPushItem { } + /** + * @return string + */ + public function getKeyword(): string { + return $this->keyword; + } + + /** + * @param string $keyword + * + * @return IPushItem + */ + public function setKeyword(string $keyword): IPushItem { + $this->keyword = $keyword; + + return $this; + } + + /** * @return array */ @@ -261,6 +284,30 @@ public function addMeta(string $k, string $v): IPushItem { return $this; } + /** + * @param string $k + * @param bool $v + * + * @return IPushItem + */ + public function addMetaBool(string $k, bool $v): IPushItem { + $this->meta[$k] = $v; + + return $this; + } + + /** + * @param string $k + * @param int $v + * + * @return IPushItem + */ + public function addMetaInt(string $k, int $v): IPushItem { + $this->meta[$k] = $v; + + return $this; + } + /** * @param string $k * @param array $v @@ -273,6 +320,25 @@ public function addMetaArray(string $k, array $v): IPushItem { return $this; } + /** + * @param string $k + * @param string $v + * + * @return IPushItem + */ + public function addMetaArrayEntry(string $k, string $v): IPushItem { + if (!array_key_exists($k, $this->meta)) { + $this->meta[$k] = []; + } + + if (!in_array($v, $this->meta[$k])) { + $this->meta[$k][] = $v; + } + + return $this; + } + + /** * @return array */ @@ -313,6 +379,7 @@ public function import(array $import): IPushItem { $this->setTtl($this->getInt('ttl', $import, -1)); $this->setPayload($this->getArray('payload', $import, [])); $this->setSource($this->get('source', $import)); + $this->setKeyword($this->get('keyword', $import)); $this->setMeta($this->getArray('meta', $import)); $this->setCreation($this->getInt('creation', $import)); @@ -325,10 +392,12 @@ public function import(array $import): IPushItem { */ public function jsonSerialize(): array { return [ + 'id' => $this->getId(), 'token' => $this->getToken(), 'app' => $this->getApp(), 'type' => $this->getType(), 'source' => $this->getSource(), + 'keyword' => $this->getKeyword(), 'payload' => $this->getPayload(), 'meta' => $this->getMeta(), 'ttl' => $this->getTtl(), diff --git a/lib/private/Push/Model/PushRecipients.php b/lib/private/Push/Model/PushRecipients.php index a156f08064a50..7993041b906ec 100644 --- a/lib/private/Push/Model/PushRecipients.php +++ b/lib/private/Push/Model/PushRecipients.php @@ -32,6 +32,7 @@ use JsonSerializable; +use OCA\Push\Model\Polling; use OCP\Push\Model\IPushRecipients; @@ -43,6 +44,18 @@ class PushRecipients implements IPushRecipients, JsonSerializable { + /** @var string */ + private $app = ''; + + /** @var string */ + private $source = ''; + + /** @var string */ + private $keyword = ''; + + /** @var array */ + private $meta = []; + /** @var array */ private $users = []; @@ -62,6 +75,148 @@ class PushRecipients implements IPushRecipients, JsonSerializable { private $limitToApps = []; + /** + * @return string + */ + public function getApp(): string { + return $this->app; + } + + /** + * @param string $app + * + * @return IPushRecipients + */ + public function setApp(string $app): IPushRecipients { + $this->app = $app; + + return $this; + } + + + /** + * @return string + */ + public function getSource(): string { + return $this->source; + } + + /** + * @param string $source + * + * @return IPushRecipients + */ + public function setSource(string $source): IPushRecipients { + $this->source = $source; + + return $this; + } + + + /** + * @return string + */ + public function getKeyword(): string { + return $this->keyword; + } + + /** + * @param string $keyword + * + * @return IPushRecipients + */ + public function setKeyword(string $keyword): IPushRecipients { + $this->keyword = $keyword; + + return $this; + } + + + /** + * @return array + */ + public function getMeta(): array { + return $this->meta; + } + + /** + * @param array $meta + * + * @return IPushRecipients + */ + public function setMeta(array $meta): IPushRecipients { + $this->meta = $meta; + + return $this; + } + + /** + * @param string $k + * @param string $v + * + * @return IPushRecipients + */ + public function addMeta(string $k, string $v): IPushRecipients { + $this->meta[$k] = $v; + + return $this; + } + + /** + * @param string $k + * @param int $v + * + * @return IPushRecipients + */ + public function addMetaInt(string $k, int $v): IPushRecipients { + $this->meta[$k] = $v; + + return $this; + } + + /** + * @param string $k + * @param array $v + * + * @return IPushRecipients + */ + public function addMetaArray(string $k, array $v): IPushRecipients { + $this->meta[$k] = $v; + + return $this; + } + + /** + * @param string $k + * @param string $v + * + * @return IPushRecipients + */ + public function addMetaArrayEntry(string $k, string $v): IPushRecipients { + if (!array_key_exists($k, $this->meta)) { + $this->meta[$k] = []; + } + + if (!in_array($v, $this->meta[$k])) { + $this->meta[$k][] = $v; + } + + return $this; + } + + /** + * @param string $k + * @param bool $v + * + * @return IPushRecipients + */ + public function addMetaBool(string $k, bool $v): IPushRecipients { + $this->meta[$k] = $v; + + return $this; + } + + /** * @param string $user * @@ -101,6 +256,7 @@ public function removeUser(string $user): IPushRecipients { public function removeUsers(array $users): IPushRecipients { $this->removedUsers = array_merge($this->removedUsers, $users); + return $this; } diff --git a/lib/private/Push/Model/PushWrapper.php b/lib/private/Push/Model/PushWrapper.php index c0e30021f1667..324e8113cd827 100644 --- a/lib/private/Push/Model/PushWrapper.php +++ b/lib/private/Push/Model/PushWrapper.php @@ -123,7 +123,7 @@ public function setRecipients(array $recipients): IPushWrapper { * @return IPushWrapper */ public function addRecipient(string $recipient): IPushWrapper { - if (!in_array($recipient, $this->recipients)) { + if (!in_array($recipient, $this->recipients) && $recipient !== '') { $this->recipients[] = $recipient; } diff --git a/lib/public/Push/Exceptions/ItemNotFoundException.php b/lib/public/Push/Exceptions/ItemNotFoundException.php new file mode 100644 index 0000000000000..9f728480e2914 --- /dev/null +++ b/lib/public/Push/Exceptions/ItemNotFoundException.php @@ -0,0 +1,44 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Push\Exceptions; + +use Exception; + +/** + * @since 18.0.0 + * + * Class PushInstallException + * + * @package OCP\Push\Exceptions + */ +class ItemNotFoundException extends Exception { +} + + diff --git a/lib/public/Push/Exceptions/PushInstallException.php b/lib/public/Push/Exceptions/PushInstallException.php index 541796c17e346..9def8243f9ff4 100644 --- a/lib/public/Push/Exceptions/PushInstallException.php +++ b/lib/public/Push/Exceptions/PushInstallException.php @@ -29,6 +29,9 @@ namespace OCP\Push\Exceptions; +use Exception; + + /** * @since 18.0.0 * @@ -36,6 +39,6 @@ * * @package OCP\Push\Exceptions */ -class PushInstallException extends \Exception { +class PushInstallException extends Exception { } diff --git a/lib/public/Push/Exceptions/UnknownStreamTypeException.php b/lib/public/Push/Exceptions/UnknownStreamTypeException.php new file mode 100644 index 0000000000000..21bfb03814d83 --- /dev/null +++ b/lib/public/Push/Exceptions/UnknownStreamTypeException.php @@ -0,0 +1,45 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCP\Push\Exceptions; + +use Exception; + + +/** + * @since 18.0.0 + * + * Class PushInstallException + * + * @package OCP\Push\Exceptions + */ +class UnknownStreamTypeException extends Exception { +} + + diff --git a/lib/public/Push/Model/Helper/IPushCallback.php b/lib/public/Push/Model/Helper/IPushCallback.php index ea2b81d1458ff..179f9010d9837 100644 --- a/lib/public/Push/Model/Helper/IPushCallback.php +++ b/lib/public/Push/Model/Helper/IPushCallback.php @@ -48,32 +48,6 @@ interface IPushCallback extends IPushRecipients { const TYPE = 'Callback'; - /** - * @return string - */ - public function getApp(): string; - - /** - * @param string $app - * - * @return self - */ - public function setApp(string $app): self; - - - /** - * @return string - */ - public function getSource(): string; - - /** - * @param string $source - * - * @return self - */ - public function setSource(string $source): self; - - /** * @return array */ diff --git a/lib/public/Push/Model/Helper/IPushEvent.php b/lib/public/Push/Model/Helper/IPushEvent.php index 921d576b1c505..6ff5c04ee9dbf 100644 --- a/lib/public/Push/Model/Helper/IPushEvent.php +++ b/lib/public/Push/Model/Helper/IPushEvent.php @@ -48,19 +48,6 @@ interface IPushEvent extends IPushRecipients { const TYPE = 'Event'; - /** - * @return string - */ - public function getApp(): string; - - /** - * @param string $app - * - * @return self - */ - public function setApp(string $app): self; - - /** * @return string */ diff --git a/lib/public/Push/Model/Helper/IPushNotification.php b/lib/public/Push/Model/Helper/IPushNotification.php index d05c88faab6d0..948d770f6f609 100644 --- a/lib/public/Push/Model/Helper/IPushNotification.php +++ b/lib/public/Push/Model/Helper/IPushNotification.php @@ -52,19 +52,6 @@ interface IPushNotification extends IPushRecipients { const LEVEL_ERROR = 'error'; - /** - * @return string - */ - public function getApp(): string; - - /** - * @param string $app - * - * @return self - */ - public function setApp(string $app): self; - - /** * @return string */ diff --git a/lib/public/Push/Model/IPushItem.php b/lib/public/Push/Model/IPushItem.php index 92d774aa33547..db470d154e367 100644 --- a/lib/public/Push/Model/IPushItem.php +++ b/lib/public/Push/Model/IPushItem.php @@ -101,6 +101,20 @@ public function getPayload(): array; */ public function setPayload(array $payload): self; + + /** + * @return string + */ + public function getKeyword(): string; + + /** + * @param string $keyword + * + * @return self + */ + public function setKeyword(string $keyword): self; + + /** * @param JsonSerializable $payload * @@ -150,6 +164,22 @@ public function setMeta(array $meta): self; */ public function addMeta(string $k, string $v): self; + /** + * @param string $k + * @param int $v + * + * @return IPushItem + */ + public function addMetaInt(string $k, int $v): self; + + /** + * @param string $k + * @param bool $v + * + * @return IPushItem + */ + public function addMetaBool(string $k, bool $v): self; + /** * @param string $k * @param array $v @@ -158,13 +188,20 @@ public function addMeta(string $k, string $v): self; */ public function addMetaArray(string $k, array $v): self; + /** + * @param string $k + * @param string $v + * + * @return IPushItem + */ + public function addMetaArrayEntry(string $k, string $v): self; + /** * @return array */ public function getMeta(): array; - /** * @param int $timestamp * diff --git a/lib/public/Push/Model/IPushRecipients.php b/lib/public/Push/Model/IPushRecipients.php index 1b0c74da62c79..af80fa4739aa2 100644 --- a/lib/public/Push/Model/IPushRecipients.php +++ b/lib/public/Push/Model/IPushRecipients.php @@ -40,6 +40,99 @@ */ interface IPushRecipients { + + /** + * @return string + */ + public function getApp(): string; + + /** + * @param string $app + * + * @return IPushRecipients + */ + public function setApp(string $app): self; + + + /** + * @return string + */ + public function getSource(): string; + + /** + * @param string $source + * + * @return IPushRecipients + */ + public function setSource(string $source): self; + + + /** + * @return string + */ + public function getKeyword(): string; + + /** + * @param string $keyword + * + * @return IPushRecipients + */ + public function setKeyword(string $keyword): self; + + + /** + * @return array + */ + public function getMeta(): array; + + /** + * @param array $meta + * + * @return IPushRecipients + */ + public function setMeta(array $meta): self; + + /** + * @param string $k + * @param string $v + * + * @return IPushRecipients + */ + public function addMeta(string $k, string $v): self; + + /** + * @param string $k + * @param int $v + * + * @return IPushRecipients + */ + public function addMetaInt(string $k, int $v): self; + + /** + * @param string $k + * @param array $v + * + * @return IPushRecipients + */ + public function addMetaArray(string $k, array $v): self; + + /** + * @param string $k + * @param string $v + * + * @return IPushRecipients + */ + public function addMetaArrayEntry(string $k, string $v): self; + + /** + * @param string $k + * @param bool $v + * + * @return IPushRecipients + */ + public function addMetaBool(string $k, bool $v): self; + + /** * @param string $user * diff --git a/lib/public/Push/Service/IPushService.php b/lib/public/Push/Service/IPushService.php index 01146986ccce5..00370f24eba6b 100644 --- a/lib/public/Push/Service/IPushService.php +++ b/lib/public/Push/Service/IPushService.php @@ -31,6 +31,9 @@ namespace OCP\Push\Service; +use OCP\Push\Exceptions\ItemNotFoundException; +use OCP\Push\Exceptions\UnknownStreamTypeException; +use OCP\Push\Model\IPushItem; use OCP\Push\Model\IPushRecipients; use OCP\Push\Model\IPushWrapper; @@ -45,7 +48,31 @@ interface IPushService { - public function push(IPushWrapper $wrapper); + /** + * erase if keyword is specified and already exist in db. + * + * @param IPushWrapper $wrapper + */ + public function push(IPushWrapper $wrapper): void; + + /** + * update only if the item still exists. + * + * @param IPushItem $item + */ + public function update(IPushItem $item): void; + + + /** + * @param string $app + * @param string $userId + * @param string $keyword + * + * @return IPushItem + * @throws ItemNotFoundException + * @throws UnknownStreamTypeException + */ + public function getItemByKeyword(string $app, string $userId, string $keyword): IPushItem; /** @@ -54,7 +81,7 @@ public function push(IPushWrapper $wrapper); * * @return mixed */ - public function fillRecipients(IPushWrapper $wrapper, IPushRecipients $recipients); + public function fillRecipients(IPushWrapper $wrapper, IPushRecipients $recipients): void; } From 66beaf9a4e85daa2bfc8dcdc95fad62ad83265f7 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 6 Sep 2019 12:05:18 -0100 Subject: [PATCH 15/16] comments Signed-off-by: Maxence Lange --- .../Push/Model/Helper/PushCallback.php | 10 ++ lib/private/Push/Model/Helper/PushEvent.php | 14 ++ .../Push/Model/Helper/PushNotification.php | 24 +++ lib/private/Push/Model/PushItem.php | 58 ++++++++ lib/private/Push/Model/PushRecipients.php | 65 ++++++++- lib/private/Push/Model/PushWrapper.php | 20 +++ lib/private/Push/PushManager.php | 15 +- .../Push/Exceptions/ItemNotFoundException.php | 2 +- .../Push/Exceptions/PushInstallException.php | 2 +- .../Exceptions/UnknownStreamTypeException.php | 2 +- lib/public/Push/Helper/IPushHelper.php | 40 ++++- lib/public/Push/IPushManager.php | 29 +++- .../Push/Model/Helper/IPushCallback.php | 16 +- lib/public/Push/Model/Helper/IPushEvent.php | 24 ++- .../Push/Model/Helper/IPushNotification.php | 48 +++++- lib/public/Push/Model/IPushItem.php | 121 +++++++++++++++- lib/public/Push/Model/IPushRecipients.php | 137 +++++++++++++++++- lib/public/Push/Model/IPushWrapper.php | 48 +++++- lib/public/Push/Service/IPushService.php | 24 ++- 19 files changed, 663 insertions(+), 36 deletions(-) diff --git a/lib/private/Push/Model/Helper/PushCallback.php b/lib/private/Push/Model/Helper/PushCallback.php index 05b7dac756715..a5ab49c27ac8d 100644 --- a/lib/private/Push/Model/Helper/PushCallback.php +++ b/lib/private/Push/Model/Helper/PushCallback.php @@ -40,6 +40,8 @@ /** * Class PushCallback * + * @since 18.0.0 + * * @package OC\Push\Model\Helper */ class PushCallback extends PushRecipients implements IPushCallback, JsonSerializable { @@ -57,6 +59,8 @@ class PushCallback extends PushRecipients implements IPushCallback, JsonSerializ * * @param string $app * @param $source + * + * @since 18.0.0 */ public function __construct($app = '', $source = '') { $this->setApp($app); @@ -66,6 +70,8 @@ public function __construct($app = '', $source = '') { /** * @return array + * + * @since 18.0.0 */ public function getPayload(): array { if ($this->payload instanceof JsonSerializable) { @@ -79,6 +85,8 @@ public function getPayload(): array { * @param array $payload * * @return IPushCallback + * + * @since 18.0.0 */ public function setPayload(array $payload): IPushCallback { $this->payload = $payload; @@ -90,6 +98,8 @@ public function setPayload(array $payload): IPushCallback { * @param JsonSerializable $payload * * @return self + * + * @since 18.0.0 */ public function setPayloadSerializable(JsonSerializable $payload): IPushCallback { $this->payload = $payload; diff --git a/lib/private/Push/Model/Helper/PushEvent.php b/lib/private/Push/Model/Helper/PushEvent.php index 05b78bd6092de..6ff0b31f8bc2e 100644 --- a/lib/private/Push/Model/Helper/PushEvent.php +++ b/lib/private/Push/Model/Helper/PushEvent.php @@ -40,6 +40,8 @@ /** * Class PushEvent * + * @since 18.0.0 + * * @package OC\Push\Model\Helper */ class PushEvent extends PushRecipients implements IPushEvent, JsonSerializable { @@ -59,6 +61,8 @@ class PushEvent extends PushRecipients implements IPushEvent, JsonSerializable { * * @param string $app * @param string $command + * + * @since 18.0.0 */ public function __construct($app = '', $command = '') { $this->setApp($app); @@ -68,6 +72,8 @@ public function __construct($app = '', $command = '') { /** * @return string + * + * @since 18.0.0 */ public function getCommand(): string { return $this->command; @@ -77,6 +83,8 @@ public function getCommand(): string { * @param string $command * * @return IPushEvent + * + * @since 18.0.0 */ public function setCommand(string $command): IPushEvent { $this->command = $command; @@ -87,6 +95,8 @@ public function setCommand(string $command): IPushEvent { /** * @return array + * + * @since 18.0.0 */ public function getPayload(): array { if ($this->payload instanceof JsonSerializable) { @@ -100,6 +110,8 @@ public function getPayload(): array { * @param array $payload * * @return IPushEvent + * + * @since 18.0.0 */ public function setPayload(array $payload): IPushEvent { $this->payload = $payload; @@ -111,6 +123,8 @@ public function setPayload(array $payload): IPushEvent { * @param JsonSerializable $payload * * @return IPushEvent + * + * @since 18.0.0 */ public function setPayloadSerializable(JsonSerializable $payload): IPushEvent { $this->payload = $payload->jsonSerialize(); diff --git a/lib/private/Push/Model/Helper/PushNotification.php b/lib/private/Push/Model/Helper/PushNotification.php index b0b7cffefb964..c6385387d9c2d 100644 --- a/lib/private/Push/Model/Helper/PushNotification.php +++ b/lib/private/Push/Model/Helper/PushNotification.php @@ -41,6 +41,8 @@ /** * Class PushNotification * + * @since 18.0.0 + * * @package OC\Push\Model\Helper */ class PushNotification extends PushRecipients implements IPushNotification, JsonSerializable { @@ -67,6 +69,8 @@ class PushNotification extends PushRecipients implements IPushNotification, Json * * @param string $app * @param int $ttl + * + * @since 18.0.0 */ public function __construct($app = '', $ttl = IPushItem::TTL_INSTANT) { $this->setApp($app); @@ -76,6 +80,8 @@ public function __construct($app = '', $ttl = IPushItem::TTL_INSTANT) { /** * @return string + * + * @since 18.0.0 */ public function getTitle(): string { return $this->getSource(); @@ -85,6 +91,8 @@ public function getTitle(): string { * @param string $title * * @return IPushNotification + * + * @since 18.0.0 */ public function setTitle(string $title): IPushNotification { $this->setSource($title); @@ -95,6 +103,8 @@ public function setTitle(string $title): IPushNotification { /** * @return string + * + * @since 18.0.0 */ public function getMessage(): string { return $this->message; @@ -104,6 +114,8 @@ public function getMessage(): string { * @param string $message * * @return IPushNotification + * + * @since 18.0.0 */ public function setMessage(string $message): IPushNotification { $this->message = $message; @@ -114,6 +126,8 @@ public function setMessage(string $message): IPushNotification { /** * @return string + * + * @since 18.0.0 */ public function getLevel(): string { return $this->level; @@ -123,6 +137,8 @@ public function getLevel(): string { * @param string $level * * @return IPushNotification + * + * @since 18.0.0 */ public function setLevel(string $level): IPushNotification { $this->level = $level; @@ -133,6 +149,8 @@ public function setLevel(string $level): IPushNotification { /** * @return string + * + * @since 18.0.0 */ public function getLink(): string { return $this->link; @@ -142,6 +160,8 @@ public function getLink(): string { * @param string $link * * @return IPushNotification + * + * @since 18.0.0 */ public function setLink(string $link): IPushNotification { $this->link = $link; @@ -152,6 +172,8 @@ public function setLink(string $link): IPushNotification { /** * @return int + * + * @since 18.0.0 */ public function getTtl(): int { return $this->ttl; @@ -161,6 +183,8 @@ public function getTtl(): int { * @param int $ttl * * @return IPushNotification + * + * @since 18.0.0 */ public function setTtl(int $ttl): IPushNotification { $this->ttl = $ttl; diff --git a/lib/private/Push/Model/PushItem.php b/lib/private/Push/Model/PushItem.php index 755547c87ea34..260f83e0e873a 100644 --- a/lib/private/Push/Model/PushItem.php +++ b/lib/private/Push/Model/PushItem.php @@ -40,6 +40,8 @@ /** * Class PushItem * + * @since 18.0.0 + * * @package OC\Push\Model */ class PushItem implements IPushItem, JsonSerializable { @@ -85,6 +87,8 @@ class PushItem implements IPushItem, JsonSerializable { * * @param string $app * @param string $type + * + * @since 18.0.0 */ public function __construct($app = '', $type = '') { $this->app = $app; @@ -98,6 +102,8 @@ public function __construct($app = '', $type = '') { * @param int $id * * @return PushItem + * + * @since 18.0.0 */ public function setId(int $id): IPushItem { $this->id = $id; @@ -107,6 +113,8 @@ public function setId(int $id): IPushItem { /** * @return int + * + * @since 18.0.0 */ public function getId(): int { return $this->id; @@ -115,6 +123,8 @@ public function getId(): int { /** * @return string + * + * @since 18.0.0 */ public function getToken(): string { return $this->token; @@ -124,6 +134,8 @@ public function getToken(): string { * @param string $token * * @return PushItem + * + * @since 18.0.0 */ public function setToken(string $token): IPushItem { $this->token = $token; @@ -134,6 +146,8 @@ public function setToken(string $token): IPushItem { /** * @return string + * + * @since 18.0.0 */ public function getApp(): string { return $this->app; @@ -143,6 +157,8 @@ public function getApp(): string { * @param string $app * * @return IPushItem + * + * @since 18.0.0 */ public function setApp(string $app): IPushItem { $this->app = $app; @@ -153,6 +169,8 @@ public function setApp(string $app): IPushItem { /** * @return string + * + * @since 18.0.0 */ public function getSource(): string { return $this->source; @@ -162,6 +180,8 @@ public function getSource(): string { * @param string $source * * @return IPushItem + * + * @since 18.0.0 */ public function setSource(string $source): IPushItem { $this->source = $source; @@ -172,6 +192,8 @@ public function setSource(string $source): IPushItem { /** * @return string + * + * @since 18.0.0 */ public function getKeyword(): string { return $this->keyword; @@ -181,6 +203,8 @@ public function getKeyword(): string { * @param string $keyword * * @return IPushItem + * + * @since 18.0.0 */ public function setKeyword(string $keyword): IPushItem { $this->keyword = $keyword; @@ -191,6 +215,8 @@ public function setKeyword(string $keyword): IPushItem { /** * @return array + * + * @since 18.0.0 */ public function getPayload(): array { if ($this->payload instanceof JsonSerializable) { @@ -204,6 +230,8 @@ public function getPayload(): array { * @param array $payload * * @return IPushItem + * + * @since 18.0.0 */ public function setPayload(array $payload): IPushItem { $this->payload = $payload; @@ -215,6 +243,8 @@ public function setPayload(array $payload): IPushItem { * @param JsonSerializable $payload * * @return IPushItem + * + * @since 18.0.0 */ public function setPayloadSerializable(JsonSerializable $payload): IPushItem { $this->payload = $payload; @@ -225,6 +255,8 @@ public function setPayloadSerializable(JsonSerializable $payload): IPushItem { /** * @return string + * + * @since 18.0.0 */ public function getType(): string { return $this->type; @@ -234,6 +266,8 @@ public function getType(): string { * @param string $type * * @return PushItem + * + * @since 18.0.0 */ public function setType(string $type): IPushItem { $this->type = $type; @@ -244,6 +278,8 @@ public function setType(string $type): IPushItem { /** * @return int + * + * @since 18.0.0 */ public function getTtl(): int { return $this->ttl; @@ -253,6 +289,8 @@ public function getTtl(): int { * @param int $ttl * * @return PushItem + * + * @since 18.0.0 */ public function setTtl(int $ttl): IPushItem { $this->ttl = $ttl; @@ -265,6 +303,8 @@ public function setTtl(int $ttl): IPushItem { * @param array $meta * * @return IPushItem + * + * @since 18.0.0 */ public function setMeta(array $meta): IPushItem { $this->meta = $meta; @@ -277,6 +317,8 @@ public function setMeta(array $meta): IPushItem { * @param string $v * * @return IPushItem + * + * @since 18.0.0 */ public function addMeta(string $k, string $v): IPushItem { $this->meta[$k] = $v; @@ -289,6 +331,8 @@ public function addMeta(string $k, string $v): IPushItem { * @param bool $v * * @return IPushItem + * + * @since 18.0.0 */ public function addMetaBool(string $k, bool $v): IPushItem { $this->meta[$k] = $v; @@ -301,6 +345,8 @@ public function addMetaBool(string $k, bool $v): IPushItem { * @param int $v * * @return IPushItem + * + * @since 18.0.0 */ public function addMetaInt(string $k, int $v): IPushItem { $this->meta[$k] = $v; @@ -313,6 +359,8 @@ public function addMetaInt(string $k, int $v): IPushItem { * @param array $v * * @return IPushItem + * + * @since 18.0.0 */ public function addMetaArray(string $k, array $v): IPushItem { $this->meta[$k] = $v; @@ -325,6 +373,8 @@ public function addMetaArray(string $k, array $v): IPushItem { * @param string $v * * @return IPushItem + * + * @since 18.0.0 */ public function addMetaArrayEntry(string $k, string $v): IPushItem { if (!array_key_exists($k, $this->meta)) { @@ -341,6 +391,8 @@ public function addMetaArrayEntry(string $k, string $v): IPushItem { /** * @return array + * + * @since 18.0.0 */ public function getMeta(): array { return $this->meta; @@ -349,6 +401,8 @@ public function getMeta(): array { /** * @return int + * + * @since 18.0.0 */ public function getCreation(): int { return $this->creation; @@ -358,6 +412,8 @@ public function getCreation(): int { * @param int $creation * * @return PushItem + * + * @since 18.0.0 */ public function setCreation(int $creation): IPushItem { $this->creation = $creation; @@ -370,6 +426,8 @@ public function setCreation(int $creation): IPushItem { * @param array $import * * @return IPushItem + * + * @since 18.0.0 */ public function import(array $import): IPushItem { $this->setId($this->getInt('id', $import, 0)); diff --git a/lib/private/Push/Model/PushRecipients.php b/lib/private/Push/Model/PushRecipients.php index 7993041b906ec..54812adbdeadf 100644 --- a/lib/private/Push/Model/PushRecipients.php +++ b/lib/private/Push/Model/PushRecipients.php @@ -32,13 +32,14 @@ use JsonSerializable; -use OCA\Push\Model\Polling; use OCP\Push\Model\IPushRecipients; /** * Class PushRecipients * + * @since 18.0.0 + * * @package OC\Push\Model\Helper */ class PushRecipients implements IPushRecipients, JsonSerializable { @@ -77,6 +78,8 @@ class PushRecipients implements IPushRecipients, JsonSerializable { /** * @return string + * + * @since 18.0.0 */ public function getApp(): string { return $this->app; @@ -86,6 +89,8 @@ public function getApp(): string { * @param string $app * * @return IPushRecipients + * + * @since 18.0.0 */ public function setApp(string $app): IPushRecipients { $this->app = $app; @@ -96,6 +101,8 @@ public function setApp(string $app): IPushRecipients { /** * @return string + * + * @since 18.0.0 */ public function getSource(): string { return $this->source; @@ -105,6 +112,8 @@ public function getSource(): string { * @param string $source * * @return IPushRecipients + * + * @since 18.0.0 */ public function setSource(string $source): IPushRecipients { $this->source = $source; @@ -115,6 +124,8 @@ public function setSource(string $source): IPushRecipients { /** * @return string + * + * @since 18.0.0 */ public function getKeyword(): string { return $this->keyword; @@ -124,6 +135,8 @@ public function getKeyword(): string { * @param string $keyword * * @return IPushRecipients + * + * @since 18.0.0 */ public function setKeyword(string $keyword): IPushRecipients { $this->keyword = $keyword; @@ -134,6 +147,8 @@ public function setKeyword(string $keyword): IPushRecipients { /** * @return array + * + * @since 18.0.0 */ public function getMeta(): array { return $this->meta; @@ -143,6 +158,8 @@ public function getMeta(): array { * @param array $meta * * @return IPushRecipients + * + * @since 18.0.0 */ public function setMeta(array $meta): IPushRecipients { $this->meta = $meta; @@ -155,6 +172,8 @@ public function setMeta(array $meta): IPushRecipients { * @param string $v * * @return IPushRecipients + * + * @since 18.0.0 */ public function addMeta(string $k, string $v): IPushRecipients { $this->meta[$k] = $v; @@ -167,6 +186,8 @@ public function addMeta(string $k, string $v): IPushRecipients { * @param int $v * * @return IPushRecipients + * + * @since 18.0.0 */ public function addMetaInt(string $k, int $v): IPushRecipients { $this->meta[$k] = $v; @@ -179,6 +200,8 @@ public function addMetaInt(string $k, int $v): IPushRecipients { * @param array $v * * @return IPushRecipients + * + * @since 18.0.0 */ public function addMetaArray(string $k, array $v): IPushRecipients { $this->meta[$k] = $v; @@ -191,6 +214,8 @@ public function addMetaArray(string $k, array $v): IPushRecipients { * @param string $v * * @return IPushRecipients + * + * @since 18.0.0 */ public function addMetaArrayEntry(string $k, string $v): IPushRecipients { if (!array_key_exists($k, $this->meta)) { @@ -209,6 +234,8 @@ public function addMetaArrayEntry(string $k, string $v): IPushRecipients { * @param bool $v * * @return IPushRecipients + * + * @since 18.0.0 */ public function addMetaBool(string $k, bool $v): IPushRecipients { $this->meta[$k] = $v; @@ -221,6 +248,8 @@ public function addMetaBool(string $k, bool $v): IPushRecipients { * @param string $user * * @return IPushRecipients + * + * @since 18.0.0 */ public function addUser(string $user): IPushRecipients { array_push($this->users, $user); @@ -232,6 +261,8 @@ public function addUser(string $user): IPushRecipients { * @param string[] $users * * @return IPushRecipients + * + * @since 18.0.0 */ public function addUsers(array $users): IPushRecipients { $this->users = array_merge($this->users, $users); @@ -243,6 +274,8 @@ public function addUsers(array $users): IPushRecipients { * @param string $user * * @return IPushRecipients + * + * @since 18.0.0 */ public function removeUser(string $user): IPushRecipients { return $this->removeUsers([$user]); @@ -252,6 +285,8 @@ public function removeUser(string $user): IPushRecipients { * @param string[] $users * * @return IPushRecipients + * + * @since 18.0.0 */ public function removeUsers(array $users): IPushRecipients { $this->removedUsers = array_merge($this->removedUsers, $users); @@ -265,6 +300,8 @@ public function removeUsers(array $users): IPushRecipients { * @param string $group * * @return IPushRecipients + * + * @since 18.0.0 */ public function addGroup(string $group): IPushRecipients { array_push($this->groups, $group); @@ -276,6 +313,8 @@ public function addGroup(string $group): IPushRecipients { * @param string[] $groups * * @return IPushRecipients + * + * @since 18.0.0 */ public function addGroups(array $groups): IPushRecipients { $this->groups = array_merge($this->groups, $groups); @@ -287,6 +326,8 @@ public function addGroups(array $groups): IPushRecipients { * @param string $group * * @return IPushRecipients + * + * @since 18.0.0 */ public function removeGroup(string $group): IPushRecipients { return $this->removeGroups([$group]); @@ -296,6 +337,8 @@ public function removeGroup(string $group): IPushRecipients { * @param string[] $groups * * @return IPushRecipients + * + * @since 18.0.0 */ public function removeGroups(array $groups): IPushRecipients { $this->removedGroups = array_merge($this->removedGroups, $groups); @@ -306,6 +349,8 @@ public function removeGroups(array $groups): IPushRecipients { /** * @return string[] + * + * @since 18.0.0 */ public function getUsers(): array { return $this->users; @@ -313,6 +358,8 @@ public function getUsers(): array { /** * @return string[] + * + * @since 18.0.0 */ public function getGroups(): array { return $this->groups; @@ -321,6 +368,8 @@ public function getGroups(): array { /** * @return string[] + * + * @since 18.0.0 */ public function getRemovedUsers(): array { return $this->removedUsers; @@ -328,6 +377,8 @@ public function getRemovedUsers(): array { /** * @return string[] + * + * @since 18.0.0 */ public function getRemovedGroups(): array { return $this->removedGroups; @@ -338,6 +389,8 @@ public function getRemovedGroups(): array { * @param string $app * * @return IPushRecipients + * + * @since 18.0.0 */ public function filterApp(string $app): IPushRecipients { return $this->filterApps([$app]); @@ -347,6 +400,8 @@ public function filterApp(string $app): IPushRecipients { * @param string[] $apps * * @return IPushRecipients + * + * @since 18.0.0 */ public function filterApps(array $apps): IPushRecipients { $this->filteredApps = array_merge($this->filteredApps, $apps); @@ -356,6 +411,8 @@ public function filterApps(array $apps): IPushRecipients { /** * @return string[] + * + * @since 18.0.0 */ public function getFilteredApps(): array { return $this->filteredApps; @@ -366,6 +423,8 @@ public function getFilteredApps(): array { * @param string $app * * @return IPushRecipients + * + * @since 18.0.0 */ public function limitToApp(string $app): IPushRecipients { return $this->limitToApps([$app]); @@ -375,6 +434,8 @@ public function limitToApp(string $app): IPushRecipients { * @param string[] $apps * * @return IPushRecipients + * + * @since 18.0.0 */ public function limitToApps(array $apps): IPushRecipients { $this->limitToApps = array_merge($this->limitToApps, $apps); @@ -384,6 +445,8 @@ public function limitToApps(array $apps): IPushRecipients { /** * @return string[] + * + * @since 18.0.0 */ public function getLimitedToApps(): array { return $this->limitToApps; diff --git a/lib/private/Push/Model/PushWrapper.php b/lib/private/Push/Model/PushWrapper.php index 324e8113cd827..e030afbee026f 100644 --- a/lib/private/Push/Model/PushWrapper.php +++ b/lib/private/Push/Model/PushWrapper.php @@ -40,6 +40,8 @@ /** * Class PushManager * + * @since 18.0.0 + * * @package OC\Push\Model */ class PushWrapper implements IPushWrapper, JsonSerializable { @@ -62,6 +64,8 @@ class PushWrapper implements IPushWrapper, JsonSerializable { * PushWrapper constructor. * * @param IPushItem $item + * + * @since 18.0.0 */ public function __construct($item = null) { if ($item !== null && $item instanceof IPushItem) { @@ -74,6 +78,8 @@ public function __construct($item = null) { /** * @return bool + * + * @since 18.0.0 */ public function hasItem(): bool { return ($this->item !== null); @@ -81,6 +87,8 @@ public function hasItem(): bool { /** * @return IPushItem + * + * @since 18.0.0 */ public function getItem(): IPushItem { return $this->item; @@ -90,6 +98,8 @@ public function getItem(): IPushItem { * @param IPushItem $item * * @return IPushWrapper + * + * @since 18.0.0 */ public function setItem(IPushItem $item): IPushWrapper { $this->item = $item; @@ -100,6 +110,8 @@ public function setItem(IPushItem $item): IPushWrapper { /** * @return string[] + * + * @since 18.0.0 */ public function getRecipients(): array { return $this->recipients; @@ -109,6 +121,8 @@ public function getRecipients(): array { * @param array $recipients * * @return IPushWrapper + * + * @since 18.0.0 */ public function setRecipients(array $recipients): IPushWrapper { $this->recipients = []; @@ -121,6 +135,8 @@ public function setRecipients(array $recipients): IPushWrapper { * @param string $recipient * * @return IPushWrapper + * + * @since 18.0.0 */ public function addRecipient(string $recipient): IPushWrapper { if (!in_array($recipient, $this->recipients) && $recipient !== '') { @@ -134,6 +150,8 @@ public function addRecipient(string $recipient): IPushWrapper { * @param array $recipients * * @return IPushWrapper + * + * @since 18.0.0 */ public function addRecipients(array $recipients): IPushWrapper { foreach ($recipients as $recipient) { @@ -148,6 +166,8 @@ public function addRecipients(array $recipients): IPushWrapper { * @param array $import * * @return self + * + * @since 18.0.0 */ public function import(array $import): IPushWrapper { $item = new PushItem(); diff --git a/lib/private/Push/PushManager.php b/lib/private/Push/PushManager.php index 0608dfa3d6d64..574a618ac781a 100644 --- a/lib/private/Push/PushManager.php +++ b/lib/private/Push/PushManager.php @@ -40,6 +40,8 @@ /** * Class PushManager * + * @since 18.0.0 + * * @package OC\Push */ class PushManager implements IPushManager { @@ -58,8 +60,7 @@ class PushManager implements IPushManager { * * @since 18.0.0 */ - public function registerPushApp(IPushService $pushService, IPushHelper $pushHelper - ) { + public function registerPushApp(IPushService $pushService, IPushHelper $pushHelper): void { $this->pushService = $pushService; $this->pushHelper = $pushHelper; } @@ -67,6 +68,8 @@ public function registerPushApp(IPushService $pushService, IPushHelper $pushHelp /** * @return bool + * + * @since 18.0.0 */ public function isAvailable(): bool { try { @@ -83,6 +86,8 @@ public function isAvailable(): bool { /** * @return IPushService * @throws PushInstallException + * + * @since 18.0.0 */ public function getPushService(): IPushService { $this->checkRegistration(); @@ -94,6 +99,8 @@ public function getPushService(): IPushService { /** * @return IPushHelper * @throws PushInstallException + * + * @since 18.0.0 */ public function getPushHelper(): IPushHelper { $this->checkRegistration(); @@ -103,7 +110,11 @@ public function getPushHelper(): IPushHelper { /** + * check if an IPushService and IPushHelper have been registered + * * @throws PushInstallException + * + * @since 18.0.0 */ private function checkRegistration() { if ($this->pushService === null || $this->pushHelper === null) { diff --git a/lib/public/Push/Exceptions/ItemNotFoundException.php b/lib/public/Push/Exceptions/ItemNotFoundException.php index 9f728480e2914..9e8b81463e0f8 100644 --- a/lib/public/Push/Exceptions/ItemNotFoundException.php +++ b/lib/public/Push/Exceptions/ItemNotFoundException.php @@ -8,7 +8,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2018, Maxence Lange + * @copyright 2020, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify diff --git a/lib/public/Push/Exceptions/PushInstallException.php b/lib/public/Push/Exceptions/PushInstallException.php index 9def8243f9ff4..4f68dc6c8411c 100644 --- a/lib/public/Push/Exceptions/PushInstallException.php +++ b/lib/public/Push/Exceptions/PushInstallException.php @@ -8,7 +8,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2018, Maxence Lange + * @copyright 2020, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify diff --git a/lib/public/Push/Exceptions/UnknownStreamTypeException.php b/lib/public/Push/Exceptions/UnknownStreamTypeException.php index 21bfb03814d83..dbc798536d04b 100644 --- a/lib/public/Push/Exceptions/UnknownStreamTypeException.php +++ b/lib/public/Push/Exceptions/UnknownStreamTypeException.php @@ -8,7 +8,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2018, Maxence Lange + * @copyright 2020, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify diff --git a/lib/public/Push/Helper/IPushHelper.php b/lib/public/Push/Helper/IPushHelper.php index 0840de2df97d4..919d8759f1856 100644 --- a/lib/public/Push/Helper/IPushHelper.php +++ b/lib/public/Push/Helper/IPushHelper.php @@ -9,7 +9,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2018, Maxence Lange + * @copyright 2020, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -40,6 +40,13 @@ /** * Interface IPushHelper * + * this Interface is used to quickly generate and save items, based on basic templates: + * - IPushNotification + * - IPushEvent + * - IPushCallback + * + * A PushHelper is registered by the Push App (when installed) + * * @since 18.0.0 * * @package OCP\Push\Helper @@ -48,57 +55,84 @@ interface IPushHelper { /** + * test the Push App integration, sending a test notification to $userId + * * @param string $userId * * @return IPushWrapper + * + * @since 18.0.0 */ public function test(string $userId): IPushWrapper; /** + * Using an IPushCallback, generates a IPushWrapper and save it in database. + * * @param IPushCallback $callback * * @return IPushWrapper + * + * @since 18.0.0 */ public function toCallback(IPushCallback $callback): IPushWrapper; /** + * Generates a IPushWrapper from an IPushCallback + * * @param IPushCallback $callback * * @return IPushWrapper + * + * @since 18.0.0 */ public function generateFromCallback(IPushCallback $callback): IPushWrapper; - - /** + * Using an IPushNotification, generates a IPushWrapper and save it in database. + * * @param IPushNotification $notification * * @return IPushWrapper + * + * @since 18.0.0 */ public function pushNotification(IPushNotification $notification): IPushWrapper; /** + * Generates a IPushWrapper from an IPushNotification + * * @param IPushNotification $notification * * @return IPushWrapper + * + * @since 18.0.0 */ public function generateFromNotification(IPushNotification $notification): IPushWrapper; /** + * Using an IPushEvent, generates a IPushWrapper and save it in database. + * * @param IPushEvent $event * * @return IPushWrapper + * + * @since 18.0.0 */ public function broadcastEvent(IPushEvent $event): IPushWrapper; /** + * Generates a IPushWrapper from an IPushEvent + * * @param IPushEvent $event * * @return IPushWrapper + * + * @since 18.0.0 */ public function generateFromEvent(IPushEvent $event): IPushWrapper; } + diff --git a/lib/public/Push/IPushManager.php b/lib/public/Push/IPushManager.php index 1e4d5784f6ff7..8a48e74b2a773 100644 --- a/lib/public/Push/IPushManager.php +++ b/lib/public/Push/IPushManager.php @@ -9,7 +9,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2018, Maxence Lange + * @copyright 2020, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -39,6 +39,15 @@ /** * Interface IPushManager * + * IPushManager is a service available in Core that can be integrated within any app: + * + * use OCP\Push\IPushManager; + * public function __construct(IPushManager $pushManager) { + * $this->pushManager = $pushManager; + * } + * + * Once defined, it will be used to obtains more services from the Push App, if the App is available. + * * @since 18.0.0 * * @package OCP\Push @@ -47,32 +56,46 @@ interface IPushManager { /** - * Register a IPushService. + * Register a IPushService and IPushHelper. + * This is used by the Push App itself. * * @param IPushService $pushService * @param IPushHelper $pushHelper * * @since 18.0.0 + * */ - public function registerPushApp(IPushService $pushService, IPushHelper $pushHelper); + public function registerPushApp(IPushService $pushService, IPushHelper $pushHelper): void; /** + * returns if the Push App is available or not. + * * @return bool + * + * @since 18.0.0 */ public function isAvailable(): bool; /** + * returns the registered IPushService + * * @return IPushService * @throws PushInstallException + * + * @since 18.0.0 */ public function getPushService(): IPushService; /** + * returns the registered IPushHelper + * * @return IPushHelper * @throws PushInstallException + * @since 18.0.0 + * */ public function getPushHelper(): IPushHelper; diff --git a/lib/public/Push/Model/Helper/IPushCallback.php b/lib/public/Push/Model/Helper/IPushCallback.php index 179f9010d9837..eaaa96caf0b94 100644 --- a/lib/public/Push/Model/Helper/IPushCallback.php +++ b/lib/public/Push/Model/Helper/IPushCallback.php @@ -9,7 +9,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2018, Maxence Lange + * @copyright 2020, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -38,6 +38,8 @@ /** * Interface IPushCallback * + * Template used to generate an IPushItem with type=Callback + * * @since 18.0.0 * * @package OCP\Push\Helper @@ -49,21 +51,33 @@ interface IPushCallback extends IPushRecipients { /** + * get the payload + * * @return array + * + * @since 18.0.0 */ public function getPayload(): array; /** + * set the payload + * * @param array $payload * * @return self + * + * @since 18.0.0 */ public function setPayload(array $payload): self; /** + * set a serializable object as the payload + * * @param JsonSerializable $payload * * @return self + * + * @since 18.0.0 */ public function setPayloadSerializable(JsonSerializable $payload): self; diff --git a/lib/public/Push/Model/Helper/IPushEvent.php b/lib/public/Push/Model/Helper/IPushEvent.php index 6ff5c04ee9dbf..093acb503ce42 100644 --- a/lib/public/Push/Model/Helper/IPushEvent.php +++ b/lib/public/Push/Model/Helper/IPushEvent.php @@ -9,7 +9,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2018, Maxence Lange + * @copyright 2020, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -38,6 +38,8 @@ /** * Interface IPushEvent * + * Template used to generate an IPushItem with type=Event + * * @since 18.0.0 * * @package OCP\Push\Helper @@ -49,34 +51,54 @@ interface IPushEvent extends IPushRecipients { /** + * get the Javascript method that will be called on the front-end + * * @return string + * + * @since 18.0.0 */ public function getCommand(): string; /** + * set the Javascript method that will be called on the front-end + * * @param string $title * * @return self + * + * @since 18.0.0 */ public function setCommand(string $title): self; /** + * get the payload + * * @return array + * + * @since 18.0.0 */ public function getPayload(): array; /** + * set the payload + * * @param array $payload * * @return self + * + * @since 18.0.0 */ public function setPayload(array $payload): self; /** + * set a serializable object as the payload + * * @param JsonSerializable $payload * * @return self + * + * @since 18.0.0 */ public function setPayloadSerializable(JsonSerializable $payload): self; diff --git a/lib/public/Push/Model/Helper/IPushNotification.php b/lib/public/Push/Model/Helper/IPushNotification.php index 948d770f6f609..bb04a842d14b6 100644 --- a/lib/public/Push/Model/Helper/IPushNotification.php +++ b/lib/public/Push/Model/Helper/IPushNotification.php @@ -9,7 +9,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2018, Maxence Lange + * @copyright 2020, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -37,6 +37,8 @@ /** * Interface IPushNotification * + * Template used to generate an IPushItem with type=Notification + * * @since 18.0.0 * * @package OCP\Push\Helper @@ -53,66 +55,110 @@ interface IPushNotification extends IPushRecipients { /** + * get the title of the notification + * * @return string + * + * @since 18.0.0 */ public function getTitle(): string; /** + * set the title of the notification + * * @param string $title * * @return self + * + * @since 18.0.0 */ public function setTitle(string $title): self; /** + * get the message of the notification + * * @return string + * + * @since 18.0.0 */ public function getMessage(): string; /** + * set the message of the notification + * * @param string $message * * @return self + * + * @since 18.0.0 */ public function setMessage(string $message): self; /** + * get the link to open on a click on the notification + * * @return string + * + * @since 18.0.0 */ public function getLink(): string; /** + * set the link to open on a click on the notification + * * @param string $link * * @return self + * + * @since 18.0.0 */ public function setLink(string $link): self; /** + * get the level of the notification. + * * @return string + * + * @since 18.0.0 */ public function getLevel(): string; /** + * set the level of the notification: + * - IPushNotification::LEVEL_SUCCESS + * - IPushNotification::LEVEL_MESSAGE + * - IPushNotification::LEVEL_WARNING + * - IPushNotification::LEVEL_ERROR + * * @param string $level * * @return self + * + * @since 18.0.0 */ public function setLevel(string $level): self; /** + * get the Time To Live + * * @return int + * + * @since 18.0.0 */ public function getTtl(): int; /** + * set the Time To Live + * * @param int $ttl * * @return self + * + * @since 18.0.0 */ public function setTtl(int $ttl): self; diff --git a/lib/public/Push/Model/IPushItem.php b/lib/public/Push/Model/IPushItem.php index db470d154e367..3d01f3eeeb21c 100644 --- a/lib/public/Push/Model/IPushItem.php +++ b/lib/public/Push/Model/IPushItem.php @@ -9,7 +9,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2018, Maxence Lange + * @copyright 2020, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -33,9 +33,15 @@ use JsonSerializable; + /** * Interface IPushItem * + * Main data object of the Push App, a IPushItem contains all data corresponding to a single event, but its + * recipient. There is no way to set a list of recipients to an IPushItem on its own, which is not an issue when + * reading/updating. + * However, when writing/creating a new IPushItem, it must be wrapped in a IPushWrapper. + * * @since 18.0.0 * * @package OCP\Push @@ -52,173 +58,272 @@ interface IPushItem { /** + * returns the Id (database) + * * @return int + * + * @since 18.0.0 */ public function getId(): int; /** + * returns the token + * * @return string + * + * @since 18.0.0 */ public function getToken(): string; /** + * returns the appId + * * @return string + * + * @since 18.0.0 */ public function getApp(): string; /** + * set the appId + * * @param string $app * * @return self + * + * @since 18.0.0 */ public function setApp(string $app): self; /** + * set the source + * * @return string + * + * @since 18.0.0 */ public function getSource(): string; /** + * returns source + * * @param string $source * * @return self + * + * @since 18.0.0 */ public function setSource(string $source): self; /** + * returns the payload of the item + * * @return array + * + * @since 18.0.0 */ public function getPayload(): array; /** + * set the payload of the item + * * @param array $payload * * @return self + * + * @since 18.0.0 */ public function setPayload(array $payload): self; + /** + * set a Serializable object as payload + * + * @param JsonSerializable $payload + * + * @return IPushItem + * + * @since 18.0.0 + */ + public function setPayloadSerializable(JsonSerializable $payload): self; + /** + * get keyword (used to identify the item) + * * @return string + * + * @since 18.0.0 */ public function getKeyword(): string; /** + * set keyword (used to identify the item) + * * @param string $keyword * * @return self + * + * @since 18.0.0 */ public function setKeyword(string $keyword): self; /** - * @param JsonSerializable $payload + * get type * - * @return IPushItem - */ - public function setPayloadSerializable(JsonSerializable $payload): self; - - - /** * @return string + * + * @since 18.0.0 */ public function getType(): string; /** + * set type of the item (Callback, Notification, Event, ...) + * * @param string $type * * @return self + * + * @since 18.0.0 */ public function setType(string $type): self; /** + * get Time To Live + * * @return int + * + * @since 18.0.0 */ public function getTtl(): int; /** + * set Time To Live + * * @param int $ttl * * @return self + * + * @since 18.0.0 */ public function setTtl(int $ttl): self; /** + * set meta for the item + * * @param array $meta * * @return IPushItem + * + * @since 18.0.0 */ public function setMeta(array $meta): self; /** + * add a meta + * * @param string $k * @param string $v * * @return IPushItem + * + * @since 18.0.0 */ public function addMeta(string $k, string $v): self; /** + * add a meta (int) + * * @param string $k * @param int $v * * @return IPushItem + * + * @since 18.0.0 */ public function addMetaInt(string $k, int $v): self; /** + * add a meta (bool) + * * @param string $k * @param bool $v * * @return IPushItem + * + * @since 18.0.0 */ public function addMetaBool(string $k, bool $v): self; /** + * add a meta (array) + * * @param string $k * @param array $v * * @return IPushItem + * + * @since 18.0.0 */ public function addMetaArray(string $k, array $v): self; /** + * add an entry to an existing array within meta + * * @param string $k * @param string $v * * @return IPushItem + * + * @since 18.0.0 */ public function addMetaArrayEntry(string $k, string $v): self; /** + * returns all meta about the item + * * @return array + * + * @since 18.0.0 */ public function getMeta(): array; /** + * set creation timestamp + * * @param int $timestamp * * @return self + * + * @since 18.0.0 */ public function setCreation(int $timestamp): self; /** + * returns creation timestamp + * * @return int + * + * @since 18.0.0 */ public function getCreation(): int; /** + * fill the current IPushItem with data from a formatted array + * * @param array $import * * @return self + * + * @since 18.0.0 */ public function import(array $import): self; diff --git a/lib/public/Push/Model/IPushRecipients.php b/lib/public/Push/Model/IPushRecipients.php index af80fa4739aa2..d7d029bd80176 100644 --- a/lib/public/Push/Model/IPushRecipients.php +++ b/lib/public/Push/Model/IPushRecipients.php @@ -9,7 +9,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2018, Maxence Lange + * @copyright 2020, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -34,6 +34,13 @@ /** * Interface IPushRecipients * + * This interface extends templates used by the IPushHelper to generate IPushItem + * It contains the base to manage: + * - appId and source + * - meta + * - recipients (users, groups) + * - blacklist and whitelist of apps + * * @since 18.0.0 * * @package OCP\Push @@ -42,214 +49,332 @@ interface IPushRecipients { /** + * returns the appId + * * @return string + * + * @since 18.0.0 */ public function getApp(): string; /** + * set the appId + * * @param string $app * * @return IPushRecipients + * + * @since 18.0.0 */ public function setApp(string $app): self; /** + * set the source + * * @return string + * + * @since 18.0.0 */ public function getSource(): string; /** + * returns the source + * * @param string $source * * @return IPushRecipients + * + * @since 18.0.0 */ public function setSource(string $source): self; /** + * set keyword + * * @return string + * + * @since 18.0.0 */ public function getKeyword(): string; /** + * returns keyword + * * @param string $keyword * * @return IPushRecipients + * + * @since 18.0.0 */ public function setKeyword(string $keyword): self; /** + * returns all meta about the item + * * @return array + * + * @since 18.0.0 */ public function getMeta(): array; /** + * set meta for the item + * * @param array $meta * * @return IPushRecipients + * + * @since 18.0.0 */ public function setMeta(array $meta): self; /** + * add a meta + * * @param string $k * @param string $v * * @return IPushRecipients + * + * @since 18.0.0 */ public function addMeta(string $k, string $v): self; /** + * add a meta (int) + * * @param string $k * @param int $v * * @return IPushRecipients + * + * @since 18.0.0 */ public function addMetaInt(string $k, int $v): self; /** + * add a meta (array) + * * @param string $k * @param array $v * * @return IPushRecipients + * + * @since 18.0.0 */ public function addMetaArray(string $k, array $v): self; /** + * add an entry to an existing array within meta + * * @param string $k * @param string $v * * @return IPushRecipients + * + * @since 18.0.0 */ public function addMetaArrayEntry(string $k, string $v): self; /** + * add meta (bool) + * * @param string $k * @param bool $v * * @return IPushRecipients + * + * @since 18.0.0 */ public function addMetaBool(string $k, bool $v): self; /** + * add a user to the list of recipients + * * @param string $user * * @return IPushRecipients + * + * @since 18.0.0 */ public function addUser(string $user): self; /** - * @param array $users + * add a list of users to the list of recipients + * + * @param string[] $users * * @return IPushRecipients + * + * @since 18.0.0 */ public function addUsers(array $users): self; /** + * remote a user from the list of recipients + * * @param string $user * * @return IPushRecipients + * + * @since 18.0.0 */ public function removeUser(string $user): self; /** - * @param array $users + * remote multiple users from the list of recipients + * + * @param string[] $users * * @return IPushRecipients + * + * @since 18.0.0 */ - public function removeUsers(array $users): self; /** + * add a group to the list of recipients + * * @param string $group * * @return IPushRecipients + * + * @since 18.0.0 */ public function addGroup(string $group): self; /** + * add multiple groups to the list of recipients + * * @param array $groups * * @return IPushRecipients + * + * @since 18.0.0 */ public function addGroups(array $groups): self; /** + * remove a group from the list of recipients + * * @param string $group * * @return IPushRecipients + * + * @since 18.0.0 */ public function removeGroup(string $group): self; /** - * @param array $groups + * remove multiple groups from the list of recipients + * + * @param string[] $groups * * @return IPushRecipients + * + * @since 18.0.0 */ - public function removeGroups(array $groups): self; /** + * returns all users set a recipients + * * @return string[] */ public function getUsers(): array; /** + * returns all groups set as recipients + * * @return string[] */ public function getGroups(): array; /** + * returns all users that should be removed from the list of recipients + * * @return string[] + * + * @since 18.0.0 */ public function getRemovedUsers(): array; /** + * returns all groups that should be removed from the list of recipients + * * @return string[] + * + * @since 18.0.0 */ public function getRemovedGroups(): array; /** + * add a single app to the list of black-listed apps + * * @param string $app * * @return IPushRecipients + * + * @since 18.0.0 */ public function filterApp(string $app): self; /** + * add multiple apps to the list of black-listed apps + * * @param string[] $apps * * @return IPushRecipients + * + * @since 18.0.0 */ public function filterApps(array $apps): self; /** + * returns black-listed apps + * * @return string[] + * + * @since 18.0.0 */ public function getFilteredApps(): array; /** + * add a single app to the list of white-listed apps + * * @param string $app * * @return IPushRecipients + * + * @since 18.0.0 */ public function limitToApp(string $app): self; /** + * add multiple apps to the list of white-listed apps + * * @param string[] $apps * * @return IPushRecipients + * + * @since 18.0.0 */ public function limitToApps(array $apps): self; /** + * returns white-listed apps + * * @return string[] + * + * @since 18.0.0 */ public function getLimitedToApps(): array; diff --git a/lib/public/Push/Model/IPushWrapper.php b/lib/public/Push/Model/IPushWrapper.php index d946a8f89601d..4708795a14cfa 100644 --- a/lib/public/Push/Model/IPushWrapper.php +++ b/lib/public/Push/Model/IPushWrapper.php @@ -9,7 +9,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2018, Maxence Lange + * @copyright 2020, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -34,6 +34,14 @@ /** * Interface IPushWrapper * + * An IPushWrapper is the main object to handle and manage IPushItem around the Push App. + * It contains: + * - a single IPushItem: data that will be send to the front-end + * - a list of recipients: Nextcloud local accounts (userId) + * + * The main purpose is to create and store new IPushItems. + * The IPushWrapper is not used when retrieving IPushItem from the database. + * * @since 18.0.0 * * @package OCP\Push @@ -42,54 +50,86 @@ interface IPushWrapper { /** + * returns if the wrapper contains an IPushItem. + * * @return bool + * + * @since 18.0.0 */ public function hasItem(): bool; /** + * returns the IPushItem from the wrapper. + * * @return IPushItem + * + * @since 18.0.0 */ public function getItem(): IPushItem; /** + * add an IPushItem to the wrapper. + * * @param IPushItem $item * * @return IPushWrapper + * + * @since 18.0.0 */ public function setItem(IPushItem $item): self; /** - * @return array + * returns the list of Nextcloud local accounts (userId) set as recipients + * + * @return string[] + * + * @since 18.0.0 */ public function getRecipients(): array; /** - * @param array $recipients + * set the list of recipients for the wrappers, based on Nextcloud local accounts (userId) + * + * @param string[] $recipients * * @return self + * + * @since 18.0.0 */ public function setRecipients(array $recipients): self; /** + * Add a single Nextcloud local account (userId) to the list of recipients + * * @param string $recipient * * @return IPushWrapper + * + * @since 18.0.0 */ public function addRecipient(string $recipient): self; /** - * @param array $recipients + * Add multiple Nextcloud local accounts (userId) to the list of recipients + * + * @param string[] $recipients * * @return IPushWrapper + * + * @since 18.0.0 */ public function addRecipients(array $recipients): self; /** + * fill the current IPushWrapper with data from a formatted array + * * @param array $import * * @return self + * + * @since 18.0.0 */ public function import(array $import): self; diff --git a/lib/public/Push/Service/IPushService.php b/lib/public/Push/Service/IPushService.php index 00370f24eba6b..b3ff12d900c2d 100644 --- a/lib/public/Push/Service/IPushService.php +++ b/lib/public/Push/Service/IPushService.php @@ -9,7 +9,7 @@ * later. See the COPYING file. * * @author Maxence Lange - * @copyright 2018, Maxence Lange + * @copyright 2020, Maxence Lange * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -41,6 +41,9 @@ /** * Interface IPushService * + * This interface contains list of tools to manage your events. + * A PushService is registered by the Push App (when installed) + * * @since 18.0.0 * * @package OCP\Push\Service @@ -49,21 +52,30 @@ interface IPushService { /** - * erase if keyword is specified and already exist in db. + * Save the item, contained in the wrapper, in the database. + * If a keyword is specified to the item, any non-published item with the same keyword/appId/userId will + * be deleted. * * @param IPushWrapper $wrapper + * + * @since 18.0.0 */ public function push(IPushWrapper $wrapper): void; /** - * update only if the item still exists. + * Update the item, if still available in the database. * * @param IPushItem $item + * + * @since 18.0.0 */ public function update(IPushItem $item): void; /** + * returns the IPushItem identified by its appId, userId and keyword. + * throws an ItemNotFoundException if the item is not available in the database. + * * @param string $app * @param string $userId * @param string $keyword @@ -71,15 +83,21 @@ public function update(IPushItem $item): void; * @return IPushItem * @throws ItemNotFoundException * @throws UnknownStreamTypeException + * + * @since 18.0.0 */ public function getItemByKeyword(string $app, string $userId, string $keyword): IPushItem; /** + * fill the IPushWrapper with recipients stored in the IPushRecipients + * * @param IPushWrapper $wrapper * @param IPushRecipients $recipients * * @return mixed + * + * @since 18.0.0 */ public function fillRecipients(IPushWrapper $wrapper, IPushRecipients $recipients): void; From 0fd60bf2e82ab3dee7ddb3073430e58f846c4c49 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 11 Sep 2019 09:49:35 -0100 Subject: [PATCH 16/16] fixing some stuff Signed-off-by: Maxence Lange --- .../Push/Model/Helper/PushCallback.php | 4 +- lib/private/Push/PushManager.php | 2 +- .../FullTextSearch/Model/ISearchResult.php | 55 ++++++++----------- lib/public/Push/IPushManager.php | 2 +- 4 files changed, 27 insertions(+), 36 deletions(-) diff --git a/lib/private/Push/Model/Helper/PushCallback.php b/lib/private/Push/Model/Helper/PushCallback.php index a5ab49c27ac8d..4d5fc2b3f25af 100644 --- a/lib/private/Push/Model/Helper/PushCallback.php +++ b/lib/private/Push/Model/Helper/PushCallback.php @@ -58,11 +58,11 @@ class PushCallback extends PushRecipients implements IPushCallback, JsonSerializ * PushCallback constructor. * * @param string $app - * @param $source + * @param string $source * * @since 18.0.0 */ - public function __construct($app = '', $source = '') { + public function __construct(string $app = '', string $source = '') { $this->setApp($app); $this->setSource($source); } diff --git a/lib/private/Push/PushManager.php b/lib/private/Push/PushManager.php index 574a618ac781a..c65a57ebc79cc 100644 --- a/lib/private/Push/PushManager.php +++ b/lib/private/Push/PushManager.php @@ -60,7 +60,7 @@ class PushManager implements IPushManager { * * @since 18.0.0 */ - public function registerPushApp(IPushService $pushService, IPushHelper $pushHelper): void { + public function registerPushService(IPushService $pushService, IPushHelper $pushHelper): void { $this->pushService = $pushService; $this->pushHelper = $pushHelper; } diff --git a/lib/public/FullTextSearch/Model/ISearchResult.php b/lib/public/FullTextSearch/Model/ISearchResult.php index d5ee12382c90c..2ca61c2f37b3e 100644 --- a/lib/public/FullTextSearch/Model/ISearchResult.php +++ b/lib/public/FullTextSearch/Model/ISearchResult.php @@ -59,20 +59,20 @@ interface ISearchResult { /** * Get the original SearchRequest. * - * @return ISearchRequest - * @since 15.0.0 - * * @see ISearchRequest * + * @since 15.0.0 + * + * @return ISearchRequest */ public function getRequest(): ISearchRequest; /** * Get the targeted Content Provider. * - * @return IFullTextSearchProvider * @since 15.0.0 * + * @return IFullTextSearchProvider */ public function getProvider(): IFullTextSearchProvider; @@ -80,65 +80,56 @@ public function getProvider(): IFullTextSearchProvider; /** * Add an IIndexDocument as one of the result of the search request. * + * @since 15.0.0 + * * @param IIndexDocument $document * * @return ISearchResult - * @since 15.0.0 - * */ public function addDocument(IIndexDocument $document): ISearchResult; /** * Returns all result of the search request, in an array of IIndexDocument. * - * @return IIndexDocument[] * @since 15.0.0 * + * @return IIndexDocument[] */ public function getDocuments(): array; /** * Set an array of IIndexDocument as the result of the search request. * + * @since 15.0.0 + * * @param IIndexDocument[] $documents * * @return ISearchResult - * @since 15.0.0 - * */ public function setDocuments(array $documents): ISearchResult; - - - public function addInfo(string $k, string $value): ISearchResult; - - public function getInfo(string $k): string; - - public function getInfosAll(): array; - - /** * Add an aggregation to the result. * + * @since 15.0.0 + * * @param string $category * @param string $value * @param int $count * * @return ISearchResult - * @since 15.0.0 - * */ public function addAggregation(string $category, string $value, int $count): ISearchResult; /** * Get all aggregations. * + * @since 15.0.0 + * * @param string $category * * @return array - * @since 15.0.0 - * */ public function getAggregations(string $category): array; @@ -146,11 +137,11 @@ public function getAggregations(string $category): array; /** * Set the raw result of the request. * + * @since 15.0.0 + * * @param string $result * * @return ISearchResult - * @since 15.0.0 - * */ public function setRawResult(string $result): ISearchResult; @@ -159,11 +150,11 @@ public function setRawResult(string $result): ISearchResult; * Set the total number of results for the search request. * Used by pagination. * + * @since 15.0.0 + * * @param int $total * * @return ISearchResult - * @since 15.0.0 - * */ public function setTotal(int $total): ISearchResult; @@ -171,11 +162,11 @@ public function setTotal(int $total): ISearchResult; /** * Set the top score for the search request. * + * @since 15.0.0 + * * @param int $score * * @return ISearchResult - * @since 15.0.0 - * */ public function setMaxScore(int $score): ISearchResult; @@ -183,11 +174,11 @@ public function setMaxScore(int $score): ISearchResult; /** * Set the time spent by the request to perform the search. * + * @since 15.0.0 + * * @param int $time * * @return ISearchResult - * @since 15.0.0 - * */ public function setTime(int $time): ISearchResult; @@ -195,11 +186,11 @@ public function setTime(int $time): ISearchResult; /** * Set to true if the request timed out. * + * @since 15.0.0 + * * @param bool $timedOut * * @return ISearchResult - * @since 15.0.0 - * */ public function setTimedOut(bool $timedOut): ISearchResult; diff --git a/lib/public/Push/IPushManager.php b/lib/public/Push/IPushManager.php index 8a48e74b2a773..07bbc1d15fcc7 100644 --- a/lib/public/Push/IPushManager.php +++ b/lib/public/Push/IPushManager.php @@ -65,7 +65,7 @@ interface IPushManager { * @since 18.0.0 * */ - public function registerPushApp(IPushService $pushService, IPushHelper $pushHelper): void; + public function registerPushService(IPushService $pushService, IPushHelper $pushHelper): void; /**