From f138ae6ed9702f5905482b12210598bc93fdbd3f Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 5 Jan 2023 02:20:57 +0900 Subject: [PATCH] Allow empty avatar for remote users --- plume-models/src/users.rs | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 200260fe..3908739c 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -256,23 +256,13 @@ impl User { pub fn refetch(&self, conn: &Connection) -> Result<()> { User::fetch(&self.ap_url.clone()).and_then(|json| { - let avatar = Media::save_remote( - conn, - json.ap_actor_ref() - .icon() - .ok_or(Error::MissingApProperty)? // FIXME: Fails when icon is not set - .iter() - .next() - .and_then(|i| { - i.clone() - .extend::() // FIXME: Don't clone() - .ok()? - .and_then(|url| Some(url.id_unchecked()?.to_string())) - }) - .ok_or(Error::MissingApProperty)?, - self, - ) - .ok(); + let avatar = json + .icon() + .and_then(|icon| icon.iter().next()) + .and_then(|i| i.clone().extend::().ok()) + .and_then(|image| image) + .and_then(|image| image.id_unchecked().map(|url| url.to_string())) + .and_then(|url| Media::save_remote(conn, url, self).ok()); let pub_key = &json.ext_one.public_key.public_key_pem; diesel::update(self)