2023-08-18 20:11:49 +01:00
|
|
|
mod database;
|
|
|
|
mod frames;
|
|
|
|
mod streaming;
|
|
|
|
|
2023-08-31 08:42:56 +01:00
|
|
|
use crate::database::ConnectionPool;
|
|
|
|
use anyhow::Result;
|
|
|
|
use async_trait::async_trait;
|
2023-08-31 14:11:14 +01:00
|
|
|
use database::{insert_post, insert_profile_if_it_doesnt_exist};
|
2023-08-31 08:42:56 +01:00
|
|
|
|
|
|
|
use streaming::{Operation, OperationProcessor};
|
|
|
|
|
|
|
|
use crate::database::make_connection_pool;
|
|
|
|
use crate::streaming::start_processing_operations_with;
|
2023-08-18 20:11:49 +01:00
|
|
|
|
|
|
|
#[tokio::main]
|
2023-08-31 08:42:56 +01:00
|
|
|
async fn main() -> Result<()> {
|
|
|
|
let db_connection_pool = make_connection_pool().await?;
|
|
|
|
|
|
|
|
// FIXME: This struct shouldn't really exist, but I couldn't find a way to replace
|
|
|
|
// this whole nonsense with a closure, which is what this whole thing should be in
|
|
|
|
// first place.
|
|
|
|
let post_saver = PostSaver { db_connection_pool };
|
|
|
|
|
|
|
|
start_processing_operations_with(post_saver).await?;
|
2023-08-18 20:11:49 +01:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2023-08-31 08:42:56 +01:00
|
|
|
|
|
|
|
struct PostSaver {
|
|
|
|
db_connection_pool: ConnectionPool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl OperationProcessor for PostSaver {
|
|
|
|
async fn process_operation(&self, operation: &Operation) -> Result<()> {
|
|
|
|
match operation {
|
|
|
|
Operation::CreatePost {
|
|
|
|
author_did,
|
|
|
|
cid,
|
|
|
|
uri,
|
|
|
|
languages,
|
|
|
|
text,
|
|
|
|
} => {
|
|
|
|
// TODO: Configure this via env vars
|
|
|
|
if !languages.contains("ru") {
|
2023-08-31 08:56:14 +01:00
|
|
|
return Ok(());
|
2023-08-31 08:42:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// BlueSky gets confused a lot about Russian vs Ukrainian, so skip posts
|
|
|
|
// that may be in Ukrainian regardless of whether Russian is in the list
|
|
|
|
// TODO: Configure this via env vars
|
|
|
|
if languages.contains("uk") {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("received insertable post from {author_did}: {text}");
|
|
|
|
|
2023-08-31 14:11:14 +01:00
|
|
|
insert_profile_if_it_doesnt_exist(&self.db_connection_pool, &author_did).await?;
|
2023-08-31 08:42:56 +01:00
|
|
|
insert_post(&self.db_connection_pool, &author_did, &cid, &uri).await?;
|
|
|
|
}
|
2023-08-31 14:11:14 +01:00
|
|
|
Operation::DeletePost { uri } => {
|
|
|
|
println!("received a post do delete: {uri}");
|
|
|
|
|
2023-08-31 08:42:56 +01:00
|
|
|
// TODO: Delete posts from db
|
|
|
|
// delete_post(&self.db_connection_pool, &uri).await?;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|