Skip to content

Commit

Permalink
Issue 13922: "voted" must not be null (#13923)
Browse files Browse the repository at this point in the history
  • Loading branch information
annando committed Feb 20, 2024
1 parent bb7d25d commit d95c9d2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/Factory/Api/Mastodon/Poll.php
Expand Up @@ -67,10 +67,12 @@ public function createFromId(int $id, int $uid = 0): \Friendica\Object\Api\Masto

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);
}
}
5 changes: 0 additions & 5 deletions src/Factory/Api/Mastodon/Status.php
Expand Up @@ -32,7 +32,6 @@
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;
Expand Down Expand Up @@ -60,8 +59,6 @@ class Status extends BaseFactory
private $mstdnAttachmentFactory;
/** @var Emoji */
private $mstdnEmojiFactory;
/** @var Error */
private $mstdnErrorFactory;
/** @var Poll */
private $mstdnPollFactory;
/** @var ContentItem */
Expand All @@ -78,7 +75,6 @@ public function __construct(
Card $mstdnCardFactory,
Attachment $mstdnAttachmentFactory,
Emoji $mstdnEmojiFactory,
Error $mstdnErrorFactory,
Poll $mstdnPollFactory,
ContentItem $contentItem,
ACLFormatter $aclFormatter
Expand All @@ -91,7 +87,6 @@ public function __construct(
$this->mstdnCardFactory = $mstdnCardFactory;
$this->mstdnAttachmentFactory = $mstdnAttachmentFactory;
$this->mstdnEmojiFactory = $mstdnEmojiFactory;
$this->mstdnErrorFactory = $mstdnErrorFactory;
$this->mstdnPollFactory = $mstdnPollFactory;
$this->contentItem = $contentItem;
$this->aclFormatter = $aclFormatter;
Expand Down
1 change: 0 additions & 1 deletion src/Module/Api/Mastodon/Polls.php
Expand Up @@ -21,7 +21,6 @@

namespace Friendica\Module\Api\Mastodon;

use Friendica\Core\System;
use Friendica\DI;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
Expand Down
18 changes: 16 additions & 2 deletions src/Object/Api/Mastodon/Poll.php
Expand Up @@ -61,17 +61,31 @@ 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;
$this->expired = $expired;
$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;
}
}

0 comments on commit d95c9d2

Please sign in to comment.