fix(ap): add url field to Note, handle Delete(actor) and Tombstone objects
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 9m12s
test / unit (pull_request) Successful in 15m52s
test / integration (pull_request) Failing after 17m10s

This commit is contained in:
2026-05-14 16:47:17 +02:00
parent 458feebcdd
commit d3b7ecad15
3 changed files with 35 additions and 4 deletions

View File

@@ -337,7 +337,7 @@ pub struct DeleteActivity {
#[serde(rename = "type", default)]
pub(crate) kind: DeleteType,
pub(crate) actor: ObjectId<DbActor>,
pub(crate) object: Url,
pub(crate) object: serde_json::Value,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub(crate) to: Vec<String>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
@@ -368,11 +368,38 @@ impl Activity for DeleteActivity {
return Ok(());
}
let actor_url = self.actor.inner().clone();
// Extract object URL — handles plain string and Tombstone {"id":"...","type":"Tombstone"}
let object_url_str = match &self.object {
serde_json::Value::String(s) => s.clone(),
serde_json::Value::Object(o) => o
.get("id")
.and_then(|v| v.as_str())
.map(|s| s.to_string())
.unwrap_or_default(),
_ => String::new(),
};
let Ok(object_url) = Url::parse(&object_url_str) else {
tracing::warn!(actor = %actor_url, "Delete activity has unparseable object, ignoring");
return Ok(());
};
// Actor self-deletion: Mastodon sends Delete(actor_url) when an account is deleted.
if object_url == *self.actor.inner() {
data.object_handler
.on_actor_removed(&actor_url)
.await
.map_err(|e| Error::from(anyhow::anyhow!(e)))?;
tracing::info!(actor = %actor_url, "received Delete(actor) — remote account deleted");
return Ok(());
}
// Normal note deletion.
data.object_handler
.on_delete(&self.object, &actor_url)
.on_delete(&object_url, &actor_url)
.await
.map_err(|e| Error::from(anyhow::anyhow!(e)))?;
tracing::info!(object = %self.object, "received delete activity");
tracing::info!(object = %object_url, "received Delete(note)");
Ok(())
}
}

View File

@@ -39,6 +39,7 @@ fn thought_note_json(
let mut note = serde_json::json!({
"type": "Note",
"id": ap_id.to_string(),
"url": ap_id.to_string(),
"attributedTo": local_actor.ap_id.to_string(),
"content": thought.content.as_str(),
"published": thought.created_at.to_rfc3339(),
@@ -653,7 +654,7 @@ impl ActivityPubService {
id: delete_id,
kind: Default::default(),
actor: ObjectId::from(local_actor.ap_id.clone()),
object: ap_id,
object: serde_json::json!(ap_id.to_string()),
to: vec![crate::urls::AS_PUBLIC.to_string()],
cc: vec![local_actor.followers_url.to_string()],
};

View File

@@ -11,6 +11,7 @@ pub struct ThoughtNote {
#[serde(rename = "type")]
pub kind: NoteType,
pub id: Url,
pub url: Url, // Mastodon uses this as the clickable link
pub attributed_to: Url,
pub content: String,
pub published: DateTime<Utc>,
@@ -39,6 +40,7 @@ impl ThoughtNote {
) -> Self {
Self {
kind: Default::default(),
url: id.clone(),
id,
attributed_to: actor_url,
content,
@@ -71,5 +73,6 @@ mod tests {
let json = serde_json::to_string(&note).unwrap();
assert!(json.contains(AS_PUBLIC));
assert!(json.contains("Hello world"));
assert!(json.contains("\"url\""));
}
}