| @@ -14,12 +14,22 @@ use feruca::Collator; |
| 14 | 14 | use matrix_sdk::RoomHeroWithProfile; |
| 15 | 15 | use matrix_sdk::room::RoomMember; |
| 16 | 16 | use matrix_sdk::ruma::events::room::member::MembershipState; |
| 17 | use matrix_sdk::ruma::events::room::power_levels::UserPowerLevel; |
| 17 | 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 | 20 | use modalkit_ratatui::Window; |
| 20 | 21 | use modalkit_ratatui::list::{List, ListCursor, ListItem, ListState}; |
| 21 | | |
| 22 | | use crate::base::{RoomNeeds, SortColumn, SortFieldRoom, SortFieldUser, SortOrder, UnreadInfo}; |
| 22 | use ratatui::prelude::Stylize; |
| 23 | |
| 24 | use crate::base::{ |
| 25 | RoomNeeds, |
| 26 | SortColumn, |
| 27 | SortFieldRoom, |
| 28 | SortFieldSpace, |
| 29 | SortFieldUser, |
| 30 | SortOrder, |
| 31 | UnreadInfo, |
| 32 | }; |
| 23 | 33 | use crate::prelude::*; |
| 24 | 34 | use crate::resolve_mxid; |
| 25 | 35 | use crate::windows::room::{RoomState, room_command}; |
| @@ -199,6 +209,20 @@ fn room_cmp<T: RoomLikeItem>( |
| 199 | 209 | // sort larger timestamps towards the top. |
| 200 | 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 | 226 | SortFieldRoom::Invite => { |
| 203 | 227 | // sort invites before other rooms. |
| 204 | 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 | 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 | 433 | trait RoomLikeItem { |
| 289 | 434 | fn room_id(&self) -> &RoomId; |
| 435 | fn room_type(&self) -> &RoomType; |
| 290 | 436 | fn has_tag(&self, tag: TagName) -> bool; |
| 291 | 437 | fn is_unread(&self) -> bool; |
| 292 | 438 | fn recent_ts(&self) -> Option<&MessageTimeStamp>; |
| @@ -565,14 +711,13 @@ impl WindowOps<IambInfo> for IambWindow { |
| 565 | 711 | .dms |
| 566 | 712 | .iter() |
| 567 | 713 | .map(|room| { |
| 568 | | GenericRoomItem::new_unspecified( |
| 569 | | room, |
| 570 | | rooms.get_or_default(room.room_id().to_owned()), |
| 571 | | ) |
| 714 | GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned())) |
| 715 | .show_room_type(false) |
| 572 | 716 | }) |
| 573 | 717 | .collect::<Vec<_>>(); |
| 574 | 718 | let fields = &settings.tunables.sort.dms; |
| 575 | 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 | 722 | state.set(items); |
| 578 | 723 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -597,6 +742,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 597 | 742 | .collect::<Vec<_>>(); |
| 598 | 743 | let fields = &settings.tunables.sort.members; |
| 599 | 744 | items.sort_by(|a, b| user_fields_cmp(a, b, fields)); |
| 745 | items.iter_mut().for_each(|i| i.set_section(fields)); |
| 600 | 746 | state.set(items); |
| 601 | 747 | *last_fetch = Some(Instant::now()); |
| 602 | 748 | } |
| @@ -643,14 +789,13 @@ impl WindowOps<IambInfo> for IambWindow { |
| 643 | 789 | .rooms |
| 644 | 790 | .iter() |
| 645 | 791 | .map(|room| { |
| 646 | | GenericRoomItem::new_unspecified( |
| 647 | | room, |
| 648 | | rooms.get_or_default(room.room_id().to_owned()), |
| 649 | | ) |
| 792 | GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned())) |
| 793 | .show_room_type(false) |
| 650 | 794 | }) |
| 651 | 795 | .collect::<Vec<_>>(); |
| 652 | 796 | let fields = &settings.tunables.sort.rooms; |
| 653 | 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 | 800 | state.set(items); |
| 656 | 801 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -674,6 +819,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 674 | 819 | |
| 675 | 820 | let fields = &settings.tunables.sort.chats; |
| 676 | 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 | 824 | state.set(items); |
| 679 | 825 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -698,6 +844,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 698 | 844 | |
| 699 | 845 | let fields = &settings.tunables.sort.chats; |
| 700 | 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 | 849 | state.set(items); |
| 703 | 850 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -722,6 +869,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 722 | 869 | |
| 723 | 870 | let fields = &settings.tunables.sort.chats; |
| 724 | 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 | 874 | state.set(items); |
| 727 | 875 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -746,6 +894,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 746 | 894 | |
| 747 | 895 | let fields = &settings.tunables.sort.chats; |
| 748 | 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 | 899 | state.set(items); |
| 751 | 900 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -762,15 +911,14 @@ impl WindowOps<IambInfo> for IambWindow { |
| 762 | 911 | .spaces |
| 763 | 912 | .iter() |
| 764 | 913 | .map(|room| { |
| 765 | | GenericRoomItem::new_unspecified( |
| 766 | | room, |
| 767 | | rooms.get_or_default(room.room_id().to_owned()), |
| 768 | | ) |
| 914 | GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned())) |
| 915 | .show_room_type(false) |
| 769 | 916 | }) |
| 770 | 917 | .collect::<Vec<_>>(); |
| 771 | 918 | |
| 772 | 919 | let fields = &settings.tunables.sort.spaces; |
| 773 | 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 | 923 | state.set(items); |
| 776 | 924 | state.set_ignorecase(settings.tunables.ignorecase); |
| @@ -1089,6 +1237,14 @@ enum RoomType { |
| 1089 | 1237 | } |
| 1090 | 1238 | |
| 1091 | 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 | 1248 | fn text(self) -> Option<&'static str> { |
| 1093 | 1249 | match self { |
| 1094 | 1250 | RoomType::DM => Some("DM"), |
| @@ -1105,14 +1261,15 @@ pub struct GenericRoomItem { |
| 1105 | 1261 | name: String, |
| 1106 | 1262 | alias: Option<OwnedRoomAliasId>, |
| 1107 | 1263 | tags: Option<Tags>, |
| 1264 | section: Option<ListSectionHeader>, |
| 1108 | 1265 | membership: MatrixRoomState, |
| 1109 | 1266 | unread: UnreadInfo, |
| 1110 | | |
| 1267 | room_type_show: bool, |
| 1111 | 1268 | room_type: RoomType, |
| 1112 | 1269 | } |
| 1113 | 1270 | |
| 1114 | 1271 | impl GenericRoomItem { |
| 1115 | | pub fn new_unspecified(room: &MatrixRoom, info: &RoomInfo) -> Self { |
| 1272 | pub fn new(room: &MatrixRoom, info: &RoomInfo) -> Self { |
| 1116 | 1273 | let room_id = room.room_id().to_owned(); |
| 1117 | 1274 | |
| 1118 | 1275 | let name = info.name.clone().unwrap_or_default(); |
| @@ -1120,18 +1277,6 @@ impl GenericRoomItem { |
| 1120 | 1277 | let unread = info.unreads(room); |
| 1121 | 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 | 1280 | let room_type = if room.is_space() { |
| 1136 | 1281 | RoomType::Space |
| 1137 | 1282 | } else if room.is_dm() { |
| @@ -1140,7 +1285,17 @@ impl GenericRoomItem { |
| 1140 | 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 | 1301 | /// Create for a room the client doesn't know about. |
| @@ -1168,6 +1323,8 @@ impl GenericRoomItem { |
| 1168 | 1323 | membership: MatrixRoomState::Left, |
| 1169 | 1324 | unread: Default::default(), |
| 1170 | 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 | 1346 | membership, |
| 1190 | 1347 | unread: Default::default(), |
| 1191 | 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 | 1364 | impl RoomLikeItem for GenericRoomItem { |
| @@ -1198,6 +1366,10 @@ impl RoomLikeItem for GenericRoomItem { |
| 1198 | 1366 | &self.room_id |
| 1199 | 1367 | } |
| 1200 | 1368 | |
| 1369 | fn room_type(&self) -> &RoomType { |
| 1370 | &self.room_type |
| 1371 | } |
| 1372 | |
| 1201 | 1373 | fn has_tag(&self, tag: TagName) -> bool { |
| 1202 | 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 | 1411 | impl ListItem<IambInfo> for GenericRoomItem { |
| 1240 | | type Section = &'static str; |
| 1412 | type Section = ListSectionHeader; |
| 1241 | 1413 | |
| 1242 | 1414 | fn show( |
| 1243 | 1415 | &self, |
| @@ -1257,7 +1429,12 @@ impl ListItem<IambInfo> for GenericRoomItem { |
| 1257 | 1429 | let tags_style = selected_style(selected, theme.rooms.labels); |
| 1258 | 1430 | let (name, mut labels) = |
| 1259 | 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 | 1439 | if let Some(label) = self.room_type.text() { |
| 1263 | 1440 | labels.push(vec![Span::styled(label, tags_style)]); |
| @@ -1275,6 +1452,10 @@ impl ListItem<IambInfo> for GenericRoomItem { |
| 1275 | 1452 | // Return the room identifier so that `gf`/`<C-W>gf`/etc. go to the room: |
| 1276 | 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 | 1461 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for GenericRoomItem { |
| @@ -1292,11 +1473,16 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for GenericRoomItem { |
| 1292 | 1473 | pub struct MemberItem { |
| 1293 | 1474 | member: RoomMember, |
| 1294 | 1475 | room_id: OwnedRoomId, |
| 1476 | section: Option<ListSectionHeader>, |
| 1295 | 1477 | } |
| 1296 | 1478 | |
| 1297 | 1479 | impl MemberItem { |
| 1298 | 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 | 1488 | fn is_knock(&self) -> bool { |
| @@ -1315,7 +1501,7 @@ impl Display for MemberItem { |
| 1315 | 1501 | } |
| 1316 | 1502 | |
| 1317 | 1503 | impl ListItem<IambInfo> for MemberItem { |
| 1318 | | type Section = &'static str; |
| 1504 | type Section = ListSectionHeader; |
| 1319 | 1505 | |
| 1320 | 1506 | fn show( |
| 1321 | 1507 | &self, |
| @@ -1404,6 +1590,10 @@ impl ListItem<IambInfo> for MemberItem { |
| 1404 | 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 | 1597 | fn get_word(&self) -> Option<String> { |
| 1408 | 1598 | self.member.user_id().to_string().into() |
| 1409 | 1599 | } |
| @@ -1544,6 +1734,7 @@ mod tests { |
| 1544 | 1734 | #[derive(Debug, Eq, PartialEq)] |
| 1545 | 1735 | pub(super) struct TestRoomItem { |
| 1546 | 1736 | pub room_id: OwnedRoomId, |
| 1737 | pub room_type: RoomType, |
| 1547 | 1738 | pub tags: Vec<TagName>, |
| 1548 | 1739 | pub alias: Option<OwnedRoomAliasId>, |
| 1549 | 1740 | pub name: &'static str, |
| @@ -1556,6 +1747,10 @@ mod tests { |
| 1556 | 1747 | self.room_id.as_ref() |
| 1557 | 1748 | } |
| 1558 | 1749 | |
| 1750 | fn room_type(&self) -> &RoomType { |
| 1751 | &self.room_type |
| 1752 | } |
| 1753 | |
| 1559 | 1754 | fn has_tag(&self, tag: TagName) -> bool { |
| 1560 | 1755 | self.tags.contains(&tag) |
| 1561 | 1756 | } |
| @@ -1596,7 +1791,9 @@ mod tests { |
| 1596 | 1791 | tags: None, |
| 1597 | 1792 | membership: MatrixRoomState::Joined, |
| 1598 | 1793 | unread: UnreadInfo::default(), |
| 1794 | room_type_show: true, |
| 1599 | 1795 | room_type: RoomType::Room, |
| 1796 | section: None, |
| 1600 | 1797 | }; |
| 1601 | 1798 | |
| 1602 | 1799 | // This should return the room ID, and not the alias or name: |
| @@ -1616,6 +1813,7 @@ mod tests { |
| 1616 | 1813 | name: "Z", |
| 1617 | 1814 | unread: UnreadInfo::default(), |
| 1618 | 1815 | membership: MatrixRoomState::Joined, |
| 1816 | room_type: RoomType::Room, |
| 1619 | 1817 | }; |
| 1620 | 1818 | |
| 1621 | 1819 | let room2 = TestRoomItem { |
| @@ -1625,6 +1823,7 @@ mod tests { |
| 1625 | 1823 | name: "Unnamed Room", |
| 1626 | 1824 | unread: UnreadInfo::default(), |
| 1627 | 1825 | membership: MatrixRoomState::Joined, |
| 1826 | room_type: RoomType::Room, |
| 1628 | 1827 | }; |
| 1629 | 1828 | |
| 1630 | 1829 | let room3 = TestRoomItem { |
| @@ -1634,6 +1833,7 @@ mod tests { |
| 1634 | 1833 | name: "Cool Room", |
| 1635 | 1834 | unread: UnreadInfo::default(), |
| 1636 | 1835 | membership: MatrixRoomState::Joined, |
| 1836 | room_type: RoomType::Room, |
| 1637 | 1837 | }; |
| 1638 | 1838 | |
| 1639 | 1839 | // Sort by Name ascending. |
| @@ -1688,6 +1888,7 @@ mod tests { |
| 1688 | 1888 | unread_mentions: 0, |
| 1689 | 1889 | }, |
| 1690 | 1890 | membership: MatrixRoomState::Joined, |
| 1891 | room_type: RoomType::Room, |
| 1691 | 1892 | }; |
| 1692 | 1893 | |
| 1693 | 1894 | let room2 = TestRoomItem { |
| @@ -1703,6 +1904,7 @@ mod tests { |
| 1703 | 1904 | unread_mentions: 0, |
| 1704 | 1905 | }, |
| 1705 | 1906 | membership: MatrixRoomState::Joined, |
| 1907 | room_type: RoomType::Room, |
| 1706 | 1908 | }; |
| 1707 | 1909 | |
| 1708 | 1910 | let room3 = TestRoomItem { |
| @@ -1718,6 +1920,7 @@ mod tests { |
| 1718 | 1920 | unread_mentions: 0, |
| 1719 | 1921 | }, |
| 1720 | 1922 | membership: MatrixRoomState::Joined, |
| 1923 | room_type: RoomType::Room, |
| 1721 | 1924 | }; |
| 1722 | 1925 | |
| 1723 | 1926 | // Sort by Recent ascending. |
| @@ -1746,6 +1949,7 @@ mod tests { |
| 1746 | 1949 | name: "Old room 1", |
| 1747 | 1950 | unread: UnreadInfo::default(), |
| 1748 | 1951 | membership: MatrixRoomState::Joined, |
| 1952 | room_type: RoomType::Room, |
| 1749 | 1953 | }; |
| 1750 | 1954 | |
| 1751 | 1955 | let room2 = TestRoomItem { |
| @@ -1755,6 +1959,7 @@ mod tests { |
| 1755 | 1959 | name: "Old room 2", |
| 1756 | 1960 | unread: UnreadInfo::default(), |
| 1757 | 1961 | membership: MatrixRoomState::Joined, |
| 1962 | room_type: RoomType::Room, |
| 1758 | 1963 | }; |
| 1759 | 1964 | |
| 1760 | 1965 | let room3 = TestRoomItem { |
| @@ -1764,6 +1969,7 @@ mod tests { |
| 1764 | 1969 | name: "New Fancy Room", |
| 1765 | 1970 | unread: UnreadInfo::default(), |
| 1766 | 1971 | membership: MatrixRoomState::Invited, |
| 1972 | room_type: RoomType::Room, |
| 1767 | 1973 | }; |
| 1768 | 1974 | |
| 1769 | 1975 | // Sort invites first |
| @@ -1800,6 +2006,7 @@ mod tests { |
| 1800 | 2006 | name: "Room E", |
| 1801 | 2007 | unread: UnreadInfo::default(), |
| 1802 | 2008 | membership: MatrixRoomState::Joined, |
| 2009 | room_type: RoomType::Room, |
| 1803 | 2010 | }; |
| 1804 | 2011 | |
| 1805 | 2012 | // Alias and V1 room ID agree: |
| @@ -1810,6 +2017,7 @@ mod tests { |
| 1810 | 2017 | name: "Room D", |
| 1811 | 2018 | unread: UnreadInfo::default(), |
| 1812 | 2019 | membership: MatrixRoomState::Joined, |
| 2020 | room_type: RoomType::Room, |
| 1813 | 2021 | }; |
| 1814 | 2022 | |
| 1815 | 2023 | // Alias, V2 room id: |
| @@ -1820,6 +2028,7 @@ mod tests { |
| 1820 | 2028 | name: "Room C", |
| 1821 | 2029 | unread: UnreadInfo::default(), |
| 1822 | 2030 | membership: MatrixRoomState::Invited, |
| 2031 | room_type: RoomType::Room, |
| 1823 | 2032 | }; |
| 1824 | 2033 | |
| 1825 | 2034 | // Alias and V2 room ID disagree, alias is used: |
| @@ -1830,6 +2039,7 @@ mod tests { |
| 1830 | 2039 | name: "Room B", |
| 1831 | 2040 | unread: UnreadInfo::default(), |
| 1832 | 2041 | membership: MatrixRoomState::Invited, |
| 2042 | room_type: RoomType::Room, |
| 1833 | 2043 | }; |
| 1834 | 2044 | |
| 1835 | 2045 | // No alias and V2 room ID: |
| @@ -1840,6 +2050,7 @@ mod tests { |
| 1840 | 2050 | name: "Room A", |
| 1841 | 2051 | unread: UnreadInfo::default(), |
| 1842 | 2052 | membership: MatrixRoomState::Invited, |
| 2053 | room_type: RoomType::Room, |
| 1843 | 2054 | }; |
| 1844 | 2055 | |
| 1845 | 2056 | // Sort servers first ascending, name tie breaks: |