Commit f89c546e44

f89c546e4474eb5650704ecc1b007387c42b3a53

parent: e8f53ed277

Unregistered key

vaw <git@nlih.de> · 2026-10-04 21:13 UTC
committer: <noreply@github.com>

Add `:spaces toplevel` (#769)

Layout: unified · split

docs/iamb.1 +2
@@ -65,6 +65,8 @@ Log out of
6565View a list of joined rooms.
6666.It Sy ":spaces"
6767View a list of joined spaces.
68.It Sy ":spaces toplevel"
69View a list of joined spaces that are not children of other joined spaces.
6870.It Sy ":unreads"
6971View a list of unread rooms.
7072.It Sy ":unreads clear"
src/base.rs +13 −1
@@ -2553,6 +2553,9 @@ pub enum IambId {
25532553 /// The `:spaces` window.
25542554 SpaceList,
25552555
2556 /// The `:spaces toplevel` window.
2557 ToplevelSpaceList,
2558
25562559 /// The `:verify` window.
25572560 VerifyList,
25582561
@@ -2592,6 +2595,7 @@ impl Display for IambId {
25922595 IambId::DirectList => f.write_str("iamb://dms"),
25932596 IambId::RoomList => f.write_str("iamb://rooms"),
25942597 IambId::SpaceList => f.write_str("iamb://spaces"),
2598 IambId::ToplevelSpaceList => f.write_str("iamb://spaces/toplevel"),
25952599 IambId::VerifyList => f.write_str("iamb://verify"),
25962600 IambId::Welcome => f.write_str("iamb://welcome"),
25972601 IambId::ChatList => f.write_str("iamb://chats"),
@@ -2711,8 +2715,12 @@ impl Visitor<'_> for IambIdVisitor {
27112715 Ok(IambId::RoomList)
27122716 },
27132717 Some("spaces") => {
2718 if url.path() == "toplevel" {
2719 return Ok(IambId::ToplevelSpaceList);
2720 }
2721
27142722 if url.path() != "" {
2715 return Err(E::custom("iamb://spaces takes no path"));
2723 return Err(E::custom("Invalid iamb window URL"));
27162724 }
27172725
27182726 Ok(IambId::SpaceList)
@@ -2821,6 +2829,9 @@ pub enum IambBufferId {
28212829 /// The `:spaces` window.
28222830 SpaceList,
28232831
2832 /// The `:spaces toplevel` window.
2833 ToplevelSpaceList,
2834
28242835 /// The `:verify` window.
28252836 VerifyList,
28262837
@@ -2853,6 +2864,7 @@ impl IambBufferId {
28532864 IambBufferId::PinnedList(room) => IambId::PinnedList(room.clone()),
28542865 IambBufferId::RoomList => IambId::RoomList,
28552866 IambBufferId::SpaceList => IambId::SpaceList,
2867 IambBufferId::ToplevelSpaceList => IambId::ToplevelSpaceList,
28562868 IambBufferId::VerifyList => IambId::VerifyList,
28572869 IambBufferId::Welcome => IambId::Welcome,
28582870 IambBufferId::ChatList => IambId::ChatList,
src/commands.rs +17 −4
@@ -583,14 +583,27 @@ fn iamb_self(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
583583}
584584
585585fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
586 if !desc.arg.text.is_empty() {
586 let mut args = desc.arg.strings()?;
587
588 if args.len() > 1 {
587589 return Result::Err(CommandError::InvalidArgument);
588590 }
589591
590 let open = ctx.switch(OpenTarget::Application(IambId::SpaceList));
591 let step = CommandStep::Continue(open, ctx.context.clone());
592 match args.pop().as_deref() {
593 Some("toplevel") => {
594 let open = ctx.switch(OpenTarget::Application(IambId::ToplevelSpaceList));
595 let step = CommandStep::Continue(open, ctx.context.clone());
592596
593 return Ok(step);
597 return Ok(step);
598 },
599 Some(_) => return Result::Err(CommandError::InvalidArgument),
600 None => {
601 let open = ctx.switch(OpenTarget::Application(IambId::SpaceList));
602 let step = CommandStep::Continue(open, ctx.context.clone());
603
604 return Ok(step);
605 },
606 }
594607}
595608
596609fn iamb_welcome(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
src/completions.rs +12 −1
@@ -532,6 +532,14 @@ fn complete_iamb_space(args: Vec<String>, store: &ChatStore) -> Vec<String> {
532532 }
533533}
534534
535/// Tab completion for `:spaces`
536fn complete_iamb_spaces(args: Vec<String>) -> Vec<String> {
537 match args.len() {
538 1 if "toplevel".starts_with(&args[0]) => vec!["toplevel".to_string()],
539 _ => vec![],
540 }
541}
542
535543/// Tab completion for `:logout`
536544fn complete_iamb_logout(args: Vec<String>, store: &ChatStore) -> Vec<String> {
537545 let id = store.settings.profile.user_id.as_str();
@@ -600,6 +608,8 @@ fn complete_cmdarg(
600608
601609 "space" => complete_iamb_space(args, store),
602610
611 "spaces" => complete_iamb_spaces(args),
612
603613 // XXX: Check whether we can get the id of the focused message to improve completion
604614 "unreact" if args.len() == 1 => complete_emoji(&args[0], store),
605615 "unreact" => vec![],
@@ -622,7 +632,7 @@ fn complete_cmdarg(
622632 // These have no arguments
623633 "cancel" | "chats" | "dms" | "editor" | "edit" | "forget" | "invites" | "leave" |
624634 "members" | "mentions" | "pin" | "pinned" | "unpin" | "replied" | "reply" | "rooms" |
625 "spaces" | "welcome" => vec![],
635 "welcome" => vec![],
626636
627637 "abo" | "aboveleft" | "bel" | "belowright" | "hor" | "horizontal" | "lefta" |
628638 "leftabove" | "rightb" | "rightbelow" | "tab" | "vert" | "vertical" => {
@@ -793,6 +803,7 @@ impl Completer<IambInfo> for IambCompleter {
793803 IambBufferId::PinnedList(_) => vec![],
794804 IambBufferId::RoomList => vec![],
795805 IambBufferId::SpaceList => vec![],
806 IambBufferId::ToplevelSpaceList => vec![],
796807 IambBufferId::VerifyList => vec![],
797808 IambBufferId::Welcome => vec![],
798809 IambBufferId::ChatList => vec![],
src/windows/mod.rs +55 −1
@@ -8,6 +8,7 @@
88//! where we have the message bar and room ID easily accessible and resettable.
99
1010use std::cmp::Ord;
11use std::collections::HashSet;
1112use std::fmt::{self, Write as _};
1213
1314use feruca::Collator;
@@ -520,6 +521,7 @@ macro_rules! delegate {
520521 IambWindow::PinnedList($id, _, _) => $e,
521522 IambWindow::RoomList($id) => $e,
522523 IambWindow::SpaceList($id) => $e,
524 IambWindow::ToplevelSpaceList($id) => $e,
523525 IambWindow::VerifyList($id) => $e,
524526 IambWindow::Welcome($id) => $e,
525527 IambWindow::ChatList($id) => $e,
@@ -538,6 +540,7 @@ pub enum IambWindow {
538540 VerifyList(VerifyListState),
539541 RoomList(RoomListState),
540542 SpaceList(RoomListState),
543 ToplevelSpaceList(RoomListState),
541544 Welcome(WelcomeState),
542545 ChatList(RoomListState),
543546 UnreadList(RoomListState),
@@ -607,6 +610,7 @@ impl IambWindow {
607610 IambWindow::DirectList(state) => state.get().map(|state| state.room_id()),
608611 IambWindow::RoomList(state) => state.get().map(|state| state.room_id()),
609612 IambWindow::SpaceList(state) => state.get().map(|state| state.room_id()),
613 IambWindow::ToplevelSpaceList(state) => state.get().map(|state| state.room_id()),
610614 IambWindow::ChatList(state) | IambWindow::UnreadList(state) => {
611615 state.get().map(|state| state.room_id())
612616 },
@@ -734,11 +738,11 @@ impl WindowOps<IambInfo> for IambWindow {
734738 let ChatStore {
735739 collator,
736740 rooms,
741 spaces,
737742 settings,
738743 sync_info,
739744 verifications,
740745 worker,
741 spaces,
742746 ..
743747 } = &mut store.application;
744748 let client = &worker.client;
@@ -1007,6 +1011,47 @@ impl WindowOps<IambInfo> for IambWindow {
10071011 .style(default_rooms_style)
10081012 .render(area, buf, state);
10091013 },
1014 IambWindow::ToplevelSpaceList(state) => {
1015 let mut toplevel_spaces: HashSet<_> =
1016 sync_info.spaces.iter().map(|room| room.room_id()).collect();
1017
1018 sync_info
1019 .spaces
1020 .iter()
1021 .filter_map(|room| spaces.get(room.room_id()))
1022 .flat_map(|info| info.children.keys())
1023 .for_each(|child_id| {
1024 toplevel_spaces.remove(child_id.deref());
1025 });
1026
1027 let mut items = toplevel_spaces
1028 .into_iter()
1029 .flat_map(|room_id| worker.client.get_room(room_id))
1030 .map(|room| {
1031 GenericRoomItem::new(
1032 &room,
1033 rooms.get_or_default(room.room_id().to_owned()),
1034 client,
1035 spaces,
1036 )
1037 .show_room_type(false)
1038 })
1039 .collect::<Vec<_>>();
1040
1041 let fields = &settings.tunables.sort.spaces;
1042 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator));
1043 items.iter_mut().for_each(|i| i.set_section(fields));
1044
1045 state.set(items);
1046 state.set_ignorecase(settings.tunables.ignorecase);
1047
1048 List::new(store)
1049 .empty_message("You haven't joined any spaces yet")
1050 .empty_alignment(Alignment::Center)
1051 .focus(focused)
1052 .style(default_rooms_style)
1053 .render(area, buf, state);
1054 },
10101055 IambWindow::VerifyList(state) => {
10111056 let mut items = verifications
10121057 .iter()
@@ -1046,6 +1091,7 @@ impl WindowOps<IambInfo> for IambWindow {
10461091 },
10471092 IambWindow::RoomList(w) => Self::RoomList(w.dup(store)),
10481093 IambWindow::SpaceList(w) => Self::SpaceList(w.dup(store)),
1094 IambWindow::ToplevelSpaceList(w) => Self::ToplevelSpaceList(w.dup(store)),
10491095 IambWindow::VerifyList(w) => w.dup(store).into(),
10501096 IambWindow::Welcome(w) => w.dup(store).into(),
10511097 IambWindow::ChatList(w) => Self::ChatList(w.dup(store)),
@@ -1090,6 +1136,7 @@ impl Window<IambInfo> for IambWindow {
10901136 IambWindow::PinnedList(_, room_id, _) => IambId::PinnedList(room_id.clone()),
10911137 IambWindow::RoomList(_) => IambId::RoomList,
10921138 IambWindow::SpaceList(_) => IambId::SpaceList,
1139 IambWindow::ToplevelSpaceList(_) => IambId::ToplevelSpaceList,
10931140 IambWindow::VerifyList(_) => IambId::VerifyList,
10941141 IambWindow::Welcome(_) => IambId::Welcome,
10951142 IambWindow::ChatList(_) => IambId::ChatList,
@@ -1104,6 +1151,7 @@ impl Window<IambInfo> for IambWindow {
11041151 IambWindow::DirectList(_) => Line::from("Direct Messages"),
11051152 IambWindow::RoomList(_) => Line::from("Rooms"),
11061153 IambWindow::SpaceList(_) => Line::from("Spaces"),
1154 IambWindow::ToplevelSpaceList(_) => Line::from("Toplevel Spaces"),
11071155 IambWindow::VerifyList(_) => Line::from("Verifications"),
11081156 IambWindow::Welcome(_) => Line::from("Welcome to iamb"),
11091157 IambWindow::ChatList(_) => Line::from("DMs & Rooms"),
@@ -1143,6 +1191,7 @@ impl Window<IambInfo> for IambWindow {
11431191 IambWindow::DirectList(_) => Line::styled("Direct Messages", style),
11441192 IambWindow::RoomList(_) => Line::styled("Rooms", style),
11451193 IambWindow::SpaceList(_) => Line::styled("Spaces", style),
1194 IambWindow::ToplevelSpaceList(_) => Line::styled("Toplevel Spaces", style),
11461195 IambWindow::VerifyList(_) => Line::styled("Verifications", style),
11471196 IambWindow::Welcome(_) => Line::styled("Welcome to iamb", style),
11481197 IambWindow::ChatList(_) => Line::styled("DMs & Rooms", style),
@@ -1228,6 +1277,11 @@ impl Window<IambInfo> for IambWindow {
12281277
12291278 return Ok(Self::SpaceList(list));
12301279 },
1280 IambId::ToplevelSpaceList => {
1281 let list = RoomListState::new(IambBufferId::ToplevelSpaceList, vec![]);
1282
1283 return Ok(Self::ToplevelSpaceList(list));
1284 },
12311285 IambId::VerifyList => {
12321286 let list = VerifyListState::new(IambBufferId::VerifyList, vec![]);
12331287