Merge branch 'fix_lang' into 'master'

Fix lang

See merge request veretcle/scootaloo!32
This commit is contained in:
VC
2022-11-19 16:39:05 +00:00
3 changed files with 14 additions and 7 deletions

2
Cargo.lock generated
View File

@@ -2103,7 +2103,7 @@ dependencies = [
[[package]]
name = "scootaloo"
version = "0.9.3"
version = "0.9.4"
dependencies = [
"chrono",
"clap",

View File

@@ -1,6 +1,6 @@
[package]
name = "scootaloo"
version = "0.9.3"
version = "0.9.4"
authors = ["VC <veretcle+framagit@mateu.be>"]
edition = "2021"

View File

@@ -19,14 +19,13 @@ mod state;
pub use state::{init_db, migrate_db};
use state::{read_state, write_state, TweetToToot};
use elefren::{prelude::*, status_builder::StatusBuilder};
use elefren::{prelude::*, status_builder::StatusBuilder, Language};
use futures::StreamExt;
use log::info;
use rusqlite::Connection;
use std::sync::Arc;
use tokio::{spawn, sync::Mutex};
use futures::StreamExt;
const DEFAULT_RATE_LIMIT: usize = 4;
const DEFAULT_PAGE_SIZE: i32 = 200;
@@ -57,7 +56,6 @@ pub async fn run(config: Config) {
spawn(async move {
info!("Starting treating {}", &mastodon_config.twitter_screen_name);
// retrieve the last tweet ID for the username
let lconn = task_conn.lock().await;
let last_tweet_id = read_state(&lconn, &mastodon_config.twitter_screen_name, None)?
@@ -78,6 +76,7 @@ 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<String> = tweet.in_reply_to_user_id.and_then(|_| {
@@ -106,12 +105,20 @@ 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);
}
// language if any
if let Some(l) = &tweet.lang {
if let Some(r) = Language::from_639_1(l) {
status_builder.language(r);
}
}
// can be activated for test purposes
// status_builder.visibility(elefren::status_builder::Visibility::Private);
status_builder.visibility(elefren::status_builder::Visibility::Private);
let status = status_builder.build()?;