]> git.mxchange.org Git - friendica.git/commitdiff
Issue 13922: "voted" must not be null (#13923)
authorMichael Vogel <icarus@dabo.de>
Tue, 20 Feb 2024 06:09:55 +0000 (07:09 +0100)
committerGitHub <noreply@github.com>
Tue, 20 Feb 2024 06:09:55 +0000 (07:09 +0100)
src/Factory/Api/Mastodon/Poll.php
src/Factory/Api/Mastodon/Status.php
src/Module/Api/Mastodon/Polls.php
src/Object/Api/Mastodon/Poll.php

index 17c8054145ee966cdb375ccc7432ec48a24e9b29..036da1d31e7b4b0d05bb59871f5421ca863729bd 100644 (file)
@@ -67,10 +67,12 @@ class Poll extends BaseFactory
 
                if (empty($uid)) {
                        $ownvotes = null;
+                       $voted    = null;
                } else {
                        $ownvotes = [];
+                       $voted    = false;
                }
 
-               return new \Friendica\Object\Api\Mastodon\Poll($question, $options, $expired, $votes, $ownvotes);
+               return new \Friendica\Object\Api\Mastodon\Poll($question, $options, $expired, $votes, $ownvotes, $voted);
        }
 }
index e001ef80e0ef06bb2a5f75a389c5a73e1b1b7468..5cfcad6362e0b544e68e1571ee6f352ecd55bed5 100644 (file)
@@ -32,7 +32,6 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Item;
 use Friendica\Model\Post;
-use Friendica\Model\Tag as TagModel;
 use Friendica\Model\Verb;
 use Friendica\Network\HTTPException;
 use Friendica\Object\Api\Mastodon\Status\FriendicaDeliveryData;
@@ -60,8 +59,6 @@ class Status extends BaseFactory
        private $mstdnAttachmentFactory;
        /** @var Emoji */
        private $mstdnEmojiFactory;
-       /** @var Error */
-       private $mstdnErrorFactory;
        /** @var Poll */
        private $mstdnPollFactory;
        /** @var ContentItem */
@@ -78,7 +75,6 @@ class Status extends BaseFactory
                Card $mstdnCardFactory,
                Attachment $mstdnAttachmentFactory,
                Emoji $mstdnEmojiFactory,
-               Error $mstdnErrorFactory,
                Poll $mstdnPollFactory,
                ContentItem $contentItem,
                ACLFormatter $aclFormatter
@@ -91,7 +87,6 @@ class Status extends BaseFactory
                $this->mstdnCardFactory       = $mstdnCardFactory;
                $this->mstdnAttachmentFactory = $mstdnAttachmentFactory;
                $this->mstdnEmojiFactory      = $mstdnEmojiFactory;
-               $this->mstdnErrorFactory      = $mstdnErrorFactory;
                $this->mstdnPollFactory       = $mstdnPollFactory;
                $this->contentItem            = $contentItem;
                $this->aclFormatter           = $aclFormatter;
index ed5ae99352d13aa6e7c30113506a9519d9c5e954..5a4d5dfe72329a8a259ed068ac35362ad06bdde6 100644 (file)
@@ -21,7 +21,6 @@
 
 namespace Friendica\Module\Api\Mastodon;
 
-use Friendica\Core\System;
 use Friendica\DI;
 use Friendica\Module\BaseApi;
 use Friendica\Network\HTTPException;
index 1ccc6d4cd7ab0a064884485961be751e18205e6c..d4455c24a1deef0f131fb221ed0b58a7d569ea71 100644 (file)
@@ -61,7 +61,7 @@ class Poll extends BaseDataTransferObject
         * @param int   $votes    Number of total votes
         * @param array $ownvotes Own vote
         */
-       public function __construct(array $question, array $options, bool $expired, int $votes, array $ownvotes = null)
+       public function __construct(array $question, array $options, bool $expired, int $votes, array $ownvotes = null, bool $voted = null)
        {
                $this->id           = (string)$question['id'];
                $this->expires_at   = !empty($question['end-time']) ? DateTimeFormat::utc($question['end-time'], DateTimeFormat::JSON) : null;
@@ -69,9 +69,23 @@ class Poll extends BaseDataTransferObject
                $this->multiple     = (bool)$question['multiple'];
                $this->votes_count  = $votes;
                $this->voters_count = $this->multiple ? $question['voters'] : null;
-               $this->voted        = null;
+               $this->voted        = $voted;
                $this->own_votes    = $ownvotes;
                $this->options      = $options;
                $this->emojis       = [];
        }
+
+       public function toArray(): array
+       {
+               $status = parent::toArray();
+
+               if (is_null($status['voted'])) {
+                       unset($status['voted']);
+               }
+
+               if (is_null($status['own_votes'])) {
+                       unset($status['own_votes']);
+               }
+               return $status;
+       }
 }