Fix addressing

This commit is contained in:
Haelwenn (lanodan) Monnier 2020-09-15 17:22:08 +02:00
parent 641184fc7a
commit 96212b2e32
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE
3 changed files with 23 additions and 18 deletions

View File

@ -4,6 +4,7 @@
defmodule Pleroma.Object.Fetcher do defmodule Pleroma.Object.Fetcher do
alias Pleroma.HTTP alias Pleroma.HTTP
alias Pleroma.Maps
alias Pleroma.Object alias Pleroma.Object
alias Pleroma.Object.Containment alias Pleroma.Object.Containment
alias Pleroma.Repo alias Pleroma.Repo
@ -124,12 +125,14 @@ defmodule Pleroma.Object.Fetcher do
defp prepare_activity_params(data) do defp prepare_activity_params(data) do
%{ %{
"type" => "Create", "type" => "Create",
"to" => data["to"] || [],
"cc" => data["cc"] || [],
# Should we seriously keep this attributedTo thing? # Should we seriously keep this attributedTo thing?
"actor" => data["actor"] || data["attributedTo"], "actor" => data["actor"] || data["attributedTo"],
"object" => data "object" => data
} }
|> Maps.put_if_present("to", data["to"])
|> Maps.put_if_present("cc", data["cc"])
|> Maps.put_if_present("bto", data["bto"])
|> Maps.put_if_present("bcc", data["bcc"])
end end
def fetch_object_from_id!(id, options \\ []) do def fetch_object_from_id!(id, options \\ []) do

View File

@ -9,9 +9,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Utils
def cast_recipients(message, field, field_fallback \\ []) do def cast_and_filter_recipients(message, field, follower_collection, field_fallback \\ []) do
{:ok, data} = ObjectValidators.Recipients.cast(message[field] || field_fallback) {:ok, data} = ObjectValidators.Recipients.cast(message[field] || field_fallback)
data =
Enum.reject(data, fn x ->
String.ends_with?(x, "/followers") and x != follower_collection
end)
Map.put(message, field, data) Map.put(message, field, data)
end end
@ -24,11 +29,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
data data
|> Map.put("context", context) |> Map.put("context", context)
|> Map.put("context_id", context_id) |> Map.put("context_id", context_id)
|> cast_recipients("to") |> cast_and_filter_recipients("to", follower_collection)
|> cast_recipients("cc") |> cast_and_filter_recipients("cc", follower_collection)
|> cast_recipients("bto") |> cast_and_filter_recipients("bto", follower_collection)
|> cast_recipients("bcc") |> cast_and_filter_recipients("bcc", follower_collection)
|> Transmogrifier.fix_explicit_addressing(follower_collection)
|> Transmogrifier.fix_implicit_addressing(follower_collection) |> Transmogrifier.fix_implicit_addressing(follower_collection)
end end
@ -36,11 +40,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
%User{follower_address: follower_collection} = User.get_cached_by_ap_id(activity["actor"]) %User{follower_address: follower_collection} = User.get_cached_by_ap_id(activity["actor"])
activity activity
|> cast_recipients("to") |> cast_and_filter_recipients("to", follower_collection)
|> cast_recipients("cc") |> cast_and_filter_recipients("cc", follower_collection)
|> cast_recipients("bto") |> cast_and_filter_recipients("bto", follower_collection)
|> cast_recipients("bcc") |> cast_and_filter_recipients("bcc", follower_collection)
|> Transmogrifier.fix_explicit_addressing(follower_collection)
|> Transmogrifier.fix_implicit_addressing(follower_collection) |> Transmogrifier.fix_implicit_addressing(follower_collection)
end end

View File

@ -63,11 +63,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator do
%User{follower_address: follower_collection} = User.get_cached_by_ap_id(data["actor"]) %User{follower_address: follower_collection} = User.get_cached_by_ap_id(data["actor"])
data data
|> CommonFixes.cast_recipients("to", object["to"]) |> CommonFixes.cast_and_filter_recipients("to", follower_collection, object["to"])
|> CommonFixes.cast_recipients("cc", object["cc"]) |> CommonFixes.cast_and_filter_recipients("cc", follower_collection, object["cc"])
|> CommonFixes.cast_recipients("bto", object["bto"]) |> CommonFixes.cast_and_filter_recipients("bto", follower_collection, object["bto"])
|> CommonFixes.cast_recipients("bcc", object["bcc"]) |> CommonFixes.cast_and_filter_recipients("bcc", follower_collection, object["bcc"])
|> Transmogrifier.fix_explicit_addressing(follower_collection)
|> Transmogrifier.fix_implicit_addressing(follower_collection) |> Transmogrifier.fix_implicit_addressing(follower_collection)
end end