Insert text representation of hashtags into object["hashtags"]
[akkoma] / lib / pleroma / web / common_api / utils.ex
index 1c74ea7875760355cbfc4baf7c0a58bf7bfb69a2..880b5d78f86965b617323960a31c2585696fbe2b 100644 (file)
@@ -310,7 +310,16 @@ defmodule Pleroma.Web.CommonAPI.Utils do
       "context" => draft.context,
       "attachment" => draft.attachments,
       "actor" => draft.user.ap_id,
-      "tag" => Keyword.values(draft.tags) |> Enum.uniq()
+      "tag" => Enum.filter(draft.tags, &is_map(&1)) |> Enum.uniq(),
+      "hashtags" =>
+        draft.tags
+        |> Enum.reduce([], fn
+          # Why so many formats
+          {:name, x}, acc -> if is_bitstring(x), do: [x | acc], else: acc
+          {"#" <> _, x}, acc -> if is_bitstring(x), do: [x | acc], else: acc
+          x, acc -> if is_bitstring(x), do: [x | acc], else: acc
+        end)
+        |> Enum.uniq()
     }
     |> add_in_reply_to(draft.in_reply_to)
     |> Map.merge(draft.extra)