forked from AkkomaGang/akkoma
Remove tags/mentions/rich text from poll options because Mastodon and
add custom emoji
This commit is contained in:
parent
5ece901af3
commit
1d90f9b969
3 changed files with 15 additions and 28 deletions
|
@ -154,7 +154,7 @@ def post(user, %{"status" => status} = data) do
|
||||||
data,
|
data,
|
||||||
visibility
|
visibility
|
||||||
),
|
),
|
||||||
{poll, mentions, tags} <- make_poll_data(data, mentions, tags),
|
{poll, poll_emoji} <- make_poll_data(data),
|
||||||
{to, cc} <- to_for_user_and_mentions(user, mentions, in_reply_to, visibility),
|
{to, cc} <- to_for_user_and_mentions(user, mentions, in_reply_to, visibility),
|
||||||
context <- make_context(in_reply_to),
|
context <- make_context(in_reply_to),
|
||||||
cw <- data["spoiler_text"] || "",
|
cw <- data["spoiler_text"] || "",
|
||||||
|
@ -179,7 +179,7 @@ def post(user, %{"status" => status} = data) do
|
||||||
Map.put(
|
Map.put(
|
||||||
object,
|
object,
|
||||||
"emoji",
|
"emoji",
|
||||||
Formatter.get_emoji_map(full_payload)
|
Map.merge(Formatter.get_emoji_map(full_payload), poll_emoji)
|
||||||
) do
|
) do
|
||||||
res =
|
res =
|
||||||
ActivityPub.create(
|
ActivityPub.create(
|
||||||
|
|
|
@ -102,26 +102,15 @@ def to_for_user_and_mentions(_user, mentions, inReplyTo, "direct") do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_poll_data(
|
def make_poll_data(%{"poll" => %{"options" => options, "expires_in" => expires_in}} = data)
|
||||||
%{"poll" => %{"options" => options, "expires_in" => expires_in}} = data,
|
|
||||||
mentions,
|
|
||||||
tags
|
|
||||||
)
|
|
||||||
when is_list(options) and is_integer(expires_in) do
|
when is_list(options) and is_integer(expires_in) do
|
||||||
content_type = get_content_type(data["content_type"])
|
{poll, emoji} =
|
||||||
# XXX: There is probably a more performant/cleaner way to do this
|
Enum.map_reduce(options, %{}, fn option, emoji ->
|
||||||
{poll, {mentions, tags}} =
|
|
||||||
Enum.map_reduce(options, {mentions, tags}, fn option, {mentions, tags} ->
|
|
||||||
# TODO: Custom emoji
|
|
||||||
{option, mentions_merge, tags_merge} = format_input(option, content_type)
|
|
||||||
mentions = mentions ++ mentions_merge
|
|
||||||
tags = tags ++ tags_merge
|
|
||||||
|
|
||||||
{%{
|
{%{
|
||||||
"name" => option,
|
"name" => option,
|
||||||
"type" => "Note",
|
"type" => "Note",
|
||||||
"replies" => %{"type" => "Collection", "totalItems" => 0}
|
"replies" => %{"type" => "Collection", "totalItems" => 0}
|
||||||
}, {mentions, tags}}
|
}, Map.merge(emoji, Formatter.get_emoji_map(option))}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end_time =
|
end_time =
|
||||||
|
@ -136,11 +125,11 @@ def make_poll_data(
|
||||||
%{"type" => "Question", "oneOf" => poll, "closed" => end_time}
|
%{"type" => "Question", "oneOf" => poll, "closed" => end_time}
|
||||||
end
|
end
|
||||||
|
|
||||||
{poll, mentions, tags}
|
{poll, emoji}
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_poll_data(_data, mentions, tags) do
|
def make_poll_data(_data) do
|
||||||
{%{}, mentions, tags}
|
{%{}, %{}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_content_html(
|
def make_content_html(
|
||||||
|
|
|
@ -325,7 +325,7 @@ def render("attachment.json", %{attachment: attachment}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Add tests for this view
|
# TODO: Add tests for this view
|
||||||
def render("poll.json", %{object: object} = opts) do
|
def render("poll.json", %{object: object} = _opts) do
|
||||||
{multiple, options} =
|
{multiple, options} =
|
||||||
case object.data do
|
case object.data do
|
||||||
%{"anyOf" => options} when is_list(options) -> {true, options}
|
%{"anyOf" => options} when is_list(options) -> {true, options}
|
||||||
|
@ -350,13 +350,10 @@ def render("poll.json", %{object: object} = opts) do
|
||||||
|
|
||||||
options =
|
options =
|
||||||
Enum.map(options, fn %{"name" => name} = option ->
|
Enum.map(options, fn %{"name" => name} = option ->
|
||||||
name =
|
%{
|
||||||
HTML.filter_tags(
|
title: HTML.strip_tags(name),
|
||||||
name,
|
votes_count: option["replies"]["votes_count"] || 0
|
||||||
User.html_filter_policy(opts[:for])
|
}
|
||||||
)
|
|
||||||
|
|
||||||
%{title: name, votes_count: option["replies"]["votes_count"] || 0}
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
@ -367,6 +364,7 @@ def render("poll.json", %{object: object} = opts) do
|
||||||
multiple: multiple,
|
multiple: multiple,
|
||||||
votes_count: votes_count,
|
votes_count: votes_count,
|
||||||
options: options,
|
options: options,
|
||||||
|
# TODO: Actually check for a vote
|
||||||
voted: false,
|
voted: false,
|
||||||
emojis: build_emojis(object.data["emoji"])
|
emojis: build_emojis(object.data["emoji"])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue