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
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}
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,
"nickname" => preferredUsername || name,
"name" => displayName || name,
"host" => URI.parse(uri).host,
- "avatar" => avatar
+ "avatar" => avatar,
+ "bio" => bio
}}
else e ->
{:error, e}
<uri>https://mastodon.social/users/lambadalambda</uri>
<name>lambadalambda</name>
<email>lambadalambda@mastodon.social</email>
- <summary></summary>
+ <summary>a cool dude.</summary>
<link rel="alternate" type="text/html" href="https://mastodon.social/@lambadalambda"/>
<link rel="avatar" type="image/gif" media:width="120" media:height="120" href="https://files.mastodon.social/accounts/avatars/000/000/264/original/1429214160519.gif?1492379244"/>
<link rel="header" type="" media:width="700" media:height="335" href="/headers/original/missing.png"/>
assert user.local == false
assert user.info["uri"] == uri
assert user.ap_id == uri
+ assert user.bio == "Call me Deacon Blues."
assert user.avatar["type"] == "Image"
{:ok, user_again} = OStatus.find_or_make_user(uri)
uri = "https://social.heldscal.la/user/23211"
{:ok, user} = OStatus.find_or_make_user(uri)
- change = Ecto.Changeset.change(user, %{avatar: nil})
+ old_name = user.name
+ old_bio = user.bio
+ change = Ecto.Changeset.change(user, %{avatar: nil, bio: nil, old_name: nil})
{:ok, user} = Repo.update(change)
refute user.avatar
[author] = :xmerl_xpath.string('//author[1]', doc)
{:ok, user} = OStatus.find_make_or_update_user(author)
assert user.avatar["type"] == "Image"
+ assert user.name == old_name
+ assert user.bio == old_bio
{:ok, user_again} = OStatus.find_make_or_update_user(author)
assert user_again == user
"uri" => "https://social.heldscal.la/user/29191",
"host" => "social.heldscal.la",
"fqn" => user,
+ "bio" => "cofe",
"avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]}
}
assert data == expected
"uri" => "https://social.heldscal.la/user/29191",
"host" => "social.heldscal.la",
"fqn" => user,
+ "bio" => "cofe",
"avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]}
}
assert data == expected
"nickname" => "lambadalambda",
"name" => "Critical Value",
"host" => "mastodon.social",
+ "bio" => "a cool dude.",
"avatar" => %{"type" => "Image", "url" => [%{"href" => "https://files.mastodon.social/accounts/avatars/000/000/264/original/1429214160519.gif?1492379244", "mediaType" => "image/gif", "type" => "Link"}]}
}