Use object.normalize.
[akkoma] / lib / pleroma / web / activity_pub / mrf / ensure_re_prepended.ex
1 defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
2 alias Pleroma.Object
3
4 @behaviour Pleroma.Web.ActivityPub.MRF
5
6 def filter_by_summary(
7 %{"summary" => parent_summary} = parent,
8 %{"summary" => child_summary} = child
9 )
10 when not is_nil(child_summary) and child_summary == parent_summary and
11 byte_size(child_summary) > 1 do
12 if not String.starts_with?(child_summary, "re:") do
13 Map.put(child, "summary", "re: " <> child_summary)
14 else
15 child
16 end
17 end
18
19 def filter_by_summary(parent, child), do: child
20
21 def filter(%{"type" => activity_type} = object) when activity_type == "Create" do
22 child = object["object"]
23 in_reply_to = Object.normalize(child["inReplyTo"])
24
25 child =
26 if(in_reply_to,
27 do: filter_by_summary(in_reply_to.data, child),
28 else: child
29 )
30
31 object = Map.put(object, "object", child)
32
33 {:ok, object}
34 end
35
36 def filter(object), do: {:ok, object}
37 end