aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Activity/Event.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Activity/Event.php')
-rw-r--r--lib/private/Activity/Event.php62
1 files changed, 15 insertions, 47 deletions
diff --git a/lib/private/Activity/Event.php b/lib/private/Activity/Event.php
index 97ab7d1c935..0ccad1d0a4e 100644
--- a/lib/private/Activity/Event.php
+++ b/lib/private/Activity/Event.php
@@ -12,6 +12,7 @@ namespace OC\Activity;
use OCP\Activity\Exceptions\InvalidValueException;
use OCP\Activity\IEvent;
use OCP\RichObjectStrings\InvalidObjectExeption;
+use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator;
class Event implements IEvent {
@@ -33,7 +34,7 @@ class Event implements IEvent {
protected $subjectParsed = '';
/** @var string */
protected $subjectRich = '';
- /** @var array */
+ /** @var array<string, array<string, string>> */
protected $subjectRichParameters = [];
/** @var string */
protected $message = '';
@@ -43,7 +44,7 @@ class Event implements IEvent {
protected $messageParsed = '';
/** @var string */
protected $messageRich = '';
- /** @var array */
+ /** @var array<string, array<string, string>> */
protected $messageRichParameters = [];
/** @var string */
protected $objectType = '';
@@ -60,14 +61,11 @@ class Event implements IEvent {
/** @var IEvent|null */
protected $child;
- /** @var IValidator */
- protected $richValidator;
- /**
- * @param IValidator $richValidator
- */
- public function __construct(IValidator $richValidator) {
- $this->richValidator = $richValidator;
+ public function __construct(
+ protected IValidator $richValidator,
+ protected IRichTextFormatter $richTextFormatter,
+ ) {
}
/**
@@ -217,7 +215,7 @@ class Event implements IEvent {
if ($this->subjectParsed === '') {
try {
- $this->subjectParsed = $this->richToParsed($subject, $parameters);
+ $this->subjectParsed = $this->richTextFormatter->richToParsed($subject, $parameters);
} catch (\InvalidArgumentException $e) {
throw new InvalidValueException('richSubjectParameters', $e);
}
@@ -227,30 +225,6 @@ class Event implements IEvent {
}
/**
- * @throws \InvalidArgumentException if a parameter has no name or no type
- */
- private function richToParsed(string $message, array $parameters): string {
- $placeholders = [];
- $replacements = [];
- foreach ($parameters as $placeholder => $parameter) {
- $placeholders[] = '{' . $placeholder . '}';
- foreach (['name','type'] as $requiredField) {
- if (!isset($parameter[$requiredField]) || !is_string($parameter[$requiredField])) {
- throw new \InvalidArgumentException("Invalid rich object, {$requiredField} field is missing");
- }
- }
- if ($parameter['type'] === 'user') {
- $replacements[] = '@' . $parameter['name'];
- } elseif ($parameter['type'] === 'file') {
- $replacements[] = $parameter['path'] ?? $parameter['name'];
- } else {
- $replacements[] = $parameter['name'];
- }
- }
- return str_replace($placeholders, $replacements, $message);
- }
-
- /**
* @return string
* @since 11.0.0
*/
@@ -259,7 +233,7 @@ class Event implements IEvent {
}
/**
- * @return array[]
+ * @return array<string, array<string, string>>
* @since 11.0.0
*/
public function getRichSubjectParameters(): array {
@@ -317,7 +291,7 @@ class Event implements IEvent {
if ($this->messageParsed === '') {
try {
- $this->messageParsed = $this->richToParsed($message, $parameters);
+ $this->messageParsed = $this->richTextFormatter->richToParsed($message, $parameters);
} catch (\InvalidArgumentException $e) {
throw new InvalidValueException('richMessageParameters', $e);
}
@@ -335,7 +309,7 @@ class Event implements IEvent {
}
/**
- * @return array[]
+ * @return array<string, array<string, string>>
* @since 11.0.0
*/
public function getRichMessageParameters(): array {
@@ -441,8 +415,7 @@ class Event implements IEvent {
public function isValid(): bool {
return
$this->isValidCommon()
- &&
- $this->getSubject() !== ''
+ && $this->getSubject() !== ''
;
}
@@ -469,20 +442,15 @@ class Event implements IEvent {
return
$this->isValidCommon()
- &&
- $this->getParsedSubject() !== ''
+ && $this->getParsedSubject() !== ''
;
}
protected function isValidCommon(): bool {
return
$this->getApp() !== ''
- &&
- $this->getType() !== ''
- &&
- $this->getAffectedUser() !== ''
- &&
- $this->getTimestamp() !== 0
+ && $this->getType() !== ''
+ && $this->getTimestamp() !== 0
/**
* Disabled for BC with old activities
* &&