1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Joas Schilling <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
6
|
|
|
* @license AGPL-3.0 |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace OCA\Notifications; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
use OCA\Notifications\Exceptions\NotificationNotFoundException; |
26
|
|
|
use OCP\Notification\IApp; |
27
|
|
|
use OCP\Notification\INotification; |
28
|
|
|
|
29
|
|
|
class App implements IApp { |
30
|
|
|
/** @var Handler */ |
31
|
|
|
protected $handler; |
32
|
|
|
/** @var Push */ |
33
|
|
|
protected $push; |
34
|
|
|
|
35
|
8 |
|
public function __construct(Handler $handler, Push $push) { |
36
|
8 |
|
$this->handler = $handler; |
37
|
8 |
|
$this->push = $push; |
38
|
8 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param INotification $notification |
42
|
|
|
* @throws \InvalidArgumentException When the notification is not valid |
43
|
|
|
* @since 8.2.0 |
44
|
|
|
*/ |
45
|
2 |
|
public function notify(INotification $notification) { |
46
|
2 |
|
$notificationId = $this->handler->add($notification); |
47
|
|
|
|
48
|
|
|
try { |
49
|
2 |
|
$notificationToPush = $this->handler->getById($notificationId, $notification->getUser()); |
50
|
2 |
|
$this->push->pushToDevice($notificationId, $notificationToPush); |
51
|
|
|
} catch (NotificationNotFoundException $e) { |
52
|
|
|
throw new \InvalidArgumentException('Error while preparing push notification'); |
53
|
|
|
} |
54
|
2 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param INotification $notification |
58
|
|
|
* @return int |
59
|
|
|
* @since 8.2.0 |
60
|
|
|
*/ |
61
|
2 |
|
public function getCount(INotification $notification): int { |
62
|
2 |
|
return $this->handler->count($notification); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param INotification $notification |
67
|
|
|
* @since 8.2.0 |
68
|
|
|
*/ |
69
|
1 |
|
public function markProcessed(INotification $notification) { |
70
|
1 |
|
$this->handler->delete($notification); |
71
|
1 |
|
} |
72
|
|
|
} |
73
|
|
|
|