notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 3e96f815b123144138c1c05a67381878e632c71b
parent 83571aaf88c5952371b805dbfb9102b1ce2c2833
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 10 Feb 2024 16:15:51 -0800

apply cargo warning suggested fixes

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Menostr/src/event.rs | 2+-
Menostr/src/relay/message.rs | 6+++---
Menostr/src/relay/pool.rs | 7++++---
Msrc/app.rs | 54++++++++++++++++++++++--------------------------------
Dsrc/contacts.rs | 16----------------
Msrc/fonts.rs | 2+-
Msrc/frame_history.rs | 2+-
Msrc/lib.rs | 1-
Msrc/timeline.rs | 24------------------------
9 files changed, 32 insertions(+), 82 deletions(-)

diff --git a/enostr/src/event.rs b/enostr/src/event.rs @@ -1,5 +1,5 @@ use crate::{Error, Pubkey}; -use log::debug; + use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::hash::{Hash, Hasher}; diff --git a/enostr/src/relay/message.rs b/enostr/src/relay/message.rs @@ -1,8 +1,8 @@ use crate::Error; -use crate::Event; + use crate::Result; -use serde_json::Value; -use tracing::{error, info}; + +use tracing::{error}; use ewebsock::{WsEvent, WsMessage}; diff --git a/enostr/src/relay/pool.rs b/enostr/src/relay/pool.rs @@ -1,4 +1,3 @@ -use crate::relay::message::{RelayEvent, RelayMessage}; use crate::relay::{Relay, RelayStatus}; use crate::{ClientMessage, Result}; @@ -8,7 +7,7 @@ use std::time::{Duration, Instant}; use ewebsock::{WsEvent, WsMessage}; #[cfg(not(target_arch = "wasm32"))] -use tracing::{debug, error, info}; +use tracing::{debug, error}; #[derive(Debug)] pub struct PoolEvent<'a> { @@ -91,7 +90,9 @@ impl RelayPool { relay.retry_connect_after, next_duration ); relay.retry_connect_after = next_duration; - relay.relay.connect(wakeup.clone()); + if let Err(err) = relay.relay.connect(wakeup.clone()) { + error!("error connecting to relay: {}", err); + } } else { // let's wait a bit before we try again } diff --git a/src/app.rs b/src/app.rs @@ -1,30 +1,27 @@ use crate::abbrev; -use crate::contacts::Contacts; use crate::error::Error; -use crate::fonts::{setup_fonts, setup_gossip_fonts}; +use crate::fonts::setup_gossip_fonts; use crate::frame_history::FrameHistory; use crate::images::fetch_img; use crate::timeline; use crate::ui::padding; use crate::Result; use egui::containers::scroll_area::ScrollBarVisibility; -use egui::load::SizedTexture; + use egui::widgets::Spinner; -use egui::{Context, Frame, ImageSource, Margin, TextureHandle, TextureId}; -use egui_extras::Size; -use enostr::{ClientMessage, EventId, Filter, Profile, Pubkey, RelayEvent, RelayMessage}; -use nostrdb::{ - Config, Ndb, NdbProfile, NdbProfileRecord, NoteKey, ProfileRecord, Subscription, Transaction, -}; +use egui::{Context, Frame, Margin, TextureHandle}; + +use enostr::{ClientMessage, Filter, Pubkey, RelayEvent, RelayMessage}; +use nostrdb::{Config, Ndb, NoteKey, ProfileRecord, Subscription, Transaction}; use poll_promise::Promise; use std::cmp::Ordering; use std::collections::{HashMap, HashSet}; use std::hash::{Hash, Hasher}; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::time::Duration; use tracing::{debug, error, info, warn}; -use enostr::{Event, RelayPool}; +use enostr::RelayPool; #[derive(Hash, Eq, PartialEq, Clone, Debug)] enum UrlKey<'a> { @@ -91,7 +88,6 @@ impl Timeline { /// We derive Deserialize/Serialize so we can persist app state on shutdown. pub struct Damus { state: DamusState, - contacts: Contacts, n_panels: u32, compose: String, @@ -283,7 +279,9 @@ fn update_damus(damus: &mut Damus, ctx: &egui::Context) { setup_initial_nostrdb_subs(damus).expect("home subscription failed"); } - try_process_event(damus, ctx); + if let Err(err) = try_process_event(damus, ctx) { + error!("error processing event: {}", err); + } } fn process_event(damus: &mut Damus, _subid: &str, event: &str) { @@ -291,7 +289,9 @@ fn process_event(damus: &mut Damus, _subid: &str, event: &str) { puffin::profile_function!(); //info!("processing event {}", event); - damus.ndb.process_event(&event); + if let Err(err) = damus.ndb.process_event(&event) { + error!("error processing event {}", event); + } /* let kind = event.kind(); @@ -358,7 +358,9 @@ fn process_message(damus: &mut Damus, relay: &str, msg: &RelayMessage) { RelayMessage::Notice(msg) => warn!("Notice from {}: {}", relay, msg), RelayMessage::OK(cr) => info!("OK {:?}", cr), RelayMessage::Eose(sid) => { - handle_eose(damus, &sid, relay); + if let Err(err) = handle_eose(damus, &sid, relay) { + error!("error handling eose: {}", err); + } } } } @@ -396,7 +398,6 @@ impl Damus { config.set_ingester_threads(2); Self { state: DamusState::Initializing, - contacts: Contacts::new(), pool: RelayPool::new(), img_cache: HashMap::new(), n_panels: 1, @@ -439,7 +440,7 @@ fn render_pfp(ui: &mut egui::Ui, img_cache: &mut ImageCache, url: &str) { None => { ui.add(Spinner::new().size(40.0)); } - Some(Err(e)) => { + Some(Err(_e)) => { //error!("Image load error: {:?}", e); ui.label("❌"); } @@ -473,7 +474,7 @@ fn ui_abbreviate_name(ui: &mut egui::Ui, name: &str, len: usize) { } } -fn render_username(ui: &mut egui::Ui, profile: Option<&ProfileRecord>, pk: &[u8; 32]) { +fn render_username(ui: &mut egui::Ui, profile: Option<&ProfileRecord>, _pk: &[u8; 32]) { #[cfg(feature = "profiling")] puffin::profile_function!(); @@ -505,7 +506,7 @@ fn no_pfp_url() -> &'static str { fn render_notes_in_viewport( ui: &mut egui::Ui, - damus: &mut Damus, + _damus: &mut Damus, viewport: egui::Rect, row_height: f32, font_id: egui::FontId, @@ -520,7 +521,7 @@ fn render_notes_in_viewport( let mut used_rect = egui::Rect::NOTHING; for i in first_item..last_item { - let padding = (i % 100) as f32; + let _padding = (i % 100) as f32; let indent = (((i as f32) / 10.0).sin() * 20.0) + 10.0; let x = ui.min_rect().left() + indent; let y = ui.min_rect().top() + i as f32 * row_height; @@ -632,11 +633,6 @@ fn top_panel(ctx: &egui::Context) -> egui::TopBottomPanel { egui::TopBottomPanel::top("top_panel").frame(Frame::none()) } -#[inline] -fn horizontal_centered() -> egui::Layout { - egui::Layout::left_to_right(egui::Align::Center) -} - fn render_panel<'a>(ctx: &egui::Context, app: &'a mut Damus, timeline_ind: usize) { top_panel(ctx).show(ctx, |ui| { set_app_style(ui); @@ -746,7 +742,7 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) { } fn postbox(ui: &mut egui::Ui, app: &mut Damus) { - let output = egui::TextEdit::multiline(&mut app.compose) + let _output = egui::TextEdit::multiline(&mut app.compose) .hint_text("Type something!") .show(ui); @@ -796,9 +792,3 @@ impl eframe::App for Damus { render_damus(self, ctx); } } - -pub const LOREM_IPSUM: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; - -pub const LOREM_IPSUM_LONG: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - -Curabitur pretium tincidunt lacus. Nulla gravida orci a odio. Nullam varius, turpis et commodo pharetra, est eros bibendum elit, nec luctus magna felis sollicitudin mauris. Integer in mauris eu nibh euismod gravida. Duis ac tellus et risus vulputate vehicula. Donec lobortis risus a elit. Etiam tempor. Ut ullamcorper, ligula eu tempor congue, eros est euismod turpis, id tincidunt sapien risus a quam. Maecenas fermentum consequat mi. Donec fermentum. Pellentesque malesuada nulla a mi. Duis sapien sem, aliquet nec, commodo eget, consequat quis, neque. Aliquam faucibus, elit ut dictum aliquet, felis nisl adipiscing sapien, sed malesuada diam lacus eget erat. Cras mollis scelerisque nunc. Nullam arcu. Aliquam consequat. Curabitur augue lorem, dapibus quis, laoreet et, pretium ac, nisi. Aenean magna nisl, mollis quis, molestie eu, feugiat in, orci. In hac habitasse platea dictumst."; diff --git a/src/contacts.rs b/src/contacts.rs @@ -1,16 +0,0 @@ -use enostr::{EventId, Profile, Pubkey}; -use std::collections::HashMap; - -pub struct Contacts { - pub events: HashMap<Pubkey, EventId>, - pub profiles: HashMap<Pubkey, Profile>, -} - -impl Contacts { - pub fn new() -> Contacts { - Contacts { - events: HashMap::new(), - profiles: HashMap::new(), - } - } -} diff --git a/src/fonts.rs b/src/fonts.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; pub fn setup_fonts(ctx: &egui::Context) { let mut fonts = FontDefinitions::default(); - let mut families = BTreeMap::<String, FontData>::new(); + let _families = BTreeMap::<String, FontData>::new(); let our_font: String = "onest".to_owned(); diff --git a/src/frame_history.rs b/src/frame_history.rs @@ -32,7 +32,7 @@ impl FrameHistory { 1.0 / self.frame_times.mean_time_interval().unwrap_or_default() } - pub fn ui(&mut self, ui: &mut egui::Ui) { + pub fn _ui(&mut self, ui: &mut egui::Ui) { ui.label(format!( "Mean CPU usage: {:.2} ms / frame", 1e3 * self.mean_frame_time() diff --git a/src/lib.rs b/src/lib.rs @@ -1,6 +1,5 @@ mod app; //mod camera; -mod contacts; mod error; //mod note; //mod block; diff --git a/src/timeline.rs b/src/timeline.rs @@ -1,27 +1,3 @@ -pub fn binary_search<T: Ord>(a: &[T], item: &T) -> usize { - let mut low = 0; - let mut high = a.len(); - - while low < high { - let mid = low + (high - low) / 2; - if item <= &a[mid] { - high = mid; - } else { - low = mid + 1; - } - } - - low -} - -pub fn binary_insertion_sort<T: Ord>(vec: &mut Vec<T>) { - for i in 1..vec.len() { - let val = vec.remove(i); - let pos = binary_search(&vec[0..i], &val); - vec.insert(pos, val); - } -} - pub fn merge_sorted_vecs<T: Ord + Copy>(vec1: &Vec<T>, vec2: &Vec<T>) -> Vec<T> { let mut merged = Vec::with_capacity(vec1.len() + vec2.len()); let mut i = 0;