| @@ -14,12 +14,22 @@ use feruca::Collator; |
| 14 | use matrix_sdk::RoomHeroWithProfile; |
14 | use matrix_sdk::RoomHeroWithProfile; |
| 15 | use matrix_sdk::room::RoomMember; |
15 | use matrix_sdk::room::RoomMember; |
| 16 | use matrix_sdk::ruma::events::room::member::MembershipState; |
16 | use matrix_sdk::ruma::events::room::member::MembershipState; |
| |
17 | use matrix_sdk::ruma::events::room::power_levels::UserPowerLevel; |
| 17 | use matrix_sdk::ruma::room::RoomType as MatrixRoomType; |
18 | use matrix_sdk::ruma::room::RoomType as MatrixRoomType; |
| 18 | use matrix_sdk::ruma::{RoomAliasId, RoomOrAliasId, assign}; |
19 | use matrix_sdk::ruma::{RoomAliasId, RoomOrAliasId}; |
| 19 | use modalkit_ratatui::Window; |
20 | use modalkit_ratatui::Window; |
| 20 | use modalkit_ratatui::list::{List, ListCursor, ListItem, ListState}; |
21 | use modalkit_ratatui::list::{List, ListCursor, ListItem, ListState}; |
| 21 | |
22 | use ratatui::prelude::Stylize; |
| 22 | use crate::base::{RoomNeeds, SortColumn, SortFieldRoom, SortFieldUser, SortOrder, UnreadInfo}; |
23 | |
| |
24 | use crate::base::{ |
| |
25 | RoomNeeds, |
| |
26 | SortColumn, |
| |
27 | SortFieldRoom, |
| |
28 | SortFieldSpace, |
| |
29 | SortFieldUser, |
| |
30 | SortOrder, |
| |
31 | UnreadInfo, |
| |
32 | }; |
| 23 | use crate::prelude::*; |
33 | use crate::prelude::*; |
| 24 | use crate::resolve_mxid; |
34 | use crate::resolve_mxid; |
| 25 | use crate::windows::room::{RoomState, room_command}; |
35 | use crate::windows::room::{RoomState, room_command}; |
| @@ -199,6 +209,20 @@ fn room_cmp<T: RoomLikeItem>( |
| 199 | // sort larger timestamps towards the top. |
209 | // sort larger timestamps towards the top. |
| 200 | some_cmp(a.recent_ts(), b.recent_ts(), |a, b| b.cmp(a)) |
210 | some_cmp(a.recent_ts(), b.recent_ts(), |a, b| b.cmp(a)) |
| 201 | }, |
211 | }, |
| |
212 | SortFieldRoom::Direct => { |
| |
213 | // sort DMs before other rooms. |
| |
214 | let a = a.room_type().is_dm(); |
| |
215 | let b = b.room_type().is_dm(); |
| |
216 | |
| |
217 | b.cmp(&a) |
| |
218 | }, |
| |
219 | SortFieldRoom::Space => { |
| |
220 | // sort spaces before other rooms. |
| |
221 | let a = a.room_type().is_space(); |
| |
222 | let b = b.room_type().is_space(); |
| |
223 | |
| |
224 | b.cmp(&a) |
| |
225 | }, |
| 202 | SortFieldRoom::Invite => { |
226 | SortFieldRoom::Invite => { |
| 203 | // sort invites before other rooms. |
227 | // sort invites before other rooms. |
| 204 | let a = a.membership() == MatrixRoomState::Invited; |
228 | let a = a.membership() == MatrixRoomState::Invited; |
| @@ -285,8 +309,130 @@ fn append_tags<'a>(tags: Vec<Vec<Span<'a>>>, spans: &mut Vec<Span<'a>>, style: S |
| 285 | spans.push(Span::styled(")", style)); |
309 | spans.push(Span::styled(")", style)); |
| 286 | } |
310 | } |
| 287 | |
311 | |
| |
312 | trait SortedSection { |
| |
313 | fn get_section<R: RoomLikeItem>(&self, room: &R) -> Option<ListSectionHeader>; |
| |
314 | } |
| |
315 | |
| |
316 | impl SortedSection for SortFieldSpace { |
| |
317 | fn get_section<R: RoomLikeItem>(&self, room: &R) -> Option<ListSectionHeader> { |
| |
318 | match self { |
| |
319 | SortFieldSpace::Room(col) => col.get_section(room), |
| |
320 | SortFieldSpace::SpaceOrder => None, |
| |
321 | } |
| |
322 | } |
| |
323 | } |
| |
324 | |
| |
325 | impl SortedSection for SortFieldRoom { |
| |
326 | fn get_section<R: RoomLikeItem>(&self, room: &R) -> Option<ListSectionHeader> { |
| |
327 | let header = match self { |
| |
328 | SortFieldRoom::Direct if room.room_type().is_dm() => ListSectionHeader::DirectMessages, |
| |
329 | SortFieldRoom::Favorite if room.has_tag(TagName::Favorite) => { |
| |
330 | ListSectionHeader::Favorites |
| |
331 | }, |
| |
332 | SortFieldRoom::Invite if room.membership() == MatrixRoomState::Invited => { |
| |
333 | ListSectionHeader::Invites |
| |
334 | }, |
| |
335 | SortFieldRoom::Joined if room.membership() != MatrixRoomState::Joined => { |
| |
336 | ListSectionHeader::NotJoined |
| |
337 | }, |
| |
338 | SortFieldRoom::LowPriority if room.has_tag(TagName::LowPriority) => { |
| |
339 | ListSectionHeader::LowPriority |
| |
340 | }, |
| |
341 | SortFieldRoom::Space if room.room_type().is_space() => ListSectionHeader::Spaces, |
| |
342 | SortFieldRoom::Unread if room.is_unread() => ListSectionHeader::Unreads, |
| |
343 | _ => return None, |
| |
344 | }; |
| |
345 | |
| |
346 | return Some(header); |
| |
347 | } |
| |
348 | } |
| |
349 | |
| |
350 | fn get_user_section(sort: &SortFieldUser, member: &MemberItem) -> Option<ListSectionHeader> { |
| |
351 | let header = match sort { |
| |
352 | SortFieldUser::PowerLevel => { |
| |
353 | match member.member.power_level() { |
| |
354 | UserPowerLevel::Infinite => ListSectionHeader::Admins, |
| |
355 | UserPowerLevel::Int(n) => { |
| |
356 | match u32::try_from(n) { |
| |
357 | Ok(100) => ListSectionHeader::Admins, |
| |
358 | Ok(51..100) => ListSectionHeader::ModeratorsPlus, |
| |
359 | Ok(50) => ListSectionHeader::Moderators, |
| |
360 | _ => return None, |
| |
361 | } |
| |
362 | }, |
| |
363 | _ => return None, |
| |
364 | } |
| |
365 | }, |
| |
366 | SortFieldUser::Knock if member.is_knock() => ListSectionHeader::Knocked, |
| |
367 | SortFieldUser::Invite if member.is_invite() => ListSectionHeader::Invited, |
| |
368 | _ => return None, |
| |
369 | }; |
| |
370 | |
| |
371 | return Some(header); |
| |
372 | } |
| |
373 | |
| |
374 | #[derive(Clone, Debug, Eq, PartialEq)] |
| |
375 | pub enum ListSectionHeader { |
| |
376 | Admins, |
| |
377 | DirectMessages, |
| |
378 | Favorites, |
| |
379 | Invited, |
| |
380 | Invites, |
| |
381 | Knocked, |
| |
382 | LowPriority, |
| |
383 | Moderators, |
| |
384 | ModeratorsPlus, |
| |
385 | NotJoined, |
| |
386 | Rooms, |
| |
387 | Spaces, |
| |
388 | Unreads, |
| |
389 | Users, |
| |
390 | } |
| |
391 | |
| |
392 | impl ListSectionHeader { |
| |
393 | fn for_room<R, T>(room: &R, sort: &[SortColumn<T>]) -> Option<Self> |
| |
394 | where |
| |
395 | T: SortedSection, |
| |
396 | R: RoomLikeItem, |
| |
397 | { |
| |
398 | sort.iter() |
| |
399 | .flat_map(|col| col.0.get_section(room)) |
| |
400 | .next() |
| |
401 | .or(Some(Self::Rooms)) |
| |
402 | } |
| |
403 | |
| |
404 | fn for_user(member: &MemberItem, sort: &[SortColumn<SortFieldUser>]) -> Option<Self> { |
| |
405 | sort.iter() |
| |
406 | .flat_map(|col| get_user_section(&col.0, member)) |
| |
407 | .next() |
| |
408 | .or(Some(Self::Users)) |
| |
409 | } |
| |
410 | } |
| |
411 | |
| |
412 | impl From<ListSectionHeader> for Line<'static> { |
| |
413 | fn from(section: ListSectionHeader) -> Self { |
| |
414 | match section { |
| |
415 | ListSectionHeader::Admins => Line::raw("Admins").bold(), |
| |
416 | ListSectionHeader::DirectMessages => Line::raw("Direct Messages").bold(), |
| |
417 | ListSectionHeader::Favorites => Line::raw("Favorites").bold(), |
| |
418 | ListSectionHeader::Invited => Line::raw("Invited").bold(), |
| |
419 | ListSectionHeader::Invites => Line::raw("Invites").bold(), |
| |
420 | ListSectionHeader::Knocked => Line::raw("Knocked").bold(), |
| |
421 | ListSectionHeader::LowPriority => Line::raw("Low Priority").bold(), |
| |
422 | ListSectionHeader::Moderators => Line::raw("Moderators").bold(), |
| |
423 | ListSectionHeader::ModeratorsPlus => Line::raw("Moderators++").bold(), |
| |
424 | ListSectionHeader::NotJoined => Line::raw("Not Joined").bold(), |
| |
425 | ListSectionHeader::Rooms => Line::raw("Rooms").bold(), |
| |
426 | ListSectionHeader::Spaces => Line::raw("Spaces").bold(), |
| |
427 | ListSectionHeader::Unreads => Line::raw("Unreads").bold(), |
| |
428 | ListSectionHeader::Users => Line::raw("Users").bold(), |
| |
429 | } |
| |
430 | } |
| |
431 | } |
| |
432 | |
| 288 | trait RoomLikeItem { |
433 | trait RoomLikeItem { |
| 289 | fn room_id(&self) -> &RoomId; |
434 | fn room_id(&self) -> &RoomId; |
| |
435 | fn room_type(&self) -> &RoomType; |
| 290 | fn has_tag(&self, tag: TagName) -> bool; |
436 | fn has_tag(&self, tag: TagName) -> bool; |
| 291 | fn is_unread(&self) -> bool; |
437 | fn is_unread(&self) -> bool; |
| 292 | fn recent_ts(&self) -> Option<&MessageTimeStamp>; |
438 | fn recent_ts(&self) -> Option<&MessageTimeStamp>; |
| @@ -565,14 +711,13 @@ impl WindowOps<IambInfo> for IambWindow { |
| 565 | .dms |
711 | .dms |
| 566 | .iter() |
712 | .iter() |
| 567 | .map(|room| { |
713 | .map(|room| { |
| 568 | GenericRoomItem::new_unspecified( |
714 | GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned())) |
| 569 | room, |
715 | .show_room_type(false) |
| 570 | rooms.get_or_default(room.room_id().to_owned()), |
| |
| 571 | ) |
| |
| 572 | }) |
716 | }) |
| 573 | .collect::<Vec<_>>(); |
717 | .collect::<Vec<_>>(); |
| 574 | let fields = &settings.tunables.sort.dms; |
718 | let fields = &settings.tunables.sort.dms; |
| 575 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
719 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| |
720 | items.iter_mut().for_each(|i| i.set_section(fields)); |
| 576 | |
721 | |
| 577 | state.set(items); |
722 | state.set(items); |
| 578 | state.set_ignorecase(settings.tunables.ignorecase); |
723 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -597,6 +742,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 597 | .collect::<Vec<_>>(); |
742 | .collect::<Vec<_>>(); |
| 598 | let fields = &settings.tunables.sort.members; |
743 | let fields = &settings.tunables.sort.members; |
| 599 | items.sort_by(|a, b| user_fields_cmp(a, b, fields)); |
744 | items.sort_by(|a, b| user_fields_cmp(a, b, fields)); |
| |
745 | items.iter_mut().for_each(|i| i.set_section(fields)); |
| 600 | state.set(items); |
746 | state.set(items); |
| 601 | *last_fetch = Some(Instant::now()); |
747 | *last_fetch = Some(Instant::now()); |
| 602 | } |
748 | } |
| @@ -643,14 +789,13 @@ impl WindowOps<IambInfo> for IambWindow { |
| 643 | .rooms |
789 | .rooms |
| 644 | .iter() |
790 | .iter() |
| 645 | .map(|room| { |
791 | .map(|room| { |
| 646 | GenericRoomItem::new_unspecified( |
792 | GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned())) |
| 647 | room, |
793 | .show_room_type(false) |
| 648 | rooms.get_or_default(room.room_id().to_owned()), |
| |
| 649 | ) |
| |
| 650 | }) |
794 | }) |
| 651 | .collect::<Vec<_>>(); |
795 | .collect::<Vec<_>>(); |
| 652 | let fields = &settings.tunables.sort.rooms; |
796 | let fields = &settings.tunables.sort.rooms; |
| 653 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
797 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| |
798 | items.iter_mut().for_each(|i| i.set_section(fields)); |
| 654 | |
799 | |
| 655 | state.set(items); |
800 | state.set(items); |
| 656 | state.set_ignorecase(settings.tunables.ignorecase); |
801 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -674,6 +819,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 674 | |
819 | |
| 675 | let fields = &settings.tunables.sort.chats; |
820 | let fields = &settings.tunables.sort.chats; |
| 676 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
821 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| |
822 | items.iter_mut().for_each(|i| i.set_section(fields)); |
| 677 | |
823 | |
| 678 | state.set(items); |
824 | state.set(items); |
| 679 | state.set_ignorecase(settings.tunables.ignorecase); |
825 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -698,6 +844,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 698 | |
844 | |
| 699 | let fields = &settings.tunables.sort.chats; |
845 | let fields = &settings.tunables.sort.chats; |
| 700 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
846 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| |
847 | items.iter_mut().for_each(|i| i.set_section(fields)); |
| 701 | |
848 | |
| 702 | state.set(items); |
849 | state.set(items); |
| 703 | state.set_ignorecase(settings.tunables.ignorecase); |
850 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -722,6 +869,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 722 | |
869 | |
| 723 | let fields = &settings.tunables.sort.chats; |
870 | let fields = &settings.tunables.sort.chats; |
| 724 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
871 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| |
872 | items.iter_mut().for_each(|i| i.set_section(fields)); |
| 725 | |
873 | |
| 726 | state.set(items); |
874 | state.set(items); |
| 727 | state.set_ignorecase(settings.tunables.ignorecase); |
875 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -746,6 +894,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 746 | |
894 | |
| 747 | let fields = &settings.tunables.sort.chats; |
895 | let fields = &settings.tunables.sort.chats; |
| 748 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
896 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| |
897 | items.iter_mut().for_each(|i| i.set_section(fields)); |
| 749 | |
898 | |
| 750 | state.set(items); |
899 | state.set(items); |
| 751 | state.set_ignorecase(settings.tunables.ignorecase); |
900 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -762,15 +911,14 @@ impl WindowOps<IambInfo> for IambWindow { |
| 762 | .spaces |
911 | .spaces |
| 763 | .iter() |
912 | .iter() |
| 764 | .map(|room| { |
913 | .map(|room| { |
| 765 | GenericRoomItem::new_unspecified( |
914 | GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned())) |
| 766 | room, |
915 | .show_room_type(false) |
| 767 | rooms.get_or_default(room.room_id().to_owned()), |
| |
| 768 | ) |
| |
| 769 | }) |
916 | }) |
| 770 | .collect::<Vec<_>>(); |
917 | .collect::<Vec<_>>(); |
| 771 | |
918 | |
| 772 | let fields = &settings.tunables.sort.spaces; |
919 | let fields = &settings.tunables.sort.spaces; |
| 773 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
920 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| |
921 | items.iter_mut().for_each(|i| i.set_section(fields)); |
| 774 | |
922 | |
| 775 | state.set(items); |
923 | state.set(items); |
| 776 | state.set_ignorecase(settings.tunables.ignorecase); |
924 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -1089,6 +1237,14 @@ enum RoomType { |
| 1089 | } |
1237 | } |
| 1090 | |
1238 | |
| 1091 | impl RoomType { |
1239 | impl RoomType { |
| |
1240 | fn is_dm(&self) -> bool { |
| |
1241 | matches!(self, Self::DM) |
| |
1242 | } |
| |
1243 | |
| |
1244 | fn is_space(&self) -> bool { |
| |
1245 | matches!(self, Self::Space) |
| |
1246 | } |
| |
1247 | |
| 1092 | fn text(self) -> Option<&'static str> { |
1248 | fn text(self) -> Option<&'static str> { |
| 1093 | match self { |
1249 | match self { |
| 1094 | RoomType::DM => Some("DM"), |
1250 | RoomType::DM => Some("DM"), |
| @@ -1105,14 +1261,15 @@ pub struct GenericRoomItem { |
| 1105 | name: String, |
1261 | name: String, |
| 1106 | alias: Option<OwnedRoomAliasId>, |
1262 | alias: Option<OwnedRoomAliasId>, |
| 1107 | tags: Option<Tags>, |
1263 | tags: Option<Tags>, |
| |
1264 | section: Option<ListSectionHeader>, |
| 1108 | membership: MatrixRoomState, |
1265 | membership: MatrixRoomState, |
| 1109 | unread: UnreadInfo, |
1266 | unread: UnreadInfo, |
| 1110 | |
1267 | room_type_show: bool, |
| 1111 | room_type: RoomType, |
1268 | room_type: RoomType, |
| 1112 | } |
1269 | } |
| 1113 | |
1270 | |
| 1114 | impl GenericRoomItem { |
1271 | impl GenericRoomItem { |
| 1115 | pub fn new_unspecified(room: &MatrixRoom, info: &RoomInfo) -> Self { |
1272 | pub fn new(room: &MatrixRoom, info: &RoomInfo) -> Self { |
| 1116 | let room_id = room.room_id().to_owned(); |
1273 | let room_id = room.room_id().to_owned(); |
| 1117 | |
1274 | |
| 1118 | let name = info.name.clone().unwrap_or_default(); |
1275 | let name = info.name.clone().unwrap_or_default(); |
| @@ -1120,18 +1277,6 @@ impl GenericRoomItem { |
| 1120 | let unread = info.unreads(room); |
1277 | let unread = info.unreads(room); |
| 1121 | let tags = info.tags.clone(); |
1278 | let tags = info.tags.clone(); |
| 1122 | |
1279 | |
| 1123 | Self { |
| |
| 1124 | name, |
| |
| 1125 | room_id, |
| |
| 1126 | alias, |
| |
| 1127 | tags, |
| |
| 1128 | unread, |
| |
| 1129 | membership: room.state(), |
| |
| 1130 | room_type: RoomType::Unspecified, |
| |
| 1131 | } |
| |
| 1132 | } |
| |
| 1133 | |
| |
| 1134 | pub fn new(room: &MatrixRoom, info: &RoomInfo) -> Self { |
| |
| 1135 | let room_type = if room.is_space() { |
1280 | let room_type = if room.is_space() { |
| 1136 | RoomType::Space |
1281 | RoomType::Space |
| 1137 | } else if room.is_dm() { |
1282 | } else if room.is_dm() { |
| @@ -1140,7 +1285,17 @@ impl GenericRoomItem { |
| 1140 | RoomType::Room |
1285 | RoomType::Room |
| 1141 | }; |
1286 | }; |
| 1142 | |
1287 | |
| 1143 | assign!(Self::new_unspecified(room, info), { room_type }) |
1288 | Self { |
| |
1289 | name, |
| |
1290 | room_id, |
| |
1291 | alias, |
| |
1292 | tags, |
| |
1293 | unread, |
| |
1294 | membership: room.state(), |
| |
1295 | room_type, |
| |
1296 | room_type_show: true, |
| |
1297 | section: None, |
| |
1298 | } |
| 1144 | } |
1299 | } |
| 1145 | |
1300 | |
| 1146 | /// Create for a room the client doesn't know about. |
1301 | /// Create for a room the client doesn't know about. |
| @@ -1168,6 +1323,8 @@ impl GenericRoomItem { |
| 1168 | membership: MatrixRoomState::Left, |
1323 | membership: MatrixRoomState::Left, |
| 1169 | unread: Default::default(), |
1324 | unread: Default::default(), |
| 1170 | room_type: RoomType::Unspecified, |
1325 | room_type: RoomType::Unspecified, |
| |
1326 | room_type_show: false, |
| |
1327 | section: None, |
| 1171 | }; |
1328 | }; |
| 1172 | }; |
1329 | }; |
| 1173 | |
1330 | |
| @@ -1189,8 +1346,19 @@ impl GenericRoomItem { |
| 1189 | membership, |
1346 | membership, |
| 1190 | unread: Default::default(), |
1347 | unread: Default::default(), |
| 1191 | room_type, |
1348 | room_type, |
| |
1349 | room_type_show: true, |
| |
1350 | section: None, |
| 1192 | } |
1351 | } |
| 1193 | } |
1352 | } |
| |
1353 | |
| |
1354 | fn show_room_type(mut self, show: bool) -> Self { |
| |
1355 | self.room_type_show = show; |
| |
1356 | self |
| |
1357 | } |
| |
1358 | |
| |
1359 | fn set_section<T: SortedSection>(&mut self, fields: &[SortColumn<T>]) { |
| |
1360 | self.section = ListSectionHeader::for_room(self, fields); |
| |
1361 | } |
| 1194 | } |
1362 | } |
| 1195 | |
1363 | |
| 1196 | impl RoomLikeItem for GenericRoomItem { |
1364 | impl RoomLikeItem for GenericRoomItem { |
| @@ -1198,6 +1366,10 @@ impl RoomLikeItem for GenericRoomItem { |
| 1198 | &self.room_id |
1366 | &self.room_id |
| 1199 | } |
1367 | } |
| 1200 | |
1368 | |
| |
1369 | fn room_type(&self) -> &RoomType { |
| |
1370 | &self.room_type |
| |
1371 | } |
| |
1372 | |
| 1201 | fn has_tag(&self, tag: TagName) -> bool { |
1373 | fn has_tag(&self, tag: TagName) -> bool { |
| 1202 | self.tags.as_ref().is_some_and(|tags| tags.contains_key(&tag)) |
1374 | self.tags.as_ref().is_some_and(|tags| tags.contains_key(&tag)) |
| 1203 | } |
1375 | } |
| @@ -1237,7 +1409,7 @@ impl Display for GenericRoomItem { |
| 1237 | } |
1409 | } |
| 1238 | |
1410 | |
| 1239 | impl ListItem<IambInfo> for GenericRoomItem { |
1411 | impl ListItem<IambInfo> for GenericRoomItem { |
| 1240 | type Section = &'static str; |
1412 | type Section = ListSectionHeader; |
| 1241 | |
1413 | |
| 1242 | fn show( |
1414 | fn show( |
| 1243 | &self, |
1415 | &self, |
| @@ -1257,7 +1429,12 @@ impl ListItem<IambInfo> for GenericRoomItem { |
| 1257 | let tags_style = selected_style(selected, theme.rooms.labels); |
1429 | let tags_style = selected_style(selected, theme.rooms.labels); |
| 1258 | let (name, mut labels) = |
1430 | let (name, mut labels) = |
| 1259 | name_and_labels(&self.name, &self.unread, self.membership, name_style, tags_style); |
1431 | name_and_labels(&self.name, &self.unread, self.membership, name_style, tags_style); |
| 1260 | let mut spans = vec![name]; |
1432 | |
| |
1433 | let mut spans = if self.section.is_some() { |
| |
1434 | vec![Span::raw(" "), name] |
| |
1435 | } else { |
| |
1436 | vec![name] |
| |
1437 | }; |
| 1261 | |
1438 | |
| 1262 | if let Some(label) = self.room_type.text() { |
1439 | if let Some(label) = self.room_type.text() { |
| 1263 | labels.push(vec![Span::styled(label, tags_style)]); |
1440 | labels.push(vec![Span::styled(label, tags_style)]); |
| @@ -1275,6 +1452,10 @@ impl ListItem<IambInfo> for GenericRoomItem { |
| 1275 | // Return the room identifier so that `gf`/`<C-W>gf`/etc. go to the room: |
1452 | // Return the room identifier so that `gf`/`<C-W>gf`/etc. go to the room: |
| 1276 | self.room_id().to_string().into() |
1453 | self.room_id().to_string().into() |
| 1277 | } |
1454 | } |
| |
1455 | |
| |
1456 | fn get_section(&self) -> Option<&Self::Section> { |
| |
1457 | self.section.as_ref() |
| |
1458 | } |
| 1278 | } |
1459 | } |
| 1279 | |
1460 | |
| 1280 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for GenericRoomItem { |
1461 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for GenericRoomItem { |
| @@ -1292,11 +1473,16 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for GenericRoomItem { |
| 1292 | pub struct MemberItem { |
1473 | pub struct MemberItem { |
| 1293 | member: RoomMember, |
1474 | member: RoomMember, |
| 1294 | room_id: OwnedRoomId, |
1475 | room_id: OwnedRoomId, |
| |
1476 | section: Option<ListSectionHeader>, |
| 1295 | } |
1477 | } |
| 1296 | |
1478 | |
| 1297 | impl MemberItem { |
1479 | impl MemberItem { |
| 1298 | fn new(member: RoomMember, room_id: OwnedRoomId) -> Self { |
1480 | fn new(member: RoomMember, room_id: OwnedRoomId) -> Self { |
| 1299 | Self { member, room_id } |
1481 | Self { member, room_id, section: None } |
| |
1482 | } |
| |
1483 | |
| |
1484 | fn set_section(&mut self, sort: &[SortColumn<SortFieldUser>]) { |
| |
1485 | self.section = ListSectionHeader::for_user(self, sort); |
| 1300 | } |
1486 | } |
| 1301 | |
1487 | |
| 1302 | fn is_knock(&self) -> bool { |
1488 | fn is_knock(&self) -> bool { |
| @@ -1315,7 +1501,7 @@ impl Display for MemberItem { |
| 1315 | } |
1501 | } |
| 1316 | |
1502 | |
| 1317 | impl ListItem<IambInfo> for MemberItem { |
1503 | impl ListItem<IambInfo> for MemberItem { |
| 1318 | type Section = &'static str; |
1504 | type Section = ListSectionHeader; |
| 1319 | |
1505 | |
| 1320 | fn show( |
1506 | fn show( |
| 1321 | &self, |
1507 | &self, |
| @@ -1404,6 +1590,10 @@ impl ListItem<IambInfo> for MemberItem { |
| 1404 | return Line::from(spans).into(); |
1590 | return Line::from(spans).into(); |
| 1405 | } |
1591 | } |
| 1406 | |
1592 | |
| |
1593 | fn get_section(&self) -> Option<&ListSectionHeader> { |
| |
1594 | self.section.as_ref() |
| |
1595 | } |
| |
1596 | |
| 1407 | fn get_word(&self) -> Option<String> { |
1597 | fn get_word(&self) -> Option<String> { |
| 1408 | self.member.user_id().to_string().into() |
1598 | self.member.user_id().to_string().into() |
| 1409 | } |
1599 | } |
| @@ -1544,6 +1734,7 @@ mod tests { |
| 1544 | #[derive(Debug, Eq, PartialEq)] |
1734 | #[derive(Debug, Eq, PartialEq)] |
| 1545 | pub(super) struct TestRoomItem { |
1735 | pub(super) struct TestRoomItem { |
| 1546 | pub room_id: OwnedRoomId, |
1736 | pub room_id: OwnedRoomId, |
| |
1737 | pub room_type: RoomType, |
| 1547 | pub tags: Vec<TagName>, |
1738 | pub tags: Vec<TagName>, |
| 1548 | pub alias: Option<OwnedRoomAliasId>, |
1739 | pub alias: Option<OwnedRoomAliasId>, |
| 1549 | pub name: &'static str, |
1740 | pub name: &'static str, |
| @@ -1556,6 +1747,10 @@ mod tests { |
| 1556 | self.room_id.as_ref() |
1747 | self.room_id.as_ref() |
| 1557 | } |
1748 | } |
| 1558 | |
1749 | |
| |
1750 | fn room_type(&self) -> &RoomType { |
| |
1751 | &self.room_type |
| |
1752 | } |
| |
1753 | |
| 1559 | fn has_tag(&self, tag: TagName) -> bool { |
1754 | fn has_tag(&self, tag: TagName) -> bool { |
| 1560 | self.tags.contains(&tag) |
1755 | self.tags.contains(&tag) |
| 1561 | } |
1756 | } |
| @@ -1596,7 +1791,9 @@ mod tests { |
| 1596 | tags: None, |
1791 | tags: None, |
| 1597 | membership: MatrixRoomState::Joined, |
1792 | membership: MatrixRoomState::Joined, |
| 1598 | unread: UnreadInfo::default(), |
1793 | unread: UnreadInfo::default(), |
| |
1794 | room_type_show: true, |
| 1599 | room_type: RoomType::Room, |
1795 | room_type: RoomType::Room, |
| |
1796 | section: None, |
| 1600 | }; |
1797 | }; |
| 1601 | |
1798 | |
| 1602 | // This should return the room ID, and not the alias or name: |
1799 | // This should return the room ID, and not the alias or name: |
| @@ -1616,6 +1813,7 @@ mod tests { |
| 1616 | name: "Z", |
1813 | name: "Z", |
| 1617 | unread: UnreadInfo::default(), |
1814 | unread: UnreadInfo::default(), |
| 1618 | membership: MatrixRoomState::Joined, |
1815 | membership: MatrixRoomState::Joined, |
| |
1816 | room_type: RoomType::Room, |
| 1619 | }; |
1817 | }; |
| 1620 | |
1818 | |
| 1621 | let room2 = TestRoomItem { |
1819 | let room2 = TestRoomItem { |
| @@ -1625,6 +1823,7 @@ mod tests { |
| 1625 | name: "Unnamed Room", |
1823 | name: "Unnamed Room", |
| 1626 | unread: UnreadInfo::default(), |
1824 | unread: UnreadInfo::default(), |
| 1627 | membership: MatrixRoomState::Joined, |
1825 | membership: MatrixRoomState::Joined, |
| |
1826 | room_type: RoomType::Room, |
| 1628 | }; |
1827 | }; |
| 1629 | |
1828 | |
| 1630 | let room3 = TestRoomItem { |
1829 | let room3 = TestRoomItem { |
| @@ -1634,6 +1833,7 @@ mod tests { |
| 1634 | name: "Cool Room", |
1833 | name: "Cool Room", |
| 1635 | unread: UnreadInfo::default(), |
1834 | unread: UnreadInfo::default(), |
| 1636 | membership: MatrixRoomState::Joined, |
1835 | membership: MatrixRoomState::Joined, |
| |
1836 | room_type: RoomType::Room, |
| 1637 | }; |
1837 | }; |
| 1638 | |
1838 | |
| 1639 | // Sort by Name ascending. |
1839 | // Sort by Name ascending. |
| @@ -1688,6 +1888,7 @@ mod tests { |
| 1688 | unread_mentions: 0, |
1888 | unread_mentions: 0, |
| 1689 | }, |
1889 | }, |
| 1690 | membership: MatrixRoomState::Joined, |
1890 | membership: MatrixRoomState::Joined, |
| |
1891 | room_type: RoomType::Room, |
| 1691 | }; |
1892 | }; |
| 1692 | |
1893 | |
| 1693 | let room2 = TestRoomItem { |
1894 | let room2 = TestRoomItem { |
| @@ -1703,6 +1904,7 @@ mod tests { |
| 1703 | unread_mentions: 0, |
1904 | unread_mentions: 0, |
| 1704 | }, |
1905 | }, |
| 1705 | membership: MatrixRoomState::Joined, |
1906 | membership: MatrixRoomState::Joined, |
| |
1907 | room_type: RoomType::Room, |
| 1706 | }; |
1908 | }; |
| 1707 | |
1909 | |
| 1708 | let room3 = TestRoomItem { |
1910 | let room3 = TestRoomItem { |
| @@ -1718,6 +1920,7 @@ mod tests { |
| 1718 | unread_mentions: 0, |
1920 | unread_mentions: 0, |
| 1719 | }, |
1921 | }, |
| 1720 | membership: MatrixRoomState::Joined, |
1922 | membership: MatrixRoomState::Joined, |
| |
1923 | room_type: RoomType::Room, |
| 1721 | }; |
1924 | }; |
| 1722 | |
1925 | |
| 1723 | // Sort by Recent ascending. |
1926 | // Sort by Recent ascending. |
| @@ -1746,6 +1949,7 @@ mod tests { |
| 1746 | name: "Old room 1", |
1949 | name: "Old room 1", |
| 1747 | unread: UnreadInfo::default(), |
1950 | unread: UnreadInfo::default(), |
| 1748 | membership: MatrixRoomState::Joined, |
1951 | membership: MatrixRoomState::Joined, |
| |
1952 | room_type: RoomType::Room, |
| 1749 | }; |
1953 | }; |
| 1750 | |
1954 | |
| 1751 | let room2 = TestRoomItem { |
1955 | let room2 = TestRoomItem { |
| @@ -1755,6 +1959,7 @@ mod tests { |
| 1755 | name: "Old room 2", |
1959 | name: "Old room 2", |
| 1756 | unread: UnreadInfo::default(), |
1960 | unread: UnreadInfo::default(), |
| 1757 | membership: MatrixRoomState::Joined, |
1961 | membership: MatrixRoomState::Joined, |
| |
1962 | room_type: RoomType::Room, |
| 1758 | }; |
1963 | }; |
| 1759 | |
1964 | |
| 1760 | let room3 = TestRoomItem { |
1965 | let room3 = TestRoomItem { |
| @@ -1764,6 +1969,7 @@ mod tests { |
| 1764 | name: "New Fancy Room", |
1969 | name: "New Fancy Room", |
| 1765 | unread: UnreadInfo::default(), |
1970 | unread: UnreadInfo::default(), |
| 1766 | membership: MatrixRoomState::Invited, |
1971 | membership: MatrixRoomState::Invited, |
| |
1972 | room_type: RoomType::Room, |
| 1767 | }; |
1973 | }; |
| 1768 | |
1974 | |
| 1769 | // Sort invites first |
1975 | // Sort invites first |
| @@ -1800,6 +2006,7 @@ mod tests { |
| 1800 | name: "Room E", |
2006 | name: "Room E", |
| 1801 | unread: UnreadInfo::default(), |
2007 | unread: UnreadInfo::default(), |
| 1802 | membership: MatrixRoomState::Joined, |
2008 | membership: MatrixRoomState::Joined, |
| |
2009 | room_type: RoomType::Room, |
| 1803 | }; |
2010 | }; |
| 1804 | |
2011 | |
| 1805 | // Alias and V1 room ID agree: |
2012 | // Alias and V1 room ID agree: |
| @@ -1810,6 +2017,7 @@ mod tests { |
| 1810 | name: "Room D", |
2017 | name: "Room D", |
| 1811 | unread: UnreadInfo::default(), |
2018 | unread: UnreadInfo::default(), |
| 1812 | membership: MatrixRoomState::Joined, |
2019 | membership: MatrixRoomState::Joined, |
| |
2020 | room_type: RoomType::Room, |
| 1813 | }; |
2021 | }; |
| 1814 | |
2022 | |
| 1815 | // Alias, V2 room id: |
2023 | // Alias, V2 room id: |
| @@ -1820,6 +2028,7 @@ mod tests { |
| 1820 | name: "Room C", |
2028 | name: "Room C", |
| 1821 | unread: UnreadInfo::default(), |
2029 | unread: UnreadInfo::default(), |
| 1822 | membership: MatrixRoomState::Invited, |
2030 | membership: MatrixRoomState::Invited, |
| |
2031 | room_type: RoomType::Room, |
| 1823 | }; |
2032 | }; |
| 1824 | |
2033 | |
| 1825 | // Alias and V2 room ID disagree, alias is used: |
2034 | // Alias and V2 room ID disagree, alias is used: |
| @@ -1830,6 +2039,7 @@ mod tests { |
| 1830 | name: "Room B", |
2039 | name: "Room B", |
| 1831 | unread: UnreadInfo::default(), |
2040 | unread: UnreadInfo::default(), |
| 1832 | membership: MatrixRoomState::Invited, |
2041 | membership: MatrixRoomState::Invited, |
| |
2042 | room_type: RoomType::Room, |
| 1833 | }; |
2043 | }; |
| 1834 | |
2044 | |
| 1835 | // No alias and V2 room ID: |
2045 | // No alias and V2 room ID: |
| @@ -1840,6 +2050,7 @@ mod tests { |
| 1840 | name: "Room A", |
2050 | name: "Room A", |
| 1841 | unread: UnreadInfo::default(), |
2051 | unread: UnreadInfo::default(), |
| 1842 | membership: MatrixRoomState::Invited, |
2052 | membership: MatrixRoomState::Invited, |
| |
2053 | room_type: RoomType::Room, |
| 1843 | }; |
2054 | }; |
| 1844 | |
2055 | |
| 1845 | // Sort servers first ascending, name tie breaks: |
2056 | // Sort servers first ascending, name tie breaks: |