From 26923745adf0a20e745b4f18064b8367f7f1af00 Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 9 Aug 2022 01:18:12 +0200 Subject: [PATCH] Show unseen message count in room status info --- src/ui/room.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/ui/room.rs b/src/ui/room.rs index 8bf4a2f..65619d5 100644 --- a/src/ui/room.rs +++ b/src/ui/room.rs @@ -119,8 +119,8 @@ impl EuphRoom { let status = self.status().await; let chat = match &status { - Some(Some(Status::Joined(joined))) => self.widget_with_nick_list(&status, joined), - _ => self.widget_without_nick_list(&status), + Some(Some(Status::Joined(joined))) => self.widget_with_nick_list(&status, joined).await, + _ => self.widget_without_nick_list(&status).await, }; match &self.state { State::Normal => chat, @@ -144,10 +144,10 @@ impl EuphRoom { } } - fn widget_without_nick_list(&self, status: &Option>) -> BoxedWidget { + async fn widget_without_nick_list(&self, status: &Option>) -> BoxedWidget { VJoin::new(vec![ Segment::new(Border::new( - Padding::new(self.status_widget(status)).horizontal(1), + Padding::new(self.status_widget(status).await).horizontal(1), )), // TODO Use last known nick? Segment::new(self.chat.widget(String::new())).expanding(true), @@ -155,7 +155,7 @@ impl EuphRoom { .into() } - fn widget_with_nick_list( + async fn widget_with_nick_list( &self, status: &Option>, joined: &Joined, @@ -163,7 +163,7 @@ impl EuphRoom { HJoin::new(vec![ Segment::new(VJoin::new(vec![ Segment::new(Border::new( - Padding::new(self.status_widget(status)).horizontal(1), + Padding::new(self.status_widget(status).await).horizontal(1), )), Segment::new(self.chat.widget(joined.session.name.clone())).expanding(true), ])) @@ -175,11 +175,12 @@ impl EuphRoom { .into() } - fn status_widget(&self, status: &Option>) -> BoxedWidget { + async fn status_widget(&self, status: &Option>) -> BoxedWidget { // TODO Include unread message count let room = self.chat.store().room(); let room_style = ContentStyle::default().bold().blue(); let mut info = Styled::new(format!("&{room}"), room_style); + info = match status { None => info.then_plain(", archive"), Some(None) => info.then_plain(", connecting..."), @@ -197,6 +198,15 @@ impl EuphRoom { } } }; + + let unseen = self.unseen_msgs_count().await; + if unseen > 0 { + info = info + .then_plain(" (") + .then(format!("{unseen}"), ContentStyle::default().bold().green()) + .then_plain(")"); + } + Text::new(info).into() }