Skip to content

Commit

Permalink
Implement CloudFederationProvider for Talk
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Kim <[email protected]>
  • Loading branch information
gary-kim committed Jun 25, 2021
1 parent 6d831c0 commit a44c90b
Show file tree
Hide file tree
Showing 14 changed files with 909 additions and 6 deletions.
21 changes: 21 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,27 @@
],
],

/**
* Federation
*/

[
'name' => 'Federation#acceptShare',
'url' => 'api/{apiVersion}/federation/pending/{id}',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1',
],
],
[
'name' => 'Federation#rejectShare',
'url' => 'api/{apiVersion}/federation/pending/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v1',
],
],

/**
* PublicShareAuth
*/
Expand Down
6 changes: 5 additions & 1 deletion lib/BackgroundJob/RemoveEmptyRooms.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Talk\BackgroundJob;

use OCA\Talk\Federation\FederationManager;
use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
Expand All @@ -46,6 +47,9 @@ class RemoveEmptyRooms extends TimedJob {
/** @var LoggerInterface */
protected $logger;

/** @var FederationManager */
protected $federationManager;

protected $numDeletedRooms = 0;

public function __construct(ITimeFactory $timeFactory,
Expand Down Expand Up @@ -77,7 +81,7 @@ public function callback(Room $room): void {
return;
}

if ($this->participantService->getNumberOfActors($room) === 0 && $room->getObjectType() !== 'file') {
if ($this->participantService->getNumberOfActors($room) === 0 && $room->getObjectType() !== 'file' && $this->federationManager->getNumberOfInvitations($room) === 0) {
$room->deleteRoom();
$this->numDeletedRooms++;
}
Expand Down
83 changes: 83 additions & 0 deletions lib/Controller/FederationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2021, Gary Kim <[email protected]>
*
* @author Gary Kim <[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\Controller;

use OC\AppFramework\Middleware\Security\Exceptions\NotLoggedInException;
use OCA\Talk\AppInfo\Application;
use OCA\Talk\Exceptions\UnauthorizedException;
use OCA\Talk\Federation\FederationManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\DB\Exception as DBException;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;

class FederationController extends OCSController {
/** @var FederationManager */
private $federationManager;

/** @var IUserSession */
private $userSession;

public function __construct(IRequest $request, FederationManager $federationManager, IUserSession $userSession) {
parent::__construct(Application::APP_ID, $request);
$this->federationManager = $federationManager;
$this->userSession = $userSession;
}

/**
* @param int $id
* @return DataResponse
* @throws NotLoggedInException
* @throws UnauthorizedException
* @throws DBException
*/
public function acceptShare(int $id): DataResponse {
$user = $this->userSession->getUser();
if (!$user instanceof IUser) {
throw new NotLoggedInException();
}
$this->federationManager->acceptRemoteRoomShare($user, $id);
return new DataResponse();
}

/**
* @param int $id
* @return DataResponse
* @throws NotLoggedInException
* @throws UnauthorizedException
* @throws DBException
*/
public function rejectShare(int $id): DataResponse {
$user = $this->userSession->getUser();
if (!$user instanceof IUser) {
throw new NotLoggedInException();
}
$this->federationManager->rejectRemoteRoomShare($user, $id);
return new DataResponse();
}
}
Loading

0 comments on commit a44c90b

Please sign in to comment.