AP -> Versia note fed

This commit is contained in:
April John 2024-11-22 22:08:25 +01:00
parent 012079cd9b
commit d275165b97
3 changed files with 67 additions and 8 deletions

View file

@ -1,4 +1,4 @@
use activitypub_federation::{fetch::object_id::ObjectId, http_signatures::generate_actor_keypair};
use activitypub_federation::{fetch::object_id::ObjectId, http_signatures::generate_actor_keypair, traits::Object};
use activitystreams_kinds::public;
use anyhow::{anyhow, Ok};
use async_recursion::async_recursion;
@ -51,10 +51,22 @@ pub async fn versia_post_from_db(
//"unlisted" => super::objects::VisibilityType::Unlisted,
_ => Some("public".to_string()),
};
//let mut mentions = Vec::new();
//for obj in post.tag.clone() {
// mentions.push(obj.href.clone());
//}
let mut mentions = Vec::new();
let ap_obj = serde_json::from_str::<crate::objects::post::Note>(post.ap_json.unwrap().as_str())?;
let req_data = data.to_request_data();
for obj in ap_obj.tag.clone() {
let option = user::Model::read_from_id(obj.href, &req_data).await.unwrap();
if let Some(model) = option {
let user = versia_user_from_db(model).await?;
let domain = user.inbox.domain();
if domain.is_none() || domain.is_some_and(|domain| LYSAND_DOMAIN.as_str() != domain) {
continue;
}
mentions.push(user.inbox);
}
}
let mut content = ContentFormat::default();
content.x.insert(
"text/html".to_string(),

View file

@ -33,6 +33,7 @@ pub async fn inbox_entry(json: &str) -> Result<()> {
match json_type.as_str() {
Some("Note") => {
let note: super::objects::Note = serde_json::from_str(json)?;
federate_inbox(note).await?;
}
Some("Follow") => {
let follow_req: super::objects::Follow = serde_json::from_str(json)?;
@ -130,3 +131,9 @@ async fn follow_request(follow: super::objects::Follow) -> Result<()> {
Ok(())
}
async fn federate_inbox(note: super::objects::Note) -> Result<()> {
Ok(())
}