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
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m

]]></description>

<version>13.0.0-dev</version>
<version>13.0.0-dev.1</version>
<licence>agpl</licence>

<author>Daniel Calviño Sánchez</author>
Expand Down
21 changes: 21 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,27 @@
],
],

/**
* Federation
*/

[
'name' => 'Federation#acceptShare',
'url' => 'api/{apiVersion}/federation/invitation/{id}',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1',
],
],
[
'name' => 'Federation#rejectShare',
'url' => 'api/{apiVersion}/federation/invitation/{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) {
Copy link
Member

Choose a reason for hiding this comment

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

When there is no local user in the room anymore it should be delete. Or is this for the share-receiving side?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is for the share-receiving side. When a share for an unknown room is received, it is created on the rooms table then the invitation put in the invitations table so don't delete rooms that have pending invitations for it.

$room->deleteRoom();
$this->numDeletedRooms++;
}
Expand Down
87 changes: 87 additions & 0 deletions lib/Controller/FederationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?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 OCA\Talk\AppInfo\Application;
use OCA\Talk\Exceptions\UnauthorizedException;
use OCA\Talk\Federation\FederationManager;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
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;
}

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

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