diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index 4b1f499d0deea..183821e37b1ee 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -404,15 +404,28 @@ public function setReferenceId(?string $referenceId): IComment { /** * @inheritDoc */ - public function getMetaData(): ?string { - return $this->data['metaData']; + public function getMetaData(): ?array { + if ($this->data['metaData'] === null) { + return null; + } + + try { + $metaData = json_decode($this->data['metaData'], true, flags: JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + return null; + } + return is_array($metaData) ? $metaData : null; } /** * @inheritDoc */ - public function setMetaData(?string $metaData): IComment { - $this->data['metaData'] = $metaData; + public function setMetaData(?array $metaData): IComment { + if ($metaData === null) { + $this->data['metaData'] = null; + } else { + $this->data['metaData'] = json_encode($metaData, JSON_THROW_ON_ERROR); + } return $this; } diff --git a/lib/public/Comments/IComment.php b/lib/public/Comments/IComment.php index de60894dc9481..0a0f1b1b251d8 100644 --- a/lib/public/Comments/IComment.php +++ b/lib/public/Comments/IComment.php @@ -280,22 +280,23 @@ public function getReferenceId(): ?string; public function setReferenceId(?string $referenceId): IComment; /** - * returns the meta data of the comment + * Returns the metadata of the comment * - * @return string|null + * @return array|null * @since 29.0.0 */ - public function getMetaData(): ?string; + public function getMetaData(): ?array; /** - * Sets (overwrites) the meta data of the comment - * It is recommended to store the data as a json encoded array + * Sets (overwrites) the metadata of the comment + * Data as a json encoded array * - * @param string|null $metaData + * @param array|null $metaData * @return IComment + * @throws \JsonException When the metadata can not be converted to a json encoded string * @since 29.0.0 */ - public function setMetaData(?string $metaData): IComment; + public function setMetaData(?array $metaData): IComment; /** * Returns the reactions array if exists