initial nostr code
This commit is contained in:
30
src/app.rs
30
src/app.rs
@@ -11,7 +11,7 @@ use std::collections::HashMap;
|
||||
use std::hash::Hash;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::Event;
|
||||
use enostr::{Event, RelayPool};
|
||||
|
||||
#[derive(Hash, Eq, PartialEq, Clone, Debug)]
|
||||
enum UrlKey<'a> {
|
||||
@@ -32,6 +32,9 @@ pub struct Damus<'a> {
|
||||
|
||||
n_panels: u32,
|
||||
|
||||
#[serde(skip)]
|
||||
pool: RelayPool,
|
||||
|
||||
#[serde(skip)]
|
||||
events: Vec<Event>,
|
||||
|
||||
@@ -49,6 +52,7 @@ impl Default for Damus<'_> {
|
||||
// Example stuff:
|
||||
label: "Hello World!".to_owned(),
|
||||
composing: false,
|
||||
pool: RelayPool::default(),
|
||||
events: vec![],
|
||||
img_cache: HashMap::new(),
|
||||
value: 2.7,
|
||||
@@ -63,6 +67,10 @@ pub fn is_mobile(ctx: &egui::Context) -> bool {
|
||||
}
|
||||
|
||||
fn damus_update(damus: &mut Damus, ctx: &Context) {
|
||||
render_damus(damus, ctx);
|
||||
}
|
||||
|
||||
fn render_damus(damus: &mut Damus, ctx: &Context) {
|
||||
if is_mobile(ctx) {
|
||||
render_damus_mobile(ctx, damus);
|
||||
} else {
|
||||
@@ -185,17 +193,17 @@ fn render_event(ui: &mut egui::Ui, img_cache: &mut ImageCache<'_>, ev: &Event) {
|
||||
//let damus_pic = "https://192.168.87.26/img/damus.svg".into();
|
||||
let jb55_pic = "https://cdn.jb55.com/img/red-me.jpg".into();
|
||||
//let jb55_pic = "http://192.168.87.26/img/red-me.jpg".into();
|
||||
let pic =
|
||||
if ev.pub_key == "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245" {
|
||||
jb55_pic
|
||||
} else {
|
||||
damus_pic
|
||||
};
|
||||
let pic = if ev.pubkey == "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"
|
||||
{
|
||||
jb55_pic
|
||||
} else {
|
||||
damus_pic
|
||||
};
|
||||
|
||||
render_pfp(ui, img_cache, &ev.pub_key, pic);
|
||||
render_pfp(ui, img_cache, &ev.pubkey, pic);
|
||||
|
||||
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
||||
render_username(ui, &ev.pub_key);
|
||||
render_username(ui, &ev.pubkey);
|
||||
|
||||
ui.label(&ev.content);
|
||||
})
|
||||
@@ -300,7 +308,7 @@ fn add_test_events(damus: &mut Damus<'_>) {
|
||||
|
||||
let test_event = Event {
|
||||
id: "6938e3cd841f3111dbdbd909f87fd52c3d1f1e4a07fd121d1243196e532811cb".to_string(),
|
||||
pub_key: "f0a6ff7f70b872de6d82c8daec692a433fd23b6a49f25923c6f034df715cdeec".to_string(),
|
||||
pubkey: "f0a6ff7f70b872de6d82c8daec692a433fd23b6a49f25923c6f034df715cdeec".to_string(),
|
||||
created_at: 1667781968,
|
||||
kind: 1,
|
||||
tags: vec![],
|
||||
@@ -310,7 +318,7 @@ fn add_test_events(damus: &mut Damus<'_>) {
|
||||
|
||||
let test_event2 = Event {
|
||||
id: "6938e3cd841f3111dbdbd909f87fd52c3d1f1e4a07fd121d1243196e532811cb".to_string(),
|
||||
pub_key: "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245".to_string(),
|
||||
pubkey: "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245".to_string(),
|
||||
created_at: 1667781968,
|
||||
kind: 1,
|
||||
tags: vec![],
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
use damus::Damus;
|
||||
use eframe;
|
||||
use log::info;
|
||||
|
||||
// Entry point for wasm
|
||||
//#[cfg(target_arch = "wasm32")]
|
||||
@@ -41,3 +40,4 @@ pub fn main() {
|
||||
.expect("failed to start eframe");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
12
src/error.rs
Normal file
12
src/error.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use enostr;
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub enum Error {
|
||||
Nostr(enostr::Error),
|
||||
}
|
||||
|
||||
impl From<enostr::Error> for Error {
|
||||
fn from(err: enostr::Error) -> Self {
|
||||
Error::Nostr(err)
|
||||
}
|
||||
}
|
||||
22
src/event.rs
22
src/event.rs
@@ -1,22 +0,0 @@
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
/// 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,
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
mod app;
|
||||
//mod camera;
|
||||
mod event;
|
||||
mod error;
|
||||
|
||||
pub use app::Damus;
|
||||
pub use event::Event;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, error::Error>;
|
||||
|
||||
//#[cfg(target_os = "android")]
|
||||
//use egui_android::run_android;
|
||||
|
||||
Reference in New Issue
Block a user