Transmogrifier: Strip internal emoji reaction fields.

This commit is contained in:
lain 2019-09-12 18:59:13 +02:00
parent 05e9776517
commit 8d4b661ecb
2 changed files with 17 additions and 1 deletions

View File

@ -995,9 +995,11 @@ def prepare_attachments(object) do
|> Map.put("attachment", attachments) |> Map.put("attachment", attachments)
end end
defp strip_internal_fields(object) do def strip_internal_fields(object) do
object object
|> Map.drop([ |> Map.drop([
"reactions",
"reaction_count",
"likes", "likes",
"like_count", "like_count",
"announcements", "announcements",

View File

@ -491,6 +491,20 @@ test "it strips internal likes" do
refute Map.has_key?(object.data, "likes") refute Map.has_key?(object.data, "likes")
end end
test "it strips internal reactions" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
{:ok, _, _} = CommonAPI.react_with_emoji(activity.id, user, "📢")
%{object: object} = Activity.get_by_id_with_object(activity.id)
assert Map.has_key?(object.data, "reactions")
assert Map.has_key?(object.data, "reaction_count")
object_data = Transmogrifier.strip_internal_fields(object.data)
refute Map.has_key?(object_data, "reactions")
refute Map.has_key?(object_data, "reaction_count")
end
test "it works for incoming update activities" do test "it works for incoming update activities" do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!() data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()