|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2017 Joas Schilling <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Joas Schilling <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\Notifications\Notifier; |
|
25
|
|
|
|
|
26
|
|
|
use OCP\IURLGenerator; |
|
27
|
|
|
use OCP\L10N\IFactory; |
|
28
|
|
|
use OCP\Notification\INotification; |
|
29
|
|
|
use OCP\Notification\INotifier; |
|
30
|
|
|
|
|
31
|
|
|
class AdminNotifications implements INotifier { |
|
32
|
|
|
|
|
33
|
|
|
/** @var IFactory */ |
|
34
|
|
|
protected $l10nFactory; |
|
35
|
|
|
|
|
36
|
|
|
/** @var IURLGenerator */ |
|
37
|
|
|
protected $urlGenerator; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param IFactory $l10nFactory |
|
41
|
|
|
* @param IURLGenerator $urlGenerator |
|
42
|
|
|
*/ |
|
43
|
3 |
|
public function __construct(IFactory $l10nFactory, IURLGenerator $urlGenerator) { |
|
44
|
3 |
|
$this->l10nFactory = $l10nFactory; |
|
45
|
3 |
|
$this->urlGenerator = $urlGenerator; |
|
46
|
3 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param INotification $notification |
|
50
|
|
|
* @param string $languageCode The code of the language that should be used to prepare the notification |
|
51
|
|
|
* @return INotification |
|
52
|
|
|
* @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
53
|
|
|
*/ |
|
54
|
3 |
|
public function prepare(INotification $notification, $languageCode): INotification { |
|
55
|
3 |
|
if ($notification->getApp() !== 'admin_notifications') { |
|
56
|
1 |
|
throw new \InvalidArgumentException('Unknown app'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
2 |
|
switch ($notification->getSubject()) { |
|
60
|
|
|
// Deal with known subjects |
|
61
|
2 |
|
case 'cli': |
|
62
|
2 |
|
case 'ocs': |
|
63
|
1 |
|
$subjectParams = $notification->getSubjectParameters(); |
|
64
|
1 |
|
$notification->setParsedSubject($subjectParams[0]); |
|
65
|
1 |
|
$messageParams = $notification->getMessageParameters(); |
|
66
|
1 |
|
if (isset($messageParams[0]) && $messageParams[0] !== '') { |
|
67
|
1 |
|
$notification->setParsedMessage($messageParams[0]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
$notification->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('notifications', 'notifications-dark.svg'))); |
|
71
|
1 |
|
return $notification; |
|
72
|
|
|
|
|
73
|
|
|
default: |
|
74
|
1 |
|
throw new \InvalidArgumentException('Unknown subject'); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|