1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Circles - Bring cloud-users closer together. |
8
|
|
|
* |
9
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
10
|
|
|
* later. See the COPYING file. |
11
|
|
|
* |
12
|
|
|
* @author Maxence Lange <[email protected]> |
13
|
|
|
* @copyright 2021 |
14
|
|
|
* @license GNU AGPL version 3 or any later version |
15
|
|
|
* |
16
|
|
|
* This program is free software: you can redistribute it and/or modify |
17
|
|
|
* it under the terms of the GNU Affero General Public License as |
18
|
|
|
* published by the Free Software Foundation, either version 3 of the |
19
|
|
|
* License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU Affero General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU Affero General Public License |
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
namespace OCA\Circles\Listeners; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
use daita\MySmallPhpTools\Model\SimpleDataStore; |
36
|
|
|
use Exception; |
37
|
|
|
use OCA\Circles\Db\CircleRequest; |
38
|
|
|
use OCA\Circles\Exceptions\ContactAddressBookNotFoundException; |
39
|
|
|
use OCA\Circles\Exceptions\ContactFormatException; |
40
|
|
|
use OCA\Circles\Exceptions\ContactNotFoundException; |
41
|
|
|
use OCA\Circles\Exceptions\FederatedUserException; |
42
|
|
|
use OCA\Circles\Exceptions\FederatedUserNotFoundException; |
43
|
|
|
use OCA\Circles\Exceptions\InitiatorNotFoundException; |
44
|
|
|
use OCA\Circles\Exceptions\InvalidIdException; |
45
|
|
|
use OCA\Circles\Exceptions\RequestBuilderException; |
46
|
|
|
use OCA\Circles\Exceptions\SingleCircleNotFoundException; |
47
|
|
|
use OCA\Circles\FederatedItems\MemberDisplayName; |
48
|
|
|
use OCA\Circles\Model\Federated\FederatedEvent; |
49
|
|
|
use OCA\Circles\Service\CircleService; |
50
|
|
|
use OCA\Circles\Service\FederatedEventService; |
51
|
|
|
use OCA\Circles\Service\FederatedUserService; |
52
|
|
|
use OCP\IUser; |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Class DeprecatedListener |
57
|
|
|
* |
58
|
|
|
* some events are still using the old dispatcher. |
59
|
|
|
* |
60
|
|
|
* @package OCA\Circles\Events |
61
|
|
|
*/ |
62
|
|
|
class DeprecatedListener { |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** @var CircleRequest */ |
66
|
|
|
private $circleRequest; |
67
|
|
|
|
68
|
|
|
/** @var FederatedEventService */ |
69
|
|
|
private $federatedEventService; |
70
|
|
|
|
71
|
|
|
/** @var FederatedUserService */ |
72
|
|
|
private $federatedUserService; |
73
|
|
|
|
74
|
|
|
/** @var CircleService */ |
75
|
|
|
private $circleService; |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* DeprecatedListener constructor. |
80
|
|
|
* |
81
|
|
|
* @param CircleRequest $circleRequest |
82
|
|
|
* @param FederatedUserService $federatedUserService |
83
|
|
|
* @param FederatedEventService $federatedEventService |
84
|
|
|
* @param CircleService $circleService |
85
|
|
|
*/ |
86
|
|
|
public function __construct( |
87
|
|
|
CircleRequest $circleRequest, |
88
|
|
|
FederatedUserService $federatedUserService, |
89
|
|
|
FederatedEventService $federatedEventService, |
90
|
|
|
CircleService $circleService |
91
|
|
|
) { |
92
|
|
|
$this->circleRequest = $circleRequest; |
93
|
|
|
$this->federatedUserService = $federatedUserService; |
94
|
|
|
$this->federatedEventService = $federatedEventService; |
95
|
|
|
$this->circleService = $circleService; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @throws ContactAddressBookNotFoundException |
101
|
|
|
* @throws ContactFormatException |
102
|
|
|
* @throws FederatedUserNotFoundException |
103
|
|
|
* @throws ContactNotFoundException |
104
|
|
|
* @throws SingleCircleNotFoundException |
105
|
|
|
* @throws RequestBuilderException |
106
|
|
|
* @throws InvalidIdException |
107
|
|
|
* @throws FederatedUserException |
108
|
|
|
* @throws InitiatorNotFoundException |
109
|
|
|
*/ |
110
|
|
|
public function userAccountUpdated(IUser $user) { |
111
|
|
|
$federatedUser = $this->federatedUserService->getLocalFederatedUser($user->getUID()); |
112
|
|
|
|
113
|
|
|
if ($federatedUser->getDisplayName() === $user->getUID()) { |
114
|
|
|
return; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$this->circleRequest->updateDisplayName($federatedUser->getSingleId(), $user->getDisplayName()); |
118
|
|
|
$this->federatedUserService->setCurrentUser($federatedUser); |
119
|
|
|
|
120
|
|
|
$params = new SimpleDataStore(['includeSystemCircles' => true]); |
121
|
|
|
$circles = $this->circleService->getCircles(null, null, $params); |
122
|
|
|
|
123
|
|
|
foreach ($circles as $circle) { |
124
|
|
|
$event = new FederatedEvent(MemberDisplayName::class); |
125
|
|
|
$event->setCircle($circle); |
126
|
|
|
$event->getParams()->s('displayName', $user->getDisplayName()); |
127
|
|
|
|
128
|
|
|
try { |
129
|
|
|
$this->federatedEventService->newEvent($event); |
130
|
|
|
} catch (Exception $e) { |
|
|
|
|
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|