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
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
use OCA\Talk\Events\SystemMessagesMultipleSentEvent;
use OCA\Talk\Events\UserJoinedRoomEvent;
use OCA\Talk\Federation\CloudFederationProviderTalk;
use OCA\Talk\Federation\Proxy\TalkV1\Listener\ResourceTypeRegisterListener;
use OCA\Talk\Federation\Proxy\TalkV1\Notifier\BeforeRoomDeletedListener as TalkV1BeforeRoomDeletedListener;
use OCA\Talk\Federation\Proxy\TalkV1\Notifier\CancelRetryOCMListener as TalkV1CancelRetryOCMListener;
use OCA\Talk\Federation\Proxy\TalkV1\Notifier\MessageSentListener as TalkV1MessageSentListener;
Expand Down Expand Up @@ -146,6 +147,7 @@
use OCP\IUser;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\OCM\Events\ResourceTypeRegisterEvent;
use OCP\Security\CSP\AddContentSecurityPolicyEvent;
use OCP\Security\FeaturePolicy\AddFeaturePolicyEvent;
use OCP\Server;
Expand Down Expand Up @@ -288,6 +290,7 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(SystemMessageSentEvent::class, TalkV1MessageSentListener::class);
$context->registerEventListener(SystemMessagesMultipleSentEvent::class, TalkV1MessageSentListener::class);
$context->registerEventListener(AttendeeRemovedEvent::class, TalkV1CancelRetryOCMListener::class);
$context->registerEventListener(ResourceTypeRegisterEvent::class, ResourceTypeRegisterListener::class);

// Signaling listeners (External)
$context->registerEventListener(AttendeesAddedEvent::class, SignalingListener::class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);
/*
* @copyright Copyright (c) 2024 Joas Schilling <[email protected]>
*
* @author Joas Schilling <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Talk\Federation\Proxy\TalkV1\Listener;

use OCA\Talk\Config;
use OCA\Talk\Federation\CloudFederationProviderTalk;
use OCA\Talk\Federation\FederationManager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\OCM\Events\ResourceTypeRegisterEvent;
use OCP\OCM\IOCMProvider;

/**
* @template-implements IEventListener<Event>
*/
class ResourceTypeRegisterListener implements IEventListener {

public function __construct(
protected Config $talkConfig,
protected IOCMProvider $provider,
protected CloudFederationProviderTalk $talkProvider,
) {
}

public function handle(Event $event): void {
if (!$event instanceof ResourceTypeRegisterEvent) {
// Unrelated
return;
}

if (!$this->talkConfig->isFederationEnabled()) {
return;
}

$event->registerResourceType(
FederationManager::TALK_ROOM_RESOURCE,
$this->talkProvider->getSupportedShareTypes(),
[
'talk-v1' => '/ocs/v2.php/apps/spreed/api/',
]
);
}
}
30 changes: 30 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3320,6 +3320,36 @@ public function setAppConfig(string $appId, TableNode $formData): void {
$this->setCurrentUser($currentUser);
}

/**
* @Given /^OCM provider (does not have|has) the following resource types$/
*
* @param TableNode $formData
*/
public function checkOCMProviderResourceTypes(string $shouldFind, TableNode $formData): void {
$this->sendFrontpageRequest('GET', '/ocm-provider');
$data = json_decode($this->response->getBody()->getContents(), true);
$expectedTypes = $formData->getHash();
$expectedFound = $shouldFind === 'has';

foreach ($expectedTypes as $expected) {
$found = false;
foreach ($data['resourceTypes'] as $type) {
if ($type['name'] === $expected['name']) {
$found = true;
Assert::assertEquals(
json_decode($expected['shareTypes'], true),
$type['shareTypes'],
);
Assert::assertEquals(
json_decode($expected['protocols'], true),
$type['protocols'],
);
}
}
Assert::assertEquals($expectedFound, $found);
}
}

/**
* @Then user :user has the following notifications
*
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/features/federation/ocm.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: federation/ocm
Background:
Given user "participant1" exists

Scenario: Check that the OCM resource is not registered when federation is disabled
Given the following "spreed" app config is set
| federation_enabled | no |
Then OCM provider does not have the following resource types
| name | shareTypes | protocols |
| talk-room | ["user"] | {"talk-v1":"/ocs/v2.php/apps/spreed/api/"} |

Scenario: Check that the OCM resource is registered when federation is enabled
Given the following "spreed" app config is set
| federation_enabled | yes |
Given OCM provider has the following resource types
| name | shareTypes | protocols |
| talk-room | ["user"] | {"talk-v1":"/ocs/v2.php/apps/spreed/api/"} |
2 changes: 1 addition & 1 deletion tests/integration/features/federation/poll.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: chat-2/poll
Feature: federation/poll
Background:
Given user "participant1" exists
Given user "participant2" exists
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/features/federation/reminder.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: federation/chat
Feature: federation/reminder
Background:
Given user "participant1" exists
Given user "participant2" exists
Expand Down