| @@ -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 | |
| 10 | use std::cmp::Ord; |
10 | use std::cmp::Ord; |
| |
11 | use std::collections::HashSet; |
| 11 | use std::fmt::{self, Write as _}; |
12 | use std::fmt::{self, Write as _}; |
| 12 | |
13 | |
| 13 | use feruca::Collator; |
14 | use 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 | |