upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/nostr/policy
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-01-05 14:31:47 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-01-05 14:31:47 +0000
commitf8235b7977c673524c12a229eddb7ace6b0c2c0d (patch)
tree1725861f36085adc7b7c3f033e67cde910fe4c75 /src/nostr/policy
parent8cb45487d7125a14d15c15dfc14b0804eb22ffd6 (diff)
purgatory: git data sync applies state and saves event
Diffstat (limited to 'src/nostr/policy')
-rw-r--r--src/nostr/policy/mod.rs19
-rw-r--r--src/nostr/policy/state.rs1
2 files changed, 20 insertions, 0 deletions
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
18use super::SharedDatabase; 18use super::SharedDatabase;
19use crate::purgatory::Purgatory; 19use crate::purgatory::Purgatory;
20use nostr_relay_builder::LocalRelay;
20use std::sync::Arc; 21use 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
31impl PolicyContext { 34impl 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!(