diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index e37facfe53dfd..5f090e6f93bb6 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -523,4 +523,23 @@ protected function fromArray($data): IComment { return $this; } + + public function jsonSerialize(): mixed { + return [ + 'id' => $this->getId(), + 'parent_id' => $this->getParentId(), + 'top_parent_id' => $this->getTopmostParentId(), + 'children_count' => $this->getChildrenCount(), + 'message' => $this->getMessage(), + 'actor_type' => $this->getActorType(), + 'actor_id' => $this->getActorId(), + 'object_type' => $this->getObjectType(), + 'object_id' => $this->getObjectId(), + 'reference_id' => $this->getReferenceId(), + 'metadata' => $this->getMetaData(), + 'creation_time' => $this->getCreationDateTime()->format(\DateTimeInterface::ATOM), + 'reactions' => $this->getReactions(), + 'expire_data' => $this->getExpireDate(), + ]; + } } diff --git a/lib/public/Comments/CommentsEvent.php b/lib/public/Comments/CommentsEvent.php index 6b9e7a12f9f1e..3ff9ea976ac09 100644 --- a/lib/public/Comments/CommentsEvent.php +++ b/lib/public/Comments/CommentsEvent.php @@ -10,6 +10,7 @@ use OCP\AppFramework\Attribute\Consumable; use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IWebhookCompatibleEvent; /** * Class CommentsEvent @@ -19,7 +20,7 @@ * In the future, once the deprecated methods are removed, this class will be abstract. */ #[Consumable(since: '9.0.0')] -class CommentsEvent extends Event { +class CommentsEvent extends Event implements IWebhookCompatibleEvent { /** * @since 11.0.0 * @deprecated 33.0.0 Use \OCP\Comments\Events\CommentAddedEvent instead. @@ -70,4 +71,10 @@ public function getEvent(): string { public function getComment(): IComment { return $this->comment; } + + public function getWebhookSerializable(): array { + return [ + 'comment' => $this->comment, + ]; + } } diff --git a/lib/public/Comments/IComment.php b/lib/public/Comments/IComment.php index 45b15f1900db2..be43ace5df25d 100644 --- a/lib/public/Comments/IComment.php +++ b/lib/public/Comments/IComment.php @@ -8,6 +8,8 @@ namespace OCP\Comments; +use JsonSerializable; + /** * Interface IComment * @@ -15,7 +17,7 @@ * * @since 9.0.0 */ -interface IComment { +interface IComment extends JsonSerializable { /** * @since 9.0.0 */