From 5cd7409491a3a4ae2f58960f2b137fb83050da54 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Wed, 13 May 2026 01:24:34 +0200 Subject: [PATCH] feat(postgres): persist outbox_url, implement get_following_outbox_url --- .../adapters/postgres-federation/src/lib.rs | 23 +++++++++++++++---- .../0018_remote_actor_outbox_url.sql | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 crates/adapters/postgres/migrations/0018_remote_actor_outbox_url.sql diff --git a/crates/adapters/postgres-federation/src/lib.rs b/crates/adapters/postgres-federation/src/lib.rs index d47736b..824734e 100644 --- a/crates/adapters/postgres-federation/src/lib.rs +++ b/crates/adapters/postgres-federation/src/lib.rs @@ -236,14 +236,15 @@ impl FederationRepository for PostgresFederationRepository { let now = Utc::now().naive_utc(); let fetched_at = datetime_to_str(&now); sqlx::query( - "INSERT INTO ap_remote_actors (url, handle, inbox_url, shared_inbox_url, display_name, avatar_url, fetched_at) - VALUES ($1, $2, $3, $4, $5, $6, $7::timestamptz) + "INSERT INTO ap_remote_actors (url, handle, inbox_url, shared_inbox_url, display_name, avatar_url, outbox_url, fetched_at) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8::timestamptz) ON CONFLICT(url) DO UPDATE SET handle = EXCLUDED.handle, inbox_url = EXCLUDED.inbox_url, shared_inbox_url = EXCLUDED.shared_inbox_url, display_name = EXCLUDED.display_name, avatar_url = EXCLUDED.avatar_url, + outbox_url = COALESCE(EXCLUDED.outbox_url, ap_remote_actors.outbox_url), fetched_at = EXCLUDED.fetched_at", ) .bind(&actor.url) @@ -252,6 +253,7 @@ impl FederationRepository for PostgresFederationRepository { .bind(&actor.shared_inbox_url) .bind(&actor.display_name) .bind(&actor.avatar_url) + .bind(&actor.outbox_url) .bind(&fetched_at) .execute(&self.pool) .await?; @@ -360,10 +362,21 @@ impl FederationRepository for PostgresFederationRepository { async fn get_following_outbox_url( &self, - _local_user_id: uuid::Uuid, - _remote_actor_url: &str, + local_user_id: uuid::Uuid, + remote_actor_url: &str, ) -> Result> { - Ok(None) + let uid = local_user_id.to_string(); + let row: Option> = sqlx::query_scalar( + "SELECT a.outbox_url + FROM ap_following f + INNER JOIN ap_remote_actors a ON a.url = f.remote_actor_url + WHERE f.local_user_id = $1 AND f.remote_actor_url = $2", + ) + .bind(&uid) + .bind(remote_actor_url) + .fetch_optional(&self.pool) + .await?; + Ok(row.flatten()) } async fn add_announce( diff --git a/crates/adapters/postgres/migrations/0018_remote_actor_outbox_url.sql b/crates/adapters/postgres/migrations/0018_remote_actor_outbox_url.sql new file mode 100644 index 0000000..a767d7d --- /dev/null +++ b/crates/adapters/postgres/migrations/0018_remote_actor_outbox_url.sql @@ -0,0 +1 @@ +ALTER TABLE ap_remote_actors ADD COLUMN outbox_url TEXT;