From 9543fe939f269fddfb9404d2aa2cc2bf389805ee Mon Sep 17 00:00:00 2001 From: April John Date: Mon, 3 Feb 2025 13:56:29 +0100 Subject: [PATCH] arson --- src/versia/inbox.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/versia/inbox.rs b/src/versia/inbox.rs index 13f6eb6..082cff7 100644 --- a/src/versia/inbox.rs +++ b/src/versia/inbox.rs @@ -15,7 +15,7 @@ use serde::Deserialize; use url::Url; use super::{ - conversion::{db_user_from_url, receive_versia_note, versia_user_from_db}, + conversion::{db_user_from_url, fetch_user_from_url, receive_versia_note, versia_user_from_db}, http::{versia_url_to_user, versia_url_to_user_and_model}, }; @@ -137,7 +137,7 @@ async fn federate_inbox(note: super::objects::Note) -> Result<()> { tokio::spawn(async move { let conf = FEDERATION_CONFIG.get().unwrap(); - let inbox = get_inbox_vec(&ap_note); + let inbox = get_inbox_vec(&ap_note).await; let res = CreatePost::sends(ap_note, note, inbox, &conf.to_request_data()).await; if let Err(e) = res { @@ -148,18 +148,33 @@ async fn federate_inbox(note: super::objects::Note) -> Result<()> { Ok(()) } -fn get_inbox_vec(ap_note: &crate::objects::post::Note) -> Vec { +async fn get_inbox_vec(ap_note: &crate::objects::post::Note) -> Vec { + let mut inbox_users: Vec = Vec::new(); let mut inbox: Vec = Vec::new(); for entry in ap_note.to.clone() { if entry.to_string().eq_ignore_ascii_case(public().to_string().as_str()) { let (_, mentions) = ap_note.to.split_at(2); - inbox.append(&mut mentions.to_vec()); + inbox_users.append(&mut mentions.to_vec()); } else { let (_, mentions) = ap_note.to.split_at(1); - inbox.append(&mut mentions.to_vec()); + inbox_users.append(&mut mentions.to_vec()); } } + inbox_users.dedup(); + + + let conf = FEDERATION_CONFIG.get().unwrap(); + let data = &conf.to_request_data(); + + for user in inbox_users { + let ap_user = ObjectId::::from(user).dereference(data) + .await.unwrap(); + inbox.push(Url::parse(&ap_user.inbox).unwrap()); + } + + inbox.dedup(); + inbox } \ No newline at end of file