Commit da31ced299

da31ced299f251a9d42041bf562ebf0c89db465b

parent: 571b803664

Unsigned

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

feat: mark space buffers in names

Layout: unified · split

README.md +3
@@ -187,6 +187,9 @@ The inactivity delay defaults to five minutes and can be changed with:
187 187
188# Matrix Spaces 188# Matrix Spaces
189 189
190Space buffers use a `+` prefix in their short name, while ordinary room buffers
191keep the `#` prefix and direct-message buffers stay unprefixed.
192
190Room buffers expose Matrix parent Spaces as WeeChat local variables. Switch to a 193Room buffers expose Matrix parent Spaces as WeeChat local variables. Switch to a
191room buffer that belongs to a Space and run: 194room buffer that belongs to a Space and run:
192 195
src/room/buffer.rs +42 −11
@@ -390,6 +390,7 @@ impl RoomBuffer {
390 }; 390 };
391 let is_direct = 391 let is_direct =
392 self.runtime.block_on(room.is_direct()).unwrap_or(false); 392 self.runtime.block_on(room.is_direct()).unwrap_or(false);
393 let is_space = room.is_space();
393 394
394 let room_name = room 395 let room_name = room
395 .name() 396 .name()
@@ -407,7 +408,7 @@ impl RoomBuffer {
407 }) 408 })
408 .unwrap_or_else(|| room.room_id().to_string()); 409 .unwrap_or_else(|| room.room_id().to_string());
409 410
410 format_buffer_name(&room_name, is_direct) 411 format_buffer_name(&room_name, is_direct, is_space)
411 } 412 }
412 413
413 pub fn calculate_thread_buffer_name( 414 pub fn calculate_thread_buffer_name(
@@ -489,13 +490,35 @@ fn non_empty_room_name(name: &str) -> Option<String> {
489 } 490 }
490} 491}
491 492
492fn format_buffer_name(room_name: &str, is_direct: bool) -> String { 493fn format_buffer_name(
494 room_name: &str,
495 is_direct: bool,
496 is_space: bool,
497) -> String {
498 if is_direct || room_name.starts_with('!') {
499 return room_name.to_owned();
500 }
501
502 if is_space {
503 if room_name == "+" {
504 return "++".to_owned();
505 }
506
507 return room_name
508 .strip_prefix('#')
509 .map(|name| format!("+{}", name))
510 .unwrap_or_else(|| {
511 if room_name.starts_with('+') {
512 room_name.to_owned()
513 } else {
514 format!("+{}", room_name)
515 }
516 });
517 }
518
493 let room_name = if room_name == "#" { 519 let room_name = if room_name == "#" {
494 "##".to_owned() 520 "##".to_owned()
495 } else if room_name.starts_with('#') 521 } else if room_name.starts_with('#') {
496 || room_name.starts_with('!')
497 || is_direct
498 {
499 room_name.to_owned() 522 room_name.to_owned()
500 } else { 523 } else {
501 format!("#{}", room_name) 524 format!("#{}", room_name)
@@ -618,28 +641,36 @@ mod tests {
618 641
619 #[test] 642 #[test]
620 fn preserves_named_channel_prefix() { 643 fn preserves_named_channel_prefix() {
621 assert_eq!(format_buffer_name("OSGeo", false), "#OSGeo"); 644 assert_eq!(format_buffer_name("OSGeo", false, false), "#OSGeo");
622 } 645 }
623 646
624 #[test] 647 #[test]
625 fn preserves_direct_room_names() { 648 fn preserves_direct_room_names() {
626 assert_eq!(format_buffer_name("Alice", true), "Alice"); 649 assert_eq!(format_buffer_name("Alice", true, false), "Alice");
627 } 650 }
628 651
629 #[test] 652 #[test]
630 fn preserves_alias_like_names() { 653 fn preserves_alias_like_names() {
631 assert_eq!(format_buffer_name("#lounge", false), "#lounge"); 654 assert_eq!(format_buffer_name("#lounge", false, false), "#lounge");
632 assert_eq!(format_buffer_name("#", false), "##"); 655 assert_eq!(format_buffer_name("#", false, false), "##");
633 } 656 }
634 657
635 #[test] 658 #[test]
636 fn preserves_room_id_fallbacks() { 659 fn preserves_room_id_fallbacks() {
637 assert_eq!( 660 assert_eq!(
638 format_buffer_name("!roomid:matrix.osgeo.org", false), 661 format_buffer_name("!roomid:matrix.osgeo.org", false, false),
639 "!roomid:matrix.osgeo.org" 662 "!roomid:matrix.osgeo.org"
640 ); 663 );
641 } 664 }
642 665
666 #[test]
667 fn marks_space_buffers_with_plus_prefix() {
668 assert_eq!(format_buffer_name("OSGeo", false, true), "+OSGeo");
669 assert_eq!(format_buffer_name("#OSGeo", false, true), "+OSGeo");
670 assert_eq!(format_buffer_name("+OSGeo", false, true), "+OSGeo");
671 assert_eq!(format_buffer_name("+", false, true), "++");
672 }
673
643 #[test] 674 #[test]
644 fn sanitizes_thread_event_id_for_buffer_name() { 675 fn sanitizes_thread_event_id_for_buffer_name() {
645 assert_eq!( 676 assert_eq!(