mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Feed date_ago
This commit is contained in:
parent
cb19731353
commit
b7e2e576e4
36
src/date_ago.rs
Normal file
36
src/date_ago.rs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
|
||||||
|
use nostr_proto::Unixtime;
|
||||||
|
|
||||||
|
pub fn date_ago(then: Unixtime) -> String {
|
||||||
|
let now = Unixtime::now().unwrap();
|
||||||
|
let seconds = now.0 - then.0;
|
||||||
|
let minutes: f32 = seconds as f32 / 60.0;
|
||||||
|
let hours: f32 = minutes / 60.0;
|
||||||
|
let days: f32 = hours / 24.0;
|
||||||
|
let years: f32 = days / 365.0;
|
||||||
|
|
||||||
|
if seconds < 45 {
|
||||||
|
format!("{}s", seconds)
|
||||||
|
} else if seconds < 90 {
|
||||||
|
"1m".to_string()
|
||||||
|
}
|
||||||
|
else if minutes < 45.0 {
|
||||||
|
format!("{}m", minutes as i64)
|
||||||
|
} else if minutes < 90.0 {
|
||||||
|
"1h".to_string()
|
||||||
|
} else if hours < 24.0 {
|
||||||
|
format!("{}h", hours as i64)
|
||||||
|
} else if hours < 42.0 {
|
||||||
|
"1d".to_string()
|
||||||
|
} else if days < 30.0 {
|
||||||
|
format!("{}d", days as i64)
|
||||||
|
} else if days < 45.0 {
|
||||||
|
"1m".to_string()
|
||||||
|
} else if days < 365.0 {
|
||||||
|
format!("{}m", (days/30.0) as i64)
|
||||||
|
} else if years < 1.5 {
|
||||||
|
"1y".to_string()
|
||||||
|
} else {
|
||||||
|
format!("{}y", years as i64)
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ extern crate lazy_static;
|
|||||||
|
|
||||||
mod about;
|
mod about;
|
||||||
mod comms;
|
mod comms;
|
||||||
|
mod date_ago;
|
||||||
mod db;
|
mod db;
|
||||||
mod error;
|
mod error;
|
||||||
mod event_related;
|
mod event_related;
|
||||||
|
@ -12,12 +12,15 @@ pub(super) fn update(_app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fr
|
|||||||
|
|
||||||
|
|
||||||
ScrollArea::vertical().show(ui, |ui| {
|
ScrollArea::vertical().show(ui, |ui| {
|
||||||
for id in feed.iter() {
|
for id in feed.iter().rev() {
|
||||||
// Stop rendering at the bottom of the window:
|
// Stop rendering at the bottom of the window:
|
||||||
let pos2 = ui.next_widget_position();
|
let pos2 = ui.next_widget_position();
|
||||||
if pos2.y > screen_rect.max.y { break; }
|
if pos2.y > screen_rect.max.y { break; }
|
||||||
|
|
||||||
if let Some(event) = crate::globals::GLOBALS.events.blocking_lock().get(id) {
|
if let Some(event) = crate::globals::GLOBALS.events.blocking_lock().get(id) {
|
||||||
|
|
||||||
|
ui.label(crate::date_ago::date_ago(event.created_at));
|
||||||
|
|
||||||
if let Some(person) = crate::globals::GLOBALS.people.blocking_lock().get(&event.pubkey) {
|
if let Some(person) = crate::globals::GLOBALS.people.blocking_lock().get(&event.pubkey) {
|
||||||
if let Some(name) = &person.name {
|
if let Some(name) = &person.name {
|
||||||
ui.label(&format!("{}", name));
|
ui.label(&format!("{}", name));
|
||||||
|
Loading…
Reference in New Issue
Block a user