Browse Source

fix(capabilities): Fix capability issues with OpenAI integration providing too many translations

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/10317/head
Joas Schilling 2 years ago
parent
commit
39d185fe14
No known key found for this signature in database GPG Key ID: 74434EFE0D2E2205
  1. 3
      docs/capabilities.md
  2. 3
      lib/Capabilities.php
  3. 18
      tests/php/CapabilitiesTest.php

3
docs/capabilities.md

@ -115,7 +115,7 @@
## 17
* `avatar` - Avatar of conversation
* `config => chat => translations` - List of translations tuples, JSON encoded sample `{"from":"de","fromLabel":"German","to":"en","toLabel":"English"}`. Those tuples should be provided as options when translating chat messages.
* ~~`config => chat => translations` - List of translations tuples, JSON encoded sample `{"from":"de","fromLabel":"German","to":"en","toLabel":"English"}`. Those tuples should be provided as options when translating chat messages.~~ Due to some providers the list was too big causing issues in various clients. So the capability was replaced by boolean `config => chat => has-translation-providers` in Talk 18.
* `config => call => predefined-backgrounds` - List of predefined virtual backgrounds. The files are in Talks img/ folder, accessible via the normal image path methods. The list is cached for 5 minutes.
* `config => call => can-upload-background` - Boolean flag whether the user can upload a custom virtual background (requires an account and non-zero quota). Uploads should be done to Talk/Backgrounds/ (respecting the user's attachment directory setting).
* `config => call => supported-reactions` - A list of emojis supported as call reactions. If the list is absent or empty, clients should not show the emoji reaction option in calls.
@ -129,3 +129,4 @@
## 18
* `session-state` - Sessions can mark themselves as inactive, so the participant receives notifications again
* `config => chat => has-translation-providers` - When true, translation tuples can be loaded from the [OCS Translation API](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-translation-api.html#get-available-translation-options).

3
lib/Capabilities.php

@ -137,8 +137,7 @@ class Capabilities implements IPublicCapability {
'chat' => [
'max-length' => ChatManager::MAX_CHAT_LENGTH,
'read-privacy' => Participant::PRIVACY_PUBLIC,
// Transform the JsonSerializable language tuples to arrays
'translations' => json_decode(json_encode($this->translationManager->getLanguages()), true),
'has-translation-providers' => $this->translationManager->hasProviders(),
'typing-privacy' => Participant::PRIVACY_PUBLIC,
],
'conversations' => [

18
tests/php/CapabilitiesTest.php

@ -38,7 +38,6 @@ use OCP\IConfig;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Translation\ITranslationManager;
use OCP\Translation\LanguageTuple;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@ -206,7 +205,7 @@ class CapabilitiesTest extends TestCase {
'chat' => [
'max-length' => 32000,
'read-privacy' => 0,
'translations' => [],
'has-translation-providers' => false,
'typing-privacy' => 0,
],
'conversations' => [
@ -330,7 +329,7 @@ class CapabilitiesTest extends TestCase {
'chat' => [
'max-length' => 32000,
'read-privacy' => $readPrivacy,
'translations' => [],
'has-translation-providers' => false,
'typing-privacy' => 0,
],
'conversations' => [
@ -447,17 +446,10 @@ class CapabilitiesTest extends TestCase {
$this->cacheFactory,
);
$translations = [];
$translations[] = new LanguageTuple('de', 'de Label', 'en', 'en Label');
$translations[] = new LanguageTuple('de_DE', 'de_DE Label', 'en', 'en Label');
$this->translationManager->method('getLanguages')
->willReturn($translations);
$this->translationManager->method('hasProviders')
->willReturn(true);
$data = json_decode(json_encode($capabilities->getCapabilities(), JSON_THROW_ON_ERROR), true);
$this->assertEquals([
['from' => 'de', 'fromLabel' => 'de Label', 'to' => 'en', 'toLabel' => 'en Label'],
['from' => 'de_DE', 'fromLabel' => 'de_DE Label', 'to' => 'en', 'toLabel' => 'en Label'],
], $data['spreed']['config']['chat']['translations']);
$this->assertEquals(true, $data['spreed']['config']['chat']['has-translation-providers']);
}
}
Loading…
Cancel
Save