fix: persist note_extensions on AP Update activity
on_update was discarding custom fields (posterUrl, movieTitle, etc), so remote notes from movies-diary lost posters after Update delivery.
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -280,6 +280,7 @@ dependencies = [
|
|||||||
"domain",
|
"domain",
|
||||||
"futures",
|
"futures",
|
||||||
"hex",
|
"hex",
|
||||||
|
"serde_json",
|
||||||
"sha2",
|
"sha2",
|
||||||
"thiserror 2.0.18",
|
"thiserror 2.0.18",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|||||||
@@ -210,11 +210,11 @@ impl ApObjectHandler for ThoughtsObjectHandler {
|
|||||||
let obj_type = object.get("type").and_then(|v| v.as_str()).unwrap_or("");
|
let obj_type = object.get("type").and_then(|v| v.as_str()).unwrap_or("");
|
||||||
match obj_type {
|
match obj_type {
|
||||||
"Note" | "Article" | "Page" => {
|
"Note" | "Article" | "Page" => {
|
||||||
let Some((note, _)) = ThoughtNote::try_from_ap(object) else {
|
let Some((note, note_extensions)) = ThoughtNote::try_from_ap(object) else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
self.repo
|
self.repo
|
||||||
.apply_note_update(ap_id.as_str(), ¬e.content)
|
.apply_note_update(ap_id.as_str(), ¬e.content, note_extensions)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!("{e}"))
|
.map_err(|e| anyhow!("{e}"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,12 @@ pub trait ActivityPubRepository: Send + Sync {
|
|||||||
async fn accept_note(&self, input: AcceptNoteInput<'_>) -> Result<ThoughtId, DomainError>;
|
async fn accept_note(&self, input: AcceptNoteInput<'_>) -> Result<ThoughtId, DomainError>;
|
||||||
|
|
||||||
/// Apply an Update to a previously accepted remote Note.
|
/// Apply an Update to a previously accepted remote Note.
|
||||||
async fn apply_note_update(&self, ap_id: &str, new_content: &str) -> Result<(), DomainError>;
|
async fn apply_note_update(
|
||||||
|
&self,
|
||||||
|
ap_id: &str,
|
||||||
|
new_content: &str,
|
||||||
|
note_extensions: Option<serde_json::Value>,
|
||||||
|
) -> Result<(), DomainError>;
|
||||||
|
|
||||||
/// Remove a specific remote Note (Delete activity). Only touches
|
/// Remove a specific remote Note (Delete activity). Only touches
|
||||||
/// remotely-originated thoughts.
|
/// remotely-originated thoughts.
|
||||||
|
|||||||
@@ -270,13 +270,19 @@ impl ActivityPubRepository for PgActivityPubRepository {
|
|||||||
Ok(ThoughtId::from_uuid(row.0))
|
Ok(ThoughtId::from_uuid(row.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn apply_note_update(&self, ap_id: &str, new_content: &str) -> Result<(), DomainError> {
|
async fn apply_note_update(
|
||||||
|
&self,
|
||||||
|
ap_id: &str,
|
||||||
|
new_content: &str,
|
||||||
|
note_extensions: Option<serde_json::Value>,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
let capped: String = new_content.chars().take(MAX_REMOTE_CONTENT_CHARS).collect();
|
let capped: String = new_content.chars().take(MAX_REMOTE_CONTENT_CHARS).collect();
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"UPDATE thoughts SET content=$2,updated_at=NOW() WHERE ap_id=$1 AND local=false",
|
"UPDATE thoughts SET content=$2,note_extensions=$3,updated_at=NOW() WHERE ap_id=$1 AND local=false",
|
||||||
)
|
)
|
||||||
.bind(ap_id)
|
.bind(ap_id)
|
||||||
.bind(&capped)
|
.bind(&capped)
|
||||||
|
.bind(¬e_extensions)
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
.await
|
.await
|
||||||
.into_domain()
|
.into_domain()
|
||||||
|
|||||||
@@ -21,3 +21,4 @@ futures = { workspace = true }
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { workspace = true, features = ["full"] }
|
tokio = { workspace = true, features = ["full"] }
|
||||||
domain = { workspace = true, features = ["test-helpers"] }
|
domain = { workspace = true, features = ["test-helpers"] }
|
||||||
|
serde_json = { workspace = true }
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ impl ActivityPubRepository for TestApRepo {
|
|||||||
) -> Result<ThoughtId, DomainError> {
|
) -> Result<ThoughtId, DomainError> {
|
||||||
Ok(ThoughtId::from_uuid(uuid::Uuid::new_v4()))
|
Ok(ThoughtId::from_uuid(uuid::Uuid::new_v4()))
|
||||||
}
|
}
|
||||||
async fn apply_note_update(&self, _ap_id: &str, _new_content: &str) -> Result<(), DomainError> {
|
async fn apply_note_update(&self, _ap_id: &str, _new_content: &str, _: Option<serde_json::Value>) -> Result<(), DomainError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn retract_note(&self, _ap_id: &str) -> Result<(), DomainError> {
|
async fn retract_note(&self, _ap_id: &str) -> Result<(), DomainError> {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ impl ActivityPubRepository for NoOpApRepo {
|
|||||||
) -> Result<ThoughtId, DomainError> {
|
) -> Result<ThoughtId, DomainError> {
|
||||||
Ok(ThoughtId::from_uuid(uuid::Uuid::new_v4()))
|
Ok(ThoughtId::from_uuid(uuid::Uuid::new_v4()))
|
||||||
}
|
}
|
||||||
async fn apply_note_update(&self, _: &str, _: &str) -> Result<(), DomainError> {
|
async fn apply_note_update(&self, _: &str, _: &str, _: Option<serde_json::Value>) -> Result<(), DomainError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn retract_note(&self, _: &str) -> Result<(), DomainError> {
|
async fn retract_note(&self, _: &str) -> Result<(), DomainError> {
|
||||||
|
|||||||
Reference in New Issue
Block a user