| @@ -8,6 +8,7 @@ |
| 8 | 8 | //! where we have the message bar and room ID easily accessible and resettable. |
| 9 | 9 | |
| 10 | 10 | use std::cmp::Ord; |
| 11 | use std::collections::HashSet; |
| 11 | 12 | use std::fmt::{self, Write as _}; |
| 12 | 13 | |
| 13 | 14 | use feruca::Collator; |
| @@ -520,6 +521,7 @@ macro_rules! delegate { |
| 520 | 521 | IambWindow::PinnedList($id, _, _) => $e, |
| 521 | 522 | IambWindow::RoomList($id) => $e, |
| 522 | 523 | IambWindow::SpaceList($id) => $e, |
| 524 | IambWindow::ToplevelSpaceList($id) => $e, |
| 523 | 525 | IambWindow::VerifyList($id) => $e, |
| 524 | 526 | IambWindow::Welcome($id) => $e, |
| 525 | 527 | IambWindow::ChatList($id) => $e, |
| @@ -538,6 +540,7 @@ pub enum IambWindow { |
| 538 | 540 | VerifyList(VerifyListState), |
| 539 | 541 | RoomList(RoomListState), |
| 540 | 542 | SpaceList(RoomListState), |
| 543 | ToplevelSpaceList(RoomListState), |
| 541 | 544 | Welcome(WelcomeState), |
| 542 | 545 | ChatList(RoomListState), |
| 543 | 546 | UnreadList(RoomListState), |
| @@ -607,6 +610,7 @@ impl IambWindow { |
| 607 | 610 | IambWindow::DirectList(state) => state.get().map(|state| state.room_id()), |
| 608 | 611 | IambWindow::RoomList(state) => state.get().map(|state| state.room_id()), |
| 609 | 612 | IambWindow::SpaceList(state) => state.get().map(|state| state.room_id()), |
| 613 | IambWindow::ToplevelSpaceList(state) => state.get().map(|state| state.room_id()), |
| 610 | 614 | IambWindow::ChatList(state) | IambWindow::UnreadList(state) => { |
| 611 | 615 | state.get().map(|state| state.room_id()) |
| 612 | 616 | }, |
| @@ -734,11 +738,11 @@ impl WindowOps<IambInfo> for IambWindow { |
| 734 | 738 | let ChatStore { |
| 735 | 739 | collator, |
| 736 | 740 | rooms, |
| 741 | spaces, |
| 737 | 742 | settings, |
| 738 | 743 | sync_info, |
| 739 | 744 | verifications, |
| 740 | 745 | worker, |
| 741 | | spaces, |
| 742 | 746 | .. |
| 743 | 747 | } = &mut store.application; |
| 744 | 748 | let client = &worker.client; |
| @@ -1007,6 +1011,47 @@ impl WindowOps<IambInfo> for IambWindow { |
| 1007 | 1011 | .style(default_rooms_style) |
| 1008 | 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 | 1055 | IambWindow::VerifyList(state) => { |
| 1011 | 1056 | let mut items = verifications |
| 1012 | 1057 | .iter() |
| @@ -1046,6 +1091,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 1046 | 1091 | }, |
| 1047 | 1092 | IambWindow::RoomList(w) => Self::RoomList(w.dup(store)), |
| 1048 | 1093 | IambWindow::SpaceList(w) => Self::SpaceList(w.dup(store)), |
| 1094 | IambWindow::ToplevelSpaceList(w) => Self::ToplevelSpaceList(w.dup(store)), |
| 1049 | 1095 | IambWindow::VerifyList(w) => w.dup(store).into(), |
| 1050 | 1096 | IambWindow::Welcome(w) => w.dup(store).into(), |
| 1051 | 1097 | IambWindow::ChatList(w) => Self::ChatList(w.dup(store)), |
| @@ -1090,6 +1136,7 @@ impl Window<IambInfo> for IambWindow { |
| 1090 | 1136 | IambWindow::PinnedList(_, room_id, _) => IambId::PinnedList(room_id.clone()), |
| 1091 | 1137 | IambWindow::RoomList(_) => IambId::RoomList, |
| 1092 | 1138 | IambWindow::SpaceList(_) => IambId::SpaceList, |
| 1139 | IambWindow::ToplevelSpaceList(_) => IambId::ToplevelSpaceList, |
| 1093 | 1140 | IambWindow::VerifyList(_) => IambId::VerifyList, |
| 1094 | 1141 | IambWindow::Welcome(_) => IambId::Welcome, |
| 1095 | 1142 | IambWindow::ChatList(_) => IambId::ChatList, |
| @@ -1104,6 +1151,7 @@ impl Window<IambInfo> for IambWindow { |
| 1104 | 1151 | IambWindow::DirectList(_) => Line::from("Direct Messages"), |
| 1105 | 1152 | IambWindow::RoomList(_) => Line::from("Rooms"), |
| 1106 | 1153 | IambWindow::SpaceList(_) => Line::from("Spaces"), |
| 1154 | IambWindow::ToplevelSpaceList(_) => Line::from("Toplevel Spaces"), |
| 1107 | 1155 | IambWindow::VerifyList(_) => Line::from("Verifications"), |
| 1108 | 1156 | IambWindow::Welcome(_) => Line::from("Welcome to iamb"), |
| 1109 | 1157 | IambWindow::ChatList(_) => Line::from("DMs & Rooms"), |
| @@ -1143,6 +1191,7 @@ impl Window<IambInfo> for IambWindow { |
| 1143 | 1191 | IambWindow::DirectList(_) => Line::styled("Direct Messages", style), |
| 1144 | 1192 | IambWindow::RoomList(_) => Line::styled("Rooms", style), |
| 1145 | 1193 | IambWindow::SpaceList(_) => Line::styled("Spaces", style), |
| 1194 | IambWindow::ToplevelSpaceList(_) => Line::styled("Toplevel Spaces", style), |
| 1146 | 1195 | IambWindow::VerifyList(_) => Line::styled("Verifications", style), |
| 1147 | 1196 | IambWindow::Welcome(_) => Line::styled("Welcome to iamb", style), |
| 1148 | 1197 | IambWindow::ChatList(_) => Line::styled("DMs & Rooms", style), |
| @@ -1228,6 +1277,11 @@ impl Window<IambInfo> for IambWindow { |
| 1228 | 1277 | |
| 1229 | 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 | 1285 | IambId::VerifyList => { |
| 1232 | 1286 | let list = VerifyListState::new(IambBufferId::VerifyList, vec![]); |
| 1233 | 1287 | |