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",
323323 }
324324
325325 Weechat::spawn(async move {
326 let result = room.get_messages().await;
326 let result = room.get_interactive_history_page().await;
327327 room.print_history_page_result(result);
328328 })
329329 .detach();
src/connection.rs +2 −2
@@ -62,7 +62,6 @@ use crate::{
6262
6363const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
6464const SSO_CALLBACK_PORT: u16 = 29_325;
65const HISTORY_BATCH_SIZE: u16 = 200;
6665
6766pub struct InteractiveAuthInfo {
6867 pub user: String,
@@ -261,6 +260,7 @@ impl Connection {
261260 &self,
262261 room: Room,
263262 prev_batch: PrevBatch,
263 limit: u16,
264264 ) -> MatrixResult<Messages> {
265265 self.spawn(async move {
266266 let mut request = match &prev_batch {
@@ -271,7 +271,7 @@ impl Connection {
271271 MessagesOptions::forward().from(Some(t.as_ref()))
272272 }
273273 };
274 request.limit = HISTORY_BATCH_SIZE.into();
274 request.limit = limit.into();
275275
276276 room.messages(request).await
277277 })
src/room/mod.rs +21 −1
@@ -130,6 +130,8 @@ pub enum HistoryPageResult {
130130
131131const HISTORY_PAGE_TAGS: [&str; 2] =
132132 ["matrix_history_page", "matrix_smart_filter"];
133const RESTORED_HISTORY_BATCH_SIZE: u16 = 25;
134const INTERACTIVE_HISTORY_BATCH_SIZE: u16 = 25;
133135
134136fn restored_prev_batch(prev_batch: Option<String>) -> Option<PrevBatch> {
135137 // A restored SDK room does not always have a sync pagination token in its
@@ -1953,6 +1955,16 @@ impl MatrixRoom {
19531955 }
19541956
19551957 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 {
19561968 let messages_lock = self.messages_in_flight.clone();
19571969
19581970 let connection = self.connection.borrow().as_ref().cloned();
@@ -1977,7 +1989,9 @@ impl MatrixRoom {
19771989 let room = self.room();
19781990 let room_id = room.room_id().to_owned();
19791991
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 {
19811995 let added = r.chunk.len();
19821996 let exhausted = r.chunk.is_empty() || r.end.is_none();
19831997
@@ -2470,6 +2484,12 @@ mod tests {
24702484 ))));
24712485 }
24722486
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
24732493 #[test]
24742494 fn history_page_markers_are_machine_readable_and_hideable() {
24752495 assert_eq!(