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:
187187
188188# Matrix Spaces
189189
190Space buffers use a `+` prefix in their short name, while ordinary room buffers
191keep the `#` prefix and direct-message buffers stay unprefixed.
192
190193Room buffers expose Matrix parent Spaces as WeeChat local variables. Switch to a
191194room buffer that belongs to a Space and run:
192195
src/room/buffer.rs +42 −11
@@ -390,6 +390,7 @@ impl RoomBuffer {
390390 };
391391 let is_direct =
392392 self.runtime.block_on(room.is_direct()).unwrap_or(false);
393 let is_space = room.is_space();
393394
394395 let room_name = room
395396 .name()
@@ -407,7 +408,7 @@ impl RoomBuffer {
407408 })
408409 .unwrap_or_else(|| room.room_id().to_string());
409410
410 format_buffer_name(&room_name, is_direct)
411 format_buffer_name(&room_name, is_direct, is_space)
411412 }
412413
413414 pub fn calculate_thread_buffer_name(
@@ -489,13 +490,35 @@ fn non_empty_room_name(name: &str) -> Option<String> {
489490 }
490491}
491492
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
493519 let room_name = if room_name == "#" {
494520 "##".to_owned()
495 } else if room_name.starts_with('#')
496 || room_name.starts_with('!')
497 || is_direct
498 {
521 } else if room_name.starts_with('#') {
499522 room_name.to_owned()
500523 } else {
501524 format!("#{}", room_name)
@@ -618,28 +641,36 @@ mod tests {
618641
619642 #[test]
620643 fn preserves_named_channel_prefix() {
621 assert_eq!(format_buffer_name("OSGeo", false), "#OSGeo");
644 assert_eq!(format_buffer_name("OSGeo", false, false), "#OSGeo");
622645 }
623646
624647 #[test]
625648 fn preserves_direct_room_names() {
626 assert_eq!(format_buffer_name("Alice", true), "Alice");
649 assert_eq!(format_buffer_name("Alice", true, false), "Alice");
627650 }
628651
629652 #[test]
630653 fn preserves_alias_like_names() {
631 assert_eq!(format_buffer_name("#lounge", false), "#lounge");
632 assert_eq!(format_buffer_name("#", false), "##");
654 assert_eq!(format_buffer_name("#lounge", false, false), "#lounge");
655 assert_eq!(format_buffer_name("#", false, false), "##");
633656 }
634657
635658 #[test]
636659 fn preserves_room_id_fallbacks() {
637660 assert_eq!(
638 format_buffer_name("!roomid:matrix.osgeo.org", false),
661 format_buffer_name("!roomid:matrix.osgeo.org", false, false),
639662 "!roomid:matrix.osgeo.org"
640663 );
641664 }
642665
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
643674 #[test]
644675 fn sanitizes_thread_event_id_for_buffer_name() {
645676 assert_eq!(