feat(note-view): show note client

This commit is contained in:
Fernando López Guevara
2025-07-01 13:44:56 -03:00
parent cb5bd75236
commit 4bf75c95de
14 changed files with 113 additions and 53 deletions

View File

@@ -6,6 +6,7 @@ use tracing::error;
pub struct Args {
pub relays: Vec<String>,
pub is_mobile: Option<bool>,
pub show_note_client: bool,
pub keys: Vec<Keypair>,
pub light: bool,
pub debug: bool,
@@ -28,6 +29,7 @@ impl Args {
is_mobile: None,
keys: vec![],
light: false,
show_note_client: false,
debug: false,
relay_debug: false,
tests: false,
@@ -116,6 +118,8 @@ impl Args {
res.use_keystore = false;
} else if arg == "--relay-debug" {
res.relay_debug = true;
} else if arg == "--show-note-client" {
res.show_note_client = true;
} else {
unrecognized_args.insert(arg.clone());
}

View File

@@ -193,3 +193,19 @@ where
|rnid| Ok(RootNoteId::new_unsafe(rnid.id)),
)
}
pub fn event_tag<'a>(ev: &nostrdb::Note<'a>, name: &str) -> Option<&'a str> {
ev.tags().iter().find_map(|tag| {
if tag.count() < 2 {
return None;
}
let cur_name = tag.get_str(0)?;
if cur_name != name {
return None;
}
tag.get_str(1)
})
}

View File

@@ -33,18 +33,28 @@ impl NoteCache {
#[derive(Clone)]
pub struct CachedNote {
reltime: TimeCached<String>,
pub client: Option<String>,
pub reply: NoteReplyBuf,
}
impl CachedNote {
pub fn new(note: &Note<'_>) -> Self {
pub fn new(note: &Note) -> Self {
use crate::note::event_tag;
let created_at = note.created_at();
let reltime = TimeCached::new(
Duration::from_secs(1),
Box::new(move || time_ago_since(created_at)),
);
let reply = NoteReply::new(note.tags()).to_owned();
CachedNote { reltime, reply }
let client = event_tag(note, "client");
CachedNote {
client: client.map(|c| c.to_string()),
reltime,
reply,
}
}
pub fn reltime_str_mut(&mut self) -> &str {

View File

@@ -64,23 +64,6 @@ impl Zap {
}
}
#[allow(dead_code)]
pub fn event_tag<'a>(ev: nostrdb::Note<'a>, name: &str) -> Option<&'a str> {
ev.tags().iter().find_map(|tag| {
if tag.count() < 2 {
return None;
}
let cur_name = tag.get_str(0)?;
if cur_name != name {
return None;
}
tag.get_str(1)
})
}
fn determine_zap_target(tags: &ZapTags) -> Option<ZapTarget> {
if let Some(note_zapped) = tags.note_zapped {
Some(ZapTarget::Note(NoteZapTarget {