Commit 3b444ddcb3

3b444ddcb39559b0b984441d136dc2e3b22a3554

parent: 88f3bc7057

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-07-31 11:55 UTC
committer: <strk@kbt.io>

feat: add headless Matrix history paging command

(cherry picked from commit a95a6fad6249cb01b1133d98e7271d38f62a66b3)

Layout: unified · split

src/commands/matrix.rs +1 −1
@@ -91,7 +91,7 @@ Use /matrix [command] help to find out more.\n",
9191 .add_completion("sso-complete %(matrix_servers)")
9292 .add_completion("thread")
9393 .add_completion(
94 "help server|connect|disconnect|reconnect|join|sso-complete|read|thread|version|keys|devices|media|verify|verification",
94 "help server|connect|disconnect|reconnect|join|sso-complete|history|read|thread|version|keys|devices|media|verify|verification",
9595 );
9696
9797 Command::new(
src/room/mod.rs +55
@@ -188,6 +188,30 @@ fn should_continue_restored_history(
188188 && lines_after < RESTORED_HISTORY_TARGET_LINES
189189}
190190
191fn has_history_page(prev_batch: &Option<PrevBatch>) -> bool {
192 prev_batch.is_some()
193}
194
195fn history_page_marker(result: &HistoryPageResult) -> String {
196 match result {
197 HistoryPageResult::Page { added, exhausted } => format!(
198 "matrix_history_page added={} exhausted={}",
199 added,
200 u8::from(*exhausted),
201 ),
202 HistoryPageResult::Unavailable => {
203 "matrix_history_page added=0 exhausted=1 state=unavailable"
204 .to_owned()
205 }
206 HistoryPageResult::Busy => {
207 "matrix_history_page added=0 exhausted=0 state=busy".to_owned()
208 }
209 HistoryPageResult::Failed => {
210 "matrix_history_page added=0 exhausted=0 state=failed".to_owned()
211 }
212 }
213}
214
191215fn should_render_event(already_rendered: bool) -> bool {
192216 !already_rendered
193217}
@@ -3262,6 +3286,37 @@ mod tests {
32623286 assert!(!should_continue_restored_history(0, 13, false));
32633287 }
32643288
3289 #[test]
3290 fn history_paging_requires_an_available_cursor() {
3291 assert!(!has_history_page(&None));
3292 assert!(has_history_page(&Some(PrevBatch::Backwards(None))));
3293 assert!(has_history_page(&Some(PrevBatch::Backwards(Some(
3294 "token".to_owned()
3295 )))));
3296 assert!(has_history_page(&Some(PrevBatch::Forward(
3297 "token".to_owned()
3298 ))));
3299 }
3300
3301 #[test]
3302 fn history_page_markers_are_machine_readable_and_hideable() {
3303 assert_eq!(
3304 HISTORY_PAGE_TAGS,
3305 ["matrix_history_page", "matrix_smart_filter"]
3306 );
3307 assert_eq!(
3308 history_page_marker(&HistoryPageResult::Page {
3309 added: 25,
3310 exhausted: false,
3311 }),
3312 "matrix_history_page added=25 exhausted=0"
3313 );
3314 assert_eq!(
3315 history_page_marker(&HistoryPageResult::Unavailable),
3316 "matrix_history_page added=0 exhausted=1 state=unavailable"
3317 );
3318 }
3319
32653320 #[test]
32663321 fn already_rendered_events_are_not_printed_again() {
32673322 assert!(should_render_event(false));