Allow empty avatar for remote users

This commit is contained in:
Kitaiti Makoto 2023-01-05 02:20:57 +09:00
parent 399af4004a
commit f138ae6ed9

View file

@ -256,23 +256,13 @@ impl User {
pub fn refetch(&self, conn: &Connection) -> Result<()> { pub fn refetch(&self, conn: &Connection) -> Result<()> {
User::fetch(&self.ap_url.clone()).and_then(|json| { User::fetch(&self.ap_url.clone()).and_then(|json| {
let avatar = Media::save_remote( let avatar = json
conn, .icon()
json.ap_actor_ref() .and_then(|icon| icon.iter().next())
.icon() .and_then(|i| i.clone().extend::<Image, ImageType>().ok())
.ok_or(Error::MissingApProperty)? // FIXME: Fails when icon is not set .and_then(|image| image)
.iter() .and_then(|image| image.id_unchecked().map(|url| url.to_string()))
.next() .and_then(|url| Media::save_remote(conn, url, self).ok());
.and_then(|i| {
i.clone()
.extend::<Image, ImageType>() // FIXME: Don't clone()
.ok()?
.and_then(|url| Some(url.id_unchecked()?.to_string()))
})
.ok_or(Error::MissingApProperty)?,
self,
)
.ok();
let pub_key = &json.ext_one.public_key.public_key_pem; let pub_key = &json.ext_one.public_key.public_key_pem;
diesel::update(self) diesel::update(self)