From b918f0f31f7b25cc05135476deb738cb595a39bd Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 14 Jun 2022 10:30:08 +0200 Subject: [PATCH] Fix message order and cursor movement --- cove-tui/src/chat/tree.rs | 2 +- cove-tui/src/store.rs | 7 ++++++- cove-tui/src/ui.rs | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cove-tui/src/chat/tree.rs b/cove-tui/src/chat/tree.rs index ed753cf..8b686e7 100644 --- a/cove-tui/src/chat/tree.rs +++ b/cove-tui/src/chat/tree.rs @@ -111,7 +111,7 @@ impl TreeView { let path = store.path(room, &cursor.id).await; let tree = store.tree(room, path.first()).await; if let Some(prev_sibling) = tree.prev_sibling(&cursor.id) { - cursor.id = prev_sibling.clone(); + cursor.id = tree.last_child(prev_sibling.clone()); return; } else if let Some(parent) = tree.parent(&cursor.id) { cursor.id = parent; diff --git a/cove-tui/src/store.rs b/cove-tui/src/store.rs index 8f28bc6..b5aea3e 100644 --- a/cove-tui/src/store.rs +++ b/cove-tui/src/store.rs @@ -1,13 +1,14 @@ pub mod dummy; use std::collections::HashMap; +use std::fmt::Debug; use std::hash::Hash; use async_trait::async_trait; use chrono::{DateTime, Utc}; pub trait Msg { - type Id: Clone + Hash + Eq; + type Id: Clone + Debug + Hash + Eq + Ord; fn id(&self) -> Self::Id; fn parent(&self) -> Option; @@ -63,6 +64,10 @@ impl Tree { } } + for list in children.values_mut() { + list.sort_unstable(); + } + Self { root, msgs, diff --git a/cove-tui/src/ui.rs b/cove-tui/src/ui.rs index 2749657..8ee1f3a 100644 --- a/cove-tui/src/ui.rs +++ b/cove-tui/src/ui.rs @@ -46,7 +46,12 @@ impl Ui { let store = DummyStore::new() .msg(DummyMsg::new(1, "nick", "content")) .msg(DummyMsg::new(2, "Some1Else", "reply").parent(1)) - .msg(DummyMsg::new(4, "nick", "reply to nothing").parent(3)); + .msg(DummyMsg::new(3, "Some1Else", "deeper reply").parent(2)) + .msg(DummyMsg::new(4, "abc123", "even deeper reply").parent(3)) + .msg(DummyMsg::new(5, "Some1Else", "another reply").parent(1)) + .msg(DummyMsg::new(7, "nick", "reply to nothing").parent(6)) + .msg(DummyMsg::new(8, "nick", "another reply to nothing").parent(6)) + .msg(DummyMsg::new(9, "abc123", "reply to reply to nothing").parent(7)); let chat = Chat::new(store, "testroom".to_string()); // Run main UI.