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