Merge branch 'develop' into 'mastopost'

# Conflicts:
#   .gitignore
This commit is contained in:
lambda 2018-06-07 16:29:33 +00:00
commit 839cb7b424
5 changed files with 63 additions and 36 deletions

2
.gitignore vendored
View file

@ -27,5 +27,5 @@ erl_crash.dump
.DS_Store .DS_Store
.env .env
# Editor configs # Editor config
/.vscode /.vscode

View file

@ -54,7 +54,8 @@
registrations_open: true, registrations_open: true,
federating: true, federating: true,
rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy, rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,
public: true public: true,
quarantined_instances: []
config :pleroma, :activitypub, accept_blocks: true config :pleroma, :activitypub, accept_blocks: true

View file

@ -562,6 +562,17 @@ def make_user_from_nickname(nickname) do
end end
end end
@quarantined_instances Keyword.get(@instance, :quarantined_instances, [])
def should_federate?(inbox, public) do
if public do
true
else
inbox_info = URI.parse(inbox)
inbox_info.host not in @quarantined_instances
end
end
def publish(actor, activity) do def publish(actor, activity) do
followers = followers =
if actor.follower_address in activity.recipients do if actor.follower_address in activity.recipients do
@ -571,6 +582,8 @@ def publish(actor, activity) do
[] []
end end
public = is_public?(activity)
remote_inboxes = remote_inboxes =
(Pleroma.Web.Salmon.remote_users(activity) ++ followers) (Pleroma.Web.Salmon.remote_users(activity) ++ followers)
|> Enum.filter(fn user -> User.ap_enabled?(user) end) |> Enum.filter(fn user -> User.ap_enabled?(user) end)
@ -578,6 +591,7 @@ def publish(actor, activity) do
(data["endpoints"] && data["endpoints"]["sharedInbox"]) || data["inbox"] (data["endpoints"] && data["endpoints"]["sharedInbox"]) || data["inbox"]
end) end)
|> Enum.uniq() |> Enum.uniq()
|> Enum.filter(fn inbox -> should_federate?(inbox, public) end)
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data) {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
json = Jason.encode!(data) json = Jason.encode!(data)

View file

@ -189,7 +189,7 @@ def follow_import(%{assigns: %{user: user}} = conn, %{"list" => list}) do
{:ok, follower} <- User.follow(follower, followed) do {:ok, follower} <- User.follow(follower, followed) do
ActivityPub.follow(follower, followed) ActivityPub.follow(follower, followed)
else else
_e -> Logger.debug("follow_import: following #{account} failed") err -> Logger.debug("follow_import: following #{account} failed with #{inspect(err)}")
end end
end) end)
end) end)

View file

@ -144,31 +144,33 @@ def ensure_keys_present(user) do
end end
end end
defp webfinger_from_xml(doc) do defp get_magic_key(magic_key) do
magic_key = XML.string_from_xpath(~s{//Link[@rel="magic-public-key"]/@href}, doc)
"data:application/magic-public-key," <> magic_key = magic_key "data:application/magic-public-key," <> magic_key = magic_key
{:ok, magic_key}
rescue
MatchError -> {:error, "Missing magic key data."}
end
topic = defp webfinger_from_xml(doc) do
with magic_key <- XML.string_from_xpath(~s{//Link[@rel="magic-public-key"]/@href}, doc),
{:ok, magic_key} <- get_magic_key(magic_key),
topic <-
XML.string_from_xpath( XML.string_from_xpath(
~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href}, ~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href},
doc doc
) ),
subject <- XML.string_from_xpath("//Subject", doc),
subject = XML.string_from_xpath("//Subject", doc) salmon <- XML.string_from_xpath(~s{//Link[@rel="salmon"]/@href}, doc),
salmon = XML.string_from_xpath(~s{//Link[@rel="salmon"]/@href}, doc) subscribe_address <-
subscribe_address =
XML.string_from_xpath( XML.string_from_xpath(
~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template}, ~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template},
doc doc
) ),
ap_id <-
ap_id =
XML.string_from_xpath( XML.string_from_xpath(
~s{//Link[@rel="self" and @type="application/activity+json"]/@href}, ~s{//Link[@rel="self" and @type="application/activity+json"]/@href},
doc doc
) ) do
data = %{ data = %{
"magic_key" => magic_key, "magic_key" => magic_key,
"topic" => topic, "topic" => topic,
@ -179,6 +181,13 @@ defp webfinger_from_xml(doc) do
} }
{:ok, data} {:ok, data}
else
{:error, e} ->
{:error, e}
e ->
{:error, e}
end
end end
defp webfinger_from_json(doc) do defp webfinger_from_json(doc) do
@ -268,8 +277,11 @@ def finger(account) do
if doc != :error do if doc != :error do
webfinger_from_xml(doc) webfinger_from_xml(doc)
else else
{:ok, doc} = Jason.decode(body) with {:ok, doc} <- Jason.decode(body) do
webfinger_from_json(doc) webfinger_from_json(doc)
else
{:error, e} -> e
end
end end
else else
e -> e ->