Commit 44ab83f5c4
Unsigned
Layout: unified · split
src/room/buffer.rs +23 −3
| @@ -383,12 +383,21 @@ fn buffer_contains_tag(buffer: &Buffer, tag: &Cow<str>) -> bool { | ||
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | fn sanitize_thread_id(thread_root: &EventId) -> String { |
| 386 | thread_root | |
| 386 | const THREAD_ID_DISPLAY_CHARS: usize = 12; | |
| 387 | ||
| 388 | let mut sanitized: String = thread_root | |
| 387 | 389 | .as_str() |
| 388 | 390 | .trim_start_matches('$') |
| 389 | 391 | .chars() |
| 390 | 392 | .map(|c| if c.is_ascii_alphanumeric() { c } else { '_' }) |
| 391 | .collect() | |
| 393 | .take(THREAD_ID_DISPLAY_CHARS) | |
| 394 | .collect(); | |
| 395 | ||
| 396 | if sanitized.is_empty() { | |
| 397 | sanitized.push_str("unknown"); | |
| 398 | } | |
| 399 | ||
| 400 | sanitized | |
| 392 | 401 | } |
| 393 | 402 | |
| 394 | 403 | fn reply_sender_id_from_tags<T: AsRef<str>>(tags: &[T]) -> Option<OwnedUserId> { |
| @@ -508,6 +517,7 @@ mod tests { | ||
| 508 | 517 | |
| 509 | 518 | use super::{ |
| 510 | 519 | format_buffer_name, reply_sender_id_from_tags, sanitize_thread_id, |
| 520 | RoomBuffer, | |
| 511 | 521 | }; |
| 512 | 522 | |
| 513 | 523 | #[test] |
| @@ -555,7 +565,17 @@ mod tests { | ||
| 555 | 565 | fn sanitizes_thread_event_id_for_buffer_name() { |
| 556 | 566 | assert_eq!( |
| 557 | 567 | sanitize_thread_id(event_id!("$abc/def:example.org")), |
| 558 | "abc_def_example_org" | |
| 568 | "abc_def_exam" | |
| 569 | ); | |
| 570 | } | |
| 571 | ||
| 572 | #[test] | |
| 573 | fn thread_buffer_suffix_uses_short_human_id() { | |
| 574 | assert_eq!( | |
| 575 | RoomBuffer::thread_buffer_suffix(event_id!( | |
| 576 | "$abcdef0123456789:example.org" | |
| 577 | )), | |
| 578 | "abcdef012345" | |
| 559 | 579 | ); |
| 560 | 580 | } |
| 561 | 581 | } |
src/room/mod.rs −1
| @@ -825,7 +825,6 @@ impl MatrixRoom { | ||
| 825 | 825 | |
| 826 | 826 | buffer.set_localvar("room_id", self.room_id.as_str()); |
| 827 | 827 | buffer.set_localvar("thread_root", thread_root.as_str()); |
| 828 | buffer.set_localvar("type", "thread"); | |
| 829 | 828 | buffer.set_title(&format!( |
| 830 | 829 | "Thread {} in {}", |
| 831 | 830 | thread_root, room_short_name |