Skip to content

Commit

Permalink
feat(federation): Register the OCM resource
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Apr 9, 2024
1 parent c59b9b8 commit 81d5cb4
Show file tree
Hide file tree
Showing 2 changed files with 69 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 @@ -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 <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @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/',
]
);
}
}

0 comments on commit 81d5cb4

Please sign in to comment.