Skip to content

Commit 1938d68

Browse files
committed
run cargo fmt
1 parent a68e5d5 commit 1938d68

7 files changed

Lines changed: 152 additions & 131 deletions

File tree

src/account_manager.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::keystorage::{Error, Result, KeyStorage, KeyStorageType};
2-
use nostr::{Keys, Event};
1+
use crate::keystorage::{Error, KeyStorage, KeyStorageType, Result};
32
use nostr::nips::nip59::UnwrappedGift;
3+
use nostr::{Event, Keys};
44
use pollster::FutureExt as _;
55

66
pub struct AccountManager {
@@ -15,12 +15,16 @@ impl AccountManager {
1515
}
1616

1717
pub fn unwrap_gift_wrap(&mut self, gift_wrap: &Event) -> Result<UnwrappedGift> {
18-
let target_pubkey = gift_wrap.tags.iter()
18+
let target_pubkey = gift_wrap
19+
.tags
20+
.iter()
1921
.find(|tag| tag.kind() == "p".into())
2022
.and_then(|tag| tag.content())
2123
.ok_or(Error::KeyNotFound)?;
2224

23-
let target_key = self.loaded_keys.iter()
25+
let target_key = self
26+
.loaded_keys
27+
.iter()
2428
.find(|key| key.public_key().to_string() == *target_pubkey)
2529
.ok_or(Error::KeyNotFound)?;
2630

src/mail_event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use nostr::{Event, EventBuilder, Keys, Kind, PublicKey, Tag, TagKind, TagStandard, EventId};
1+
use nostr::{Event, EventBuilder, EventId, Keys, Kind, PublicKey, Tag, TagKind, TagStandard};
22
use pollster::FutureExt as _;
33
use std::collections::HashMap;
44

@@ -31,7 +31,7 @@ impl MailMessage {
3131
));
3232
pubkeys_to_send_to.push(*pubkey);
3333
}
34-
34+
3535
for event in &self.parent_events {
3636
tags.push(Tag::event(*event));
3737
}

src/relay/message.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use ewebsock::{WsMessage, WsEvent};
1+
use crate::error;
2+
use ewebsock::{WsEvent, WsMessage};
23
use nostr::types::Filter;
34
use nostr::Event;
45
use serde::de::{SeqAccess, Visitor};
56
use serde::ser::SerializeSeq;
67
use serde::{Deserialize, Deserializer, Serialize, Serializer};
78
use std::fmt::{self};
8-
use crate::error;
99

