1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Joas Schilling <[email protected]> |
6
|
|
|
* @author Robin Appelman <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @license GNU AGPL version 3 or any later version |
9
|
|
|
* |
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
13
|
|
|
* License, or (at your option) any later version. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU Affero General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace OCA\Files_Sharing\Activity\Providers; |
26
|
|
|
|
27
|
|
|
use OCP\Activity\IEvent; |
28
|
|
|
use OCP\Activity\IManager; |
29
|
|
|
use OCP\Contacts\IManager as IContactsManager; |
30
|
|
|
use OCP\Federation\ICloudIdManager; |
31
|
|
|
use OCP\IURLGenerator; |
32
|
|
|
use OCP\IUserManager; |
33
|
|
|
use OCP\L10N\IFactory; |
34
|
|
|
|
35
|
|
|
class RemoteShares extends Base { |
36
|
|
|
|
37
|
|
|
const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted'; |
38
|
|
|
const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined'; |
39
|
|
|
const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received'; |
40
|
|
|
const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared'; |
41
|
|
|
|
42
|
|
|
public function __construct(IFactory $languageFactory, |
43
|
|
|
IURLGenerator $url, |
44
|
|
|
IManager $activityManager, |
45
|
|
|
IUserManager $userManager, |
46
|
|
|
IContactsManager $contactsManager, |
47
|
|
|
ICloudIdManager $cloudIdManager |
48
|
|
|
) { |
49
|
|
|
parent::__construct($languageFactory, $url, $activityManager, $userManager, $cloudIdManager, $contactsManager); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param IEvent $event |
54
|
|
|
* @return IEvent |
55
|
|
|
* @throws \InvalidArgumentException |
56
|
|
|
* @since 11.0.0 |
57
|
|
|
*/ |
58
|
|
|
public function parseShortVersion(IEvent $event) { |
59
|
|
|
$parsedParameters = $this->getParsedParameters($event); |
60
|
|
|
|
61
|
|
|
if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { |
62
|
|
|
$subject = $this->l->t('{user} accepted the remote share'); |
63
|
|
|
} else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { |
64
|
|
|
$subject = $this->l->t('{user} declined the remote share'); |
65
|
|
|
} else { |
66
|
|
|
throw new \InvalidArgumentException(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ($this->activityManager->getRequirePNG()) { |
70
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
71
|
|
|
} else { |
72
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
73
|
|
|
} |
74
|
|
|
$this->setSubjects($event, $subject, $parsedParameters); |
75
|
|
|
|
76
|
|
|
return $event; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param IEvent $event |
81
|
|
|
* @return IEvent |
82
|
|
|
* @throws \InvalidArgumentException |
83
|
|
|
* @since 11.0.0 |
84
|
|
|
*/ |
85
|
|
|
public function parseLongVersion(IEvent $event) { |
86
|
|
|
$parsedParameters = $this->getParsedParameters($event); |
87
|
|
|
|
88
|
|
|
if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_RECEIVED) { |
89
|
|
|
$subject = $this->l->t('You received a new remote share {file} from {user}'); |
90
|
|
|
} else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { |
91
|
|
|
$subject = $this->l->t('{user} accepted the remote share of {file}'); |
92
|
|
|
} else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { |
93
|
|
|
$subject = $this->l->t('{user} declined the remote share of {file}'); |
94
|
|
|
} else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_UNSHARED) { |
95
|
|
|
$subject = $this->l->t('{user} unshared {file} from you'); |
96
|
|
|
} else { |
97
|
|
|
throw new \InvalidArgumentException(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if ($this->activityManager->getRequirePNG()) { |
101
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
102
|
|
|
} else { |
103
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
104
|
|
|
} |
105
|
|
|
$this->setSubjects($event, $subject, $parsedParameters); |
106
|
|
|
|
107
|
|
|
return $event; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
protected function getParsedParameters(IEvent $event) { |
111
|
|
|
$subject = $event->getSubject(); |
112
|
|
|
$parameters = $event->getSubjectParameters(); |
113
|
|
|
|
114
|
|
|
switch ($subject) { |
115
|
|
|
case self::SUBJECT_REMOTE_SHARE_RECEIVED: |
116
|
|
|
case self::SUBJECT_REMOTE_SHARE_UNSHARED: |
117
|
|
|
return [ |
118
|
|
|
'file' => [ |
119
|
|
|
'type' => 'pending-federated-share', |
120
|
|
|
'id' => $parameters[1], |
121
|
|
|
'name' => $parameters[1], |
122
|
|
|
], |
123
|
|
|
'user' => $this->getUser($parameters[0]), |
124
|
|
|
]; |
125
|
|
|
case self::SUBJECT_REMOTE_SHARE_ACCEPTED: |
126
|
|
|
case self::SUBJECT_REMOTE_SHARE_DECLINED: |
127
|
|
|
$fileParameter = $parameters[1]; |
128
|
|
|
if (!is_array($fileParameter)) { |
129
|
|
|
$fileParameter = [$event->getObjectId() => $event->getObjectName()]; |
130
|
|
|
} |
131
|
|
|
return [ |
132
|
|
|
'file' => $this->getFile($fileParameter), |
133
|
|
|
'user' => $this->getUser($parameters[0]), |
134
|
|
|
]; |
135
|
|
|
} |
136
|
|
|
throw new \InvalidArgumentException(); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|