diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-05-16 18:33:40 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-05-16 18:33:40 +0300 |
commit | f2a08bacc9859178e74d23a0fbe71c3a5e319f25 (patch) | |
tree | f24cf8f9f89641b3954c7108b48c7a5004daeed8 /lib/Db | |
parent | c8148e64d320f2d16b00c5ccde6133f3164892cb (diff) |
Always serialize outbox message recipients into arrays
array_filter keeps the index of array elements prior to the filtering.
So if you have a message with one *to* and one *cc* values, the *to*
will have index 0 and *cc* has 1. json_encode will later consider the
former as a simple PHP array and map it to a json array. Since the *cc*
value has a non-0 index for its first element, it would convert the
value to a json object and use the 1 index as key.
By running the values through array_value we can re-index all recipient
arrays before they run through json_encode.
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Db')
-rw-r--r-- | lib/Db/LocalMessage.php | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/Db/LocalMessage.php b/lib/Db/LocalMessage.php index 722a4c9ad..54825ff5a 100644 --- a/lib/Db/LocalMessage.php +++ b/lib/Db/LocalMessage.php @@ -107,18 +107,26 @@ class LocalMessage extends Entity implements JsonSerializable { 'isHtml' => $this->isHtml(), 'inReplyToMessageId' => $this->getInReplyToMessageId(), 'attachments' => $this->getAttachments(), - 'from' => array_filter($this->getRecipients(), function (Recipient $recipient) { - return $recipient->getType() === Recipient::TYPE_FROM; - }), - 'to' => array_filter($this->getRecipients(), function (Recipient $recipient) { - return $recipient->getType() === Recipient::TYPE_TO; - }), - 'cc' => array_filter($this->getRecipients(), function (Recipient $recipient) { - return $recipient->getType() === Recipient::TYPE_CC; - }), - 'bcc' => array_filter($this->getRecipients(), function (Recipient $recipient) { - return $recipient->getType() === Recipient::TYPE_BCC; - }), + 'from' => array_values( + array_filter($this->getRecipients(), function (Recipient $recipient) { + return $recipient->getType() === Recipient::TYPE_FROM; + }) + ), + 'to' => array_values( + array_filter($this->getRecipients(), function (Recipient $recipient) { + return $recipient->getType() === Recipient::TYPE_TO; + }) + ), + 'cc' => array_values( + array_filter($this->getRecipients(), function (Recipient $recipient) { + return $recipient->getType() === Recipient::TYPE_CC; + }) + ), + 'bcc' => array_values( + array_filter($this->getRecipients(), function (Recipient $recipient) { + return $recipient->getType() === Recipient::TYPE_BCC; + }) + ), ]; } |