[REFACTORING]Use method chain instead of if clauses

This commit is contained in:
Kitaiti Makoto 2022-02-13 01:31:15 +09:00
parent 4ccfec8019
commit d3e11c78d7
2 changed files with 11 additions and 15 deletions

View File

@ -445,16 +445,16 @@ pub trait ToAsUri {
impl ToAsUri for OneOrMany<AnyBase> {
fn to_as_uri(&self) -> Option<String> {
if let Some(prop) = self.as_one() {
prop.as_xsd_any_uri().map(|uri| uri.to_string())
} else if let Some(prop) = self.as_many() {
prop.iter()
self.as_one()
.and_then(|prop| prop.as_xsd_any_uri().map(|uri| uri.to_string()))
.or_else(|| {
self.as_many().and_then(|props| {
props
.iter()
.next()
.and_then(|p| p.as_xsd_any_uri())
.map(|uri| uri.to_string())
} else {
None
}
.and_then(|prop| prop.as_xsd_any_uri().map(|uri| uri.to_string()))
})
})
}
}

View File

@ -1074,11 +1074,7 @@ impl FromId07<DbConn> for User {
..NewUser::default()
};
let avatar_id = if let Some(icon) = acct.object_ref().icon() {
icon.to_as_uri()
} else {
None
};
let avatar_id = acct.object_ref().icon().and_then(|icon| icon.to_as_uri());
let (ap_url, inst) = {
let any_base = acct.into_any_base()?;