diff --git a/Cargo.lock b/Cargo.lock index 04af011..2e12908 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -455,7 +455,7 @@ dependencies = [ [[package]] name = "discoursio-presence" -version = "0.2.16" +version = "0.2.19" dependencies = [ "actix-web", "futures", diff --git a/Cargo.toml b/Cargo.toml index 365b69e..9e647f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "discoursio-presence" -version = "0.2.16" +version = "0.2.19" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/data.rs b/src/data.rs index 2fad83d..bf5bfd2 100644 --- a/src/data.rs +++ b/src/data.rs @@ -7,7 +7,6 @@ use std::error::Error; use crate::SSEMessageData; - async fn get_author_id(user: &str) -> Result> { let api_base = env::var("API_BASE")?; let query_name = "get_author_id"; @@ -46,12 +45,10 @@ async fn get_author_id(user: &str) -> Result> { println!("Author ID retrieved: {}", id); Ok(id as i32) } - None => { - Err(Box::new(std::io::Error::new( - std::io::ErrorKind::Other, - "No author ID found in the response", - ))) - } + None => Err(Box::new(std::io::Error::new( + std::io::ErrorKind::Other, + "No author ID found in the response", + ))), } } else { Err(Box::new(std::io::Error::new( @@ -61,7 +58,6 @@ async fn get_author_id(user: &str) -> Result> { } } - pub async fn get_id_by_token(token: &str) -> Result> { let auth_api_base = env::var("AUTH_URL")?; let query_name = "validate_jwt_token"; @@ -97,7 +93,8 @@ pub async fn get_id_by_token(token: &str) -> Result> { .and_then(|data| data.get(query_name)) .and_then(|query| query.get("claims")) .and_then(|claims| claims.get("sub")) - .and_then(|id| id.as_str()); + .and_then(|id| id.as_str()) + .map(|id| id.trim()); match user_id { Some(id) => { @@ -154,7 +151,10 @@ async fn get_shout_followers(shout_id: &str) -> Result, Box> println!("Request failed with status: {}", response.status()); Err(Box::new(std::io::Error::new( std::io::ErrorKind::Other, - format!("[get_shout_followers] Request failed with status: {}", response.status()), + format!( + "[get_shout_followers] Request failed with status: {}", + response.status() + ), ))) } } @@ -172,9 +172,9 @@ pub async fn is_fitting( } else if message_data.entity == "shout" { // payload is Shout - // TODO: check all community subscribers if no then - // TODO: check all topics subscribers if no then - // TODO: check all authors subscribers + // TODO: check all shout.communities subscribers if no then + // TODO: check all shout.topics subscribers if no then + // TODO: check all shout.authors subscribers ??? Ok(true) } else if message_data.entity == "chat" { @@ -186,7 +186,7 @@ pub async fn is_fitting( } else if message_data.entity == "follower" { // payload is Author Ok(true) - }else { + } else { eprintln!("[data] unknown entity"); eprintln!("{:?}", message_data); Ok(false)