From 62dde4b2ac01b82bac424a93406d43cca2e6870d Mon Sep 17 00:00:00 2001 From: userAdityaa Date: Wed, 15 Apr 2026 15:18:27 +0545 Subject: [PATCH] fix: respect activity_type in set_relay_status and include activate_relay --- backend/spec/infra.md | 2 +- backend/src/billing.rs | 3 --- backend/src/command.rs | 3 +-- backend/src/infra.rs | 30 +++++++++++++++++++++++------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/backend/spec/infra.md b/backend/spec/infra.md index 94d7204..b4beff8 100644 --- a/backend/spec/infra.md +++ b/backend/spec/infra.md @@ -19,7 +19,7 @@ Members: ## `async fn handle_activity(&self, activity: &Activity)` -- For `create_relay`, `update_relay`, or `deactivate_relay` activity, calls `sync_and_report`. +- For `create_relay`, `update_relay`, `activate_relay`, or `deactivate_relay` activity, calls `sync_and_report`. - All other activity types are ignored (e.g. `fail_relay_sync`, `complete_relay_sync`). ## `async fn sync_and_report(&self, relay: &Relay, is_new: bool)` diff --git a/backend/src/billing.rs b/backend/src/billing.rs index a5f60fa..4f3a7f5 100644 --- a/backend/src/billing.rs +++ b/backend/src/billing.rs @@ -901,10 +901,7 @@ mod tests { &unknown_status_paid )); } -} -#[cfg(test)] -mod tests { use super::*; use sqlx::SqlitePool; use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions}; diff --git a/backend/src/command.rs b/backend/src/command.rs index 031977e..e75100a 100644 --- a/backend/src/command.rs +++ b/backend/src/command.rs @@ -209,8 +209,7 @@ impl Command { .execute(&mut *tx) .await?; - let activity = - Self::insert_activity(&mut tx, "deactivate_relay", "relay", &relay_id).await?; + let activity = Self::insert_activity(&mut tx, activity_type, "relay", relay_id).await?; tx.commit().await?; self.emit(activity); diff --git a/backend/src/infra.rs b/backend/src/infra.rs index 7cc5b04..1f7232f 100644 --- a/backend/src/infra.rs +++ b/backend/src/infra.rs @@ -56,10 +56,7 @@ impl Infra { } async fn handle_activity(&self, activity: &Activity) -> Result<()> { - let needs_sync = matches!( - activity.activity_type.as_str(), - "create_relay" | "update_relay" | "deactivate_relay" - ); + let needs_sync = should_sync_relay_activity(activity.activity_type.as_str()); if needs_sync { let Some(relay) = self.query.get_relay(&activity.resource_id).await? else { @@ -93,7 +90,9 @@ impl Infra { async fn nip98_auth(&self, url: &str, method: HttpMethod) -> Result { let keys = Keys::parse(&self.api_secret)?; let server_url = Url::parse(url)?; - let auth = HttpData::new(server_url, method).to_authorization(&keys).await?; + let auth = HttpData::new(server_url, method) + .to_authorization(&keys) + .await?; Ok(auth) } @@ -150,11 +149,21 @@ impl Infra { let response = if is_new { let url = format!("{}/relay/{}", base, relay.id); let auth = self.nip98_auth(&url, HttpMethod::POST).await?; - client.post(&url).header("Authorization", auth).json(&body).send().await? + client + .post(&url) + .header("Authorization", auth) + .json(&body) + .send() + .await? } else { let url = format!("{}/relay/{}", base, relay.id); let auth = self.nip98_auth(&url, HttpMethod::PUT).await?; - client.put(&url).header("Authorization", auth).json(&body).send().await? + client + .put(&url) + .header("Authorization", auth) + .json(&body) + .send() + .await? }; if !response.status().is_success() { @@ -165,3 +174,10 @@ impl Infra { Ok(()) } } + +fn should_sync_relay_activity(activity_type: &str) -> bool { + matches!( + activity_type, + "create_relay" | "update_relay" | "activate_relay" | "deactivate_relay" + ) +} -- 2.52.0