wip: refactor

This commit is contained in:
2024-12-17 18:51:06 +07:00
parent 377f169420
commit 0682612d42
27 changed files with 486 additions and 259 deletions

View File

@@ -0,0 +1,41 @@
use gpui::*;
use nostr_sdk::prelude::*;
use tokio::sync::mpsc::Sender;
#[derive(Clone)]
pub enum Signal {
/// Send
DONE(PublicKey),
/// Receive
REQ(PublicKey),
}
pub struct MetadataRegistry {
seens: Vec<PublicKey>,
pub reqs: Sender<Signal>,
}
impl Global for MetadataRegistry {}
impl MetadataRegistry {
pub fn set_global(cx: &mut AppContext, reqs: Sender<Signal>) {
cx.set_global(Self::new(reqs));
}
pub fn contains(&self, public_key: PublicKey) -> bool {
self.seens.contains(&public_key)
}
pub fn seen(&mut self, public_key: PublicKey) {
if !self.seens.contains(&public_key) {
self.seens.push(public_key);
}
}
fn new(reqs: Sender<Signal>) -> Self {
Self {
seens: Vec::new(),
reqs,
}
}
}