Re-fetch user data on salmon decode error.
This commit is contained in:
parent
77e272df2d
commit
41b8a76e96
3 changed files with 62 additions and 5 deletions
|
|
@ -221,7 +221,7 @@ defmodule Pleroma.Web.OStatus do
|
|||
Repo.insert(cs, on_conflict: :replace_all, conflict_target: :nickname)
|
||||
end
|
||||
|
||||
def make_user(uri) do
|
||||
def make_user(uri, update \\ false) do
|
||||
with {:ok, info} <- gather_user_info(uri) do
|
||||
data = %{
|
||||
name: info["name"],
|
||||
|
|
@ -231,7 +231,8 @@ defmodule Pleroma.Web.OStatus do
|
|||
avatar: info["avatar"],
|
||||
bio: info["bio"]
|
||||
}
|
||||
with %User{} = user <- User.get_by_ap_id(data.ap_id) do
|
||||
with false <- update,
|
||||
%User{} = user <- User.get_by_ap_id(data.ap_id) do
|
||||
{:ok, user}
|
||||
else _e -> insert_or_update_user(data)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|
|||
alias Pleroma.Web.OStatus.{FeedRepresenter, ActivityRepresenter}
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.{OStatus, Federator}
|
||||
alias Pleroma.Web.XML
|
||||
import Ecto.Query
|
||||
|
||||
def feed_redirect(conn, %{"nickname" => nickname}) do
|
||||
|
|
@ -36,10 +37,26 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|
|||
|> send_resp(200, response)
|
||||
end
|
||||
|
||||
defp decode_or_retry(body) do
|
||||
with {:ok, magic_key} <- Pleroma.Web.Salmon.fetch_magic_key(body),
|
||||
{:ok, doc} <- Pleroma.Web.Salmon.decode_and_validate(magic_key, body) do
|
||||
{:ok, doc}
|
||||
else
|
||||
_e ->
|
||||
with [decoded | _] <- Pleroma.Web.Salmon.decode(body),
|
||||
doc <- XML.parse_document(decoded),
|
||||
uri when not is_nil(uri) <- XML.string_from_xpath("/entry/author[1]/uri", doc),
|
||||
{:ok, user} <- Pleroma.Web.OStatus.make_user(uri, true),
|
||||
{:ok, magic_key} <- Pleroma.Web.Salmon.fetch_magic_key(body),
|
||||
{:ok, doc} <- Pleroma.Web.Salmon.decode_and_validate(magic_key, body) do
|
||||
{:ok, doc}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def salmon_incoming(conn, params) do
|
||||
{:ok, body, _conn} = read_body(conn)
|
||||
{:ok, magic_key} = Pleroma.Web.Salmon.fetch_magic_key(body)
|
||||
{:ok, doc} = Pleroma.Web.Salmon.decode_and_validate(magic_key, body)
|
||||
{:ok, doc} = decode_or_retry(body)
|
||||
|
||||
Federator.enqueue(:incoming_doc, doc)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue