1 defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
4 @behaviour Pleroma.Web.ActivityPub.MRF
6 @reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless])
8 %{"summary" => parent_summary} = _parent,
9 %{"summary" => child_summary} = child
11 when not is_nil(child_summary) and byte_size(child_summary) > 0 and
12 not is_nil(parent_summary) and byte_size(parent_summary) > 0 do
13 if (child_summary == parent_summary and not Regex.match?(@reply_prefix, child_summary)) or
14 (Regex.match?(@reply_prefix, parent_summary) &&
15 Regex.replace(@reply_prefix, parent_summary, "") == child_summary) do
16 Map.put(child, "summary", "re: " <> child_summary)
22 def filter_by_summary(_parent, child), do: child
24 def filter(%{"type" => activity_type} = object) when activity_type == "Create" do
25 child = object["object"]
26 in_reply_to = Object.normalize(child["inReplyTo"])
30 do: filter_by_summary(in_reply_to.data, child),
34 object = Map.put(object, "object", child)
39 def filter(object), do: {:ok, object}