Skip to content

Commit

Permalink
Fix a message scroll bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkulak committed Apr 22, 2023
1 parent cd470b0 commit 8555e7f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ possible and there's no mouse support (yet, at least).

![Matui](https://github.com/pkulak/matui/blob/main/screenshot.png?raw=true "The main chat window.")

# Who should use this client?

Anyone who wants a very simple terminal Matrix client, but runs another client
somewhere else for the missing features. There are some very basic actions
that aren't supported at the moment, like joining rooms and moderation. Also,
many events are still not suported, like replies and threads (which are still
shown, but not formatted very well). Also, this project is very early, so you
need to be tolerant of some bugs.

# Keybindings

Modal UIs can be a bit overwhelming, but thankfully chat isn't terribly
Modal UIs can be a bit overwhelming, but thankfully chat, isn't terribly
complicated. Especially if you don't implement too many features.

## Chat Window

| Key | Description |
|-------|--------------------------------------------------------|
| Space | Show the room switcher. |
| j* | Select one message down. |
| k* | Select one message up. |
| j* | Select one line down. |
| k* | Select one line up. |
| i | Create a new message using the external editor. |
| Enter | Open the selected message (images, videos, urls, etc). |
| c | Edit the selected message in the external editor. |
Expand All @@ -26,14 +35,16 @@ complicated. Especially if you don't implement too many features.
| V | View the current room in the external editor. |
| u | Upload a file. |

\* arrow keys are fine too

## Rooms Window

| Key | Description |
|-----|-------------------------------------------------|
| j* | Select one room down. |
| k* | Select one room up. |
| i | Search for a room. |
| esc | Leave search mode. |
| esc | Leave search mode, or close the popup. |

\* arrow keys are fine too

# External Applications

Expand Down
3 changes: 3 additions & 0 deletions src/matrix/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ impl Matrix {

pub fn fetch_messages(&self, room: Joined, cursor: Option<String>) {
self.rt.spawn(async move {
Matrix::send(ProgressStarted("Fetching more messages.".to_string(), 1000));

// fetch the actual messages
let mut options = MessagesOptions::new(Direction::Backward);
options.limit = UInt::from(25_u16);
Expand All @@ -284,6 +286,7 @@ impl Matrix {
cursor: messages.end,
};

Matrix::send(MatuiEvent::ProgressComplete);
Matrix::send(MatuiEvent::TimelineBatch(batch));
});
}
Expand Down
13 changes: 8 additions & 5 deletions src/widgets/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct Chat {
next_cursor: Option<String>,
fetching: Cell<bool>,
width: Cell<usize>,
total_list_items: Cell<usize>,
focus: bool,
delete_combo: KeyCombo,

Expand All @@ -68,6 +69,7 @@ impl Chat {
next_cursor: None,
fetching: Cell::new(true),
width: Cell::new(80),
total_list_items: Cell::new(0),
focus: true,
delete_combo: KeyCombo::new(vec!['d', 'd']),
members: vec![],
Expand Down Expand Up @@ -437,10 +439,10 @@ impl Chat {
}

let state = self.list_state.take();
let buffer = self.messages.len() - state.selected().unwrap_or_default();
let buffer = self.total_list_items.get() - state.selected().unwrap_or_default();
self.list_state.set(state);

if buffer < 25 {
if buffer < 100 {
self.matrix
.fetch_messages(self.room(), self.next_cursor.clone());
self.fetching.set(true);
Expand All @@ -453,8 +455,8 @@ impl Chat {

let i = match state.selected() {
Some(i) => {
if i >= &self.messages.len() - 1 {
&self.messages.len() - 1
if i >= &self.total_list_items.get() - 1 {
&self.total_list_items.get() - 1
} else {
i + 1
}
Expand Down Expand Up @@ -651,8 +653,9 @@ impl Widget for ChatWidget<'_> {
.flat_map(|m| m.to_list_items((area.width - 2) as usize))
.collect();

// make sure we save our last render width
// make sure we save our last render width and total items
self.chat.width.set((area.width - 2).into());
self.chat.total_list_items.set(items.len());

let mut list_state = self.chat.list_state.take();

Expand Down

0 comments on commit 8555e7f

Please sign in to comment.