Remove tags/mentions/rich text from poll options because Mastodon and
authorrinpatch <rinpatch@sdf.org>
Sun, 19 May 2019 14:06:44 +0000 (17:06 +0300)
committerrinpatch <rinpatch@sdf.org>
Sun, 19 May 2019 14:06:44 +0000 (17:06 +0300)
add custom emoji

lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/common_api/utils.ex
lib/pleroma/web/mastodon_api/views/status_view.ex

index bc8f80389526a221286c0a18327807e02b302992..374967a1b659fc4f5862553b0a2264b9d10bb7cb 100644 (file)
@@ -154,7 +154,7 @@ defmodule Pleroma.Web.CommonAPI do
              data,
              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),
          context <- make_context(in_reply_to),
          cw <- data["spoiler_text"] || "",
@@ -179,7 +179,7 @@ defmodule Pleroma.Web.CommonAPI do
            Map.put(
              object,
              "emoji",
-             Formatter.get_emoji_map(full_payload)
+             Map.merge(Formatter.get_emoji_map(full_payload), poll_emoji)
            ) do
       res =
         ActivityPub.create(
index 2ea997789a3b2aedb352440735449502b38f44f0..cd8483c11614742ba450e9e07926cde4f8e0d4c2 100644 (file)
@@ -102,26 +102,15 @@ defmodule Pleroma.Web.CommonAPI.Utils do
     end
   end
 
-  def make_poll_data(
-        %{"poll" => %{"options" => options, "expires_in" => expires_in}} = data,
-        mentions,
-        tags
-      )
+  def make_poll_data(%{"poll" => %{"options" => options, "expires_in" => expires_in}} = data)
       when is_list(options) and is_integer(expires_in) do
-    content_type = get_content_type(data["content_type"])
-    # XXX: There is probably a more performant/cleaner way to do this
-    {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
-
+    {poll, emoji} =
+      Enum.map_reduce(options, %{}, fn option, emoji ->
         {%{
            "name" => option,
            "type" => "Note",
            "replies" => %{"type" => "Collection", "totalItems" => 0}
-         }, {mentions, tags}}
+         }, Map.merge(emoji, Formatter.get_emoji_map(option))}
       end)
 
     end_time =
@@ -136,11 +125,11 @@ defmodule Pleroma.Web.CommonAPI.Utils do
         %{"type" => "Question", "oneOf" => poll, "closed" => end_time}
       end
 
-    {poll, mentions, tags}
+    {poll, emoji}
   end
 
-  def make_poll_data(_data, mentions, tags) do
-    {%{}, mentions, tags}
+  def make_poll_data(_data) do
+    {%{}, %{}}
   end
 
   def make_content_html(
index 2a5691e1fc940aaa707bdc728c7c4b2a8b244995..0df8bb5c2bbe24a2738f3f02f668563e061cc06e 100644 (file)
@@ -325,7 +325,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
   end
 
   # TODO: Add tests for this view
-  def render("poll.json", %{object: object} = opts) do
+  def render("poll.json", %{object: object} = _opts) do
     {multiple, options} =
       case object.data do
         %{"anyOf" => options} when is_list(options) -> {true, options}
@@ -350,13 +350,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
 
       options =
         Enum.map(options, fn %{"name" => name} = option ->
-          name =
-            HTML.filter_tags(
-              name,
-              User.html_filter_policy(opts[:for])
-            )
-
-          %{title: name, votes_count: option["replies"]["votes_count"] || 0}
+          %{
+            title: HTML.strip_tags(name),
+            votes_count: option["replies"]["votes_count"] || 0
+          }
         end)
 
       %{
@@ -367,6 +364,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
         multiple: multiple,
         votes_count: votes_count,
         options: options,
+        # TODO: Actually check for a vote
         voted: false,
         emojis: build_emojis(object.data["emoji"])
       }