|
37 | 37 | use OCA\Talk\TalkSession; |
38 | 38 | use OCA\Talk\TInitialState; |
39 | 39 | use OCA\Viewer\Event\LoadViewer; |
| 40 | +use OCP\Accounts\IAccountManager; |
40 | 41 | use OCP\App\IAppManager; |
41 | 42 | use OCP\AppFramework\Controller; |
42 | 43 | use OCP\AppFramework\Http; |
|
67 | 68 | use OCP\IUserSession; |
68 | 69 | use OCP\L10N\IFactory; |
69 | 70 | use OCP\Notification\IManager as INotificationManager; |
| 71 | +use OCP\Profile\IProfileManager; |
70 | 72 | use OCP\Security\Bruteforce\IThrottler; |
71 | 73 | use OCP\Security\RateLimiting\ILimiter; |
72 | 74 | use OCP\Security\RateLimiting\IRateLimitExceededException; |
@@ -98,6 +100,7 @@ public function __construct( |
98 | 100 | IConfig $serverConfig, |
99 | 101 | IGroupManager $groupManager, |
100 | 102 | protected IUserManager $userManager, |
| 103 | + protected IProfileManager $profileManager, |
101 | 104 | protected ILimiter $limiter, |
102 | 105 | protected IFactory $l10nFactory, |
103 | 106 | ) { |
@@ -150,25 +153,26 @@ public function duplicateSession(): Response { |
150 | 153 | return $this->index(); |
151 | 154 | } |
152 | 155 |
|
153 | | - protected function createPrivateRoom(string $targetUserId): ?Room { |
| 156 | + /** |
| 157 | + * @throws \InvalidArgumentException |
| 158 | + */ |
| 159 | + protected function createPrivateRoom(string $targetUserId): Room { |
154 | 160 | $user = $this->userManager->get($targetUserId); |
155 | 161 | if (!$user instanceof IUser) { |
156 | | - return null; |
| 162 | + throw new \InvalidArgumentException('user'); |
157 | 163 | } |
158 | 164 |
|
159 | | - $l = $this->l10nFactory->get('spreed', $this->l10nFactory->getUserLanguage($user)); |
160 | | - |
161 | | - try { |
162 | | - $room = $this->roomService->createConversation( |
163 | | - Room::TYPE_PUBLIC, |
164 | | - $l->t('Contact request'), |
165 | | - $user, |
166 | | - ); |
167 | | - } catch (\InvalidArgumentException) { |
168 | | - return null; |
| 165 | + if ($this->profileManager->isProfileFieldVisible('talk', $user, null)) { |
| 166 | + throw new \InvalidArgumentException('profile'); |
169 | 167 | } |
170 | 168 |
|
171 | | - return $room; |
| 169 | + $l = $this->l10nFactory->get('spreed', $this->l10nFactory->getUserLanguage($user)); |
| 170 | + |
| 171 | + return $this->roomService->createConversation( |
| 172 | + Room::TYPE_PUBLIC, |
| 173 | + $l->t('Contact request'), |
| 174 | + $user, |
| 175 | + ); |
172 | 176 | } |
173 | 177 |
|
174 | 178 | /** |
@@ -199,8 +203,9 @@ public function index(string $token = '', string $callUser = '', string $passwor |
199 | 203 | return new TooManyRequestsResponse(); |
200 | 204 | } |
201 | 205 |
|
202 | | - $room = $this->createPrivateRoom($callUser); |
203 | | - if ($room === null) { |
| 206 | + try { |
| 207 | + $room = $this->createPrivateRoom($callUser); |
| 208 | + } catch (\InvalidArgumentException) { |
204 | 209 | $response = new TemplateResponse('core', '404-profile', [], TemplateResponse::RENDER_AS_GUEST); |
205 | 210 | $response->throttle(['action' => 'callUser', 'callUser' => $callUser]); |
206 | 211 | return $response; |
|
0 commit comments