dominus

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

commit 28c5ddbc80500e61af004b5cf9af2e3a8eecd13c
parent 46f9bde2575537cc77d08ccc9e37af0734682b98
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  6 Nov 2022 20:54:30 -0800

progress

Diffstat:
MCargo.lock | 312++-----------------------------------------------------------------------------
MCargo.toml | 4+++-
Msrc/app.rs | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Asrc/event.rs | 23+++++++++++++++++++++++
Msrc/lib.rs | 2++
Msrc/main.rs | 2+-
6 files changed, 91 insertions(+), 336 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -112,12 +112,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" [[package]] -name = "bitcoin_hashes" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90064b8dee6815a6470d60bad07bbbaee885c0e12d04177138fa3291a01b7bc4" - -[[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -130,24 +124,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - -[[package]] -name = "block-buffer" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" -dependencies = [ - "generic-array", -] - -[[package]] name = "bumpalo" version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -362,15 +338,6 @@ dependencies = [ ] [[package]] -name = "cpufeatures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" -dependencies = [ - "libc", -] - -[[package]] name = "crc32fast" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -452,16 +419,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] name = "cty" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -477,9 +434,10 @@ dependencies = [ "egui_extras", "ehttp", "image", - "nostr_rust", "poll-promise", "serde", + "serde_derive", + "serde_json", "tracing-subscriber", "tracing-wasm", ] @@ -538,25 +496,6 @@ dependencies = [ ] [[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "digest" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" -dependencies = [ - "block-buffer 0.10.3", - "crypto-common", -] - -[[package]] name = "directories-next" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -918,16 +857,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" [[package]] -name = "generic-array" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] name = "gethostname" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1067,29 +996,6 @@ dependencies = [ ] [[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "http" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - -[[package]] name = "ident_case" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1464,22 +1370,6 @@ dependencies = [ ] [[package]] -name = "nostr_rust" -version = "0.3.0" -source = "git+git://jb55.com/nostr_rust?rev=ccf7e521fe3bb9ca8f86516aef2c1f71db0213ed#ccf7e521fe3bb9ca8f86516aef2c1f71db0213ed" -dependencies = [ - "hex", - "rand", - "secp256k1", - "serde", - "serde_derive", - "serde_json", - "sha256", - "tungstenite", - "url", -] - -[[package]] name = "num-integer" version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1576,18 +1466,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" [[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] name = "osmesa-sys" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1694,12 +1572,6 @@ dependencies = [ ] [[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] name = "proc-macro-crate" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1729,36 +1601,6 @@ dependencies = [ ] [[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] name = "raw-window-handle" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1910,27 +1752,6 @@ dependencies = [ ] [[package]] -name = "rustls-native-certs" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50" -dependencies = [ - "openssl-probe", - "rustls-pemfile", - "schannel", - "security-framework", -] - -[[package]] -name = "rustls-pemfile" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" -dependencies = [ - "base64", -] - -[[package]] name = "rustybuzz" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1971,16 +1792,6 @@ dependencies = [ ] [[package]] -name = "schannel" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" -dependencies = [ - "lazy_static", - "windows-sys", -] - -[[package]] name = "scoped-tls" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2021,62 +1832,19 @@ dependencies = [ ] [[package]] -name = "secp256k1" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff55dc09d460954e9ef2fa8a7ced735a964be9981fd50e870b2b3b0705e14964" -dependencies = [ - "bitcoin_hashes", - "rand", - "secp256k1-sys", -] - -[[package]] -name = "secp256k1-sys" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83080e2c2fc1006e625be82e5d1eb6a43b7fd9578b617fcc55814daf286bba4b" -dependencies = [ - "cc", -] - -[[package]] -name = "security-framework" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] name = "serde" -version = "1.0.143" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.143" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3d8e8de557aee63c26b85b947f5e59b690d0454c753f3adeb5cd7835ab88391" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" dependencies = [ "proc-macro2", "quote", @@ -2116,40 +1884,6 @@ dependencies = [ ] [[package]] -name = "sha-1" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.5", -] - -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", -] - -[[package]] -name = "sha256" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e334db67871c14c18fc066ad14af13f9fdf5f9a91c61af432d1e3a39c8c6a141" -dependencies = [ - "hex", - "sha2", -] - -[[package]] name = "sharded-slab" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2484,34 +2218,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff" [[package]] -name = "tungstenite" -version = "0.17.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0" -dependencies = [ - "base64", - "byteorder", - "bytes", - "http", - "httparse", - "log", - "rand", - "rustls", - "rustls-native-certs", - "sha-1", - "thiserror", - "url", - "utf-8", - "webpki", -] - -[[package]] -name = "typenum" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" - -[[package]] name = "unicode-bidi" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2624,12 +2330,6 @@ dependencies = [ ] [[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - -[[package]] name = "valuable" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml @@ -12,11 +12,13 @@ rust-version = "1.60" egui = "0.19.0" eframe = { version = "0.19.0", features = ["persistence"] } serde = { version = "1", features = ["derive"] } # You only need this if you want app persistence -nostr_rust = { git = "git://jb55.com/nostr_rust", rev = "ccf7e521fe3bb9ca8f86516aef2c1f71db0213ed" } +#nostr_rust = { git = "git://jb55.com/nostr_rust", rev = "ccf7e521fe3bb9ca8f86516aef2c1f71db0213ed" } ehttp = "0.2.0" image = { version = "0.24", features = ["jpeg", "png", "webp"] } egui_extras = { version = "0.19.0", features = ["image", "svg"] } poll-promise = "0.2.0" +serde_json = { version = "1", default-features = false, features = ["std"] } +serde_derive = "1" # native: [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/src/app.rs b/src/app.rs @@ -1,10 +1,12 @@ use egui::{Align, Layout, RichText, WidgetText}; use egui_extras::RetainedImage; -use nostr_rust::events::Event; +//use nostr_rust::events::Event; use poll_promise::Promise; use std::borrow::{Borrow, Cow}; use std::collections::HashMap; +use crate::Event; + type ImageCache = HashMap<String, Promise<ehttp::Result<RetainedImage>>>; /// We derive Deserialize/Serialize so we can persist app state on shutdown. @@ -57,7 +59,7 @@ impl Damus { fn parse_response(response: ehttp::Response) -> Result<RetainedImage, String> { let content_type = response.content_type().unwrap_or_default(); - if content_type.starts_with("image/svg+xml") { + if content_type.starts_with("image/svg") { RetainedImage::from_svg_bytes(&response.url, &response.bytes) } else if content_type.starts_with("image/") { RetainedImage::from_image_bytes(&response.url, &response.bytes) @@ -99,29 +101,46 @@ fn render_pfp(ctx: &egui::Context, img_cache: &mut ImageCache, ui: &mut egui::Ui } } -fn render_event(ctx: &egui::Context, img_cache: &mut ImageCache, ui: &mut egui::Ui, ev: &Event) { - render_pfp( - ctx, - img_cache, - ui, - //"https://damus.io/img/damus.svg".into(), - "http://cdn.jb55.com/img/red-me.jpg".into(), - ); - ui.label(&ev.content); +fn render_username(ui: &mut egui::Ui, pk: &str) { + ui.horizontal(|ui| { + ui.spacing_mut().item_spacing.x = 0.0; + ui.label(&pk[0..8]); + ui.label(":"); + ui.label(&pk[64 - 8..]); + }); } -fn render_events(ctx: &egui::Context, app: &mut Damus, ui: &mut egui::Ui) { - for ev in &app.events { - ui.spacing_mut().item_spacing.y = 10.0; - render_event(ctx, &mut app.img_cache, ui, ev); - } +fn render_event(ctx: &egui::Context, img_cache: &mut ImageCache, ui: &mut egui::Ui, ev: &Event) { + ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| { + let damus_pic = "https://damus.io/img/damus.svg".into(); + let jb55_pic = "http://cdn.jb55.com/img/red-me.jpg".into(); + let pic = + if ev.pub_key == "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245" { + jb55_pic + } else { + damus_pic + }; + + render_pfp(ctx, img_cache, ui, pic); + + ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| { + render_username(ui, &ev.pub_key); + + ui.label(&ev.content); + }) + }); } fn timeline_view(ctx: &egui::Context, app: &mut Damus, ui: &mut egui::Ui) { + //let row_height = 100_f32; + //let total_rows = app.events.len(); ui.heading("Timeline"); - egui::ScrollArea::vertical().show(ui, |ui| { - render_events(ctx, app, ui); + egui::ScrollArea::both().show(ui, |ui| { + for ev in &app.events { + ui.separator(); + render_event(ctx, &mut app.img_cache, ui, ev); + } }); /* @@ -159,12 +178,8 @@ fn render_damus(ctx: &egui::Context, _frame: &mut eframe::Frame, app: &mut Damus egui::CentralPanel::default().show(ctx, |ui| { // The central panel the region left after adding TopPanel's and SidePanel's - ui.heading("eframe template"); - ui.hyperlink("https://github.com/emilk/eframe_template"); - ui.add(egui::github_link_file!( - "https://github.com/emilk/eframe_template/blob/master/", - "Source code." - )); + ui.heading("Damus Desktop"); + ui.hyperlink("https://damus.io"); egui::warn_if_debug_build(ui); }); } @@ -189,17 +204,30 @@ impl eframe::App for Damus { created_at: 1667781968, kind: 1, tags: vec![], - content: "yello\nthere".to_string(), + content: "yello\nthere\nbeep\nboop\nyoink".to_string(), + sig: "af02c971015995f79e07fa98aaf98adeeb6a56d0005e451ee4e78844cff712a6bc0f2109f72a878975f162dcefde4173b65ebd4c3d3ab3b520a9dcac6acf092d".to_string(), + }; + + let test_event2 = Event { + id: "6938e3cd841f3111dbdbd909f87fd52c3d1f1e4a07fd121d1243196e532811cb".to_string(), + pub_key: "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245".to_string(), + created_at: 1667781968, + kind: 1, + tags: vec![], + content: "yo yo\nwhats up\nnotmuch".to_string(), sig: "af02c971015995f79e07fa98aaf98adeeb6a56d0005e451ee4e78844cff712a6bc0f2109f72a878975f162dcefde4173b65ebd4c3d3ab3b520a9dcac6acf092d".to_string(), }; if self.events.len() == 0 { self.events.push(test_event.clone()); - println!("{}", &self.events[0].content); + self.events.push(test_event2.clone()); + self.events.push(test_event.clone()); + self.events.push(test_event2.clone()); + self.events.push(test_event.clone()); + self.events.push(test_event2.clone()); self.events.push(test_event.clone()); - println!("{}", &self.events[1].content); + self.events.push(test_event2.clone()); self.events.push(test_event.clone()); - println!("{}", &self.events[2].content); } render_damus(ctx, _frame, self); diff --git a/src/event.rs b/src/event.rs @@ -0,0 +1,23 @@ +use serde_derive::{Deserialize, Serialize}; +use serde_json::json; + +/// Event is the struct used to represent a Nostr event +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct Event { + /// 32-bytes sha256 of the the serialized event data + pub id: String, + /// 32-bytes hex-encoded public key of the event creator + #[serde(rename = "pubkey")] + pub pub_key: String, + /// unix timestamp in seconds + pub created_at: u64, + /// integer + /// 0: NostrEvent + pub kind: u8, + /// Tags + pub tags: Vec<Vec<String>>, + /// arbitrary string + pub content: String, + /// 64-bytes signature of the sha256 hash of the serialized event data, which is the same as the "id" field + pub sig: String, +} diff --git a/src/lib.rs b/src/lib.rs @@ -1,4 +1,6 @@ #![warn(clippy::all, rust_2018_idioms)] mod app; +mod event; pub use app::Damus; +pub use event::Event; diff --git a/src/main.rs b/src/main.rs @@ -9,7 +9,7 @@ fn main() { let native_options = eframe::NativeOptions::default(); eframe::run_native( - "eframe template", + "Damus Desktop", native_options, Box::new(|cc| Box::new(damus::Damus::new(cc))), );