@@ -44,549 +44,549 @@ |
||
| 44 | 44 | |
| 45 | 45 | class Provider implements IProvider { |
| 46 | 46 | |
| 47 | - /** @var IFactory */ |
|
| 48 | - protected $languageFactory; |
|
| 49 | - |
|
| 50 | - /** @var IL10N */ |
|
| 51 | - protected $l; |
|
| 52 | - /** @var IL10N */ |
|
| 53 | - protected $activityLang; |
|
| 54 | - |
|
| 55 | - /** @var IURLGenerator */ |
|
| 56 | - protected $url; |
|
| 57 | - |
|
| 58 | - /** @var IManager */ |
|
| 59 | - protected $activityManager; |
|
| 60 | - |
|
| 61 | - /** @var IUserManager */ |
|
| 62 | - protected $userManager; |
|
| 63 | - |
|
| 64 | - /** @var IRootFolder */ |
|
| 65 | - protected $rootFolder; |
|
| 66 | - |
|
| 67 | - /** @var IEventMerger */ |
|
| 68 | - protected $eventMerger; |
|
| 69 | - |
|
| 70 | - /** @var ICloudIdManager */ |
|
| 71 | - protected $cloudIdManager; |
|
| 72 | - |
|
| 73 | - /** @var IContactsManager */ |
|
| 74 | - protected $contactsManager; |
|
| 75 | - |
|
| 76 | - /** @var string[] cached displayNames - key is the cloud id and value the displayname */ |
|
| 77 | - protected $displayNames = []; |
|
| 78 | - |
|
| 79 | - protected $fileIsEncrypted = false; |
|
| 80 | - |
|
| 81 | - public function __construct(IFactory $languageFactory, |
|
| 82 | - IURLGenerator $url, |
|
| 83 | - IManager $activityManager, |
|
| 84 | - IUserManager $userManager, |
|
| 85 | - IRootFolder $rootFolder, |
|
| 86 | - ICloudIdManager $cloudIdManager, |
|
| 87 | - IContactsManager $contactsManager, |
|
| 88 | - IEventMerger $eventMerger) { |
|
| 89 | - $this->languageFactory = $languageFactory; |
|
| 90 | - $this->url = $url; |
|
| 91 | - $this->activityManager = $activityManager; |
|
| 92 | - $this->userManager = $userManager; |
|
| 93 | - $this->rootFolder = $rootFolder; |
|
| 94 | - $this->cloudIdManager = $cloudIdManager; |
|
| 95 | - $this->contactsManager = $contactsManager; |
|
| 96 | - $this->eventMerger = $eventMerger; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param string $language |
|
| 101 | - * @param IEvent $event |
|
| 102 | - * @param IEvent|null $previousEvent |
|
| 103 | - * @return IEvent |
|
| 104 | - * @throws \InvalidArgumentException |
|
| 105 | - * @since 11.0.0 |
|
| 106 | - */ |
|
| 107 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 108 | - if ($event->getApp() !== 'files') { |
|
| 109 | - throw new \InvalidArgumentException(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - $this->l = $this->languageFactory->get('files', $language); |
|
| 113 | - $this->activityLang = $this->languageFactory->get('activity', $language); |
|
| 114 | - |
|
| 115 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 116 | - try { |
|
| 117 | - return $this->parseShortVersion($event, $previousEvent); |
|
| 118 | - } catch (\InvalidArgumentException $e) { |
|
| 119 | - // Ignore and simply use the long version... |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $this->parseLongVersion($event, $previousEvent); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - protected function setIcon(IEvent $event, string $icon, string $app = 'files') { |
|
| 127 | - if ($this->activityManager->getRequirePNG()) { |
|
| 128 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon . '.png'))); |
|
| 129 | - } else { |
|
| 130 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon . '.svg'))); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @param IEvent $event |
|
| 136 | - * @param IEvent|null $previousEvent |
|
| 137 | - * @return IEvent |
|
| 138 | - * @throws \InvalidArgumentException |
|
| 139 | - * @since 11.0.0 |
|
| 140 | - */ |
|
| 141 | - public function parseShortVersion(IEvent $event, IEvent $previousEvent = null) { |
|
| 142 | - $parsedParameters = $this->getParameters($event); |
|
| 143 | - |
|
| 144 | - if ($event->getSubject() === 'created_by') { |
|
| 145 | - $subject = $this->l->t('Created by {user}'); |
|
| 146 | - $this->setIcon($event, 'add-color'); |
|
| 147 | - } elseif ($event->getSubject() === 'changed_by') { |
|
| 148 | - $subject = $this->l->t('Changed by {user}'); |
|
| 149 | - $this->setIcon($event, 'change'); |
|
| 150 | - } elseif ($event->getSubject() === 'deleted_by') { |
|
| 151 | - $subject = $this->l->t('Deleted by {user}'); |
|
| 152 | - $this->setIcon($event, 'delete-color'); |
|
| 153 | - } elseif ($event->getSubject() === 'restored_by') { |
|
| 154 | - $subject = $this->l->t('Restored by {user}'); |
|
| 155 | - $this->setIcon($event, 'actions/history', 'core'); |
|
| 156 | - } elseif ($event->getSubject() === 'renamed_by') { |
|
| 157 | - $subject = $this->l->t('Renamed by {user}'); |
|
| 158 | - $this->setIcon($event, 'change'); |
|
| 159 | - } elseif ($event->getSubject() === 'moved_by') { |
|
| 160 | - $subject = $this->l->t('Moved by {user}'); |
|
| 161 | - $this->setIcon($event, 'change'); |
|
| 162 | - } else { |
|
| 163 | - throw new \InvalidArgumentException(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if (!isset($parsedParameters['user'])) { |
|
| 167 | - // External user via public link share |
|
| 168 | - $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
| 172 | - |
|
| 173 | - return $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param IEvent $event |
|
| 178 | - * @param IEvent|null $previousEvent |
|
| 179 | - * @return IEvent |
|
| 180 | - * @throws \InvalidArgumentException |
|
| 181 | - * @since 11.0.0 |
|
| 182 | - */ |
|
| 183 | - public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
|
| 184 | - $this->fileIsEncrypted = false; |
|
| 185 | - $parsedParameters = $this->getParameters($event); |
|
| 186 | - |
|
| 187 | - if ($event->getSubject() === 'created_self') { |
|
| 188 | - $subject = $this->l->t('You created {file}'); |
|
| 189 | - if ($this->fileIsEncrypted) { |
|
| 190 | - $subject = $this->l->t('You created an encrypted file in {file}'); |
|
| 191 | - } |
|
| 192 | - $this->setIcon($event, 'add-color'); |
|
| 193 | - } elseif ($event->getSubject() === 'created_by') { |
|
| 194 | - $subject = $this->l->t('{user} created {file}'); |
|
| 195 | - if ($this->fileIsEncrypted) { |
|
| 196 | - $subject = $this->l->t('{user} created an encrypted file in {file}'); |
|
| 197 | - } |
|
| 198 | - $this->setIcon($event, 'add-color'); |
|
| 199 | - } elseif ($event->getSubject() === 'created_public') { |
|
| 200 | - $subject = $this->l->t('{file} was created in a public folder'); |
|
| 201 | - $this->setIcon($event, 'add-color'); |
|
| 202 | - } elseif ($event->getSubject() === 'changed_self') { |
|
| 203 | - $subject = $this->l->t('You changed {file}'); |
|
| 204 | - if ($this->fileIsEncrypted) { |
|
| 205 | - $subject = $this->l->t('You changed an encrypted file in {file}'); |
|
| 206 | - } |
|
| 207 | - $this->setIcon($event, 'change'); |
|
| 208 | - } elseif ($event->getSubject() === 'changed_by') { |
|
| 209 | - $subject = $this->l->t('{user} changed {file}'); |
|
| 210 | - if ($this->fileIsEncrypted) { |
|
| 211 | - $subject = $this->l->t('{user} changed an encrypted file in {file}'); |
|
| 212 | - } |
|
| 213 | - $this->setIcon($event, 'change'); |
|
| 214 | - } elseif ($event->getSubject() === 'deleted_self') { |
|
| 215 | - $subject = $this->l->t('You deleted {file}'); |
|
| 216 | - if ($this->fileIsEncrypted) { |
|
| 217 | - $subject = $this->l->t('You deleted an encrypted file in {file}'); |
|
| 218 | - } |
|
| 219 | - $this->setIcon($event, 'delete-color'); |
|
| 220 | - } elseif ($event->getSubject() === 'deleted_by') { |
|
| 221 | - $subject = $this->l->t('{user} deleted {file}'); |
|
| 222 | - if ($this->fileIsEncrypted) { |
|
| 223 | - $subject = $this->l->t('{user} deleted an encrypted file in {file}'); |
|
| 224 | - } |
|
| 225 | - $this->setIcon($event, 'delete-color'); |
|
| 226 | - } elseif ($event->getSubject() === 'restored_self') { |
|
| 227 | - $subject = $this->l->t('You restored {file}'); |
|
| 228 | - $this->setIcon($event, 'actions/history', 'core'); |
|
| 229 | - } elseif ($event->getSubject() === 'restored_by') { |
|
| 230 | - $subject = $this->l->t('{user} restored {file}'); |
|
| 231 | - $this->setIcon($event, 'actions/history', 'core'); |
|
| 232 | - } elseif ($event->getSubject() === 'renamed_self') { |
|
| 233 | - $oldFileName = $parsedParameters['oldfile']['name']; |
|
| 234 | - $newFileName = $parsedParameters['newfile']['name']; |
|
| 235 | - |
|
| 236 | - if ($this->isHiddenFile($oldFileName)) { |
|
| 237 | - if ($this->isHiddenFile($newFileName)) { |
|
| 238 | - $subject = $this->l->t('You renamed {oldfile} (hidden) to {newfile} (hidden)'); |
|
| 239 | - } else { |
|
| 240 | - $subject = $this->l->t('You renamed {oldfile} (hidden) to {newfile}'); |
|
| 241 | - } |
|
| 242 | - } else { |
|
| 243 | - if ($this->isHiddenFile($newFileName)) { |
|
| 244 | - $subject = $this->l->t('You renamed {oldfile} to {newfile} (hidden)'); |
|
| 245 | - } else { |
|
| 246 | - $subject = $this->l->t('You renamed {oldfile} to {newfile}'); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $this->setIcon($event, 'change'); |
|
| 251 | - } elseif ($event->getSubject() === 'renamed_by') { |
|
| 252 | - $oldFileName = $parsedParameters['oldfile']['name']; |
|
| 253 | - $newFileName = $parsedParameters['newfile']['name']; |
|
| 254 | - |
|
| 255 | - if ($this->isHiddenFile($oldFileName)) { |
|
| 256 | - if ($this->isHiddenFile($newFileName)) { |
|
| 257 | - $subject = $this->l->t('{user} renamed {oldfile} (hidden) to {newfile} (hidden)'); |
|
| 258 | - } else { |
|
| 259 | - $subject = $this->l->t('{user} renamed {oldfile} (hidden) to {newfile}'); |
|
| 260 | - } |
|
| 261 | - } else { |
|
| 262 | - if ($this->isHiddenFile($newFileName)) { |
|
| 263 | - $subject = $this->l->t('{user} renamed {oldfile} to {newfile} (hidden)'); |
|
| 264 | - } else { |
|
| 265 | - $subject = $this->l->t('{user} renamed {oldfile} to {newfile}'); |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $this->setIcon($event, 'change'); |
|
| 270 | - } elseif ($event->getSubject() === 'moved_self') { |
|
| 271 | - $subject = $this->l->t('You moved {oldfile} to {newfile}'); |
|
| 272 | - $this->setIcon($event, 'change'); |
|
| 273 | - } elseif ($event->getSubject() === 'moved_by') { |
|
| 274 | - $subject = $this->l->t('{user} moved {oldfile} to {newfile}'); |
|
| 275 | - $this->setIcon($event, 'change'); |
|
| 276 | - } else { |
|
| 277 | - throw new \InvalidArgumentException(); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - if ($this->fileIsEncrypted) { |
|
| 281 | - $event->setSubject($event->getSubject() . '_enc', $event->getSubjectParameters()); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - if (!isset($parsedParameters['user'])) { |
|
| 285 | - // External user via public link share |
|
| 286 | - $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
| 290 | - |
|
| 291 | - if ($event->getSubject() === 'moved_self' || $event->getSubject() === 'moved_by') { |
|
| 292 | - $event = $this->eventMerger->mergeEvents('oldfile', $event, $previousEvent); |
|
| 293 | - } else { |
|
| 294 | - $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - if ($event->getChildEvent() === null) { |
|
| 298 | - // Couldn't group by file, maybe we can group by user |
|
| 299 | - $event = $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - return $event; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - private function isHiddenFile(string $filename): bool { |
|
| 306 | - return strlen($filename) > 0 && $filename[0] === '.'; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 310 | - $placeholders = $replacements = []; |
|
| 311 | - foreach ($parameters as $placeholder => $parameter) { |
|
| 312 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 313 | - if ($parameter['type'] === 'file') { |
|
| 314 | - $replacements[] = $parameter['path']; |
|
| 315 | - } else { |
|
| 316 | - $replacements[] = $parameter['name']; |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 321 | - ->setRichSubject($subject, $parameters); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * @param IEvent $event |
|
| 326 | - * @return array |
|
| 327 | - * @throws \InvalidArgumentException |
|
| 328 | - */ |
|
| 329 | - protected function getParameters(IEvent $event) { |
|
| 330 | - $parameters = $event->getSubjectParameters(); |
|
| 331 | - switch ($event->getSubject()) { |
|
| 332 | - case 'created_self': |
|
| 333 | - case 'created_public': |
|
| 334 | - case 'changed_self': |
|
| 335 | - case 'deleted_self': |
|
| 336 | - case 'restored_self': |
|
| 337 | - return [ |
|
| 338 | - 'file' => $this->getFile($parameters[0], $event), |
|
| 339 | - ]; |
|
| 340 | - case 'created_by': |
|
| 341 | - case 'changed_by': |
|
| 342 | - case 'deleted_by': |
|
| 343 | - case 'restored_by': |
|
| 344 | - if ($parameters[1] === '') { |
|
| 345 | - // External user via public link share |
|
| 346 | - return [ |
|
| 347 | - 'file' => $this->getFile($parameters[0], $event), |
|
| 348 | - ]; |
|
| 349 | - } |
|
| 350 | - return [ |
|
| 351 | - 'file' => $this->getFile($parameters[0], $event), |
|
| 352 | - 'user' => $this->getUser($parameters[1]), |
|
| 353 | - ]; |
|
| 354 | - case 'renamed_self': |
|
| 355 | - case 'moved_self': |
|
| 356 | - return [ |
|
| 357 | - 'newfile' => $this->getFile($parameters[0]), |
|
| 358 | - 'oldfile' => $this->getFile($parameters[1]), |
|
| 359 | - ]; |
|
| 360 | - case 'renamed_by': |
|
| 361 | - case 'moved_by': |
|
| 362 | - if ($parameters[1] === '') { |
|
| 363 | - // External user via public link share |
|
| 364 | - return [ |
|
| 365 | - 'newfile' => $this->getFile($parameters[0]), |
|
| 366 | - 'oldfile' => $this->getFile($parameters[2]), |
|
| 367 | - ]; |
|
| 368 | - } |
|
| 369 | - return [ |
|
| 370 | - 'newfile' => $this->getFile($parameters[0]), |
|
| 371 | - 'user' => $this->getUser($parameters[1]), |
|
| 372 | - 'oldfile' => $this->getFile($parameters[2]), |
|
| 373 | - ]; |
|
| 374 | - } |
|
| 375 | - return []; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * @param array|string $parameter |
|
| 380 | - * @param IEvent|null $event |
|
| 381 | - * @return array |
|
| 382 | - * @throws \InvalidArgumentException |
|
| 383 | - */ |
|
| 384 | - protected function getFile($parameter, IEvent $event = null) { |
|
| 385 | - if (is_array($parameter)) { |
|
| 386 | - $path = reset($parameter); |
|
| 387 | - $id = (string) key($parameter); |
|
| 388 | - } elseif ($event !== null) { |
|
| 389 | - // Legacy from before ownCloud 8.2 |
|
| 390 | - $path = $parameter; |
|
| 391 | - $id = $event->getObjectId(); |
|
| 392 | - } else { |
|
| 393 | - throw new \InvalidArgumentException('Could not generate file parameter'); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - $encryptionContainer = $this->getEndToEndEncryptionContainer($id, $path); |
|
| 397 | - if ($encryptionContainer instanceof Folder) { |
|
| 398 | - $this->fileIsEncrypted = true; |
|
| 399 | - try { |
|
| 400 | - $fullPath = rtrim($encryptionContainer->getPath(), '/'); |
|
| 401 | - // Remove /user/files/... |
|
| 402 | - [,,, $path] = explode('/', $fullPath, 4); |
|
| 403 | - if (!$path) { |
|
| 404 | - throw new InvalidPathException('Path could not be split correctly'); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - return [ |
|
| 408 | - 'type' => 'file', |
|
| 409 | - 'id' => $encryptionContainer->getId(), |
|
| 410 | - 'name' => $encryptionContainer->getName(), |
|
| 411 | - 'path' => $path, |
|
| 412 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $encryptionContainer->getId()]), |
|
| 413 | - ]; |
|
| 414 | - } catch (\Exception $e) { |
|
| 415 | - // fall back to the normal one |
|
| 416 | - $this->fileIsEncrypted = false; |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - return [ |
|
| 421 | - 'type' => 'file', |
|
| 422 | - 'id' => $id, |
|
| 423 | - 'name' => basename($path), |
|
| 424 | - 'path' => trim($path, '/'), |
|
| 425 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 426 | - ]; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - protected $fileEncrypted = []; |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * Check if a file is end2end encrypted |
|
| 433 | - * @param int $fileId |
|
| 434 | - * @param string $path |
|
| 435 | - * @return Folder|null |
|
| 436 | - */ |
|
| 437 | - protected function getEndToEndEncryptionContainer($fileId, $path) { |
|
| 438 | - if (isset($this->fileEncrypted[$fileId])) { |
|
| 439 | - return $this->fileEncrypted[$fileId]; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - $fileName = basename($path); |
|
| 443 | - if (!preg_match('/^[0-9a-fA-F]{32}$/', $fileName)) { |
|
| 444 | - $this->fileEncrypted[$fileId] = false; |
|
| 445 | - return $this->fileEncrypted[$fileId]; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - $userFolder = $this->rootFolder->getUserFolder($this->activityManager->getCurrentUserId()); |
|
| 449 | - $files = $userFolder->getById($fileId); |
|
| 450 | - if (empty($files)) { |
|
| 451 | - try { |
|
| 452 | - // Deleted, try with parent |
|
| 453 | - $file = $this->findExistingParent($userFolder, dirname($path)); |
|
| 454 | - } catch (NotFoundException $e) { |
|
| 455 | - return null; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - if (!$file instanceof Folder || !$file->isEncrypted()) { |
|
| 459 | - return null; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - $this->fileEncrypted[$fileId] = $file; |
|
| 463 | - return $file; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - $file = array_shift($files); |
|
| 467 | - |
|
| 468 | - if ($file instanceof Folder && $file->isEncrypted()) { |
|
| 469 | - // If the folder is encrypted, it is the Container, |
|
| 470 | - // but can be the name is just fine. |
|
| 471 | - $this->fileEncrypted[$fileId] = true; |
|
| 472 | - return null; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - $this->fileEncrypted[$fileId] = $this->getParentEndToEndEncryptionContainer($userFolder, $file); |
|
| 476 | - return $this->fileEncrypted[$fileId]; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * @param Folder $userFolder |
|
| 481 | - * @param string $path |
|
| 482 | - * @return Folder |
|
| 483 | - * @throws NotFoundException |
|
| 484 | - */ |
|
| 485 | - protected function findExistingParent(Folder $userFolder, $path) { |
|
| 486 | - if ($path === '/') { |
|
| 487 | - throw new NotFoundException('Reached the root'); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - try { |
|
| 491 | - $folder = $userFolder->get(dirname($path)); |
|
| 492 | - } catch (NotFoundException $e) { |
|
| 493 | - return $this->findExistingParent($userFolder, dirname($path)); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return $folder; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * Check all parents until the user's root folder if one is encrypted |
|
| 501 | - * |
|
| 502 | - * @param Folder $userFolder |
|
| 503 | - * @param Node $file |
|
| 504 | - * @return Node|null |
|
| 505 | - */ |
|
| 506 | - protected function getParentEndToEndEncryptionContainer(Folder $userFolder, Node $file) { |
|
| 507 | - try { |
|
| 508 | - $parent = $file->getParent(); |
|
| 509 | - |
|
| 510 | - if ($userFolder->getId() === $parent->getId()) { |
|
| 511 | - return null; |
|
| 512 | - } |
|
| 513 | - } catch (\Exception $e) { |
|
| 514 | - return null; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - if ($parent->isEncrypted()) { |
|
| 518 | - return $parent; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - return $this->getParentEndToEndEncryptionContainer($userFolder, $parent); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * @param string $uid |
|
| 526 | - * @return array |
|
| 527 | - */ |
|
| 528 | - protected function getUser($uid) { |
|
| 529 | - // First try local user |
|
| 530 | - $displayName = $this->userManager->getDisplayName($uid); |
|
| 531 | - if ($displayName !== null) { |
|
| 532 | - return [ |
|
| 533 | - 'type' => 'user', |
|
| 534 | - 'id' => $uid, |
|
| 535 | - 'name' => $displayName, |
|
| 536 | - ]; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - // Then a contact from the addressbook |
|
| 540 | - if ($this->cloudIdManager->isValidCloudId($uid)) { |
|
| 541 | - $cloudId = $this->cloudIdManager->resolveCloudId($uid); |
|
| 542 | - return [ |
|
| 543 | - 'type' => 'user', |
|
| 544 | - 'id' => $cloudId->getUser(), |
|
| 545 | - 'name' => $this->getDisplayNameFromAddressBook($cloudId->getDisplayId()), |
|
| 546 | - 'server' => $cloudId->getRemote(), |
|
| 547 | - ]; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - // Fallback to empty dummy data |
|
| 551 | - return [ |
|
| 552 | - 'type' => 'user', |
|
| 553 | - 'id' => $uid, |
|
| 554 | - 'name' => $uid, |
|
| 555 | - ]; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - protected function getDisplayNameFromAddressBook(string $search): string { |
|
| 559 | - if (isset($this->displayNames[$search])) { |
|
| 560 | - return $this->displayNames[$search]; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD'], [ |
|
| 564 | - 'limit' => 1, |
|
| 565 | - 'enumeration' => false, |
|
| 566 | - 'fullmatch' => false, |
|
| 567 | - 'strict_search' => true, |
|
| 568 | - ]); |
|
| 569 | - foreach ($addressBookContacts as $contact) { |
|
| 570 | - if (isset($contact['isLocalSystemBook'])) { |
|
| 571 | - continue; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - if (isset($contact['CLOUD'])) { |
|
| 575 | - $cloudIds = $contact['CLOUD']; |
|
| 576 | - if (is_string($cloudIds)) { |
|
| 577 | - $cloudIds = [$cloudIds]; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - $lowerSearch = strtolower($search); |
|
| 581 | - foreach ($cloudIds as $cloudId) { |
|
| 582 | - if (strtolower($cloudId) === $lowerSearch) { |
|
| 583 | - $this->displayNames[$search] = $contact['FN'] . " ($cloudId)"; |
|
| 584 | - return $this->displayNames[$search]; |
|
| 585 | - } |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - return $search; |
|
| 591 | - } |
|
| 47 | + /** @var IFactory */ |
|
| 48 | + protected $languageFactory; |
|
| 49 | + |
|
| 50 | + /** @var IL10N */ |
|
| 51 | + protected $l; |
|
| 52 | + /** @var IL10N */ |
|
| 53 | + protected $activityLang; |
|
| 54 | + |
|
| 55 | + /** @var IURLGenerator */ |
|
| 56 | + protected $url; |
|
| 57 | + |
|
| 58 | + /** @var IManager */ |
|
| 59 | + protected $activityManager; |
|
| 60 | + |
|
| 61 | + /** @var IUserManager */ |
|
| 62 | + protected $userManager; |
|
| 63 | + |
|
| 64 | + /** @var IRootFolder */ |
|
| 65 | + protected $rootFolder; |
|
| 66 | + |
|
| 67 | + /** @var IEventMerger */ |
|
| 68 | + protected $eventMerger; |
|
| 69 | + |
|
| 70 | + /** @var ICloudIdManager */ |
|
| 71 | + protected $cloudIdManager; |
|
| 72 | + |
|
| 73 | + /** @var IContactsManager */ |
|
| 74 | + protected $contactsManager; |
|
| 75 | + |
|
| 76 | + /** @var string[] cached displayNames - key is the cloud id and value the displayname */ |
|
| 77 | + protected $displayNames = []; |
|
| 78 | + |
|
| 79 | + protected $fileIsEncrypted = false; |
|
| 80 | + |
|
| 81 | + public function __construct(IFactory $languageFactory, |
|
| 82 | + IURLGenerator $url, |
|
| 83 | + IManager $activityManager, |
|
| 84 | + IUserManager $userManager, |
|
| 85 | + IRootFolder $rootFolder, |
|
| 86 | + ICloudIdManager $cloudIdManager, |
|
| 87 | + IContactsManager $contactsManager, |
|
| 88 | + IEventMerger $eventMerger) { |
|
| 89 | + $this->languageFactory = $languageFactory; |
|
| 90 | + $this->url = $url; |
|
| 91 | + $this->activityManager = $activityManager; |
|
| 92 | + $this->userManager = $userManager; |
|
| 93 | + $this->rootFolder = $rootFolder; |
|
| 94 | + $this->cloudIdManager = $cloudIdManager; |
|
| 95 | + $this->contactsManager = $contactsManager; |
|
| 96 | + $this->eventMerger = $eventMerger; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param string $language |
|
| 101 | + * @param IEvent $event |
|
| 102 | + * @param IEvent|null $previousEvent |
|
| 103 | + * @return IEvent |
|
| 104 | + * @throws \InvalidArgumentException |
|
| 105 | + * @since 11.0.0 |
|
| 106 | + */ |
|
| 107 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 108 | + if ($event->getApp() !== 'files') { |
|
| 109 | + throw new \InvalidArgumentException(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + $this->l = $this->languageFactory->get('files', $language); |
|
| 113 | + $this->activityLang = $this->languageFactory->get('activity', $language); |
|
| 114 | + |
|
| 115 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 116 | + try { |
|
| 117 | + return $this->parseShortVersion($event, $previousEvent); |
|
| 118 | + } catch (\InvalidArgumentException $e) { |
|
| 119 | + // Ignore and simply use the long version... |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $this->parseLongVersion($event, $previousEvent); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + protected function setIcon(IEvent $event, string $icon, string $app = 'files') { |
|
| 127 | + if ($this->activityManager->getRequirePNG()) { |
|
| 128 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon . '.png'))); |
|
| 129 | + } else { |
|
| 130 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath($app, $icon . '.svg'))); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @param IEvent $event |
|
| 136 | + * @param IEvent|null $previousEvent |
|
| 137 | + * @return IEvent |
|
| 138 | + * @throws \InvalidArgumentException |
|
| 139 | + * @since 11.0.0 |
|
| 140 | + */ |
|
| 141 | + public function parseShortVersion(IEvent $event, IEvent $previousEvent = null) { |
|
| 142 | + $parsedParameters = $this->getParameters($event); |
|
| 143 | + |
|
| 144 | + if ($event->getSubject() === 'created_by') { |
|
| 145 | + $subject = $this->l->t('Created by {user}'); |
|
| 146 | + $this->setIcon($event, 'add-color'); |
|
| 147 | + } elseif ($event->getSubject() === 'changed_by') { |
|
| 148 | + $subject = $this->l->t('Changed by {user}'); |
|
| 149 | + $this->setIcon($event, 'change'); |
|
| 150 | + } elseif ($event->getSubject() === 'deleted_by') { |
|
| 151 | + $subject = $this->l->t('Deleted by {user}'); |
|
| 152 | + $this->setIcon($event, 'delete-color'); |
|
| 153 | + } elseif ($event->getSubject() === 'restored_by') { |
|
| 154 | + $subject = $this->l->t('Restored by {user}'); |
|
| 155 | + $this->setIcon($event, 'actions/history', 'core'); |
|
| 156 | + } elseif ($event->getSubject() === 'renamed_by') { |
|
| 157 | + $subject = $this->l->t('Renamed by {user}'); |
|
| 158 | + $this->setIcon($event, 'change'); |
|
| 159 | + } elseif ($event->getSubject() === 'moved_by') { |
|
| 160 | + $subject = $this->l->t('Moved by {user}'); |
|
| 161 | + $this->setIcon($event, 'change'); |
|
| 162 | + } else { |
|
| 163 | + throw new \InvalidArgumentException(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if (!isset($parsedParameters['user'])) { |
|
| 167 | + // External user via public link share |
|
| 168 | + $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
| 172 | + |
|
| 173 | + return $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param IEvent $event |
|
| 178 | + * @param IEvent|null $previousEvent |
|
| 179 | + * @return IEvent |
|
| 180 | + * @throws \InvalidArgumentException |
|
| 181 | + * @since 11.0.0 |
|
| 182 | + */ |
|
| 183 | + public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
|
| 184 | + $this->fileIsEncrypted = false; |
|
| 185 | + $parsedParameters = $this->getParameters($event); |
|
| 186 | + |
|
| 187 | + if ($event->getSubject() === 'created_self') { |
|
| 188 | + $subject = $this->l->t('You created {file}'); |
|
| 189 | + if ($this->fileIsEncrypted) { |
|
| 190 | + $subject = $this->l->t('You created an encrypted file in {file}'); |
|
| 191 | + } |
|
| 192 | + $this->setIcon($event, 'add-color'); |
|
| 193 | + } elseif ($event->getSubject() === 'created_by') { |
|
| 194 | + $subject = $this->l->t('{user} created {file}'); |
|
| 195 | + if ($this->fileIsEncrypted) { |
|
| 196 | + $subject = $this->l->t('{user} created an encrypted file in {file}'); |
|
| 197 | + } |
|
| 198 | + $this->setIcon($event, 'add-color'); |
|
| 199 | + } elseif ($event->getSubject() === 'created_public') { |
|
| 200 | + $subject = $this->l->t('{file} was created in a public folder'); |
|
| 201 | + $this->setIcon($event, 'add-color'); |
|
| 202 | + } elseif ($event->getSubject() === 'changed_self') { |
|
| 203 | + $subject = $this->l->t('You changed {file}'); |
|
| 204 | + if ($this->fileIsEncrypted) { |
|
| 205 | + $subject = $this->l->t('You changed an encrypted file in {file}'); |
|
| 206 | + } |
|
| 207 | + $this->setIcon($event, 'change'); |
|
| 208 | + } elseif ($event->getSubject() === 'changed_by') { |
|
| 209 | + $subject = $this->l->t('{user} changed {file}'); |
|
| 210 | + if ($this->fileIsEncrypted) { |
|
| 211 | + $subject = $this->l->t('{user} changed an encrypted file in {file}'); |
|
| 212 | + } |
|
| 213 | + $this->setIcon($event, 'change'); |
|
| 214 | + } elseif ($event->getSubject() === 'deleted_self') { |
|
| 215 | + $subject = $this->l->t('You deleted {file}'); |
|
| 216 | + if ($this->fileIsEncrypted) { |
|
| 217 | + $subject = $this->l->t('You deleted an encrypted file in {file}'); |
|
| 218 | + } |
|
| 219 | + $this->setIcon($event, 'delete-color'); |
|
| 220 | + } elseif ($event->getSubject() === 'deleted_by') { |
|
| 221 | + $subject = $this->l->t('{user} deleted {file}'); |
|
| 222 | + if ($this->fileIsEncrypted) { |
|
| 223 | + $subject = $this->l->t('{user} deleted an encrypted file in {file}'); |
|
| 224 | + } |
|
| 225 | + $this->setIcon($event, 'delete-color'); |
|
| 226 | + } elseif ($event->getSubject() === 'restored_self') { |
|
| 227 | + $subject = $this->l->t('You restored {file}'); |
|
| 228 | + $this->setIcon($event, 'actions/history', 'core'); |
|
| 229 | + } elseif ($event->getSubject() === 'restored_by') { |
|
| 230 | + $subject = $this->l->t('{user} restored {file}'); |
|
| 231 | + $this->setIcon($event, 'actions/history', 'core'); |
|
| 232 | + } elseif ($event->getSubject() === 'renamed_self') { |
|
| 233 | + $oldFileName = $parsedParameters['oldfile']['name']; |
|
| 234 | + $newFileName = $parsedParameters['newfile']['name']; |
|
| 235 | + |
|
| 236 | + if ($this->isHiddenFile($oldFileName)) { |
|
| 237 | + if ($this->isHiddenFile($newFileName)) { |
|
| 238 | + $subject = $this->l->t('You renamed {oldfile} (hidden) to {newfile} (hidden)'); |
|
| 239 | + } else { |
|
| 240 | + $subject = $this->l->t('You renamed {oldfile} (hidden) to {newfile}'); |
|
| 241 | + } |
|
| 242 | + } else { |
|
| 243 | + if ($this->isHiddenFile($newFileName)) { |
|
| 244 | + $subject = $this->l->t('You renamed {oldfile} to {newfile} (hidden)'); |
|
| 245 | + } else { |
|
| 246 | + $subject = $this->l->t('You renamed {oldfile} to {newfile}'); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $this->setIcon($event, 'change'); |
|
| 251 | + } elseif ($event->getSubject() === 'renamed_by') { |
|
| 252 | + $oldFileName = $parsedParameters['oldfile']['name']; |
|
| 253 | + $newFileName = $parsedParameters['newfile']['name']; |
|
| 254 | + |
|
| 255 | + if ($this->isHiddenFile($oldFileName)) { |
|
| 256 | + if ($this->isHiddenFile($newFileName)) { |
|
| 257 | + $subject = $this->l->t('{user} renamed {oldfile} (hidden) to {newfile} (hidden)'); |
|
| 258 | + } else { |
|
| 259 | + $subject = $this->l->t('{user} renamed {oldfile} (hidden) to {newfile}'); |
|
| 260 | + } |
|
| 261 | + } else { |
|
| 262 | + if ($this->isHiddenFile($newFileName)) { |
|
| 263 | + $subject = $this->l->t('{user} renamed {oldfile} to {newfile} (hidden)'); |
|
| 264 | + } else { |
|
| 265 | + $subject = $this->l->t('{user} renamed {oldfile} to {newfile}'); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $this->setIcon($event, 'change'); |
|
| 270 | + } elseif ($event->getSubject() === 'moved_self') { |
|
| 271 | + $subject = $this->l->t('You moved {oldfile} to {newfile}'); |
|
| 272 | + $this->setIcon($event, 'change'); |
|
| 273 | + } elseif ($event->getSubject() === 'moved_by') { |
|
| 274 | + $subject = $this->l->t('{user} moved {oldfile} to {newfile}'); |
|
| 275 | + $this->setIcon($event, 'change'); |
|
| 276 | + } else { |
|
| 277 | + throw new \InvalidArgumentException(); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + if ($this->fileIsEncrypted) { |
|
| 281 | + $event->setSubject($event->getSubject() . '_enc', $event->getSubjectParameters()); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + if (!isset($parsedParameters['user'])) { |
|
| 285 | + // External user via public link share |
|
| 286 | + $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
| 290 | + |
|
| 291 | + if ($event->getSubject() === 'moved_self' || $event->getSubject() === 'moved_by') { |
|
| 292 | + $event = $this->eventMerger->mergeEvents('oldfile', $event, $previousEvent); |
|
| 293 | + } else { |
|
| 294 | + $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + if ($event->getChildEvent() === null) { |
|
| 298 | + // Couldn't group by file, maybe we can group by user |
|
| 299 | + $event = $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + return $event; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + private function isHiddenFile(string $filename): bool { |
|
| 306 | + return strlen($filename) > 0 && $filename[0] === '.'; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 310 | + $placeholders = $replacements = []; |
|
| 311 | + foreach ($parameters as $placeholder => $parameter) { |
|
| 312 | + $placeholders[] = '{' . $placeholder . '}'; |
|
| 313 | + if ($parameter['type'] === 'file') { |
|
| 314 | + $replacements[] = $parameter['path']; |
|
| 315 | + } else { |
|
| 316 | + $replacements[] = $parameter['name']; |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 321 | + ->setRichSubject($subject, $parameters); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * @param IEvent $event |
|
| 326 | + * @return array |
|
| 327 | + * @throws \InvalidArgumentException |
|
| 328 | + */ |
|
| 329 | + protected function getParameters(IEvent $event) { |
|
| 330 | + $parameters = $event->getSubjectParameters(); |
|
| 331 | + switch ($event->getSubject()) { |
|
| 332 | + case 'created_self': |
|
| 333 | + case 'created_public': |
|
| 334 | + case 'changed_self': |
|
| 335 | + case 'deleted_self': |
|
| 336 | + case 'restored_self': |
|
| 337 | + return [ |
|
| 338 | + 'file' => $this->getFile($parameters[0], $event), |
|
| 339 | + ]; |
|
| 340 | + case 'created_by': |
|
| 341 | + case 'changed_by': |
|
| 342 | + case 'deleted_by': |
|
| 343 | + case 'restored_by': |
|
| 344 | + if ($parameters[1] === '') { |
|
| 345 | + // External user via public link share |
|
| 346 | + return [ |
|
| 347 | + 'file' => $this->getFile($parameters[0], $event), |
|
| 348 | + ]; |
|
| 349 | + } |
|
| 350 | + return [ |
|
| 351 | + 'file' => $this->getFile($parameters[0], $event), |
|
| 352 | + 'user' => $this->getUser($parameters[1]), |
|
| 353 | + ]; |
|
| 354 | + case 'renamed_self': |
|
| 355 | + case 'moved_self': |
|
| 356 | + return [ |
|
| 357 | + 'newfile' => $this->getFile($parameters[0]), |
|
| 358 | + 'oldfile' => $this->getFile($parameters[1]), |
|
| 359 | + ]; |
|
| 360 | + case 'renamed_by': |
|
| 361 | + case 'moved_by': |
|
| 362 | + if ($parameters[1] === '') { |
|
| 363 | + // External user via public link share |
|
| 364 | + return [ |
|
| 365 | + 'newfile' => $this->getFile($parameters[0]), |
|
| 366 | + 'oldfile' => $this->getFile($parameters[2]), |
|
| 367 | + ]; |
|
| 368 | + } |
|
| 369 | + return [ |
|
| 370 | + 'newfile' => $this->getFile($parameters[0]), |
|
| 371 | + 'user' => $this->getUser($parameters[1]), |
|
| 372 | + 'oldfile' => $this->getFile($parameters[2]), |
|
| 373 | + ]; |
|
| 374 | + } |
|
| 375 | + return []; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * @param array|string $parameter |
|
| 380 | + * @param IEvent|null $event |
|
| 381 | + * @return array |
|
| 382 | + * @throws \InvalidArgumentException |
|
| 383 | + */ |
|
| 384 | + protected function getFile($parameter, IEvent $event = null) { |
|
| 385 | + if (is_array($parameter)) { |
|
| 386 | + $path = reset($parameter); |
|
| 387 | + $id = (string) key($parameter); |
|
| 388 | + } elseif ($event !== null) { |
|
| 389 | + // Legacy from before ownCloud 8.2 |
|
| 390 | + $path = $parameter; |
|
| 391 | + $id = $event->getObjectId(); |
|
| 392 | + } else { |
|
| 393 | + throw new \InvalidArgumentException('Could not generate file parameter'); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + $encryptionContainer = $this->getEndToEndEncryptionContainer($id, $path); |
|
| 397 | + if ($encryptionContainer instanceof Folder) { |
|
| 398 | + $this->fileIsEncrypted = true; |
|
| 399 | + try { |
|
| 400 | + $fullPath = rtrim($encryptionContainer->getPath(), '/'); |
|
| 401 | + // Remove /user/files/... |
|
| 402 | + [,,, $path] = explode('/', $fullPath, 4); |
|
| 403 | + if (!$path) { |
|
| 404 | + throw new InvalidPathException('Path could not be split correctly'); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + return [ |
|
| 408 | + 'type' => 'file', |
|
| 409 | + 'id' => $encryptionContainer->getId(), |
|
| 410 | + 'name' => $encryptionContainer->getName(), |
|
| 411 | + 'path' => $path, |
|
| 412 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $encryptionContainer->getId()]), |
|
| 413 | + ]; |
|
| 414 | + } catch (\Exception $e) { |
|
| 415 | + // fall back to the normal one |
|
| 416 | + $this->fileIsEncrypted = false; |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + return [ |
|
| 421 | + 'type' => 'file', |
|
| 422 | + 'id' => $id, |
|
| 423 | + 'name' => basename($path), |
|
| 424 | + 'path' => trim($path, '/'), |
|
| 425 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 426 | + ]; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + protected $fileEncrypted = []; |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * Check if a file is end2end encrypted |
|
| 433 | + * @param int $fileId |
|
| 434 | + * @param string $path |
|
| 435 | + * @return Folder|null |
|
| 436 | + */ |
|
| 437 | + protected function getEndToEndEncryptionContainer($fileId, $path) { |
|
| 438 | + if (isset($this->fileEncrypted[$fileId])) { |
|
| 439 | + return $this->fileEncrypted[$fileId]; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + $fileName = basename($path); |
|
| 443 | + if (!preg_match('/^[0-9a-fA-F]{32}$/', $fileName)) { |
|
| 444 | + $this->fileEncrypted[$fileId] = false; |
|
| 445 | + return $this->fileEncrypted[$fileId]; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + $userFolder = $this->rootFolder->getUserFolder($this->activityManager->getCurrentUserId()); |
|
| 449 | + $files = $userFolder->getById($fileId); |
|
| 450 | + if (empty($files)) { |
|
| 451 | + try { |
|
| 452 | + // Deleted, try with parent |
|
| 453 | + $file = $this->findExistingParent($userFolder, dirname($path)); |
|
| 454 | + } catch (NotFoundException $e) { |
|
| 455 | + return null; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + if (!$file instanceof Folder || !$file->isEncrypted()) { |
|
| 459 | + return null; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + $this->fileEncrypted[$fileId] = $file; |
|
| 463 | + return $file; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + $file = array_shift($files); |
|
| 467 | + |
|
| 468 | + if ($file instanceof Folder && $file->isEncrypted()) { |
|
| 469 | + // If the folder is encrypted, it is the Container, |
|
| 470 | + // but can be the name is just fine. |
|
| 471 | + $this->fileEncrypted[$fileId] = true; |
|
| 472 | + return null; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + $this->fileEncrypted[$fileId] = $this->getParentEndToEndEncryptionContainer($userFolder, $file); |
|
| 476 | + return $this->fileEncrypted[$fileId]; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * @param Folder $userFolder |
|
| 481 | + * @param string $path |
|
| 482 | + * @return Folder |
|
| 483 | + * @throws NotFoundException |
|
| 484 | + */ |
|
| 485 | + protected function findExistingParent(Folder $userFolder, $path) { |
|
| 486 | + if ($path === '/') { |
|
| 487 | + throw new NotFoundException('Reached the root'); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + try { |
|
| 491 | + $folder = $userFolder->get(dirname($path)); |
|
| 492 | + } catch (NotFoundException $e) { |
|
| 493 | + return $this->findExistingParent($userFolder, dirname($path)); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return $folder; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * Check all parents until the user's root folder if one is encrypted |
|
| 501 | + * |
|
| 502 | + * @param Folder $userFolder |
|
| 503 | + * @param Node $file |
|
| 504 | + * @return Node|null |
|
| 505 | + */ |
|
| 506 | + protected function getParentEndToEndEncryptionContainer(Folder $userFolder, Node $file) { |
|
| 507 | + try { |
|
| 508 | + $parent = $file->getParent(); |
|
| 509 | + |
|
| 510 | + if ($userFolder->getId() === $parent->getId()) { |
|
| 511 | + return null; |
|
| 512 | + } |
|
| 513 | + } catch (\Exception $e) { |
|
| 514 | + return null; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + if ($parent->isEncrypted()) { |
|
| 518 | + return $parent; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + return $this->getParentEndToEndEncryptionContainer($userFolder, $parent); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * @param string $uid |
|
| 526 | + * @return array |
|
| 527 | + */ |
|
| 528 | + protected function getUser($uid) { |
|
| 529 | + // First try local user |
|
| 530 | + $displayName = $this->userManager->getDisplayName($uid); |
|
| 531 | + if ($displayName !== null) { |
|
| 532 | + return [ |
|
| 533 | + 'type' => 'user', |
|
| 534 | + 'id' => $uid, |
|
| 535 | + 'name' => $displayName, |
|
| 536 | + ]; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + // Then a contact from the addressbook |
|
| 540 | + if ($this->cloudIdManager->isValidCloudId($uid)) { |
|
| 541 | + $cloudId = $this->cloudIdManager->resolveCloudId($uid); |
|
| 542 | + return [ |
|
| 543 | + 'type' => 'user', |
|
| 544 | + 'id' => $cloudId->getUser(), |
|
| 545 | + 'name' => $this->getDisplayNameFromAddressBook($cloudId->getDisplayId()), |
|
| 546 | + 'server' => $cloudId->getRemote(), |
|
| 547 | + ]; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + // Fallback to empty dummy data |
|
| 551 | + return [ |
|
| 552 | + 'type' => 'user', |
|
| 553 | + 'id' => $uid, |
|
| 554 | + 'name' => $uid, |
|
| 555 | + ]; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + protected function getDisplayNameFromAddressBook(string $search): string { |
|
| 559 | + if (isset($this->displayNames[$search])) { |
|
| 560 | + return $this->displayNames[$search]; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD'], [ |
|
| 564 | + 'limit' => 1, |
|
| 565 | + 'enumeration' => false, |
|
| 566 | + 'fullmatch' => false, |
|
| 567 | + 'strict_search' => true, |
|
| 568 | + ]); |
|
| 569 | + foreach ($addressBookContacts as $contact) { |
|
| 570 | + if (isset($contact['isLocalSystemBook'])) { |
|
| 571 | + continue; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + if (isset($contact['CLOUD'])) { |
|
| 575 | + $cloudIds = $contact['CLOUD']; |
|
| 576 | + if (is_string($cloudIds)) { |
|
| 577 | + $cloudIds = [$cloudIds]; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + $lowerSearch = strtolower($search); |
|
| 581 | + foreach ($cloudIds as $cloudId) { |
|
| 582 | + if (strtolower($cloudId) === $lowerSearch) { |
|
| 583 | + $this->displayNames[$search] = $contact['FN'] . " ($cloudId)"; |
|
| 584 | + return $this->displayNames[$search]; |
|
| 585 | + } |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + return $search; |
|
| 591 | + } |
|
| 592 | 592 | } |
@@ -37,341 +37,341 @@ |
||
| 37 | 37 | |
| 38 | 38 | class Activity implements IProvider { |
| 39 | 39 | |
| 40 | - /** @var IFactory */ |
|
| 41 | - protected $languageFactory; |
|
| 40 | + /** @var IFactory */ |
|
| 41 | + protected $languageFactory; |
|
| 42 | 42 | |
| 43 | - /** @var IL10N */ |
|
| 44 | - protected $l; |
|
| 43 | + /** @var IL10N */ |
|
| 44 | + protected $l; |
|
| 45 | 45 | |
| 46 | - /** @var IURLGenerator */ |
|
| 47 | - protected $url; |
|
| 46 | + /** @var IURLGenerator */ |
|
| 47 | + protected $url; |
|
| 48 | 48 | |
| 49 | - /** @var IManager */ |
|
| 50 | - protected $activityManager; |
|
| 49 | + /** @var IManager */ |
|
| 50 | + protected $activityManager; |
|
| 51 | 51 | |
| 52 | - /** @var IUserManager */ |
|
| 53 | - protected $userManager; |
|
| 54 | - /** @var IContactsManager */ |
|
| 55 | - protected $contactsManager; |
|
| 52 | + /** @var IUserManager */ |
|
| 53 | + protected $userManager; |
|
| 54 | + /** @var IContactsManager */ |
|
| 55 | + protected $contactsManager; |
|
| 56 | 56 | |
| 57 | - /** @var array */ |
|
| 58 | - protected $contactNames = []; |
|
| 57 | + /** @var array */ |
|
| 58 | + protected $contactNames = []; |
|
| 59 | 59 | |
| 60 | - public const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self'; |
|
| 61 | - public const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by'; |
|
| 62 | - public const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send'; |
|
| 63 | - public const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self'; |
|
| 64 | - public const SUBJECT_UNSHARED_EMAIL_SELF = 'unshared_with_email_self'; |
|
| 65 | - public const SUBJECT_UNSHARED_EMAIL_BY = 'unshared_with_email_by'; |
|
| 60 | + public const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self'; |
|
| 61 | + public const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by'; |
|
| 62 | + public const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send'; |
|
| 63 | + public const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self'; |
|
| 64 | + public const SUBJECT_UNSHARED_EMAIL_SELF = 'unshared_with_email_self'; |
|
| 65 | + public const SUBJECT_UNSHARED_EMAIL_BY = 'unshared_with_email_by'; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @param IFactory $languageFactory |
|
| 69 | - * @param IURLGenerator $url |
|
| 70 | - * @param IManager $activityManager |
|
| 71 | - * @param IUserManager $userManager |
|
| 72 | - * @param IContactsManager $contactsManager |
|
| 73 | - */ |
|
| 74 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) { |
|
| 75 | - $this->languageFactory = $languageFactory; |
|
| 76 | - $this->url = $url; |
|
| 77 | - $this->activityManager = $activityManager; |
|
| 78 | - $this->userManager = $userManager; |
|
| 79 | - $this->contactsManager = $contactsManager; |
|
| 80 | - } |
|
| 67 | + /** |
|
| 68 | + * @param IFactory $languageFactory |
|
| 69 | + * @param IURLGenerator $url |
|
| 70 | + * @param IManager $activityManager |
|
| 71 | + * @param IUserManager $userManager |
|
| 72 | + * @param IContactsManager $contactsManager |
|
| 73 | + */ |
|
| 74 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) { |
|
| 75 | + $this->languageFactory = $languageFactory; |
|
| 76 | + $this->url = $url; |
|
| 77 | + $this->activityManager = $activityManager; |
|
| 78 | + $this->userManager = $userManager; |
|
| 79 | + $this->contactsManager = $contactsManager; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @param string $language |
|
| 84 | - * @param IEvent $event |
|
| 85 | - * @param IEvent|null $previousEvent |
|
| 86 | - * @return IEvent |
|
| 87 | - * @throws \InvalidArgumentException |
|
| 88 | - * @since 11.0.0 |
|
| 89 | - */ |
|
| 90 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 91 | - if ($event->getApp() !== 'sharebymail') { |
|
| 92 | - throw new \InvalidArgumentException(); |
|
| 93 | - } |
|
| 82 | + /** |
|
| 83 | + * @param string $language |
|
| 84 | + * @param IEvent $event |
|
| 85 | + * @param IEvent|null $previousEvent |
|
| 86 | + * @return IEvent |
|
| 87 | + * @throws \InvalidArgumentException |
|
| 88 | + * @since 11.0.0 |
|
| 89 | + */ |
|
| 90 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 91 | + if ($event->getApp() !== 'sharebymail') { |
|
| 92 | + throw new \InvalidArgumentException(); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - $this->l = $this->languageFactory->get('sharebymail', $language); |
|
| 95 | + $this->l = $this->languageFactory->get('sharebymail', $language); |
|
| 96 | 96 | |
| 97 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 98 | - try { |
|
| 99 | - return $this->parseShortVersion($event); |
|
| 100 | - } catch (\InvalidArgumentException $e) { |
|
| 101 | - // Ignore and simply use the long version... |
|
| 102 | - } |
|
| 103 | - } |
|
| 97 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 98 | + try { |
|
| 99 | + return $this->parseShortVersion($event); |
|
| 100 | + } catch (\InvalidArgumentException $e) { |
|
| 101 | + // Ignore and simply use the long version... |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return $this->parseLongVersion($event); |
|
| 106 | - } |
|
| 105 | + return $this->parseLongVersion($event); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @param IEvent $event |
|
| 110 | - * @return IEvent |
|
| 111 | - * @throws \InvalidArgumentException |
|
| 112 | - * @since 11.0.0 |
|
| 113 | - */ |
|
| 114 | - public function parseShortVersion(IEvent $event) { |
|
| 115 | - $parsedParameters = $this->getParsedParameters($event); |
|
| 108 | + /** |
|
| 109 | + * @param IEvent $event |
|
| 110 | + * @return IEvent |
|
| 111 | + * @throws \InvalidArgumentException |
|
| 112 | + * @since 11.0.0 |
|
| 113 | + */ |
|
| 114 | + public function parseShortVersion(IEvent $event) { |
|
| 115 | + $parsedParameters = $this->getParsedParameters($event); |
|
| 116 | 116 | |
| 117 | - if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
| 118 | - $event->setParsedSubject($this->l->t('Shared with %1$s', [ |
|
| 119 | - $parsedParameters['email']['name'], |
|
| 120 | - ])) |
|
| 121 | - ->setRichSubject($this->l->t('Shared with {email}'), [ |
|
| 122 | - 'email' => $parsedParameters['email'], |
|
| 123 | - ]); |
|
| 124 | - if ($this->activityManager->getRequirePNG()) { |
|
| 125 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 126 | - } else { |
|
| 127 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 128 | - } |
|
| 129 | - } elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
| 130 | - $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [ |
|
| 131 | - $parsedParameters['email']['name'], |
|
| 132 | - $parsedParameters['actor']['name'], |
|
| 133 | - ])) |
|
| 134 | - ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [ |
|
| 135 | - 'email' => $parsedParameters['email'], |
|
| 136 | - 'actor' => $parsedParameters['actor'], |
|
| 137 | - ]); |
|
| 138 | - if ($this->activityManager->getRequirePNG()) { |
|
| 139 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 140 | - } else { |
|
| 141 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 142 | - } |
|
| 143 | - } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) { |
|
| 144 | - $event->setParsedSubject($this->l->t('Unshared from %1$s', [ |
|
| 145 | - $parsedParameters['email']['name'], |
|
| 146 | - ])) |
|
| 147 | - ->setRichSubject($this->l->t('Unshared from {email}'), [ |
|
| 148 | - 'email' => $parsedParameters['email'], |
|
| 149 | - ]); |
|
| 150 | - if ($this->activityManager->getRequirePNG()) { |
|
| 151 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 152 | - } else { |
|
| 153 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 154 | - } |
|
| 155 | - } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) { |
|
| 156 | - $event->setParsedSubject($this->l->t('Unshared from %1$s by %2$s', [ |
|
| 157 | - $parsedParameters['email']['name'], |
|
| 158 | - $parsedParameters['actor']['name'], |
|
| 159 | - ])) |
|
| 160 | - ->setRichSubject($this->l->t('Unshared from {email} by {actor}'), [ |
|
| 161 | - 'email' => $parsedParameters['email'], |
|
| 162 | - 'actor' => $parsedParameters['actor'], |
|
| 163 | - ]); |
|
| 164 | - if ($this->activityManager->getRequirePNG()) { |
|
| 165 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 166 | - } else { |
|
| 167 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 168 | - } |
|
| 169 | - } elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
| 170 | - $event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [ |
|
| 171 | - $parsedParameters['email']['name'] |
|
| 172 | - ])) |
|
| 173 | - ->setRichSubject($this->l->t('Password for mail share sent to {email}'), [ |
|
| 174 | - 'email' => $parsedParameters['email'] |
|
| 175 | - ]); |
|
| 176 | - if ($this->activityManager->getRequirePNG()) { |
|
| 177 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 178 | - } else { |
|
| 179 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 180 | - } |
|
| 181 | - } elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
| 182 | - $event->setParsedSubject($this->l->t('Password for mail share sent to you')) |
|
| 183 | - ->setRichSubject($this->l->t('Password for mail share sent to you')); |
|
| 184 | - if ($this->activityManager->getRequirePNG()) { |
|
| 185 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 186 | - } else { |
|
| 187 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 188 | - } |
|
| 189 | - } else { |
|
| 190 | - throw new \InvalidArgumentException(); |
|
| 191 | - } |
|
| 117 | + if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
| 118 | + $event->setParsedSubject($this->l->t('Shared with %1$s', [ |
|
| 119 | + $parsedParameters['email']['name'], |
|
| 120 | + ])) |
|
| 121 | + ->setRichSubject($this->l->t('Shared with {email}'), [ |
|
| 122 | + 'email' => $parsedParameters['email'], |
|
| 123 | + ]); |
|
| 124 | + if ($this->activityManager->getRequirePNG()) { |
|
| 125 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 126 | + } else { |
|
| 127 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 128 | + } |
|
| 129 | + } elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
| 130 | + $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [ |
|
| 131 | + $parsedParameters['email']['name'], |
|
| 132 | + $parsedParameters['actor']['name'], |
|
| 133 | + ])) |
|
| 134 | + ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [ |
|
| 135 | + 'email' => $parsedParameters['email'], |
|
| 136 | + 'actor' => $parsedParameters['actor'], |
|
| 137 | + ]); |
|
| 138 | + if ($this->activityManager->getRequirePNG()) { |
|
| 139 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 140 | + } else { |
|
| 141 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 142 | + } |
|
| 143 | + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) { |
|
| 144 | + $event->setParsedSubject($this->l->t('Unshared from %1$s', [ |
|
| 145 | + $parsedParameters['email']['name'], |
|
| 146 | + ])) |
|
| 147 | + ->setRichSubject($this->l->t('Unshared from {email}'), [ |
|
| 148 | + 'email' => $parsedParameters['email'], |
|
| 149 | + ]); |
|
| 150 | + if ($this->activityManager->getRequirePNG()) { |
|
| 151 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 152 | + } else { |
|
| 153 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 154 | + } |
|
| 155 | + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) { |
|
| 156 | + $event->setParsedSubject($this->l->t('Unshared from %1$s by %2$s', [ |
|
| 157 | + $parsedParameters['email']['name'], |
|
| 158 | + $parsedParameters['actor']['name'], |
|
| 159 | + ])) |
|
| 160 | + ->setRichSubject($this->l->t('Unshared from {email} by {actor}'), [ |
|
| 161 | + 'email' => $parsedParameters['email'], |
|
| 162 | + 'actor' => $parsedParameters['actor'], |
|
| 163 | + ]); |
|
| 164 | + if ($this->activityManager->getRequirePNG()) { |
|
| 165 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 166 | + } else { |
|
| 167 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 168 | + } |
|
| 169 | + } elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
| 170 | + $event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [ |
|
| 171 | + $parsedParameters['email']['name'] |
|
| 172 | + ])) |
|
| 173 | + ->setRichSubject($this->l->t('Password for mail share sent to {email}'), [ |
|
| 174 | + 'email' => $parsedParameters['email'] |
|
| 175 | + ]); |
|
| 176 | + if ($this->activityManager->getRequirePNG()) { |
|
| 177 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 178 | + } else { |
|
| 179 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 180 | + } |
|
| 181 | + } elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
| 182 | + $event->setParsedSubject($this->l->t('Password for mail share sent to you')) |
|
| 183 | + ->setRichSubject($this->l->t('Password for mail share sent to you')); |
|
| 184 | + if ($this->activityManager->getRequirePNG()) { |
|
| 185 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 186 | + } else { |
|
| 187 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 188 | + } |
|
| 189 | + } else { |
|
| 190 | + throw new \InvalidArgumentException(); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - return $event; |
|
| 194 | - } |
|
| 193 | + return $event; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * @param IEvent $event |
|
| 198 | - * @return IEvent |
|
| 199 | - * @throws \InvalidArgumentException |
|
| 200 | - * @since 11.0.0 |
|
| 201 | - */ |
|
| 202 | - public function parseLongVersion(IEvent $event) { |
|
| 203 | - $parsedParameters = $this->getParsedParameters($event); |
|
| 196 | + /** |
|
| 197 | + * @param IEvent $event |
|
| 198 | + * @return IEvent |
|
| 199 | + * @throws \InvalidArgumentException |
|
| 200 | + * @since 11.0.0 |
|
| 201 | + */ |
|
| 202 | + public function parseLongVersion(IEvent $event) { |
|
| 203 | + $parsedParameters = $this->getParsedParameters($event); |
|
| 204 | 204 | |
| 205 | - if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
| 206 | - $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [ |
|
| 207 | - $parsedParameters['file']['path'], |
|
| 208 | - $parsedParameters['email']['name'], |
|
| 209 | - ])) |
|
| 210 | - ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters); |
|
| 211 | - if ($this->activityManager->getRequirePNG()) { |
|
| 212 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 213 | - } else { |
|
| 214 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 215 | - } |
|
| 216 | - } elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
| 217 | - $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [ |
|
| 218 | - $parsedParameters['file']['path'], |
|
| 219 | - $parsedParameters['email']['name'], |
|
| 220 | - $parsedParameters['actor']['name'], |
|
| 221 | - ])) |
|
| 222 | - ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters); |
|
| 223 | - if ($this->activityManager->getRequirePNG()) { |
|
| 224 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 225 | - } else { |
|
| 226 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 227 | - } |
|
| 228 | - } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) { |
|
| 229 | - $event->setParsedSubject($this->l->t('You unshared %1$s from %2$s by mail', [ |
|
| 230 | - $parsedParameters['file']['path'], |
|
| 231 | - $parsedParameters['email']['name'], |
|
| 232 | - ])) |
|
| 233 | - ->setRichSubject($this->l->t('You unshared {file} from {email} by mail'), $parsedParameters); |
|
| 234 | - if ($this->activityManager->getRequirePNG()) { |
|
| 235 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 236 | - } else { |
|
| 237 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 238 | - } |
|
| 239 | - } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) { |
|
| 240 | - $event->setParsedSubject($this->l->t('%3$s unshared %1$s from %2$s by mail', [ |
|
| 241 | - $parsedParameters['file']['path'], |
|
| 242 | - $parsedParameters['email']['name'], |
|
| 243 | - $parsedParameters['actor']['name'], |
|
| 244 | - ])) |
|
| 245 | - ->setRichSubject($this->l->t('{actor} unshared {file} from {email} by mail'), $parsedParameters); |
|
| 246 | - if ($this->activityManager->getRequirePNG()) { |
|
| 247 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 248 | - } else { |
|
| 249 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 250 | - } |
|
| 251 | - } elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
| 252 | - $event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [ |
|
| 253 | - $parsedParameters['file']['path'], |
|
| 254 | - $parsedParameters['email']['name'] |
|
| 255 | - ])) |
|
| 256 | - ->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters); |
|
| 257 | - if ($this->activityManager->getRequirePNG()) { |
|
| 258 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 259 | - } else { |
|
| 260 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 261 | - } |
|
| 262 | - } elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
| 263 | - $event->setParsedSubject( |
|
| 264 | - $this->l->t('Password to access %1$s was sent to you', |
|
| 265 | - [$parsedParameters['file']['path']])) |
|
| 266 | - ->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters); |
|
| 267 | - if ($this->activityManager->getRequirePNG()) { |
|
| 268 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 269 | - } else { |
|
| 270 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 271 | - } |
|
| 272 | - } else { |
|
| 273 | - throw new \InvalidArgumentException(); |
|
| 274 | - } |
|
| 205 | + if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
| 206 | + $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [ |
|
| 207 | + $parsedParameters['file']['path'], |
|
| 208 | + $parsedParameters['email']['name'], |
|
| 209 | + ])) |
|
| 210 | + ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters); |
|
| 211 | + if ($this->activityManager->getRequirePNG()) { |
|
| 212 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 213 | + } else { |
|
| 214 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 215 | + } |
|
| 216 | + } elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
| 217 | + $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [ |
|
| 218 | + $parsedParameters['file']['path'], |
|
| 219 | + $parsedParameters['email']['name'], |
|
| 220 | + $parsedParameters['actor']['name'], |
|
| 221 | + ])) |
|
| 222 | + ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters); |
|
| 223 | + if ($this->activityManager->getRequirePNG()) { |
|
| 224 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 225 | + } else { |
|
| 226 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 227 | + } |
|
| 228 | + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) { |
|
| 229 | + $event->setParsedSubject($this->l->t('You unshared %1$s from %2$s by mail', [ |
|
| 230 | + $parsedParameters['file']['path'], |
|
| 231 | + $parsedParameters['email']['name'], |
|
| 232 | + ])) |
|
| 233 | + ->setRichSubject($this->l->t('You unshared {file} from {email} by mail'), $parsedParameters); |
|
| 234 | + if ($this->activityManager->getRequirePNG()) { |
|
| 235 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 236 | + } else { |
|
| 237 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 238 | + } |
|
| 239 | + } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) { |
|
| 240 | + $event->setParsedSubject($this->l->t('%3$s unshared %1$s from %2$s by mail', [ |
|
| 241 | + $parsedParameters['file']['path'], |
|
| 242 | + $parsedParameters['email']['name'], |
|
| 243 | + $parsedParameters['actor']['name'], |
|
| 244 | + ])) |
|
| 245 | + ->setRichSubject($this->l->t('{actor} unshared {file} from {email} by mail'), $parsedParameters); |
|
| 246 | + if ($this->activityManager->getRequirePNG()) { |
|
| 247 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 248 | + } else { |
|
| 249 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 250 | + } |
|
| 251 | + } elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
| 252 | + $event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [ |
|
| 253 | + $parsedParameters['file']['path'], |
|
| 254 | + $parsedParameters['email']['name'] |
|
| 255 | + ])) |
|
| 256 | + ->setRichSubject($this->l->t('Password to access {file} was sent to {email}'), $parsedParameters); |
|
| 257 | + if ($this->activityManager->getRequirePNG()) { |
|
| 258 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 259 | + } else { |
|
| 260 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 261 | + } |
|
| 262 | + } elseif ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
| 263 | + $event->setParsedSubject( |
|
| 264 | + $this->l->t('Password to access %1$s was sent to you', |
|
| 265 | + [$parsedParameters['file']['path']])) |
|
| 266 | + ->setRichSubject($this->l->t('Password to access {file} was sent to you'), $parsedParameters); |
|
| 267 | + if ($this->activityManager->getRequirePNG()) { |
|
| 268 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
| 269 | + } else { |
|
| 270 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
| 271 | + } |
|
| 272 | + } else { |
|
| 273 | + throw new \InvalidArgumentException(); |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - return $event; |
|
| 277 | - } |
|
| 276 | + return $event; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - protected function getParsedParameters(IEvent $event) { |
|
| 280 | - $subject = $event->getSubject(); |
|
| 281 | - $parameters = $event->getSubjectParameters(); |
|
| 279 | + protected function getParsedParameters(IEvent $event) { |
|
| 280 | + $subject = $event->getSubject(); |
|
| 281 | + $parameters = $event->getSubjectParameters(); |
|
| 282 | 282 | |
| 283 | - switch ($subject) { |
|
| 284 | - case self::SUBJECT_SHARED_EMAIL_SELF: |
|
| 285 | - case self::SUBJECT_UNSHARED_EMAIL_SELF: |
|
| 286 | - return [ |
|
| 287 | - 'file' => $this->generateFileParameter($event->getObjectId(), $parameters[0]), |
|
| 288 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
| 289 | - ]; |
|
| 290 | - case self::SUBJECT_SHARED_EMAIL_BY: |
|
| 291 | - case self::SUBJECT_UNSHARED_EMAIL_BY: |
|
| 292 | - return [ |
|
| 293 | - 'file' => $this->generateFileParameter($event->getObjectId(), $parameters[0]), |
|
| 294 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
| 295 | - 'actor' => $this->generateUserParameter($parameters[2]), |
|
| 296 | - ]; |
|
| 297 | - case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND: |
|
| 298 | - return [ |
|
| 299 | - 'file' => $this->generateFileParameter($event->getObjectId(), $parameters[0]), |
|
| 300 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
| 301 | - ]; |
|
| 302 | - case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF: |
|
| 303 | - return [ |
|
| 304 | - 'file' => $this->generateFileParameter($event->getObjectId(), $parameters[0]), |
|
| 305 | - ]; |
|
| 306 | - } |
|
| 307 | - throw new \InvalidArgumentException(); |
|
| 308 | - } |
|
| 283 | + switch ($subject) { |
|
| 284 | + case self::SUBJECT_SHARED_EMAIL_SELF: |
|
| 285 | + case self::SUBJECT_UNSHARED_EMAIL_SELF: |
|
| 286 | + return [ |
|
| 287 | + 'file' => $this->generateFileParameter($event->getObjectId(), $parameters[0]), |
|
| 288 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
| 289 | + ]; |
|
| 290 | + case self::SUBJECT_SHARED_EMAIL_BY: |
|
| 291 | + case self::SUBJECT_UNSHARED_EMAIL_BY: |
|
| 292 | + return [ |
|
| 293 | + 'file' => $this->generateFileParameter($event->getObjectId(), $parameters[0]), |
|
| 294 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
| 295 | + 'actor' => $this->generateUserParameter($parameters[2]), |
|
| 296 | + ]; |
|
| 297 | + case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND: |
|
| 298 | + return [ |
|
| 299 | + 'file' => $this->generateFileParameter($event->getObjectId(), $parameters[0]), |
|
| 300 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
| 301 | + ]; |
|
| 302 | + case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF: |
|
| 303 | + return [ |
|
| 304 | + 'file' => $this->generateFileParameter($event->getObjectId(), $parameters[0]), |
|
| 305 | + ]; |
|
| 306 | + } |
|
| 307 | + throw new \InvalidArgumentException(); |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - /** |
|
| 311 | - * @param int $id |
|
| 312 | - * @param string $path |
|
| 313 | - * @return array |
|
| 314 | - */ |
|
| 315 | - protected function generateFileParameter($id, $path) { |
|
| 316 | - return [ |
|
| 317 | - 'type' => 'file', |
|
| 318 | - 'id' => $id, |
|
| 319 | - 'name' => basename($path), |
|
| 320 | - 'path' => trim($path, '/'), |
|
| 321 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 322 | - ]; |
|
| 323 | - } |
|
| 310 | + /** |
|
| 311 | + * @param int $id |
|
| 312 | + * @param string $path |
|
| 313 | + * @return array |
|
| 314 | + */ |
|
| 315 | + protected function generateFileParameter($id, $path) { |
|
| 316 | + return [ |
|
| 317 | + 'type' => 'file', |
|
| 318 | + 'id' => $id, |
|
| 319 | + 'name' => basename($path), |
|
| 320 | + 'path' => trim($path, '/'), |
|
| 321 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 322 | + ]; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - /** |
|
| 326 | - * @param string $email |
|
| 327 | - * @return array |
|
| 328 | - */ |
|
| 329 | - protected function generateEmailParameter($email) { |
|
| 330 | - if (!isset($this->contactNames[$email])) { |
|
| 331 | - $this->contactNames[$email] = $this->getContactName($email); |
|
| 332 | - } |
|
| 325 | + /** |
|
| 326 | + * @param string $email |
|
| 327 | + * @return array |
|
| 328 | + */ |
|
| 329 | + protected function generateEmailParameter($email) { |
|
| 330 | + if (!isset($this->contactNames[$email])) { |
|
| 331 | + $this->contactNames[$email] = $this->getContactName($email); |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - return [ |
|
| 335 | - 'type' => 'email', |
|
| 336 | - 'id' => $email, |
|
| 337 | - 'name' => $this->contactNames[$email], |
|
| 338 | - ]; |
|
| 339 | - } |
|
| 334 | + return [ |
|
| 335 | + 'type' => 'email', |
|
| 336 | + 'id' => $email, |
|
| 337 | + 'name' => $this->contactNames[$email], |
|
| 338 | + ]; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * @param string $uid |
|
| 343 | - * @return array |
|
| 344 | - */ |
|
| 345 | - protected function generateUserParameter($uid) { |
|
| 346 | - return [ |
|
| 347 | - 'type' => 'user', |
|
| 348 | - 'id' => $uid, |
|
| 349 | - 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 350 | - ]; |
|
| 351 | - } |
|
| 341 | + /** |
|
| 342 | + * @param string $uid |
|
| 343 | + * @return array |
|
| 344 | + */ |
|
| 345 | + protected function generateUserParameter($uid) { |
|
| 346 | + return [ |
|
| 347 | + 'type' => 'user', |
|
| 348 | + 'id' => $uid, |
|
| 349 | + 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 350 | + ]; |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | - /** |
|
| 354 | - * @param string $email |
|
| 355 | - * @return string |
|
| 356 | - */ |
|
| 357 | - protected function getContactName($email) { |
|
| 358 | - $addressBookContacts = $this->contactsManager->search($email, ['EMAIL'], [ |
|
| 359 | - 'limit' => 1, |
|
| 360 | - 'enumeration' => false, |
|
| 361 | - 'fullmatch' => false, |
|
| 362 | - 'strict_search' => true, |
|
| 363 | - ]); |
|
| 353 | + /** |
|
| 354 | + * @param string $email |
|
| 355 | + * @return string |
|
| 356 | + */ |
|
| 357 | + protected function getContactName($email) { |
|
| 358 | + $addressBookContacts = $this->contactsManager->search($email, ['EMAIL'], [ |
|
| 359 | + 'limit' => 1, |
|
| 360 | + 'enumeration' => false, |
|
| 361 | + 'fullmatch' => false, |
|
| 362 | + 'strict_search' => true, |
|
| 363 | + ]); |
|
| 364 | 364 | |
| 365 | - foreach ($addressBookContacts as $contact) { |
|
| 366 | - if (isset($contact['isLocalSystemBook'])) { |
|
| 367 | - continue; |
|
| 368 | - } |
|
| 365 | + foreach ($addressBookContacts as $contact) { |
|
| 366 | + if (isset($contact['isLocalSystemBook'])) { |
|
| 367 | + continue; |
|
| 368 | + } |
|
| 369 | 369 | |
| 370 | - if (in_array($email, $contact['EMAIL'])) { |
|
| 371 | - return $contact['FN']; |
|
| 372 | - } |
|
| 373 | - } |
|
| 370 | + if (in_array($email, $contact['EMAIL'])) { |
|
| 371 | + return $contact['FN']; |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - return $email; |
|
| 376 | - } |
|
| 375 | + return $email; |
|
| 376 | + } |
|
| 377 | 377 | } |
@@ -37,206 +37,206 @@ |
||
| 37 | 37 | |
| 38 | 38 | abstract class Base implements IProvider { |
| 39 | 39 | |
| 40 | - /** @var IFactory */ |
|
| 41 | - protected $languageFactory; |
|
| 42 | - |
|
| 43 | - /** @var IL10N */ |
|
| 44 | - protected $l; |
|
| 45 | - |
|
| 46 | - /** @var IURLGenerator */ |
|
| 47 | - protected $url; |
|
| 48 | - |
|
| 49 | - /** @var IManager */ |
|
| 50 | - protected $activityManager; |
|
| 51 | - |
|
| 52 | - /** @var IUserManager */ |
|
| 53 | - protected $userManager; |
|
| 54 | - |
|
| 55 | - /** @var IEventMerger */ |
|
| 56 | - protected $eventMerger; |
|
| 57 | - |
|
| 58 | - /** @var IContactsManager */ |
|
| 59 | - protected $contactsManager; |
|
| 60 | - |
|
| 61 | - /** @var ICloudIdManager */ |
|
| 62 | - protected $cloudIdManager; |
|
| 63 | - |
|
| 64 | - /** @var array */ |
|
| 65 | - protected $displayNames = []; |
|
| 66 | - |
|
| 67 | - public function __construct(IFactory $languageFactory, |
|
| 68 | - IURLGenerator $url, |
|
| 69 | - IManager $activityManager, |
|
| 70 | - IUserManager $userManager, |
|
| 71 | - ICloudIdManager $cloudIdManager, |
|
| 72 | - IContactsManager $contactsManager, |
|
| 73 | - IEventMerger $eventMerger) { |
|
| 74 | - $this->languageFactory = $languageFactory; |
|
| 75 | - $this->url = $url; |
|
| 76 | - $this->activityManager = $activityManager; |
|
| 77 | - $this->userManager = $userManager; |
|
| 78 | - $this->cloudIdManager = $cloudIdManager; |
|
| 79 | - $this->contactsManager = $contactsManager; |
|
| 80 | - $this->eventMerger = $eventMerger; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @param string $language |
|
| 85 | - * @param IEvent $event |
|
| 86 | - * @param IEvent|null $previousEvent |
|
| 87 | - * @return IEvent |
|
| 88 | - * @throws \InvalidArgumentException |
|
| 89 | - * @since 11.0.0 |
|
| 90 | - */ |
|
| 91 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 92 | - if ($event->getApp() !== 'files_sharing') { |
|
| 93 | - throw new \InvalidArgumentException(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $this->l = $this->languageFactory->get('files_sharing', $language); |
|
| 97 | - |
|
| 98 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 99 | - try { |
|
| 100 | - return $this->parseShortVersion($event); |
|
| 101 | - } catch (\InvalidArgumentException $e) { |
|
| 102 | - // Ignore and simply use the long version... |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $this->parseLongVersion($event, $previousEvent); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param IEvent $event |
|
| 111 | - * @return IEvent |
|
| 112 | - * @throws \InvalidArgumentException |
|
| 113 | - * @since 11.0.0 |
|
| 114 | - */ |
|
| 115 | - abstract protected function parseShortVersion(IEvent $event); |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @param IEvent $event |
|
| 119 | - * @param IEvent|null $previousEvent |
|
| 120 | - * @return IEvent |
|
| 121 | - * @throws \InvalidArgumentException |
|
| 122 | - * @since 11.0.0 |
|
| 123 | - */ |
|
| 124 | - abstract protected function parseLongVersion(IEvent $event, IEvent $previousEvent = null); |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @param IEvent $event |
|
| 128 | - * @param string $subject |
|
| 129 | - * @param array $parameters |
|
| 130 | - * @throws \InvalidArgumentException |
|
| 131 | - */ |
|
| 132 | - protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 133 | - $placeholders = $replacements = []; |
|
| 134 | - foreach ($parameters as $placeholder => $parameter) { |
|
| 135 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 136 | - if ($parameter['type'] === 'file') { |
|
| 137 | - $replacements[] = $parameter['path']; |
|
| 138 | - } else { |
|
| 139 | - $replacements[] = $parameter['name']; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 144 | - ->setRichSubject($subject, $parameters); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param array|string $parameter |
|
| 149 | - * @param IEvent|null $event |
|
| 150 | - * @return array |
|
| 151 | - * @throws \InvalidArgumentException |
|
| 152 | - */ |
|
| 153 | - protected function getFile($parameter, IEvent $event = null) { |
|
| 154 | - if (is_array($parameter)) { |
|
| 155 | - $path = reset($parameter); |
|
| 156 | - $id = (string) key($parameter); |
|
| 157 | - } elseif ($event !== null) { |
|
| 158 | - // Legacy from before ownCloud 8.2 |
|
| 159 | - $path = $parameter; |
|
| 160 | - $id = $event->getObjectId(); |
|
| 161 | - } else { |
|
| 162 | - throw new \InvalidArgumentException('Could not generate file parameter'); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return [ |
|
| 166 | - 'type' => 'file', |
|
| 167 | - 'id' => $id, |
|
| 168 | - 'name' => basename($path), |
|
| 169 | - 'path' => trim($path, '/'), |
|
| 170 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 171 | - ]; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @param string $uid |
|
| 176 | - * @return array |
|
| 177 | - */ |
|
| 178 | - protected function getUser($uid) { |
|
| 179 | - // First try local user |
|
| 180 | - $displayName = $this->userManager->getDisplayName($uid); |
|
| 181 | - if ($displayName !== null) { |
|
| 182 | - return [ |
|
| 183 | - 'type' => 'user', |
|
| 184 | - 'id' => $uid, |
|
| 185 | - 'name' => $displayName, |
|
| 186 | - ]; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // Then a contact from the addressbook |
|
| 190 | - if ($this->cloudIdManager->isValidCloudId($uid)) { |
|
| 191 | - $cloudId = $this->cloudIdManager->resolveCloudId($uid); |
|
| 192 | - return [ |
|
| 193 | - 'type' => 'user', |
|
| 194 | - 'id' => $cloudId->getUser(), |
|
| 195 | - 'name' => $this->getDisplayNameFromAddressBook($cloudId->getDisplayId()), |
|
| 196 | - 'server' => $cloudId->getRemote(), |
|
| 197 | - ]; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // Fallback to empty dummy data |
|
| 201 | - return [ |
|
| 202 | - 'type' => 'user', |
|
| 203 | - 'id' => $uid, |
|
| 204 | - 'name' => $uid, |
|
| 205 | - ]; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - protected function getDisplayNameFromAddressBook(string $search): string { |
|
| 209 | - if (isset($this->displayNames[$search])) { |
|
| 210 | - return $this->displayNames[$search]; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD'], [ |
|
| 214 | - 'limit' => 1, |
|
| 215 | - 'enumeration' => false, |
|
| 216 | - 'fullmatch' => false, |
|
| 217 | - 'strict_search' => true, |
|
| 218 | - ]); |
|
| 219 | - foreach ($addressBookContacts as $contact) { |
|
| 220 | - if (isset($contact['isLocalSystemBook'])) { |
|
| 221 | - continue; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - if (isset($contact['CLOUD'])) { |
|
| 225 | - $cloudIds = $contact['CLOUD']; |
|
| 226 | - if (is_string($cloudIds)) { |
|
| 227 | - $cloudIds = [$cloudIds]; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $lowerSearch = strtolower($search); |
|
| 231 | - foreach ($cloudIds as $cloudId) { |
|
| 232 | - if (strtolower($cloudId) === $lowerSearch) { |
|
| 233 | - $this->displayNames[$search] = $contact['FN'] . " ($cloudId)"; |
|
| 234 | - return $this->displayNames[$search]; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - return $search; |
|
| 241 | - } |
|
| 40 | + /** @var IFactory */ |
|
| 41 | + protected $languageFactory; |
|
| 42 | + |
|
| 43 | + /** @var IL10N */ |
|
| 44 | + protected $l; |
|
| 45 | + |
|
| 46 | + /** @var IURLGenerator */ |
|
| 47 | + protected $url; |
|
| 48 | + |
|
| 49 | + /** @var IManager */ |
|
| 50 | + protected $activityManager; |
|
| 51 | + |
|
| 52 | + /** @var IUserManager */ |
|
| 53 | + protected $userManager; |
|
| 54 | + |
|
| 55 | + /** @var IEventMerger */ |
|
| 56 | + protected $eventMerger; |
|
| 57 | + |
|
| 58 | + /** @var IContactsManager */ |
|
| 59 | + protected $contactsManager; |
|
| 60 | + |
|
| 61 | + /** @var ICloudIdManager */ |
|
| 62 | + protected $cloudIdManager; |
|
| 63 | + |
|
| 64 | + /** @var array */ |
|
| 65 | + protected $displayNames = []; |
|
| 66 | + |
|
| 67 | + public function __construct(IFactory $languageFactory, |
|
| 68 | + IURLGenerator $url, |
|
| 69 | + IManager $activityManager, |
|
| 70 | + IUserManager $userManager, |
|
| 71 | + ICloudIdManager $cloudIdManager, |
|
| 72 | + IContactsManager $contactsManager, |
|
| 73 | + IEventMerger $eventMerger) { |
|
| 74 | + $this->languageFactory = $languageFactory; |
|
| 75 | + $this->url = $url; |
|
| 76 | + $this->activityManager = $activityManager; |
|
| 77 | + $this->userManager = $userManager; |
|
| 78 | + $this->cloudIdManager = $cloudIdManager; |
|
| 79 | + $this->contactsManager = $contactsManager; |
|
| 80 | + $this->eventMerger = $eventMerger; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @param string $language |
|
| 85 | + * @param IEvent $event |
|
| 86 | + * @param IEvent|null $previousEvent |
|
| 87 | + * @return IEvent |
|
| 88 | + * @throws \InvalidArgumentException |
|
| 89 | + * @since 11.0.0 |
|
| 90 | + */ |
|
| 91 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 92 | + if ($event->getApp() !== 'files_sharing') { |
|
| 93 | + throw new \InvalidArgumentException(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $this->l = $this->languageFactory->get('files_sharing', $language); |
|
| 97 | + |
|
| 98 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 99 | + try { |
|
| 100 | + return $this->parseShortVersion($event); |
|
| 101 | + } catch (\InvalidArgumentException $e) { |
|
| 102 | + // Ignore and simply use the long version... |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $this->parseLongVersion($event, $previousEvent); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param IEvent $event |
|
| 111 | + * @return IEvent |
|
| 112 | + * @throws \InvalidArgumentException |
|
| 113 | + * @since 11.0.0 |
|
| 114 | + */ |
|
| 115 | + abstract protected function parseShortVersion(IEvent $event); |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @param IEvent $event |
|
| 119 | + * @param IEvent|null $previousEvent |
|
| 120 | + * @return IEvent |
|
| 121 | + * @throws \InvalidArgumentException |
|
| 122 | + * @since 11.0.0 |
|
| 123 | + */ |
|
| 124 | + abstract protected function parseLongVersion(IEvent $event, IEvent $previousEvent = null); |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @param IEvent $event |
|
| 128 | + * @param string $subject |
|
| 129 | + * @param array $parameters |
|
| 130 | + * @throws \InvalidArgumentException |
|
| 131 | + */ |
|
| 132 | + protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 133 | + $placeholders = $replacements = []; |
|
| 134 | + foreach ($parameters as $placeholder => $parameter) { |
|
| 135 | + $placeholders[] = '{' . $placeholder . '}'; |
|
| 136 | + if ($parameter['type'] === 'file') { |
|
| 137 | + $replacements[] = $parameter['path']; |
|
| 138 | + } else { |
|
| 139 | + $replacements[] = $parameter['name']; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 144 | + ->setRichSubject($subject, $parameters); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param array|string $parameter |
|
| 149 | + * @param IEvent|null $event |
|
| 150 | + * @return array |
|
| 151 | + * @throws \InvalidArgumentException |
|
| 152 | + */ |
|
| 153 | + protected function getFile($parameter, IEvent $event = null) { |
|
| 154 | + if (is_array($parameter)) { |
|
| 155 | + $path = reset($parameter); |
|
| 156 | + $id = (string) key($parameter); |
|
| 157 | + } elseif ($event !== null) { |
|
| 158 | + // Legacy from before ownCloud 8.2 |
|
| 159 | + $path = $parameter; |
|
| 160 | + $id = $event->getObjectId(); |
|
| 161 | + } else { |
|
| 162 | + throw new \InvalidArgumentException('Could not generate file parameter'); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return [ |
|
| 166 | + 'type' => 'file', |
|
| 167 | + 'id' => $id, |
|
| 168 | + 'name' => basename($path), |
|
| 169 | + 'path' => trim($path, '/'), |
|
| 170 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 171 | + ]; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @param string $uid |
|
| 176 | + * @return array |
|
| 177 | + */ |
|
| 178 | + protected function getUser($uid) { |
|
| 179 | + // First try local user |
|
| 180 | + $displayName = $this->userManager->getDisplayName($uid); |
|
| 181 | + if ($displayName !== null) { |
|
| 182 | + return [ |
|
| 183 | + 'type' => 'user', |
|
| 184 | + 'id' => $uid, |
|
| 185 | + 'name' => $displayName, |
|
| 186 | + ]; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // Then a contact from the addressbook |
|
| 190 | + if ($this->cloudIdManager->isValidCloudId($uid)) { |
|
| 191 | + $cloudId = $this->cloudIdManager->resolveCloudId($uid); |
|
| 192 | + return [ |
|
| 193 | + 'type' => 'user', |
|
| 194 | + 'id' => $cloudId->getUser(), |
|
| 195 | + 'name' => $this->getDisplayNameFromAddressBook($cloudId->getDisplayId()), |
|
| 196 | + 'server' => $cloudId->getRemote(), |
|
| 197 | + ]; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // Fallback to empty dummy data |
|
| 201 | + return [ |
|
| 202 | + 'type' => 'user', |
|
| 203 | + 'id' => $uid, |
|
| 204 | + 'name' => $uid, |
|
| 205 | + ]; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + protected function getDisplayNameFromAddressBook(string $search): string { |
|
| 209 | + if (isset($this->displayNames[$search])) { |
|
| 210 | + return $this->displayNames[$search]; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD'], [ |
|
| 214 | + 'limit' => 1, |
|
| 215 | + 'enumeration' => false, |
|
| 216 | + 'fullmatch' => false, |
|
| 217 | + 'strict_search' => true, |
|
| 218 | + ]); |
|
| 219 | + foreach ($addressBookContacts as $contact) { |
|
| 220 | + if (isset($contact['isLocalSystemBook'])) { |
|
| 221 | + continue; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + if (isset($contact['CLOUD'])) { |
|
| 225 | + $cloudIds = $contact['CLOUD']; |
|
| 226 | + if (is_string($cloudIds)) { |
|
| 227 | + $cloudIds = [$cloudIds]; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $lowerSearch = strtolower($search); |
|
| 231 | + foreach ($cloudIds as $cloudId) { |
|
| 232 | + if (strtolower($cloudId) === $lowerSearch) { |
|
| 233 | + $this->displayNames[$search] = $contact['FN'] . " ($cloudId)"; |
|
| 234 | + return $this->displayNames[$search]; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + return $search; |
|
| 241 | + } |
|
| 242 | 242 | } |
@@ -33,319 +33,319 @@ |
||
| 33 | 33 | use OCP\L10N\IFactory; |
| 34 | 34 | |
| 35 | 35 | class Provider implements IProvider { |
| 36 | - public const CREATE_TAG = 'create_tag'; |
|
| 37 | - public const UPDATE_TAG = 'update_tag'; |
|
| 38 | - public const DELETE_TAG = 'delete_tag'; |
|
| 36 | + public const CREATE_TAG = 'create_tag'; |
|
| 37 | + public const UPDATE_TAG = 'update_tag'; |
|
| 38 | + public const DELETE_TAG = 'delete_tag'; |
|
| 39 | 39 | |
| 40 | - public const ASSIGN_TAG = 'assign_tag'; |
|
| 41 | - public const UNASSIGN_TAG = 'unassign_tag'; |
|
| 40 | + public const ASSIGN_TAG = 'assign_tag'; |
|
| 41 | + public const UNASSIGN_TAG = 'unassign_tag'; |
|
| 42 | 42 | |
| 43 | - /** @var IFactory */ |
|
| 44 | - protected $languageFactory; |
|
| 43 | + /** @var IFactory */ |
|
| 44 | + protected $languageFactory; |
|
| 45 | 45 | |
| 46 | - /** @var IL10N */ |
|
| 47 | - protected $l; |
|
| 46 | + /** @var IL10N */ |
|
| 47 | + protected $l; |
|
| 48 | 48 | |
| 49 | - /** @var IURLGenerator */ |
|
| 50 | - protected $url; |
|
| 49 | + /** @var IURLGenerator */ |
|
| 50 | + protected $url; |
|
| 51 | 51 | |
| 52 | - /** @var IManager */ |
|
| 53 | - protected $activityManager; |
|
| 52 | + /** @var IManager */ |
|
| 53 | + protected $activityManager; |
|
| 54 | 54 | |
| 55 | - /** @var IUserManager */ |
|
| 56 | - protected $userManager; |
|
| 55 | + /** @var IUserManager */ |
|
| 56 | + protected $userManager; |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @param IFactory $languageFactory |
|
| 60 | - * @param IURLGenerator $url |
|
| 61 | - * @param IManager $activityManager |
|
| 62 | - * @param IUserManager $userManager |
|
| 63 | - */ |
|
| 64 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) { |
|
| 65 | - $this->languageFactory = $languageFactory; |
|
| 66 | - $this->url = $url; |
|
| 67 | - $this->activityManager = $activityManager; |
|
| 68 | - $this->userManager = $userManager; |
|
| 69 | - } |
|
| 58 | + /** |
|
| 59 | + * @param IFactory $languageFactory |
|
| 60 | + * @param IURLGenerator $url |
|
| 61 | + * @param IManager $activityManager |
|
| 62 | + * @param IUserManager $userManager |
|
| 63 | + */ |
|
| 64 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) { |
|
| 65 | + $this->languageFactory = $languageFactory; |
|
| 66 | + $this->url = $url; |
|
| 67 | + $this->activityManager = $activityManager; |
|
| 68 | + $this->userManager = $userManager; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param string $language |
|
| 73 | - * @param IEvent $event |
|
| 74 | - * @param IEvent|null $previousEvent |
|
| 75 | - * @return IEvent |
|
| 76 | - * @throws \InvalidArgumentException |
|
| 77 | - * @since 11.0.0 |
|
| 78 | - */ |
|
| 79 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 80 | - if ($event->getApp() !== 'systemtags') { |
|
| 81 | - throw new \InvalidArgumentException(); |
|
| 82 | - } |
|
| 71 | + /** |
|
| 72 | + * @param string $language |
|
| 73 | + * @param IEvent $event |
|
| 74 | + * @param IEvent|null $previousEvent |
|
| 75 | + * @return IEvent |
|
| 76 | + * @throws \InvalidArgumentException |
|
| 77 | + * @since 11.0.0 |
|
| 78 | + */ |
|
| 79 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 80 | + if ($event->getApp() !== 'systemtags') { |
|
| 81 | + throw new \InvalidArgumentException(); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - $this->l = $this->languageFactory->get('systemtags', $language); |
|
| 84 | + $this->l = $this->languageFactory->get('systemtags', $language); |
|
| 85 | 85 | |
| 86 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 87 | - try { |
|
| 88 | - return $this->parseShortVersion($event); |
|
| 89 | - } catch (\InvalidArgumentException $e) { |
|
| 90 | - // Ignore and simply use the long version... |
|
| 91 | - } |
|
| 92 | - } |
|
| 86 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 87 | + try { |
|
| 88 | + return $this->parseShortVersion($event); |
|
| 89 | + } catch (\InvalidArgumentException $e) { |
|
| 90 | + // Ignore and simply use the long version... |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return $this->parseLongVersion($event); |
|
| 95 | - } |
|
| 94 | + return $this->parseLongVersion($event); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @param IEvent $event |
|
| 99 | - * @return IEvent |
|
| 100 | - * @throws \InvalidArgumentException |
|
| 101 | - * @since 11.0.0 |
|
| 102 | - */ |
|
| 103 | - public function parseShortVersion(IEvent $event) { |
|
| 104 | - $parsedParameters = $this->getParameters($event); |
|
| 97 | + /** |
|
| 98 | + * @param IEvent $event |
|
| 99 | + * @return IEvent |
|
| 100 | + * @throws \InvalidArgumentException |
|
| 101 | + * @since 11.0.0 |
|
| 102 | + */ |
|
| 103 | + public function parseShortVersion(IEvent $event) { |
|
| 104 | + $parsedParameters = $this->getParameters($event); |
|
| 105 | 105 | |
| 106 | - if ($this->activityManager->getRequirePNG()) { |
|
| 107 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
| 108 | - } else { |
|
| 109 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
| 110 | - } |
|
| 106 | + if ($this->activityManager->getRequirePNG()) { |
|
| 107 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
| 108 | + } else { |
|
| 109 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - if ($event->getSubject() === self::ASSIGN_TAG) { |
|
| 113 | - if ($parsedParameters['actor']['id'] === '') { |
|
| 114 | - $event->setParsedSubject($this->l->t('System tag %1$s added by the system', [ |
|
| 115 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 116 | - ])) |
|
| 117 | - ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
| 118 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 119 | - ]); |
|
| 120 | - } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 121 | - $event->setParsedSubject($this->l->t('Added system tag %1$s', [ |
|
| 122 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 123 | - ])) |
|
| 124 | - ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
| 125 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 126 | - ]); |
|
| 127 | - } else { |
|
| 128 | - $event->setParsedSubject($this->l->t('%1$s added system tag %2$s', [ |
|
| 129 | - $parsedParameters['actor']['name'], |
|
| 130 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 131 | - ])) |
|
| 132 | - ->setRichSubject($this->l->t('{actor} added system tag {systemtag}'), [ |
|
| 133 | - 'actor' => $parsedParameters['actor'], |
|
| 134 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 135 | - ]); |
|
| 136 | - } |
|
| 137 | - } elseif ($event->getSubject() === self::UNASSIGN_TAG) { |
|
| 138 | - if ($parsedParameters['actor']['id'] === '') { |
|
| 139 | - $event->setParsedSubject($this->l->t('System tag %1$s removed by the system', [ |
|
| 140 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 141 | - ])) |
|
| 142 | - ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
| 143 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 144 | - ]); |
|
| 145 | - } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 146 | - $event->setParsedSubject($this->l->t('Removed system tag %1$s', [ |
|
| 147 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 148 | - ])) |
|
| 149 | - ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
| 150 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 151 | - ]); |
|
| 152 | - } else { |
|
| 153 | - $event->setParsedSubject($this->l->t('%1$s removed system tag %2$s', [ |
|
| 154 | - $parsedParameters['actor']['name'], |
|
| 155 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 156 | - ])) |
|
| 157 | - ->setRichSubject($this->l->t('{actor} removed system tag {systemtag}'), [ |
|
| 158 | - 'actor' => $parsedParameters['actor'], |
|
| 159 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 160 | - ]); |
|
| 161 | - } |
|
| 162 | - } else { |
|
| 163 | - throw new \InvalidArgumentException(); |
|
| 164 | - } |
|
| 112 | + if ($event->getSubject() === self::ASSIGN_TAG) { |
|
| 113 | + if ($parsedParameters['actor']['id'] === '') { |
|
| 114 | + $event->setParsedSubject($this->l->t('System tag %1$s added by the system', [ |
|
| 115 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 116 | + ])) |
|
| 117 | + ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
| 118 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 119 | + ]); |
|
| 120 | + } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 121 | + $event->setParsedSubject($this->l->t('Added system tag %1$s', [ |
|
| 122 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 123 | + ])) |
|
| 124 | + ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
| 125 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 126 | + ]); |
|
| 127 | + } else { |
|
| 128 | + $event->setParsedSubject($this->l->t('%1$s added system tag %2$s', [ |
|
| 129 | + $parsedParameters['actor']['name'], |
|
| 130 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 131 | + ])) |
|
| 132 | + ->setRichSubject($this->l->t('{actor} added system tag {systemtag}'), [ |
|
| 133 | + 'actor' => $parsedParameters['actor'], |
|
| 134 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 135 | + ]); |
|
| 136 | + } |
|
| 137 | + } elseif ($event->getSubject() === self::UNASSIGN_TAG) { |
|
| 138 | + if ($parsedParameters['actor']['id'] === '') { |
|
| 139 | + $event->setParsedSubject($this->l->t('System tag %1$s removed by the system', [ |
|
| 140 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 141 | + ])) |
|
| 142 | + ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
| 143 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 144 | + ]); |
|
| 145 | + } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 146 | + $event->setParsedSubject($this->l->t('Removed system tag %1$s', [ |
|
| 147 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 148 | + ])) |
|
| 149 | + ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
| 150 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 151 | + ]); |
|
| 152 | + } else { |
|
| 153 | + $event->setParsedSubject($this->l->t('%1$s removed system tag %2$s', [ |
|
| 154 | + $parsedParameters['actor']['name'], |
|
| 155 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 156 | + ])) |
|
| 157 | + ->setRichSubject($this->l->t('{actor} removed system tag {systemtag}'), [ |
|
| 158 | + 'actor' => $parsedParameters['actor'], |
|
| 159 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 160 | + ]); |
|
| 161 | + } |
|
| 162 | + } else { |
|
| 163 | + throw new \InvalidArgumentException(); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - return $event; |
|
| 167 | - } |
|
| 166 | + return $event; |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * @param IEvent $event |
|
| 171 | - * @return IEvent |
|
| 172 | - * @throws \InvalidArgumentException |
|
| 173 | - * @since 11.0.0 |
|
| 174 | - */ |
|
| 175 | - public function parseLongVersion(IEvent $event) { |
|
| 176 | - $parsedParameters = $this->getParameters($event); |
|
| 169 | + /** |
|
| 170 | + * @param IEvent $event |
|
| 171 | + * @return IEvent |
|
| 172 | + * @throws \InvalidArgumentException |
|
| 173 | + * @since 11.0.0 |
|
| 174 | + */ |
|
| 175 | + public function parseLongVersion(IEvent $event) { |
|
| 176 | + $parsedParameters = $this->getParameters($event); |
|
| 177 | 177 | |
| 178 | - if ($this->activityManager->getRequirePNG()) { |
|
| 179 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
| 180 | - } else { |
|
| 181 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
| 182 | - } |
|
| 178 | + if ($this->activityManager->getRequirePNG()) { |
|
| 179 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
| 180 | + } else { |
|
| 181 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - if ($event->getSubject() === self::CREATE_TAG) { |
|
| 185 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 186 | - $event->setParsedSubject($this->l->t('You created system tag %1$s', [ |
|
| 187 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 188 | - ])) |
|
| 189 | - ->setRichSubject($this->l->t('You created system tag {systemtag}'), $parsedParameters); |
|
| 190 | - } else { |
|
| 191 | - $event->setParsedSubject($this->l->t('%1$s created system tag %2$s', [ |
|
| 192 | - $parsedParameters['actor']['name'], |
|
| 193 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 194 | - ])) |
|
| 195 | - ->setRichSubject($this->l->t('{actor} created system tag {systemtag}'), $parsedParameters); |
|
| 196 | - } |
|
| 197 | - } elseif ($event->getSubject() === self::DELETE_TAG) { |
|
| 198 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 199 | - $event->setParsedSubject($this->l->t('You deleted system tag %1$s', [ |
|
| 200 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 201 | - ])) |
|
| 202 | - ->setRichSubject($this->l->t('You deleted system tag {systemtag}'), $parsedParameters); |
|
| 203 | - } else { |
|
| 204 | - $event->setParsedSubject($this->l->t('%1$s deleted system tag %2$s', [ |
|
| 205 | - $parsedParameters['actor']['name'], |
|
| 206 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 207 | - ])) |
|
| 208 | - ->setRichSubject($this->l->t('{actor} deleted system tag {systemtag}'), $parsedParameters); |
|
| 209 | - } |
|
| 210 | - } elseif ($event->getSubject() === self::UPDATE_TAG) { |
|
| 211 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 212 | - $event->setParsedSubject($this->l->t('You updated system tag %2$s to %1$s', [ |
|
| 213 | - $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
| 214 | - $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
| 215 | - ])) |
|
| 216 | - ->setRichSubject($this->l->t('You updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
| 217 | - } else { |
|
| 218 | - $event->setParsedSubject($this->l->t('%1$s updated system tag %3$s to %2$s', [ |
|
| 219 | - $parsedParameters['actor']['name'], |
|
| 220 | - $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
| 221 | - $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
| 222 | - ])) |
|
| 223 | - ->setRichSubject($this->l->t('{actor} updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
| 224 | - } |
|
| 225 | - } elseif ($event->getSubject() === self::ASSIGN_TAG) { |
|
| 226 | - if ($parsedParameters['actor']['id'] === '') { |
|
| 227 | - unset($parsedParameters['actor']); |
|
| 228 | - $event->setParsedSubject($this->l->t('System tag %2$s was added to %1$s by the system', [ |
|
| 229 | - $parsedParameters['file']['path'], |
|
| 230 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 231 | - ])) |
|
| 232 | - ->setRichSubject($this->l->t('System tag {systemtag} was added to {file} by the system'), $parsedParameters); |
|
| 233 | - } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 234 | - $event->setParsedSubject($this->l->t('You added system tag %2$s to %1$s', [ |
|
| 235 | - $parsedParameters['file']['path'], |
|
| 236 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 237 | - ])) |
|
| 238 | - ->setRichSubject($this->l->t('You added system tag {systemtag} to {file}'), $parsedParameters); |
|
| 239 | - } else { |
|
| 240 | - $event->setParsedSubject($this->l->t('%1$s added system tag %3$s to %2$s', [ |
|
| 241 | - $parsedParameters['actor']['name'], |
|
| 242 | - $parsedParameters['file']['path'], |
|
| 243 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 244 | - ])) |
|
| 245 | - ->setRichSubject($this->l->t('{actor} added system tag {systemtag} to {file}'), $parsedParameters); |
|
| 246 | - } |
|
| 247 | - } elseif ($event->getSubject() === self::UNASSIGN_TAG) { |
|
| 248 | - if ($parsedParameters['actor']['id'] === '') { |
|
| 249 | - unset($parsedParameters['actor']); |
|
| 250 | - $event->setParsedSubject($this->l->t('System tag %2$s was removed from %1$s by the system', [ |
|
| 251 | - $parsedParameters['file']['path'], |
|
| 252 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 253 | - ])) |
|
| 254 | - ->setRichSubject($this->l->t('System tag {systemtag} was removed from {file} by the system'), $parsedParameters); |
|
| 255 | - } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 256 | - $event->setParsedSubject($this->l->t('You removed system tag %2$s from %1$s', [ |
|
| 257 | - $parsedParameters['file']['path'], |
|
| 258 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 259 | - ])) |
|
| 260 | - ->setRichSubject($this->l->t('You removed system tag {systemtag} from {file}'), $parsedParameters); |
|
| 261 | - } else { |
|
| 262 | - $event->setParsedSubject($this->l->t('%1$s removed system tag %3$s from %2$s', [ |
|
| 263 | - $parsedParameters['actor']['name'], |
|
| 264 | - $parsedParameters['file']['path'], |
|
| 265 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 266 | - ])) |
|
| 267 | - ->setRichSubject($this->l->t('{actor} removed system tag {systemtag} from {file}'), $parsedParameters); |
|
| 268 | - } |
|
| 269 | - } else { |
|
| 270 | - throw new \InvalidArgumentException(); |
|
| 271 | - } |
|
| 184 | + if ($event->getSubject() === self::CREATE_TAG) { |
|
| 185 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 186 | + $event->setParsedSubject($this->l->t('You created system tag %1$s', [ |
|
| 187 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 188 | + ])) |
|
| 189 | + ->setRichSubject($this->l->t('You created system tag {systemtag}'), $parsedParameters); |
|
| 190 | + } else { |
|
| 191 | + $event->setParsedSubject($this->l->t('%1$s created system tag %2$s', [ |
|
| 192 | + $parsedParameters['actor']['name'], |
|
| 193 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 194 | + ])) |
|
| 195 | + ->setRichSubject($this->l->t('{actor} created system tag {systemtag}'), $parsedParameters); |
|
| 196 | + } |
|
| 197 | + } elseif ($event->getSubject() === self::DELETE_TAG) { |
|
| 198 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 199 | + $event->setParsedSubject($this->l->t('You deleted system tag %1$s', [ |
|
| 200 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 201 | + ])) |
|
| 202 | + ->setRichSubject($this->l->t('You deleted system tag {systemtag}'), $parsedParameters); |
|
| 203 | + } else { |
|
| 204 | + $event->setParsedSubject($this->l->t('%1$s deleted system tag %2$s', [ |
|
| 205 | + $parsedParameters['actor']['name'], |
|
| 206 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 207 | + ])) |
|
| 208 | + ->setRichSubject($this->l->t('{actor} deleted system tag {systemtag}'), $parsedParameters); |
|
| 209 | + } |
|
| 210 | + } elseif ($event->getSubject() === self::UPDATE_TAG) { |
|
| 211 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 212 | + $event->setParsedSubject($this->l->t('You updated system tag %2$s to %1$s', [ |
|
| 213 | + $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
| 214 | + $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
| 215 | + ])) |
|
| 216 | + ->setRichSubject($this->l->t('You updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
| 217 | + } else { |
|
| 218 | + $event->setParsedSubject($this->l->t('%1$s updated system tag %3$s to %2$s', [ |
|
| 219 | + $parsedParameters['actor']['name'], |
|
| 220 | + $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
| 221 | + $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
| 222 | + ])) |
|
| 223 | + ->setRichSubject($this->l->t('{actor} updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
| 224 | + } |
|
| 225 | + } elseif ($event->getSubject() === self::ASSIGN_TAG) { |
|
| 226 | + if ($parsedParameters['actor']['id'] === '') { |
|
| 227 | + unset($parsedParameters['actor']); |
|
| 228 | + $event->setParsedSubject($this->l->t('System tag %2$s was added to %1$s by the system', [ |
|
| 229 | + $parsedParameters['file']['path'], |
|
| 230 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 231 | + ])) |
|
| 232 | + ->setRichSubject($this->l->t('System tag {systemtag} was added to {file} by the system'), $parsedParameters); |
|
| 233 | + } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 234 | + $event->setParsedSubject($this->l->t('You added system tag %2$s to %1$s', [ |
|
| 235 | + $parsedParameters['file']['path'], |
|
| 236 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 237 | + ])) |
|
| 238 | + ->setRichSubject($this->l->t('You added system tag {systemtag} to {file}'), $parsedParameters); |
|
| 239 | + } else { |
|
| 240 | + $event->setParsedSubject($this->l->t('%1$s added system tag %3$s to %2$s', [ |
|
| 241 | + $parsedParameters['actor']['name'], |
|
| 242 | + $parsedParameters['file']['path'], |
|
| 243 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 244 | + ])) |
|
| 245 | + ->setRichSubject($this->l->t('{actor} added system tag {systemtag} to {file}'), $parsedParameters); |
|
| 246 | + } |
|
| 247 | + } elseif ($event->getSubject() === self::UNASSIGN_TAG) { |
|
| 248 | + if ($parsedParameters['actor']['id'] === '') { |
|
| 249 | + unset($parsedParameters['actor']); |
|
| 250 | + $event->setParsedSubject($this->l->t('System tag %2$s was removed from %1$s by the system', [ |
|
| 251 | + $parsedParameters['file']['path'], |
|
| 252 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 253 | + ])) |
|
| 254 | + ->setRichSubject($this->l->t('System tag {systemtag} was removed from {file} by the system'), $parsedParameters); |
|
| 255 | + } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 256 | + $event->setParsedSubject($this->l->t('You removed system tag %2$s from %1$s', [ |
|
| 257 | + $parsedParameters['file']['path'], |
|
| 258 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 259 | + ])) |
|
| 260 | + ->setRichSubject($this->l->t('You removed system tag {systemtag} from {file}'), $parsedParameters); |
|
| 261 | + } else { |
|
| 262 | + $event->setParsedSubject($this->l->t('%1$s removed system tag %3$s from %2$s', [ |
|
| 263 | + $parsedParameters['actor']['name'], |
|
| 264 | + $parsedParameters['file']['path'], |
|
| 265 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 266 | + ])) |
|
| 267 | + ->setRichSubject($this->l->t('{actor} removed system tag {systemtag} from {file}'), $parsedParameters); |
|
| 268 | + } |
|
| 269 | + } else { |
|
| 270 | + throw new \InvalidArgumentException(); |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - return $event; |
|
| 274 | - } |
|
| 273 | + return $event; |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - protected function getParameters(IEvent $event) { |
|
| 277 | - $subject = $event->getSubject(); |
|
| 278 | - $parameters = $event->getSubjectParameters(); |
|
| 276 | + protected function getParameters(IEvent $event) { |
|
| 277 | + $subject = $event->getSubject(); |
|
| 278 | + $parameters = $event->getSubjectParameters(); |
|
| 279 | 279 | |
| 280 | - switch ($subject) { |
|
| 281 | - case self::CREATE_TAG: |
|
| 282 | - case self::DELETE_TAG: |
|
| 283 | - return [ |
|
| 284 | - 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 285 | - 'systemtag' => $this->getSystemTagParameter($parameters[1]), |
|
| 286 | - ]; |
|
| 287 | - case self::UPDATE_TAG: |
|
| 288 | - return [ |
|
| 289 | - 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 290 | - 'newsystemtag' => $this->getSystemTagParameter($parameters[1]), |
|
| 291 | - 'oldsystemtag' => $this->getSystemTagParameter($parameters[2]), |
|
| 292 | - ]; |
|
| 293 | - case self::ASSIGN_TAG: |
|
| 294 | - case self::UNASSIGN_TAG: |
|
| 295 | - return [ |
|
| 296 | - 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 297 | - 'file' => $this->getFileParameter($event->getObjectId(), $parameters[1]), |
|
| 298 | - 'systemtag' => $this->getSystemTagParameter($parameters[2]), |
|
| 299 | - ]; |
|
| 300 | - } |
|
| 301 | - return []; |
|
| 302 | - } |
|
| 280 | + switch ($subject) { |
|
| 281 | + case self::CREATE_TAG: |
|
| 282 | + case self::DELETE_TAG: |
|
| 283 | + return [ |
|
| 284 | + 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 285 | + 'systemtag' => $this->getSystemTagParameter($parameters[1]), |
|
| 286 | + ]; |
|
| 287 | + case self::UPDATE_TAG: |
|
| 288 | + return [ |
|
| 289 | + 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 290 | + 'newsystemtag' => $this->getSystemTagParameter($parameters[1]), |
|
| 291 | + 'oldsystemtag' => $this->getSystemTagParameter($parameters[2]), |
|
| 292 | + ]; |
|
| 293 | + case self::ASSIGN_TAG: |
|
| 294 | + case self::UNASSIGN_TAG: |
|
| 295 | + return [ |
|
| 296 | + 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 297 | + 'file' => $this->getFileParameter($event->getObjectId(), $parameters[1]), |
|
| 298 | + 'systemtag' => $this->getSystemTagParameter($parameters[2]), |
|
| 299 | + ]; |
|
| 300 | + } |
|
| 301 | + return []; |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - protected function getFileParameter($id, $path) { |
|
| 305 | - return [ |
|
| 306 | - 'type' => 'file', |
|
| 307 | - 'id' => $id, |
|
| 308 | - 'name' => basename($path), |
|
| 309 | - 'path' => trim($path, '/'), |
|
| 310 | - ]; |
|
| 311 | - } |
|
| 304 | + protected function getFileParameter($id, $path) { |
|
| 305 | + return [ |
|
| 306 | + 'type' => 'file', |
|
| 307 | + 'id' => $id, |
|
| 308 | + 'name' => basename($path), |
|
| 309 | + 'path' => trim($path, '/'), |
|
| 310 | + ]; |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - protected function getSystemTagParameter($parameter) { |
|
| 314 | - $tagData = json_decode($parameter, true); |
|
| 315 | - if ($tagData === null) { |
|
| 316 | - [$name, $status] = explode('|||', substr($parameter, 3, -3)); |
|
| 317 | - $tagData = [ |
|
| 318 | - 'id' => 0,// No way to recover the ID |
|
| 319 | - 'name' => $name, |
|
| 320 | - 'assignable' => $status === 'assignable', |
|
| 321 | - 'visible' => $status !== 'invisible', |
|
| 322 | - ]; |
|
| 323 | - } |
|
| 313 | + protected function getSystemTagParameter($parameter) { |
|
| 314 | + $tagData = json_decode($parameter, true); |
|
| 315 | + if ($tagData === null) { |
|
| 316 | + [$name, $status] = explode('|||', substr($parameter, 3, -3)); |
|
| 317 | + $tagData = [ |
|
| 318 | + 'id' => 0,// No way to recover the ID |
|
| 319 | + 'name' => $name, |
|
| 320 | + 'assignable' => $status === 'assignable', |
|
| 321 | + 'visible' => $status !== 'invisible', |
|
| 322 | + ]; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - return [ |
|
| 326 | - 'type' => 'systemtag', |
|
| 327 | - 'id' => (int) $tagData['id'], |
|
| 328 | - 'name' => $tagData['name'], |
|
| 329 | - 'assignable' => $tagData['assignable'] ? '1' : '0', |
|
| 330 | - 'visibility' => $tagData['visible'] ? '1' : '0', |
|
| 331 | - ]; |
|
| 332 | - } |
|
| 325 | + return [ |
|
| 326 | + 'type' => 'systemtag', |
|
| 327 | + 'id' => (int) $tagData['id'], |
|
| 328 | + 'name' => $tagData['name'], |
|
| 329 | + 'assignable' => $tagData['assignable'] ? '1' : '0', |
|
| 330 | + 'visibility' => $tagData['visible'] ? '1' : '0', |
|
| 331 | + ]; |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - protected function getUserParameter(string $uid): array { |
|
| 335 | - return [ |
|
| 336 | - 'type' => 'user', |
|
| 337 | - 'id' => $uid, |
|
| 338 | - 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 339 | - ]; |
|
| 340 | - } |
|
| 334 | + protected function getUserParameter(string $uid): array { |
|
| 335 | + return [ |
|
| 336 | + 'type' => 'user', |
|
| 337 | + 'id' => $uid, |
|
| 338 | + 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 339 | + ]; |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - protected function generatePlainSystemTag(array $parameter) { |
|
| 343 | - if ($parameter['assignable'] === '1') { |
|
| 344 | - return $parameter['name']; |
|
| 345 | - } elseif ($parameter['visibility'] === '1') { |
|
| 346 | - return $this->l->t('%s (restricted)', $parameter['name']); |
|
| 347 | - } else { |
|
| 348 | - return $this->l->t('%s (invisible)', $parameter['name']); |
|
| 349 | - } |
|
| 350 | - } |
|
| 342 | + protected function generatePlainSystemTag(array $parameter) { |
|
| 343 | + if ($parameter['assignable'] === '1') { |
|
| 344 | + return $parameter['name']; |
|
| 345 | + } elseif ($parameter['visibility'] === '1') { |
|
| 346 | + return $this->l->t('%s (restricted)', $parameter['name']); |
|
| 347 | + } else { |
|
| 348 | + return $this->l->t('%s (invisible)', $parameter['name']); |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | 351 | } |
@@ -37,100 +37,100 @@ |
||
| 37 | 37 | |
| 38 | 38 | abstract class Base implements IProvider { |
| 39 | 39 | |
| 40 | - /** @var IUserManager */ |
|
| 41 | - protected $userManager; |
|
| 42 | - |
|
| 43 | - /** @var string[] */ |
|
| 44 | - protected $userDisplayNames = []; |
|
| 45 | - |
|
| 46 | - /** @var IGroupManager */ |
|
| 47 | - protected $groupManager; |
|
| 48 | - |
|
| 49 | - /** @var string[] */ |
|
| 50 | - protected $groupDisplayNames = []; |
|
| 51 | - |
|
| 52 | - /** @var IURLGenerator */ |
|
| 53 | - protected $url; |
|
| 54 | - |
|
| 55 | - public function __construct(IUserManager $userManager, |
|
| 56 | - IGroupManager $groupManager, |
|
| 57 | - IURLGenerator $urlGenerator) { |
|
| 58 | - $this->userManager = $userManager; |
|
| 59 | - $this->groupManager = $groupManager; |
|
| 60 | - $this->url = $urlGenerator; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @param IEvent $event |
|
| 65 | - * @param string $subject |
|
| 66 | - * @param array $parameters |
|
| 67 | - */ |
|
| 68 | - protected function setSubjects(IEvent $event, string $subject, array $parameters): void { |
|
| 69 | - $placeholders = $replacements = []; |
|
| 70 | - foreach ($parameters as $placeholder => $parameter) { |
|
| 71 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 72 | - $replacements[] = $parameter['name']; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 76 | - ->setRichSubject($subject, $parameters); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param array $data |
|
| 81 | - * @param IL10N $l |
|
| 82 | - * @return array |
|
| 83 | - */ |
|
| 84 | - protected function generateAddressbookParameter(array $data, IL10N $l): array { |
|
| 85 | - if ($data['uri'] === CardDavBackend::PERSONAL_ADDRESSBOOK_URI && |
|
| 86 | - $data['name'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME) { |
|
| 87 | - return [ |
|
| 88 | - 'type' => 'addressbook', |
|
| 89 | - 'id' => $data['id'], |
|
| 90 | - 'name' => $l->t('Personal'), |
|
| 91 | - ]; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return [ |
|
| 95 | - 'type' => 'addressbook', |
|
| 96 | - 'id' => $data['id'], |
|
| 97 | - 'name' => $data['name'], |
|
| 98 | - ]; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - protected function generateUserParameter(string $uid): array { |
|
| 102 | - return [ |
|
| 103 | - 'type' => 'user', |
|
| 104 | - 'id' => $uid, |
|
| 105 | - 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 106 | - ]; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param string $gid |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - protected function generateGroupParameter(string $gid): array { |
|
| 114 | - if (!isset($this->groupDisplayNames[$gid])) { |
|
| 115 | - $this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return [ |
|
| 119 | - 'type' => 'user-group', |
|
| 120 | - 'id' => $gid, |
|
| 121 | - 'name' => $this->groupDisplayNames[$gid], |
|
| 122 | - ]; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param string $gid |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - protected function getGroupDisplayName(string $gid): string { |
|
| 130 | - $group = $this->groupManager->get($gid); |
|
| 131 | - if ($group instanceof IGroup) { |
|
| 132 | - return $group->getDisplayName(); |
|
| 133 | - } |
|
| 134 | - return $gid; |
|
| 135 | - } |
|
| 40 | + /** @var IUserManager */ |
|
| 41 | + protected $userManager; |
|
| 42 | + |
|
| 43 | + /** @var string[] */ |
|
| 44 | + protected $userDisplayNames = []; |
|
| 45 | + |
|
| 46 | + /** @var IGroupManager */ |
|
| 47 | + protected $groupManager; |
|
| 48 | + |
|
| 49 | + /** @var string[] */ |
|
| 50 | + protected $groupDisplayNames = []; |
|
| 51 | + |
|
| 52 | + /** @var IURLGenerator */ |
|
| 53 | + protected $url; |
|
| 54 | + |
|
| 55 | + public function __construct(IUserManager $userManager, |
|
| 56 | + IGroupManager $groupManager, |
|
| 57 | + IURLGenerator $urlGenerator) { |
|
| 58 | + $this->userManager = $userManager; |
|
| 59 | + $this->groupManager = $groupManager; |
|
| 60 | + $this->url = $urlGenerator; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @param IEvent $event |
|
| 65 | + * @param string $subject |
|
| 66 | + * @param array $parameters |
|
| 67 | + */ |
|
| 68 | + protected function setSubjects(IEvent $event, string $subject, array $parameters): void { |
|
| 69 | + $placeholders = $replacements = []; |
|
| 70 | + foreach ($parameters as $placeholder => $parameter) { |
|
| 71 | + $placeholders[] = '{' . $placeholder . '}'; |
|
| 72 | + $replacements[] = $parameter['name']; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 76 | + ->setRichSubject($subject, $parameters); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param array $data |
|
| 81 | + * @param IL10N $l |
|
| 82 | + * @return array |
|
| 83 | + */ |
|
| 84 | + protected function generateAddressbookParameter(array $data, IL10N $l): array { |
|
| 85 | + if ($data['uri'] === CardDavBackend::PERSONAL_ADDRESSBOOK_URI && |
|
| 86 | + $data['name'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME) { |
|
| 87 | + return [ |
|
| 88 | + 'type' => 'addressbook', |
|
| 89 | + 'id' => $data['id'], |
|
| 90 | + 'name' => $l->t('Personal'), |
|
| 91 | + ]; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return [ |
|
| 95 | + 'type' => 'addressbook', |
|
| 96 | + 'id' => $data['id'], |
|
| 97 | + 'name' => $data['name'], |
|
| 98 | + ]; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + protected function generateUserParameter(string $uid): array { |
|
| 102 | + return [ |
|
| 103 | + 'type' => 'user', |
|
| 104 | + 'id' => $uid, |
|
| 105 | + 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 106 | + ]; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param string $gid |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + protected function generateGroupParameter(string $gid): array { |
|
| 114 | + if (!isset($this->groupDisplayNames[$gid])) { |
|
| 115 | + $this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return [ |
|
| 119 | + 'type' => 'user-group', |
|
| 120 | + 'id' => $gid, |
|
| 121 | + 'name' => $this->groupDisplayNames[$gid], |
|
| 122 | + ]; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param string $gid |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + protected function getGroupDisplayName(string $gid): string { |
|
| 130 | + $group = $this->groupManager->get($gid); |
|
| 131 | + if ($group instanceof IGroup) { |
|
| 132 | + return $group->getDisplayName(); |
|
| 133 | + } |
|
| 134 | + return $gid; |
|
| 135 | + } |
|
| 136 | 136 | } |
@@ -35,116 +35,116 @@ |
||
| 35 | 35 | |
| 36 | 36 | abstract class Base implements IProvider { |
| 37 | 37 | |
| 38 | - /** @var IUserManager */ |
|
| 39 | - protected $userManager; |
|
| 40 | - |
|
| 41 | - /** @var string[] */ |
|
| 42 | - protected $userDisplayNames = []; |
|
| 43 | - |
|
| 44 | - /** @var IGroupManager */ |
|
| 45 | - protected $groupManager; |
|
| 46 | - |
|
| 47 | - /** @var string[] */ |
|
| 48 | - protected $groupDisplayNames = []; |
|
| 49 | - |
|
| 50 | - /** @var IURLGenerator */ |
|
| 51 | - protected $url; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param IUserManager $userManager |
|
| 55 | - * @param IGroupManager $groupManager |
|
| 56 | - * @param IURLGenerator $urlGenerator |
|
| 57 | - */ |
|
| 58 | - public function __construct(IUserManager $userManager, IGroupManager $groupManager, IURLGenerator $urlGenerator) { |
|
| 59 | - $this->userManager = $userManager; |
|
| 60 | - $this->groupManager = $groupManager; |
|
| 61 | - $this->url = $urlGenerator; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param IEvent $event |
|
| 66 | - * @param string $subject |
|
| 67 | - * @param array $parameters |
|
| 68 | - */ |
|
| 69 | - protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 70 | - $placeholders = $replacements = []; |
|
| 71 | - foreach ($parameters as $placeholder => $parameter) { |
|
| 72 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 73 | - $replacements[] = $parameter['name']; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 77 | - ->setRichSubject($subject, $parameters); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param array $data |
|
| 82 | - * @param IL10N $l |
|
| 83 | - * @return array |
|
| 84 | - */ |
|
| 85 | - protected function generateCalendarParameter($data, IL10N $l) { |
|
| 86 | - if ($data['uri'] === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
| 87 | - $data['name'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
| 88 | - return [ |
|
| 89 | - 'type' => 'calendar', |
|
| 90 | - 'id' => $data['id'], |
|
| 91 | - 'name' => $l->t('Personal'), |
|
| 92 | - ]; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return [ |
|
| 96 | - 'type' => 'calendar', |
|
| 97 | - 'id' => $data['id'], |
|
| 98 | - 'name' => $data['name'], |
|
| 99 | - ]; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param int $id |
|
| 104 | - * @param string $name |
|
| 105 | - * @return array |
|
| 106 | - */ |
|
| 107 | - protected function generateLegacyCalendarParameter($id, $name) { |
|
| 108 | - return [ |
|
| 109 | - 'type' => 'calendar', |
|
| 110 | - 'id' => $id, |
|
| 111 | - 'name' => $name, |
|
| 112 | - ]; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - protected function generateUserParameter(string $uid): array { |
|
| 116 | - return [ |
|
| 117 | - 'type' => 'user', |
|
| 118 | - 'id' => $uid, |
|
| 119 | - 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 120 | - ]; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @param string $gid |
|
| 125 | - * @return array |
|
| 126 | - */ |
|
| 127 | - protected function generateGroupParameter($gid) { |
|
| 128 | - if (!isset($this->groupDisplayNames[$gid])) { |
|
| 129 | - $this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return [ |
|
| 133 | - 'type' => 'user-group', |
|
| 134 | - 'id' => $gid, |
|
| 135 | - 'name' => $this->groupDisplayNames[$gid], |
|
| 136 | - ]; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param string $gid |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - protected function getGroupDisplayName($gid) { |
|
| 144 | - $group = $this->groupManager->get($gid); |
|
| 145 | - if ($group instanceof IGroup) { |
|
| 146 | - return $group->getDisplayName(); |
|
| 147 | - } |
|
| 148 | - return $gid; |
|
| 149 | - } |
|
| 38 | + /** @var IUserManager */ |
|
| 39 | + protected $userManager; |
|
| 40 | + |
|
| 41 | + /** @var string[] */ |
|
| 42 | + protected $userDisplayNames = []; |
|
| 43 | + |
|
| 44 | + /** @var IGroupManager */ |
|
| 45 | + protected $groupManager; |
|
| 46 | + |
|
| 47 | + /** @var string[] */ |
|
| 48 | + protected $groupDisplayNames = []; |
|
| 49 | + |
|
| 50 | + /** @var IURLGenerator */ |
|
| 51 | + protected $url; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param IUserManager $userManager |
|
| 55 | + * @param IGroupManager $groupManager |
|
| 56 | + * @param IURLGenerator $urlGenerator |
|
| 57 | + */ |
|
| 58 | + public function __construct(IUserManager $userManager, IGroupManager $groupManager, IURLGenerator $urlGenerator) { |
|
| 59 | + $this->userManager = $userManager; |
|
| 60 | + $this->groupManager = $groupManager; |
|
| 61 | + $this->url = $urlGenerator; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param IEvent $event |
|
| 66 | + * @param string $subject |
|
| 67 | + * @param array $parameters |
|
| 68 | + */ |
|
| 69 | + protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 70 | + $placeholders = $replacements = []; |
|
| 71 | + foreach ($parameters as $placeholder => $parameter) { |
|
| 72 | + $placeholders[] = '{' . $placeholder . '}'; |
|
| 73 | + $replacements[] = $parameter['name']; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 77 | + ->setRichSubject($subject, $parameters); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param array $data |
|
| 82 | + * @param IL10N $l |
|
| 83 | + * @return array |
|
| 84 | + */ |
|
| 85 | + protected function generateCalendarParameter($data, IL10N $l) { |
|
| 86 | + if ($data['uri'] === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
| 87 | + $data['name'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
| 88 | + return [ |
|
| 89 | + 'type' => 'calendar', |
|
| 90 | + 'id' => $data['id'], |
|
| 91 | + 'name' => $l->t('Personal'), |
|
| 92 | + ]; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return [ |
|
| 96 | + 'type' => 'calendar', |
|
| 97 | + 'id' => $data['id'], |
|
| 98 | + 'name' => $data['name'], |
|
| 99 | + ]; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param int $id |
|
| 104 | + * @param string $name |
|
| 105 | + * @return array |
|
| 106 | + */ |
|
| 107 | + protected function generateLegacyCalendarParameter($id, $name) { |
|
| 108 | + return [ |
|
| 109 | + 'type' => 'calendar', |
|
| 110 | + 'id' => $id, |
|
| 111 | + 'name' => $name, |
|
| 112 | + ]; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + protected function generateUserParameter(string $uid): array { |
|
| 116 | + return [ |
|
| 117 | + 'type' => 'user', |
|
| 118 | + 'id' => $uid, |
|
| 119 | + 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 120 | + ]; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @param string $gid |
|
| 125 | + * @return array |
|
| 126 | + */ |
|
| 127 | + protected function generateGroupParameter($gid) { |
|
| 128 | + if (!isset($this->groupDisplayNames[$gid])) { |
|
| 129 | + $this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return [ |
|
| 133 | + 'type' => 'user-group', |
|
| 134 | + 'id' => $gid, |
|
| 135 | + 'name' => $this->groupDisplayNames[$gid], |
|
| 136 | + ]; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param string $gid |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + protected function getGroupDisplayName($gid) { |
|
| 144 | + $group = $this->groupManager->get($gid); |
|
| 145 | + if ($group instanceof IGroup) { |
|
| 146 | + return $group->getDisplayName(); |
|
| 147 | + } |
|
| 148 | + return $gid; |
|
| 149 | + } |
|
| 150 | 150 | } |
@@ -38,175 +38,175 @@ |
||
| 38 | 38 | use OCP\L10N\IFactory; |
| 39 | 39 | |
| 40 | 40 | class Provider implements IProvider { |
| 41 | - public const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
| 42 | - public const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
| 43 | - public const PASSWORD_RESET = 'password_changed'; |
|
| 44 | - public const PASSWORD_RESET_SELF = 'password_reset_self'; |
|
| 45 | - public const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
| 46 | - public const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
| 47 | - public const EMAIL_CHANGED = 'email_changed'; |
|
| 48 | - public const APP_TOKEN_CREATED = 'app_token_created'; |
|
| 49 | - public const APP_TOKEN_DELETED = 'app_token_deleted'; |
|
| 50 | - public const APP_TOKEN_RENAMED = 'app_token_renamed'; |
|
| 51 | - public const APP_TOKEN_FILESYSTEM_GRANTED = 'app_token_filesystem_granted'; |
|
| 52 | - public const APP_TOKEN_FILESYSTEM_REVOKED = 'app_token_filesystem_revoked'; |
|
| 53 | - |
|
| 54 | - /** @var IFactory */ |
|
| 55 | - protected $languageFactory; |
|
| 56 | - |
|
| 57 | - /** @var IL10N */ |
|
| 58 | - protected $l; |
|
| 59 | - |
|
| 60 | - /** @var IURLGenerator */ |
|
| 61 | - protected $url; |
|
| 62 | - |
|
| 63 | - /** @var IUserManager */ |
|
| 64 | - protected $userManager; |
|
| 65 | - |
|
| 66 | - /** @var IManager */ |
|
| 67 | - private $activityManager; |
|
| 68 | - |
|
| 69 | - public function __construct(IFactory $languageFactory, |
|
| 70 | - IURLGenerator $url, |
|
| 71 | - IUserManager $userManager, |
|
| 72 | - IManager $activityManager) { |
|
| 73 | - $this->languageFactory = $languageFactory; |
|
| 74 | - $this->url = $url; |
|
| 75 | - $this->userManager = $userManager; |
|
| 76 | - $this->activityManager = $activityManager; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param string $language |
|
| 81 | - * @param IEvent $event |
|
| 82 | - * @param IEvent|null $previousEvent |
|
| 83 | - * @return IEvent |
|
| 84 | - * @throws \InvalidArgumentException |
|
| 85 | - * @since 11.0.0 |
|
| 86 | - */ |
|
| 87 | - public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent { |
|
| 88 | - if ($event->getApp() !== 'settings') { |
|
| 89 | - throw new \InvalidArgumentException('Unknown app'); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - $this->l = $this->languageFactory->get('settings', $language); |
|
| 93 | - |
|
| 94 | - if ($this->activityManager->getRequirePNG()) { |
|
| 95 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
| 96 | - } else { |
|
| 97 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
| 101 | - $subject = $this->l->t('{actor} changed your password'); |
|
| 102 | - } elseif ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
| 103 | - $subject = $this->l->t('You changed your password'); |
|
| 104 | - } elseif ($event->getSubject() === self::PASSWORD_RESET) { |
|
| 105 | - $subject = $this->l->t('Your password was reset by an administrator'); |
|
| 106 | - } elseif ($event->getSubject() === self::PASSWORD_RESET_SELF) { |
|
| 107 | - $subject = $this->l->t('Your password was reset'); |
|
| 108 | - } elseif ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
| 109 | - $subject = $this->l->t('{actor} changed your email address'); |
|
| 110 | - } elseif ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
| 111 | - $subject = $this->l->t('You changed your email address'); |
|
| 112 | - } elseif ($event->getSubject() === self::EMAIL_CHANGED) { |
|
| 113 | - $subject = $this->l->t('Your email address was changed by an administrator'); |
|
| 114 | - } elseif ($event->getSubject() === self::APP_TOKEN_CREATED) { |
|
| 115 | - if ($event->getAffectedUser() === $event->getAuthor()) { |
|
| 116 | - $subject = $this->l->t('You created app password "{token}"'); |
|
| 117 | - } else { |
|
| 118 | - $subject = $this->l->t('An administrator created app password "{token}"'); |
|
| 119 | - } |
|
| 120 | - } elseif ($event->getSubject() === self::APP_TOKEN_DELETED) { |
|
| 121 | - $subject = $this->l->t('You deleted app password "{token}"'); |
|
| 122 | - } elseif ($event->getSubject() === self::APP_TOKEN_RENAMED) { |
|
| 123 | - $subject = $this->l->t('You renamed app password "{token}" to "{newToken}"'); |
|
| 124 | - } elseif ($event->getSubject() === self::APP_TOKEN_FILESYSTEM_GRANTED) { |
|
| 125 | - $subject = $this->l->t('You granted filesystem access to app password "{token}"'); |
|
| 126 | - } elseif ($event->getSubject() === self::APP_TOKEN_FILESYSTEM_REVOKED) { |
|
| 127 | - $subject = $this->l->t('You revoked filesystem access from app password "{token}"'); |
|
| 128 | - } else { |
|
| 129 | - throw new \InvalidArgumentException('Unknown subject'); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $parsedParameters = $this->getParameters($event); |
|
| 133 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
| 134 | - |
|
| 135 | - return $event; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @param IEvent $event |
|
| 140 | - * @return array |
|
| 141 | - * @throws \InvalidArgumentException |
|
| 142 | - */ |
|
| 143 | - protected function getParameters(IEvent $event): array { |
|
| 144 | - $subject = $event->getSubject(); |
|
| 145 | - $parameters = $event->getSubjectParameters(); |
|
| 146 | - |
|
| 147 | - switch ($subject) { |
|
| 148 | - case self::PASSWORD_CHANGED_SELF: |
|
| 149 | - case self::PASSWORD_RESET: |
|
| 150 | - case self::PASSWORD_RESET_SELF: |
|
| 151 | - case self::EMAIL_CHANGED_SELF: |
|
| 152 | - case self::EMAIL_CHANGED: |
|
| 153 | - return []; |
|
| 154 | - case self::PASSWORD_CHANGED_BY: |
|
| 155 | - case self::EMAIL_CHANGED_BY: |
|
| 156 | - return [ |
|
| 157 | - 'actor' => $this->generateUserParameter($parameters[0]), |
|
| 158 | - ]; |
|
| 159 | - case self::APP_TOKEN_CREATED: |
|
| 160 | - case self::APP_TOKEN_DELETED: |
|
| 161 | - case self::APP_TOKEN_FILESYSTEM_GRANTED: |
|
| 162 | - case self::APP_TOKEN_FILESYSTEM_REVOKED: |
|
| 163 | - return [ |
|
| 164 | - 'token' => [ |
|
| 165 | - 'type' => 'highlight', |
|
| 166 | - 'id' => $event->getObjectId(), |
|
| 167 | - 'name' => $parameters['name'], |
|
| 168 | - ] |
|
| 169 | - ]; |
|
| 170 | - case self::APP_TOKEN_RENAMED: |
|
| 171 | - return [ |
|
| 172 | - 'token' => [ |
|
| 173 | - 'type' => 'highlight', |
|
| 174 | - 'id' => $event->getObjectId(), |
|
| 175 | - 'name' => $parameters['name'], |
|
| 176 | - ], |
|
| 177 | - 'newToken' => [ |
|
| 178 | - 'type' => 'highlight', |
|
| 179 | - 'id' => $event->getObjectId(), |
|
| 180 | - 'name' => $parameters['newName'], |
|
| 181 | - ] |
|
| 182 | - ]; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - throw new \InvalidArgumentException('Unknown subject'); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @param IEvent $event |
|
| 190 | - * @param string $subject |
|
| 191 | - * @param array $parameters |
|
| 192 | - * @throws \InvalidArgumentException |
|
| 193 | - */ |
|
| 194 | - protected function setSubjects(IEvent $event, string $subject, array $parameters): void { |
|
| 195 | - $placeholders = $replacements = []; |
|
| 196 | - foreach ($parameters as $placeholder => $parameter) { |
|
| 197 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 198 | - $replacements[] = $parameter['name']; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 202 | - ->setRichSubject($subject, $parameters); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - protected function generateUserParameter(string $uid): array { |
|
| 206 | - return [ |
|
| 207 | - 'type' => 'user', |
|
| 208 | - 'id' => $uid, |
|
| 209 | - 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 210 | - ]; |
|
| 211 | - } |
|
| 41 | + public const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
| 42 | + public const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
| 43 | + public const PASSWORD_RESET = 'password_changed'; |
|
| 44 | + public const PASSWORD_RESET_SELF = 'password_reset_self'; |
|
| 45 | + public const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
| 46 | + public const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
| 47 | + public const EMAIL_CHANGED = 'email_changed'; |
|
| 48 | + public const APP_TOKEN_CREATED = 'app_token_created'; |
|
| 49 | + public const APP_TOKEN_DELETED = 'app_token_deleted'; |
|
| 50 | + public const APP_TOKEN_RENAMED = 'app_token_renamed'; |
|
| 51 | + public const APP_TOKEN_FILESYSTEM_GRANTED = 'app_token_filesystem_granted'; |
|
| 52 | + public const APP_TOKEN_FILESYSTEM_REVOKED = 'app_token_filesystem_revoked'; |
|
| 53 | + |
|
| 54 | + /** @var IFactory */ |
|
| 55 | + protected $languageFactory; |
|
| 56 | + |
|
| 57 | + /** @var IL10N */ |
|
| 58 | + protected $l; |
|
| 59 | + |
|
| 60 | + /** @var IURLGenerator */ |
|
| 61 | + protected $url; |
|
| 62 | + |
|
| 63 | + /** @var IUserManager */ |
|
| 64 | + protected $userManager; |
|
| 65 | + |
|
| 66 | + /** @var IManager */ |
|
| 67 | + private $activityManager; |
|
| 68 | + |
|
| 69 | + public function __construct(IFactory $languageFactory, |
|
| 70 | + IURLGenerator $url, |
|
| 71 | + IUserManager $userManager, |
|
| 72 | + IManager $activityManager) { |
|
| 73 | + $this->languageFactory = $languageFactory; |
|
| 74 | + $this->url = $url; |
|
| 75 | + $this->userManager = $userManager; |
|
| 76 | + $this->activityManager = $activityManager; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param string $language |
|
| 81 | + * @param IEvent $event |
|
| 82 | + * @param IEvent|null $previousEvent |
|
| 83 | + * @return IEvent |
|
| 84 | + * @throws \InvalidArgumentException |
|
| 85 | + * @since 11.0.0 |
|
| 86 | + */ |
|
| 87 | + public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent { |
|
| 88 | + if ($event->getApp() !== 'settings') { |
|
| 89 | + throw new \InvalidArgumentException('Unknown app'); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + $this->l = $this->languageFactory->get('settings', $language); |
|
| 93 | + |
|
| 94 | + if ($this->activityManager->getRequirePNG()) { |
|
| 95 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
| 96 | + } else { |
|
| 97 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
| 101 | + $subject = $this->l->t('{actor} changed your password'); |
|
| 102 | + } elseif ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
| 103 | + $subject = $this->l->t('You changed your password'); |
|
| 104 | + } elseif ($event->getSubject() === self::PASSWORD_RESET) { |
|
| 105 | + $subject = $this->l->t('Your password was reset by an administrator'); |
|
| 106 | + } elseif ($event->getSubject() === self::PASSWORD_RESET_SELF) { |
|
| 107 | + $subject = $this->l->t('Your password was reset'); |
|
| 108 | + } elseif ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
| 109 | + $subject = $this->l->t('{actor} changed your email address'); |
|
| 110 | + } elseif ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
| 111 | + $subject = $this->l->t('You changed your email address'); |
|
| 112 | + } elseif ($event->getSubject() === self::EMAIL_CHANGED) { |
|
| 113 | + $subject = $this->l->t('Your email address was changed by an administrator'); |
|
| 114 | + } elseif ($event->getSubject() === self::APP_TOKEN_CREATED) { |
|
| 115 | + if ($event->getAffectedUser() === $event->getAuthor()) { |
|
| 116 | + $subject = $this->l->t('You created app password "{token}"'); |
|
| 117 | + } else { |
|
| 118 | + $subject = $this->l->t('An administrator created app password "{token}"'); |
|
| 119 | + } |
|
| 120 | + } elseif ($event->getSubject() === self::APP_TOKEN_DELETED) { |
|
| 121 | + $subject = $this->l->t('You deleted app password "{token}"'); |
|
| 122 | + } elseif ($event->getSubject() === self::APP_TOKEN_RENAMED) { |
|
| 123 | + $subject = $this->l->t('You renamed app password "{token}" to "{newToken}"'); |
|
| 124 | + } elseif ($event->getSubject() === self::APP_TOKEN_FILESYSTEM_GRANTED) { |
|
| 125 | + $subject = $this->l->t('You granted filesystem access to app password "{token}"'); |
|
| 126 | + } elseif ($event->getSubject() === self::APP_TOKEN_FILESYSTEM_REVOKED) { |
|
| 127 | + $subject = $this->l->t('You revoked filesystem access from app password "{token}"'); |
|
| 128 | + } else { |
|
| 129 | + throw new \InvalidArgumentException('Unknown subject'); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $parsedParameters = $this->getParameters($event); |
|
| 133 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
| 134 | + |
|
| 135 | + return $event; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @param IEvent $event |
|
| 140 | + * @return array |
|
| 141 | + * @throws \InvalidArgumentException |
|
| 142 | + */ |
|
| 143 | + protected function getParameters(IEvent $event): array { |
|
| 144 | + $subject = $event->getSubject(); |
|
| 145 | + $parameters = $event->getSubjectParameters(); |
|
| 146 | + |
|
| 147 | + switch ($subject) { |
|
| 148 | + case self::PASSWORD_CHANGED_SELF: |
|
| 149 | + case self::PASSWORD_RESET: |
|
| 150 | + case self::PASSWORD_RESET_SELF: |
|
| 151 | + case self::EMAIL_CHANGED_SELF: |
|
| 152 | + case self::EMAIL_CHANGED: |
|
| 153 | + return []; |
|
| 154 | + case self::PASSWORD_CHANGED_BY: |
|
| 155 | + case self::EMAIL_CHANGED_BY: |
|
| 156 | + return [ |
|
| 157 | + 'actor' => $this->generateUserParameter($parameters[0]), |
|
| 158 | + ]; |
|
| 159 | + case self::APP_TOKEN_CREATED: |
|
| 160 | + case self::APP_TOKEN_DELETED: |
|
| 161 | + case self::APP_TOKEN_FILESYSTEM_GRANTED: |
|
| 162 | + case self::APP_TOKEN_FILESYSTEM_REVOKED: |
|
| 163 | + return [ |
|
| 164 | + 'token' => [ |
|
| 165 | + 'type' => 'highlight', |
|
| 166 | + 'id' => $event->getObjectId(), |
|
| 167 | + 'name' => $parameters['name'], |
|
| 168 | + ] |
|
| 169 | + ]; |
|
| 170 | + case self::APP_TOKEN_RENAMED: |
|
| 171 | + return [ |
|
| 172 | + 'token' => [ |
|
| 173 | + 'type' => 'highlight', |
|
| 174 | + 'id' => $event->getObjectId(), |
|
| 175 | + 'name' => $parameters['name'], |
|
| 176 | + ], |
|
| 177 | + 'newToken' => [ |
|
| 178 | + 'type' => 'highlight', |
|
| 179 | + 'id' => $event->getObjectId(), |
|
| 180 | + 'name' => $parameters['newName'], |
|
| 181 | + ] |
|
| 182 | + ]; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + throw new \InvalidArgumentException('Unknown subject'); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @param IEvent $event |
|
| 190 | + * @param string $subject |
|
| 191 | + * @param array $parameters |
|
| 192 | + * @throws \InvalidArgumentException |
|
| 193 | + */ |
|
| 194 | + protected function setSubjects(IEvent $event, string $subject, array $parameters): void { |
|
| 195 | + $placeholders = $replacements = []; |
|
| 196 | + foreach ($parameters as $placeholder => $parameter) { |
|
| 197 | + $placeholders[] = '{' . $placeholder . '}'; |
|
| 198 | + $replacements[] = $parameter['name']; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 202 | + ->setRichSubject($subject, $parameters); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + protected function generateUserParameter(string $uid): array { |
|
| 206 | + return [ |
|
| 207 | + 'type' => 'user', |
|
| 208 | + 'id' => $uid, |
|
| 209 | + 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 210 | + ]; |
|
| 211 | + } |
|
| 212 | 212 | } |
@@ -35,143 +35,143 @@ |
||
| 35 | 35 | use OCP\L10N\IFactory as L10nFactory; |
| 36 | 36 | |
| 37 | 37 | class GroupProvider implements IProvider { |
| 38 | - public const ADDED_TO_GROUP = 'group_added'; |
|
| 39 | - public const REMOVED_FROM_GROUP = 'group_removed'; |
|
| 40 | - |
|
| 41 | - /** @var L10nFactory */ |
|
| 42 | - private $l10n; |
|
| 43 | - /** @var IURLGenerator */ |
|
| 44 | - private $urlGenerator; |
|
| 45 | - /** @var IManager */ |
|
| 46 | - private $activityManager; |
|
| 47 | - /** @var IUserManager */ |
|
| 48 | - protected $userManager; |
|
| 49 | - /** @var IGroupManager */ |
|
| 50 | - protected $groupManager; |
|
| 51 | - |
|
| 52 | - /** @var string[] */ |
|
| 53 | - protected $groupDisplayNames = []; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - public function __construct(L10nFactory $l10n, |
|
| 57 | - IURLGenerator $urlGenerator, |
|
| 58 | - IManager $activityManager, |
|
| 59 | - IUserManager $userManager, |
|
| 60 | - IGroupManager $groupManager) { |
|
| 61 | - $this->urlGenerator = $urlGenerator; |
|
| 62 | - $this->l10n = $l10n; |
|
| 63 | - $this->activityManager = $activityManager; |
|
| 64 | - $this->userManager = $userManager; |
|
| 65 | - $this->groupManager = $groupManager; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 69 | - if ($event->getType() !== 'group_settings') { |
|
| 70 | - throw new InvalidArgumentException(); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $l = $this->l10n->get('settings', $language); |
|
| 74 | - |
|
| 75 | - $params = $event->getSubjectParameters(); |
|
| 76 | - $parsedParameters = [ |
|
| 77 | - 'user' => $this->generateUserParameter($params['user']), |
|
| 78 | - 'group' => $this->generateGroupParameter($params['group']), |
|
| 79 | - ]; |
|
| 80 | - |
|
| 81 | - if (isset($params['actor'])) { |
|
| 82 | - $parsedParameters['actor'] = $this->generateUserParameter($params['actor']); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - switch ($event->getSubject()) { |
|
| 86 | - case self::ADDED_TO_GROUP: |
|
| 87 | - if (isset($parsedParameters['actor'])) { |
|
| 88 | - if ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
| 89 | - $subject = $l->t('{actor} added you to group {group}'); |
|
| 90 | - } elseif (isset($params['actor']) && $this->activityManager->getCurrentUserId() === $params['actor']) { |
|
| 91 | - $subject = $l->t('You added {user} to group {group}'); |
|
| 92 | - } else { |
|
| 93 | - $subject = $l->t('{actor} added {user} to group {group}'); |
|
| 94 | - } |
|
| 95 | - } elseif ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
| 96 | - $subject = $l->t('An administrator added you to group {group}'); |
|
| 97 | - } else { |
|
| 98 | - $subject = $l->t('An administrator added {user} to group {group}'); |
|
| 99 | - } |
|
| 100 | - break; |
|
| 101 | - case self::REMOVED_FROM_GROUP: |
|
| 102 | - if (isset($parsedParameters['actor'])) { |
|
| 103 | - if ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
| 104 | - $subject = $l->t('{actor} removed you from group {group}'); |
|
| 105 | - } elseif (isset($params['actor']) && $this->activityManager->getCurrentUserId() === $params['actor']) { |
|
| 106 | - $subject = $l->t('You removed {user} from group {group}'); |
|
| 107 | - } else { |
|
| 108 | - $subject = $l->t('{actor} removed {user} from group {group}'); |
|
| 109 | - } |
|
| 110 | - } elseif ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
| 111 | - $subject = $l->t('An administrator removed you from group {group}'); |
|
| 112 | - } else { |
|
| 113 | - $subject = $l->t('An administrator removed {user} from group {group}'); |
|
| 114 | - } |
|
| 115 | - break; |
|
| 116 | - default: |
|
| 117 | - throw new InvalidArgumentException(); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
| 121 | - |
|
| 122 | - return $event; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param IEvent $event |
|
| 127 | - * @param string $subject |
|
| 128 | - * @param array $parameters |
|
| 129 | - * @throws \InvalidArgumentException |
|
| 130 | - */ |
|
| 131 | - protected function setSubjects(IEvent $event, string $subject, array $parameters): void { |
|
| 132 | - $placeholders = $replacements = []; |
|
| 133 | - foreach ($parameters as $placeholder => $parameter) { |
|
| 134 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 135 | - $replacements[] = $parameter['name']; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 139 | - ->setRichSubject($subject, $parameters); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param string $gid |
|
| 144 | - * @return array |
|
| 145 | - */ |
|
| 146 | - protected function generateGroupParameter(string $gid): array { |
|
| 147 | - if (!isset($this->groupDisplayNames[$gid])) { |
|
| 148 | - $this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return [ |
|
| 152 | - 'type' => 'user-group', |
|
| 153 | - 'id' => $gid, |
|
| 154 | - 'name' => $this->groupDisplayNames[$gid], |
|
| 155 | - ]; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @param string $gid |
|
| 160 | - * @return string |
|
| 161 | - */ |
|
| 162 | - protected function getGroupDisplayName(string $gid): string { |
|
| 163 | - $group = $this->groupManager->get($gid); |
|
| 164 | - if ($group instanceof IGroup) { |
|
| 165 | - return $group->getDisplayName(); |
|
| 166 | - } |
|
| 167 | - return $gid; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - protected function generateUserParameter(string $uid): array { |
|
| 171 | - return [ |
|
| 172 | - 'type' => 'user', |
|
| 173 | - 'id' => $uid, |
|
| 174 | - 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 175 | - ]; |
|
| 176 | - } |
|
| 38 | + public const ADDED_TO_GROUP = 'group_added'; |
|
| 39 | + public const REMOVED_FROM_GROUP = 'group_removed'; |
|
| 40 | + |
|
| 41 | + /** @var L10nFactory */ |
|
| 42 | + private $l10n; |
|
| 43 | + /** @var IURLGenerator */ |
|
| 44 | + private $urlGenerator; |
|
| 45 | + /** @var IManager */ |
|
| 46 | + private $activityManager; |
|
| 47 | + /** @var IUserManager */ |
|
| 48 | + protected $userManager; |
|
| 49 | + /** @var IGroupManager */ |
|
| 50 | + protected $groupManager; |
|
| 51 | + |
|
| 52 | + /** @var string[] */ |
|
| 53 | + protected $groupDisplayNames = []; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + public function __construct(L10nFactory $l10n, |
|
| 57 | + IURLGenerator $urlGenerator, |
|
| 58 | + IManager $activityManager, |
|
| 59 | + IUserManager $userManager, |
|
| 60 | + IGroupManager $groupManager) { |
|
| 61 | + $this->urlGenerator = $urlGenerator; |
|
| 62 | + $this->l10n = $l10n; |
|
| 63 | + $this->activityManager = $activityManager; |
|
| 64 | + $this->userManager = $userManager; |
|
| 65 | + $this->groupManager = $groupManager; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 69 | + if ($event->getType() !== 'group_settings') { |
|
| 70 | + throw new InvalidArgumentException(); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $l = $this->l10n->get('settings', $language); |
|
| 74 | + |
|
| 75 | + $params = $event->getSubjectParameters(); |
|
| 76 | + $parsedParameters = [ |
|
| 77 | + 'user' => $this->generateUserParameter($params['user']), |
|
| 78 | + 'group' => $this->generateGroupParameter($params['group']), |
|
| 79 | + ]; |
|
| 80 | + |
|
| 81 | + if (isset($params['actor'])) { |
|
| 82 | + $parsedParameters['actor'] = $this->generateUserParameter($params['actor']); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + switch ($event->getSubject()) { |
|
| 86 | + case self::ADDED_TO_GROUP: |
|
| 87 | + if (isset($parsedParameters['actor'])) { |
|
| 88 | + if ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
| 89 | + $subject = $l->t('{actor} added you to group {group}'); |
|
| 90 | + } elseif (isset($params['actor']) && $this->activityManager->getCurrentUserId() === $params['actor']) { |
|
| 91 | + $subject = $l->t('You added {user} to group {group}'); |
|
| 92 | + } else { |
|
| 93 | + $subject = $l->t('{actor} added {user} to group {group}'); |
|
| 94 | + } |
|
| 95 | + } elseif ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
| 96 | + $subject = $l->t('An administrator added you to group {group}'); |
|
| 97 | + } else { |
|
| 98 | + $subject = $l->t('An administrator added {user} to group {group}'); |
|
| 99 | + } |
|
| 100 | + break; |
|
| 101 | + case self::REMOVED_FROM_GROUP: |
|
| 102 | + if (isset($parsedParameters['actor'])) { |
|
| 103 | + if ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
| 104 | + $subject = $l->t('{actor} removed you from group {group}'); |
|
| 105 | + } elseif (isset($params['actor']) && $this->activityManager->getCurrentUserId() === $params['actor']) { |
|
| 106 | + $subject = $l->t('You removed {user} from group {group}'); |
|
| 107 | + } else { |
|
| 108 | + $subject = $l->t('{actor} removed {user} from group {group}'); |
|
| 109 | + } |
|
| 110 | + } elseif ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
| 111 | + $subject = $l->t('An administrator removed you from group {group}'); |
|
| 112 | + } else { |
|
| 113 | + $subject = $l->t('An administrator removed {user} from group {group}'); |
|
| 114 | + } |
|
| 115 | + break; |
|
| 116 | + default: |
|
| 117 | + throw new InvalidArgumentException(); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
| 121 | + |
|
| 122 | + return $event; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param IEvent $event |
|
| 127 | + * @param string $subject |
|
| 128 | + * @param array $parameters |
|
| 129 | + * @throws \InvalidArgumentException |
|
| 130 | + */ |
|
| 131 | + protected function setSubjects(IEvent $event, string $subject, array $parameters): void { |
|
| 132 | + $placeholders = $replacements = []; |
|
| 133 | + foreach ($parameters as $placeholder => $parameter) { |
|
| 134 | + $placeholders[] = '{' . $placeholder . '}'; |
|
| 135 | + $replacements[] = $parameter['name']; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 139 | + ->setRichSubject($subject, $parameters); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param string $gid |
|
| 144 | + * @return array |
|
| 145 | + */ |
|
| 146 | + protected function generateGroupParameter(string $gid): array { |
|
| 147 | + if (!isset($this->groupDisplayNames[$gid])) { |
|
| 148 | + $this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return [ |
|
| 152 | + 'type' => 'user-group', |
|
| 153 | + 'id' => $gid, |
|
| 154 | + 'name' => $this->groupDisplayNames[$gid], |
|
| 155 | + ]; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @param string $gid |
|
| 160 | + * @return string |
|
| 161 | + */ |
|
| 162 | + protected function getGroupDisplayName(string $gid): string { |
|
| 163 | + $group = $this->groupManager->get($gid); |
|
| 164 | + if ($group instanceof IGroup) { |
|
| 165 | + return $group->getDisplayName(); |
|
| 166 | + } |
|
| 167 | + return $gid; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + protected function generateUserParameter(string $uid): array { |
|
| 171 | + return [ |
|
| 172 | + 'type' => 'user', |
|
| 173 | + 'id' => $uid, |
|
| 174 | + 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 175 | + ]; |
|
| 176 | + } |
|
| 177 | 177 | } |
@@ -37,184 +37,184 @@ |
||
| 37 | 37 | |
| 38 | 38 | class Provider implements IProvider { |
| 39 | 39 | |
| 40 | - protected IFactory $languageFactory; |
|
| 41 | - protected ?IL10N $l = null; |
|
| 42 | - protected IUrlGenerator $url; |
|
| 43 | - protected ICommentsManager $commentsManager; |
|
| 44 | - protected IUserManager $userManager; |
|
| 45 | - protected IManager $activityManager; |
|
| 46 | - |
|
| 47 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, ICommentsManager $commentsManager, IUserManager $userManager, IManager $activityManager) { |
|
| 48 | - $this->languageFactory = $languageFactory; |
|
| 49 | - $this->url = $url; |
|
| 50 | - $this->commentsManager = $commentsManager; |
|
| 51 | - $this->userManager = $userManager; |
|
| 52 | - $this->activityManager = $activityManager; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param string $language |
|
| 57 | - * @param IEvent $event |
|
| 58 | - * @param IEvent|null $previousEvent |
|
| 59 | - * @return IEvent |
|
| 60 | - * @throws \InvalidArgumentException |
|
| 61 | - * @since 11.0.0 |
|
| 62 | - */ |
|
| 63 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 64 | - if ($event->getApp() !== 'comments') { |
|
| 65 | - throw new \InvalidArgumentException(); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $this->l = $this->languageFactory->get('comments', $language); |
|
| 69 | - |
|
| 70 | - if ($event->getSubject() === 'add_comment_subject') { |
|
| 71 | - $this->parseMessage($event); |
|
| 72 | - if ($this->activityManager->getRequirePNG()) { |
|
| 73 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.png'))); |
|
| 74 | - } else { |
|
| 75 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg'))); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 79 | - try { |
|
| 80 | - return $this->parseShortVersion($event); |
|
| 81 | - } catch (\InvalidArgumentException $e) { |
|
| 82 | - // Ignore and simply use the long version... |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - return $this->parseLongVersion($event); |
|
| 87 | - } else { |
|
| 88 | - throw new \InvalidArgumentException(); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @throws \InvalidArgumentException |
|
| 94 | - */ |
|
| 95 | - protected function parseShortVersion(IEvent $event): IEvent { |
|
| 96 | - $subjectParameters = $this->getSubjectParameters($event); |
|
| 97 | - |
|
| 98 | - if ($event->getSubject() === 'add_comment_subject') { |
|
| 99 | - if ($subjectParameters['actor'] === $this->activityManager->getCurrentUserId()) { |
|
| 100 | - $event->setParsedSubject($this->l->t('You commented')) |
|
| 101 | - ->setRichSubject($this->l->t('You commented'), []); |
|
| 102 | - } else { |
|
| 103 | - $author = $this->generateUserParameter($subjectParameters['actor']); |
|
| 104 | - $event->setParsedSubject($this->l->t('%1$s commented', [$author['name']])) |
|
| 105 | - ->setRichSubject($this->l->t('{author} commented'), [ |
|
| 106 | - 'author' => $author, |
|
| 107 | - ]); |
|
| 108 | - } |
|
| 109 | - } else { |
|
| 110 | - throw new \InvalidArgumentException(); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return $event; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @throws \InvalidArgumentException |
|
| 118 | - */ |
|
| 119 | - protected function parseLongVersion(IEvent $event): IEvent { |
|
| 120 | - $subjectParameters = $this->getSubjectParameters($event); |
|
| 121 | - |
|
| 122 | - if ($event->getSubject() === 'add_comment_subject') { |
|
| 123 | - if ($subjectParameters['actor'] === $this->activityManager->getCurrentUserId()) { |
|
| 124 | - $event->setParsedSubject($this->l->t('You commented on %1$s', [ |
|
| 125 | - $subjectParameters['filePath'], |
|
| 126 | - ])) |
|
| 127 | - ->setRichSubject($this->l->t('You commented on {file}'), [ |
|
| 128 | - 'file' => $this->generateFileParameter($subjectParameters['fileId'], $subjectParameters['filePath']), |
|
| 129 | - ]); |
|
| 130 | - } else { |
|
| 131 | - $author = $this->generateUserParameter($subjectParameters['actor']); |
|
| 132 | - $event->setParsedSubject($this->l->t('%1$s commented on %2$s', [ |
|
| 133 | - $author['name'], |
|
| 134 | - $subjectParameters['filePath'], |
|
| 135 | - ])) |
|
| 136 | - ->setRichSubject($this->l->t('{author} commented on {file}'), [ |
|
| 137 | - 'author' => $author, |
|
| 138 | - 'file' => $this->generateFileParameter($subjectParameters['fileId'], $subjectParameters['filePath']), |
|
| 139 | - ]); |
|
| 140 | - } |
|
| 141 | - } else { |
|
| 142 | - throw new \InvalidArgumentException(); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return $event; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - protected function getSubjectParameters(IEvent $event): array { |
|
| 149 | - $subjectParameters = $event->getSubjectParameters(); |
|
| 150 | - if (isset($subjectParameters['fileId'])) { |
|
| 151 | - return $subjectParameters; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // Fix subjects from 12.0.3 and older |
|
| 155 | - // |
|
| 156 | - // Do NOT Remove unless necessary |
|
| 157 | - // Removing this will break parsing of activities that were created on |
|
| 158 | - // Nextcloud 12, so we should keep this as long as it's acceptable. |
|
| 159 | - // Otherwise if people upgrade over multiple releases in a short period, |
|
| 160 | - // they will get the dead entries in their stream. |
|
| 161 | - return [ |
|
| 162 | - 'actor' => $subjectParameters[0], |
|
| 163 | - 'fileId' => $event->getObjectId(), |
|
| 164 | - 'filePath' => trim($subjectParameters[1], '/'), |
|
| 165 | - ]; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - protected function parseMessage(IEvent $event): void { |
|
| 169 | - $messageParameters = $event->getMessageParameters(); |
|
| 170 | - if (empty($messageParameters)) { |
|
| 171 | ||
| 172 | - return; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $commentId = isset($messageParameters['commentId']) ? $messageParameters['commentId'] : $messageParameters[0]; |
|
| 176 | - |
|
| 177 | - try { |
|
| 178 | - $comment = $this->commentsManager->get((string) $commentId); |
|
| 179 | - $message = $comment->getMessage(); |
|
| 180 | - |
|
| 181 | - $mentionCount = 1; |
|
| 182 | - $mentions = []; |
|
| 183 | - foreach ($comment->getMentions() as $mention) { |
|
| 184 | - if ($mention['type'] !== 'user') { |
|
| 185 | - continue; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $message = str_replace('@"' . $mention['id'] . '"', '{mention' . $mentionCount . '}', $message); |
|
| 189 | - if (strpos($mention['id'], ' ') === false && strpos($mention['id'], 'guest/') !== 0) { |
|
| 190 | - $message = str_replace('@' . $mention['id'], '{mention' . $mentionCount . '}', $message); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - $mentions['mention' . $mentionCount] = $this->generateUserParameter($mention['id']); |
|
| 194 | - $mentionCount++; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $event->setParsedMessage($comment->getMessage()) |
|
| 198 | - ->setRichMessage($message, $mentions); |
|
| 199 | - } catch (NotFoundException $e) { |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - protected function generateFileParameter(int $id, string $path): array { |
|
| 204 | - return [ |
|
| 205 | - 'type' => 'file', |
|
| 206 | - 'id' => $id, |
|
| 207 | - 'name' => basename($path), |
|
| 208 | - 'path' => $path, |
|
| 209 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 210 | - ]; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - protected function generateUserParameter(string $uid): array { |
|
| 214 | - return [ |
|
| 215 | - 'type' => 'user', |
|
| 216 | - 'id' => $uid, |
|
| 217 | - 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 218 | - ]; |
|
| 219 | - } |
|
| 40 | + protected IFactory $languageFactory; |
|
| 41 | + protected ?IL10N $l = null; |
|
| 42 | + protected IUrlGenerator $url; |
|
| 43 | + protected ICommentsManager $commentsManager; |
|
| 44 | + protected IUserManager $userManager; |
|
| 45 | + protected IManager $activityManager; |
|
| 46 | + |
|
| 47 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, ICommentsManager $commentsManager, IUserManager $userManager, IManager $activityManager) { |
|
| 48 | + $this->languageFactory = $languageFactory; |
|
| 49 | + $this->url = $url; |
|
| 50 | + $this->commentsManager = $commentsManager; |
|
| 51 | + $this->userManager = $userManager; |
|
| 52 | + $this->activityManager = $activityManager; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param string $language |
|
| 57 | + * @param IEvent $event |
|
| 58 | + * @param IEvent|null $previousEvent |
|
| 59 | + * @return IEvent |
|
| 60 | + * @throws \InvalidArgumentException |
|
| 61 | + * @since 11.0.0 |
|
| 62 | + */ |
|
| 63 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 64 | + if ($event->getApp() !== 'comments') { |
|
| 65 | + throw new \InvalidArgumentException(); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $this->l = $this->languageFactory->get('comments', $language); |
|
| 69 | + |
|
| 70 | + if ($event->getSubject() === 'add_comment_subject') { |
|
| 71 | + $this->parseMessage($event); |
|
| 72 | + if ($this->activityManager->getRequirePNG()) { |
|
| 73 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.png'))); |
|
| 74 | + } else { |
|
| 75 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg'))); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 79 | + try { |
|
| 80 | + return $this->parseShortVersion($event); |
|
| 81 | + } catch (\InvalidArgumentException $e) { |
|
| 82 | + // Ignore and simply use the long version... |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return $this->parseLongVersion($event); |
|
| 87 | + } else { |
|
| 88 | + throw new \InvalidArgumentException(); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @throws \InvalidArgumentException |
|
| 94 | + */ |
|
| 95 | + protected function parseShortVersion(IEvent $event): IEvent { |
|
| 96 | + $subjectParameters = $this->getSubjectParameters($event); |
|
| 97 | + |
|
| 98 | + if ($event->getSubject() === 'add_comment_subject') { |
|
| 99 | + if ($subjectParameters['actor'] === $this->activityManager->getCurrentUserId()) { |
|
| 100 | + $event->setParsedSubject($this->l->t('You commented')) |
|
| 101 | + ->setRichSubject($this->l->t('You commented'), []); |
|
| 102 | + } else { |
|
| 103 | + $author = $this->generateUserParameter($subjectParameters['actor']); |
|
| 104 | + $event->setParsedSubject($this->l->t('%1$s commented', [$author['name']])) |
|
| 105 | + ->setRichSubject($this->l->t('{author} commented'), [ |
|
| 106 | + 'author' => $author, |
|
| 107 | + ]); |
|
| 108 | + } |
|
| 109 | + } else { |
|
| 110 | + throw new \InvalidArgumentException(); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return $event; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @throws \InvalidArgumentException |
|
| 118 | + */ |
|
| 119 | + protected function parseLongVersion(IEvent $event): IEvent { |
|
| 120 | + $subjectParameters = $this->getSubjectParameters($event); |
|
| 121 | + |
|
| 122 | + if ($event->getSubject() === 'add_comment_subject') { |
|
| 123 | + if ($subjectParameters['actor'] === $this->activityManager->getCurrentUserId()) { |
|
| 124 | + $event->setParsedSubject($this->l->t('You commented on %1$s', [ |
|
| 125 | + $subjectParameters['filePath'], |
|
| 126 | + ])) |
|
| 127 | + ->setRichSubject($this->l->t('You commented on {file}'), [ |
|
| 128 | + 'file' => $this->generateFileParameter($subjectParameters['fileId'], $subjectParameters['filePath']), |
|
| 129 | + ]); |
|
| 130 | + } else { |
|
| 131 | + $author = $this->generateUserParameter($subjectParameters['actor']); |
|
| 132 | + $event->setParsedSubject($this->l->t('%1$s commented on %2$s', [ |
|
| 133 | + $author['name'], |
|
| 134 | + $subjectParameters['filePath'], |
|
| 135 | + ])) |
|
| 136 | + ->setRichSubject($this->l->t('{author} commented on {file}'), [ |
|
| 137 | + 'author' => $author, |
|
| 138 | + 'file' => $this->generateFileParameter($subjectParameters['fileId'], $subjectParameters['filePath']), |
|
| 139 | + ]); |
|
| 140 | + } |
|
| 141 | + } else { |
|
| 142 | + throw new \InvalidArgumentException(); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return $event; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + protected function getSubjectParameters(IEvent $event): array { |
|
| 149 | + $subjectParameters = $event->getSubjectParameters(); |
|
| 150 | + if (isset($subjectParameters['fileId'])) { |
|
| 151 | + return $subjectParameters; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // Fix subjects from 12.0.3 and older |
|
| 155 | + // |
|
| 156 | + // Do NOT Remove unless necessary |
|
| 157 | + // Removing this will break parsing of activities that were created on |
|
| 158 | + // Nextcloud 12, so we should keep this as long as it's acceptable. |
|
| 159 | + // Otherwise if people upgrade over multiple releases in a short period, |
|
| 160 | + // they will get the dead entries in their stream. |
|
| 161 | + return [ |
|
| 162 | + 'actor' => $subjectParameters[0], |
|
| 163 | + 'fileId' => $event->getObjectId(), |
|
| 164 | + 'filePath' => trim($subjectParameters[1], '/'), |
|
| 165 | + ]; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + protected function parseMessage(IEvent $event): void { |
|
| 169 | + $messageParameters = $event->getMessageParameters(); |
|
| 170 | + if (empty($messageParameters)) { |
|
| 171 | ||
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $commentId = isset($messageParameters['commentId']) ? $messageParameters['commentId'] : $messageParameters[0]; |
|
| 176 | + |
|
| 177 | + try { |
|
| 178 | + $comment = $this->commentsManager->get((string) $commentId); |
|
| 179 | + $message = $comment->getMessage(); |
|
| 180 | + |
|
| 181 | + $mentionCount = 1; |
|
| 182 | + $mentions = []; |
|
| 183 | + foreach ($comment->getMentions() as $mention) { |
|
| 184 | + if ($mention['type'] !== 'user') { |
|
| 185 | + continue; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + $message = str_replace('@"' . $mention['id'] . '"', '{mention' . $mentionCount . '}', $message); |
|
| 189 | + if (strpos($mention['id'], ' ') === false && strpos($mention['id'], 'guest/') !== 0) { |
|
| 190 | + $message = str_replace('@' . $mention['id'], '{mention' . $mentionCount . '}', $message); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + $mentions['mention' . $mentionCount] = $this->generateUserParameter($mention['id']); |
|
| 194 | + $mentionCount++; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $event->setParsedMessage($comment->getMessage()) |
|
| 198 | + ->setRichMessage($message, $mentions); |
|
| 199 | + } catch (NotFoundException $e) { |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + protected function generateFileParameter(int $id, string $path): array { |
|
| 204 | + return [ |
|
| 205 | + 'type' => 'file', |
|
| 206 | + 'id' => $id, |
|
| 207 | + 'name' => basename($path), |
|
| 208 | + 'path' => $path, |
|
| 209 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
| 210 | + ]; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + protected function generateUserParameter(string $uid): array { |
|
| 214 | + return [ |
|
| 215 | + 'type' => 'user', |
|
| 216 | + 'id' => $uid, |
|
| 217 | + 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 218 | + ]; |
|
| 219 | + } |
|
| 220 | 220 | } |