chore: fix some gossip and nip4e bugs #23

Merged
reya merged 6 commits from fix-gossip into master 2026-03-18 08:21:40 +00:00
2 changed files with 33 additions and 36 deletions
Showing only changes of commit 4651221ded - Show all commits

View File

@@ -13,7 +13,6 @@ use state::{NostrRegistry, TIMEOUT};
use crate::NewMessage; use crate::NewMessage;
const NO_RELAY: &str = "User hasn't set up any messaging relays yet.";
const NO_DEKEY: &str = "User hasn't set up a decoupled encryption key yet."; const NO_DEKEY: &str = "User hasn't set up a decoupled encryption key yet.";
const USER_NO_DEKEY: &str = "You haven't set up a decoupled encryption key or it's not available."; const USER_NO_DEKEY: &str = "You haven't set up a decoupled encryption key or it's not available.";
@@ -501,16 +500,9 @@ impl Room {
// Process each member // Process each member
for member in members { for member in members {
let relays = member.messaging_relays();
let announcement = member.announcement(); let announcement = member.announcement();
let public_key = member.public_key(); let public_key = member.public_key();
// Skip members with no relays
if relays.is_empty() {
reports.push(SendReport::new(public_key).error(NO_RELAY));
continue;
}
// Handle encryption signer requirements // Handle encryption signer requirements
if signer_kind.encryption() { if signer_kind.encryption() {
// Receiver didn't set up a decoupled encryption key // Receiver didn't set up a decoupled encryption key
@@ -546,7 +538,7 @@ impl Room {
}; };
// Send the gift wrap event and collect the report // Send the gift wrap event and collect the report
match send_gift_wrap(&client, &signer, &member, &rumor, signer_kind, relays).await { match send_gift_wrap(&client, &signer, &member, &rumor, signer_kind).await {
Ok(report) => { Ok(report) => {
reports.push(report); reports.push(report);
sents += 1; sents += 1;
@@ -561,7 +553,6 @@ impl Room {
// Send backup to current user if needed // Send backup to current user if needed
if backup && sents >= 1 { if backup && sents >= 1 {
let public_key = sender.public_key(); let public_key = sender.public_key();
let relays = sender.messaging_relays();
// Determine the signer to use // Determine the signer to use
let signer = match signer_kind { let signer = match signer_kind {
@@ -582,7 +573,7 @@ impl Room {
SignerKind::User => user_signer.clone(), SignerKind::User => user_signer.clone(),
}; };
match send_gift_wrap(&client, &signer, &sender, &rumor, signer_kind, relays).await { match send_gift_wrap(&client, &signer, &sender, &rumor, signer_kind).await {
Ok(report) => reports.push(report), Ok(report) => reports.push(report),
Err(error) => { Err(error) => {
let report = SendReport::new(public_key).error(error.to_string()); let report = SendReport::new(public_key).error(error.to_string());
@@ -603,7 +594,6 @@ async fn send_gift_wrap<T>(
receiver: &Person, receiver: &Person,
rumor: &UnsignedEvent, rumor: &UnsignedEvent,
config: &SignerKind, config: &SignerKind,
to: &[RelayUrl],
) -> Result<SendReport, Error> ) -> Result<SendReport, Error>
where where
T: NostrSigner + 'static, T: NostrSigner + 'static,
@@ -634,15 +624,10 @@ where
// Construct the gift wrap event // Construct the gift wrap event
let event = EventBuilder::gift_wrap(signer, &receiver, rumor.clone(), extra_tags).await?; let event = EventBuilder::gift_wrap(signer, &receiver, rumor.clone(), extra_tags).await?;
// Connect to each relay before sending
for url in to.iter() {
client.add_relay(url).and_connect().await.ok();
}
// Send the gift wrap event and collect the report // Send the gift wrap event and collect the report
let report = client let report = client
.send_event(&event) .send_event(&event)
.to(to) .to_nip17()
.ack_policy(AckPolicy::none()) .ack_policy(AckPolicy::none())
.await .await
.map(|output| { .map(|output| {

View File

@@ -379,9 +379,13 @@ impl ChatPanel {
/// Send message in the background and wait for the response /// Send message in the background and wait for the response
fn send_and_wait(&mut self, rumor: UnsignedEvent, window: &mut Window, cx: &mut Context<Self>) { fn send_and_wait(&mut self, rumor: UnsignedEvent, window: &mut Window, cx: &mut Context<Self>) {
let sent_ids = self.sent_ids.clone(); let sent_ids = self.sent_ids.clone();
// This can't fail, because we already ensured that the ID is set // This can't fail, because we already ensured that the ID is set
let id = rumor.id.unwrap(); let id = rumor.id.unwrap();
// Add empty reports
self.insert_reports(id, vec![], cx);
// Upgrade room reference // Upgrade room reference
let Some(room) = self.room.upgrade() else { let Some(room) = self.room.upgrade() else {
return; return;
@@ -430,7 +434,7 @@ impl ChatPanel {
/// Insert reports /// Insert reports
fn insert_reports(&mut self, id: EventId, reports: Vec<SendReport>, cx: &mut Context<Self>) { fn insert_reports(&mut self, id: EventId, reports: Vec<SendReport>, cx: &mut Context<Self>) {
self.reports_by_id.update(cx, |this, cx| { self.reports_by_id.update(cx, |this, cx| {
this.insert(id, reports); this.entry(id).or_default().extend(reports);
cx.notify(); cx.notify();
}); });
} }
@@ -924,20 +928,26 @@ impl ChatPanel {
fn render_sent_reports(&self, id: &EventId, cx: &App) -> impl IntoElement { fn render_sent_reports(&self, id: &EventId, cx: &App) -> impl IntoElement {
let reports = self.sent_reports(id, cx); let reports = self.sent_reports(id, cx);
let pending = reports
.as_ref()
.is_some_and(|reports| reports.is_empty() || reports.iter().any(|r| r.pending()));
let success = reports let success = reports
.as_ref() .as_ref()
.is_some_and(|reports| reports.iter().any(|r| r.success())); .is_some_and(|reports| !reports.is_empty() && reports.iter().any(|r| r.success()));
let failed = reports let failed = reports
.as_ref() .as_ref()
.is_some_and(|reports| reports.iter().all(|r| r.failed())); .is_some_and(|reports| !reports.is_empty() && reports.iter().all(|r| r.failed()));
let label = if success { let label = if success {
SharedString::from("• Sent") SharedString::from("• Sent")
} else if failed { } else if failed {
SharedString::from("Failed") SharedString::from("Error")
} else { } else if pending {
SharedString::from("• Sending...") SharedString::from("• Sending...")
} else {
SharedString::from("• Unknown")
}; };
div() div()
@@ -945,22 +955,24 @@ impl ChatPanel {
.child(label) .child(label)
.when(failed, |this| this.text_color(cx.theme().text_danger)) .when(failed, |this| this.text_color(cx.theme().text_danger))
.when_some(reports, |this, reports| { .when_some(reports, |this, reports| {
this.on_click(move |_e, window, cx| { this.when(!pending, |this| {
let reports = reports.clone(); this.on_click(move |_e, window, cx| {
let reports = reports.clone();
window.open_modal(cx, move |this, _window, cx| { window.open_modal(cx, move |this, _window, cx| {
this.title(SharedString::from("Sent Reports")) this.title(SharedString::from("Sent Reports"))
.show_close(true) .show_close(true)
.child(v_flex().gap_4().children({ .child(v_flex().gap_4().children({
let mut items = Vec::with_capacity(reports.len()); let mut items = Vec::with_capacity(reports.len());
for report in reports.iter() { for report in reports.iter() {
items.push(Self::render_report(report, cx)) items.push(Self::render_report(report, cx))
} }
items items
})) }))
}); });
})
}) })
}) })
} }