diff --git a/fractal-matrix-api/src/backend/register.rs b/fractal-matrix-api/src/backend/register.rs index d4e465bb..4193957e 100644 --- a/fractal-matrix-api/src/backend/register.rs +++ b/fractal-matrix-api/src/backend/register.rs @@ -5,7 +5,6 @@ use std::thread; use url::Url; use crate::error::Error; -use crate::globals; use crate::util::json_q; use crate::types::LoginRequest; @@ -16,6 +15,8 @@ use crate::types::RegisterResponse; use crate::backend::types::BKResponse; use crate::backend::types::Backend; +use crate::globals; + pub fn guest(bk: &Backend, server: &str) -> Result<(), Error> { let baseu = Url::parse(server)?; let url = baseu diff --git a/fractal-matrix-api/src/backend/room.rs b/fractal-matrix-api/src/backend/room.rs index 69ced0fb..8699e7bd 100644 --- a/fractal-matrix-api/src/backend/room.rs +++ b/fractal-matrix-api/src/backend/room.rs @@ -453,8 +453,7 @@ pub fn set_room_avatar(bk: &Backend, roomid: &str, avatar: &str) -> Result<(), E &roomurl, &attrs, |_| tx.send(BKResponse::SetRoomAvatar).unwrap(), - |err| tx.send(BKResponse::SetRoomAvatarError(err)).unwrap(), - 0 + |err| tx.send(BKResponse::SetRoomAvatarError(err)).unwrap() ); } }; @@ -577,7 +576,7 @@ pub fn direct_chat(bk: &Backend, user: &Member, internal_id: String) -> Result<( } let attrs = json!(directs.clone()); - put!(&direct_url, &attrs, |_| {}, |err| error!("{:?}", err), 0); + put!(&direct_url, &attrs, |_| {}, |err| error!("{:?}", err)); }, |err| { tx.send(BKResponse::NewRoomError(err, internal_id)).unwrap(); diff --git a/fractal-matrix-api/src/backend/stickers.rs b/fractal-matrix-api/src/backend/stickers.rs index 30331f3b..0877824b 100644 --- a/fractal-matrix-api/src/backend/stickers.rs +++ b/fractal-matrix-api/src/backend/stickers.rs @@ -8,8 +8,6 @@ use std::sync::{Arc, Mutex}; use std::thread; use url::Url; -use crate::globals; -//use std::thread; use crate::error::Error; use crate::backend::types::BKCommand; @@ -187,12 +185,12 @@ fn get_scalar_token(data: &Arc>) -> Result { let uid = data.lock().unwrap().user_id.clone(); let url = url(data, &format!("user/{}/openid/request_token", uid), vec![])?; - let js = json_q("post", &url, &json!({}), globals::TIMEOUT)?; + let js = json_q("post", &url, &json!({}))?; let vurl = base .join("/api/register") .expect("Wrong URL in get_scalar_token()"); - let js = json_q("post", &vurl, &js, globals::TIMEOUT)?; + let js = json_q("post", &vurl, &js)?; match js["scalar_token"].as_str() { Some(st) => { diff --git a/fractal-matrix-api/src/backend/sync.rs b/fractal-matrix-api/src/backend/sync.rs index 02b46d9a..23c8d914 100644 --- a/fractal-matrix-api/src/backend/sync.rs +++ b/fractal-matrix-api/src/backend/sync.rs @@ -33,9 +33,7 @@ pub fn sync(bk: &Backend, new_since: Option, initial: bool) -> Result<() params.push(("since", since)); } - let timeout = if !initial { - time::Duration::from_secs(30) - } else { + if initial { let filter = Filter { room: Some(RoomFilter { state: Some(RoomEventFilter { @@ -71,10 +69,9 @@ pub fn sync(bk: &Backend, new_since: Option, initial: bool) -> Result<() let filter_str = serde_json::to_string(&filter).expect("Failed to serialize sync request filter"); params.push(("filter", filter_str)); - - Default::default() }; + let timeout = time::Duration::from_secs(30); params.push(("timeout", timeout.as_secs().to_string())); let baseu = bk.get_base_url(); @@ -192,8 +189,7 @@ pub fn sync(bk: &Backend, new_since: Option, initial: bool) -> Result<() thread::sleep(time::Duration::from_secs(10)); tx.send(BKResponse::SyncError(err)).unwrap(); - }, - timeout.as_secs() + } ); Ok(()) diff --git a/fractal-matrix-api/src/backend/user.rs b/fractal-matrix-api/src/backend/user.rs index 4d95ad57..293aa2bc 100644 --- a/fractal-matrix-api/src/backend/user.rs +++ b/fractal-matrix-api/src/backend/user.rs @@ -6,7 +6,6 @@ use std::io::prelude::*; use crate::backend::types::BKResponse; use crate::backend::types::Backend; use crate::error::Error; -use crate::globals; use crate::util::encode_uid; use crate::util::get_user_avatar; use crate::util::get_user_avatar_img; @@ -496,8 +495,7 @@ pub fn set_user_avatar(bk: &Backend, avatar: String) -> Result<(), Error> { &url, &attrs, |_| tx.send(BKResponse::SetUserAvatar(avatar)).unwrap(), - |err| tx.send(BKResponse::SetUserAvatarError(err)).unwrap(), - 0 + |err| tx.send(BKResponse::SetUserAvatarError(err)).unwrap() ); } }; diff --git a/fractal-matrix-api/src/util.rs b/fractal-matrix-api/src/util.rs index 05fad2ee..1d9f9bef 100644 --- a/fractal-matrix-api/src/util.rs +++ b/fractal-matrix-api/src/util.rs @@ -127,9 +127,9 @@ macro_rules! put { #[macro_export] macro_rules! query { - ($method: expr, $url: expr, $attrs: expr, $okcb: expr, $errcb: expr, $timeout: expr) => { + ($method: expr, $url: expr, $attrs: expr, $okcb: expr, $errcb: expr) => { thread::spawn(move || { - let js = json_q($method, $url, $attrs, $timeout); + let js = json_q($method, $url, $attrs); match js { Ok(r) => $okcb(r), @@ -177,7 +177,7 @@ pub fn get_prev_batch_from( let path = format!("rooms/{}/context/{}", roomid, evid); let url = client_url(baseu, &path, params)?; - let r = json_q("get", &url, &json!(null), globals::TIMEOUT)?; + let r = json_q("get", &url, &json!(null))?; let prev_batch = r["start"].to_string().trim_matches('"').to_string(); Ok(prev_batch) @@ -218,7 +218,7 @@ pub fn get_room_media_list( let path = format!("rooms/{}/messages", roomid); let url = client_url(baseu, &path, ¶ms)?; - let r = json_q("get", &url, &json!(null), globals::TIMEOUT)?; + let r = json_q("get", &url, &json!(null))?; let array = r["chunk"].as_array(); let prev_batch = r["end"].to_string().trim_matches('"').to_string(); if array.is_none() || array.unwrap().is_empty() { @@ -348,12 +348,7 @@ pub fn download_file(url: &str, fname: String, dest: Option<&str>) -> Result Result { +pub fn json_q(method: &str, url: &Url, attrs: &JsonValue) -> Result { let mut conn = match method { "post" => HTTP_CLIENT.post(url.as_str()), "put" => HTTP_CLIENT.put(url.as_str()), @@ -398,7 +393,7 @@ pub fn get_user_avatar(baseu: &Url, userid: &str) -> Result<(String, String), Er let url = client_url(baseu, &format!("profile/{}", encode_uid(userid)), &[])?; let attrs = json!(null); - match json_q("get", &url, &attrs, globals::TIMEOUT) { + match json_q("get", &url, &attrs) { Ok(js) => { let name = match js["displayname"].as_str() { Some(n) if n.is_empty() => userid.to_string(),