Parse poll options
This commit is contained in:
parent
1b543a5644
commit
fa3894d3fa
|
@ -149,6 +149,7 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
context <- make_context(in_reply_to),
|
||||
cw <- data["spoiler_text"],
|
||||
full_payload <- String.trim(status <> (data["spoiler_text"] || "")),
|
||||
poll_options <- maybe_parse_poll_options(data["poll_options"] || []),
|
||||
length when length in 1..limit <- String.length(full_payload),
|
||||
object <-
|
||||
make_note_data(
|
||||
|
@ -157,6 +158,7 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
context,
|
||||
content_html,
|
||||
attachments,
|
||||
poll_options,
|
||||
in_reply_to,
|
||||
tags,
|
||||
cw,
|
||||
|
|
|
@ -60,6 +60,10 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
end)
|
||||
end
|
||||
|
||||
def maybe_parse_poll_options(options) do
|
||||
Enum.reject(options, &(&1 == ""))
|
||||
end
|
||||
|
||||
def to_for_user_and_mentions(user, mentions, inReplyTo, "public") do
|
||||
mentioned_users = Enum.map(mentions, fn {_, %{ap_id: ap_id}} -> ap_id end)
|
||||
|
||||
|
@ -208,7 +212,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
context,
|
||||
content_html,
|
||||
attachments,
|
||||
inReplyTo,
|
||||
poll_options,
|
||||
in_reply_to,
|
||||
tags,
|
||||
cw \\ nil,
|
||||
cc \\ []
|
||||
|
@ -221,14 +226,15 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
"summary" => cw,
|
||||
"context" => context,
|
||||
"attachment" => attachments,
|
||||
"poll" => %{"votes" => Enum.map(poll_options, &%{"name" => &1, "count" => 0})},
|
||||
"actor" => actor,
|
||||
"tag" => tags |> Enum.map(fn {_, tag} -> tag end) |> Enum.uniq()
|
||||
}
|
||||
|
||||
if inReplyTo do
|
||||
if in_reply_to do
|
||||
object
|
||||
|> Map.put("inReplyTo", inReplyTo.data["object"]["id"])
|
||||
|> Map.put("inReplyToStatusId", inReplyTo.id)
|
||||
|> Map.put("inReplyTo", in_reply_to.data["object"]["id"])
|
||||
|> Map.put("inReplyToStatusId", in_reply_to.id)
|
||||
else
|
||||
object
|
||||
end
|
||||
|
|
|
@ -196,7 +196,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
|||
pleroma: %{
|
||||
local: activity.local,
|
||||
conversation_id: get_context_id(activity)
|
||||
}
|
||||
},
|
||||
poll: object["poll"] || %{}
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -131,6 +131,28 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
refute id == third_id
|
||||
end
|
||||
|
||||
test "posting a status with poll" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" => "cofe",
|
||||
"poll_options" => ["yay", "nay"],
|
||||
"sensitive" => "false"
|
||||
})
|
||||
|
||||
assert %{
|
||||
"content" => "cofe",
|
||||
"id" => id,
|
||||
"sensitive" => false,
|
||||
"poll" => %{"options" => ["yay", "nay"]}
|
||||
} = json_response(conn, 200)
|
||||
|
||||
assert Activity.get_by_id(id)
|
||||
end
|
||||
|
||||
test "posting a sensitive status", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
Loading…
Reference in New Issue