1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Joas Schilling <[email protected]> |
4
|
|
|
* @author Thomas Müller <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
7
|
|
|
* @license AGPL-3.0 |
8
|
|
|
* |
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
11
|
|
|
* as published by the Free Software Foundation. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace OCA\Activity; |
24
|
|
|
|
25
|
|
|
use OCP\Activity\IConsumer; |
26
|
|
|
use OCP\Activity\IEvent; |
27
|
|
|
use OCP\Activity\IExtension; |
28
|
|
|
use OCP\Activity\IManager; |
29
|
|
|
use OCP\AppFramework\IAppContainer; |
30
|
|
|
use OCP\L10N\IFactory; |
31
|
|
|
|
32
|
|
|
class Consumer implements IConsumer { |
33
|
|
|
|
34
|
|
|
/** @var Data */ |
35
|
|
|
protected $data; |
36
|
|
|
|
37
|
|
|
/** @var UserSettings */ |
38
|
|
|
protected $userSettings; |
39
|
|
|
|
40
|
|
|
/** @var IFactory */ |
41
|
|
|
protected $l10nFactory; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Constructor |
45
|
|
|
* |
46
|
|
|
* @param Data $data |
47
|
|
|
* @param UserSettings $userSettings |
48
|
|
|
* @param IFactory $l10nFactory |
49
|
|
|
*/ |
50
|
22 |
|
public function __construct(Data $data, UserSettings $userSettings, IFactory $l10nFactory) { |
51
|
22 |
|
$this->data = $data; |
52
|
22 |
|
$this->userSettings = $userSettings; |
53
|
22 |
|
$this->l10nFactory = $l10nFactory; |
54
|
22 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Send an event to the notifications of a user |
58
|
|
|
* |
59
|
|
|
* @param IEvent $event |
60
|
|
|
* @return null |
61
|
|
|
*/ |
62
|
20 |
|
public function receive(IEvent $event) { |
63
|
20 |
|
$selfAction = $event->getAffectedUser() === $event->getAuthor(); |
64
|
20 |
|
$streamSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'stream', $event->getType()); |
65
|
20 |
|
$emailSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'email', $event->getType()); |
66
|
20 |
|
$emailSetting = ($emailSetting) ? $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'batchtime') : false; |
67
|
|
|
|
68
|
20 |
|
$types = $this->data->getNotificationTypes($this->l10nFactory->get('activity')); |
69
|
20 |
|
$typeData = $types[$event->getType()]; |
70
|
|
|
|
71
|
|
|
// User is not the author or wants to see their own actions |
72
|
20 |
|
$createStream = !$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'self'); |
73
|
|
|
// User can not control the setting |
74
|
20 |
|
$createStream = $createStream || \is_array($typeData) && isset($typeData['methods']) && !\in_array(IExtension::METHOD_STREAM, $typeData['methods']); |
75
|
|
|
|
76
|
|
|
// Add activity to stream |
77
|
20 |
|
if ($streamSetting && $createStream) { |
78
|
14 |
|
$this->data->send($event); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
// User is not the author or wants to see their own actions |
82
|
20 |
|
$createEmail = !$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'selfemail'); |
83
|
|
|
// User can not control the setting |
84
|
20 |
|
$createEmail = $createEmail || \is_array($typeData) && isset($typeData['methods']) && !\in_array(IExtension::METHOD_MAIL, $typeData['methods']); |
85
|
|
|
|
86
|
|
|
// Add activity to mail queue |
87
|
20 |
|
if ($emailSetting && $createEmail) { |
88
|
14 |
|
$latestSend = $event->getTimestamp() + $emailSetting; |
89
|
14 |
|
$this->data->storeMail($event, $latestSend); |
90
|
|
|
} |
91
|
20 |
|
} |
92
|
|
|
} |
93
|
|
|
|