dc299709f7
OCS endpoint for support.f7cloud.ru, notification notifier, and ?ticket= URL opening in the client UI.
75 lines
2.0 KiB
PHP
75 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\F7Support\Notification;
|
|
|
|
use OCP\IURLGenerator;
|
|
use OCP\L10N\IFactory;
|
|
use OCP\Notification\IManager as INotificationManager;
|
|
use OCP\Notification\INotification;
|
|
use OCP\Notification\INotifier;
|
|
use OCP\Notification\UnknownNotificationException;
|
|
|
|
class Notifier implements INotifier {
|
|
public function __construct(
|
|
private IFactory $l10nFactory,
|
|
private IURLGenerator $urlGenerator,
|
|
private INotificationManager $notificationManager,
|
|
) {
|
|
}
|
|
|
|
public function getID(): string {
|
|
return 'f7support';
|
|
}
|
|
|
|
public function getName(): string {
|
|
return $this->l10nFactory->get('f7support')->t('Support');
|
|
}
|
|
|
|
public function prepare(INotification $notification, string $languageCode): INotification {
|
|
if ($notification->getApp() !== 'f7support') {
|
|
throw new UnknownNotificationException();
|
|
}
|
|
|
|
if ($notification->getSubject() !== 'support_reply') {
|
|
throw new UnknownNotificationException();
|
|
}
|
|
|
|
$params = $notification->getSubjectParameters();
|
|
$ticketNumber = (string)($params['ticketNumber'] ?? '');
|
|
$ticketSubject = trim((string)($params['ticketSubject'] ?? ''));
|
|
$preview = trim((string)($params['preview'] ?? ''));
|
|
|
|
if ($preview === '') {
|
|
$msgParams = $notification->getMessageParameters();
|
|
$preview = trim((string)($msgParams['preview'] ?? ''));
|
|
}
|
|
|
|
if ($ticketSubject !== '') {
|
|
$title = 'Заявка ' . $ticketNumber . ': ' . $ticketSubject;
|
|
} else {
|
|
$title = 'Заявка ' . $ticketNumber;
|
|
}
|
|
|
|
if ($preview === '') {
|
|
$preview = 'Новый ответ от поддержки';
|
|
}
|
|
|
|
$icon = $this->urlGenerator->getAbsoluteURL(
|
|
$this->urlGenerator->imagePath('f7support', 'app.svg')
|
|
);
|
|
|
|
if ($this->notificationManager->isPreparingPushNotification()) {
|
|
$notification->setParsedSubject($title . "\n" . $preview);
|
|
} else {
|
|
$notification->setParsedSubject($title);
|
|
$notification->setParsedMessage($preview);
|
|
}
|
|
|
|
$notification->setIcon($icon);
|
|
|
|
return $notification;
|
|
}
|
|
}
|