diff --git a/apps/mtxchat/src/api.rs b/apps/mtxchat/src/api.rs index 3426b8c45..928450532 100644 --- a/apps/mtxchat/src/api.rs +++ b/apps/mtxchat/src/api.rs @@ -1,5 +1,3 @@ -use rkyv::{Archive, Deserialize, Serialize}; - #[allow(dead_code)] pub(crate) const SERVER_NAME_MTXCHAT: &str = "_Matrix chat_"; @@ -32,4 +30,3 @@ pub struct Msg { pub sender: Option, pub ts: Option, } - diff --git a/apps/mtxchat/src/web.rs b/apps/mtxchat/src/web.rs index 9d78290ee..62ffa0862 100644 --- a/apps/mtxchat/src/web.rs +++ b/apps/mtxchat/src/web.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use ureq::Agent; use ureq::serde_json::{Map, Value}; +use ureq::Agent; use crate::{url, Msg}; @@ -62,17 +62,27 @@ pub fn get_json(url: &str, agent: &mut Agent) -> Result Result { +pub fn get_json_auth( + url: &str, + token: &str, + agent: &mut Agent, +) -> Result { let mut authorization = String::from(BEARER); authorization.push_str(token); - agent.get(&url) + agent + .get(&url) .set(ACCEPT, ACCEPT_JSON) .set(AUTHORIZATION, &authorization) .call() } -pub fn post_string(url: &str, request_body: &str, agent: &mut Agent) -> Result { - agent.post(&url) +pub fn post_string( + url: &str, + request_body: &str, + agent: &mut Agent, +) -> Result { + agent + .post(&url) .set(ACCEPT, ACCEPT_JSON) .send_string(request_body) } @@ -85,7 +95,8 @@ pub fn post_string_auth( ) -> Result { let mut authorization = String::from(BEARER); authorization.push_str(token); - agent.post(&url) + agent + .post(&url) .set(ACCEPT, ACCEPT_JSON) .set(AUTHORIZATION, &authorization) .send_string(request_body) @@ -99,7 +110,8 @@ pub fn put_string_auth( ) -> Result { let mut authorization = String::from(BEARER); authorization.push_str(token); - agent.put(&url) + agent + .put(&url) .set(ACCEPT, ACCEPT_JSON) .set(AUTHORIZATION, &authorization) .send_string(request_body) @@ -175,7 +187,12 @@ impl AuthRequest { } // fn authenticate_user() -> Result { -pub fn authenticate_user(server: &str, user: &str, password: &str, agent: &mut Agent) -> Option { +pub fn authenticate_user( + server: &str, + user: &str, + password: &str, + agent: &mut Agent, +) -> Option { let mut maybe_token: Option = None; let mut url = String::from(server); url.push_str("/_matrix/client/r0/login"); @@ -192,7 +209,12 @@ pub fn authenticate_user(server: &str, user: &str, password: &str, agent: &mut A maybe_token } -pub fn get_room_id(server: &str, room_server: &str, token: &str, agent: &mut Agent) -> Option { +pub fn get_room_id( + server: &str, + room_server: &str, + token: &str, + agent: &mut Agent, +) -> Option { let room_encoded = url::encode(room_server); let mut url = String::from(server); url.push_str("/_matrix/client/v3/directory/room/"); @@ -305,7 +327,13 @@ impl FilterRequest { } } -pub fn get_filter(user: &str, server: &str, room_id: &str, token: &str, agent: &mut Agent) -> Option { +pub fn get_filter( + user: &str, + server: &str, + room_id: &str, + token: &str, + agent: &mut Agent, +) -> Option { let user_encoded = url::encode(user); let mut url = String::from(server); url.push_str("/_matrix/client/v3/user/"); @@ -375,7 +403,7 @@ fn get_messages(body: Map, room_id: &str) -> Vec { pub fn client_sync( server: &str, filter: &str, - since: &str, + since: Option<&str>, timeout: i32, room_id: &str, token: &str, @@ -387,7 +415,7 @@ pub fn client_sync( url.push_str(filter); url.push_str("&timeout="); url.push_str(&timeout.to_string()); - if since.len() > 0 { + if let Some(since) = since { url.push_str("&since="); url.push_str(since); } @@ -423,7 +451,14 @@ impl MessageRequest { } } -pub fn send_message(server: &str, room_id: &str, text: &str, txn_id: &str, token: &str, agent: &mut Agent) -> bool { +pub fn send_message( + server: &str, + room_id: &str, + text: &str, + txn_id: &str, + token: &str, + agent: &mut Agent, +) -> bool { log::info!("heap usage: {}", crate::heap_usage()); let room_id_encoded = url::encode(room_id); let mut url = String::from(server); diff --git a/libs/chat/src/api.rs b/libs/chat/src/api.rs index 587b36bbe..582c43c40 100644 --- a/libs/chat/src/api.rs +++ b/libs/chat/src/api.rs @@ -105,8 +105,6 @@ pub enum PostFlag { Hidden, } - - #[derive( Archive, Serialize,