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);
}
}
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;
private $mstdnAttachmentFactory;
/** @var Emoji */
private $mstdnEmojiFactory;
- /** @var Error */
- private $mstdnErrorFactory;
/** @var Poll */
private $mstdnPollFactory;
/** @var ContentItem */
Card $mstdnCardFactory,
Attachment $mstdnAttachmentFactory,
Emoji $mstdnEmojiFactory,
- Error $mstdnErrorFactory,
Poll $mstdnPollFactory,
ContentItem $contentItem,
ACLFormatter $aclFormatter
$this->mstdnCardFactory = $mstdnCardFactory;
$this->mstdnAttachmentFactory = $mstdnAttachmentFactory;
$this->mstdnEmojiFactory = $mstdnEmojiFactory;
- $this->mstdnErrorFactory = $mstdnErrorFactory;
$this->mstdnPollFactory = $mstdnPollFactory;
$this->contentItem = $contentItem;
$this->aclFormatter = $aclFormatter;
namespace Friendica\Module\Api\Mastodon;
-use Friendica\Core\System;
use Friendica\DI;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
* @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->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;
+ }
}