wip: refactor
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
use gpui::*;
|
||||
use nostr_sdk::prelude::*;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::broadcast::Sender;
|
||||
|
||||
pub struct SignalRegistry {
|
||||
public_keys: Vec<PublicKey>,
|
||||
pub queue: Arc<Sender<PublicKey>>,
|
||||
}
|
||||
|
||||
impl Global for SignalRegistry {}
|
||||
|
||||
impl SignalRegistry {
|
||||
pub fn set_global(cx: &mut AppContext) {
|
||||
cx.set_global(Self::new());
|
||||
pub fn set_global(cx: &mut AppContext, queue: Arc<Sender<PublicKey>>) {
|
||||
cx.set_global(Self::new(queue));
|
||||
}
|
||||
|
||||
pub fn contains(&self, public_key: PublicKey) -> bool {
|
||||
@@ -20,9 +23,16 @@ impl SignalRegistry {
|
||||
self.public_keys.push(public_key);
|
||||
}
|
||||
|
||||
fn new() -> Self {
|
||||
pub fn add_to_queue(&mut self, public_key: PublicKey) {
|
||||
if let Err(e) = self.queue.send(public_key) {
|
||||
println!("Dropped: {}", e)
|
||||
}
|
||||
}
|
||||
|
||||
fn new(queue: Arc<Sender<PublicKey>>) -> Self {
|
||||
Self {
|
||||
public_keys: Vec::new(),
|
||||
queue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user