1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
8 @moduledoc "Ensure a re: is prepended on replies to a post with a Subject"
9 @behaviour Pleroma.Web.ActivityPub.MRF
11 @reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless])
12 def filter_by_summary(
13 %{"summary" => parent_summary} = _parent,
14 %{"summary" => child_summary} = child
16 when not is_nil(child_summary) and byte_size(child_summary) > 0 and
17 not is_nil(parent_summary) and byte_size(parent_summary) > 0 do
18 if (child_summary == parent_summary and not Regex.match?(@reply_prefix, child_summary)) or
19 (Regex.match?(@reply_prefix, parent_summary) &&
20 Regex.replace(@reply_prefix, parent_summary, "") == child_summary) do
21 Map.put(child, "summary", "re: " <> child_summary)
27 def filter_by_summary(_parent, child), do: child
29 def filter(%{"type" => activity_type} = object) when activity_type == "Create" do
30 child = object["object"]
31 in_reply_to = Object.normalize(child["inReplyTo"])
35 do: filter_by_summary(in_reply_to.data, child),
39 object = Map.put(object, "object", child)
44 def filter(object), do: {:ok, object}