fix: respect activity_type in set_relay_status and include activate_relay #14

Merged
hodlbod merged 1 commits from userAdityaa/caravel:activity-logging into master 2026-04-15 20:39:06 +00:00
4 changed files with 25 additions and 13 deletions
+1 -1
View File
@@ -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)`
-3
View File
@@ -901,10 +901,7 @@ mod tests {
&unknown_status_paid
));
}
}
#[cfg(test)]
mod tests {
use super::*;
use sqlx::SqlitePool;
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
+1 -2
View File
@@ -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);
+23 -7
View File
@@ -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<String> {
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"
)
}