Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/nextcloud_announcements.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2019-09-11 14:29:55 +0300
committerGitHub <noreply@github.com>2019-09-11 14:29:55 +0300
commit78eef83eb2e9f3cf16062ec168a030be3c5e0c15 (patch)
treef5bfb593fb10846959262fdfd248bc4641cd0572
parentc5bb4d116373bd6f7f6540bb930799a01fa644fb (diff)
parentc4587838ef4578db30f126a33c0081562ad03b06 (diff)
Merge pull request #52 from nextcloud/backport/50/stable17v17.0.0rc1
[stable17] Bugfix/noid/improve the notifications
-rw-r--r--lib/Notification/Notifier.php48
1 files changed, 38 insertions, 10 deletions
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index 835b85a..4a1c1f8 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -24,8 +24,11 @@
namespace OCA\NextcloudAnnouncements\Notification;
+use OCP\IConfig;
+use OCP\IGroupManager;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
+use OCP\Notification\IAction;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
@@ -35,22 +38,25 @@ class Notifier implements INotifier {
/** @var string */
protected $appName;
-
/** @var IFactory */
protected $l10nFactory;
-
/** @var IURLGenerator */
protected $url;
-
- /**
- * @param string $appName
- * @param IFactory $l10nFactory
- * @param IURLGenerator $url
- */
- public function __construct($appName, IFactory $l10nFactory, IURLGenerator $url) {
+ /** @var IConfig */
+ protected $config;
+ /** @var IGroupManager */
+ protected $groupManager;
+
+ public function __construct(string $appName,
+ IFactory $l10nFactory,
+ IURLGenerator $url,
+ IConfig $config,
+ IGroupManager $groupManager) {
$this->appName = $appName;
$this->l10nFactory = $l10nFactory;
$this->url = $url;
+ $this->config = $config;
+ $this->groupManager = $groupManager;
}
/**
@@ -91,10 +97,32 @@ class Notifier implements INotifier {
switch ($notification->getSubject()) {
case self::SUBJECT:
$parameters = $notification->getSubjectParameters();
+ $message = $parameters[0];
$notification->setParsedSubject($l->t('Nextcloud announcement'))
- ->setParsedMessage($parameters[0])
->setIcon($this->url->getAbsoluteURL($this->url->imagePath($this->appName, 'app-dark.svg')));
+ $action = $notification->createAction();
+ $action->setParsedLabel($l->t('Read more'))
+ ->setLink($notification->getLink(), IAction::TYPE_WEB)
+ ->setPrimary(true);
+ $notification->addParsedAction($action);
+
+ $isAdmin = $this->groupManager->isAdmin($notification->getUser());
+ if ($isAdmin) {
+ $groups = $this->config->getAppValue($this->appName, 'notification_groups', '');
+ if ($groups === '') {
+ $action = $notification->createAction();
+ $action->setParsedLabel($l->t('Disable announcements'))
+ ->setLink($this->url->linkToOCSRouteAbsolute('provisioning_api.AppsController.disable', ['app' => 'nextcloud_announcements']), IAction::TYPE_DELETE)
+ ->setPrimary(false);
+ $notification->addParsedAction($action);
+
+ $message .= "\n\n" . $l->t('(These announcements are only shown to administrators)');
+ }
+ }
+
+ $notification->setParsedMessage($message);
+
return $notification;
default: