diff --git a/src/lib.rs b/src/lib.rs index e19b0a1..eec647a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,9 +7,7 @@ use config::Config; mod mastodon; pub use mastodon::register; -use mastodon::{ - associate_urls, decode_urls, get_mastodon_token, replace_alt_services, twitter_mentions, -}; +use mastodon::*; mod twitter; use twitter::*; @@ -94,19 +92,6 @@ pub async fn run(config: Config) { for tweet in &feed { info!("Treating Tweet {} inside feed", tweet.id); - let lconn = task_conn.lock().await; - // initiate the toot_reply_id var and retrieve the corresponding toot_id - let toot_reply_id: Option = tweet.in_reply_to_user_id.and_then(|_| { - read_state( - &lconn, - &mastodon_config.twitter_screen_name, - tweet.in_reply_to_status_id, - ) - .unwrap_or(None) - .map(|s| s.toot_id) - }); - drop(lconn); - // basic toot text let mut status_text = tweet.text.clone(); @@ -150,9 +135,17 @@ pub async fn run(config: Config) { status_builder.status(status_text).media_ids(status_medias); - // theard if necessary - if let Some(i) = toot_reply_id { - status_builder.in_reply_to(&i); + // thread if necessary + if tweet.in_reply_to_user_id.is_some() { + let lconn = task_conn.lock().await; + if let Ok(Some(r)) = read_state( + &lconn, + &mastodon_config.twitter_screen_name, + tweet.in_reply_to_status_id, + ) { + status_builder.in_reply_to(&r.toot_id); + } + drop(lconn); } // language if any