Commit bdc4031c08
bdc4031c0839a008ad1c815889e1c53cab71cd1b
parent: a05dcfd08a
Unsigned
Darafei Praliaskouski <me@komzpa.net> · 2026-07-31 12:43 UTC
committer: <strk@kbt.io>
fix: keep interactive history pages responsive
Layout: unified · split
src/commands/matrix.rs
+1 −1
| @@ -323,7 +323,7 @@ Use /matrix [command] help to find out more.\n", |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | Weechat::spawn(async move { |
| 326 | | let result = room.get_messages().await; |
| 326 | let result = room.get_interactive_history_page().await; |
| 327 | 327 | room.print_history_page_result(result); |
| 328 | 328 | }) |
| 329 | 329 | .detach(); |
src/connection.rs
+2 −2
| @@ -62,7 +62,6 @@ use crate::{ |
| 62 | 62 | |
| 63 | 63 | const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30); |
| 64 | 64 | const SSO_CALLBACK_PORT: u16 = 29_325; |
| 65 | | const HISTORY_BATCH_SIZE: u16 = 200; |
| 66 | 65 | |
| 67 | 66 | pub struct InteractiveAuthInfo { |
| 68 | 67 | pub user: String, |
| @@ -261,6 +260,7 @@ impl Connection { |
| 261 | 260 | &self, |
| 262 | 261 | room: Room, |
| 263 | 262 | prev_batch: PrevBatch, |
| 263 | limit: u16, |
| 264 | 264 | ) -> MatrixResult<Messages> { |
| 265 | 265 | self.spawn(async move { |
| 266 | 266 | let mut request = match &prev_batch { |
| @@ -271,7 +271,7 @@ impl Connection { |
| 271 | 271 | MessagesOptions::forward().from(Some(t.as_ref())) |
| 272 | 272 | } |
| 273 | 273 | }; |
| 274 | | request.limit = HISTORY_BATCH_SIZE.into(); |
| 274 | request.limit = limit.into(); |
| 275 | 275 | |
| 276 | 276 | room.messages(request).await |
| 277 | 277 | }) |
src/room/mod.rs
+21 −1
| @@ -130,6 +130,8 @@ pub enum HistoryPageResult { |
| 130 | 130 | |
| 131 | 131 | const HISTORY_PAGE_TAGS: [&str; 2] = |
| 132 | 132 | ["matrix_history_page", "matrix_smart_filter"]; |
| 133 | const RESTORED_HISTORY_BATCH_SIZE: u16 = 25; |
| 134 | const INTERACTIVE_HISTORY_BATCH_SIZE: u16 = 25; |
| 133 | 135 | |
| 134 | 136 | fn restored_prev_batch(prev_batch: Option<String>) -> Option<PrevBatch> { |
| 135 | 137 | // A restored SDK room does not always have a sync pagination token in its |
| @@ -1953,6 +1955,16 @@ impl MatrixRoom { |
| 1953 | 1955 | } |
| 1954 | 1956 | |
| 1955 | 1957 | pub async fn get_messages(&self) -> HistoryPageResult { |
| 1958 | self.get_messages_with_limit(RESTORED_HISTORY_BATCH_SIZE) |
| 1959 | .await |
| 1960 | } |
| 1961 | |
| 1962 | pub async fn get_interactive_history_page(&self) -> HistoryPageResult { |
| 1963 | self.get_messages_with_limit(INTERACTIVE_HISTORY_BATCH_SIZE) |
| 1964 | .await |
| 1965 | } |
| 1966 | |
| 1967 | async fn get_messages_with_limit(&self, limit: u16) -> HistoryPageResult { |
| 1956 | 1968 | let messages_lock = self.messages_in_flight.clone(); |
| 1957 | 1969 | |
| 1958 | 1970 | let connection = self.connection.borrow().as_ref().cloned(); |
| @@ -1977,7 +1989,9 @@ impl MatrixRoom { |
| 1977 | 1989 | let room = self.room(); |
| 1978 | 1990 | let room_id = room.room_id().to_owned(); |
| 1979 | 1991 | |
| 1980 | | if let Ok(r) = connection.room_messages(room, prev_batch).await { |
| 1992 | if let Ok(r) = |
| 1993 | connection.room_messages(room, prev_batch, limit).await |
| 1994 | { |
| 1981 | 1995 | let added = r.chunk.len(); |
| 1982 | 1996 | let exhausted = r.chunk.is_empty() || r.end.is_none(); |
| 1983 | 1997 | |
| @@ -2470,6 +2484,12 @@ mod tests { |
| 2470 | 2484 | )))); |
| 2471 | 2485 | } |
| 2472 | 2486 | |
| 2487 | #[test] |
| 2488 | fn interactive_history_pages_are_bounded() { |
| 2489 | assert_eq!(INTERACTIVE_HISTORY_BATCH_SIZE, 25); |
| 2490 | assert_eq!(RESTORED_HISTORY_BATCH_SIZE, 25); |
| 2491 | } |
| 2492 | |
| 2473 | 2493 | #[test] |
| 2474 | 2494 | fn history_page_markers_are_machine_readable_and_hideable() { |
| 2475 | 2495 | assert_eq!( |