Skip to content

Commit

Permalink
add capability telling if the assistant is enabled for the current user
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Jan 25, 2024
1 parent 00fec49 commit 508dfb1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
39 changes: 39 additions & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace OCA\TpAssistant;

use OCA\TpAssistant\AppInfo\Application;
use OCP\App\IAppManager;
use OCP\Capabilities\IPublicCapability;
use OCP\IConfig;

class Capabilities implements IPublicCapability {

public function __construct(
private IAppManager $appManager,
private IConfig $config,
private ?string $userId,
) {
}

/**
* @return array<string, array<string, bool|string>>
*/
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;
}
}

0 comments on commit 508dfb1

Please sign in to comment.