Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ egui_virtual_list = { git = "https://github.com/jb55/hello_egui", rev = "a66b679
ehttp = "0.5.0"
enostr = { path = "crates/enostr" }
ewebsock = { version = "0.2.0", features = ["tls"] }
futures = "0.3.31"
hex = "0.4.3"
image = { version = "0.25", features = ["jpeg", "png", "webp"] }
indexmap = "2.6.0"
Expand Down
59 changes: 58 additions & 1 deletion crates/enostr/src/relay/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ impl PoolRelay {
}

pub fn subscribe(&mut self, subid: String, filter: Vec<Filter>) -> Result<()> {
debug!(
"PoolRelay subscribe: sending sub {} {}: {:?}",
subid,
self.url(),
filter
.iter()
.map(|f| f.json().unwrap_or_default())
.collect::<Vec<_>>(),
);
self.send(&ClientMessage::req(subid, filter))
}

Expand Down Expand Up @@ -197,6 +206,7 @@ impl RelayPool {
if let Some(debug) = &mut self.debug {
debug.send_cmd(relay.url().to_owned(), &cmd);
}
debug!("RelayPool unsubscribe close {} {}", subid, relay.url());
if let Err(err) = relay.send(&cmd) {
error!(
"error unsubscribing from {} on {}: {err}",
Expand All @@ -215,10 +225,57 @@ impl RelayPool {
&ClientMessage::req(subid.clone(), filter.clone()),
);
}
debug!(
"RelayPool subscribe: sending sub {} {}: {:?}",
subid,
relay.url(),
filter
.iter()
.map(|f| f.json().unwrap_or_default())
.collect::<Vec<_>>(),
);
if let Err(err) = relay.send(&ClientMessage::req(subid.clone(), filter.clone())) {
error!("error subscribing to {}: {err}", relay.url());
}
}
}

// if the relay is in the pool already send the subscription, otherwise add the
// relay to the pool and we'll send it on open.
pub fn subscribe_relay(
&mut self,
subid: String,
filter: Vec<Filter>,
relaystr: String,
) -> bool {
if let Some(&mut ref mut relay) = self.relays.iter_mut().find(|r| r.url() == relaystr) {
if let Some(debug) = &mut self.debug {
debug.send_cmd(
relay.url().to_owned(),
&ClientMessage::req(subid.clone(), filter.clone()),
);
}
debug!(
"RelayPool subscribe_relay: sending sub {} {}: {:?}",
subid,
relay.url(),
filter
.iter()
.map(|f| f.json().unwrap_or_default())
.collect::<Vec<_>>(),
);
if let Err(err) = relay.send(&ClientMessage::req(subid.clone(), filter.clone())) {
error!("error subscribing to {}: {err}", relay.url());
}
true
} else {
let wakeup = move || {
// ignore
};
if let Err(err) = self.add_url(relaystr.clone(), wakeup) {
error!("trouble adding url {}: {:?}", relaystr, err);
}
false
}
}

Expand Down Expand Up @@ -343,7 +400,7 @@ impl RelayPool {
}

// standardize the format (ie, trailing slashes)
fn canonicalize_url(url: String) -> String {
pub fn canonicalize_url(url: String) -> String {
match Url::parse(&url) {
Ok(parsed_url) => parsed_url.to_string(),
Err(_) => url, // If parsing fails, return the original URL.
Expand Down
3 changes: 3 additions & 0 deletions crates/notedeck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enostr = { workspace = true }
nostr = { workspace = true }
egui = { workspace = true }
eframe = { workspace = true }
futures = { workspace = true }
image = { workspace = true }
base32 = { workspace = true }
poll-promise = { workspace = true }
Expand All @@ -32,9 +33,11 @@ ehttp = {workspace = true }
mime_guess = { workspace = true }
egui-winit = { workspace = true }
tokenator = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "fs"] }

[dev-dependencies]
tempfile = { workspace = true }
nostr = { workspace = true }

[target.'cfg(target_os = "android")'.dependencies]
jni = { workspace = true }
Expand Down
Loading