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
65View a list of joined rooms. 65View a list of joined rooms.
66.It Sy ":spaces" 66.It Sy ":spaces"
67View a list of joined spaces. 67View a list of joined spaces.
68.It Sy ":spaces toplevel"
69View a list of joined spaces that are not children of other joined spaces.
68.It Sy ":unreads" 70.It Sy ":unreads"
69View a list of unread rooms. 71View a list of unread rooms.
70.It Sy ":unreads clear" 72.It Sy ":unreads clear"
src/base.rs +13 −1
@@ -2553,6 +2553,9 @@ pub enum IambId {
2553 /// The `:spaces` window. 2553 /// The `:spaces` window.
2554 SpaceList, 2554 SpaceList,
2555 2555
2556 /// The `:spaces toplevel` window.
2557 ToplevelSpaceList,
2558
2556 /// The `:verify` window. 2559 /// The `:verify` window.
2557 VerifyList, 2560 VerifyList,
2558 2561
@@ -2592,6 +2595,7 @@ impl Display for IambId {
2592 IambId::DirectList => f.write_str("iamb://dms"), 2595 IambId::DirectList => f.write_str("iamb://dms"),
2593 IambId::RoomList => f.write_str("iamb://rooms"), 2596 IambId::RoomList => f.write_str("iamb://rooms"),
2594 IambId::SpaceList => f.write_str("iamb://spaces"), 2597 IambId::SpaceList => f.write_str("iamb://spaces"),
2598 IambId::ToplevelSpaceList => f.write_str("iamb://spaces/toplevel"),
2595 IambId::VerifyList => f.write_str("iamb://verify"), 2599 IambId::VerifyList => f.write_str("iamb://verify"),
2596 IambId::Welcome => f.write_str("iamb://welcome"), 2600 IambId::Welcome => f.write_str("iamb://welcome"),
2597 IambId::ChatList => f.write_str("iamb://chats"), 2601 IambId::ChatList => f.write_str("iamb://chats"),
@@ -2711,8 +2715,12 @@ impl Visitor<'_> for IambIdVisitor {
2711 Ok(IambId::RoomList) 2715 Ok(IambId::RoomList)
2712 }, 2716 },
2713 Some("spaces") => { 2717 Some("spaces") => {
2718 if url.path() == "toplevel" {
2719 return Ok(IambId::ToplevelSpaceList);
2720 }
2721
2714 if url.path() != "" { 2722 if url.path() != "" {
2715 return Err(E::custom("iamb://spaces takes no path")); 2723 return Err(E::custom("Invalid iamb window URL"));
2716 } 2724 }
2717 2725
2718 Ok(IambId::SpaceList) 2726 Ok(IambId::SpaceList)
@@ -2821,6 +2829,9 @@ pub enum IambBufferId {
2821 /// The `:spaces` window. 2829 /// The `:spaces` window.
2822 SpaceList, 2830 SpaceList,
2823 2831
2832 /// The `:spaces toplevel` window.
2833 ToplevelSpaceList,
2834
2824 /// The `:verify` window. 2835 /// The `:verify` window.
2825 VerifyList, 2836 VerifyList,
2826 2837
@@ -2853,6 +2864,7 @@ impl IambBufferId {
2853 IambBufferId::PinnedList(room) => IambId::PinnedList(room.clone()), 2864 IambBufferId::PinnedList(room) => IambId::PinnedList(room.clone()),
2854 IambBufferId::RoomList => IambId::RoomList, 2865 IambBufferId::RoomList => IambId::RoomList,
2855 IambBufferId::SpaceList => IambId::SpaceList, 2866 IambBufferId::SpaceList => IambId::SpaceList,
2867 IambBufferId::ToplevelSpaceList => IambId::ToplevelSpaceList,
2856 IambBufferId::VerifyList => IambId::VerifyList, 2868 IambBufferId::VerifyList => IambId::VerifyList,
2857 IambBufferId::Welcome => IambId::Welcome, 2869 IambBufferId::Welcome => IambId::Welcome,
2858 IambBufferId::ChatList => IambId::ChatList, 2870 IambBufferId::ChatList => IambId::ChatList,
src/commands.rs +17 −4
@@ -583,14 +583,27 @@ fn iamb_self(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
583} 583}
584 584
585fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { 585fn 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 {
587 return Result::Err(CommandError::InvalidArgument); 589 return Result::Err(CommandError::InvalidArgument);
588 } 590 }
589 591
590 let open = ctx.switch(OpenTarget::Application(IambId::SpaceList)); 592 match args.pop().as_deref() {
591 let step = CommandStep::Continue(open, ctx.context.clone()); 593 Some("toplevel") => {
594 let open = ctx.switch(OpenTarget::Application(IambId::ToplevelSpaceList));
595 let step = CommandStep::Continue(open, ctx.context.clone());
592 596
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 }
594} 607}
595 608
596fn iamb_welcome(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { 609fn 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> {
532 } 532 }
533} 533}
534 534
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
535/// Tab completion for `:logout` 543/// Tab completion for `:logout`
536fn complete_iamb_logout(args: Vec<String>, store: &ChatStore) -> Vec<String> { 544fn complete_iamb_logout(args: Vec<String>, store: &ChatStore) -> Vec<String> {
537 let id = store.settings.profile.user_id.as_str(); 545 let id = store.settings.profile.user_id.as_str();
@@ -600,6 +608,8 @@ fn complete_cmdarg(
600 608
601 "space" => complete_iamb_space(args, store), 609 "space" => complete_iamb_space(args, store),
602 610
611 "spaces" => complete_iamb_spaces(args),
612
603 // XXX: Check whether we can get the id of the focused message to improve completion 613 // XXX: Check whether we can get the id of the focused message to improve completion
604 "unreact" if args.len() == 1 => complete_emoji(&args[0], store), 614 "unreact" if args.len() == 1 => complete_emoji(&args[0], store),
605 "unreact" => vec![], 615 "unreact" => vec![],
@@ -622,7 +632,7 @@ fn complete_cmdarg(
622 // These have no arguments 632 // These have no arguments
623 "cancel" | "chats" | "dms" | "editor" | "edit" | "forget" | "invites" | "leave" | 633 "cancel" | "chats" | "dms" | "editor" | "edit" | "forget" | "invites" | "leave" |
624 "members" | "mentions" | "pin" | "pinned" | "unpin" | "replied" | "reply" | "rooms" | 634 "members" | "mentions" | "pin" | "pinned" | "unpin" | "replied" | "reply" | "rooms" |
625 "spaces" | "welcome" => vec![], 635 "welcome" => vec![],
626 636
627 "abo" | "aboveleft" | "bel" | "belowright" | "hor" | "horizontal" | "lefta" | 637 "abo" | "aboveleft" | "bel" | "belowright" | "hor" | "horizontal" | "lefta" |
628 "leftabove" | "rightb" | "rightbelow" | "tab" | "vert" | "vertical" => { 638 "leftabove" | "rightb" | "rightbelow" | "tab" | "vert" | "vertical" => {
@@ -793,6 +803,7 @@ impl Completer<IambInfo> for IambCompleter {
793 IambBufferId::PinnedList(_) => vec![], 803 IambBufferId::PinnedList(_) => vec![],
794 IambBufferId::RoomList => vec![], 804 IambBufferId::RoomList => vec![],
795 IambBufferId::SpaceList => vec![], 805 IambBufferId::SpaceList => vec![],
806 IambBufferId::ToplevelSpaceList => vec![],
796 IambBufferId::VerifyList => vec![], 807 IambBufferId::VerifyList => vec![],
797 IambBufferId::Welcome => vec![], 808 IambBufferId::Welcome => vec![],
798 IambBufferId::ChatList => vec![], 809 IambBufferId::ChatList => vec![],
src/windows/mod.rs +55 −1
@@ -8,6 +8,7 @@
8//! where we have the message bar and room ID easily accessible and resettable. 8//! where we have the message bar and room ID easily accessible and resettable.
9 9
10use std::cmp::Ord; 10use std::cmp::Ord;
11use std::collections::HashSet;
11use std::fmt::{self, Write as _}; 12use std::fmt::{self, Write as _};
12 13
13use feruca::Collator; 14use feruca::Collator;
@@ -520,6 +521,7 @@ macro_rules! delegate {
520 IambWindow::PinnedList($id, _, _) => $e, 521 IambWindow::PinnedList($id, _, _) => $e,
521 IambWindow::RoomList($id) => $e, 522 IambWindow::RoomList($id) => $e,
522 IambWindow::SpaceList($id) => $e, 523 IambWindow::SpaceList($id) => $e,
524 IambWindow::ToplevelSpaceList($id) => $e,
523 IambWindow::VerifyList($id) => $e, 525 IambWindow::VerifyList($id) => $e,
524 IambWindow::Welcome($id) => $e, 526 IambWindow::Welcome($id) => $e,
525 IambWindow::ChatList($id) => $e, 527 IambWindow::ChatList($id) => $e,
@@ -538,6 +540,7 @@ pub enum IambWindow {
538 VerifyList(VerifyListState), 540 VerifyList(VerifyListState),
539 RoomList(RoomListState), 541 RoomList(RoomListState),
540 SpaceList(RoomListState), 542 SpaceList(RoomListState),
543 ToplevelSpaceList(RoomListState),
541 Welcome(WelcomeState), 544 Welcome(WelcomeState),
542 ChatList(RoomListState), 545 ChatList(RoomListState),
543 UnreadList(RoomListState), 546 UnreadList(RoomListState),
@@ -607,6 +610,7 @@ impl IambWindow {
607 IambWindow::DirectList(state) => state.get().map(|state| state.room_id()), 610 IambWindow::DirectList(state) => state.get().map(|state| state.room_id()),
608 IambWindow::RoomList(state) => state.get().map(|state| state.room_id()), 611 IambWindow::RoomList(state) => state.get().map(|state| state.room_id()),
609 IambWindow::SpaceList(state) => state.get().map(|state| state.room_id()), 612 IambWindow::SpaceList(state) => state.get().map(|state| state.room_id()),
613 IambWindow::ToplevelSpaceList(state) => state.get().map(|state| state.room_id()),
610 IambWindow::ChatList(state) | IambWindow::UnreadList(state) => { 614 IambWindow::ChatList(state) | IambWindow::UnreadList(state) => {
611 state.get().map(|state| state.room_id()) 615 state.get().map(|state| state.room_id())
612 }, 616 },
@@ -734,11 +738,11 @@ impl WindowOps<IambInfo> for IambWindow {
734 let ChatStore { 738 let ChatStore {
735 collator, 739 collator,
736 rooms, 740 rooms,
741 spaces,
737 settings, 742 settings,
738 sync_info, 743 sync_info,
739 verifications, 744 verifications,
740 worker, 745 worker,
741 spaces,
742 .. 746 ..
743 } = &mut store.application; 747 } = &mut store.application;
744 let client = &worker.client; 748 let client = &worker.client;
@@ -1007,6 +1011,47 @@ impl WindowOps<IambInfo> for IambWindow {
1007 .style(default_rooms_style) 1011 .style(default_rooms_style)
1008 .render(area, buf, state); 1012 .render(area, buf, state);
1009 }, 1013 },
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 },
1010 IambWindow::VerifyList(state) => { 1055 IambWindow::VerifyList(state) => {
1011 let mut items = verifications 1056 let mut items = verifications
1012 .iter() 1057 .iter()
@@ -1046,6 +1091,7 @@ impl WindowOps<IambInfo> for IambWindow {
1046 }, 1091 },
1047 IambWindow::RoomList(w) => Self::RoomList(w.dup(store)), 1092 IambWindow::RoomList(w) => Self::RoomList(w.dup(store)),
1048 IambWindow::SpaceList(w) => Self::SpaceList(w.dup(store)), 1093 IambWindow::SpaceList(w) => Self::SpaceList(w.dup(store)),
1094 IambWindow::ToplevelSpaceList(w) => Self::ToplevelSpaceList(w.dup(store)),
1049 IambWindow::VerifyList(w) => w.dup(store).into(), 1095 IambWindow::VerifyList(w) => w.dup(store).into(),
1050 IambWindow::Welcome(w) => w.dup(store).into(), 1096 IambWindow::Welcome(w) => w.dup(store).into(),
1051 IambWindow::ChatList(w) => Self::ChatList(w.dup(store)), 1097 IambWindow::ChatList(w) => Self::ChatList(w.dup(store)),
@@ -1090,6 +1136,7 @@ impl Window<IambInfo> for IambWindow {
1090 IambWindow::PinnedList(_, room_id, _) => IambId::PinnedList(room_id.clone()), 1136 IambWindow::PinnedList(_, room_id, _) => IambId::PinnedList(room_id.clone()),
1091 IambWindow::RoomList(_) => IambId::RoomList, 1137 IambWindow::RoomList(_) => IambId::RoomList,
1092 IambWindow::SpaceList(_) => IambId::SpaceList, 1138 IambWindow::SpaceList(_) => IambId::SpaceList,
1139 IambWindow::ToplevelSpaceList(_) => IambId::ToplevelSpaceList,
1093 IambWindow::VerifyList(_) => IambId::VerifyList, 1140 IambWindow::VerifyList(_) => IambId::VerifyList,
1094 IambWindow::Welcome(_) => IambId::Welcome, 1141 IambWindow::Welcome(_) => IambId::Welcome,
1095 IambWindow::ChatList(_) => IambId::ChatList, 1142 IambWindow::ChatList(_) => IambId::ChatList,
@@ -1104,6 +1151,7 @@ impl Window<IambInfo> for IambWindow {
1104 IambWindow::DirectList(_) => Line::from("Direct Messages"), 1151 IambWindow::DirectList(_) => Line::from("Direct Messages"),
1105 IambWindow::RoomList(_) => Line::from("Rooms"), 1152 IambWindow::RoomList(_) => Line::from("Rooms"),
1106 IambWindow::SpaceList(_) => Line::from("Spaces"), 1153 IambWindow::SpaceList(_) => Line::from("Spaces"),
1154 IambWindow::ToplevelSpaceList(_) => Line::from("Toplevel Spaces"),
1107 IambWindow::VerifyList(_) => Line::from("Verifications"), 1155 IambWindow::VerifyList(_) => Line::from("Verifications"),
1108 IambWindow::Welcome(_) => Line::from("Welcome to iamb"), 1156 IambWindow::Welcome(_) => Line::from("Welcome to iamb"),
1109 IambWindow::ChatList(_) => Line::from("DMs & Rooms"), 1157 IambWindow::ChatList(_) => Line::from("DMs & Rooms"),
@@ -1143,6 +1191,7 @@ impl Window<IambInfo> for IambWindow {
1143 IambWindow::DirectList(_) => Line::styled("Direct Messages", style), 1191 IambWindow::DirectList(_) => Line::styled("Direct Messages", style),
1144 IambWindow::RoomList(_) => Line::styled("Rooms", style), 1192 IambWindow::RoomList(_) => Line::styled("Rooms", style),
1145 IambWindow::SpaceList(_) => Line::styled("Spaces", style), 1193 IambWindow::SpaceList(_) => Line::styled("Spaces", style),
1194 IambWindow::ToplevelSpaceList(_) => Line::styled("Toplevel Spaces", style),
1146 IambWindow::VerifyList(_) => Line::styled("Verifications", style), 1195 IambWindow::VerifyList(_) => Line::styled("Verifications", style),
1147 IambWindow::Welcome(_) => Line::styled("Welcome to iamb", style), 1196 IambWindow::Welcome(_) => Line::styled("Welcome to iamb", style),
1148 IambWindow::ChatList(_) => Line::styled("DMs & Rooms", style), 1197 IambWindow::ChatList(_) => Line::styled("DMs & Rooms", style),
@@ -1228,6 +1277,11 @@ impl Window<IambInfo> for IambWindow {
1228 1277
1229 return Ok(Self::SpaceList(list)); 1278 return Ok(Self::SpaceList(list));
1230 }, 1279 },
1280 IambId::ToplevelSpaceList => {
1281 let list = RoomListState::new(IambBufferId::ToplevelSpaceList, vec![]);
1282
1283 return Ok(Self::ToplevelSpaceList(list));
1284 },
1231 IambId::VerifyList => { 1285 IambId::VerifyList => {
1232 let list = VerifyListState::new(IambBufferId::VerifyList, vec![]); 1286 let list = VerifyListState::new(IambBufferId::VerifyList, vec![]);
1233 1287