From 573f23146667b23117106db607847cbacd5791cd Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 8 Aug 2022 15:37:43 +0200 Subject: [PATCH] Mark all messages as seen --- src/logger.rs | 2 ++ src/store.rs | 1 + src/ui/chat/tree.rs | 7 ++++++- src/vault/euph.rs | 27 ++++++++++++++++++++++++++- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/logger.rs b/src/logger.rs index fd4d30b..41a3d05 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -124,6 +124,8 @@ impl MsgStore for Logger { } async fn set_seen(&self, _id: &usize, _seen: bool) {} + + async fn set_all_seen(&self, _seen: bool) {} } impl Log for Logger { diff --git a/src/store.rs b/src/store.rs index 0e6cc33..81b32b6 100644 --- a/src/store.rs +++ b/src/store.rs @@ -130,4 +130,5 @@ pub trait MsgStore { async fn older_msg_id(&self, id: &M::Id) -> Option; async fn newer_msg_id(&self, id: &M::Id) -> Option; async fn set_seen(&self, id: &M::Id, seen: bool); + async fn set_all_seen(&self, seen: bool); } diff --git a/src/ui/chat/tree.rs b/src/ui/chat/tree.rs index 47cd576..ed740a9 100644 --- a/src/ui/chat/tree.rs +++ b/src/ui/chat/tree.rs @@ -97,7 +97,7 @@ impl> InnerTreeViewState { pub fn list_action_key_bindings(&self, bindings: &mut KeyBindingsList) { bindings.binding("s", "toggle current message's seen status"); bindings.binding("S", "mark all visible messages as seen"); - // bindings.binding("ctrl+S", "mark all messages as seen"); + bindings.binding("ctrl+S", "mark all messages as seen"); } async fn handle_action_key_event(&mut self, event: KeyEvent, id: Option<&M::Id>) -> bool { @@ -116,6 +116,11 @@ impl> InnerTreeViewState { } return true; } + key!(Ctrl + 'S') => { + // Ctrl + Shift + s, extra hard to hit accidentally + self.store.set_all_seen(true).await; + return true; + } _ => {} } false diff --git a/src/vault/euph.rs b/src/vault/euph.rs index b194ed2..19a0a31 100644 --- a/src/vault/euph.rs +++ b/src/vault/euph.rs @@ -267,6 +267,14 @@ impl MsgStore for EuphVault { }; let _ = self.vault.tx.send(request.into()); } + + async fn set_all_seen(&self, seen: bool) { + let request = EuphRequest::SetAllSeen { + room: self.room.clone(), + seen, + }; + let _ = self.vault.tx.send(request.into()); + } } pub(super) enum EuphRequest { @@ -364,6 +372,10 @@ pub(super) enum EuphRequest { id: Snowflake, seen: bool, }, + SetAllSeen { + room: String, + seen: bool, + }, } impl EuphRequest { @@ -414,6 +426,7 @@ impl EuphRequest { Self::get_newer_msg_id(conn, room, id, result) } EuphRequest::SetSeen { room, id, seen } => Self::set_seen(conn, room, id, seen), + EuphRequest::SetAllSeen { room, seen } => Self::set_all_seen(conn, room, seen), }; if let Err(e) = result { // If an error occurs here, the rest of the UI will likely panic and @@ -1004,7 +1017,19 @@ impl EuphRequest { WHERE room = :room AND id = :id ", - named_params! {":room": room, ":id": id, ":seen": seen}, + named_params! { ":room": room, ":id": id, ":seen": seen }, + )?; + Ok(()) + } + + fn set_all_seen(conn: &Connection, room: String, seen: bool) -> rusqlite::Result<()> { + conn.execute( + " + UPDATE euph_msgs + SET seen = :seen + WHERE room = :room + ", + named_params! { ":room": room, ":seen": seen }, )?; Ok(()) }