Mark all messages as seen

This commit is contained in:
Joscha 2022-08-08 15:37:43 +02:00
parent 43247e2a5c
commit 573f231466
4 changed files with 35 additions and 2 deletions

View file

@ -124,6 +124,8 @@ impl MsgStore<LogMsg> for Logger {
} }
async fn set_seen(&self, _id: &usize, _seen: bool) {} async fn set_seen(&self, _id: &usize, _seen: bool) {}
async fn set_all_seen(&self, _seen: bool) {}
} }
impl Log for Logger { impl Log for Logger {

View file

@ -130,4 +130,5 @@ pub trait MsgStore<M: Msg> {
async fn older_msg_id(&self, id: &M::Id) -> Option<M::Id>; async fn older_msg_id(&self, id: &M::Id) -> Option<M::Id>;
async fn newer_msg_id(&self, id: &M::Id) -> Option<M::Id>; async fn newer_msg_id(&self, id: &M::Id) -> Option<M::Id>;
async fn set_seen(&self, id: &M::Id, seen: bool); async fn set_seen(&self, id: &M::Id, seen: bool);
async fn set_all_seen(&self, seen: bool);
} }

View file

@ -97,7 +97,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
pub fn list_action_key_bindings(&self, bindings: &mut KeyBindingsList) { pub fn list_action_key_bindings(&self, bindings: &mut KeyBindingsList) {
bindings.binding("s", "toggle current message's seen status"); bindings.binding("s", "toggle current message's seen status");
bindings.binding("S", "mark all visible messages as seen"); 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 { async fn handle_action_key_event(&mut self, event: KeyEvent, id: Option<&M::Id>) -> bool {
@ -116,6 +116,11 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
} }
return true; return true;
} }
key!(Ctrl + 'S') => {
// Ctrl + Shift + s, extra hard to hit accidentally
self.store.set_all_seen(true).await;
return true;
}
_ => {} _ => {}
} }
false false

View file

@ -267,6 +267,14 @@ impl MsgStore<SmallMessage> for EuphVault {
}; };
let _ = self.vault.tx.send(request.into()); 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 { pub(super) enum EuphRequest {
@ -364,6 +372,10 @@ pub(super) enum EuphRequest {
id: Snowflake, id: Snowflake,
seen: bool, seen: bool,
}, },
SetAllSeen {
room: String,
seen: bool,
},
} }
impl EuphRequest { impl EuphRequest {
@ -414,6 +426,7 @@ impl EuphRequest {
Self::get_newer_msg_id(conn, room, id, result) Self::get_newer_msg_id(conn, room, id, result)
} }
EuphRequest::SetSeen { room, id, seen } => Self::set_seen(conn, room, id, seen), 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 let Err(e) = result {
// If an error occurs here, the rest of the UI will likely panic and // If an error occurs here, the rest of the UI will likely panic and
@ -1008,4 +1021,16 @@ impl EuphRequest {
)?; )?;
Ok(()) 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(())
}
} }