|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace OCA\Circles\Activity; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Exception; |
|
8
|
|
|
use InvalidArgumentException; |
|
9
|
|
|
use OCA\Circles\Api\v1\Circles; |
|
10
|
|
|
use OCA\Circles\Model\Circle; |
|
11
|
|
|
use OCA\Circles\Model\FederatedLink; |
|
12
|
|
|
use OCA\Circles\Model\Member; |
|
13
|
|
|
use OCA\Circles\Service\CirclesService; |
|
14
|
|
|
use OCA\Circles\Service\MiscService; |
|
15
|
|
|
use OCP\Activity\IEvent; |
|
16
|
|
|
use OCP\Activity\IManager; |
|
17
|
|
|
use OCP\Activity\IProvider; |
|
18
|
|
|
use OCP\IL10N; |
|
19
|
|
|
use OCP\IURLGenerator; |
|
20
|
|
|
use OpenCloud\Common\Exceptions\InvalidArgumentError; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
class Provider implements IProvider { |
|
24
|
|
|
|
|
25
|
|
|
/** @var MiscService */ |
|
26
|
|
|
protected $miscService; |
|
27
|
|
|
|
|
28
|
|
|
/** @var IL10N */ |
|
29
|
|
|
protected $l10n; |
|
30
|
|
|
|
|
31
|
|
|
/** @var IURLGenerator */ |
|
32
|
|
|
protected $url; |
|
33
|
|
|
|
|
34
|
|
|
/** @var IManager */ |
|
35
|
|
|
protected $activityManager; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct( |
|
38
|
|
|
IURLGenerator $url, IManager $activityManager, IL10N $l10n, MiscService $miscService |
|
39
|
|
|
) { |
|
40
|
|
|
$this->url = $url; |
|
41
|
|
|
$this->activityManager = $activityManager; |
|
42
|
|
|
$this->l10n = $l10n; |
|
43
|
|
|
$this->miscService = $miscService; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $lang |
|
49
|
|
|
* @param IEvent $event |
|
50
|
|
|
* @param IEvent|null $previousEvent |
|
51
|
|
|
* |
|
52
|
|
|
* @return IEvent |
|
53
|
|
|
*/ |
|
54
|
|
|
public function parse($lang, IEvent $event, IEvent $previousEvent = null) { |
|
55
|
|
|
|
|
56
|
|
|
if ($event->getApp() !== 'circles') { |
|
57
|
|
|
throw new \InvalidArgumentException(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
try { |
|
61
|
|
|
|
|
62
|
|
|
$params = $event->getSubjectParameters(); |
|
63
|
|
|
$circle = Circle::fromJSON($this->l10n, $params['circle']); |
|
64
|
|
|
|
|
65
|
|
|
$this->setIcon($event, $circle); |
|
66
|
|
|
$this->parseAsMember($event, $circle, $params); |
|
67
|
|
|
$this->parseAsModerator($event, $circle, $params); |
|
68
|
|
|
$this->generateParsedSubject($event); |
|
69
|
|
|
|
|
70
|
|
|
return $event; |
|
71
|
|
|
} catch (\Exception $e) { |
|
72
|
|
|
throw new \InvalidArgumentException(); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
private function setIcon(IEvent &$event, Circle $circle) { |
|
78
|
|
|
$event->setIcon( |
|
79
|
|
|
CirclesService::getCircleIcon( |
|
80
|
|
|
$circle->getType(), |
|
81
|
|
|
(method_exists($this->activityManager, 'getRequirePNG') |
|
82
|
|
|
&& $this->activityManager->getRequirePNG()) |
|
83
|
|
|
) |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param Circle $circle |
|
89
|
|
|
* @param IEvent $event |
|
90
|
|
|
* @param array $params |
|
91
|
|
|
* |
|
92
|
|
|
* @return IEvent |
|
93
|
|
|
*/ |
|
94
|
|
|
private function parseAsMember(IEvent &$event, Circle $circle, $params) { |
|
95
|
|
|
if ($event->getType() !== 'circles_as_member') { |
|
96
|
|
|
return $event; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
switch ($event->getSubject()) { |
|
100
|
|
|
case 'circle_create': |
|
101
|
|
|
return $this->parseCircleEvent( |
|
102
|
|
|
$event, $circle, null, |
|
103
|
|
|
$this->l10n->t('You created the circle {circle}'), |
|
104
|
|
|
$this->l10n->t('{author} created the circle {circle}') |
|
105
|
|
|
); |
|
106
|
|
|
|
|
107
|
|
|
case 'circle_delete': |
|
108
|
|
|
return $this->parseCircleEvent( |
|
109
|
|
|
$event, $circle, null, |
|
110
|
|
|
$this->l10n->t('You deleted {circle}'), |
|
111
|
|
|
$this->l10n->t('{author} deleted {circle}') |
|
112
|
|
|
); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
if (key_exists('member', $params)) { |
|
116
|
|
|
$this->parseMemberAsMember($event, $circle); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return $event; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param Circle $circle |
|
125
|
|
|
* @param IEvent $event |
|
126
|
|
|
* |
|
127
|
|
|
* @return IEvent |
|
128
|
|
|
*/ |
|
129
|
|
|
private function parseMemberAsMember(IEvent &$event, Circle $circle) { |
|
130
|
|
|
$params = $event->getSubjectParameters(); |
|
131
|
|
|
$member = Member::fromJSON($this->l10n, $params['member']); |
|
132
|
|
|
|
|
133
|
|
|
switch ($event->getSubject()) { |
|
134
|
|
View Code Duplication |
case 'member_join': |
|
|
|
|
|
|
135
|
|
|
return $this->parseCircleMemberEvent( |
|
136
|
|
|
$event, $circle, $member, |
|
137
|
|
|
$this->l10n->t('You joined {circle}'), |
|
138
|
|
|
$this->l10n->t('{member} joined {circle}') |
|
139
|
|
|
); |
|
140
|
|
|
|
|
141
|
|
View Code Duplication |
case 'member_add': |
|
|
|
|
|
|
142
|
|
|
return $this->parseCircleMemberAdvancedEvent( |
|
143
|
|
|
$event, $circle, $member, |
|
144
|
|
|
$this->l10n->t('You added {member} as member to {circle}'), |
|
145
|
|
|
$this->l10n->t('You were added as member to {circle} by {author}'), |
|
146
|
|
|
$this->l10n->t('{member} was added as member to {circle} by {author}') |
|
147
|
|
|
); |
|
148
|
|
|
|
|
149
|
|
View Code Duplication |
case 'member_left': |
|
|
|
|
|
|
150
|
|
|
return $this->parseCircleMemberEvent( |
|
151
|
|
|
$event, $circle, $member, |
|
152
|
|
|
$this->l10n->t('You left {circle}'), |
|
153
|
|
|
$this->l10n->t('{member} left {circle}') |
|
154
|
|
|
); |
|
155
|
|
|
|
|
156
|
|
View Code Duplication |
case 'member_remove': |
|
|
|
|
|
|
157
|
|
|
return $this->parseCircleMemberAdvancedEvent( |
|
158
|
|
|
$event, $circle, $member, |
|
159
|
|
|
$this->l10n->t('You removed {member} from {circle}'), |
|
160
|
|
|
$this->l10n->t('You were removed from {circle} by {author}'), |
|
161
|
|
|
$this->l10n->t('{member} was removed from {circle} by {author}') |
|
162
|
|
|
); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
return $event; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @param Circle $circle |
|
171
|
|
|
* @param IEvent $event |
|
172
|
|
|
* @param array $params |
|
173
|
|
|
* |
|
174
|
|
|
* @return IEvent |
|
175
|
|
|
* @throws Exception |
|
176
|
|
|
*/ |
|
177
|
|
|
private function parseAsModerator(IEvent &$event, Circle $circle, $params) { |
|
178
|
|
|
if ($event->getType() !== 'circles_as_moderator') { |
|
179
|
|
|
return $event; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
try { |
|
183
|
|
|
if (key_exists('member', $params)) { |
|
184
|
|
|
return $this->parseMemberAsModerator($event, $circle); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
if (key_exists('link', $params)) { |
|
188
|
|
|
return $this->parseLinkAsModerator($event, $circle); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
throw new InvalidArgumentError(); |
|
192
|
|
|
} catch (Exception $e) { |
|
193
|
|
|
throw $e; |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @param Circle $circle |
|
200
|
|
|
* @param IEvent $event |
|
201
|
|
|
* |
|
202
|
|
|
* @return IEvent |
|
203
|
|
|
*/ |
|
204
|
|
|
private function parseMemberAsModerator(IEvent &$event, Circle $circle) { |
|
205
|
|
|
|
|
206
|
|
|
$params = $event->getSubjectParameters(); |
|
207
|
|
|
$member = Member::fromJSON($this->l10n, $params['member']); |
|
208
|
|
|
|
|
209
|
|
|
switch ($event->getSubject()) { |
|
210
|
|
View Code Duplication |
case 'member_invited': |
|
|
|
|
|
|
211
|
|
|
return $this->parseCircleMemberAdvancedEvent( |
|
212
|
|
|
$event, $circle, $member, |
|
213
|
|
|
$this->l10n->t('You invited {member} into {circle}'), |
|
214
|
|
|
$this->l10n->t('You have been invited into {circle} by {author}'), |
|
215
|
|
|
$this->l10n->t('{member} have been invited into {circle} by {author}') |
|
216
|
|
|
); |
|
217
|
|
|
|
|
218
|
|
|
case 'member_level': |
|
219
|
|
|
$level = [$this->l10n->t($member->getLevelString())]; |
|
220
|
|
|
|
|
221
|
|
|
return $this->parseCircleMemberAdvancedEvent( |
|
222
|
|
|
$event, $circle, $member, |
|
223
|
|
|
$this->l10n->t('You changed {member}\'s level in {circle} to %1$s', $level), |
|
224
|
|
|
$this->l10n->t('{author} changed your level in {circle} to %1$s', $level), |
|
225
|
|
|
$this->l10n->t('{author} changed {member}\'s level in {circle} to %1$s', $level) |
|
226
|
|
|
); |
|
227
|
|
|
|
|
228
|
|
View Code Duplication |
case 'member_request_invitation': |
|
|
|
|
|
|
229
|
|
|
return $this->parseMemberEvent( |
|
230
|
|
|
$event, $circle, $member, |
|
231
|
|
|
$this->l10n->t('You requested an invitation into {circle}'), |
|
232
|
|
|
$this->l10n->t( |
|
233
|
|
|
'{member} has requested an invitation into {circle}' |
|
234
|
|
|
) |
|
235
|
|
|
); |
|
236
|
|
|
|
|
237
|
|
View Code Duplication |
case 'member_owner': |
|
|
|
|
|
|
238
|
|
|
return $this->parseMemberEvent( |
|
239
|
|
|
$event, $circle, $member, |
|
240
|
|
|
$this->l10n->t('You are the new owner of {circle}'), |
|
241
|
|
|
$this->l10n->t('{member} is the new owner of {circle}') |
|
242
|
|
|
); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
throw new InvalidArgumentException(); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* @param Circle $circle |
|
251
|
|
|
* @param IEvent $event |
|
252
|
|
|
* |
|
253
|
|
|
* @return IEvent |
|
254
|
|
|
*/ |
|
255
|
|
|
private function parseLinkAsModerator(IEvent &$event, Circle $circle) { |
|
256
|
|
|
|
|
257
|
|
|
$params = $event->getSubjectParameters(); |
|
258
|
|
|
$remote = FederatedLink::fromJSON($params['link']); |
|
259
|
|
|
|
|
260
|
|
|
switch ($event->getSubject()) { |
|
261
|
|
View Code Duplication |
case 'link_request_sent': |
|
|
|
|
|
|
262
|
|
|
return $this->parseCircleEvent( |
|
263
|
|
|
$event, $circle, $remote, |
|
264
|
|
|
$this->l10n->t('You sent a request to link {circle} with {remote}'), |
|
265
|
|
|
$this->l10n->t('{author} sent a request to link {circle} with {remote}') |
|
266
|
|
|
); |
|
267
|
|
|
|
|
268
|
|
|
case 'link_request_received'; |
|
|
|
|
|
|
269
|
|
|
return $this->parseLinkEvent( |
|
270
|
|
|
$event, $circle, $remote, |
|
271
|
|
|
$this->l10n->t('{remote} requested a link with {circle}') |
|
272
|
|
|
); |
|
273
|
|
|
|
|
274
|
|
|
case 'link_request_rejected'; |
|
|
|
|
|
|
275
|
|
|
return $this->parseLinkEvent( |
|
276
|
|
|
$event, $circle, $remote, $this->l10n->t( |
|
277
|
|
|
'The request to link {circle} with {remote} has been rejected' |
|
278
|
|
|
) |
|
279
|
|
|
); |
|
280
|
|
|
|
|
281
|
|
|
case 'link_request_canceled': |
|
282
|
|
|
return $this->parseLinkEvent( |
|
283
|
|
|
$event, $circle, $remote, |
|
284
|
|
|
$this->l10n->t( |
|
285
|
|
|
'The request to link {remote} with {circle} has been canceled remotely' |
|
286
|
|
|
) |
|
287
|
|
|
); |
|
288
|
|
|
|
|
289
|
|
|
case 'link_request_accepted': |
|
290
|
|
|
return $this->parseLinkEvent( |
|
291
|
|
|
$event, $circle, $remote, |
|
292
|
|
|
$this->l10n->t('The request to link {circle} with {remote} has been accepted') |
|
293
|
|
|
); |
|
294
|
|
|
|
|
295
|
|
View Code Duplication |
case 'link_request_removed': |
|
|
|
|
|
|
296
|
|
|
return $this->parseCircleEvent( |
|
297
|
|
|
$event, $circle, $remote, |
|
298
|
|
|
$this->l10n->t('You dismissed the request to link {remote} with {circle}'), |
|
299
|
|
|
$this->l10n->t('{author} dismissed the request to link {remote} with {circle}') |
|
300
|
|
|
); |
|
301
|
|
|
|
|
302
|
|
View Code Duplication |
case 'link_request_canceling': |
|
|
|
|
|
|
303
|
|
|
return $this->parseCircleEvent( |
|
304
|
|
|
$event, $circle, $remote, |
|
305
|
|
|
$this->l10n->t('You canceled the request to link {circle} with {remote}'), |
|
306
|
|
|
$this->l10n->t('{author} canceled the request to link {circle} with {remote}') |
|
307
|
|
|
); |
|
308
|
|
|
|
|
309
|
|
View Code Duplication |
case 'link_request_accepting': |
|
|
|
|
|
|
310
|
|
|
return $this->parseCircleEvent( |
|
311
|
|
|
$event, $circle, $remote, |
|
312
|
|
|
$this->l10n->t('You accepted the request to link {remote} with {circle}'), |
|
313
|
|
|
$this->l10n->t('{author} accepted the request to link {remote} with {circle}') |
|
314
|
|
|
); |
|
315
|
|
|
|
|
316
|
|
|
case 'link_up': |
|
317
|
|
|
return $this->parseLinkEvent( |
|
318
|
|
|
$event, $circle, $remote, |
|
319
|
|
|
$this->l10n->t('A link between {circle} and {remote} is now up and running') |
|
320
|
|
|
); |
|
321
|
|
|
|
|
322
|
|
|
case 'link_down': |
|
323
|
|
|
return $this->parseLinkEvent( |
|
324
|
|
|
$event, $circle, $remote, |
|
325
|
|
|
$this->l10n->t( |
|
326
|
|
|
'The link between {circle} and {remote} has been shutdown remotely' |
|
327
|
|
|
) |
|
328
|
|
|
); |
|
329
|
|
|
|
|
330
|
|
View Code Duplication |
case 'link_remove': |
|
|
|
|
|
|
331
|
|
|
return $this->parseCircleEvent( |
|
332
|
|
|
$event, $circle, $remote, |
|
333
|
|
|
$this->l10n->t('You closed the link between {circle} and {remote}'), |
|
334
|
|
|
$this->l10n->t('{author} closed the link between {circle} and {remote}') |
|
335
|
|
|
); |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
throw new InvalidArgumentException(); |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* general function to generate Circle event. |
|
344
|
|
|
* |
|
345
|
|
|
* @param IEvent $event |
|
346
|
|
|
* @param Circle $circle |
|
347
|
|
|
* @param FederatedLink $remote |
|
348
|
|
|
* @param string $ownEvent |
|
349
|
|
|
* @param string $othersEvent |
|
350
|
|
|
* |
|
351
|
|
|
* @return IEvent |
|
352
|
|
|
*/ |
|
353
|
|
|
private function parseCircleEvent( |
|
354
|
|
|
IEvent &$event, Circle $circle, $remote, $ownEvent, $othersEvent |
|
355
|
|
|
) { |
|
356
|
|
|
$data = [ |
|
357
|
|
|
'author' => $this->generateViewerParameter($circle), |
|
358
|
|
|
'circle' => $this->generateCircleParameter($circle), |
|
359
|
|
|
'remote' => ($remote === null) ? '' : $this->generateRemoteCircleParameter($remote) |
|
360
|
|
|
]; |
|
361
|
|
|
|
|
362
|
|
|
if ($this->isViewerTheAuthor($circle, $this->activityManager->getCurrentUserId())) { |
|
363
|
|
|
return $event->setRichSubject($ownEvent, $data); |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
return $event->setRichSubject($othersEvent, $data); |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
|
|
370
|
|
|
/** |
|
371
|
|
|
* general function to generate Member event. |
|
372
|
|
|
* |
|
373
|
|
|
* @param Circle $circle |
|
374
|
|
|
* @param $member |
|
375
|
|
|
* @param IEvent $event |
|
376
|
|
|
* @param $ownEvent |
|
377
|
|
|
* @param $othersEvent |
|
378
|
|
|
* |
|
379
|
|
|
* @return IEvent |
|
380
|
|
|
*/ |
|
381
|
|
View Code Duplication |
private function parseMemberEvent( |
|
|
|
|
|
|
382
|
|
|
IEvent &$event, Circle $circle, Member $member, $ownEvent, $othersEvent |
|
383
|
|
|
) { |
|
384
|
|
|
$data = [ |
|
385
|
|
|
'circle' => $this->generateCircleParameter($circle), |
|
386
|
|
|
'member' => $this->generateMemberParameter($member) |
|
387
|
|
|
]; |
|
388
|
|
|
|
|
389
|
|
|
if ($member->getUserId() === $this->activityManager->getCurrentUserId() |
|
390
|
|
|
) { |
|
391
|
|
|
return $event->setRichSubject($ownEvent, $data); |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
return $event->setRichSubject($othersEvent, $data); |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
|
|
398
|
|
|
/** |
|
399
|
|
|
* general function to generate Link event. |
|
400
|
|
|
* |
|
401
|
|
|
* @param Circle $circle |
|
402
|
|
|
* @param FederatedLink $remote |
|
403
|
|
|
* @param IEvent $event |
|
404
|
|
|
* @param string $line |
|
405
|
|
|
* |
|
406
|
|
|
* @return IEvent |
|
407
|
|
|
*/ |
|
408
|
|
|
private function parseLinkEvent(IEvent &$event, Circle $circle, FederatedLink $remote, $line) { |
|
409
|
|
|
$data = [ |
|
410
|
|
|
'circle' => $this->generateCircleParameter($circle), |
|
411
|
|
|
'remote' => $this->generateRemoteCircleParameter($remote) |
|
412
|
|
|
]; |
|
413
|
|
|
|
|
414
|
|
|
return $event->setRichSubject($line, $data); |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
|
|
418
|
|
|
/** |
|
419
|
|
|
* general function to generate Circle+Member event. |
|
420
|
|
|
* |
|
421
|
|
|
* @param Circle $circle |
|
422
|
|
|
* @param Member $member |
|
423
|
|
|
* @param IEvent $event |
|
424
|
|
|
* @param string $ownEvent |
|
425
|
|
|
* @param string $othersEvent |
|
426
|
|
|
* |
|
427
|
|
|
* @return IEvent |
|
428
|
|
|
*/ |
|
429
|
|
View Code Duplication |
private function parseCircleMemberEvent( |
|
|
|
|
|
|
430
|
|
|
IEvent &$event, Circle $circle, Member $member, $ownEvent, $othersEvent |
|
431
|
|
|
) { |
|
432
|
|
|
$data = [ |
|
433
|
|
|
'circle' => $this->generateCircleParameter($circle), |
|
434
|
|
|
'member' => $this->generateMemberParameter($member) |
|
435
|
|
|
]; |
|
436
|
|
|
|
|
437
|
|
|
if ($this->isViewerTheAuthor($circle, $this->activityManager->getCurrentUserId())) { |
|
438
|
|
|
return $event->setRichSubject($ownEvent, $data); |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
return $event->setRichSubject($othersEvent, $data); |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
|
|
445
|
|
|
/** |
|
446
|
|
|
* general function to generate Circle+Member advanced event. |
|
447
|
|
|
* |
|
448
|
|
|
* @param Circle $circle |
|
449
|
|
|
* @param Member $member |
|
450
|
|
|
* @param IEvent $event |
|
451
|
|
|
*\ |
|
452
|
|
|
* @param $ownEvent |
|
453
|
|
|
* @param $targetEvent |
|
454
|
|
|
* @param $othersEvent |
|
455
|
|
|
* |
|
456
|
|
|
* @return IEvent |
|
457
|
|
|
*/ |
|
458
|
|
|
private function parseCircleMemberAdvancedEvent( |
|
459
|
|
|
IEvent &$event, Circle $circle, Member $member, $ownEvent, $targetEvent, $othersEvent |
|
460
|
|
|
) { |
|
461
|
|
|
|
|
462
|
|
|
$data = [ |
|
463
|
|
|
'author' => $this->generateViewerParameter($circle), |
|
464
|
|
|
'circle' => $this->generateCircleParameter($circle), |
|
465
|
|
|
'member' => $this->generateMemberParameter($member) |
|
466
|
|
|
]; |
|
467
|
|
|
|
|
468
|
|
|
if ($this->isViewerTheAuthor($circle, $this->activityManager->getCurrentUserId())) { |
|
469
|
|
|
return $event->setRichSubject($ownEvent, $data); |
|
470
|
|
|
} |
|
471
|
|
|
|
|
472
|
|
|
if ($member->getUserId() === $this->activityManager->getCurrentUserId()) { |
|
473
|
|
|
return $event->setRichSubject($targetEvent, $data); |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
return $event->setRichSubject($othersEvent, $data); |
|
477
|
|
|
} |
|
478
|
|
|
|
|
479
|
|
|
|
|
480
|
|
|
/** |
|
481
|
|
|
* @param IEvent $event |
|
482
|
|
|
*/ |
|
483
|
|
|
private function generateParsedSubject(IEvent &$event) { |
|
484
|
|
|
$subject = $event->getRichSubject(); |
|
485
|
|
|
$params = $event->getRichSubjectParameters(); |
|
486
|
|
|
$ak = array_keys($params); |
|
487
|
|
|
foreach ($ak as $k) { |
|
488
|
|
|
if (is_array($params[$k])) { |
|
489
|
|
|
$subject = str_replace('{' . $k . '}', $params[$k]['parsed'], $subject); |
|
490
|
|
|
} |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
$event->setParsedSubject($subject); |
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
|
|
497
|
|
|
/** |
|
498
|
|
|
* @param Circle $circle |
|
499
|
|
|
* @param string $userId |
|
500
|
|
|
* |
|
501
|
|
|
* @return bool |
|
502
|
|
|
*/ |
|
503
|
|
|
private function isViewerTheAuthor(Circle $circle, $userId) { |
|
504
|
|
|
if ($circle->getViewer() === null) { |
|
505
|
|
|
return false; |
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
|
|
if ($circle->getViewer() |
|
|
|
|
|
|
509
|
|
|
->getUserId() === $userId) { |
|
510
|
|
|
return true; |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
return false; |
|
514
|
|
|
} |
|
515
|
|
|
|
|
516
|
|
|
|
|
517
|
|
|
/** |
|
518
|
|
|
* @param Member $member |
|
519
|
|
|
* |
|
520
|
|
|
* @return array<string,string|integer> |
|
521
|
|
|
*/ |
|
522
|
|
|
private function generateMemberParameter(Member $member) { |
|
523
|
|
|
return $this->generateUserParameter($member->getUserId()); |
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
/** |
|
527
|
|
|
* @param Circle $circle |
|
528
|
|
|
* |
|
529
|
|
|
* @return array <string,string|integer> |
|
|
|
|
|
|
530
|
|
|
*/ |
|
531
|
|
|
private function generateViewerParameter(Circle $circle) { |
|
532
|
|
|
if ($circle->getViewer() === null) { |
|
533
|
|
|
return ''; |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
return $this->generateUserParameter( |
|
537
|
|
|
$circle->getViewer() |
|
538
|
|
|
->getUserId() |
|
539
|
|
|
); |
|
540
|
|
|
} |
|
541
|
|
|
|
|
542
|
|
|
|
|
543
|
|
|
/** |
|
544
|
|
|
* @param Circle $circle |
|
545
|
|
|
* |
|
546
|
|
|
* @return array<string,string|integer> |
|
547
|
|
|
*/ |
|
548
|
|
|
private function generateCircleParameter(Circle $circle) { |
|
549
|
|
|
return [ |
|
550
|
|
|
'type' => 'circle', |
|
551
|
|
|
'id' => $circle->getId(), |
|
552
|
|
|
'name' => $circle->getName(), |
|
553
|
|
|
'parsed' => $circle->getName(), |
|
554
|
|
|
'link' => Circles::generateLink($circle->getUniqueId()) |
|
555
|
|
|
]; |
|
556
|
|
|
} |
|
557
|
|
|
|
|
558
|
|
|
|
|
559
|
|
|
/** |
|
560
|
|
|
* @param FederatedLink $link |
|
561
|
|
|
* |
|
562
|
|
|
* @return array<string,string|integer> |
|
|
|
|
|
|
563
|
|
|
*/ |
|
564
|
|
|
private function generateRemoteCircleParameter(FederatedLink $link) { |
|
565
|
|
|
return [ |
|
566
|
|
|
'type' => 'circle', |
|
567
|
|
|
'id' => $link->getUniqueId(), |
|
568
|
|
|
'name' => $link->getToken() . '@' . $link->getAddress(), |
|
569
|
|
|
'parsed' => $link->getToken() . '@' . $link->getAddress() |
|
570
|
|
|
]; |
|
571
|
|
|
// 'link' => Circles::generateRemoteLink($link) |
|
|
|
|
|
|
572
|
|
|
} |
|
573
|
|
|
|
|
574
|
|
|
|
|
575
|
|
|
/** |
|
576
|
|
|
* @param $userId |
|
577
|
|
|
* |
|
578
|
|
|
* @return array<string,string|integer> |
|
579
|
|
|
*/ |
|
580
|
|
|
private function generateUserParameter($userId) { |
|
581
|
|
|
return [ |
|
582
|
|
|
'type' => 'user', |
|
583
|
|
|
'id' => $userId, |
|
584
|
|
|
'name' => \OC::$server->getUserManager() |
|
585
|
|
|
->get($userId) |
|
586
|
|
|
->getDisplayName(), |
|
587
|
|
|
'parsed' => \OC::$server->getUserManager() |
|
588
|
|
|
->get($userId) |
|
589
|
|
|
->getDisplayName() |
|
590
|
|
|
]; |
|
591
|
|
|
} |
|
592
|
|
|
} |
|
593
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.