1010
#[derive(Debug, Eq, PartialEq)]
1111
pub struct CommandResult<'a> {
@@ -29,7 +29,7 @@ pub enum RelayEvent<'a> {
2929
Closed,
3030
Other(&'a WsMessage),
3131
Error(error::Error),
32-
Message(RelayMessage<'a>)
32+
Message(RelayMessage<'a>),
3333
}
3434

3535
impl<'a> From<&'a WsEvent> for RelayEvent<'a> {
@@ -104,17 +104,17 @@ impl<'a> RelayMessage<'a> {
104104
if let Some(comma_index) = msg[start..].find(',') {
105105
let subid_end = start + comma_index;
106106
let subid = &msg[start..subid_end].trim().trim_matches('"');
107-
107+
108108
// Find start of event JSON after subscription ID
109109
let event_start = subid_end + 1;
110110
let mut event_start = event_start;
111111
while let Some(&b' ') = msg.as_bytes().get(event_start) {
112112
event_start += 1;
113113
}
114-
114+
115115
// Event JSON goes until end, minus closing bracket
116-
let event_json = &msg[event_start..msg.len()-1];
117-
116+
let event_json = &msg[event_start..msg.len() - 1];
117+
118118
return Ok(Self::event(event_json, subid));
119119
} else {
120120
return Ok(Self::event("{}", "fixme")); // Empty event JSON if parsing fails

src/relay/pool.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::relay::Subscription;
44
use crate::relay::{Relay, RelayStatus};
55
use ewebsock::{WsEvent, WsMessage};
66
use std::collections::HashMap;
7-
use tracing::{error, debug};
8-
use std::time::{Instant, Duration};
7+
use std::time::{Duration, Instant};
8+
use tracing::{debug, error};
99

1010
pub const RELAY_RECONNECT_SECONDS: u64 = 5;
1111

@@ -34,7 +34,9 @@ impl RelayPool {
3434
let now = Instant::now();
3535

3636
// Check disconnected relays
37-
if now.duration_since(self.last_reconnect_attempt) >= Duration::from_secs(RELAY_RECONNECT_SECONDS) {
37+
if now.duration_since(self.last_reconnect_attempt)
38+
>= Duration::from_secs(RELAY_RECONNECT_SECONDS)
39+
{
3840
for relay in self.relays.values_mut() {
3941
if relay.status != RelayStatus::Connected {
4042
relay.status = RelayStatus::Connecting;
@@ -145,7 +147,11 @@ impl RelayPool {
145147
}
146148
}
147149
Pong(m) => {
148-
debug!("pong recieved from {} after approx {} seconds", &url, self.last_ping.elapsed().as_secs());
150+
debug!(
151+
"pong recieved from {} after approx {} seconds",
152+
&url,
153+
self.last_ping.elapsed().as_secs()
154+
);
149155
}
150156
_ => {
151157
// who cares

src/ui/compose_window.rs

Lines changed: 117 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -21,139 +21,144 @@ impl ComposeWindow {
2121
let screen_rect = ctx.screen_rect();
2222
let min_width = screen_rect.width().min(600.0);
2323
let min_height = screen_rect.height().min(400.0);
24-
24+
2525
// First collect all window IDs and their minimized state
2626
let state = app
2727
.state
2828
.compose_window
2929
.get_mut(&id)
3030
.expect("no state found for id");
3131

32-
egui::Window::new("New Message")
33-
.id(id)
34-
.default_size([min_width, min_height])
35-
.min_width(300.0)
36-
.min_height(200.0)
37-
.default_pos([screen_rect.right() - min_width - 20.0, screen_rect.bottom() - min_height - 20.0])
38-
.show(ctx, |ui| {
39-
ui.vertical(|ui| {
40-
// Header section
41-
ui.horizontal(|ui| {
42-
ui.label("To:");
43-
ui.add_sized(
44-
[ui.available_width(), 24.0],
45-
egui::TextEdit::singleline(&mut state.to_field)
46-
);
47-
});
32+
egui::Window::new("New Message")
33+
.id(id)
34+
.default_size([min_width, min_height])
35+
.min_width(300.0)
36+
.min_height(200.0)
37+
.default_pos([
38+
screen_rect.right() - min_width - 20.0,
39+
screen_rect.bottom() - min_height - 20.0,
40+
])
41+
.show(ctx, |ui| {
42+
ui.vertical(|ui| {
43+
// Header section
44+
ui.horizontal(|ui| {
45+
ui.label("To:");
46+
ui.add_sized(
47+
[ui.available_width(), 24.0],
48+
egui::TextEdit::singleline(&mut state.to_field),
49+
);
50+
});
51+
52+
ui.horizontal(|ui| {
53+
ui.label("Subject:");
54+
ui.add_sized(
55+
[ui.available_width(), 24.0],
56+
egui::TextEdit::singleline(&mut state.subject),
57+
);
58+
});
59+
60+
// Toolbar
61+
ui.horizontal(|ui| {
62+
ui.style_mut().spacing.button_padding = egui::vec2(4.0, 4.0);
63+
if ui.button("B").clicked() {}
64+
if ui.button("I").clicked() {}
65+
if ui.button("U").clicked() {}
66+
ui.separator();
67+
if ui.button("🔗").clicked() {}
68+
if ui.button("📎").clicked() {}
69+
if ui.button("😀").clicked() {}
70+
ui.separator();
71+
if ui.button("⌄").clicked() {}
72+
});
4873

49-
ui.horizontal(|ui| {
50-
ui.label("Subject:");
74+
// Message content
75+
let available_height = ui.available_height() - 40.0; // Reserve space for bottom bar
76+
egui::ScrollArea::vertical()
77+
.max_height(available_height)
78+
.show(ui, |ui| {
5179
ui.add_sized(
52-
[ui.available_width(), 24.0],
53-
egui::TextEdit::singleline(&mut state.subject)
80+
[ui.available_width(), available_height - 20.0],
81+
egui::TextEdit::multiline(&mut state.content),
5482
);
5583
});
5684

57-
// Toolbar
58-
ui.horizontal(|ui| {
59-
ui.style_mut().spacing.button_padding = egui::vec2(4.0, 4.0);
60-
if ui.button("B").clicked() {}
61-
if ui.button("I").clicked() {}
62-
if ui.button("U").clicked() {}
63-
ui.separator();
64-
if ui.button("🔗").clicked() {}
65-
if ui.button("📎").clicked() {}
66-
if ui.button("😀").clicked() {}
67-
ui.separator();
68-
if ui.button("⌄").clicked() {}
69-
});
70-
71-
// Message content
72-
let available_height = ui.available_height() - 40.0; // Reserve space for bottom bar
73-
egui::ScrollArea::vertical()
74-
.max_height(available_height)
75-
.show(ui, |ui| {
76-
ui.add_sized(
77-
[ui.available_width(), available_height - 20.0],
78-
egui::TextEdit::multiline(&mut state.content)
79-
);
80-
});
85+
// Bottom bar with account selector and send button
86+
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
87+
if ui.button("Send").clicked() {
88+
if state.selected_account.is_none() {
89+
error!("No Account Selected!");
90+
return;
91+
}
92+
// convert to field into PublicKey object
93+
let to_field = state.to_field.clone();
8194

82-
// Bottom bar with account selector and send button
83-
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
84-
if ui.button("Send").clicked() {
85-
if state.selected_account.is_none() {
86-
error!("No Account Selected!");
87-
return;
88-
}
89-
// convert to field into PublicKey object
90-
let to_field = state.to_field.clone();
91-
92-
let mut recipient_keys: Vec<PublicKey> = Vec::new();
93-
for key_string in to_field.split_whitespace() {
94-
use nostr::FromBech32;
95-
match PublicKey::from_bech32(key_string) {
96-
Ok(k) => recipient_keys.push(k),
97-
Err(e) => debug!("could not parse public key as bech32: {}", e),
98-
};
99-
100-
match PublicKey::from_hex(key_string) {
101-
Ok(k) => recipient_keys.push(k),
102-
Err(e) => debug!("could not parse public key as hex: {}", e),
103-
};
104-
}
95+
let mut recipient_keys: Vec<PublicKey> = Vec::new();
96+
for key_string in to_field.split_whitespace() {
97+
use nostr::FromBech32;
98+
match PublicKey::from_bech32(key_string) {
99+
Ok(k) => recipient_keys.push(k),
100+
Err(e) => debug!("could not parse public key as bech32: {}", e),
101+
};
105102

106-
let mut msg = MailMessage {
107-
to: recipient_keys,
108-
cc: vec![],
109-
bcc: vec![],
110-
parent_events: state.parent_events.clone(),
111-
subject: state.subject.clone(),
112-
content: state.content.clone(),
103+
match PublicKey::from_hex(key_string) {
104+
Ok(k) => recipient_keys.push(k),
105+
Err(e) => debug!("could not parse public key as hex: {}", e),
113106
};
114-
let events_to_send =
115-
msg.to_events(&state.selected_account.clone().unwrap());
116-
117-
// send over wire
118-
for event in events_to_send {
119-
match serde_json::to_string(&ClientMessage::Event { event: event.1 }) {
120-
Ok(v) => match app.relays.send(ewebsock::WsMessage::Text(v)) {
121-
Ok(r) => r,
122-
Err(e) => error!("could not send event to relays: {}", e),
123-
},
124-
Err(e) => error!("could not serialize event: {}", e),
125-
};
126-
}
127107
}
128108

129-
// Account selector
130-
let accounts = app.account_manager.loaded_keys.clone();
131-
use nostr::ToBech32;
132-
let mut formatted_key = String::new();
133-
if state.selected_account.is_some() {
134-
formatted_key = state
135-
.selected_account
136-
.clone()
137-
.unwrap()
138-
.public_key()
139-
.to_bech32()
140-
.unwrap();
109+
let mut msg = MailMessage {
110+
to: recipient_keys,
111+
cc: vec![],
112+
bcc: vec![],
113+
parent_events: state.parent_events.clone(),
114+
subject: state.subject.clone(),
115+
content: state.content.clone(),
116+
};
117+
let events_to_send =
118+
msg.to_events(&state.selected_account.clone().unwrap());
119+
120+
// send over wire
121+
for event in events_to_send {
122+
match serde_json::to_string(&ClientMessage::Event {
123+
event: event.1,
124+
}) {
125+
Ok(v) => match app.relays.send(ewebsock::WsMessage::Text(v)) {
126+
Ok(r) => r,
127+
Err(e) => error!("could not send event to relays: {}", e),
128+
},
129+
Err(e) => error!("could not serialize event: {}", e),
130+
};
141131
}
132+
}
142133

143-
egui::ComboBox::from_id_source("account_selector")
144-
.selected_text(format!("{}", formatted_key))
145-
.show_ui(ui, |ui| {
146-
for key in accounts {
147-
ui.selectable_value(
148-
&mut state.selected_account,
149-
Some(key.clone()),
150-
key.public_key().to_bech32().unwrap(),
151-
);
152-
}
153-
});
154-
});
134+
// Account selector
135+
let accounts = app.account_manager.loaded_keys.clone();
136+
use nostr::ToBech32;
137+
let mut formatted_key = String::new();
138+
if state.selected_account.is_some() {
139+
formatted_key = state
140+
.selected_account
141+
.clone()
142+
.unwrap()
143+
.public_key()
144+
.to_bech32()
145+
.unwrap();
146+
}
147+
148+
egui::ComboBox::from_id_source("account_selector")
149+
.selected_text(format!("{}", formatted_key))
150+
.show_ui(ui, |ui| {
151+
for key in accounts {
152+
ui.selectable_value(
153+
&mut state.selected_account,
154+
Some(key.clone()),
155+
key.public_key().to_bech32().unwrap(),
156+
);
157+
}
158+
});
155159
});
156160
});
161+
});
157162
}
158163

159164
// Keep the original show method for backward compatibility

src/ui/onboarding.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ impl OnboardingScreen {
5151

5252
// here, we are assuming that the most recent key added is the one that was generated in
5353
// onboarding_new()'s button click.
54-
let first_key = app.account_manager.loaded_keys.last().expect("wanted a key from last screen").clone();
54+
let first_key = app
55+
.account_manager
56+
.loaded_keys
57+
.last()
58+
.expect("wanted a key from last screen")
59+
.clone();
5560
ui.label(format!(
5661
"New identity: {}",
5762
first_key.public_key().to_bech32().unwrap()

0 commit comments

Comments
 (0)