From 508dfb1501632a628125daa1a907d9bbf8177a55 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Thu, 25 Jan 2024 11:42:38 +0100 Subject: [PATCH] add capability telling if the assistant is enabled for the current user Signed-off-by: Julien Veyssier --- lib/AppInfo/Application.php | 3 +++ lib/Capabilities.php | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/Capabilities.php diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 1c5dac88..636fedf0 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -2,6 +2,7 @@ namespace OCA\TpAssistant\AppInfo; +use OCA\TpAssistant\Capabilities; use OCA\TpAssistant\Listener\BeforeTemplateRenderedListener; use OCA\TpAssistant\Listener\FreePrompt\FreePromptReferenceListener; use OCA\TpAssistant\Listener\SpeechToText\SpeechToTextReferenceListener; @@ -48,6 +49,8 @@ public function __construct(array $urlParams = []) { } public function register(IRegistrationContext $context): void { + $context->registerCapability(Capabilities::class); + $context->registerReferenceProvider(Text2ImageReferenceProvider::class); $context->registerReferenceProvider(FreePromptReferenceProvider::class); $context->registerReferenceProvider(SpeechToTextReferenceProvider::class); diff --git a/lib/Capabilities.php b/lib/Capabilities.php new file mode 100644 index 00000000..7a9ba67b --- /dev/null +++ b/lib/Capabilities.php @@ -0,0 +1,39 @@ +> + */ + public function getCapabilities(): array { + $appVersion = $this->appManager->getAppVersion(Application::APP_ID); + $capability = [ + Application::APP_ID => [ + 'version' => $appVersion, + ], + ]; + if ($this->userId !== null) { + $adminAssistantEnabled = $this->config->getAppValue(Application::APP_ID, 'assistant_enabled', '1') === '1'; + $userAssistantEnabled = $this->config->getUserValue($this->userId, Application::APP_ID, 'assistant_enabled', '1') === '1'; + $assistantEnabled = $adminAssistantEnabled && $userAssistantEnabled; + $capability[Application::APP_ID]['enabled'] = $assistantEnabled; + } + return $capability; + } +}