feat: BoostRemoved → Undo(Announce) fan-out via OutboundFederationPort

This commit is contained in:
2026-05-14 14:10:11 +02:00
parent eaf079069f
commit b0b3c6a59b
3 changed files with 146 additions and 4 deletions

View File

@@ -58,6 +58,17 @@ impl FederationEventService {
self.ap.broadcast_announce(user_id, &object_ap_id).await
}
DomainEvent::BoostRemoved { user_id, thought_id } => {
let thought = match self.thoughts.find_by_id(thought_id).await? {
Some(t) => t,
None => return Ok(()),
};
let object_ap_id = thought.ap_id.clone().unwrap_or_else(|| {
format!("{}/thoughts/{}", self.base_url, thought_id)
});
self.ap.broadcast_undo_announce(user_id, &object_ap_id).await
}
_ => Ok(()),
}
}
@@ -82,10 +93,11 @@ mod tests {
#[derive(Default)]
struct SpyPort {
created: Mutex<Vec<ThoughtId>>,
deleted: Mutex<Vec<String>>,
updated: Mutex<Vec<ThoughtId>>,
announced: Mutex<Vec<String>>,
created: Mutex<Vec<ThoughtId>>,
deleted: Mutex<Vec<String>>,
updated: Mutex<Vec<ThoughtId>>,
announced: Mutex<Vec<String>>,
undo_announced: Mutex<Vec<String>>,
}
#[async_trait]
@@ -106,6 +118,10 @@ mod tests {
self.announced.lock().unwrap().push(ap_id.to_string());
Ok(())
}
async fn broadcast_undo_announce(&self, _: &UserId, ap_id: &str) -> Result<(), DomainError> {
self.undo_announced.lock().unwrap().push(ap_id.to_string());
Ok(())
}
}
fn alice() -> User {
@@ -354,6 +370,50 @@ mod tests {
assert!(spy.created.lock().unwrap().is_empty());
}
#[tokio::test]
async fn boost_removed_sends_undo_announce_for_local_thought() {
let store = TestStore::default();
let alice = alice();
let thought = local_thought(alice.id.clone()); // ap_id = None → constructed URL
store.thoughts.lock().unwrap().push(thought.clone());
let spy = Arc::new(SpyPort::default());
svc(&store, spy.clone())
.process(&DomainEvent::BoostRemoved {
user_id: alice.id.clone(),
thought_id: thought.id.clone(),
})
.await
.unwrap();
let undo_announced = spy.undo_announced.lock().unwrap();
assert_eq!(undo_announced.len(), 1);
assert_eq!(undo_announced[0], format!("https://example.com/thoughts/{}", thought.id));
}
#[tokio::test]
async fn boost_removed_sends_undo_announce_for_remote_thought() {
let store = TestStore::default();
let alice = alice();
let mut thought = local_thought(alice.id.clone());
thought.local = false;
thought.ap_id = Some("https://mastodon.social/users/bob/statuses/456".into());
store.thoughts.lock().unwrap().push(thought.clone());
let spy = Arc::new(SpyPort::default());
svc(&store, spy.clone())
.process(&DomainEvent::BoostRemoved {
user_id: alice.id.clone(),
thought_id: thought.id.clone(),
})
.await
.unwrap();
let undo_announced = spy.undo_announced.lock().unwrap();
assert_eq!(undo_announced.len(), 1);
assert_eq!(undo_announced[0], "https://mastodon.social/users/bob/statuses/456");
}
#[tokio::test]
async fn thought_updated_does_not_broadcast_if_user_missing() {
let store = TestStore::default();