notedeck

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

commit f3201bee21ee678e8787410a618b6d1fc778fa41
parent 2ce2d4cc703c16824e89381e19577cca367e7d87
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 15 Feb 2024 13:56:07 -0800

ui: add reltime rendering

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

Diffstat:
Msrc/app.rs | 36+++++++++++++++++++++++++++++++-----
Msrc/notecache.rs | 4++++
2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/app.rs b/src/app.rs @@ -10,7 +10,7 @@ use crate::Result; use egui::containers::scroll_area::ScrollBarVisibility; use egui::widgets::Spinner; -use egui::{Color32, Context, Frame, Hyperlink, Image, Margin, RichText, TextureHandle}; +use egui::{Color32, Context, Frame, Hyperlink, Image, Label, Margin, RichText, TextureHandle}; use enostr::{ClientMessage, Filter, Pubkey, RelayEvent, RelayMessage}; use nostrdb::{ @@ -461,10 +461,10 @@ impl Damus { } } - pub fn get_note_cache_mut(&mut self, note_ref: &NoteRef) -> &mut NoteCache { + pub fn get_note_cache_mut(&mut self, note_key: NoteKey, created_at: u64) -> &mut NoteCache { self.note_cache - .entry(note_ref.key) - .or_insert_with(|| NoteCache::new(note_ref.created_at)) + .entry(note_key) + .or_insert_with(|| NoteCache::new(created_at)) } } @@ -702,7 +702,26 @@ fn render_note_contents( } } +fn render_reltime(ui: &mut egui::Ui, note_cache: &mut NoteCache) { + #[cfg(feature = "profiling")] + puffin::profile_function!(); + + ui.add(Label::new( + RichText::new("⋅") + .size(10.0) + .color(ui.visuals().weak_text_color()), + )); + ui.add(Label::new( + RichText::new(note_cache.reltime_str()) + .size(10.0) + .color(ui.visuals().weak_text_color()), + )); +} + fn render_note(ui: &mut egui::Ui, damus: &mut Damus, note_key: NoteKey) -> Result<()> { + #[cfg(feature = "profiling")] + puffin::profile_function!(); + let txn = Transaction::new(&damus.ndb)?; let note = damus.ndb.get_note_by_key(&txn, note_key)?; @@ -722,7 +741,14 @@ fn render_note(ui: &mut egui::Ui, damus: &mut Damus, note_key: NoteKey) -> Resul } ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| { - render_username(ui, profile.as_ref().ok(), note.pubkey()); + ui.horizontal(|ui| { + ui.spacing_mut().item_spacing.x = 2.0; + + render_username(ui, profile.as_ref().ok(), note.pubkey()); + + let note_cache = damus.get_note_cache_mut(note_key, note.created_at()); + render_reltime(ui, note_cache); + }); render_note_contents(ui, damus, &txn, &note, note_key); }) diff --git a/src/notecache.rs b/src/notecache.rs @@ -14,4 +14,8 @@ impl NoteCache { ); NoteCache { reltime } } + + pub fn reltime_str(&mut self) -> &str { + return &self.reltime.get(); + } }