Commit 44ab83f5c4

44ab83f5c447aa9bb96c4a86f473ae88fd9206bf

parent: 0ebc487ddd

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-07-21 21:58 UTC
committer: <strk@kbt.io>

fix: tidy thread buffer presentation

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
385fn sanitize_thread_id(thread_root: &EventId) -> String { 385fn 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 .as_str() 389 .as_str()
388 .trim_start_matches('$') 390 .trim_start_matches('$')
389 .chars() 391 .chars()
390 .map(|c| if c.is_ascii_alphanumeric() { c } else { '_' }) 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
394fn reply_sender_id_from_tags<T: AsRef<str>>(tags: &[T]) -> Option<OwnedUserId> { 403fn reply_sender_id_from_tags<T: AsRef<str>>(tags: &[T]) -> Option<OwnedUserId> {
@@ -508,6 +517,7 @@ mod tests {
508 517
509 use super::{ 518 use super::{
510 format_buffer_name, reply_sender_id_from_tags, sanitize_thread_id, 519 format_buffer_name, reply_sender_id_from_tags, sanitize_thread_id,
520 RoomBuffer,
511 }; 521 };
512 522
513 #[test] 523 #[test]
@@ -555,7 +565,17 @@ mod tests {
555 fn sanitizes_thread_event_id_for_buffer_name() { 565 fn sanitizes_thread_event_id_for_buffer_name() {
556 assert_eq!( 566 assert_eq!(
557 sanitize_thread_id(event_id!("$abc/def:example.org")), 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 buffer.set_localvar("room_id", self.room_id.as_str()); 826 buffer.set_localvar("room_id", self.room_id.as_str());
827 buffer.set_localvar("thread_root", thread_root.as_str()); 827 buffer.set_localvar("thread_root", thread_root.as_str());
828 buffer.set_localvar("type", "thread");
829 buffer.set_title(&format!( 828 buffer.set_title(&format!(
830 "Thread {} in {}", 829 "Thread {} in {}",
831 thread_root, room_short_name 830 thread_root, room_short_name