|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Circles - Bring cloud-users closer together. |
|
5
|
|
|
* |
|
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
7
|
|
|
* later. See the COPYING file. |
|
8
|
|
|
* |
|
9
|
|
|
* @author Maxence Lange <[email protected]> |
|
10
|
|
|
* @copyright 2017 |
|
11
|
|
|
* @license GNU AGPL version 3 or any later version |
|
12
|
|
|
* |
|
13
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
14
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
15
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
16
|
|
|
* License, or (at your option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, |
|
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21
|
|
|
* GNU Affero General Public License for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
25
|
|
|
* |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
namespace OCA\Circles\Activity; |
|
29
|
|
|
|
|
30
|
|
|
use Exception; |
|
31
|
|
|
use InvalidArgumentException; |
|
32
|
|
|
use OCA\Circles\AppInfo\Application; |
|
33
|
|
|
use OCA\Circles\Exceptions\FakeException; |
|
34
|
|
|
use OCA\Circles\Model\Circle; |
|
35
|
|
|
use OCA\Circles\Model\FederatedLink; |
|
36
|
|
|
use OCA\Circles\Model\Member; |
|
37
|
|
|
use OCA\Circles\Service\CirclesService; |
|
38
|
|
|
use OCP\Activity\IEvent; |
|
39
|
|
|
use OCP\Activity\IProvider; |
|
40
|
|
|
use OpenCloud\Common\Exceptions\InvalidArgumentError; |
|
41
|
|
|
|
|
42
|
|
|
class Provider extends BaseProvider implements IProvider { |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param string $lang |
|
47
|
|
|
* @param IEvent $event |
|
48
|
|
|
* @param IEvent|null $previousEvent |
|
49
|
|
|
* |
|
50
|
|
|
* @return IEvent |
|
51
|
|
|
*/ |
|
52
|
|
|
public function parse($lang, IEvent $event, IEvent $previousEvent = null) { |
|
53
|
|
|
|
|
54
|
|
|
if ($event->getApp() !== Application::APP_NAME) { |
|
55
|
|
|
throw new \InvalidArgumentException(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
try { |
|
59
|
|
|
|
|
60
|
|
|
$params = $event->getSubjectParameters(); |
|
61
|
|
|
$circle = Circle::fromJSON($params['circle']); |
|
62
|
|
|
|
|
63
|
|
|
$this->setIcon($event, $circle); |
|
64
|
|
|
$this->parseAsMember($event, $circle, $params); |
|
65
|
|
|
$this->parseAsModerator($event, $circle, $params); |
|
66
|
|
|
$this->generateParsedSubject($event); |
|
67
|
|
|
|
|
68
|
|
|
return $event; |
|
69
|
|
|
} catch (\Exception $e) { |
|
70
|
|
|
throw new \InvalidArgumentException(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
private function setIcon(IEvent &$event, Circle $circle) { |
|
76
|
|
|
$event->setIcon( |
|
77
|
|
|
CirclesService::getCircleIcon( |
|
78
|
|
|
$circle->getType(), |
|
79
|
|
|
(method_exists($this->activityManager, 'getRequirePNG') |
|
80
|
|
|
&& $this->activityManager->getRequirePNG()) |
|
81
|
|
|
) |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param Circle $circle |
|
87
|
|
|
* @param IEvent $event |
|
88
|
|
|
* @param array $params |
|
89
|
|
|
* |
|
90
|
|
|
* @return IEvent |
|
91
|
|
|
*/ |
|
92
|
|
|
private function parseAsMember(IEvent &$event, Circle $circle, $params) { |
|
93
|
|
|
if ($event->getType() !== 'circles_as_member') { |
|
94
|
|
|
return $event; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
switch ($event->getSubject()) { |
|
98
|
|
|
case 'circle_create': |
|
99
|
|
|
return $this->parseCircleEvent( |
|
100
|
|
|
$event, $circle, null, |
|
101
|
|
|
$this->l10n->t('You created the circle {circle}'), |
|
102
|
|
|
$this->l10n->t('{author} created the circle {circle}') |
|
103
|
|
|
); |
|
104
|
|
|
|
|
105
|
|
|
case 'circle_delete': |
|
106
|
|
|
return $this->parseCircleEvent( |
|
107
|
|
|
$event, $circle, null, |
|
108
|
|
|
$this->l10n->t('You deleted {circle}'), |
|
109
|
|
|
$this->l10n->t('{author} deleted {circle}') |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
if (key_exists('member', $params)) { |
|
114
|
|
|
$this->parseMemberAsMember($event, $circle); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
return $event; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param Circle $circle |
|
123
|
|
|
* @param IEvent $event |
|
124
|
|
|
* @param array $params |
|
125
|
|
|
* |
|
126
|
|
|
* @return IEvent |
|
127
|
|
|
* @throws Exception |
|
128
|
|
|
*/ |
|
129
|
|
|
private function parseAsModerator(IEvent &$event, Circle $circle, $params) { |
|
130
|
|
|
if ($event->getType() !== 'circles_as_moderator') { |
|
131
|
|
|
return $event; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
try { |
|
135
|
|
|
if (key_exists('member', $params)) { |
|
136
|
|
|
return $this->parseMemberAsModerator($event, $circle); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
if (key_exists('group', $params)) { |
|
140
|
|
|
return $this->parseGroupAsModerator($event, $circle); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
if (key_exists('link', $params)) { |
|
144
|
|
|
return $this->parseLinkAsModerator($event, $circle); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
throw new InvalidArgumentError(); |
|
148
|
|
|
} catch (Exception $e) { |
|
149
|
|
|
throw $e; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @param Circle $circle |
|
156
|
|
|
* @param IEvent $event |
|
157
|
|
|
* |
|
158
|
|
|
* @return IEvent |
|
159
|
|
|
*/ |
|
160
|
|
View Code Duplication |
private function parseMemberAsMember(IEvent &$event, Circle $circle) { |
|
|
|
|
|
|
161
|
|
|
$params = $event->getSubjectParameters(); |
|
162
|
|
|
$member = Member::fromJSON($params['member']); |
|
163
|
|
|
|
|
164
|
|
|
try { |
|
165
|
|
|
$this->parseSubjectMemberJoin($event, $circle, $member); |
|
166
|
|
|
$this->parseSubjectMemberAdd($event, $circle, $member); |
|
167
|
|
|
$this->parseSubjectMemberLeft($event, $circle, $member); |
|
168
|
|
|
$this->parseSubjectMemberRemove($event, $circle, $member); |
|
169
|
|
|
} catch (FakeException $e) { |
|
170
|
|
|
return $event; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
|
|
174
|
|
|
return $event; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Parse on Subject 'member_join'. |
|
180
|
|
|
* If circle is closed, we say that user accepted his invitation. |
|
181
|
|
|
* |
|
182
|
|
|
* @param IEvent $event |
|
183
|
|
|
* @param Circle $circle |
|
184
|
|
|
* @param Member $member |
|
185
|
|
|
* |
|
186
|
|
|
* @throws FakeException |
|
187
|
|
|
*/ |
|
188
|
|
|
private function parseSubjectMemberJoin(IEvent &$event, Circle $circle, Member $member) { |
|
189
|
|
|
|
|
190
|
|
|
if ($event->getSubject() !== 'member_request_invitation') { |
|
191
|
|
|
return; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
$this->parseSubjectMemberJoinClosedCircle($event, $circle, $member); |
|
195
|
|
|
$this->parseCircleMemberEvent( |
|
196
|
|
|
$event, $circle, $member, $this->l10n->t('You joined {circle}'), |
|
197
|
|
|
$this->l10n->t('{member} joined {circle}') |
|
198
|
|
|
); |
|
199
|
|
|
|
|
200
|
|
|
throw new FakeException(); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @param IEvent $event |
|
206
|
|
|
* @param Circle $circle |
|
207
|
|
|
* @param Member $member |
|
208
|
|
|
* |
|
209
|
|
|
* @throws FakeException |
|
210
|
|
|
*/ |
|
211
|
|
|
private function parseSubjectMemberJoinClosedCircle(IEvent &$event, Circle $circle, Member $member) { |
|
|
|
|
|
|
212
|
|
|
if ($circle->getType() !== Circle::CIRCLES_CLOSED) { |
|
213
|
|
|
return; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
$this->parseCircleMemberEvent( |
|
217
|
|
|
$event, $circle, $member, |
|
218
|
|
|
$this->l10n->t('You accepted the invitation to join {circle}'), |
|
219
|
|
|
$this->l10n->t('{member} accepted the invitation to join {circle}') |
|
220
|
|
|
); |
|
221
|
|
|
|
|
222
|
|
|
throw new FakeException(); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Parse on Subject 'member_add'. |
|
228
|
|
|
* If circle is closed, we say that user's invitation was accepted. |
|
229
|
|
|
* |
|
230
|
|
|
* @param IEvent $event |
|
231
|
|
|
* @param Circle $circle |
|
232
|
|
|
* @param Member $member |
|
233
|
|
|
* |
|
234
|
|
|
* @throws FakeException |
|
235
|
|
|
*/ |
|
236
|
|
View Code Duplication |
private function parseSubjectMemberAdd(IEvent &$event, Circle $circle, Member $member) { |
|
|
|
|
|
|
237
|
|
|
if ($event->getSubject() !== 'member_add') { |
|
238
|
|
|
return; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
$this->parseSubjectMemberAddClosedCircle($event, $circle, $member); |
|
242
|
|
|
$this->parseCircleMemberAdvancedEvent( |
|
243
|
|
|
$event, $circle, $member, |
|
244
|
|
|
$this->l10n->t('You added {member} as member to {circle}'), |
|
245
|
|
|
$this->l10n->t('You have been added as member to {circle} by {author}'), |
|
246
|
|
|
$this->l10n->t('{member} has been added as member to {circle} by {author}') |
|
247
|
|
|
); |
|
248
|
|
|
|
|
249
|
|
|
throw new FakeException(); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* @param IEvent $event |
|
255
|
|
|
* @param Circle $circle |
|
256
|
|
|
* @param Member $member |
|
257
|
|
|
* |
|
258
|
|
|
* @throws FakeException |
|
259
|
|
|
*/ |
|
260
|
|
|
private function parseSubjectMemberAddClosedCircle(IEvent &$event, Circle $circle, Member $member) { |
|
|
|
|
|
|
261
|
|
|
if ($circle->getType() !== Circle::CIRCLES_CLOSED) { |
|
262
|
|
|
return; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
$this->parseCircleMemberAdvancedEvent( |
|
266
|
|
|
$event, $circle, $member, |
|
267
|
|
|
$this->l10n->t("You accepted {member}'s request to join {circle}"), |
|
268
|
|
|
$this->l10n->t('Your request to join {circle} has been accepted by {author}'), |
|
269
|
|
|
$this->l10n->t("{member}'s request to join {circle} has been accepted by {author}") |
|
270
|
|
|
); |
|
271
|
|
|
|
|
272
|
|
|
throw new FakeException(); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* Parse on Subject 'member_left'. |
|
278
|
|
|
* If circle is closed and member was not a real member, we send him to |
|
279
|
|
|
* parseSubjectNonMemberLeftClosedCircle(); |
|
280
|
|
|
* |
|
281
|
|
|
* @param IEvent $event |
|
282
|
|
|
* @param Circle $circle |
|
283
|
|
|
* @param Member $member |
|
284
|
|
|
* |
|
285
|
|
|
* @throws FakeException |
|
286
|
|
|
*/ |
|
287
|
|
|
private function parseSubjectMemberLeft(IEvent &$event, Circle $circle, Member $member) { |
|
288
|
|
|
|
|
289
|
|
|
if ($event->getSubject() !== 'member_left') { |
|
290
|
|
|
return; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
$this->parseSubjectNonMemberLeftClosedCircle($event, $circle, $member); |
|
294
|
|
|
$this->parseCircleMemberEvent( |
|
295
|
|
|
$event, $circle, $member, |
|
296
|
|
|
$this->l10n->t('You left {circle}'), |
|
297
|
|
|
$this->l10n->t('{member} left {circle}') |
|
298
|
|
|
); |
|
299
|
|
|
|
|
300
|
|
|
throw new FakeException(); |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* Parse on Subject 'member_left' on a closed circle when user were not yet a member. |
|
306
|
|
|
* If status is Invited we say that member rejected his invitation. |
|
307
|
|
|
* If status is Requested we say he dismissed his request. |
|
308
|
|
|
* |
|
309
|
|
|
* @param IEvent $event |
|
310
|
|
|
* @param Circle $circle |
|
311
|
|
|
* @param Member $member |
|
312
|
|
|
* |
|
313
|
|
|
* @throws FakeException |
|
314
|
|
|
*/ |
|
315
|
|
View Code Duplication |
private function parseSubjectNonMemberLeftClosedCircle(IEvent &$event, Circle $circle, Member $member |
|
|
|
|
|
|
316
|
|
|
) { |
|
317
|
|
|
if ($circle->getType() !== Circle::CIRCLES_CLOSED |
|
318
|
|
|
|| $member->getLevel() !== Member::LEVEL_NONE) { |
|
319
|
|
|
return; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
if ($member->getStatus() === Member::STATUS_INVITED) { |
|
323
|
|
|
$this->parseCircleMemberEvent( |
|
324
|
|
|
$event, $circle, $member, |
|
325
|
|
|
$this->l10n->t("You declined the invitation to join {circle}"), |
|
326
|
|
|
$this->l10n->t("{member} declined an invitation to join {circle}") |
|
327
|
|
|
); |
|
328
|
|
|
} else { |
|
329
|
|
|
$this->parseCircleMemberEvent( |
|
330
|
|
|
$event, $circle, $member, |
|
331
|
|
|
$this->l10n->t("You cancelled your request to join {circle}"), |
|
332
|
|
|
$this->l10n->t("{member} cancelled his request to join {circle}") |
|
333
|
|
|
); |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
throw new FakeException(); |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* Parse on Subject 'member_remove'. |
|
342
|
|
|
* If circle is closed and member was not a real member, we send him to |
|
343
|
|
|
* parseSubjectNonMemberRemoveClosedCircle(); |
|
344
|
|
|
* |
|
345
|
|
|
* @param IEvent $event |
|
346
|
|
|
* @param Circle $circle |
|
347
|
|
|
* @param Member $member |
|
348
|
|
|
* |
|
349
|
|
|
* @throws FakeException |
|
350
|
|
|
*/ |
|
351
|
|
View Code Duplication |
private function parseSubjectMemberRemove(IEvent &$event, Circle $circle, Member $member) { |
|
|
|
|
|
|
352
|
|
|
|
|
353
|
|
|
if ($event->getSubject() !== 'member_remove') { |
|
354
|
|
|
return; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
if ($circle->getType() === Circle::CIRCLES_CLOSED |
|
358
|
|
|
&& $member->getLevel() === Member::LEVEL_NONE) { |
|
359
|
|
|
$this->parseSubjectNonMemberRemoveClosedCircle($event, $circle, $member); |
|
360
|
|
|
|
|
361
|
|
|
} else { |
|
362
|
|
|
$this->parseCircleMemberAdvancedEvent( |
|
363
|
|
|
$event, $circle, $member, |
|
364
|
|
|
$this->l10n->t('You removed {member} from {circle}'), |
|
365
|
|
|
$this->l10n->t('You have been removed from {circle} by {author}'), |
|
366
|
|
|
$this->l10n->t('{member} has been removed from {circle} by {author}') |
|
367
|
|
|
); |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
throw new FakeException(); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* Parse on Subject 'member_remove' on a closed circle when user were not yet a member. |
|
376
|
|
|
* If status is Invited we say that author cancelled his invitation. |
|
377
|
|
|
* If status is Requested we say that his invitation was rejected. |
|
378
|
|
|
* |
|
379
|
|
|
* @param IEvent $event |
|
380
|
|
|
* @param Circle $circle |
|
381
|
|
|
* @param Member $member |
|
382
|
|
|
* |
|
383
|
|
|
* @return IEvent |
|
384
|
|
|
*/ |
|
385
|
|
|
private function parseSubjectNonMemberRemoveClosedCircle( |
|
386
|
|
|
IEvent &$event, Circle $circle, Member $member |
|
387
|
|
|
) { |
|
388
|
|
|
if ($member->getStatus() === Member::STATUS_REQUEST) { |
|
389
|
|
|
return $this->parseCircleMemberAdvancedEvent( |
|
390
|
|
|
$event, $circle, $member, |
|
391
|
|
|
$this->l10n->t("You dismissed {member}'s request to join {circle}"), |
|
392
|
|
|
$this->l10n->t('Your request to join {circle} has been dismissed by {author}'), |
|
393
|
|
|
$this->l10n->t("{member}'s request to join {circle} has been dismissed by {author}") |
|
394
|
|
|
); |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
return $this->parseCircleMemberAdvancedEvent( |
|
398
|
|
|
$event, $circle, $member, |
|
399
|
|
|
$this->l10n->t("You cancelled {member}'s invitation to join {circle}"), |
|
400
|
|
|
$this->l10n->t('Your invitation to join {circle} has been cancelled by {author}'), |
|
401
|
|
|
$this->l10n->t("{author} cancelled {member}'s invitation to join {circle}") |
|
402
|
|
|
); |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
|
|
406
|
|
|
/** |
|
407
|
|
|
* @param Circle $circle |
|
408
|
|
|
* @param IEvent $event |
|
409
|
|
|
* |
|
410
|
|
|
* @return IEvent |
|
411
|
|
|
*/ |
|
412
|
|
|
private function parseGroupAsModerator(IEvent &$event, Circle $circle) { |
|
413
|
|
|
|
|
414
|
|
|
$params = $event->getSubjectParameters(); |
|
415
|
|
|
$group = Member::fromJSON($params['group']); |
|
416
|
|
|
|
|
417
|
|
|
try { |
|
418
|
|
|
$this->parseGroupLink($event, $circle, $group); |
|
419
|
|
|
$this->parseGroupUnlink($event, $circle, $group); |
|
420
|
|
|
$this->parseGroupLevel($event, $circle, $group); |
|
421
|
|
|
} catch (FakeException $e) { |
|
422
|
|
|
return $event; |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
throw new InvalidArgumentException(); |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
|
|
429
|
|
|
/** |
|
430
|
|
|
* @param Circle $circle |
|
431
|
|
|
* @param IEvent $event |
|
432
|
|
|
* |
|
433
|
|
|
* @return IEvent |
|
434
|
|
|
*/ |
|
435
|
|
View Code Duplication |
private function parseMemberAsModerator(IEvent &$event, Circle $circle) { |
|
|
|
|
|
|
436
|
|
|
|
|
437
|
|
|
$params = $event->getSubjectParameters(); |
|
438
|
|
|
$member = Member::fromJSON($params['member']); |
|
439
|
|
|
|
|
440
|
|
|
try { |
|
441
|
|
|
$this->parseMemberInvited($event, $circle, $member); |
|
442
|
|
|
$this->parseMemberLevel($event, $circle, $member); |
|
443
|
|
|
$this->parseMemberRequestInvitation($event, $circle, $member); |
|
444
|
|
|
$this->parseMemberOwner($event, $circle, $member); |
|
445
|
|
|
} catch (FakeException $e) { |
|
446
|
|
|
return $event; |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
throw new InvalidArgumentException(); |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
|
|
453
|
|
|
/** |
|
454
|
|
|
* @param Circle $circle |
|
455
|
|
|
* @param IEvent $event |
|
456
|
|
|
* |
|
457
|
|
|
* @return IEvent |
|
458
|
|
|
*/ |
|
459
|
|
|
private function parseLinkAsModerator(IEvent &$event, Circle $circle) { |
|
460
|
|
|
|
|
461
|
|
|
$params = $event->getSubjectParameters(); |
|
462
|
|
|
$remote = FederatedLink::fromJSON($params['link']); |
|
463
|
|
|
|
|
464
|
|
|
try { |
|
465
|
|
|
$this->parseLinkRequestSent($event, $circle, $remote); |
|
466
|
|
|
$this->parseLinkRequestReceived($event, $circle, $remote); |
|
467
|
|
|
$this->parseLinkRequestRejected($event, $circle, $remote); |
|
468
|
|
|
$this->parseLinkRequestCanceled($event, $circle, $remote); |
|
469
|
|
|
$this->parseLinkRequestAccepted($event, $circle, $remote); |
|
470
|
|
|
$this->parseLinkRequestRemoved($event, $circle, $remote); |
|
471
|
|
|
$this->parseLinkRequestCanceling($event, $circle, $remote); |
|
472
|
|
|
$this->parseLinkRequestAccepting($event, $circle, $remote); |
|
473
|
|
|
$this->parseLinkUp($event, $circle, $remote); |
|
474
|
|
|
$this->parseLinkDown($event, $circle, $remote); |
|
475
|
|
|
$this->parseLinkRemove($event, $circle, $remote); |
|
476
|
|
|
} catch (FakeException $e) { |
|
477
|
|
|
return $event; |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
throw new InvalidArgumentException(); |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
|
|
484
|
|
|
/** |
|
485
|
|
|
* @param IEvent $event |
|
486
|
|
|
* @param Circle $circle |
|
487
|
|
|
* @param Member $group |
|
488
|
|
|
* |
|
489
|
|
|
* @throws FakeException |
|
490
|
|
|
*/ |
|
491
|
|
View Code Duplication |
private function parseGroupLink(IEvent &$event, Circle $circle, Member $group) { |
|
|
|
|
|
|
492
|
|
|
if ($event->getSubject() !== 'group_link') { |
|
493
|
|
|
return; |
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
$this->parseCircleMemberEvent( |
|
497
|
|
|
$event, $circle, $group, |
|
498
|
|
|
$this->l10n->t('You linked {group} to {circle}'), |
|
499
|
|
|
$this->l10n->t('{group} has been linked to {circle} by {author}') |
|
500
|
|
|
); |
|
501
|
|
|
throw new FakeException(); |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
|
|
|
|
505
|
|
|
/** |
|
506
|
|
|
* @param IEvent $event |
|
507
|
|
|
* @param Circle $circle |
|
508
|
|
|
* @param Member $group |
|
509
|
|
|
* |
|
510
|
|
|
* @throws FakeException |
|
511
|
|
|
*/ |
|
512
|
|
View Code Duplication |
private function parseGroupUnlink(IEvent &$event, Circle $circle, Member $group) { |
|
|
|
|
|
|
513
|
|
|
if ($event->getSubject() !== 'group_unlink') { |
|
514
|
|
|
return; |
|
515
|
|
|
} |
|
516
|
|
|
$this->parseCircleMemberEvent( |
|
517
|
|
|
$event, $circle, $group, |
|
518
|
|
|
$this->l10n->t('You unlinked {group} from {circle}'), |
|
519
|
|
|
$this->l10n->t('{group} has been unlinked from {circle} by {author}') |
|
520
|
|
|
); |
|
521
|
|
|
|
|
522
|
|
|
throw new FakeException(); |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
|
|
|
|
526
|
|
|
/** |
|
527
|
|
|
* @param IEvent $event |
|
528
|
|
|
* @param Circle $circle |
|
529
|
|
|
* @param Member $group |
|
530
|
|
|
* |
|
531
|
|
|
* @throws FakeException |
|
532
|
|
|
*/ |
|
533
|
|
|
private function parseGroupLevel(IEvent &$event, Circle $circle, Member $group) { |
|
534
|
|
|
if ($event->getSubject() !== 'group_level') { |
|
535
|
|
|
return; |
|
536
|
|
|
} |
|
537
|
|
|
|
|
538
|
|
|
$l = $this->l10n; |
|
539
|
|
|
|
|
540
|
|
|
$level = [$l->t($group->getLevelString())]; |
|
541
|
|
|
$this->parseCircleMemberEvent( |
|
542
|
|
|
$event, $circle, $group, |
|
543
|
|
|
$l->t('You changed the level of the linked group {group} in {circle} to %1$s', $level), |
|
544
|
|
|
$l->t('{author} changed the level of the linked group {group} in {circle} to %1$s', $level) |
|
545
|
|
|
); |
|
546
|
|
|
|
|
547
|
|
|
throw new FakeException(); |
|
548
|
|
|
} |
|
549
|
|
|
|
|
550
|
|
|
|
|
551
|
|
|
/** |
|
552
|
|
|
* @param IEvent $event |
|
553
|
|
|
* @param Circle $circle |
|
554
|
|
|
* @param Member $member |
|
555
|
|
|
* |
|
556
|
|
|
* @throws FakeException |
|
557
|
|
|
*/ |
|
558
|
|
View Code Duplication |
private function parseMemberInvited(IEvent &$event, Circle $circle, Member $member) { |
|
|
|
|
|
|
559
|
|
|
if ($event->getSubject() !== 'member_invited') { |
|
560
|
|
|
return; |
|
561
|
|
|
} |
|
562
|
|
|
|
|
563
|
|
|
$this->parseCircleMemberAdvancedEvent( |
|
564
|
|
|
$event, $circle, $member, |
|
565
|
|
|
$this->l10n->t('You invited {member} to join {circle}'), |
|
566
|
|
|
$this->l10n->t('You have been invited to join {circle} by {author}'), |
|
567
|
|
|
$this->l10n->t('{member} has been invited to join {circle} by {author}') |
|
568
|
|
|
); |
|
569
|
|
|
|
|
570
|
|
|
throw new FakeException(); |
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
|
|
574
|
|
|
/** |
|
575
|
|
|
* @param IEvent $event |
|
576
|
|
|
* @param Circle $circle |
|
577
|
|
|
* @param Member $member |
|
578
|
|
|
* |
|
579
|
|
|
* @throws FakeException |
|
580
|
|
|
*/ |
|
581
|
|
View Code Duplication |
private function parseMemberLevel(IEvent &$event, Circle $circle, Member $member) { |
|
|
|
|
|
|
582
|
|
|
if ($event->getSubject() !== 'member_level') { |
|
583
|
|
|
return; |
|
584
|
|
|
} |
|
585
|
|
|
|
|
586
|
|
|
$level = [$this->l10n->t($member->getLevelString())]; |
|
587
|
|
|
$this->parseCircleMemberAdvancedEvent( |
|
588
|
|
|
$event, $circle, $member, |
|
589
|
|
|
$this->l10n->t('You changed {member}\'s level in {circle} to %1$s', $level), |
|
590
|
|
|
$this->l10n->t('{author} changed your level in {circle} to %1$s', $level), |
|
591
|
|
|
$this->l10n->t('{author} changed {member}\'s level in {circle} to %1$s', $level) |
|
592
|
|
|
); |
|
593
|
|
|
|
|
594
|
|
|
throw new FakeException(); |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
|
|
598
|
|
|
/** |
|
599
|
|
|
* @param IEvent $event |
|
600
|
|
|
* @param Circle $circle |
|
601
|
|
|
* @param Member $member |
|
602
|
|
|
* |
|
603
|
|
|
* @throws FakeException |
|
604
|
|
|
*/ |
|
605
|
|
View Code Duplication |
private function parseMemberRequestInvitation(IEvent &$event, Circle $circle, Member $member) { |
|
|
|
|
|
|
606
|
|
|
if ($event->getSubject() !== 'member_request_invitation') { |
|
607
|
|
|
return; |
|
608
|
|
|
} |
|
609
|
|
|
|
|
610
|
|
|
$this->parseMemberEvent( |
|
611
|
|
|
$event, $circle, $member, |
|
612
|
|
|
$this->l10n->t('You sent a request to join {circle}'), |
|
613
|
|
|
$this->l10n->t('{member} sent a request to join {circle}') |
|
614
|
|
|
); |
|
615
|
|
|
|
|
616
|
|
|
throw new FakeException(); |
|
617
|
|
|
} |
|
618
|
|
|
|
|
619
|
|
|
|
|
620
|
|
|
/** |
|
621
|
|
|
* @param IEvent $event |
|
622
|
|
|
* @param Circle $circle |
|
623
|
|
|
* @param Member $member |
|
624
|
|
|
* |
|
625
|
|
|
* @throws FakeException |
|
626
|
|
|
*/ |
|
627
|
|
View Code Duplication |
private function parseMemberOwner(IEvent &$event, Circle $circle, Member $member) { |
|
|
|
|
|
|
628
|
|
|
if ($event->getSubject() !== 'member_owner') { |
|
629
|
|
|
return; |
|
630
|
|
|
} |
|
631
|
|
|
|
|
632
|
|
|
$this->parseMemberEvent( |
|
633
|
|
|
$event, $circle, $member, |
|
634
|
|
|
$this->l10n->t('You are the new owner of {circle}'), |
|
635
|
|
|
$this->l10n->t('{member} is the new owner of {circle}') |
|
636
|
|
|
); |
|
637
|
|
|
throw new FakeException(); |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
|
|
641
|
|
|
/** |
|
642
|
|
|
* @param IEvent $event |
|
643
|
|
|
* @param Circle $circle |
|
644
|
|
|
* @param FederatedLink $remote |
|
645
|
|
|
* |
|
646
|
|
|
* @throws FakeException |
|
647
|
|
|
*/ |
|
648
|
|
View Code Duplication |
private function parseLinkRequestSent(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
|
|
|
|
|
649
|
|
|
if ($event->getSubject() !== 'link_request_sent') { |
|
650
|
|
|
return; |
|
651
|
|
|
} |
|
652
|
|
|
|
|
653
|
|
|
$this->parseCircleEvent( |
|
654
|
|
|
$event, $circle, $remote, |
|
655
|
|
|
$this->l10n->t('You sent a request to link {circle} with {remote}'), |
|
656
|
|
|
$this->l10n->t('{author} sent a request to link {circle} with {remote}') |
|
657
|
|
|
); |
|
658
|
|
|
|
|
659
|
|
|
throw new FakeException(); |
|
660
|
|
|
} |
|
661
|
|
|
|
|
662
|
|
|
|
|
663
|
|
|
/** |
|
664
|
|
|
* @param IEvent $event |
|
665
|
|
|
* @param Circle $circle |
|
666
|
|
|
* @param FederatedLink $remote |
|
667
|
|
|
* |
|
668
|
|
|
* @throws FakeException |
|
669
|
|
|
*/ |
|
670
|
|
View Code Duplication |
private function parseLinkRequestReceived(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
|
|
|
|
|
671
|
|
|
if ($event->getSubject() !== 'link_request_received') { |
|
672
|
|
|
return; |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
|
$this->parseLinkEvent( |
|
676
|
|
|
$event, $circle, $remote, $this->l10n->t('{remote} requested a link with {circle}') |
|
677
|
|
|
); |
|
678
|
|
|
|
|
679
|
|
|
throw new FakeException(); |
|
680
|
|
|
} |
|
681
|
|
|
|
|
682
|
|
|
|
|
683
|
|
|
/** |
|
684
|
|
|
* @param IEvent $event |
|
685
|
|
|
* @param Circle $circle |
|
686
|
|
|
* @param FederatedLink $remote |
|
687
|
|
|
* |
|
688
|
|
|
* @throws FakeException |
|
689
|
|
|
*/ |
|
690
|
|
View Code Duplication |
private function parseLinkRequestRejected(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
|
|
|
|
|
691
|
|
|
if ($event->getSubject() !== 'link_request_rejected') { |
|
692
|
|
|
return; |
|
693
|
|
|
} |
|
694
|
|
|
|
|
695
|
|
|
$this->parseLinkEvent( |
|
696
|
|
|
$event, $circle, $remote, |
|
697
|
|
|
$this->l10n->t('The request to link {circle} with {remote} has been rejected') |
|
698
|
|
|
); |
|
699
|
|
|
|
|
700
|
|
|
throw new FakeException(); |
|
701
|
|
|
} |
|
702
|
|
|
|
|
703
|
|
|
|
|
704
|
|
|
/** |
|
705
|
|
|
* @param IEvent $event |
|
706
|
|
|
* @param Circle $circle |
|
707
|
|
|
* @param FederatedLink $remote |
|
708
|
|
|
* |
|
709
|
|
|
* @throws FakeException |
|
710
|
|
|
*/ |
|
711
|
|
View Code Duplication |
private function parseLinkRequestCanceled(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
|
|
|
|
|
712
|
|
|
if ($event->getSubject() !== 'link_request_canceled') { |
|
713
|
|
|
return; |
|
714
|
|
|
} |
|
715
|
|
|
|
|
716
|
|
|
$this->parseLinkEvent( |
|
717
|
|
|
$event, $circle, $remote, |
|
718
|
|
|
$this->l10n->t( |
|
719
|
|
|
'The request to link {remote} with {circle} has been canceled remotely' |
|
720
|
|
|
) |
|
721
|
|
|
); |
|
722
|
|
|
|
|
723
|
|
|
throw new FakeException(); |
|
724
|
|
|
} |
|
725
|
|
|
|
|
726
|
|
|
|
|
727
|
|
|
/** |
|
728
|
|
|
* @param IEvent $event |
|
729
|
|
|
* @param Circle $circle |
|
730
|
|
|
* @param FederatedLink $remote |
|
731
|
|
|
* |
|
732
|
|
|
* @throws FakeException |
|
733
|
|
|
*/ |
|
734
|
|
View Code Duplication |
private function parseLinkRequestAccepted(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
|
|
|
|
|
735
|
|
|
if ($event->getSubject() !== 'link_request_accepted') { |
|
736
|
|
|
return; |
|
737
|
|
|
} |
|
738
|
|
|
|
|
739
|
|
|
$this->parseLinkEvent( |
|
740
|
|
|
$event, $circle, $remote, |
|
741
|
|
|
$this->l10n->t('The request to link {circle} with {remote} has been accepted') |
|
742
|
|
|
); |
|
743
|
|
|
|
|
744
|
|
|
throw new FakeException(); |
|
745
|
|
|
} |
|
746
|
|
|
|
|
747
|
|
|
|
|
748
|
|
|
/** |
|
749
|
|
|
* @param IEvent $event |
|
750
|
|
|
* @param Circle $circle |
|
751
|
|
|
* @param FederatedLink $remote |
|
752
|
|
|
* |
|
753
|
|
|
* @throws FakeException |
|
754
|
|
|
*/ |
|
755
|
|
View Code Duplication |
private function parseLinkRequestRemoved(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
|
|
|
|
|
756
|
|
|
if ($event->getSubject() !== 'link_request_removed') { |
|
757
|
|
|
return; |
|
758
|
|
|
} |
|
759
|
|
|
|
|
760
|
|
|
$this->parseCircleEvent( |
|
761
|
|
|
$event, $circle, $remote, |
|
762
|
|
|
$this->l10n->t('You dismissed the request to link {remote} with {circle}'), |
|
763
|
|
|
$this->l10n->t('{author} dismissed the request to link {remote} with {circle}') |
|
764
|
|
|
); |
|
765
|
|
|
|
|
766
|
|
|
throw new FakeException(); |
|
767
|
|
|
} |
|
768
|
|
|
|
|
769
|
|
|
|
|
770
|
|
|
/** |
|
771
|
|
|
* @param IEvent $event |
|
772
|
|
|
* @param Circle $circle |
|
773
|
|
|
* @param FederatedLink $remote |
|
774
|
|
|
* |
|
775
|
|
|
* @throws FakeException |
|
776
|
|
|
*/ |
|
777
|
|
View Code Duplication |
private function parseLinkRequestCanceling(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
|
|
|
|
|
778
|
|
|
if ($event->getSubject() !== 'link_request_canceling') { |
|
779
|
|
|
return; |
|
780
|
|
|
} |
|
781
|
|
|
|
|
782
|
|
|
$this->parseCircleEvent( |
|
783
|
|
|
$event, $circle, $remote, |
|
784
|
|
|
$this->l10n->t('You canceled the request to link {circle} with {remote}'), |
|
785
|
|
|
$this->l10n->t('{author} canceled the request to link {circle} with {remote}') |
|
786
|
|
|
); |
|
787
|
|
|
|
|
788
|
|
|
throw new FakeException(); |
|
789
|
|
|
} |
|
790
|
|
|
|
|
791
|
|
|
|
|
792
|
|
|
/** |
|
793
|
|
|
* @param IEvent $event |
|
794
|
|
|
* @param Circle $circle |
|
795
|
|
|
* @param FederatedLink $remote |
|
796
|
|
|
* |
|
797
|
|
|
* @throws FakeException |
|
798
|
|
|
*/ |
|
799
|
|
View Code Duplication |
private function parseLinkRequestAccepting(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
|
|
|
|
|
800
|
|
|
if ($event->getSubject() !== 'link_request_accepting') { |
|
801
|
|
|
return; |
|
802
|
|
|
} |
|
803
|
|
|
|
|
804
|
|
|
$this->parseCircleEvent( |
|
805
|
|
|
$event, $circle, $remote, |
|
806
|
|
|
$this->l10n->t('You accepted the request to link {remote} with {circle}'), |
|
807
|
|
|
$this->l10n->t('{author} accepted the request to link {remote} with {circle}') |
|
808
|
|
|
); |
|
809
|
|
|
|
|
810
|
|
|
throw new FakeException(); |
|
811
|
|
|
} |
|
812
|
|
|
|
|
813
|
|
|
|
|
814
|
|
|
/** |
|
815
|
|
|
* @param IEvent $event |
|
816
|
|
|
* @param Circle $circle |
|
817
|
|
|
* @param FederatedLink $remote |
|
818
|
|
|
* |
|
819
|
|
|
* @throws FakeException |
|
820
|
|
|
*/ |
|
821
|
|
View Code Duplication |
private function parseLinkUp(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
|
|
|
|
|
822
|
|
|
if ($event->getSubject() !== 'link_up') { |
|
823
|
|
|
return; |
|
824
|
|
|
} |
|
825
|
|
|
|
|
826
|
|
|
$this->parseLinkEvent( |
|
827
|
|
|
$event, $circle, $remote, |
|
828
|
|
|
$this->l10n->t('A link between {circle} and {remote} is now up and running') |
|
829
|
|
|
); |
|
830
|
|
|
|
|
831
|
|
|
throw new FakeException(); |
|
832
|
|
|
} |
|
833
|
|
|
|
|
834
|
|
|
|
|
835
|
|
|
/** |
|
836
|
|
|
* @param IEvent $event |
|
837
|
|
|
* @param Circle $circle |
|
838
|
|
|
* @param FederatedLink $remote |
|
839
|
|
|
* |
|
840
|
|
|
* @throws FakeException |
|
841
|
|
|
*/ |
|
842
|
|
View Code Duplication |
private function parseLinkDown(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
|
|
|
|
|
843
|
|
|
if ($event->getSubject() !== 'link_down') { |
|
844
|
|
|
return; |
|
845
|
|
|
} |
|
846
|
|
|
|
|
847
|
|
|
$this->parseLinkEvent( |
|
848
|
|
|
$event, $circle, $remote, |
|
849
|
|
|
$this->l10n->t( |
|
850
|
|
|
'The link between {circle} and {remote} has been shutdown remotely' |
|
851
|
|
|
) |
|
852
|
|
|
); |
|
853
|
|
|
|
|
854
|
|
|
throw new FakeException(); |
|
855
|
|
|
} |
|
856
|
|
|
|
|
857
|
|
|
|
|
858
|
|
|
/** |
|
859
|
|
|
* @param IEvent $event |
|
860
|
|
|
* @param Circle $circle |
|
861
|
|
|
* @param FederatedLink $remote |
|
862
|
|
|
* |
|
863
|
|
|
* @throws FakeException |
|
864
|
|
|
*/ |
|
865
|
|
View Code Duplication |
private function parseLinkRemove(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
|
|
|
|
|
866
|
|
|
if ($event->getSubject() !== 'link_remove') { |
|
867
|
|
|
return; |
|
868
|
|
|
} |
|
869
|
|
|
|
|
870
|
|
|
$this->parseCircleEvent( |
|
871
|
|
|
$event, $circle, $remote, |
|
872
|
|
|
$this->l10n->t('You closed the link between {circle} and {remote}'), |
|
873
|
|
|
$this->l10n->t('{author} closed the link between {circle} and {remote}') |
|
874
|
|
|
); |
|
875
|
|
|
|
|
876
|
|
|
throw new FakeException(); |
|
877
|
|
|
} |
|
878
|
|
|
} |
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.