Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@

## 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.
23 changes: 8 additions & 15 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,18 @@
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Translation\ITranslationManager;

class Capabilities implements IPublicCapability {
protected IConfig $serverConfig;
protected Config $talkConfig;
protected ICommentsManager $commentsManager;
protected IUserSession $userSession;
private IAppManager $appManager;

public function __construct(
IConfig $serverConfig,
Config $talkConfig,
ICommentsManager $commentsManager,
IUserSession $userSession,
IAppManager $appManager,
protected IConfig $serverConfig,
protected Config $talkConfig,
protected ICommentsManager $commentsManager,
protected IUserSession $userSession,
protected IAppManager $appManager,
Copy link

@max-nextcloud max-nextcloud Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$appManager was private before.
Is that change on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I have protected as it prevents extending

protected ITranslationManager $translationManager,
Comment on lines +40 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

) {
$this->serverConfig = $serverConfig;
$this->talkConfig = $talkConfig;
$this->commentsManager = $commentsManager;
$this->userSession = $userSession;
$this->appManager = $appManager;
}

public function getCapabilities(): array {
Expand Down Expand Up @@ -134,6 +126,7 @@ public function getCapabilities(): array {
'max-length' => ChatManager::MAX_CHAT_LENGTH,
'read-privacy' => Participant::PRIVACY_PUBLIC,
//'legacy' => true, // Temporary A-B switch to opt-out of the new context loading
'translations' => $this->translationManager->getLanguages(),
],
'conversations' => [
'can-create' => $user instanceof IUser && !$this->talkConfig->isNotAllowedToCreateConversations($user)
Expand Down
60 changes: 45 additions & 15 deletions tests/php/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,18 @@
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;

class CapabilitiesTest extends TestCase {
/** @var IConfig|MockObject */
protected $serverConfig;
/** @var Config|MockObject */
protected $talkConfig;
/** @var CommentsManager|MockObject */
protected $commentsManager;
/** @var IUserSession|MockObject */
protected $userSession;
/** @var IAppManager|MockObject */
protected $appManager;
protected IConfig|MockObject $serverConfig;
protected Config|MockObject $talkConfig;
protected CommentsManager|MockObject $commentsManager;
protected IUserSession|MockObject $userSession;
protected IAppManager|MockObject $appManager;
protected ITranslationManager|MockObject $translationManager;
protected ?array $baseFeatures = null;

public function setUp(): void {
Expand All @@ -58,6 +56,7 @@ public function setUp(): void {
$this->commentsManager = $this->createMock(CommentsManager::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->translationManager = $this->createMock(ITranslationManager::class);

$this->commentsManager->expects($this->any())
->method('supportReactions')
Expand Down Expand Up @@ -138,7 +137,8 @@ public function testGetCapabilitiesGuest(): void {
$this->talkConfig,
$this->commentsManager,
$this->userSession,
$this->appManager
$this->appManager,
$this->translationManager,
);

$this->userSession->expects($this->once())
Expand Down Expand Up @@ -178,6 +178,7 @@ public function testGetCapabilitiesGuest(): void {
'chat' => [
'max-length' => 32000,
'read-privacy' => 0,
'translations' => [],
],
'conversations' => [
'can-create' => false,
Expand Down Expand Up @@ -213,7 +214,8 @@ public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCrea
$this->talkConfig,
$this->commentsManager,
$this->userSession,
$this->appManager
$this->appManager,
$this->translationManager,
);

$user = $this->createMock(IUser::class);
Expand Down Expand Up @@ -280,6 +282,7 @@ public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCrea
'chat' => [
'max-length' => 32000,
'read-privacy' => $readPrivacy,
'translations' => [],
],
'conversations' => [
'can-create' => $canCreate,
Expand Down Expand Up @@ -317,7 +320,8 @@ public function testGetCapabilitiesUserDisallowed(): void {
$this->talkConfig,
$this->commentsManager,
$this->userSession,
$this->appManager
$this->appManager,
$this->translationManager,
);

$user = $this->createMock(IUser::class);
Expand All @@ -340,7 +344,8 @@ public function testCapabilitiesHelloV2Key(): void {
$this->talkConfig,
$this->commentsManager,
$this->userSession,
$this->appManager
$this->appManager,
$this->translationManager,
);

$this->talkConfig->expects($this->once())
Expand All @@ -360,7 +365,8 @@ public function testConfigRecording(bool $enabled): void {
$this->talkConfig,
$this->commentsManager,
$this->userSession,
$this->appManager
$this->appManager,
$this->translationManager,
);

$this->talkConfig->expects($this->once())
Expand All @@ -377,4 +383,28 @@ public function dataTestConfigRecording(): array {
[false],
];
}

public function testCapabilitiesTranslations(): void {
$capabilities = new Capabilities(
$this->serverConfig,
$this->talkConfig,
$this->commentsManager,
$this->userSession,
$this->appManager,
$this->translationManager,
);

$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);

$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']);
}
}