upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/nostr/policy/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/nostr/policy/mod.rs')
-rw-r--r--src/nostr/policy/mod.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/nostr/policy/mod.rs b/src/nostr/policy/mod.rs
index 1566b6c..78a09fc 100644
--- a/src/nostr/policy/mod.rs
+++ b/src/nostr/policy/mod.rs
@@ -20,6 +20,7 @@ pub use crate::git::sync::AlignmentResult;
20 20
21use super::SharedDatabase; 21use super::SharedDatabase;
22use crate::purgatory::Purgatory; 22use crate::purgatory::Purgatory;
23use crate::sync::{AddFilters, RepoSyncIndex};
23use nostr_relay_builder::LocalRelay; 24use nostr_relay_builder::LocalRelay;
24use std::sync::Arc; 25use std::sync::Arc;
25 26
@@ -34,6 +35,16 @@ pub struct PolicyContext {
34 pub local_relay: Arc<std::sync::RwLock<Option<LocalRelay>>>, 35 pub local_relay: Arc<std::sync::RwLock<Option<LocalRelay>>>,
35 /// Configuration reference for policy settings (includes blacklists) 36 /// Configuration reference for policy settings (includes blacklists)
36 pub config: crate::config::Config, 37 pub config: crate::config::Config,
38 /// Optional repo sync index for triggering relay discovery when announcements
39 /// go to purgatory via user submission (not via the sync path).
40 /// Wrapped in Arc<RwLock> for interior mutability (PolicyContext is Clone).
41 pub repo_sync_index: Arc<std::sync::RwLock<Option<RepoSyncIndex>>>,
42 /// Optional sender for AddFilters actions to SyncManager.
43 /// Used to trigger relay discovery when user-submitted purgatory announcements
44 /// are registered with StateOnly sync level.
45 /// Wrapped in Arc<RwLock> for interior mutability (PolicyContext is Clone).
46 pub sync_action_tx:
47 Arc<std::sync::RwLock<Option<tokio::sync::mpsc::Sender<AddFilters>>>>,
37} 48}
38 49
39impl PolicyContext { 50impl PolicyContext {
@@ -51,6 +62,8 @@ impl PolicyContext {
51 purgatory, 62 purgatory,
52 local_relay: Arc::new(std::sync::RwLock::new(None)), 63 local_relay: Arc::new(std::sync::RwLock::new(None)),
53 config, 64 config,
65 repo_sync_index: Arc::new(std::sync::RwLock::new(None)),
66 sync_action_tx: Arc::new(std::sync::RwLock::new(None)),
54 } 67 }
55 } 68 }
56 69
@@ -68,4 +81,28 @@ impl PolicyContext {
68 let guard = self.local_relay.read().unwrap(); 81 let guard = self.local_relay.read().unwrap();
69 guard.clone() 82 guard.clone()
70 } 83 }
84
85 /// Set the repo sync index for relay discovery from user-submitted purgatory announcements.
86 pub fn set_repo_sync_index(&self, index: RepoSyncIndex) {
87 let mut guard = self.repo_sync_index.write().unwrap();
88 *guard = Some(index);
89 }
90
91 /// Get a clone of the repo sync index if it's been set.
92 pub fn get_repo_sync_index(&self) -> Option<RepoSyncIndex> {
93 let guard = self.repo_sync_index.read().unwrap();
94 guard.clone()
95 }
96
97 /// Set the sync action sender for sending AddFilters actions to SyncManager.
98 pub fn set_sync_action_tx(&self, tx: tokio::sync::mpsc::Sender<AddFilters>) {
99 let mut guard = self.sync_action_tx.write().unwrap();
100 *guard = Some(tx);
101 }
102
103 /// Get a clone of the sync action sender if it's been set.
104 pub fn get_sync_action_tx(&self) -> Option<tokio::sync::mpsc::Sender<AddFilters>> {
105 let guard = self.sync_action_tx.read().unwrap();
106 guard.clone()
107 }
71} 108}