run cargo fmt
This commit is contained in:
parent
46cb4b3462
commit
e30384c387
6 changed files with 62 additions and 31 deletions
|
@ -3,7 +3,7 @@
|
|||
use nostr::{Keys, PublicKey, SecretKey};
|
||||
use tracing::error;
|
||||
|
||||
use super::{Result, Error, KeyStorage};
|
||||
use super::{Error, KeyStorage, Result};
|
||||
|
||||
use security_framework::item::{ItemClass, ItemSearchOptions, Limit, SearchResult};
|
||||
use security_framework::passwords::{delete_generic_password, set_generic_password};
|
||||
|
@ -14,13 +14,15 @@ pub struct MacOSKeyStorage {
|
|||
|
||||
impl MacOSKeyStorage {
|
||||
pub fn new(service_name: &'static str) -> Self {
|
||||
Self {
|
||||
service_name,
|
||||
}
|
||||
Self { service_name }
|
||||
}
|
||||
|
||||
fn add_key(&self, key: &Keys) -> Result<()> {
|
||||
match set_generic_password(self.service_name, &key.public_key().to_hex(), key.secret_key().unwrap().as_secret_bytes()) {
|
||||
match set_generic_password(
|
||||
self.service_name,
|
||||
&key.public_key().to_hex(),
|
||||
key.secret_key().unwrap().as_secret_bytes(),
|
||||
) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err(Error::Addition(key.public_key().to_hex())),
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use nostr::{Event, EventBuilder, Keys, Kind, PublicKey, Tag};
|
||||
use std::collections::HashMap;
|
||||
use nostr::{EventBuilder, Event, PublicKey, Kind, Tag, Keys};
|
||||
|
||||
pub const MAIL_EVENT_KIND: u16 = 1059;
|
||||
|
||||
|
@ -21,11 +21,13 @@ impl MailMessage {
|
|||
pubkeys_to_send_to.push(*pubkey);
|
||||
}
|
||||
|
||||
let base_event = EventBuilder::new(Kind::Custom(MAIL_EVENT_KIND), &self.content, []).to_unsigned_event(sending_keys.clone().public_key());
|
||||
let base_event = EventBuilder::new(Kind::Custom(MAIL_EVENT_KIND), &self.content, [])
|
||||
.to_unsigned_event(sending_keys.clone().public_key());
|
||||
|
||||
let mut event_list: HashMap<PublicKey, Event> = HashMap::new();
|
||||
for pubkey in pubkeys_to_send_to {
|
||||
let wrapped_event = EventBuilder::gift_wrap(sending_keys, &pubkey, base_event.clone(), None).unwrap();
|
||||
let wrapped_event =
|
||||
EventBuilder::gift_wrap(sending_keys, &pubkey, base_event.clone(), None).unwrap();
|
||||
event_list.insert(pubkey, wrapped_event);
|
||||
}
|
||||
|
||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -1,17 +1,17 @@
|
|||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // for windows release
|
||||
|
||||
use std::collections::HashMap;
|
||||
use eframe::egui::{self, FontDefinitions, Sense, Vec2b};
|
||||
use egui::FontFamily::Proportional;
|
||||
use egui_extras::{Column, TableBuilder};
|
||||
use std::collections::HashMap;
|
||||
use tracing::{debug, error, info, Level};
|
||||
|
||||
mod account_manager;
|
||||
mod error;
|
||||
mod keystorage;
|
||||
mod mail_event;
|
||||
mod relay;
|
||||
mod ui;
|
||||
mod mail_event;
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
let (non_blocking, _guard) = tracing_appender::non_blocking(std::io::stdout()); // add log files in prod one day
|
||||
|
@ -104,9 +104,11 @@ fn update_app(app: &mut Hoot, ctx: &egui::Context) {
|
|||
Ok(..) => {}
|
||||
Err(v) => error!("something went wrong trying to load keys: {}", v),
|
||||
}
|
||||
let _ = app.relays
|
||||
let _ = app
|
||||
.relays
|
||||
.add_url("wss://relay.damus.io".to_string(), wake_up.clone());
|
||||
let _ = app.relays
|
||||
let _ = app
|
||||
.relays
|
||||
.add_url("wss://relay-dev.hoot.sh".to_string(), wake_up);
|
||||
|
||||
if app.account_manager.loaded_keys.len() > 0 {
|
||||
|
@ -122,7 +124,7 @@ fn update_app(app: &mut Hoot, ctx: &egui::Context) {
|
|||
// TODO: fix error handling
|
||||
let _ = app.relays.add_subscription(gw_sub);
|
||||
}
|
||||
|
||||
|
||||
app.status = HootStatus::Ready;
|
||||
info!("Hoot Ready");
|
||||
}
|
||||
|
@ -198,7 +200,9 @@ fn render_app(app: &mut Hoot, ctx: &egui::Context) {
|
|||
content: String::new(),
|
||||
selected_account: None,
|
||||
};
|
||||
app.state.compose_window.insert(egui::Id::new(rand::random::<u32>()), state);
|
||||
app.state
|
||||
.compose_window
|
||||
.insert(egui::Id::new(rand::random::<u32>()), state);
|
||||
}
|
||||
|
||||
if ui.button("Send Test Event").clicked() {
|
||||
|
@ -280,7 +284,11 @@ fn render_app(app: &mut Hoot, ctx: &egui::Context) {
|
|||
"focused_post should not be empty when Page::Post"
|
||||
);
|
||||
|
||||
let event_to_display = app.events.iter().find(|&x| x.id().to_string() == app.focused_post).expect("event id should be present inside event list");
|
||||
let event_to_display = app
|
||||
.events
|
||||
.iter()
|
||||
.find(|&x| x.id().to_string() == app.focused_post)
|
||||
.expect("event id should be present inside event list");
|
||||
|
||||
ui.heading("View Message");
|
||||
ui.label(format!("Content: {}", event_to_display.content));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use tracing::{error, info, debug};
|
||||
use ewebsock::{WsEvent, WsMessage};
|
||||
use crate::error::{Error, Result};
|
||||
use ewebsock::{WsEvent, WsMessage};
|
||||
use tracing::{debug, error, info};
|
||||
|
||||
mod pool;
|
||||
pub use pool::RelayPool;
|
||||
|
@ -61,8 +61,7 @@ impl Relay {
|
|||
if let Some(event) = self.reader.try_recv() {
|
||||
use WsEvent::*;
|
||||
match event {
|
||||
Message(_) => {
|
||||
}
|
||||
Message(_) => {}
|
||||
Opened => {
|
||||
self.status = RelayStatus::Connected;
|
||||
}
|
||||
|
@ -81,7 +80,6 @@ impl Relay {
|
|||
None
|
||||
}
|
||||
|
||||
|
||||
pub fn ping(&mut self) {
|
||||
let ping_msg = WsMessage::Ping(Vec::new());
|
||||
match self.send(ping_msg) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::error::Result;
|
||||
use crate::relay::Subscription;
|
||||
use crate::relay::message::ClientMessage;
|
||||
use crate::relay::Subscription;
|
||||
use crate::relay::{Relay, RelayStatus};
|
||||
use ewebsock::{WsEvent, WsMessage};
|
||||
use std::collections::HashMap;
|
||||
|
@ -36,7 +36,11 @@ impl RelayPool {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_url(&mut self, url: String, wake_up: impl Fn() + Send + Sync + 'static) -> Result<()> {
|
||||
pub fn add_url(
|
||||
&mut self,
|
||||
url: String,
|
||||
wake_up: impl Fn() + Send + Sync + 'static,
|
||||
) -> Result<()> {
|
||||
let relay = Relay::new_with_wakeup(url.clone(), wake_up);
|
||||
self.relays.insert(url, relay);
|
||||
|
||||
|
@ -67,12 +71,14 @@ impl RelayPool {
|
|||
Err(e) => {
|
||||
error!("could not turn subscription into json: {}", e);
|
||||
continue;
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
match relay.send(ewebsock::WsMessage::Text(payload)) {
|
||||
Ok(_) => (),
|
||||
Err(e) => error!("could not send subscription to {}: {:?}", relay.url, e),
|
||||
Err(e) => {
|
||||
error!("could not send subscription to {}: {:?}", relay.url, e)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use tracing::{info, debug, error};
|
||||
use crate::mail_event::MailMessage;
|
||||
use eframe::egui::{self, RichText};
|
||||
use nostr::{Keys, PublicKey};
|
||||
use crate::mail_event::MailMessage;
|
||||
use tracing::{debug, error, info};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ComposeWindowState {
|
||||
|
@ -15,7 +15,11 @@ pub struct ComposeWindow {}
|
|||
|
||||
impl ComposeWindow {
|
||||
pub fn show(app: &mut crate::Hoot, ui: &mut egui::Ui, id: egui::Id) {
|
||||
let state = app.state.compose_window.get_mut(&id).expect("no state found for id");
|
||||
let state = app
|
||||
.state
|
||||
.compose_window
|
||||
.get_mut(&id)
|
||||
.expect("no state found for id");
|
||||
egui::Window::new(&state.subject)
|
||||
.id(id)
|
||||
.show(ui.ctx(), |ui| {
|
||||
|
@ -32,14 +36,24 @@ impl ComposeWindow {
|
|||
use nostr::ToBech32;
|
||||
let mut formatted_key = String::new();
|
||||
if state.selected_account.is_some() {
|
||||
formatted_key = state.selected_account.clone().unwrap().public_key().to_bech32().unwrap();
|
||||
formatted_key = state
|
||||
.selected_account
|
||||
.clone()
|
||||
.unwrap()
|
||||
.public_key()
|
||||
.to_bech32()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
egui::ComboBox::from_label("Select Keys to Send With")
|
||||
.selected_text(format!("{}", formatted_key))
|
||||
.show_ui(ui, |ui| {
|
||||
for key in accounts {
|
||||
ui.selectable_value(&mut state.selected_account, Some(key.clone()), key.public_key().to_bech32().unwrap());
|
||||
ui.selectable_value(
|
||||
&mut state.selected_account,
|
||||
Some(key.clone()),
|
||||
key.public_key().to_bech32().unwrap(),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -58,7 +72,7 @@ impl ComposeWindow {
|
|||
}
|
||||
// convert to field into PublicKey object
|
||||
let to_field = state.to_field.clone();
|
||||
|
||||
|
||||
let mut recipient_keys: Vec<PublicKey> = Vec::new();
|
||||
for key_string in to_field.split_whitespace() {
|
||||
use nostr::FromBech32;
|
||||
|
@ -80,7 +94,8 @@ impl ComposeWindow {
|
|||
subject: state.subject.clone(),
|
||||
content: state.content.clone(),
|
||||
};
|
||||
let events_to_send = msg.to_events(&state.selected_account.clone().unwrap());
|
||||
let events_to_send =
|
||||
msg.to_events(&state.selected_account.clone().unwrap());
|
||||
|
||||
info!("new events! {:?}", events_to_send);
|
||||
// send over wire
|
||||
|
|
Loading…
Add table
Reference in a new issue