Merge branch 'import' into 'develop'
Fix follow errors See merge request pleroma/pleroma!198
This commit is contained in:
commit
b114808a10
|
@ -26,3 +26,6 @@ erl_crash.dump
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
# Editor config
|
||||||
|
/.vscode
|
|
@ -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)
|
||||||
|
|
|
@ -144,41 +144,50 @@ 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
|
||||||
XML.string_from_xpath(
|
with magic_key <- XML.string_from_xpath(~s{//Link[@rel="magic-public-key"]/@href}, doc),
|
||||||
~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href},
|
{:ok, magic_key} <- get_magic_key(magic_key),
|
||||||
doc
|
topic <-
|
||||||
)
|
XML.string_from_xpath(
|
||||||
|
~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href},
|
||||||
|
doc
|
||||||
|
),
|
||||||
|
subject <- XML.string_from_xpath("//Subject", doc),
|
||||||
|
salmon <- XML.string_from_xpath(~s{//Link[@rel="salmon"]/@href}, doc),
|
||||||
|
subscribe_address <-
|
||||||
|
XML.string_from_xpath(
|
||||||
|
~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template},
|
||||||
|
doc
|
||||||
|
),
|
||||||
|
ap_id <-
|
||||||
|
XML.string_from_xpath(
|
||||||
|
~s{//Link[@rel="self" and @type="application/activity+json"]/@href},
|
||||||
|
doc
|
||||||
|
) do
|
||||||
|
data = %{
|
||||||
|
"magic_key" => magic_key,
|
||||||
|
"topic" => topic,
|
||||||
|
"subject" => subject,
|
||||||
|
"salmon" => salmon,
|
||||||
|
"subscribe_address" => subscribe_address,
|
||||||
|
"ap_id" => ap_id
|
||||||
|
}
|
||||||
|
|
||||||
subject = XML.string_from_xpath("//Subject", doc)
|
{:ok, data}
|
||||||
salmon = XML.string_from_xpath(~s{//Link[@rel="salmon"]/@href}, doc)
|
else
|
||||||
|
{:error, e} ->
|
||||||
|
{:error, e}
|
||||||
|
|
||||||
subscribe_address =
|
e ->
|
||||||
XML.string_from_xpath(
|
{:error, e}
|
||||||
~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template},
|
end
|
||||||
doc
|
|
||||||
)
|
|
||||||
|
|
||||||
ap_id =
|
|
||||||
XML.string_from_xpath(
|
|
||||||
~s{//Link[@rel="self" and @type="application/activity+json"]/@href},
|
|
||||||
doc
|
|
||||||
)
|
|
||||||
|
|
||||||
data = %{
|
|
||||||
"magic_key" => magic_key,
|
|
||||||
"topic" => topic,
|
|
||||||
"subject" => subject,
|
|
||||||
"salmon" => salmon,
|
|
||||||
"subscribe_address" => subscribe_address,
|
|
||||||
"ap_id" => ap_id
|
|
||||||
}
|
|
||||||
|
|
||||||
{:ok, data}
|
|
||||||
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 ->
|
||||||
|
|
Loading…
Reference in New Issue