diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-05 14:31:47 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-05 14:31:47 +0000 |
| commit | f8235b7977c673524c12a229eddb7ace6b0c2c0d (patch) | |
| tree | 1725861f36085adc7b7c3f033e67cde910fe4c75 /src/nostr | |
| parent | 8cb45487d7125a14d15c15dfc14b0804eb22ffd6 (diff) | |
purgatory: git data sync applies state and saves event
Diffstat (limited to 'src/nostr')
| -rw-r--r-- | src/nostr/builder.rs | 8 | ||||
| -rw-r--r-- | src/nostr/policy/mod.rs | 19 | ||||
| -rw-r--r-- | src/nostr/policy/state.rs | 1 |
3 files changed, 28 insertions, 0 deletions
diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs index da81e64..db2f59b 100644 --- a/src/nostr/builder.rs +++ b/src/nostr/builder.rs | |||
| @@ -74,6 +74,14 @@ impl Nip34WritePolicy { | |||
| 74 | &self.ctx.purgatory | 74 | &self.ctx.purgatory |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | /// Set the local relay for purgatory notifications. | ||
| 78 | /// | ||
| 79 | /// This must be called after the relay is created since the relay depends | ||
| 80 | /// on this policy, but purgatory sync needs the relay to notify subscribers. | ||
| 81 | pub fn set_local_relay(&self, relay: nostr_relay_builder::LocalRelay) { | ||
| 82 | self.ctx.set_local_relay(relay); | ||
| 83 | } | ||
| 84 | |||
| 77 | /// Handle repository announcement event | 85 | /// Handle repository announcement event |
| 78 | async fn handle_announcement(&self, event: &Event) -> WritePolicyResult { | 86 | async fn handle_announcement(&self, event: &Event) -> WritePolicyResult { |
| 79 | let event_id_str = event.id.to_bech32().unwrap_or_else(|_| event.id.to_hex()); | 87 | let event_id_str = event.id.to_bech32().unwrap_or_else(|_| event.id.to_hex()); |
diff --git a/src/nostr/policy/mod.rs b/src/nostr/policy/mod.rs index 2a446fe..c3c5829 100644 --- a/src/nostr/policy/mod.rs +++ b/src/nostr/policy/mod.rs | |||
| @@ -17,6 +17,7 @@ pub use state::{AlignmentResult, StatePolicy, StateResult}; | |||
| 17 | 17 | ||
| 18 | use super::SharedDatabase; | 18 | use super::SharedDatabase; |
| 19 | use crate::purgatory::Purgatory; | 19 | use crate::purgatory::Purgatory; |
| 20 | use nostr_relay_builder::LocalRelay; | ||
| 20 | use std::sync::Arc; | 21 | use std::sync::Arc; |
| 21 | 22 | ||
| 22 | /// Shared context for all sub-policies | 23 | /// Shared context for all sub-policies |
| @@ -26,6 +27,8 @@ pub struct PolicyContext { | |||
| 26 | pub database: SharedDatabase, | 27 | pub database: SharedDatabase, |
| 27 | pub git_data_path: std::path::PathBuf, | 28 | pub git_data_path: std::path::PathBuf, |
| 28 | pub purgatory: Arc<Purgatory>, | 29 | pub purgatory: Arc<Purgatory>, |
| 30 | /// Local relay for notifying WebSocket subscribers (set after relay creation) | ||
| 31 | pub local_relay: Arc<std::sync::RwLock<Option<LocalRelay>>>, | ||
| 29 | } | 32 | } |
| 30 | 33 | ||
| 31 | impl PolicyContext { | 34 | impl PolicyContext { |
| @@ -40,6 +43,22 @@ impl PolicyContext { | |||
| 40 | database, | 43 | database, |
| 41 | git_data_path: git_data_path.into(), | 44 | git_data_path: git_data_path.into(), |
| 42 | purgatory, | 45 | purgatory, |
| 46 | local_relay: Arc::new(std::sync::RwLock::new(None)), | ||
| 43 | } | 47 | } |
| 44 | } | 48 | } |
| 49 | |||
| 50 | /// Set the local relay after it's been created. | ||
| 51 | /// | ||
| 52 | /// This is called after the relay is built since the relay depends on the policy | ||
| 53 | /// but the policy needs the relay for purgatory notifications. | ||
| 54 | pub fn set_local_relay(&self, relay: LocalRelay) { | ||
| 55 | let mut guard = self.local_relay.write().unwrap(); | ||
| 56 | *guard = Some(relay); | ||
| 57 | } | ||
| 58 | |||
| 59 | /// Get a clone of the local relay if it's been set. | ||
| 60 | pub fn get_local_relay(&self) -> Option<LocalRelay> { | ||
| 61 | let guard = self.local_relay.read().unwrap(); | ||
| 62 | guard.clone() | ||
| 63 | } | ||
| 45 | } | 64 | } |
diff --git a/src/nostr/policy/state.rs b/src/nostr/policy/state.rs index 9ca3ee6..7521ef1 100644 --- a/src/nostr/policy/state.rs +++ b/src/nostr/policy/state.rs | |||
| @@ -179,6 +179,7 @@ impl StatePolicy { | |||
| 179 | state.clone(), | 179 | state.clone(), |
| 180 | self.ctx.database.clone(), | 180 | self.ctx.database.clone(), |
| 181 | Some(self.ctx.domain.clone()), | 181 | Some(self.ctx.domain.clone()), |
| 182 | self.ctx.get_local_relay(), | ||
| 182 | ); | 183 | ); |
| 183 | 184 | ||
| 184 | tracing::info!( | 185 | tracing::info!( |