@@ -33,12 +33,12 @@ |
||
33 | 33 | * @since 8.0.0 |
34 | 34 | */ |
35 | 35 | interface IExtension { |
36 | - const METHOD_STREAM = 'stream'; |
|
37 | - const METHOD_MAIL = 'email'; |
|
36 | + const METHOD_STREAM = 'stream'; |
|
37 | + const METHOD_MAIL = 'email'; |
|
38 | 38 | |
39 | - const PRIORITY_VERYLOW = 10; |
|
40 | - const PRIORITY_LOW = 20; |
|
41 | - const PRIORITY_MEDIUM = 30; |
|
42 | - const PRIORITY_HIGH = 40; |
|
43 | - const PRIORITY_VERYHIGH = 50; |
|
39 | + const PRIORITY_VERYLOW = 10; |
|
40 | + const PRIORITY_LOW = 20; |
|
41 | + const PRIORITY_MEDIUM = 30; |
|
42 | + const PRIORITY_HIGH = 40; |
|
43 | + const PRIORITY_VERYHIGH = 50; |
|
44 | 44 | } |
@@ -36,9 +36,9 @@ |
||
36 | 36 | const METHOD_STREAM = 'stream'; |
37 | 37 | const METHOD_MAIL = 'email'; |
38 | 38 | |
39 | - const PRIORITY_VERYLOW = 10; |
|
40 | - const PRIORITY_LOW = 20; |
|
41 | - const PRIORITY_MEDIUM = 30; |
|
42 | - const PRIORITY_HIGH = 40; |
|
43 | - const PRIORITY_VERYHIGH = 50; |
|
39 | + const PRIORITY_VERYLOW = 10; |
|
40 | + const PRIORITY_LOW = 20; |
|
41 | + const PRIORITY_MEDIUM = 30; |
|
42 | + const PRIORITY_HIGH = 40; |
|
43 | + const PRIORITY_VERYHIGH = 50; |
|
44 | 44 | } |
@@ -34,141 +34,141 @@ |
||
34 | 34 | * @since 6.0.0 |
35 | 35 | */ |
36 | 36 | interface IManager { |
37 | - /** |
|
38 | - * Generates a new IEvent object |
|
39 | - * |
|
40 | - * Make sure to call at least the following methods before sending it to the |
|
41 | - * app with via the publish() method: |
|
42 | - * - setApp() |
|
43 | - * - setType() |
|
44 | - * - setAffectedUser() |
|
45 | - * - setSubject() |
|
46 | - * |
|
47 | - * @return IEvent |
|
48 | - * @since 8.2.0 |
|
49 | - */ |
|
50 | - public function generateEvent(): IEvent; |
|
51 | - |
|
52 | - /** |
|
53 | - * Publish an event to the activity consumers |
|
54 | - * |
|
55 | - * Make sure to call at least the following methods before sending an Event: |
|
56 | - * - setApp() |
|
57 | - * - setType() |
|
58 | - * - setAffectedUser() |
|
59 | - * - setSubject() |
|
60 | - * |
|
61 | - * @param IEvent $event |
|
62 | - * @throws \BadMethodCallException if required values have not been set |
|
63 | - * @since 8.2.0 |
|
64 | - */ |
|
65 | - public function publish(IEvent $event): void; |
|
66 | - |
|
67 | - /** |
|
68 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
69 | - * activity consumers are actually requested |
|
70 | - * |
|
71 | - * $callable has to return an instance of \OCP\Activity\IConsumer |
|
72 | - * |
|
73 | - * @param \Closure $callable |
|
74 | - * @since 6.0.0 |
|
75 | - */ |
|
76 | - public function registerConsumer(\Closure $callable): void; |
|
77 | - |
|
78 | - /** |
|
79 | - * @param string $filter Class must implement OCA\Activity\IFilter |
|
80 | - * @since 11.0.0 |
|
81 | - */ |
|
82 | - public function registerFilter(string $filter): void; |
|
83 | - |
|
84 | - /** |
|
85 | - * @return IFilter[] |
|
86 | - * @since 11.0.0 |
|
87 | - */ |
|
88 | - public function getFilters(): array; |
|
89 | - |
|
90 | - /** |
|
91 | - * @param string $id |
|
92 | - * @return IFilter |
|
93 | - * @throws \InvalidArgumentException when the filter was not found |
|
94 | - * @since 11.0.0 |
|
95 | - */ |
|
96 | - public function getFilterById(string $id): IFilter; |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $setting Class must implement OCA\Activity\ISetting |
|
100 | - * @since 11.0.0 |
|
101 | - */ |
|
102 | - public function registerSetting(string $setting): void; |
|
103 | - |
|
104 | - /** |
|
105 | - * @return ISetting[] |
|
106 | - * @since 11.0.0 |
|
107 | - */ |
|
108 | - public function getSettings(): array; |
|
109 | - |
|
110 | - /** |
|
111 | - * @param string $provider Class must implement OCA\Activity\IProvider |
|
112 | - * @since 11.0.0 |
|
113 | - */ |
|
114 | - public function registerProvider(string $provider): void; |
|
115 | - |
|
116 | - /** |
|
117 | - * @return IProvider[] |
|
118 | - * @since 11.0.0 |
|
119 | - */ |
|
120 | - public function getProviders(): array; |
|
121 | - |
|
122 | - /** |
|
123 | - * @param string $id |
|
124 | - * @return ISetting |
|
125 | - * @throws \InvalidArgumentException when the setting was not found |
|
126 | - * @since 11.0.0 |
|
127 | - */ |
|
128 | - public function getSettingById(string $id): ISetting; |
|
129 | - |
|
130 | - /** |
|
131 | - * @param string $type |
|
132 | - * @param int $id |
|
133 | - * @since 8.2.0 |
|
134 | - */ |
|
135 | - public function setFormattingObject(string $type, int $id): void; |
|
136 | - |
|
137 | - /** |
|
138 | - * @return bool |
|
139 | - * @since 8.2.0 |
|
140 | - */ |
|
141 | - public function isFormattingFilteredObject(): bool; |
|
142 | - |
|
143 | - /** |
|
144 | - * @param bool $status Set to true, when parsing events should not use SVG icons |
|
145 | - * @since 12.0.1 |
|
146 | - */ |
|
147 | - public function setRequirePNG(bool $status): void; |
|
148 | - |
|
149 | - /** |
|
150 | - * @return bool |
|
151 | - * @since 12.0.1 |
|
152 | - */ |
|
153 | - public function getRequirePNG(): bool; |
|
154 | - |
|
155 | - /** |
|
156 | - * Set the user we need to use |
|
157 | - * |
|
158 | - * @param string|null $currentUserId |
|
159 | - * @throws \UnexpectedValueException If the user is invalid |
|
160 | - * @since 9.0.1 |
|
161 | - */ |
|
162 | - public function setCurrentUserId(string $currentUserId = null): void; |
|
163 | - |
|
164 | - /** |
|
165 | - * Get the user we need to use |
|
166 | - * |
|
167 | - * Either the user is logged in, or we try to get it from the token |
|
168 | - * |
|
169 | - * @return string |
|
170 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
171 | - * @since 8.1.0 |
|
172 | - */ |
|
173 | - public function getCurrentUserId(): string; |
|
37 | + /** |
|
38 | + * Generates a new IEvent object |
|
39 | + * |
|
40 | + * Make sure to call at least the following methods before sending it to the |
|
41 | + * app with via the publish() method: |
|
42 | + * - setApp() |
|
43 | + * - setType() |
|
44 | + * - setAffectedUser() |
|
45 | + * - setSubject() |
|
46 | + * |
|
47 | + * @return IEvent |
|
48 | + * @since 8.2.0 |
|
49 | + */ |
|
50 | + public function generateEvent(): IEvent; |
|
51 | + |
|
52 | + /** |
|
53 | + * Publish an event to the activity consumers |
|
54 | + * |
|
55 | + * Make sure to call at least the following methods before sending an Event: |
|
56 | + * - setApp() |
|
57 | + * - setType() |
|
58 | + * - setAffectedUser() |
|
59 | + * - setSubject() |
|
60 | + * |
|
61 | + * @param IEvent $event |
|
62 | + * @throws \BadMethodCallException if required values have not been set |
|
63 | + * @since 8.2.0 |
|
64 | + */ |
|
65 | + public function publish(IEvent $event): void; |
|
66 | + |
|
67 | + /** |
|
68 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
69 | + * activity consumers are actually requested |
|
70 | + * |
|
71 | + * $callable has to return an instance of \OCP\Activity\IConsumer |
|
72 | + * |
|
73 | + * @param \Closure $callable |
|
74 | + * @since 6.0.0 |
|
75 | + */ |
|
76 | + public function registerConsumer(\Closure $callable): void; |
|
77 | + |
|
78 | + /** |
|
79 | + * @param string $filter Class must implement OCA\Activity\IFilter |
|
80 | + * @since 11.0.0 |
|
81 | + */ |
|
82 | + public function registerFilter(string $filter): void; |
|
83 | + |
|
84 | + /** |
|
85 | + * @return IFilter[] |
|
86 | + * @since 11.0.0 |
|
87 | + */ |
|
88 | + public function getFilters(): array; |
|
89 | + |
|
90 | + /** |
|
91 | + * @param string $id |
|
92 | + * @return IFilter |
|
93 | + * @throws \InvalidArgumentException when the filter was not found |
|
94 | + * @since 11.0.0 |
|
95 | + */ |
|
96 | + public function getFilterById(string $id): IFilter; |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $setting Class must implement OCA\Activity\ISetting |
|
100 | + * @since 11.0.0 |
|
101 | + */ |
|
102 | + public function registerSetting(string $setting): void; |
|
103 | + |
|
104 | + /** |
|
105 | + * @return ISetting[] |
|
106 | + * @since 11.0.0 |
|
107 | + */ |
|
108 | + public function getSettings(): array; |
|
109 | + |
|
110 | + /** |
|
111 | + * @param string $provider Class must implement OCA\Activity\IProvider |
|
112 | + * @since 11.0.0 |
|
113 | + */ |
|
114 | + public function registerProvider(string $provider): void; |
|
115 | + |
|
116 | + /** |
|
117 | + * @return IProvider[] |
|
118 | + * @since 11.0.0 |
|
119 | + */ |
|
120 | + public function getProviders(): array; |
|
121 | + |
|
122 | + /** |
|
123 | + * @param string $id |
|
124 | + * @return ISetting |
|
125 | + * @throws \InvalidArgumentException when the setting was not found |
|
126 | + * @since 11.0.0 |
|
127 | + */ |
|
128 | + public function getSettingById(string $id): ISetting; |
|
129 | + |
|
130 | + /** |
|
131 | + * @param string $type |
|
132 | + * @param int $id |
|
133 | + * @since 8.2.0 |
|
134 | + */ |
|
135 | + public function setFormattingObject(string $type, int $id): void; |
|
136 | + |
|
137 | + /** |
|
138 | + * @return bool |
|
139 | + * @since 8.2.0 |
|
140 | + */ |
|
141 | + public function isFormattingFilteredObject(): bool; |
|
142 | + |
|
143 | + /** |
|
144 | + * @param bool $status Set to true, when parsing events should not use SVG icons |
|
145 | + * @since 12.0.1 |
|
146 | + */ |
|
147 | + public function setRequirePNG(bool $status): void; |
|
148 | + |
|
149 | + /** |
|
150 | + * @return bool |
|
151 | + * @since 12.0.1 |
|
152 | + */ |
|
153 | + public function getRequirePNG(): bool; |
|
154 | + |
|
155 | + /** |
|
156 | + * Set the user we need to use |
|
157 | + * |
|
158 | + * @param string|null $currentUserId |
|
159 | + * @throws \UnexpectedValueException If the user is invalid |
|
160 | + * @since 9.0.1 |
|
161 | + */ |
|
162 | + public function setCurrentUserId(string $currentUserId = null): void; |
|
163 | + |
|
164 | + /** |
|
165 | + * Get the user we need to use |
|
166 | + * |
|
167 | + * Either the user is logged in, or we try to get it from the token |
|
168 | + * |
|
169 | + * @return string |
|
170 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
171 | + * @since 8.1.0 |
|
172 | + */ |
|
173 | + public function getCurrentUserId(): string; |
|
174 | 174 | } |
@@ -39,349 +39,349 @@ |
||
39 | 39 | use OCP\RichObjectStrings\IValidator; |
40 | 40 | |
41 | 41 | class Manager implements IManager { |
42 | - /** @var IRequest */ |
|
43 | - protected $request; |
|
44 | - |
|
45 | - /** @var IUserSession */ |
|
46 | - protected $session; |
|
47 | - |
|
48 | - /** @var IConfig */ |
|
49 | - protected $config; |
|
50 | - |
|
51 | - /** @var IValidator */ |
|
52 | - protected $validator; |
|
53 | - |
|
54 | - /** @var string */ |
|
55 | - protected $formattingObjectType; |
|
56 | - |
|
57 | - /** @var int */ |
|
58 | - protected $formattingObjectId; |
|
59 | - |
|
60 | - /** @var bool */ |
|
61 | - protected $requirePNG; |
|
62 | - |
|
63 | - /** @var string */ |
|
64 | - protected $currentUserId; |
|
65 | - |
|
66 | - public function __construct(IRequest $request, |
|
67 | - IUserSession $session, |
|
68 | - IConfig $config, |
|
69 | - IValidator $validator) { |
|
70 | - $this->request = $request; |
|
71 | - $this->session = $session; |
|
72 | - $this->config = $config; |
|
73 | - $this->validator = $validator; |
|
74 | - } |
|
75 | - |
|
76 | - /** @var \Closure[] */ |
|
77 | - private $consumersClosures = array(); |
|
78 | - |
|
79 | - /** @var IConsumer[] */ |
|
80 | - private $consumers = array(); |
|
81 | - |
|
82 | - /** |
|
83 | - * @return \OCP\Activity\IConsumer[] |
|
84 | - */ |
|
85 | - protected function getConsumers(): array { |
|
86 | - if (!empty($this->consumers)) { |
|
87 | - return $this->consumers; |
|
88 | - } |
|
89 | - |
|
90 | - $this->consumers = []; |
|
91 | - foreach($this->consumersClosures as $consumer) { |
|
92 | - $c = $consumer(); |
|
93 | - if ($c instanceof IConsumer) { |
|
94 | - $this->consumers[] = $c; |
|
95 | - } else { |
|
96 | - throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - return $this->consumers; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Generates a new IEvent object |
|
105 | - * |
|
106 | - * Make sure to call at least the following methods before sending it to the |
|
107 | - * app with via the publish() method: |
|
108 | - * - setApp() |
|
109 | - * - setType() |
|
110 | - * - setAffectedUser() |
|
111 | - * - setSubject() |
|
112 | - * |
|
113 | - * @return IEvent |
|
114 | - */ |
|
115 | - public function generateEvent(): IEvent { |
|
116 | - return new Event($this->validator); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Publish an event to the activity consumers |
|
121 | - * |
|
122 | - * Make sure to call at least the following methods before sending an Event: |
|
123 | - * - setApp() |
|
124 | - * - setType() |
|
125 | - * - setAffectedUser() |
|
126 | - * - setSubject() |
|
127 | - * |
|
128 | - * @param IEvent $event |
|
129 | - * @throws \BadMethodCallException if required values have not been set |
|
130 | - */ |
|
131 | - public function publish(IEvent $event): void { |
|
132 | - if ($event->getAuthor() === '') { |
|
133 | - if ($this->session->getUser() instanceof IUser) { |
|
134 | - $event->setAuthor($this->session->getUser()->getUID()); |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - if (!$event->getTimestamp()) { |
|
139 | - $event->setTimestamp(time()); |
|
140 | - } |
|
141 | - |
|
142 | - if (!$event->isValid()) { |
|
143 | - throw new \BadMethodCallException('The given event is invalid'); |
|
144 | - } |
|
145 | - |
|
146 | - foreach ($this->getConsumers() as $c) { |
|
147 | - $c->receive($event); |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
153 | - * activity consumers are actually requested |
|
154 | - * |
|
155 | - * $callable has to return an instance of OCA\Activity\IConsumer |
|
156 | - * |
|
157 | - * @param \Closure $callable |
|
158 | - */ |
|
159 | - public function registerConsumer(\Closure $callable): void { |
|
160 | - $this->consumersClosures[] = $callable; |
|
161 | - $this->consumers = []; |
|
162 | - } |
|
163 | - |
|
164 | - /** @var string[] */ |
|
165 | - protected $filterClasses = []; |
|
166 | - |
|
167 | - /** @var IFilter[] */ |
|
168 | - protected $filters = []; |
|
169 | - |
|
170 | - /** |
|
171 | - * @param string $filter Class must implement OCA\Activity\IFilter |
|
172 | - * @return void |
|
173 | - */ |
|
174 | - public function registerFilter(string $filter): void { |
|
175 | - $this->filterClasses[$filter] = false; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @return IFilter[] |
|
180 | - * @throws \InvalidArgumentException |
|
181 | - */ |
|
182 | - public function getFilters(): array { |
|
183 | - foreach ($this->filterClasses as $class => $false) { |
|
184 | - /** @var IFilter $filter */ |
|
185 | - $filter = \OC::$server->query($class); |
|
186 | - |
|
187 | - if (!$filter instanceof IFilter) { |
|
188 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
189 | - } |
|
190 | - |
|
191 | - $this->filters[$filter->getIdentifier()] = $filter; |
|
192 | - |
|
193 | - unset($this->filterClasses[$class]); |
|
194 | - } |
|
195 | - return $this->filters; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * @param string $id |
|
200 | - * @return IFilter |
|
201 | - * @throws \InvalidArgumentException when the filter was not found |
|
202 | - * @since 11.0.0 |
|
203 | - */ |
|
204 | - public function getFilterById(string $id): IFilter { |
|
205 | - $filters = $this->getFilters(); |
|
206 | - |
|
207 | - if (isset($filters[$id])) { |
|
208 | - return $filters[$id]; |
|
209 | - } |
|
210 | - |
|
211 | - throw new \InvalidArgumentException('Requested filter does not exist'); |
|
212 | - } |
|
213 | - |
|
214 | - /** @var string[] */ |
|
215 | - protected $providerClasses = []; |
|
216 | - |
|
217 | - /** @var IProvider[] */ |
|
218 | - protected $providers = []; |
|
219 | - |
|
220 | - /** |
|
221 | - * @param string $provider Class must implement OCA\Activity\IProvider |
|
222 | - * @return void |
|
223 | - */ |
|
224 | - public function registerProvider(string $provider): void { |
|
225 | - $this->providerClasses[$provider] = false; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @return IProvider[] |
|
230 | - * @throws \InvalidArgumentException |
|
231 | - */ |
|
232 | - public function getProviders(): array { |
|
233 | - foreach ($this->providerClasses as $class => $false) { |
|
234 | - /** @var IProvider $provider */ |
|
235 | - $provider = \OC::$server->query($class); |
|
236 | - |
|
237 | - if (!$provider instanceof IProvider) { |
|
238 | - throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
239 | - } |
|
240 | - |
|
241 | - $this->providers[] = $provider; |
|
242 | - |
|
243 | - unset($this->providerClasses[$class]); |
|
244 | - } |
|
245 | - return $this->providers; |
|
246 | - } |
|
247 | - |
|
248 | - /** @var string[] */ |
|
249 | - protected $settingsClasses = []; |
|
250 | - |
|
251 | - /** @var ISetting[] */ |
|
252 | - protected $settings = []; |
|
253 | - |
|
254 | - /** |
|
255 | - * @param string $setting Class must implement OCA\Activity\ISetting |
|
256 | - * @return void |
|
257 | - */ |
|
258 | - public function registerSetting(string $setting): void { |
|
259 | - $this->settingsClasses[$setting] = false; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * @return ISetting[] |
|
264 | - * @throws \InvalidArgumentException |
|
265 | - */ |
|
266 | - public function getSettings(): array { |
|
267 | - foreach ($this->settingsClasses as $class => $false) { |
|
268 | - /** @var ISetting $setting */ |
|
269 | - $setting = \OC::$server->query($class); |
|
270 | - |
|
271 | - if (!$setting instanceof ISetting) { |
|
272 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
273 | - } |
|
274 | - |
|
275 | - $this->settings[$setting->getIdentifier()] = $setting; |
|
276 | - |
|
277 | - unset($this->settingsClasses[$class]); |
|
278 | - } |
|
279 | - return $this->settings; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * @param string $id |
|
284 | - * @return ISetting |
|
285 | - * @throws \InvalidArgumentException when the setting was not found |
|
286 | - * @since 11.0.0 |
|
287 | - */ |
|
288 | - public function getSettingById(string $id): ISetting { |
|
289 | - $settings = $this->getSettings(); |
|
290 | - |
|
291 | - if (isset($settings[$id])) { |
|
292 | - return $settings[$id]; |
|
293 | - } |
|
294 | - |
|
295 | - throw new \InvalidArgumentException('Requested setting does not exist'); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @param string $type |
|
301 | - * @param int $id |
|
302 | - */ |
|
303 | - public function setFormattingObject(string $type, int $id): void { |
|
304 | - $this->formattingObjectType = $type; |
|
305 | - $this->formattingObjectId = $id; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * @return bool |
|
310 | - */ |
|
311 | - public function isFormattingFilteredObject(): bool { |
|
312 | - return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
313 | - && $this->formattingObjectType === $this->request->getParam('object_type') |
|
314 | - && $this->formattingObjectId === (int) $this->request->getParam('object_id'); |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * @param bool $status Set to true, when parsing events should not use SVG icons |
|
319 | - */ |
|
320 | - public function setRequirePNG(bool $status): void { |
|
321 | - $this->requirePNG = $status; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * @return bool |
|
326 | - */ |
|
327 | - public function getRequirePNG(): bool { |
|
328 | - return $this->requirePNG; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Set the user we need to use |
|
333 | - * |
|
334 | - * @param string|null $currentUserId |
|
335 | - * @throws \UnexpectedValueException If the user is invalid |
|
336 | - */ |
|
337 | - public function setCurrentUserId(string $currentUserId = null): void { |
|
338 | - if (!is_string($currentUserId) && $currentUserId !== null) { |
|
339 | - throw new \UnexpectedValueException('The given current user is invalid'); |
|
340 | - } |
|
341 | - $this->currentUserId = $currentUserId; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Get the user we need to use |
|
346 | - * |
|
347 | - * Either the user is logged in, or we try to get it from the token |
|
348 | - * |
|
349 | - * @return string |
|
350 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
351 | - */ |
|
352 | - public function getCurrentUserId(): string { |
|
353 | - if ($this->currentUserId !== null) { |
|
354 | - return $this->currentUserId; |
|
355 | - } |
|
356 | - |
|
357 | - if (!$this->session->isLoggedIn()) { |
|
358 | - return $this->getUserFromToken(); |
|
359 | - } |
|
360 | - |
|
361 | - return $this->session->getUser()->getUID(); |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * Get the user for the token |
|
366 | - * |
|
367 | - * @return string |
|
368 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
369 | - */ |
|
370 | - protected function getUserFromToken(): string { |
|
371 | - $token = (string) $this->request->getParam('token', ''); |
|
372 | - if (strlen($token) !== 30) { |
|
373 | - throw new \UnexpectedValueException('The token is invalid'); |
|
374 | - } |
|
375 | - |
|
376 | - $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
377 | - |
|
378 | - if (count($users) !== 1) { |
|
379 | - // No unique user found |
|
380 | - throw new \UnexpectedValueException('The token is invalid'); |
|
381 | - } |
|
382 | - |
|
383 | - // Token found login as that user |
|
384 | - return array_shift($users); |
|
385 | - } |
|
42 | + /** @var IRequest */ |
|
43 | + protected $request; |
|
44 | + |
|
45 | + /** @var IUserSession */ |
|
46 | + protected $session; |
|
47 | + |
|
48 | + /** @var IConfig */ |
|
49 | + protected $config; |
|
50 | + |
|
51 | + /** @var IValidator */ |
|
52 | + protected $validator; |
|
53 | + |
|
54 | + /** @var string */ |
|
55 | + protected $formattingObjectType; |
|
56 | + |
|
57 | + /** @var int */ |
|
58 | + protected $formattingObjectId; |
|
59 | + |
|
60 | + /** @var bool */ |
|
61 | + protected $requirePNG; |
|
62 | + |
|
63 | + /** @var string */ |
|
64 | + protected $currentUserId; |
|
65 | + |
|
66 | + public function __construct(IRequest $request, |
|
67 | + IUserSession $session, |
|
68 | + IConfig $config, |
|
69 | + IValidator $validator) { |
|
70 | + $this->request = $request; |
|
71 | + $this->session = $session; |
|
72 | + $this->config = $config; |
|
73 | + $this->validator = $validator; |
|
74 | + } |
|
75 | + |
|
76 | + /** @var \Closure[] */ |
|
77 | + private $consumersClosures = array(); |
|
78 | + |
|
79 | + /** @var IConsumer[] */ |
|
80 | + private $consumers = array(); |
|
81 | + |
|
82 | + /** |
|
83 | + * @return \OCP\Activity\IConsumer[] |
|
84 | + */ |
|
85 | + protected function getConsumers(): array { |
|
86 | + if (!empty($this->consumers)) { |
|
87 | + return $this->consumers; |
|
88 | + } |
|
89 | + |
|
90 | + $this->consumers = []; |
|
91 | + foreach($this->consumersClosures as $consumer) { |
|
92 | + $c = $consumer(); |
|
93 | + if ($c instanceof IConsumer) { |
|
94 | + $this->consumers[] = $c; |
|
95 | + } else { |
|
96 | + throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + return $this->consumers; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Generates a new IEvent object |
|
105 | + * |
|
106 | + * Make sure to call at least the following methods before sending it to the |
|
107 | + * app with via the publish() method: |
|
108 | + * - setApp() |
|
109 | + * - setType() |
|
110 | + * - setAffectedUser() |
|
111 | + * - setSubject() |
|
112 | + * |
|
113 | + * @return IEvent |
|
114 | + */ |
|
115 | + public function generateEvent(): IEvent { |
|
116 | + return new Event($this->validator); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Publish an event to the activity consumers |
|
121 | + * |
|
122 | + * Make sure to call at least the following methods before sending an Event: |
|
123 | + * - setApp() |
|
124 | + * - setType() |
|
125 | + * - setAffectedUser() |
|
126 | + * - setSubject() |
|
127 | + * |
|
128 | + * @param IEvent $event |
|
129 | + * @throws \BadMethodCallException if required values have not been set |
|
130 | + */ |
|
131 | + public function publish(IEvent $event): void { |
|
132 | + if ($event->getAuthor() === '') { |
|
133 | + if ($this->session->getUser() instanceof IUser) { |
|
134 | + $event->setAuthor($this->session->getUser()->getUID()); |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + if (!$event->getTimestamp()) { |
|
139 | + $event->setTimestamp(time()); |
|
140 | + } |
|
141 | + |
|
142 | + if (!$event->isValid()) { |
|
143 | + throw new \BadMethodCallException('The given event is invalid'); |
|
144 | + } |
|
145 | + |
|
146 | + foreach ($this->getConsumers() as $c) { |
|
147 | + $c->receive($event); |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
153 | + * activity consumers are actually requested |
|
154 | + * |
|
155 | + * $callable has to return an instance of OCA\Activity\IConsumer |
|
156 | + * |
|
157 | + * @param \Closure $callable |
|
158 | + */ |
|
159 | + public function registerConsumer(\Closure $callable): void { |
|
160 | + $this->consumersClosures[] = $callable; |
|
161 | + $this->consumers = []; |
|
162 | + } |
|
163 | + |
|
164 | + /** @var string[] */ |
|
165 | + protected $filterClasses = []; |
|
166 | + |
|
167 | + /** @var IFilter[] */ |
|
168 | + protected $filters = []; |
|
169 | + |
|
170 | + /** |
|
171 | + * @param string $filter Class must implement OCA\Activity\IFilter |
|
172 | + * @return void |
|
173 | + */ |
|
174 | + public function registerFilter(string $filter): void { |
|
175 | + $this->filterClasses[$filter] = false; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @return IFilter[] |
|
180 | + * @throws \InvalidArgumentException |
|
181 | + */ |
|
182 | + public function getFilters(): array { |
|
183 | + foreach ($this->filterClasses as $class => $false) { |
|
184 | + /** @var IFilter $filter */ |
|
185 | + $filter = \OC::$server->query($class); |
|
186 | + |
|
187 | + if (!$filter instanceof IFilter) { |
|
188 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
189 | + } |
|
190 | + |
|
191 | + $this->filters[$filter->getIdentifier()] = $filter; |
|
192 | + |
|
193 | + unset($this->filterClasses[$class]); |
|
194 | + } |
|
195 | + return $this->filters; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * @param string $id |
|
200 | + * @return IFilter |
|
201 | + * @throws \InvalidArgumentException when the filter was not found |
|
202 | + * @since 11.0.0 |
|
203 | + */ |
|
204 | + public function getFilterById(string $id): IFilter { |
|
205 | + $filters = $this->getFilters(); |
|
206 | + |
|
207 | + if (isset($filters[$id])) { |
|
208 | + return $filters[$id]; |
|
209 | + } |
|
210 | + |
|
211 | + throw new \InvalidArgumentException('Requested filter does not exist'); |
|
212 | + } |
|
213 | + |
|
214 | + /** @var string[] */ |
|
215 | + protected $providerClasses = []; |
|
216 | + |
|
217 | + /** @var IProvider[] */ |
|
218 | + protected $providers = []; |
|
219 | + |
|
220 | + /** |
|
221 | + * @param string $provider Class must implement OCA\Activity\IProvider |
|
222 | + * @return void |
|
223 | + */ |
|
224 | + public function registerProvider(string $provider): void { |
|
225 | + $this->providerClasses[$provider] = false; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @return IProvider[] |
|
230 | + * @throws \InvalidArgumentException |
|
231 | + */ |
|
232 | + public function getProviders(): array { |
|
233 | + foreach ($this->providerClasses as $class => $false) { |
|
234 | + /** @var IProvider $provider */ |
|
235 | + $provider = \OC::$server->query($class); |
|
236 | + |
|
237 | + if (!$provider instanceof IProvider) { |
|
238 | + throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
239 | + } |
|
240 | + |
|
241 | + $this->providers[] = $provider; |
|
242 | + |
|
243 | + unset($this->providerClasses[$class]); |
|
244 | + } |
|
245 | + return $this->providers; |
|
246 | + } |
|
247 | + |
|
248 | + /** @var string[] */ |
|
249 | + protected $settingsClasses = []; |
|
250 | + |
|
251 | + /** @var ISetting[] */ |
|
252 | + protected $settings = []; |
|
253 | + |
|
254 | + /** |
|
255 | + * @param string $setting Class must implement OCA\Activity\ISetting |
|
256 | + * @return void |
|
257 | + */ |
|
258 | + public function registerSetting(string $setting): void { |
|
259 | + $this->settingsClasses[$setting] = false; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * @return ISetting[] |
|
264 | + * @throws \InvalidArgumentException |
|
265 | + */ |
|
266 | + public function getSettings(): array { |
|
267 | + foreach ($this->settingsClasses as $class => $false) { |
|
268 | + /** @var ISetting $setting */ |
|
269 | + $setting = \OC::$server->query($class); |
|
270 | + |
|
271 | + if (!$setting instanceof ISetting) { |
|
272 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
273 | + } |
|
274 | + |
|
275 | + $this->settings[$setting->getIdentifier()] = $setting; |
|
276 | + |
|
277 | + unset($this->settingsClasses[$class]); |
|
278 | + } |
|
279 | + return $this->settings; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * @param string $id |
|
284 | + * @return ISetting |
|
285 | + * @throws \InvalidArgumentException when the setting was not found |
|
286 | + * @since 11.0.0 |
|
287 | + */ |
|
288 | + public function getSettingById(string $id): ISetting { |
|
289 | + $settings = $this->getSettings(); |
|
290 | + |
|
291 | + if (isset($settings[$id])) { |
|
292 | + return $settings[$id]; |
|
293 | + } |
|
294 | + |
|
295 | + throw new \InvalidArgumentException('Requested setting does not exist'); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @param string $type |
|
301 | + * @param int $id |
|
302 | + */ |
|
303 | + public function setFormattingObject(string $type, int $id): void { |
|
304 | + $this->formattingObjectType = $type; |
|
305 | + $this->formattingObjectId = $id; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * @return bool |
|
310 | + */ |
|
311 | + public function isFormattingFilteredObject(): bool { |
|
312 | + return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
313 | + && $this->formattingObjectType === $this->request->getParam('object_type') |
|
314 | + && $this->formattingObjectId === (int) $this->request->getParam('object_id'); |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * @param bool $status Set to true, when parsing events should not use SVG icons |
|
319 | + */ |
|
320 | + public function setRequirePNG(bool $status): void { |
|
321 | + $this->requirePNG = $status; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * @return bool |
|
326 | + */ |
|
327 | + public function getRequirePNG(): bool { |
|
328 | + return $this->requirePNG; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Set the user we need to use |
|
333 | + * |
|
334 | + * @param string|null $currentUserId |
|
335 | + * @throws \UnexpectedValueException If the user is invalid |
|
336 | + */ |
|
337 | + public function setCurrentUserId(string $currentUserId = null): void { |
|
338 | + if (!is_string($currentUserId) && $currentUserId !== null) { |
|
339 | + throw new \UnexpectedValueException('The given current user is invalid'); |
|
340 | + } |
|
341 | + $this->currentUserId = $currentUserId; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Get the user we need to use |
|
346 | + * |
|
347 | + * Either the user is logged in, or we try to get it from the token |
|
348 | + * |
|
349 | + * @return string |
|
350 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
351 | + */ |
|
352 | + public function getCurrentUserId(): string { |
|
353 | + if ($this->currentUserId !== null) { |
|
354 | + return $this->currentUserId; |
|
355 | + } |
|
356 | + |
|
357 | + if (!$this->session->isLoggedIn()) { |
|
358 | + return $this->getUserFromToken(); |
|
359 | + } |
|
360 | + |
|
361 | + return $this->session->getUser()->getUID(); |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * Get the user for the token |
|
366 | + * |
|
367 | + * @return string |
|
368 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
369 | + */ |
|
370 | + protected function getUserFromToken(): string { |
|
371 | + $token = (string) $this->request->getParam('token', ''); |
|
372 | + if (strlen($token) !== 30) { |
|
373 | + throw new \UnexpectedValueException('The token is invalid'); |
|
374 | + } |
|
375 | + |
|
376 | + $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
377 | + |
|
378 | + if (count($users) !== 1) { |
|
379 | + // No unique user found |
|
380 | + throw new \UnexpectedValueException('The token is invalid'); |
|
381 | + } |
|
382 | + |
|
383 | + // Token found login as that user |
|
384 | + return array_shift($users); |
|
385 | + } |
|
386 | 386 | |
387 | 387 | } |
@@ -88,7 +88,7 @@ |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | $this->consumers = []; |
91 | - foreach($this->consumersClosures as $consumer) { |
|
91 | + foreach ($this->consumersClosures as $consumer) { |
|
92 | 92 | $c = $consumer(); |
93 | 93 | if ($c instanceof IConsumer) { |
94 | 94 | $this->consumers[] = $c; |