initial navigation

This commit is contained in:
William Casarin
2024-06-04 01:51:30 -05:00
parent bff0f3f628
commit 0dd33c90e7
16 changed files with 528 additions and 576 deletions

View File

@@ -11,7 +11,6 @@ serde_derive = "1"
serde = { version = "1", features = ["derive"] } # You only need this if you want app persistence
serde_json = "1.0.89"
tracing = "0.1.37"
shatter = "0.1.1"
nostr = { version = "0.30.0" }
hex = "0.4.3"
log = "0.4.20"

View File

@@ -3,6 +3,7 @@ mod error;
mod event;
mod filter;
mod keypair;
mod note;
mod profile;
mod pubkey;
mod relay;
@@ -14,6 +15,7 @@ pub use ewebsock;
pub use filter::Filter;
pub use keypair::{FullKeypair, Keypair};
pub use nostr::SecretKey;
pub use note::NoteId;
pub use profile::Profile;
pub use pubkey::Pubkey;
pub use relay::message::{RelayEvent, RelayMessage};

View File

@@ -1,87 +1,12 @@
use crate::Event;
use shatter::shard::Shards;
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct NoteId([u8; 32]);
#[derive(Debug, Eq, PartialEq)]
struct RefId(i32);
impl NoteId {
pub fn new(bytes: [u8; 32]) -> Self {
NoteId(bytes)
}
struct Ref<'a> {
ref_tag: u8,
relay_id: Option<&'a str>,
id: &'a str,
}
impl<'a> RefId {
fn get_ref(self, tags: &'a Vec<Vec<String>>) -> Option<Ref<'a>> {
let ind = self.0 as usize;
if ind > tags.len() - 1 {
return None;
}
let tag = &tags[ind];
if tag.len() < 2 {
return None;
}
if tag[0].len() != 1 {
return None;
}
let ref_tag = if let Some(rtag) = tag[0].as_bytes().first() {
*rtag
} else {
0
};
let id = &tag[1];
if id.len() != 64 {
return None;
}
let relay_id = if tag[2].len() == 0 {
None
} else {
Some(&*tag[2])
};
Some(Ref {
ref_tag,
relay_id,
id,
})
pub fn bytes(&self) -> &[u8; 32] {
&self.0
}
}
enum MentionType {
Pubkey,
Event,
}
struct Mention {
index: Option<i32>,
typ: MentionType,
refid: RefId,
}
enum EventRef {
Mention(Mention),
ThreadId(RefId),
Reply(RefId),
ReplyToRoot(RefId),
}
struct EventRefs {
refs: Vec<EventRef>,
}
struct DM {
decrypted: Option<String>,
shards: Shards,
}
struct Note {
event: NostrEvent,
shards: Shards,
refs: EventRef,
}