forked from mirror/pixelfed
Update ComposeController
This commit is contained in:
parent
bdc5abbfbc
commit
fee2857deb
2 changed files with 55 additions and 1 deletions
|
@ -18,6 +18,7 @@ use App\{
|
|||
UserFilter,
|
||||
UserSetting
|
||||
};
|
||||
use App\Models\Poll;
|
||||
use App\Transformer\Api\{
|
||||
MediaTransformer,
|
||||
MediaDraftTransformer,
|
||||
|
@ -42,7 +43,7 @@ use App\Services\MediaPathService;
|
|||
use App\Services\MediaBlocklistService;
|
||||
use App\Services\MediaStorageService;
|
||||
use App\Services\MediaTagService;
|
||||
use App\Services\ServiceService;
|
||||
use App\Services\StatusService;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use App\Util\Lexer\Extractor;
|
||||
|
@ -682,4 +683,53 @@ class ComposeController extends Controller
|
|||
return json_decode($res->compose_settings, true);
|
||||
}));
|
||||
}
|
||||
|
||||
public function createPoll(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'caption' => 'nullable|string|max:'.config('pixelfed.max_caption_length', 500),
|
||||
'cw' => 'nullable|boolean',
|
||||
'visibility' => 'required|string|in:public,private',
|
||||
'comments_disabled' => 'nullable',
|
||||
'expiry' => 'required|in:60,360,1440,10080',
|
||||
'pollOptions' => 'required|array|min:1|max:4'
|
||||
]);
|
||||
|
||||
abort_if(config('instance.polls.enabled') == false, 404, 'Polls not enabled');
|
||||
|
||||
abort_if(Status::whereType('poll')
|
||||
->whereProfileId($request->user()->profile_id)
|
||||
->whereCaption($request->input('caption'))
|
||||
->where('created_at', '>', now()->subDays(2))
|
||||
->exists()
|
||||
, 422, 'Duplicate detected.');
|
||||
|
||||
$status = new Status;
|
||||
$status->profile_id = $request->user()->profile_id;
|
||||
$status->caption = $request->input('caption');
|
||||
$status->rendered = Autolink::create()->autolink($status->caption);
|
||||
$status->visibility = 'draft';
|
||||
$status->scope = 'draft';
|
||||
$status->type = 'poll';
|
||||
$status->local = true;
|
||||
$status->save();
|
||||
|
||||
$poll = new Poll;
|
||||
$poll->status_id = $status->id;
|
||||
$poll->profile_id = $status->profile_id;
|
||||
$poll->poll_options = $request->input('pollOptions');
|
||||
$poll->expires_at = now()->addMinutes($request->input('expiry'));
|
||||
$poll->cached_tallies = collect($poll->poll_options)->map(function($o) {
|
||||
return 0;
|
||||
})->toArray();
|
||||
$poll->save();
|
||||
|
||||
$status->visibility = $request->input('visibility');
|
||||
$status->scope = $request->input('visibility');
|
||||
$status->save();
|
||||
|
||||
NewStatusPipeline::dispatch($status);
|
||||
|
||||
return ['url' => $status->url()];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,10 @@ return [
|
|||
]
|
||||
],
|
||||
|
||||
'polls' => [
|
||||
'enabled' => false
|
||||
],
|
||||
|
||||
'stories' => [
|
||||
'enabled' => env('STORIES_ENABLED', false),
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue