Skip to content

Commit 286ef27

Browse files
committed
Implement CloudFederationProvider for Talk
Signed-off-by: Gary Kim <[email protected]>
1 parent 6d831c0 commit 286ef27

14 files changed

Lines changed: 905 additions & 6 deletions

appinfo/routes.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,27 @@
514514
],
515515
],
516516

517+
/**
518+
* Federation
519+
*/
520+
521+
[
522+
'name' => 'Federation#acceptShare',
523+
'url' => 'api/{apiVersion}/federation/pending/{id}',
524+
'verb' => 'POST',
525+
'requirements' => [
526+
'apiVersion' => 'v1',
527+
],
528+
],
529+
[
530+
'name' => 'Federation#rejectShare',
531+
'url' => 'api/{apiVersion}/federation/pending/{id}',
532+
'verb' => 'DELETE',
533+
'requirements' => [
534+
'apiVersion' => 'v1',
535+
],
536+
],
537+
517538
/**
518539
* PublicShareAuth
519540
*/

lib/BackgroundJob/RemoveEmptyRooms.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace OCA\Talk\BackgroundJob;
2525

26+
use OCA\Talk\Federation\FederationManager;
2627
use OCA\Talk\Service\ParticipantService;
2728
use OCP\AppFramework\Utility\ITimeFactory;
2829
use OCP\BackgroundJob\TimedJob;
@@ -46,6 +47,9 @@ class RemoveEmptyRooms extends TimedJob {
4647
/** @var LoggerInterface */
4748
protected $logger;
4849

50+
/** @var FederationManager */
51+
protected $federationManager;
52+
4953
protected $numDeletedRooms = 0;
5054

5155
public function __construct(ITimeFactory $timeFactory,
@@ -77,7 +81,7 @@ public function callback(Room $room): void {
7781
return;
7882
}
7983

80-
if ($this->participantService->getNumberOfActors($room) === 0 && $room->getObjectType() !== 'file') {
84+
if ($this->participantService->getNumberOfActors($room) === 0 && $room->getObjectType() !== 'file' && $this->federationManager->getNumberOfInvitations($room) === 0) {
8185
$room->deleteRoom();
8286
$this->numDeletedRooms++;
8387
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2021, Gary Kim <[email protected]>
6+
*
7+
* @author Gary Kim <[email protected]>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
namespace OCA\Talk\Controller;
27+
28+
use OC\AppFramework\Middleware\Security\Exceptions\NotLoggedInException;
29+
use OCA\Talk\AppInfo\Application;
30+
use OCA\Talk\Exceptions\UnauthorizedException;
31+
use OCA\Talk\Federation\FederationManager;
32+
use OCP\AppFramework\Http\DataResponse;
33+
use OCP\AppFramework\OCSController;
34+
use OCP\DB\Exception as DBException;
35+
use OCP\IRequest;
36+
use OCP\IUser;
37+
use OCP\IUserSession;
38+
39+
class FederationController extends OCSController {
40+
/** @var FederationManager */
41+
private $federationManager;
42+
43+
/** @var IUserSession */
44+
private $userSession;
45+
46+
public function __construct(IRequest $request, FederationManager $federationManager, IUserSession $userSession) {
47+
parent::__construct(Application::APP_ID, $request);
48+
$this->federationManager = $federationManager;
49+
$this->userSession = $userSession;
50+
}
51+
52+
/**
53+
* @param int $id
54+
* @return DataResponse
55+
* @throws NotLoggedInException
56+
* @throws UnauthorizedException
57+
* @throws DBException
58+
*/
59+
public function acceptShare(int $id): DataResponse {
60+
$user = $this->userSession->getUser();
61+
if (!$user instanceof IUser) {
62+
throw new NotLoggedInException();
63+
}
64+
$this->federationManager->acceptRemoteRoomShare($user, $id);
65+
return new DataResponse();
66+
}
67+
68+
/**
69+
* @param int $id
70+
* @return DataResponse
71+
* @throws NotLoggedInException
72+
* @throws UnauthorizedException
73+
* @throws DBException
74+
*/
75+
public function rejectShare(int $id): DataResponse {
76+
$user = $this->userSession->getUser();
77+
if (!$user instanceof IUser) {
78+
throw new NotLoggedInException();
79+
}
80+
$this->federationManager->rejectRemoteRoomShare($user, $id);
81+
return new DataResponse();
82+
}
83+
}

0 commit comments

Comments
 (0)