@@ -43,508 +43,508 @@ |
||
| 43 | 43 | |
| 44 | 44 | class Provider implements IProvider { |
| 45 | 45 | |
| 46 | - /** @var IFactory */ |
|
| 47 | - protected $languageFactory; |
|
| 48 | - |
|
| 49 | - /** @var IL10N */ |
|
| 50 | - protected $l; |
|
| 51 | - /** @var IL10N */ |
|
| 52 | - protected $activityLang; |
|
| 53 | - |
|
| 54 | - /** @var IURLGenerator */ |
|
| 55 | - protected $url; |
|
| 56 | - |
|
| 57 | - /** @var IManager */ |
|
| 58 | - protected $activityManager; |
|
| 59 | - |
|
| 60 | - /** @var IUserManager */ |
|
| 61 | - protected $userManager; |
|
| 62 | - |
|
| 63 | - /** @var IRootFolder */ |
|
| 64 | - protected $rootFolder; |
|
| 65 | - |
|
| 66 | - /** @var IEventMerger */ |
|
| 67 | - protected $eventMerger; |
|
| 68 | - |
|
| 69 | - /** @var ICloudIdManager */ |
|
| 70 | - protected $cloudIdManager; |
|
| 71 | - |
|
| 72 | - /** @var IContactsManager */ |
|
| 73 | - protected $contactsManager; |
|
| 74 | - |
|
| 75 | - /** @var string[] cached displayNames - key is the cloud id and value the displayname */ |
|
| 76 | - protected $displayNames = []; |
|
| 77 | - |
|
| 78 | - protected $fileIsEncrypted = false; |
|
| 79 | - |
|
| 80 | - public function __construct(IFactory $languageFactory, |
|
| 81 | - IURLGenerator $url, |
|
| 82 | - IManager $activityManager, |
|
| 83 | - IUserManager $userManager, |
|
| 84 | - IRootFolder $rootFolder, |
|
| 85 | - ICloudIdManager $cloudIdManager, |
|
| 86 | - IContactsManager $contactsManager, |
|
| 87 | - IEventMerger $eventMerger) { |
|
| 88 | - $this->languageFactory = $languageFactory; |
|
| 89 | - $this->url = $url; |
|
| 90 | - $this->activityManager = $activityManager; |
|
| 91 | - $this->userManager = $userManager; |
|
| 92 | - $this->rootFolder = $rootFolder; |
|
| 93 | - $this->cloudIdManager = $cloudIdManager; |
|
| 94 | - $this->contactsManager = $contactsManager; |
|
| 95 | - $this->eventMerger = $eventMerger; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @param string $language |
|
| 100 | - * @param IEvent $event |
|
| 101 | - * @param IEvent|null $previousEvent |
|
| 102 | - * @return IEvent |
|
| 103 | - * @throws \InvalidArgumentException |
|
| 104 | - * @since 11.0.0 |
|
| 105 | - */ |
|
| 106 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 107 | - if ($event->getApp() !== 'files') { |
|
| 108 | - throw new \InvalidArgumentException(); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $this->l = $this->languageFactory->get('files', $language); |
|
| 112 | - $this->activityLang = $this->languageFactory->get('activity', $language); |
|
| 113 | - |
|
| 114 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 115 | - try { |
|
| 116 | - return $this->parseShortVersion($event, $previousEvent); |
|
| 117 | - } catch (\InvalidArgumentException $e) { |
|
| 118 | - // Ignore and simply use the long version... |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return $this->parseLongVersion($event, $previousEvent); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - protected function setIcon(IEvent $event, string $icon, string $app = 'files') { |
|
| 126 | - if ($this->activityManager->getRequirePNG()) { |
|
| 127 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon . '.png'))); |
|
| 128 | - } else { |
|
| 129 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon . '.svg'))); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @param IEvent $event |
|
| 135 | - * @param IEvent|null $previousEvent |
|
| 136 | - * @return IEvent |
|
| 137 | - * @throws \InvalidArgumentException |
|
| 138 | - * @since 11.0.0 |
|
| 139 | - */ |
|
| 140 | - public function parseShortVersion(IEvent $event, IEvent $previousEvent = null) { |
|
| 141 | - $parsedParameters = $this->getParameters($event); |
|
| 142 | - |
|
| 143 | - if ($event->getSubject() === 'created_by') { |
|
| 144 | - $subject = $this->l->t('Created by {user}'); |
|
| 145 | - $this->setIcon($event, 'add-color'); |
|
| 146 | - } else if ($event->getSubject() === 'changed_by') { |
|
| 147 | - $subject = $this->l->t('Changed by {user}'); |
|
| 148 | - $this->setIcon($event, 'change'); |
|
| 149 | - } else if ($event->getSubject() === 'deleted_by') { |
|
| 150 | - $subject = $this->l->t('Deleted by {user}'); |
|
| 151 | - $this->setIcon($event, 'delete-color'); |
|
| 152 | - } else if ($event->getSubject() === 'restored_by') { |
|
| 153 | - $subject = $this->l->t('Restored by {user}'); |
|
| 154 | - $this->setIcon($event, 'actions/history', 'core'); |
|
| 155 | - } else if ($event->getSubject() === 'renamed_by') { |
|
| 156 | - $subject = $this->l->t('Renamed by {user}'); |
|
| 157 | - $this->setIcon($event, 'change'); |
|
| 158 | - } else if ($event->getSubject() === 'moved_by') { |
|
| 159 | - $subject = $this->l->t('Moved by {user}'); |
|
| 160 | - $this->setIcon($event, 'change'); |
|
| 161 | - } else { |
|
| 162 | - throw new \InvalidArgumentException(); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - if (!isset($parsedParameters['user'])) { |
|
| 166 | - // External user via public link share |
|
| 167 | - $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
| 171 | - |
|
| 172 | - return $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @param IEvent $event |
|
| 177 | - * @param IEvent|null $previousEvent |
|
| 178 | - * @return IEvent |
|
| 179 | - * @throws \InvalidArgumentException |
|
| 180 | - * @since 11.0.0 |
|
| 181 | - */ |
|
| 182 | - public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
|
| 183 | - $this->fileIsEncrypted = false; |
|
| 184 | - $parsedParameters = $this->getParameters($event); |
|
| 185 | - |
|
| 186 | - if ($event->getSubject() === 'created_self') { |
|
| 187 | - $subject = $this->l->t('You created {file}'); |
|
| 188 | - if ($this->fileIsEncrypted) { |
|
| 189 | - $subject = $this->l->t('You created an encrypted file in {file}'); |
|
| 190 | - } |
|
| 191 | - $this->setIcon($event, 'add-color'); |
|
| 192 | - } else if ($event->getSubject() === 'created_by') { |
|
| 193 | - $subject = $this->l->t('{user} created {file}'); |
|
| 194 | - if ($this->fileIsEncrypted) { |
|
| 195 | - $subject = $this->l->t('{user} created an encrypted file in {file}'); |
|
| 196 | - } |
|
| 197 | - $this->setIcon($event, 'add-color'); |
|
| 198 | - } else if ($event->getSubject() === 'created_public') { |
|
| 199 | - $subject = $this->l->t('{file} was created in a public folder'); |
|
| 200 | - $this->setIcon($event, 'add-color'); |
|
| 201 | - } else if ($event->getSubject() === 'changed_self') { |
|
| 202 | - $subject = $this->l->t('You changed {file}'); |
|
| 203 | - if ($this->fileIsEncrypted) { |
|
| 204 | - $subject = $this->l->t('You changed an encrypted file in {file}'); |
|
| 205 | - } |
|
| 206 | - $this->setIcon($event, 'change'); |
|
| 207 | - } else if ($event->getSubject() === 'changed_by') { |
|
| 208 | - $subject = $this->l->t('{user} changed {file}'); |
|
| 209 | - if ($this->fileIsEncrypted) { |
|
| 210 | - $subject = $this->l->t('{user} changed an encrypted file in {file}'); |
|
| 211 | - } |
|
| 212 | - $this->setIcon($event, 'change'); |
|
| 213 | - } else if ($event->getSubject() === 'deleted_self') { |
|
| 214 | - $subject = $this->l->t('You deleted {file}'); |
|
| 215 | - if ($this->fileIsEncrypted) { |
|
| 216 | - $subject = $this->l->t('You deleted an encrypted file in {file}'); |
|
| 217 | - } |
|
| 218 | - $this->setIcon($event, 'delete-color'); |
|
| 219 | - } else if ($event->getSubject() === 'deleted_by') { |
|
| 220 | - $subject = $this->l->t('{user} deleted {file}'); |
|
| 221 | - if ($this->fileIsEncrypted) { |
|
| 222 | - $subject = $this->l->t('{user} deleted an encrypted file in {file}'); |
|
| 223 | - } |
|
| 224 | - $this->setIcon($event, 'delete-color'); |
|
| 225 | - } else if ($event->getSubject() === 'restored_self') { |
|
| 226 | - $subject = $this->l->t('You restored {file}'); |
|
| 227 | - $this->setIcon($event, 'actions/history', 'core'); |
|
| 228 | - } else if ($event->getSubject() === 'restored_by') { |
|
| 229 | - $subject = $this->l->t('{user} restored {file}'); |
|
| 230 | - $this->setIcon($event, 'actions/history', 'core'); |
|
| 231 | - } else if ($event->getSubject() === 'renamed_self') { |
|
| 232 | - $subject = $this->l->t('You renamed {oldfile} to {newfile}'); |
|
| 233 | - $this->setIcon($event, 'change'); |
|
| 234 | - } else if ($event->getSubject() === 'renamed_by') { |
|
| 235 | - $subject = $this->l->t('{user} renamed {oldfile} to {newfile}'); |
|
| 236 | - $this->setIcon($event, 'change'); |
|
| 237 | - } else if ($event->getSubject() === 'moved_self') { |
|
| 238 | - $subject = $this->l->t('You moved {oldfile} to {newfile}'); |
|
| 239 | - $this->setIcon($event, 'change'); |
|
| 240 | - } else if ($event->getSubject() === 'moved_by') { |
|
| 241 | - $subject = $this->l->t('{user} moved {oldfile} to {newfile}'); |
|
| 242 | - $this->setIcon($event, 'change'); |
|
| 243 | - } else { |
|
| 244 | - throw new \InvalidArgumentException(); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - if ($this->fileIsEncrypted) { |
|
| 248 | - $event->setSubject($event->getSubject() . '_enc', $event->getSubjectParameters()); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - if (!isset($parsedParameters['user'])) { |
|
| 252 | - // External user via public link share |
|
| 253 | - $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
| 257 | - |
|
| 258 | - if ($event->getSubject() === 'moved_self' || $event->getSubject() === 'moved_by') { |
|
| 259 | - $event = $this->eventMerger->mergeEvents('oldfile', $event, $previousEvent); |
|
| 260 | - } else { |
|
| 261 | - $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - if ($event->getChildEvent() === null) { |
|
| 265 | - // Couldn't group by file, maybe we can group by user |
|
| 266 | - $event = $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - return $event; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 273 | - $placeholders = $replacements = []; |
|
| 274 | - foreach ($parameters as $placeholder => $parameter) { |
|
| 275 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 276 | - if ($parameter['type'] === 'file') { |
|
| 277 | - $replacements[] = $parameter['path']; |
|
| 278 | - } else { |
|
| 279 | - $replacements[] = $parameter['name']; |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 284 | - ->setRichSubject($subject, $parameters); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @param IEvent $event |
|
| 289 | - * @return array |
|
| 290 | - * @throws \InvalidArgumentException |
|
| 291 | - */ |
|
| 292 | - protected function getParameters(IEvent $event) { |
|
| 293 | - $parameters = $event->getSubjectParameters(); |
|
| 294 | - switch ($event->getSubject()) { |
|
| 295 | - case 'created_self': |
|
| 296 | - case 'created_public': |
|
| 297 | - case 'changed_self': |
|
| 298 | - case 'deleted_self': |
|
| 299 | - case 'restored_self': |
|
| 300 | - return [ |
|
| 301 | - 'file' => $this->getFile($parameters[0], $event), |
|
| 302 | - ]; |
|
| 303 | - case 'created_by': |
|
| 304 | - case 'changed_by': |
|
| 305 | - case 'deleted_by': |
|
| 306 | - case 'restored_by': |
|
| 307 | - if ($parameters[1] === '') { |
|
| 308 | - // External user via public link share |
|
| 309 | - return [ |
|
| 310 | - 'file' => $this->getFile($parameters[0], $event), |
|
| 311 | - ]; |
|
| 312 | - } |
|
| 313 | - return [ |
|
| 314 | - 'file' => $this->getFile($parameters[0], $event), |
|
| 315 | - 'user' => $this->getUser($parameters[1]), |
|
| 316 | - ]; |
|
| 317 | - case 'renamed_self': |
|
| 318 | - case 'moved_self': |
|
| 319 | - return [ |
|
| 320 | - 'newfile' => $this->getFile($parameters[0]), |
|
| 321 | - 'oldfile' => $this->getFile($parameters[1]), |
|
| 322 | - ]; |
|
| 323 | - case 'renamed_by': |
|
| 324 | - case 'moved_by': |
|
| 325 | - if ($parameters[1] === '') { |
|
| 326 | - // External user via public link share |
|
| 327 | - return [ |
|
| 328 | - 'newfile' => $this->getFile($parameters[0]), |
|
| 329 | - 'oldfile' => $this->getFile($parameters[2]), |
|
| 330 | - ]; |
|
| 331 | - } |
|
| 332 | - return [ |
|
| 333 | - 'newfile' => $this->getFile($parameters[0]), |
|
| 334 | - 'user' => $this->getUser($parameters[1]), |
|
| 335 | - 'oldfile' => $this->getFile($parameters[2]), |
|
| 336 | - ]; |
|
| 337 | - } |
|
| 338 | - return []; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * @param array|string $parameter |
|
| 343 | - * @param IEvent|null $event |
|
| 344 | - * @return array |
|
| 345 | - * @throws \InvalidArgumentException |
|
| 346 | - */ |
|
| 347 | - protected function getFile($parameter, IEvent $event = null) { |
|
| 348 | - if (is_array($parameter)) { |
|
| 349 | - $path = reset($parameter); |
|
| 350 | - $id = (string) key($parameter); |
|
| 351 | - } else if ($event !== null) { |
|
| 352 | - // Legacy from before ownCloud 8.2 |
|
| 353 | - $path = $parameter; |
|
| 354 | - $id = $event->getObjectId(); |
|
| 355 | - } else { |
|
| 356 | - throw new \InvalidArgumentException('Could not generate file parameter'); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - $encryptionContainer = $this->getEndToEndEncryptionContainer($id, $path); |
|
| 360 | - if ($encryptionContainer instanceof Folder) { |
|
| 361 | - $this->fileIsEncrypted = true; |
|
| 362 | - try { |
|
| 363 | - $fullPath = rtrim($encryptionContainer->getPath(), '/'); |
|
| 364 | - // Remove /user/files/... |
|
| 365 | - list(,,, $path) = explode('/', $fullPath, 4); |
|
| 366 | - if (!$path) { |
|
| 367 | - throw new InvalidPathException('Path could not be split correctly'); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - return [ |
|
| 371 | - 'type' => 'file', |
|
| 372 | - 'id' => $encryptionContainer->getId(), |
|
| 373 | - 'name' => $encryptionContainer->getName(), |
|
| 374 | - 'path' => $path, |
|
| 375 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $encryptionContainer->getId()]), |
|
| 376 | - ]; |
|
| 377 | - } catch (\Exception $e) { |
|
| 378 | - // fall back to the normal one |
|
| 379 | - $this->fileIsEncrypted = false; |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - return [ |
|
| 384 | - 'type' => 'file', |
|
| 385 | - 'id' => $id, |
|
| 386 | - 'name' => basename($path), |
|
| 387 | - 'path' => trim($path, '/'), |
|
| 388 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 389 | - ]; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - protected $fileEncrypted = []; |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * Check if a file is end2end encrypted |
|
| 396 | - * @param int $fileId |
|
| 397 | - * @param string $path |
|
| 398 | - * @return Folder|null |
|
| 399 | - */ |
|
| 400 | - protected function getEndToEndEncryptionContainer($fileId, $path) { |
|
| 401 | - if (isset($this->fileEncrypted[$fileId])) { |
|
| 402 | - return $this->fileEncrypted[$fileId]; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - $fileName = basename($path); |
|
| 406 | - if (!preg_match('/^[0-9a-fA-F]{32}$/', $fileName)) { |
|
| 407 | - $this->fileEncrypted[$fileId] = false; |
|
| 408 | - return $this->fileEncrypted[$fileId]; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - $userFolder = $this->rootFolder->getUserFolder($this->activityManager->getCurrentUserId()); |
|
| 412 | - $files = $userFolder->getById($fileId); |
|
| 413 | - if (empty($files)) { |
|
| 414 | - try { |
|
| 415 | - // Deleted, try with parent |
|
| 416 | - $file = $this->findExistingParent($userFolder, dirname($path)); |
|
| 417 | - } catch (NotFoundException $e) { |
|
| 418 | - return null; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - if (!$file instanceof Folder || !$file->isEncrypted()) { |
|
| 422 | - return null; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - $this->fileEncrypted[$fileId] = $file; |
|
| 426 | - return $file; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - $file = array_shift($files); |
|
| 430 | - |
|
| 431 | - if ($file instanceof Folder && $file->isEncrypted()) { |
|
| 432 | - // If the folder is encrypted, it is the Container, |
|
| 433 | - // but can be the name is just fine. |
|
| 434 | - $this->fileEncrypted[$fileId] = true; |
|
| 435 | - return null; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - $this->fileEncrypted[$fileId] = $this->getParentEndToEndEncryptionContainer($userFolder, $file); |
|
| 439 | - return $this->fileEncrypted[$fileId]; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * @param Folder $userFolder |
|
| 444 | - * @param string $path |
|
| 445 | - * @return Folder |
|
| 446 | - * @throws NotFoundException |
|
| 447 | - */ |
|
| 448 | - protected function findExistingParent(Folder $userFolder, $path) { |
|
| 449 | - if ($path === '/') { |
|
| 450 | - throw new NotFoundException('Reached the root'); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - try { |
|
| 454 | - $folder = $userFolder->get(dirname($path)); |
|
| 455 | - } catch (NotFoundException $e) { |
|
| 456 | - return $this->findExistingParent($userFolder, dirname($path)); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - return $folder; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * Check all parents until the user's root folder if one is encrypted |
|
| 464 | - * |
|
| 465 | - * @param Folder $userFolder |
|
| 466 | - * @param Node $file |
|
| 467 | - * @return Node|null |
|
| 468 | - */ |
|
| 469 | - protected function getParentEndToEndEncryptionContainer(Folder $userFolder, Node $file) { |
|
| 470 | - try { |
|
| 471 | - $parent = $file->getParent(); |
|
| 472 | - |
|
| 473 | - if ($userFolder->getId() === $parent->getId()) { |
|
| 474 | - return null; |
|
| 475 | - } |
|
| 476 | - } catch (\Exception $e) { |
|
| 477 | - return null; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - if ($parent->isEncrypted()) { |
|
| 481 | - return $parent; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - return $this->getParentEndToEndEncryptionContainer($userFolder, $parent); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * @param string $uid |
|
| 489 | - * @return array |
|
| 490 | - */ |
|
| 491 | - protected function getUser($uid) { |
|
| 492 | - // First try local user |
|
| 493 | - $user = $this->userManager->get($uid); |
|
| 494 | - if ($user instanceof IUser) { |
|
| 495 | - return [ |
|
| 496 | - 'type' => 'user', |
|
| 497 | - 'id' => $user->getUID(), |
|
| 498 | - 'name' => $user->getDisplayName(), |
|
| 499 | - ]; |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - // Then a contact from the addressbook |
|
| 503 | - if ($this->cloudIdManager->isValidCloudId($uid)) { |
|
| 504 | - $cloudId = $this->cloudIdManager->resolveCloudId($uid); |
|
| 505 | - return [ |
|
| 506 | - 'type' => 'user', |
|
| 507 | - 'id' => $cloudId->getUser(), |
|
| 508 | - 'name' => $this->getDisplayNameFromAddressBook($cloudId->getDisplayId()), |
|
| 509 | - 'server' => $cloudId->getRemote(), |
|
| 510 | - ]; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - // Fallback to empty dummy data |
|
| 514 | - return [ |
|
| 515 | - 'type' => 'user', |
|
| 516 | - 'id' => $uid, |
|
| 517 | - 'name' => $uid, |
|
| 518 | - ]; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - protected function getDisplayNameFromAddressBook(string $search): string { |
|
| 522 | - if (isset($this->displayNames[$search])) { |
|
| 523 | - return $this->displayNames[$search]; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD']); |
|
| 527 | - foreach ($addressBookContacts as $contact) { |
|
| 528 | - if (isset($contact['isLocalSystemBook'])) { |
|
| 529 | - continue; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - if (isset($contact['CLOUD'])) { |
|
| 533 | - $cloudIds = $contact['CLOUD']; |
|
| 534 | - if (is_string($cloudIds)) { |
|
| 535 | - $cloudIds = [$cloudIds]; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - $lowerSearch = strtolower($search); |
|
| 539 | - foreach ($cloudIds as $cloudId) { |
|
| 540 | - if (strtolower($cloudId) === $lowerSearch) { |
|
| 541 | - $this->displayNames[$search] = $contact['FN'] . " ($cloudId)"; |
|
| 542 | - return $this->displayNames[$search]; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - return $search; |
|
| 549 | - } |
|
| 46 | + /** @var IFactory */ |
|
| 47 | + protected $languageFactory; |
|
| 48 | + |
|
| 49 | + /** @var IL10N */ |
|
| 50 | + protected $l; |
|
| 51 | + /** @var IL10N */ |
|
| 52 | + protected $activityLang; |
|
| 53 | + |
|
| 54 | + /** @var IURLGenerator */ |
|
| 55 | + protected $url; |
|
| 56 | + |
|
| 57 | + /** @var IManager */ |
|
| 58 | + protected $activityManager; |
|
| 59 | + |
|
| 60 | + /** @var IUserManager */ |
|
| 61 | + protected $userManager; |
|
| 62 | + |
|
| 63 | + /** @var IRootFolder */ |
|
| 64 | + protected $rootFolder; |
|
| 65 | + |
|
| 66 | + /** @var IEventMerger */ |
|
| 67 | + protected $eventMerger; |
|
| 68 | + |
|
| 69 | + /** @var ICloudIdManager */ |
|
| 70 | + protected $cloudIdManager; |
|
| 71 | + |
|
| 72 | + /** @var IContactsManager */ |
|
| 73 | + protected $contactsManager; |
|
| 74 | + |
|
| 75 | + /** @var string[] cached displayNames - key is the cloud id and value the displayname */ |
|
| 76 | + protected $displayNames = []; |
|
| 77 | + |
|
| 78 | + protected $fileIsEncrypted = false; |
|
| 79 | + |
|
| 80 | + public function __construct(IFactory $languageFactory, |
|
| 81 | + IURLGenerator $url, |
|
| 82 | + IManager $activityManager, |
|
| 83 | + IUserManager $userManager, |
|
| 84 | + IRootFolder $rootFolder, |
|
| 85 | + ICloudIdManager $cloudIdManager, |
|
| 86 | + IContactsManager $contactsManager, |
|
| 87 | + IEventMerger $eventMerger) { |
|
| 88 | + $this->languageFactory = $languageFactory; |
|
| 89 | + $this->url = $url; |
|
| 90 | + $this->activityManager = $activityManager; |
|
| 91 | + $this->userManager = $userManager; |
|
| 92 | + $this->rootFolder = $rootFolder; |
|
| 93 | + $this->cloudIdManager = $cloudIdManager; |
|
| 94 | + $this->contactsManager = $contactsManager; |
|
| 95 | + $this->eventMerger = $eventMerger; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @param string $language |
|
| 100 | + * @param IEvent $event |
|
| 101 | + * @param IEvent|null $previousEvent |
|
| 102 | + * @return IEvent |
|
| 103 | + * @throws \InvalidArgumentException |
|
| 104 | + * @since 11.0.0 |
|
| 105 | + */ |
|
| 106 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 107 | + if ($event->getApp() !== 'files') { |
|
| 108 | + throw new \InvalidArgumentException(); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $this->l = $this->languageFactory->get('files', $language); |
|
| 112 | + $this->activityLang = $this->languageFactory->get('activity', $language); |
|
| 113 | + |
|
| 114 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 115 | + try { |
|
| 116 | + return $this->parseShortVersion($event, $previousEvent); |
|
| 117 | + } catch (\InvalidArgumentException $e) { |
|
| 118 | + // Ignore and simply use the long version... |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return $this->parseLongVersion($event, $previousEvent); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + protected function setIcon(IEvent $event, string $icon, string $app = 'files') { |
|
| 126 | + if ($this->activityManager->getRequirePNG()) { |
|
| 127 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon . '.png'))); |
|
| 128 | + } else { |
|
| 129 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon . '.svg'))); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @param IEvent $event |
|
| 135 | + * @param IEvent|null $previousEvent |
|
| 136 | + * @return IEvent |
|
| 137 | + * @throws \InvalidArgumentException |
|
| 138 | + * @since 11.0.0 |
|
| 139 | + */ |
|
| 140 | + public function parseShortVersion(IEvent $event, IEvent $previousEvent = null) { |
|
| 141 | + $parsedParameters = $this->getParameters($event); |
|
| 142 | + |
|
| 143 | + if ($event->getSubject() === 'created_by') { |
|
| 144 | + $subject = $this->l->t('Created by {user}'); |
|
| 145 | + $this->setIcon($event, 'add-color'); |
|
| 146 | + } else if ($event->getSubject() === 'changed_by') { |
|
| 147 | + $subject = $this->l->t('Changed by {user}'); |
|
| 148 | + $this->setIcon($event, 'change'); |
|
| 149 | + } else if ($event->getSubject() === 'deleted_by') { |
|
| 150 | + $subject = $this->l->t('Deleted by {user}'); |
|
| 151 | + $this->setIcon($event, 'delete-color'); |
|
| 152 | + } else if ($event->getSubject() === 'restored_by') { |
|
| 153 | + $subject = $this->l->t('Restored by {user}'); |
|
| 154 | + $this->setIcon($event, 'actions/history', 'core'); |
|
| 155 | + } else if ($event->getSubject() === 'renamed_by') { |
|
| 156 | + $subject = $this->l->t('Renamed by {user}'); |
|
| 157 | + $this->setIcon($event, 'change'); |
|
| 158 | + } else if ($event->getSubject() === 'moved_by') { |
|
| 159 | + $subject = $this->l->t('Moved by {user}'); |
|
| 160 | + $this->setIcon($event, 'change'); |
|
| 161 | + } else { |
|
| 162 | + throw new \InvalidArgumentException(); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + if (!isset($parsedParameters['user'])) { |
|
| 166 | + // External user via public link share |
|
| 167 | + $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
| 171 | + |
|
| 172 | + return $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @param IEvent $event |
|
| 177 | + * @param IEvent|null $previousEvent |
|
| 178 | + * @return IEvent |
|
| 179 | + * @throws \InvalidArgumentException |
|
| 180 | + * @since 11.0.0 |
|
| 181 | + */ |
|
| 182 | + public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
|
| 183 | + $this->fileIsEncrypted = false; |
|
| 184 | + $parsedParameters = $this->getParameters($event); |
|
| 185 | + |
|
| 186 | + if ($event->getSubject() === 'created_self') { |
|
| 187 | + $subject = $this->l->t('You created {file}'); |
|
| 188 | + if ($this->fileIsEncrypted) { |
|
| 189 | + $subject = $this->l->t('You created an encrypted file in {file}'); |
|
| 190 | + } |
|
| 191 | + $this->setIcon($event, 'add-color'); |
|
| 192 | + } else if ($event->getSubject() === 'created_by') { |
|
| 193 | + $subject = $this->l->t('{user} created {file}'); |
|
| 194 | + if ($this->fileIsEncrypted) { |
|
| 195 | + $subject = $this->l->t('{user} created an encrypted file in {file}'); |
|
| 196 | + } |
|
| 197 | + $this->setIcon($event, 'add-color'); |
|
| 198 | + } else if ($event->getSubject() === 'created_public') { |
|
| 199 | + $subject = $this->l->t('{file} was created in a public folder'); |
|
| 200 | + $this->setIcon($event, 'add-color'); |
|
| 201 | + } else if ($event->getSubject() === 'changed_self') { |
|
| 202 | + $subject = $this->l->t('You changed {file}'); |
|
| 203 | + if ($this->fileIsEncrypted) { |
|
| 204 | + $subject = $this->l->t('You changed an encrypted file in {file}'); |
|
| 205 | + } |
|
| 206 | + $this->setIcon($event, 'change'); |
|
| 207 | + } else if ($event->getSubject() === 'changed_by') { |
|
| 208 | + $subject = $this->l->t('{user} changed {file}'); |
|
| 209 | + if ($this->fileIsEncrypted) { |
|
| 210 | + $subject = $this->l->t('{user} changed an encrypted file in {file}'); |
|
| 211 | + } |
|
| 212 | + $this->setIcon($event, 'change'); |
|
| 213 | + } else if ($event->getSubject() === 'deleted_self') { |
|
| 214 | + $subject = $this->l->t('You deleted {file}'); |
|
| 215 | + if ($this->fileIsEncrypted) { |
|
| 216 | + $subject = $this->l->t('You deleted an encrypted file in {file}'); |
|
| 217 | + } |
|
| 218 | + $this->setIcon($event, 'delete-color'); |
|
| 219 | + } else if ($event->getSubject() === 'deleted_by') { |
|
| 220 | + $subject = $this->l->t('{user} deleted {file}'); |
|
| 221 | + if ($this->fileIsEncrypted) { |
|
| 222 | + $subject = $this->l->t('{user} deleted an encrypted file in {file}'); |
|
| 223 | + } |
|
| 224 | + $this->setIcon($event, 'delete-color'); |
|
| 225 | + } else if ($event->getSubject() === 'restored_self') { |
|
| 226 | + $subject = $this->l->t('You restored {file}'); |
|
| 227 | + $this->setIcon($event, 'actions/history', 'core'); |
|
| 228 | + } else if ($event->getSubject() === 'restored_by') { |
|
| 229 | + $subject = $this->l->t('{user} restored {file}'); |
|
| 230 | + $this->setIcon($event, 'actions/history', 'core'); |
|
| 231 | + } else if ($event->getSubject() === 'renamed_self') { |
|
| 232 | + $subject = $this->l->t('You renamed {oldfile} to {newfile}'); |
|
| 233 | + $this->setIcon($event, 'change'); |
|
| 234 | + } else if ($event->getSubject() === 'renamed_by') { |
|
| 235 | + $subject = $this->l->t('{user} renamed {oldfile} to {newfile}'); |
|
| 236 | + $this->setIcon($event, 'change'); |
|
| 237 | + } else if ($event->getSubject() === 'moved_self') { |
|
| 238 | + $subject = $this->l->t('You moved {oldfile} to {newfile}'); |
|
| 239 | + $this->setIcon($event, 'change'); |
|
| 240 | + } else if ($event->getSubject() === 'moved_by') { |
|
| 241 | + $subject = $this->l->t('{user} moved {oldfile} to {newfile}'); |
|
| 242 | + $this->setIcon($event, 'change'); |
|
| 243 | + } else { |
|
| 244 | + throw new \InvalidArgumentException(); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + if ($this->fileIsEncrypted) { |
|
| 248 | + $event->setSubject($event->getSubject() . '_enc', $event->getSubjectParameters()); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + if (!isset($parsedParameters['user'])) { |
|
| 252 | + // External user via public link share |
|
| 253 | + $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
| 257 | + |
|
| 258 | + if ($event->getSubject() === 'moved_self' || $event->getSubject() === 'moved_by') { |
|
| 259 | + $event = $this->eventMerger->mergeEvents('oldfile', $event, $previousEvent); |
|
| 260 | + } else { |
|
| 261 | + $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + if ($event->getChildEvent() === null) { |
|
| 265 | + // Couldn't group by file, maybe we can group by user |
|
| 266 | + $event = $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + return $event; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 273 | + $placeholders = $replacements = []; |
|
| 274 | + foreach ($parameters as $placeholder => $parameter) { |
|
| 275 | + $placeholders[] = '{' . $placeholder . '}'; |
|
| 276 | + if ($parameter['type'] === 'file') { |
|
| 277 | + $replacements[] = $parameter['path']; |
|
| 278 | + } else { |
|
| 279 | + $replacements[] = $parameter['name']; |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 284 | + ->setRichSubject($subject, $parameters); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @param IEvent $event |
|
| 289 | + * @return array |
|
| 290 | + * @throws \InvalidArgumentException |
|
| 291 | + */ |
|
| 292 | + protected function getParameters(IEvent $event) { |
|
| 293 | + $parameters = $event->getSubjectParameters(); |
|
| 294 | + switch ($event->getSubject()) { |
|
| 295 | + case 'created_self': |
|
| 296 | + case 'created_public': |
|
| 297 | + case 'changed_self': |
|
| 298 | + case 'deleted_self': |
|
| 299 | + case 'restored_self': |
|
| 300 | + return [ |
|
| 301 | + 'file' => $this->getFile($parameters[0], $event), |
|
| 302 | + ]; |
|
| 303 | + case 'created_by': |
|
| 304 | + case 'changed_by': |
|
| 305 | + case 'deleted_by': |
|
| 306 | + case 'restored_by': |
|
| 307 | + if ($parameters[1] === '') { |
|
| 308 | + // External user via public link share |
|
| 309 | + return [ |
|
| 310 | + 'file' => $this->getFile($parameters[0], $event), |
|
| 311 | + ]; |
|
| 312 | + } |
|
| 313 | + return [ |
|
| 314 | + 'file' => $this->getFile($parameters[0], $event), |
|
| 315 | + 'user' => $this->getUser($parameters[1]), |
|
| 316 | + ]; |
|
| 317 | + case 'renamed_self': |
|
| 318 | + case 'moved_self': |
|
| 319 | + return [ |
|
| 320 | + 'newfile' => $this->getFile($parameters[0]), |
|
| 321 | + 'oldfile' => $this->getFile($parameters[1]), |
|
| 322 | + ]; |
|
| 323 | + case 'renamed_by': |
|
| 324 | + case 'moved_by': |
|
| 325 | + if ($parameters[1] === '') { |
|
| 326 | + // External user via public link share |
|
| 327 | + return [ |
|
| 328 | + 'newfile' => $this->getFile($parameters[0]), |
|
| 329 | + 'oldfile' => $this->getFile($parameters[2]), |
|
| 330 | + ]; |
|
| 331 | + } |
|
| 332 | + return [ |
|
| 333 | + 'newfile' => $this->getFile($parameters[0]), |
|
| 334 | + 'user' => $this->getUser($parameters[1]), |
|
| 335 | + 'oldfile' => $this->getFile($parameters[2]), |
|
| 336 | + ]; |
|
| 337 | + } |
|
| 338 | + return []; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * @param array|string $parameter |
|
| 343 | + * @param IEvent|null $event |
|
| 344 | + * @return array |
|
| 345 | + * @throws \InvalidArgumentException |
|
| 346 | + */ |
|
| 347 | + protected function getFile($parameter, IEvent $event = null) { |
|
| 348 | + if (is_array($parameter)) { |
|
| 349 | + $path = reset($parameter); |
|
| 350 | + $id = (string) key($parameter); |
|
| 351 | + } else if ($event !== null) { |
|
| 352 | + // Legacy from before ownCloud 8.2 |
|
| 353 | + $path = $parameter; |
|
| 354 | + $id = $event->getObjectId(); |
|
| 355 | + } else { |
|
| 356 | + throw new \InvalidArgumentException('Could not generate file parameter'); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + $encryptionContainer = $this->getEndToEndEncryptionContainer($id, $path); |
|
| 360 | + if ($encryptionContainer instanceof Folder) { |
|
| 361 | + $this->fileIsEncrypted = true; |
|
| 362 | + try { |
|
| 363 | + $fullPath = rtrim($encryptionContainer->getPath(), '/'); |
|
| 364 | + // Remove /user/files/... |
|
| 365 | + list(,,, $path) = explode('/', $fullPath, 4); |
|
| 366 | + if (!$path) { |
|
| 367 | + throw new InvalidPathException('Path could not be split correctly'); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + return [ |
|
| 371 | + 'type' => 'file', |
|
| 372 | + 'id' => $encryptionContainer->getId(), |
|
| 373 | + 'name' => $encryptionContainer->getName(), |
|
| 374 | + 'path' => $path, |
|
| 375 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $encryptionContainer->getId()]), |
|
| 376 | + ]; |
|
| 377 | + } catch (\Exception $e) { |
|
| 378 | + // fall back to the normal one |
|
| 379 | + $this->fileIsEncrypted = false; |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + return [ |
|
| 384 | + 'type' => 'file', |
|
| 385 | + 'id' => $id, |
|
| 386 | + 'name' => basename($path), |
|
| 387 | + 'path' => trim($path, '/'), |
|
| 388 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 389 | + ]; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + protected $fileEncrypted = []; |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * Check if a file is end2end encrypted |
|
| 396 | + * @param int $fileId |
|
| 397 | + * @param string $path |
|
| 398 | + * @return Folder|null |
|
| 399 | + */ |
|
| 400 | + protected function getEndToEndEncryptionContainer($fileId, $path) { |
|
| 401 | + if (isset($this->fileEncrypted[$fileId])) { |
|
| 402 | + return $this->fileEncrypted[$fileId]; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + $fileName = basename($path); |
|
| 406 | + if (!preg_match('/^[0-9a-fA-F]{32}$/', $fileName)) { |
|
| 407 | + $this->fileEncrypted[$fileId] = false; |
|
| 408 | + return $this->fileEncrypted[$fileId]; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + $userFolder = $this->rootFolder->getUserFolder($this->activityManager->getCurrentUserId()); |
|
| 412 | + $files = $userFolder->getById($fileId); |
|
| 413 | + if (empty($files)) { |
|
| 414 | + try { |
|
| 415 | + // Deleted, try with parent |
|
| 416 | + $file = $this->findExistingParent($userFolder, dirname($path)); |
|
| 417 | + } catch (NotFoundException $e) { |
|
| 418 | + return null; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + if (!$file instanceof Folder || !$file->isEncrypted()) { |
|
| 422 | + return null; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + $this->fileEncrypted[$fileId] = $file; |
|
| 426 | + return $file; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + $file = array_shift($files); |
|
| 430 | + |
|
| 431 | + if ($file instanceof Folder && $file->isEncrypted()) { |
|
| 432 | + // If the folder is encrypted, it is the Container, |
|
| 433 | + // but can be the name is just fine. |
|
| 434 | + $this->fileEncrypted[$fileId] = true; |
|
| 435 | + return null; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + $this->fileEncrypted[$fileId] = $this->getParentEndToEndEncryptionContainer($userFolder, $file); |
|
| 439 | + return $this->fileEncrypted[$fileId]; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * @param Folder $userFolder |
|
| 444 | + * @param string $path |
|
| 445 | + * @return Folder |
|
| 446 | + * @throws NotFoundException |
|
| 447 | + */ |
|
| 448 | + protected function findExistingParent(Folder $userFolder, $path) { |
|
| 449 | + if ($path === '/') { |
|
| 450 | + throw new NotFoundException('Reached the root'); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + try { |
|
| 454 | + $folder = $userFolder->get(dirname($path)); |
|
| 455 | + } catch (NotFoundException $e) { |
|
| 456 | + return $this->findExistingParent($userFolder, dirname($path)); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + return $folder; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Check all parents until the user's root folder if one is encrypted |
|
| 464 | + * |
|
| 465 | + * @param Folder $userFolder |
|
| 466 | + * @param Node $file |
|
| 467 | + * @return Node|null |
|
| 468 | + */ |
|
| 469 | + protected function getParentEndToEndEncryptionContainer(Folder $userFolder, Node $file) { |
|
| 470 | + try { |
|
| 471 | + $parent = $file->getParent(); |
|
| 472 | + |
|
| 473 | + if ($userFolder->getId() === $parent->getId()) { |
|
| 474 | + return null; |
|
| 475 | + } |
|
| 476 | + } catch (\Exception $e) { |
|
| 477 | + return null; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + if ($parent->isEncrypted()) { |
|
| 481 | + return $parent; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + return $this->getParentEndToEndEncryptionContainer($userFolder, $parent); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * @param string $uid |
|
| 489 | + * @return array |
|
| 490 | + */ |
|
| 491 | + protected function getUser($uid) { |
|
| 492 | + // First try local user |
|
| 493 | + $user = $this->userManager->get($uid); |
|
| 494 | + if ($user instanceof IUser) { |
|
| 495 | + return [ |
|
| 496 | + 'type' => 'user', |
|
| 497 | + 'id' => $user->getUID(), |
|
| 498 | + 'name' => $user->getDisplayName(), |
|
| 499 | + ]; |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + // Then a contact from the addressbook |
|
| 503 | + if ($this->cloudIdManager->isValidCloudId($uid)) { |
|
| 504 | + $cloudId = $this->cloudIdManager->resolveCloudId($uid); |
|
| 505 | + return [ |
|
| 506 | + 'type' => 'user', |
|
| 507 | + 'id' => $cloudId->getUser(), |
|
| 508 | + 'name' => $this->getDisplayNameFromAddressBook($cloudId->getDisplayId()), |
|
| 509 | + 'server' => $cloudId->getRemote(), |
|
| 510 | + ]; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + // Fallback to empty dummy data |
|
| 514 | + return [ |
|
| 515 | + 'type' => 'user', |
|
| 516 | + 'id' => $uid, |
|
| 517 | + 'name' => $uid, |
|
| 518 | + ]; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + protected function getDisplayNameFromAddressBook(string $search): string { |
|
| 522 | + if (isset($this->displayNames[$search])) { |
|
| 523 | + return $this->displayNames[$search]; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD']); |
|
| 527 | + foreach ($addressBookContacts as $contact) { |
|
| 528 | + if (isset($contact['isLocalSystemBook'])) { |
|
| 529 | + continue; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + if (isset($contact['CLOUD'])) { |
|
| 533 | + $cloudIds = $contact['CLOUD']; |
|
| 534 | + if (is_string($cloudIds)) { |
|
| 535 | + $cloudIds = [$cloudIds]; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + $lowerSearch = strtolower($search); |
|
| 539 | + foreach ($cloudIds as $cloudId) { |
|
| 540 | + if (strtolower($cloudId) === $lowerSearch) { |
|
| 541 | + $this->displayNames[$search] = $contact['FN'] . " ($cloudId)"; |
|
| 542 | + return $this->displayNames[$search]; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + return $search; |
|
| 549 | + } |
|
| 550 | 550 | } |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | protected function setIcon(IEvent $event, string $icon, string $app = 'files') { |
| 126 | 126 | if ($this->activityManager->getRequirePNG()) { |
| 127 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon . '.png'))); |
|
| 127 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon.'.png'))); |
|
| 128 | 128 | } else { |
| 129 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon . '.svg'))); |
|
| 129 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon.'.svg'))); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | if ($this->fileIsEncrypted) { |
| 248 | - $event->setSubject($event->getSubject() . '_enc', $event->getSubjectParameters()); |
|
| 248 | + $event->setSubject($event->getSubject().'_enc', $event->getSubjectParameters()); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | if (!isset($parsedParameters['user'])) { |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | protected function setSubjects(IEvent $event, $subject, array $parameters) { |
| 273 | 273 | $placeholders = $replacements = []; |
| 274 | 274 | foreach ($parameters as $placeholder => $parameter) { |
| 275 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 275 | + $placeholders[] = '{'.$placeholder.'}'; |
|
| 276 | 276 | if ($parameter['type'] === 'file') { |
| 277 | 277 | $replacements[] = $parameter['path']; |
| 278 | 278 | } else { |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | $lowerSearch = strtolower($search); |
| 539 | 539 | foreach ($cloudIds as $cloudId) { |
| 540 | 540 | if (strtolower($cloudId) === $lowerSearch) { |
| 541 | - $this->displayNames[$search] = $contact['FN'] . " ($cloudId)"; |
|
| 541 | + $this->displayNames[$search] = $contact['FN']." ($cloudId)"; |
|
| 542 | 542 | return $this->displayNames[$search]; |
| 543 | 543 | } |
| 544 | 544 | } |
@@ -34,105 +34,105 @@ |
||
| 34 | 34 | |
| 35 | 35 | class RemoteShares extends Base { |
| 36 | 36 | |
| 37 | - const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted'; |
|
| 38 | - const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined'; |
|
| 39 | - const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received'; |
|
| 40 | - const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared'; |
|
| 37 | + const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted'; |
|
| 38 | + const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined'; |
|
| 39 | + const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received'; |
|
| 40 | + const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared'; |
|
| 41 | 41 | |
| 42 | - public function __construct(IFactory $languageFactory, |
|
| 43 | - IURLGenerator $url, |
|
| 44 | - IManager $activityManager, |
|
| 45 | - IUserManager $userManager, |
|
| 46 | - IContactsManager $contactsManager, |
|
| 47 | - ICloudIdManager $cloudIdManager |
|
| 48 | - ) { |
|
| 49 | - parent::__construct($languageFactory, $url, $activityManager, $userManager, $cloudIdManager, $contactsManager); |
|
| 50 | - } |
|
| 42 | + public function __construct(IFactory $languageFactory, |
|
| 43 | + IURLGenerator $url, |
|
| 44 | + IManager $activityManager, |
|
| 45 | + IUserManager $userManager, |
|
| 46 | + IContactsManager $contactsManager, |
|
| 47 | + ICloudIdManager $cloudIdManager |
|
| 48 | + ) { |
|
| 49 | + parent::__construct($languageFactory, $url, $activityManager, $userManager, $cloudIdManager, $contactsManager); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param IEvent $event |
|
| 54 | - * @return IEvent |
|
| 55 | - * @throws \InvalidArgumentException |
|
| 56 | - * @since 11.0.0 |
|
| 57 | - */ |
|
| 58 | - public function parseShortVersion(IEvent $event) { |
|
| 59 | - $parsedParameters = $this->getParsedParameters($event); |
|
| 52 | + /** |
|
| 53 | + * @param IEvent $event |
|
| 54 | + * @return IEvent |
|
| 55 | + * @throws \InvalidArgumentException |
|
| 56 | + * @since 11.0.0 |
|
| 57 | + */ |
|
| 58 | + public function parseShortVersion(IEvent $event) { |
|
| 59 | + $parsedParameters = $this->getParsedParameters($event); |
|
| 60 | 60 | |
| 61 | - if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { |
|
| 62 | - $subject = $this->l->t('{user} accepted the remote share'); |
|
| 63 | - } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { |
|
| 64 | - $subject = $this->l->t('{user} declined the remote share'); |
|
| 65 | - } else { |
|
| 66 | - throw new \InvalidArgumentException(); |
|
| 67 | - } |
|
| 61 | + if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { |
|
| 62 | + $subject = $this->l->t('{user} accepted the remote share'); |
|
| 63 | + } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { |
|
| 64 | + $subject = $this->l->t('{user} declined the remote share'); |
|
| 65 | + } else { |
|
| 66 | + throw new \InvalidArgumentException(); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - if ($this->activityManager->getRequirePNG()) { |
|
| 70 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 71 | - } else { |
|
| 72 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 73 | - } |
|
| 74 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
| 69 | + if ($this->activityManager->getRequirePNG()) { |
|
| 70 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 71 | + } else { |
|
| 72 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 73 | + } |
|
| 74 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
| 75 | 75 | |
| 76 | - return $event; |
|
| 77 | - } |
|
| 76 | + return $event; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @param IEvent $event |
|
| 81 | - * @return IEvent |
|
| 82 | - * @throws \InvalidArgumentException |
|
| 83 | - * @since 11.0.0 |
|
| 84 | - */ |
|
| 85 | - public function parseLongVersion(IEvent $event) { |
|
| 86 | - $parsedParameters = $this->getParsedParameters($event); |
|
| 79 | + /** |
|
| 80 | + * @param IEvent $event |
|
| 81 | + * @return IEvent |
|
| 82 | + * @throws \InvalidArgumentException |
|
| 83 | + * @since 11.0.0 |
|
| 84 | + */ |
|
| 85 | + public function parseLongVersion(IEvent $event) { |
|
| 86 | + $parsedParameters = $this->getParsedParameters($event); |
|
| 87 | 87 | |
| 88 | - if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_RECEIVED) { |
|
| 89 | - $subject = $this->l->t('You received a new remote share {file} from {user}'); |
|
| 90 | - } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { |
|
| 91 | - $subject = $this->l->t('{user} accepted the remote share of {file}'); |
|
| 92 | - } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { |
|
| 93 | - $subject = $this->l->t('{user} declined the remote share of {file}'); |
|
| 94 | - } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_UNSHARED) { |
|
| 95 | - $subject = $this->l->t('{user} unshared {file} from you'); |
|
| 96 | - } else { |
|
| 97 | - throw new \InvalidArgumentException(); |
|
| 98 | - } |
|
| 88 | + if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_RECEIVED) { |
|
| 89 | + $subject = $this->l->t('You received a new remote share {file} from {user}'); |
|
| 90 | + } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) { |
|
| 91 | + $subject = $this->l->t('{user} accepted the remote share of {file}'); |
|
| 92 | + } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { |
|
| 93 | + $subject = $this->l->t('{user} declined the remote share of {file}'); |
|
| 94 | + } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_UNSHARED) { |
|
| 95 | + $subject = $this->l->t('{user} unshared {file} from you'); |
|
| 96 | + } else { |
|
| 97 | + throw new \InvalidArgumentException(); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - if ($this->activityManager->getRequirePNG()) { |
|
| 101 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 102 | - } else { |
|
| 103 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 104 | - } |
|
| 105 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
| 100 | + if ($this->activityManager->getRequirePNG()) { |
|
| 101 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 102 | + } else { |
|
| 103 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 104 | + } |
|
| 105 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
| 106 | 106 | |
| 107 | - return $event; |
|
| 108 | - } |
|
| 107 | + return $event; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - protected function getParsedParameters(IEvent $event) { |
|
| 111 | - $subject = $event->getSubject(); |
|
| 112 | - $parameters = $event->getSubjectParameters(); |
|
| 110 | + protected function getParsedParameters(IEvent $event) { |
|
| 111 | + $subject = $event->getSubject(); |
|
| 112 | + $parameters = $event->getSubjectParameters(); |
|
| 113 | 113 | |
| 114 | - switch ($subject) { |
|
| 115 | - case self::SUBJECT_REMOTE_SHARE_RECEIVED: |
|
| 116 | - case self::SUBJECT_REMOTE_SHARE_UNSHARED: |
|
| 117 | - return [ |
|
| 118 | - 'file' => [ |
|
| 119 | - 'type' => 'pending-federated-share', |
|
| 120 | - 'id' => $parameters[1], |
|
| 121 | - 'name' => $parameters[1], |
|
| 122 | - ], |
|
| 123 | - 'user' => $this->getUser($parameters[0]), |
|
| 124 | - ]; |
|
| 125 | - case self::SUBJECT_REMOTE_SHARE_ACCEPTED: |
|
| 126 | - case self::SUBJECT_REMOTE_SHARE_DECLINED: |
|
| 127 | - $fileParameter = $parameters[1]; |
|
| 128 | - if (!is_array($fileParameter)) { |
|
| 129 | - $fileParameter = [$event->getObjectId() => $event->getObjectName()]; |
|
| 130 | - } |
|
| 131 | - return [ |
|
| 132 | - 'file' => $this->getFile($fileParameter), |
|
| 133 | - 'user' => $this->getUser($parameters[0]), |
|
| 134 | - ]; |
|
| 135 | - } |
|
| 136 | - throw new \InvalidArgumentException(); |
|
| 137 | - } |
|
| 114 | + switch ($subject) { |
|
| 115 | + case self::SUBJECT_REMOTE_SHARE_RECEIVED: |
|
| 116 | + case self::SUBJECT_REMOTE_SHARE_UNSHARED: |
|
| 117 | + return [ |
|
| 118 | + 'file' => [ |
|
| 119 | + 'type' => 'pending-federated-share', |
|
| 120 | + 'id' => $parameters[1], |
|
| 121 | + 'name' => $parameters[1], |
|
| 122 | + ], |
|
| 123 | + 'user' => $this->getUser($parameters[0]), |
|
| 124 | + ]; |
|
| 125 | + case self::SUBJECT_REMOTE_SHARE_ACCEPTED: |
|
| 126 | + case self::SUBJECT_REMOTE_SHARE_DECLINED: |
|
| 127 | + $fileParameter = $parameters[1]; |
|
| 128 | + if (!is_array($fileParameter)) { |
|
| 129 | + $fileParameter = [$event->getObjectId() => $event->getObjectName()]; |
|
| 130 | + } |
|
| 131 | + return [ |
|
| 132 | + 'file' => $this->getFile($fileParameter), |
|
| 133 | + 'user' => $this->getUser($parameters[0]), |
|
| 134 | + ]; |
|
| 135 | + } |
|
| 136 | + throw new \InvalidArgumentException(); |
|
| 137 | + } |
|
| 138 | 138 | } |
@@ -36,145 +36,145 @@ |
||
| 36 | 36 | |
| 37 | 37 | class Groups extends Base { |
| 38 | 38 | |
| 39 | - const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self'; |
|
| 40 | - const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by'; |
|
| 41 | - |
|
| 42 | - const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self'; |
|
| 43 | - const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by'; |
|
| 44 | - |
|
| 45 | - const SUBJECT_EXPIRED_GROUP = 'expired_group'; |
|
| 46 | - |
|
| 47 | - /** @var IGroupManager */ |
|
| 48 | - protected $groupManager; |
|
| 49 | - |
|
| 50 | - /** @var string[] */ |
|
| 51 | - protected $groupDisplayNames = []; |
|
| 52 | - |
|
| 53 | - public function __construct(IFactory $languageFactory, |
|
| 54 | - IURLGenerator $url, |
|
| 55 | - IManager $activityManager, |
|
| 56 | - IUserManager $userManager, |
|
| 57 | - ICloudIdManager $cloudIdManager, |
|
| 58 | - IContactsManager $contactsManager, |
|
| 59 | - IGroupManager $groupManager) { |
|
| 60 | - parent::__construct($languageFactory, $url, $activityManager, $userManager, $cloudIdManager, $contactsManager); |
|
| 61 | - $this->groupManager = $groupManager; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param IEvent $event |
|
| 66 | - * @return IEvent |
|
| 67 | - * @throws \InvalidArgumentException |
|
| 68 | - * @since 11.0.0 |
|
| 69 | - */ |
|
| 70 | - public function parseShortVersion(IEvent $event) { |
|
| 71 | - $parsedParameters = $this->getParsedParameters($event); |
|
| 72 | - |
|
| 73 | - if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { |
|
| 74 | - $subject = $this->l->t('Shared with group {group}'); |
|
| 75 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { |
|
| 76 | - $subject = $this->l->t('Removed share for group {group}'); |
|
| 77 | - } else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { |
|
| 78 | - $subject = $this->l->t('{actor} shared with group {group}'); |
|
| 79 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { |
|
| 80 | - $subject = $this->l->t('{actor} removed share for group {group}'); |
|
| 81 | - } else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) { |
|
| 82 | - $subject = $this->l->t('Share for group {group} expired'); |
|
| 83 | - } else { |
|
| 84 | - throw new \InvalidArgumentException(); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - if ($this->activityManager->getRequirePNG()) { |
|
| 88 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 89 | - } else { |
|
| 90 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 91 | - } |
|
| 92 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
| 93 | - |
|
| 94 | - return $event; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param IEvent $event |
|
| 99 | - * @return IEvent |
|
| 100 | - * @throws \InvalidArgumentException |
|
| 101 | - * @since 11.0.0 |
|
| 102 | - */ |
|
| 103 | - public function parseLongVersion(IEvent $event) { |
|
| 104 | - $parsedParameters = $this->getParsedParameters($event); |
|
| 105 | - |
|
| 106 | - if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { |
|
| 107 | - $subject = $this->l->t('You shared {file} with group {group}'); |
|
| 108 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { |
|
| 109 | - $subject = $this->l->t('You removed group {group} from {file}'); |
|
| 110 | - } else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { |
|
| 111 | - $subject = $this->l->t('{actor} shared {file} with group {group}'); |
|
| 112 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { |
|
| 113 | - $subject = $this->l->t('{actor} removed group {group} from {file}'); |
|
| 114 | - } else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) { |
|
| 115 | - $subject = $this->l->t('Share for file {file} with group {group} expired'); |
|
| 116 | - } else { |
|
| 117 | - throw new \InvalidArgumentException(); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if ($this->activityManager->getRequirePNG()) { |
|
| 121 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 122 | - } else { |
|
| 123 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 124 | - } |
|
| 125 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
| 126 | - |
|
| 127 | - return $event; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - protected function getParsedParameters(IEvent $event) { |
|
| 131 | - $subject = $event->getSubject(); |
|
| 132 | - $parameters = $event->getSubjectParameters(); |
|
| 133 | - |
|
| 134 | - switch ($subject) { |
|
| 135 | - case self::SUBJECT_RESHARED_GROUP_BY: |
|
| 136 | - case self::SUBJECT_UNSHARED_GROUP_BY: |
|
| 137 | - return [ |
|
| 138 | - 'file' => $this->getFile($parameters[0], $event), |
|
| 139 | - 'group' => $this->generateGroupParameter($parameters[2]), |
|
| 140 | - 'actor' => $this->getUser($parameters[1]), |
|
| 141 | - ]; |
|
| 142 | - case self::SUBJECT_SHARED_GROUP_SELF: |
|
| 143 | - case self::SUBJECT_UNSHARED_GROUP_SELF: |
|
| 144 | - case self::SUBJECT_EXPIRED_GROUP: |
|
| 145 | - return [ |
|
| 146 | - 'file' => $this->getFile($parameters[0], $event), |
|
| 147 | - 'group' => $this->generateGroupParameter($parameters[1]), |
|
| 148 | - ]; |
|
| 149 | - } |
|
| 150 | - return []; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param string $gid |
|
| 155 | - * @return array |
|
| 156 | - */ |
|
| 157 | - protected function generateGroupParameter($gid) { |
|
| 158 | - if (!isset($this->groupDisplayNames[$gid])) { |
|
| 159 | - $this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - return [ |
|
| 163 | - 'type' => 'user-group', |
|
| 164 | - 'id' => $gid, |
|
| 165 | - 'name' => $this->groupDisplayNames[$gid], |
|
| 166 | - ]; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param string $gid |
|
| 171 | - * @return string |
|
| 172 | - */ |
|
| 173 | - protected function getGroupDisplayName($gid) { |
|
| 174 | - $group = $this->groupManager->get($gid); |
|
| 175 | - if ($group instanceof IGroup) { |
|
| 176 | - return $group->getDisplayName(); |
|
| 177 | - } |
|
| 178 | - return $gid; |
|
| 179 | - } |
|
| 39 | + const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self'; |
|
| 40 | + const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by'; |
|
| 41 | + |
|
| 42 | + const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self'; |
|
| 43 | + const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by'; |
|
| 44 | + |
|
| 45 | + const SUBJECT_EXPIRED_GROUP = 'expired_group'; |
|
| 46 | + |
|
| 47 | + /** @var IGroupManager */ |
|
| 48 | + protected $groupManager; |
|
| 49 | + |
|
| 50 | + /** @var string[] */ |
|
| 51 | + protected $groupDisplayNames = []; |
|
| 52 | + |
|
| 53 | + public function __construct(IFactory $languageFactory, |
|
| 54 | + IURLGenerator $url, |
|
| 55 | + IManager $activityManager, |
|
| 56 | + IUserManager $userManager, |
|
| 57 | + ICloudIdManager $cloudIdManager, |
|
| 58 | + IContactsManager $contactsManager, |
|
| 59 | + IGroupManager $groupManager) { |
|
| 60 | + parent::__construct($languageFactory, $url, $activityManager, $userManager, $cloudIdManager, $contactsManager); |
|
| 61 | + $this->groupManager = $groupManager; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param IEvent $event |
|
| 66 | + * @return IEvent |
|
| 67 | + * @throws \InvalidArgumentException |
|
| 68 | + * @since 11.0.0 |
|
| 69 | + */ |
|
| 70 | + public function parseShortVersion(IEvent $event) { |
|
| 71 | + $parsedParameters = $this->getParsedParameters($event); |
|
| 72 | + |
|
| 73 | + if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { |
|
| 74 | + $subject = $this->l->t('Shared with group {group}'); |
|
| 75 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { |
|
| 76 | + $subject = $this->l->t('Removed share for group {group}'); |
|
| 77 | + } else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { |
|
| 78 | + $subject = $this->l->t('{actor} shared with group {group}'); |
|
| 79 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { |
|
| 80 | + $subject = $this->l->t('{actor} removed share for group {group}'); |
|
| 81 | + } else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) { |
|
| 82 | + $subject = $this->l->t('Share for group {group} expired'); |
|
| 83 | + } else { |
|
| 84 | + throw new \InvalidArgumentException(); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + if ($this->activityManager->getRequirePNG()) { |
|
| 88 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 89 | + } else { |
|
| 90 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 91 | + } |
|
| 92 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
| 93 | + |
|
| 94 | + return $event; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param IEvent $event |
|
| 99 | + * @return IEvent |
|
| 100 | + * @throws \InvalidArgumentException |
|
| 101 | + * @since 11.0.0 |
|
| 102 | + */ |
|
| 103 | + public function parseLongVersion(IEvent $event) { |
|
| 104 | + $parsedParameters = $this->getParsedParameters($event); |
|
| 105 | + |
|
| 106 | + if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { |
|
| 107 | + $subject = $this->l->t('You shared {file} with group {group}'); |
|
| 108 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { |
|
| 109 | + $subject = $this->l->t('You removed group {group} from {file}'); |
|
| 110 | + } else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { |
|
| 111 | + $subject = $this->l->t('{actor} shared {file} with group {group}'); |
|
| 112 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { |
|
| 113 | + $subject = $this->l->t('{actor} removed group {group} from {file}'); |
|
| 114 | + } else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) { |
|
| 115 | + $subject = $this->l->t('Share for file {file} with group {group} expired'); |
|
| 116 | + } else { |
|
| 117 | + throw new \InvalidArgumentException(); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if ($this->activityManager->getRequirePNG()) { |
|
| 121 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 122 | + } else { |
|
| 123 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 124 | + } |
|
| 125 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
| 126 | + |
|
| 127 | + return $event; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + protected function getParsedParameters(IEvent $event) { |
|
| 131 | + $subject = $event->getSubject(); |
|
| 132 | + $parameters = $event->getSubjectParameters(); |
|
| 133 | + |
|
| 134 | + switch ($subject) { |
|
| 135 | + case self::SUBJECT_RESHARED_GROUP_BY: |
|
| 136 | + case self::SUBJECT_UNSHARED_GROUP_BY: |
|
| 137 | + return [ |
|
| 138 | + 'file' => $this->getFile($parameters[0], $event), |
|
| 139 | + 'group' => $this->generateGroupParameter($parameters[2]), |
|
| 140 | + 'actor' => $this->getUser($parameters[1]), |
|
| 141 | + ]; |
|
| 142 | + case self::SUBJECT_SHARED_GROUP_SELF: |
|
| 143 | + case self::SUBJECT_UNSHARED_GROUP_SELF: |
|
| 144 | + case self::SUBJECT_EXPIRED_GROUP: |
|
| 145 | + return [ |
|
| 146 | + 'file' => $this->getFile($parameters[0], $event), |
|
| 147 | + 'group' => $this->generateGroupParameter($parameters[1]), |
|
| 148 | + ]; |
|
| 149 | + } |
|
| 150 | + return []; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param string $gid |
|
| 155 | + * @return array |
|
| 156 | + */ |
|
| 157 | + protected function generateGroupParameter($gid) { |
|
| 158 | + if (!isset($this->groupDisplayNames[$gid])) { |
|
| 159 | + $this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return [ |
|
| 163 | + 'type' => 'user-group', |
|
| 164 | + 'id' => $gid, |
|
| 165 | + 'name' => $this->groupDisplayNames[$gid], |
|
| 166 | + ]; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param string $gid |
|
| 171 | + * @return string |
|
| 172 | + */ |
|
| 173 | + protected function getGroupDisplayName($gid) { |
|
| 174 | + $group = $this->groupManager->get($gid); |
|
| 175 | + if ($group instanceof IGroup) { |
|
| 176 | + return $group->getDisplayName(); |
|
| 177 | + } |
|
| 178 | + return $gid; |
|
| 179 | + } |
|
| 180 | 180 | } |
@@ -36,195 +36,195 @@ |
||
| 36 | 36 | |
| 37 | 37 | abstract class Base implements IProvider { |
| 38 | 38 | |
| 39 | - /** @var IFactory */ |
|
| 40 | - protected $languageFactory; |
|
| 41 | - |
|
| 42 | - /** @var IL10N */ |
|
| 43 | - protected $l; |
|
| 44 | - |
|
| 45 | - /** @var IURLGenerator */ |
|
| 46 | - protected $url; |
|
| 47 | - |
|
| 48 | - /** @var IManager */ |
|
| 49 | - protected $activityManager; |
|
| 50 | - |
|
| 51 | - /** @var IUserManager */ |
|
| 52 | - protected $userManager; |
|
| 53 | - |
|
| 54 | - /** @var IContactsManager */ |
|
| 55 | - protected $contactsManager; |
|
| 56 | - |
|
| 57 | - /** @var ICloudIdManager */ |
|
| 58 | - protected $cloudIdManager; |
|
| 59 | - |
|
| 60 | - /** @var array */ |
|
| 61 | - protected $displayNames = []; |
|
| 62 | - |
|
| 63 | - public function __construct(IFactory $languageFactory, |
|
| 64 | - IURLGenerator $url, |
|
| 65 | - IManager $activityManager, |
|
| 66 | - IUserManager $userManager, |
|
| 67 | - ICloudIdManager $cloudIdManager, |
|
| 68 | - IContactsManager $contactsManager) { |
|
| 69 | - $this->languageFactory = $languageFactory; |
|
| 70 | - $this->url = $url; |
|
| 71 | - $this->activityManager = $activityManager; |
|
| 72 | - $this->userManager = $userManager; |
|
| 73 | - $this->cloudIdManager = $cloudIdManager; |
|
| 74 | - $this->contactsManager = $contactsManager; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param string $language |
|
| 79 | - * @param IEvent $event |
|
| 80 | - * @param IEvent|null $previousEvent |
|
| 81 | - * @return IEvent |
|
| 82 | - * @throws \InvalidArgumentException |
|
| 83 | - * @since 11.0.0 |
|
| 84 | - */ |
|
| 85 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 86 | - if ($event->getApp() !== 'files_sharing') { |
|
| 87 | - throw new \InvalidArgumentException(); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $this->l = $this->languageFactory->get('files_sharing', $language); |
|
| 91 | - |
|
| 92 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 93 | - try { |
|
| 94 | - return $this->parseShortVersion($event); |
|
| 95 | - } catch (\InvalidArgumentException $e) { |
|
| 96 | - // Ignore and simply use the long version... |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return $this->parseLongVersion($event); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param IEvent $event |
|
| 105 | - * @return IEvent |
|
| 106 | - * @throws \InvalidArgumentException |
|
| 107 | - * @since 11.0.0 |
|
| 108 | - */ |
|
| 109 | - abstract protected function parseShortVersion(IEvent $event); |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param IEvent $event |
|
| 113 | - * @return IEvent |
|
| 114 | - * @throws \InvalidArgumentException |
|
| 115 | - * @since 11.0.0 |
|
| 116 | - */ |
|
| 117 | - abstract protected function parseLongVersion(IEvent $event); |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @param IEvent $event |
|
| 121 | - * @param string $subject |
|
| 122 | - * @param array $parameters |
|
| 123 | - * @throws \InvalidArgumentException |
|
| 124 | - */ |
|
| 125 | - protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 126 | - $placeholders = $replacements = []; |
|
| 127 | - foreach ($parameters as $placeholder => $parameter) { |
|
| 128 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 129 | - if ($parameter['type'] === 'file') { |
|
| 130 | - $replacements[] = $parameter['path']; |
|
| 131 | - } else { |
|
| 132 | - $replacements[] = $parameter['name']; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 137 | - ->setRichSubject($subject, $parameters); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param array|string $parameter |
|
| 142 | - * @param IEvent|null $event |
|
| 143 | - * @return array |
|
| 144 | - * @throws \InvalidArgumentException |
|
| 145 | - */ |
|
| 146 | - protected function getFile($parameter, IEvent $event = null) { |
|
| 147 | - if (is_array($parameter)) { |
|
| 148 | - $path = reset($parameter); |
|
| 149 | - $id = (string) key($parameter); |
|
| 150 | - } else if ($event !== null) { |
|
| 151 | - // Legacy from before ownCloud 8.2 |
|
| 152 | - $path = $parameter; |
|
| 153 | - $id = $event->getObjectId(); |
|
| 154 | - } else { |
|
| 155 | - throw new \InvalidArgumentException('Could not generate file parameter'); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - return [ |
|
| 159 | - 'type' => 'file', |
|
| 160 | - 'id' => $id, |
|
| 161 | - 'name' => basename($path), |
|
| 162 | - 'path' => trim($path, '/'), |
|
| 163 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 164 | - ]; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param string $uid |
|
| 169 | - * @return array |
|
| 170 | - */ |
|
| 171 | - protected function getUser($uid) { |
|
| 172 | - // First try local user |
|
| 173 | - $user = $this->userManager->get($uid); |
|
| 174 | - if ($user instanceof IUser) { |
|
| 175 | - return [ |
|
| 176 | - 'type' => 'user', |
|
| 177 | - 'id' => $user->getUID(), |
|
| 178 | - 'name' => $user->getDisplayName(), |
|
| 179 | - ]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - // Then a contact from the addressbook |
|
| 183 | - if ($this->cloudIdManager->isValidCloudId($uid)) { |
|
| 184 | - $cloudId = $this->cloudIdManager->resolveCloudId($uid); |
|
| 185 | - return [ |
|
| 186 | - 'type' => 'user', |
|
| 187 | - 'id' => $cloudId->getUser(), |
|
| 188 | - 'name' => $this->getDisplayNameFromAddressBook($cloudId->getDisplayId()), |
|
| 189 | - 'server' => $cloudId->getRemote(), |
|
| 190 | - ]; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // Fallback to empty dummy data |
|
| 194 | - return [ |
|
| 195 | - 'type' => 'user', |
|
| 196 | - 'id' => $uid, |
|
| 197 | - 'name' => $uid, |
|
| 198 | - ]; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - protected function getDisplayNameFromAddressBook(string $search): string { |
|
| 202 | - if (isset($this->displayNames[$search])) { |
|
| 203 | - return $this->displayNames[$search]; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD']); |
|
| 207 | - foreach ($addressBookContacts as $contact) { |
|
| 208 | - if (isset($contact['isLocalSystemBook'])) { |
|
| 209 | - continue; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - if (isset($contact['CLOUD'])) { |
|
| 213 | - $cloudIds = $contact['CLOUD']; |
|
| 214 | - if (is_string($cloudIds)) { |
|
| 215 | - $cloudIds = [$cloudIds]; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $lowerSearch = strtolower($search); |
|
| 219 | - foreach ($cloudIds as $cloudId) { |
|
| 220 | - if (strtolower($cloudId) === $lowerSearch) { |
|
| 221 | - $this->displayNames[$search] = $contact['FN'] . " ($cloudId)"; |
|
| 222 | - return $this->displayNames[$search]; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return $search; |
|
| 229 | - } |
|
| 39 | + /** @var IFactory */ |
|
| 40 | + protected $languageFactory; |
|
| 41 | + |
|
| 42 | + /** @var IL10N */ |
|
| 43 | + protected $l; |
|
| 44 | + |
|
| 45 | + /** @var IURLGenerator */ |
|
| 46 | + protected $url; |
|
| 47 | + |
|
| 48 | + /** @var IManager */ |
|
| 49 | + protected $activityManager; |
|
| 50 | + |
|
| 51 | + /** @var IUserManager */ |
|
| 52 | + protected $userManager; |
|
| 53 | + |
|
| 54 | + /** @var IContactsManager */ |
|
| 55 | + protected $contactsManager; |
|
| 56 | + |
|
| 57 | + /** @var ICloudIdManager */ |
|
| 58 | + protected $cloudIdManager; |
|
| 59 | + |
|
| 60 | + /** @var array */ |
|
| 61 | + protected $displayNames = []; |
|
| 62 | + |
|
| 63 | + public function __construct(IFactory $languageFactory, |
|
| 64 | + IURLGenerator $url, |
|
| 65 | + IManager $activityManager, |
|
| 66 | + IUserManager $userManager, |
|
| 67 | + ICloudIdManager $cloudIdManager, |
|
| 68 | + IContactsManager $contactsManager) { |
|
| 69 | + $this->languageFactory = $languageFactory; |
|
| 70 | + $this->url = $url; |
|
| 71 | + $this->activityManager = $activityManager; |
|
| 72 | + $this->userManager = $userManager; |
|
| 73 | + $this->cloudIdManager = $cloudIdManager; |
|
| 74 | + $this->contactsManager = $contactsManager; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param string $language |
|
| 79 | + * @param IEvent $event |
|
| 80 | + * @param IEvent|null $previousEvent |
|
| 81 | + * @return IEvent |
|
| 82 | + * @throws \InvalidArgumentException |
|
| 83 | + * @since 11.0.0 |
|
| 84 | + */ |
|
| 85 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 86 | + if ($event->getApp() !== 'files_sharing') { |
|
| 87 | + throw new \InvalidArgumentException(); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $this->l = $this->languageFactory->get('files_sharing', $language); |
|
| 91 | + |
|
| 92 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 93 | + try { |
|
| 94 | + return $this->parseShortVersion($event); |
|
| 95 | + } catch (\InvalidArgumentException $e) { |
|
| 96 | + // Ignore and simply use the long version... |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return $this->parseLongVersion($event); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param IEvent $event |
|
| 105 | + * @return IEvent |
|
| 106 | + * @throws \InvalidArgumentException |
|
| 107 | + * @since 11.0.0 |
|
| 108 | + */ |
|
| 109 | + abstract protected function parseShortVersion(IEvent $event); |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param IEvent $event |
|
| 113 | + * @return IEvent |
|
| 114 | + * @throws \InvalidArgumentException |
|
| 115 | + * @since 11.0.0 |
|
| 116 | + */ |
|
| 117 | + abstract protected function parseLongVersion(IEvent $event); |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @param IEvent $event |
|
| 121 | + * @param string $subject |
|
| 122 | + * @param array $parameters |
|
| 123 | + * @throws \InvalidArgumentException |
|
| 124 | + */ |
|
| 125 | + protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 126 | + $placeholders = $replacements = []; |
|
| 127 | + foreach ($parameters as $placeholder => $parameter) { |
|
| 128 | + $placeholders[] = '{' . $placeholder . '}'; |
|
| 129 | + if ($parameter['type'] === 'file') { |
|
| 130 | + $replacements[] = $parameter['path']; |
|
| 131 | + } else { |
|
| 132 | + $replacements[] = $parameter['name']; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 137 | + ->setRichSubject($subject, $parameters); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param array|string $parameter |
|
| 142 | + * @param IEvent|null $event |
|
| 143 | + * @return array |
|
| 144 | + * @throws \InvalidArgumentException |
|
| 145 | + */ |
|
| 146 | + protected function getFile($parameter, IEvent $event = null) { |
|
| 147 | + if (is_array($parameter)) { |
|
| 148 | + $path = reset($parameter); |
|
| 149 | + $id = (string) key($parameter); |
|
| 150 | + } else if ($event !== null) { |
|
| 151 | + // Legacy from before ownCloud 8.2 |
|
| 152 | + $path = $parameter; |
|
| 153 | + $id = $event->getObjectId(); |
|
| 154 | + } else { |
|
| 155 | + throw new \InvalidArgumentException('Could not generate file parameter'); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + return [ |
|
| 159 | + 'type' => 'file', |
|
| 160 | + 'id' => $id, |
|
| 161 | + 'name' => basename($path), |
|
| 162 | + 'path' => trim($path, '/'), |
|
| 163 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 164 | + ]; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param string $uid |
|
| 169 | + * @return array |
|
| 170 | + */ |
|
| 171 | + protected function getUser($uid) { |
|
| 172 | + // First try local user |
|
| 173 | + $user = $this->userManager->get($uid); |
|
| 174 | + if ($user instanceof IUser) { |
|
| 175 | + return [ |
|
| 176 | + 'type' => 'user', |
|
| 177 | + 'id' => $user->getUID(), |
|
| 178 | + 'name' => $user->getDisplayName(), |
|
| 179 | + ]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + // Then a contact from the addressbook |
|
| 183 | + if ($this->cloudIdManager->isValidCloudId($uid)) { |
|
| 184 | + $cloudId = $this->cloudIdManager->resolveCloudId($uid); |
|
| 185 | + return [ |
|
| 186 | + 'type' => 'user', |
|
| 187 | + 'id' => $cloudId->getUser(), |
|
| 188 | + 'name' => $this->getDisplayNameFromAddressBook($cloudId->getDisplayId()), |
|
| 189 | + 'server' => $cloudId->getRemote(), |
|
| 190 | + ]; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // Fallback to empty dummy data |
|
| 194 | + return [ |
|
| 195 | + 'type' => 'user', |
|
| 196 | + 'id' => $uid, |
|
| 197 | + 'name' => $uid, |
|
| 198 | + ]; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + protected function getDisplayNameFromAddressBook(string $search): string { |
|
| 202 | + if (isset($this->displayNames[$search])) { |
|
| 203 | + return $this->displayNames[$search]; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD']); |
|
| 207 | + foreach ($addressBookContacts as $contact) { |
|
| 208 | + if (isset($contact['isLocalSystemBook'])) { |
|
| 209 | + continue; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + if (isset($contact['CLOUD'])) { |
|
| 213 | + $cloudIds = $contact['CLOUD']; |
|
| 214 | + if (is_string($cloudIds)) { |
|
| 215 | + $cloudIds = [$cloudIds]; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $lowerSearch = strtolower($search); |
|
| 219 | + foreach ($cloudIds as $cloudId) { |
|
| 220 | + if (strtolower($cloudId) === $lowerSearch) { |
|
| 221 | + $this->displayNames[$search] = $contact['FN'] . " ($cloudId)"; |
|
| 222 | + return $this->displayNames[$search]; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return $search; |
|
| 229 | + } |
|
| 230 | 230 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | protected function setSubjects(IEvent $event, $subject, array $parameters) { |
| 126 | 126 | $placeholders = $replacements = []; |
| 127 | 127 | foreach ($parameters as $placeholder => $parameter) { |
| 128 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 128 | + $placeholders[] = '{'.$placeholder.'}'; |
|
| 129 | 129 | if ($parameter['type'] === 'file') { |
| 130 | 130 | $replacements[] = $parameter['path']; |
| 131 | 131 | } else { |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $lowerSearch = strtolower($search); |
| 219 | 219 | foreach ($cloudIds as $cloudId) { |
| 220 | 220 | if (strtolower($cloudId) === $lowerSearch) { |
| 221 | - $this->displayNames[$search] = $contact['FN'] . " ($cloudId)"; |
|
| 221 | + $this->displayNames[$search] = $contact['FN']." ($cloudId)"; |
|
| 222 | 222 | return $this->displayNames[$search]; |
| 223 | 223 | } |
| 224 | 224 | } |