2020-11-13 19:01:46 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
|
|
|
|
*
|
|
|
|
* @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\NotifyPush;
|
|
|
|
|
|
|
|
use OCP\Capabilities\ICapability;
|
|
|
|
use OCP\IConfig;
|
2021-01-12 21:34:25 +03:00
|
|
|
use OCP\IURLGenerator;
|
2020-11-13 19:01:46 +03:00
|
|
|
|
|
|
|
class Capabilities implements ICapability {
|
|
|
|
private $config;
|
2021-01-12 21:34:25 +03:00
|
|
|
private $urlGenerator;
|
2020-11-13 19:01:46 +03:00
|
|
|
|
2021-01-12 21:34:25 +03:00
|
|
|
public function __construct(IConfig $config, IURLGenerator $urlGenerator) {
|
2020-11-13 19:01:46 +03:00
|
|
|
$this->config = $config;
|
2021-01-12 21:34:25 +03:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
2020-11-13 19:01:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
2020-12-02 20:25:55 +03:00
|
|
|
$baseEndpoint = $this->config->getAppValue('notify_push', 'base_endpoint');
|
|
|
|
|
|
|
|
$wsEndpoint = str_replace('https://', 'wss://', $baseEndpoint);
|
2020-12-03 18:51:26 +03:00
|
|
|
$wsEndpoint = str_replace('http://', 'ws://', $wsEndpoint) . '/ws';
|
2020-12-02 20:25:55 +03:00
|
|
|
|
|
|
|
if ($baseEndpoint) {
|
|
|
|
return [
|
|
|
|
'notify_push' => [
|
2021-01-26 16:56:14 +03:00
|
|
|
'type' => ['files', 'activities', 'notifications'],
|
2020-12-02 20:25:55 +03:00
|
|
|
'endpoints' => [
|
|
|
|
'websocket' => $wsEndpoint,
|
2021-01-22 23:14:43 +03:00
|
|
|
'pre_auth' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('notify_push.Auth.preAuth'))
|
2020-12-02 20:25:55 +03:00
|
|
|
],
|
2020-11-13 19:01:46 +03:00
|
|
|
],
|
2020-12-02 20:25:55 +03:00
|
|
|
];
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
2020-11-13 19:01:46 +03:00
|
|
|
}
|
|
|
|
}
|