From 2c356d085236ba17367f25998953b61368078fcd Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 20 Dec 2021 17:58:54 +0100 Subject: Add a Talk API for OCP Signed-off-by: Christoph Wurst --- .../AppFramework/Bootstrap/RegistrationContext.php | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lib/private/AppFramework/Bootstrap') diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index 6a9073b576b..401a967c988 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -30,6 +30,8 @@ declare(strict_types=1); namespace OC\AppFramework\Bootstrap; use Closure; +use OCP\Talk\ITalkBackend; +use RuntimeException; use function array_shift; use OC\Support\CrashReport\Registry; use OCP\AppFramework\App; @@ -65,6 +67,9 @@ class RegistrationContext { /** @var ServiceRegistration[] */ private $profileLinkActions = []; + /** @var null|ServiceRegistration */ + private $talkBackendRegistration = null; + /** @var ServiceFactoryRegistration[] */ private $services = []; @@ -259,6 +264,13 @@ class RegistrationContext { $actionClass ); } + + public function registerTalkBackend(string $backend): void { + $this->context->registerTalkBackend( + $this->appId, + $backend + ); + } }; } @@ -349,6 +361,21 @@ class RegistrationContext { $this->profileLinkActions[] = new ServiceRegistration($appId, $actionClass); } + /** + * @psalm-param class-string $backend + */ + public function registerTalkBackend(string $appId, string $backend) { + // Some safeguards for invalid registrations + if ($appId !== 'spreed') { + throw new RuntimeException("Only the Talk app is allowed to register a Talk backend"); + } + if ($this->talkBackendRegistration !== null) { + throw new RuntimeException("There can only be one Talk backend"); + } + + $this->talkBackendRegistration = new ServiceRegistration($appId, $backend); + } + /** * @param App[] $apps */ @@ -600,4 +627,12 @@ class RegistrationContext { public function getProfileLinkActions(): array { return $this->profileLinkActions; } + + /** + * @return ServiceRegistration|null + * @psalm-return ServiceRegistration|null + */ + public function getTalkBackendRegistration(): ?ServiceRegistration { + return $this->talkBackendRegistration; + } } -- cgit v1.2.3