[#3213] Fixed Object.object_data_hashtags/1 to process only AS2 elements of `data...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Wed, 30 Dec 2020 11:42:35 +0000 (14:42 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Wed, 30 Dec 2020 11:42:35 +0000 (14:42 +0300)
lib/pleroma/object.ex

index 08114d4f2c7dd51dfca55b44228579a2fa05b9fb..dad572f2bea8caa077abd68caf6f6ddd659e8d8c 100644 (file)
@@ -405,8 +405,16 @@ defmodule Pleroma.Object do
   defp embedded_hashtags(_), do: []
 
   defp object_data_hashtags(%{"tag" => tags}) when is_list(tags) do
-    # Note: AS2 map-type elements are ignored
-    Enum.filter(tags, &is_bitstring(&1))
+    # Note: Old format with copy of hashtags as strings is ignored, using AS2
+    tags
+    |> Enum.filter(fn
+      %{"type" => "Hashtag"} = data -> Map.has_key?(data, "name")
+      _ -> false
+    end)
+    |> Enum.map(fn
+      %{"name" => "#" <> hashtag} -> String.downcase(hashtag)
+      %{"name" => hashtag} -> String.downcase(hashtag)
+    end)
   end
 
   defp object_data_hashtags(_), do: []