Commit 3b444ddcb3
Unsigned
Layout: unified · split
src/commands/matrix.rs +1 −1
| @@ -91,7 +91,7 @@ Use /matrix [command] help to find out more.\n", | |||
| 91 | .add_completion("sso-complete %(matrix_servers)") | 91 | .add_completion("sso-complete %(matrix_servers)") |
| 92 | .add_completion("thread") | 92 | .add_completion("thread") |
| 93 | .add_completion( | 93 | .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", |
| 95 | ); | 95 | ); |
| 96 | 96 | ||
| 97 | Command::new( | 97 | Command::new( |
src/room/mod.rs +55
| @@ -188,6 +188,30 @@ fn should_continue_restored_history( | |||
| 188 | && lines_after < RESTORED_HISTORY_TARGET_LINES | 188 | && lines_after < RESTORED_HISTORY_TARGET_LINES |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | fn has_history_page(prev_batch: &Option<PrevBatch>) -> bool { | ||
| 192 | prev_batch.is_some() | ||
| 193 | } | ||
| 194 | |||
| 195 | fn 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 | |||
| 191 | fn should_render_event(already_rendered: bool) -> bool { | 215 | fn should_render_event(already_rendered: bool) -> bool { |
| 192 | !already_rendered | 216 | !already_rendered |
| 193 | } | 217 | } |
| @@ -3262,6 +3286,37 @@ mod tests { | |||
| 3262 | assert!(!should_continue_restored_history(0, 13, false)); | 3286 | assert!(!should_continue_restored_history(0, 13, false)); |
| 3263 | } | 3287 | } |
| 3264 | 3288 | ||
| 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 | |||
| 3265 | #[test] | 3320 | #[test] |
| 3266 | fn already_rendered_events_are_not_printed_again() { | 3321 | fn already_rendered_events_are_not_printed_again() { |
| 3267 | assert!(should_render_event(false)); | 3322 | assert!(should_render_event(false)); |