From 697985d7ca935b250cb2fbdd522b11f49bdb2d4b Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 31 Dec 2023 13:38:24 +0000 Subject: [PATCH] UNTESTED: go to Read Mentions if user is mentioned. Annoyingly, I can't test this on the dev instance, because its streaming API doesn't work! --- src/activity_stack.rs | 10 ++++++++++ src/tui.rs | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/activity_stack.rs b/src/activity_stack.rs index 9f44223..7136ba4 100644 --- a/src/activity_stack.rs +++ b/src/activity_stack.rs @@ -41,6 +41,16 @@ pub struct ActivityStack { util: Option, } +impl Activity { + pub fn throw_into_mentions(&self) -> bool { + // ReadMentions itself doesn't count. This will have to return + // false for post-editing activities. + match self { + _ => true, + } + } +} + impl ActivityStack { pub fn new() -> Self { ActivityStack { diff --git a/src/tui.rs b/src/tui.rs index 6f78573..5a17b81 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -344,9 +344,24 @@ impl Tui { }, Ok(SubthreadEvent::StreamEv(update)) => { match self.client.process_stream_update(update) { - Ok(feeds_updated) => - state.handle_feed_updates(feeds_updated, - &mut self.client), + Ok(feeds_updated) => { + match state.handle_feed_updates(feeds_updated, + &mut self.client) { + PhysicalAction::Beep => { + Self::beep()? + }, + + PhysicalAction::Exit => { + break 'outer Ok(()); + }, + + PhysicalAction::Error(err) => { + break 'outer Err(err); + }, + + PhysicalAction::Nothing => (), + } + }, // FIXME: errors here should go in the Error Log _ => (), @@ -501,12 +516,20 @@ impl TuiLogicalState { } fn handle_feed_updates(&mut self, feeds_updated: HashSet, - client: &mut Client) { - // FIXME: if the mentions feed is updated, we may need to - // actually change the activity stack to throw the user into - // Read Messages. - + client: &mut Client) -> PhysicalAction { self.activity_state.handle_feed_updates(&feeds_updated, client); + + if feeds_updated.contains(&FeedId::Mentions) { + if self.activity_stack.top().throw_into_mentions() { + self.activity_stack.goto(UtilityActivity::ReadMentions.into()); + self.changed_activity(client); + } + + // FIXME: we'd quite like a double-beep if you're in the composer + PhysicalAction::Beep + } else { + PhysicalAction::Nothing + } } fn changed_activity(&mut self, client: &mut Client) { -- 2.30.2