diff --git a/fractal-matrix-api/src/backend/register.rs b/fractal-matrix-api/src/backend/register.rs index d1fa20d6..95bd71a9 100644 --- a/fractal-matrix-api/src/backend/register.rs +++ b/fractal-matrix-api/src/backend/register.rs @@ -43,11 +43,10 @@ fn build_login_attrs(user: &str, password: &str) -> Result { let emailre = Regex::new( r"^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])+@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$", )?; - let attrs; // Email - if emailre.is_match(&user) { - attrs = json!({ + let attrs = if emailre.is_match(&user) { + json!({ "type": "m.login.password", "password": password, "initial_device_display_name": "Fractal", @@ -58,15 +57,15 @@ fn build_login_attrs(user: &str, password: &str) -> Result { "medium": "email", "address": user, } - }); + }) } else { - attrs = json!({ + json!({ "type": "m.login.password", "initial_device_display_name": "Fractal", "user": user, "password": password - }); - } + }) + }; Ok(attrs) } diff --git a/fractal-matrix-api/src/util.rs b/fractal-matrix-api/src/util.rs index 7ccfaa57..8bb25cb0 100644 --- a/fractal-matrix-api/src/util.rs +++ b/fractal-matrix-api/src/util.rs @@ -513,16 +513,15 @@ pub fn resolve_media_url(base: &Url, url: &str, thumb: bool, w: i32, h: i32) -> let media = String::from(&caps["media"]); let mut params: Vec<(&str, String)> = vec![]; - let path: String; - if thumb { + let path = if thumb { params.push(("width", format!("{}", w))); params.push(("height", format!("{}", h))); params.push(("method", String::from("scale"))); - path = format!("thumbnail/{}/{}", server, media); + format!("thumbnail/{}/{}", server, media) } else { - path = format!("download/{}/{}", server, media); - } + format!("download/{}/{}", server, media) + }; media_url(base, &path, ¶ms) } @@ -541,16 +540,15 @@ pub fn dw_media( let media = String::from(&caps["media"]); let mut params: Vec<(&str, String)> = vec![]; - let path: String; - if thumb { + let path = if thumb { params.push(("width", format!("{}", w))); params.push(("height", format!("{}", h))); params.push(("method", String::from("crop"))); - path = format!("thumbnail/{}/{}", server, media); + format!("thumbnail/{}/{}", server, media) } else { - path = format!("download/{}/{}", server, media); - } + format!("download/{}/{}", server, media) + }; let url = media_url(base, &path, ¶ms)?;