event_new tracking/highlighting

This commit is contained in:
Mike Dilger 2022-12-30 16:37:59 +13:00
parent bd7363b40e
commit 11784b33eb
4 changed files with 123 additions and 96 deletions

View File

@ -66,6 +66,9 @@ pub struct Globals {
/// Dismissed Events
pub dismissed: RwLock<Vec<Id>>,
/// Event is new
pub event_is_new: RwLock<Vec<Id>>,
/// Feed
pub feed: Mutex<Feed>,
}
@ -95,6 +98,7 @@ lazy_static! {
settings: RwLock::new(Settings::default()),
signer: RwLock::new(Signer::default()),
dismissed: RwLock::new(Vec::new()),
event_is_new: RwLock::new(Vec::new()),
feed: Mutex::new(Feed::new()),
}
};

View File

@ -484,6 +484,9 @@ impl Overlord {
self.post_reply(content, reply_to).await?;
}
"process_incoming_events" => {
// Clear new events
GLOBALS.event_is_new.write().await.clear();
let _ = tokio::spawn(async move {
for (event, url) in GLOBALS.incoming_events.write().await.drain(..) {
let _ =

View File

@ -263,5 +263,8 @@ pub async fn process_new_event(
// FIXME: Handle EventKind::ContactList
// Save in event_is_new
GLOBALS.event_is_new.write().await.push(event.id);
Ok(())
}

View File

@ -148,7 +148,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
fn render_post(
app: &mut GossipUi,
_ctx: &Context,
ctx: &Context,
_frame: &mut eframe::Frame,
ui: &mut Ui,
id: Id,
@ -206,6 +206,22 @@ fn render_post(
let threaded = GLOBALS.settings.blocking_read().view_threaded;
#[allow(clippy::collapsible_else_if)]
let bgcolor = if GLOBALS.event_is_new.blocking_read().contains(&event.id) {
if ctx.style().visuals.dark_mode {
Color32::from_rgb(60, 0, 0)
} else {
Color32::LIGHT_YELLOW
}
} else {
if ctx.style().visuals.dark_mode {
Color32::BLACK
} else {
Color32::WHITE
}
};
Frame::none().fill(bgcolor).show(ui, |ui| {
ui.horizontal(|ui| {
// Indents first (if threaded)
if threaded {
@ -317,12 +333,13 @@ fn render_post(
}
});
});
});
ui.separator();
if threaded && !as_reply_to && !app.hides.contains(&id) {
for reply_id in replies {
render_post(app, _ctx, _frame, ui, reply_id, indent + 1, as_reply_to);
render_post(app, ctx, _frame, ui, reply_id, indent + 1, as_reply_to);
}
}
}