libresign/lib/Activity/Provider/SignRequest.php
Vitor Mattos 863508e8e4
Implement activity
Signed-off-by: Vitor Mattos <vitor@php.rio>
2024-03-04 20:38:44 -03:00

78 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2024 Vitor Mattos <vitor@php.rio>
*
* @author Vitor Mattos <vitor@php.rio>
*
* @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\Libresign\Activity\Provider;
use OCA\Libresign\AppInfo\Application;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\Activity\IProvider;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory;
class SignRequest implements IProvider {
public function __construct(
protected IFactory $languageFactory,
protected IURLGenerator $url,
protected IManager $activityManager,
protected IUserManager $userManager,
) {
}
public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent {
if ($event->getApp() !== Application::APP_ID) {
throw new \InvalidArgumentException('Wrong app');
}
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')));
}
if ($event->getSubject() === 'new_sign_request') {
$l = $this->languageFactory->get(Application::APP_ID, $language);
$parameters = $event->getSubjectParameters();
$subject = $l->t('{from} invited you to sign a file');
$event->setParsedSubject(
str_replace(
'{from}',
$this->userManager->getDisplayName($parameters['from']) ?? $parameters['from'],
$subject
));
}
return $event;
}
protected function getUser(string $uid): array {
return [
'type' => 'user',
'id' => $uid,
'name' => $this->userManager->getDisplayName($uid) ?? $uid,
];
}
}