Mark all visible messages as seen
This commit is contained in:
parent
de569211f6
commit
43247e2a5c
2 changed files with 34 additions and 8 deletions
|
|
@ -36,6 +36,7 @@ struct InnerTreeViewState<M: Msg, S: MsgStore<M>> {
|
||||||
|
|
||||||
last_cursor: Cursor<M::Id>,
|
last_cursor: Cursor<M::Id>,
|
||||||
last_cursor_line: i32,
|
last_cursor_line: i32,
|
||||||
|
last_visible_msgs: Vec<M::Id>,
|
||||||
|
|
||||||
cursor: Cursor<M::Id>,
|
cursor: Cursor<M::Id>,
|
||||||
|
|
||||||
|
|
@ -53,6 +54,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
||||||
store,
|
store,
|
||||||
last_cursor: Cursor::Bottom,
|
last_cursor: Cursor::Bottom,
|
||||||
last_cursor_line: 0,
|
last_cursor_line: 0,
|
||||||
|
last_visible_msgs: vec![],
|
||||||
cursor: Cursor::Bottom,
|
cursor: Cursor::Bottom,
|
||||||
scroll: 0,
|
scroll: 0,
|
||||||
correction: None,
|
correction: None,
|
||||||
|
|
@ -94,25 +96,30 @@ 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 {
|
||||||
if let Some(id) = id {
|
|
||||||
match event {
|
match event {
|
||||||
key!('s') => {
|
key!('s') => {
|
||||||
|
if let Some(id) = id {
|
||||||
if let Some(msg) = self.store.tree(id).await.msg(id) {
|
if let Some(msg) = self.store.tree(id).await.msg(id) {
|
||||||
self.store.set_seen(id, !msg.seen()).await;
|
self.store.set_seen(id, !msg.seen()).await;
|
||||||
}
|
}
|
||||||
true
|
return true;
|
||||||
}
|
}
|
||||||
_ => false,
|
|
||||||
}
|
}
|
||||||
} else {
|
key!('S') => {
|
||||||
|
for id in &self.last_visible_msgs {
|
||||||
|
self.store.set_seen(id, true).await;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn list_edit_initiating_key_bindings(&self, bindings: &mut KeyBindingsList) {
|
pub fn list_edit_initiating_key_bindings(&self, bindings: &mut KeyBindingsList) {
|
||||||
bindings.empty();
|
bindings.empty();
|
||||||
|
|
|
||||||
|
|
@ -420,6 +420,23 @@ impl<M: Msg + ChatMsg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visible_msgs(frame: &Frame, blocks: &TreeBlocks<M::Id>) -> Vec<M::Id> {
|
||||||
|
let height: i32 = frame.size().height.into();
|
||||||
|
let first_line = 0;
|
||||||
|
let last_line = first_line + height - 1;
|
||||||
|
|
||||||
|
let mut result = vec![];
|
||||||
|
for block in blocks.blocks().iter() {
|
||||||
|
if Self::visible(block, first_line, last_line) {
|
||||||
|
if let BlockId::Msg(id) = &block.id {
|
||||||
|
result.push(id.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn relayout(&mut self, nick: &str, frame: &mut Frame) -> TreeBlocks<M::Id> {
|
pub async fn relayout(&mut self, nick: &str, frame: &mut Frame) -> TreeBlocks<M::Id> {
|
||||||
// The basic idea is this:
|
// The basic idea is this:
|
||||||
//
|
//
|
||||||
|
|
@ -472,6 +489,7 @@ impl<M: Msg + ChatMsg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
||||||
|
|
||||||
self.last_cursor = self.cursor.clone();
|
self.last_cursor = self.cursor.clone();
|
||||||
self.last_cursor_line = self.cursor_line(&blocks);
|
self.last_cursor_line = self.cursor_line(&blocks);
|
||||||
|
self.last_visible_msgs = Self::visible_msgs(frame, &blocks);
|
||||||
self.scroll = 0;
|
self.scroll = 0;
|
||||||
self.correction = None;
|
self.correction = None;
|
||||||
|
|
||||||
|
|
@ -488,6 +506,7 @@ impl<M: Msg + ChatMsg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
||||||
|
|
||||||
self.last_cursor = self.cursor.clone();
|
self.last_cursor = self.cursor.clone();
|
||||||
self.last_cursor_line = self.cursor_line(&blocks);
|
self.last_cursor_line = self.cursor_line(&blocks);
|
||||||
|
self.last_visible_msgs = Self::visible_msgs(frame, &blocks);
|
||||||
self.scroll = 0;
|
self.scroll = 0;
|
||||||
self.correction = None;
|
self.correction = None;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue