1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
8 @behaviour Pleroma.Web.ActivityPub.MRF
10 @reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless])
11 def filter_by_summary(
12 %{"summary" => parent_summary} = _parent,
13 %{"summary" => child_summary} = child
15 when not is_nil(child_summary) and byte_size(child_summary) > 0 and
16 not is_nil(parent_summary) and byte_size(parent_summary) > 0 do
17 if (child_summary == parent_summary and not Regex.match?(@reply_prefix, child_summary)) or
18 (Regex.match?(@reply_prefix, parent_summary) &&
19 Regex.replace(@reply_prefix, parent_summary, "") == child_summary) do
20 Map.put(child, "summary", "re: " <> child_summary)
26 def filter_by_summary(_parent, child), do: child
28 def filter(%{"type" => activity_type} = object) when activity_type == "Create" do
29 child = object["object"]
30 in_reply_to = Object.normalize(child["inReplyTo"])
34 do: filter_by_summary(in_reply_to.data, child),
38 object = Map.put(object, "object", child)
43 def filter(object), do: {:ok, object}