mirror of
https://framagit.org/tom79/fediplan.git
synced 2025-04-05 05:31:48 +02:00
Support polls
This commit is contained in:
parent
b8cc61d94b
commit
af3a7323ce
4 changed files with 40 additions and 8 deletions
|
@ -17,7 +17,6 @@ use App\SocialEntity\MastodonAccount;
|
|||
use App\SocialEntity\PollOption;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
@ -204,6 +203,30 @@ class FediPlanController extends AbstractController
|
|||
}
|
||||
$params['sensitive'] = ($data->getSensitive() == null || !$data->getSensitive())?false:true;
|
||||
|
||||
$pollOptions = $data->getPollOptions();
|
||||
$pollExpiresAt = $data->getPollExpiresAt();
|
||||
$isPollMultiple = $data->isPollMultiple();
|
||||
if( count($pollOptions) > 0){
|
||||
$count_correct_values = 0;
|
||||
foreach($pollOptions as $po) {
|
||||
/** @var $po PollOption */
|
||||
if( $po->getTitle() != null && strlen(trim($po->getTitle())) > 0){
|
||||
$count_correct_values++;
|
||||
}
|
||||
}
|
||||
|
||||
if( $count_correct_values > 1 ){
|
||||
$params['poll']['options'] = [];
|
||||
foreach($pollOptions as $po) {
|
||||
/** @var $po PollOption */
|
||||
if( $po->getTitle() != null && strlen(trim($po->getTitle())) > 0){
|
||||
$params['poll']['options'][] = trim($po->getTitle());
|
||||
}
|
||||
}
|
||||
$params['poll']['expires_in'] = $pollExpiresAt;
|
||||
$params['poll']['multiple'] = $isPollMultiple;
|
||||
}
|
||||
}
|
||||
try {
|
||||
$date = new DateTime( $data->getScheduledAt()->format("Y-m-d H:i"), new DateTimeZone($data->getTimeZone()) );
|
||||
$date->setTimezone( new DateTimeZone("UTC"));
|
||||
|
@ -212,13 +235,14 @@ class FediPlanController extends AbstractController
|
|||
try {
|
||||
$response = $mastodon_api->post_statuses($params);
|
||||
} catch (\ErrorException $e) {}
|
||||
|
||||
|
||||
$session = $request->getSession();
|
||||
if( isset($response['error']) ){
|
||||
$session->getFlashBag()->add(
|
||||
'Error',
|
||||
$response['error_message']
|
||||
);
|
||||
$form->get('content')->addError(new FormError( $response['error_message']));
|
||||
}else{
|
||||
unset($compose);
|
||||
unset($form);
|
||||
|
|
|
@ -220,7 +220,15 @@ class Mastodon_api {
|
|||
|
||||
unset($parameters['body']['media_ids']);
|
||||
}
|
||||
if(isset($parameters['body']['poll']['options'])) {
|
||||
$url .= strpos($url, '?') !== false ? '' : '?';
|
||||
foreach ($parameters['body']['poll']['options'] as $key => $value){
|
||||
$url .= 'poll[options][]=' . $value . '&';
|
||||
}
|
||||
$url = substr($url, 0, -1);
|
||||
|
||||
unset($parameters['body']['poll']['options']);
|
||||
}
|
||||
//Special treatment for filtering notifications
|
||||
if( isset($parameters['body']['exclude_types[]']) && $parameters['method'] == "GET" ){
|
||||
$url .="?";
|
||||
|
|
|
@ -14,7 +14,7 @@ class PollOption
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle(): string
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class PollOption
|
|||
/**
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle(string $title): void
|
||||
public function setTitle(?string $title): void
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class PollOption
|
|||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getVotesCount(): int
|
||||
public function getVotesCount(): ?int
|
||||
{
|
||||
return $this->votes_count;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class PollOption
|
|||
/**
|
||||
* @param int $votes_count
|
||||
*/
|
||||
public function setVotesCount(int $votes_count): void
|
||||
public function setVotesCount(?int $votes_count): void
|
||||
{
|
||||
$this->votes_count = $votes_count;
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@
|
|||
{% for message in messages %}
|
||||
{% if type == 'Error' %}
|
||||
<div class="row">
|
||||
<div class="alert alert-danger col-md-6" style="text-align: center">
|
||||
<div class="alert alert-danger col-md-12" style="text-align: center">
|
||||
{{ message }}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="row">
|
||||
<div class="alert alert-success col-md-6" style="text-align: center">
|
||||
<div class="alert alert-success col-md-12" style="text-align: center">
|
||||
{{ message }}
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue