refactor: eliminate response tweet earlier

This commit is contained in:
VC
2022-11-18 10:51:04 +01:00
parent fe3745d91f
commit 93a27deae8
2 changed files with 22 additions and 29 deletions

View File

@@ -64,8 +64,8 @@ pub async fn run(config: Config) {
.map(|r| r.tweet_id);
drop(lconn);
// get user timeline feed (Vec<tweet>)
let mut feed = get_user_timeline(
// get reversed, curated user timeline
let feed = get_user_timeline(
&mastodon_config.twitter_screen_name,
&token,
last_tweet_id,
@@ -73,41 +73,23 @@ pub async fn run(config: Config) {
)
.await?;
// empty feed -> exiting
if feed.is_empty() {
info!("Nothing to retrieve since last time, exiting…");
return Ok(());
}
// get Mastodon instance
let mastodon = get_mastodon_token(&mastodon_config);
// order needs to be chronological
feed.reverse();
for tweet in &feed {
info!("Treating Tweet {} inside feed", tweet.id);
// initiate the toot_reply_id var
let mut toot_reply_id: Option<String> = None;
// determine if the tweet is part of a thread (response to self) or a standard response
if let Some(r) = &tweet.in_reply_to_screen_name {
if r.to_lowercase() != mastodon_config.twitter_screen_name.to_lowercase() {
// we are responding not threading
info!("Tweet is a direct response, skipping");
continue;
}
info!("Tweet is a thread");
// get the corresponding toot id
let lconn = task_conn.lock().await;
toot_reply_id = read_state(
let lconn = task_conn.lock().await;
// initiate the toot_reply_id var and retrieve the corresponding toot_id
let toot_reply_id: Option<String> = 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);
};
.map(|s| s.toot_id)
});
drop(lconn);
// build basic status by just yielding text and dereferencing contained urls
let mut status_text = build_basic_status(tweet);