|
| 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