diff options
author | Joas Schilling <coding@schilljs.com> | 2022-08-16 16:03:54 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-08-22 17:25:15 +0200 |
commit | 9e1b19ba0650878063375032e52b910417ba3579 (patch) | |
tree | 18079bae34bbfac69f74f68b00009f39585b3262 /lib | |
parent | f05f908afa7050106d714590752192eedb47be47 (diff) |
Ensure that the reactions array is always a JSON object
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Model/Message.php | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/Model/Message.php b/lib/Model/Message.php index 60245778c..4ed526e1b 100644 --- a/lib/Model/Message.php +++ b/lib/Model/Message.php @@ -172,6 +172,13 @@ class Message { public function toArray(): array { $expireDate = $this->getComment()->getExpireDate(); + $reactions = $this->getComment()->getReactions(); + if (empty($reactions)) { + // Cheating here to make sure the reactions array is always a + // JSON object on the API, even when there is no reaction at all. + $reactions = new \StdClass(); + } + $data = [ 'id' => (int) $this->getComment()->getId(), 'token' => $this->getRoom()->getToken(), @@ -185,7 +192,7 @@ class Message { 'messageType' => $this->getMessageType(), 'isReplyable' => $this->isReplyable(), 'referenceId' => (string) $this->getComment()->getReferenceId(), - 'reactions' => $this->getComment()->getReactions(), + 'reactions' => $reactions, 'expirationTimestamp' => $expireDate ? $expireDate->getTimestamp() : 0, ]; |