Save remote user bio and update if we see new data.
This commit is contained in:
parent
94e980d6b4
commit
bdcf42180f
5 changed files with 36 additions and 11 deletions
|
|
@ -228,16 +228,30 @@ defmodule Pleroma.Web.OStatus do
|
|||
end
|
||||
end
|
||||
|
||||
def maybe_update(doc, user) do
|
||||
old_data = %{
|
||||
avatar: user.avatar,
|
||||
bio: user.bio,
|
||||
name: user.name
|
||||
}
|
||||
|
||||
with false <- user.local,
|
||||
avatar <- make_avatar_object(doc),
|
||||
bio when not is_nil(bio) <- string_from_xpath("//author[1]/summary", doc),
|
||||
name when not is_nil(name) <- string_from_xpath("//author[1]/poco:displayName", doc),
|
||||
new_data <- %{avatar: avatar, name: name, bio: bio},
|
||||
false <- new_data == old_data do
|
||||
change = Ecto.Changeset.change(user, new_data)
|
||||
Repo.update(change)
|
||||
else e ->
|
||||
{:ok, user}
|
||||
end
|
||||
end
|
||||
|
||||
def find_make_or_update_user(doc) do
|
||||
uri = string_from_xpath("//author/uri[1]", doc)
|
||||
with {:ok, user} <- find_or_make_user(uri) do
|
||||
avatar = make_avatar_object(doc)
|
||||
if !user.local && user.avatar != avatar do
|
||||
change = Ecto.Changeset.change(user, %{avatar: avatar})
|
||||
Repo.update(change)
|
||||
else
|
||||
{:ok, user}
|
||||
end
|
||||
maybe_update(doc, user)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -261,7 +275,8 @@ defmodule Pleroma.Web.OStatus do
|
|||
nickname: info["nickname"] <> "@" <> info["host"],
|
||||
ap_id: info["uri"],
|
||||
info: info,
|
||||
avatar: info["avatar"]
|
||||
avatar: info["avatar"],
|
||||
bio: info["bio"]
|
||||
}
|
||||
with %User{} = user <- User.get_by_ap_id(data.ap_id) do
|
||||
{:ok, user}
|
||||
|
|
|
|||
|
|
@ -156,6 +156,7 @@ defmodule Pleroma.Web.Websub do
|
|||
preferredUsername = XML.string_from_xpath("/feed/author[1]/poco:preferredUsername", doc)
|
||||
displayName = XML.string_from_xpath("/feed/author[1]/poco:displayName", doc)
|
||||
avatar = OStatus.make_avatar_object(doc)
|
||||
bio = XML.string_from_xpath("/feed/author[1]/summary", doc)
|
||||
|
||||
{:ok, %{
|
||||
"uri" => uri,
|
||||
|
|
@ -163,7 +164,8 @@ defmodule Pleroma.Web.Websub do
|
|||
"nickname" => preferredUsername || name,
|
||||
"name" => displayName || name,
|
||||
"host" => URI.parse(uri).host,
|
||||
"avatar" => avatar
|
||||
"avatar" => avatar,
|
||||
"bio" => bio
|
||||
}}
|
||||
else e ->
|
||||
{:error, e}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue