Commit 760fe154c3

760fe154c3c398a01a9b1ec32f12addd587538ce

parent: 7f5420850f

Unregistered key

vaw <git@nlih.de> · 2026-09-18 03:34 UTC
committer: <noreply@github.com>

Unify the the room list representation (#708)

Layout: unified · split

src/base.rs +10 −8
@@ -1783,22 +1783,22 @@ fn emoji_map() -> CompletionMap<String, &'static Emoji> {
1783#[derive(Default)] 1783#[derive(Default)]
1784pub struct SyncInfo { 1784pub struct SyncInfo {
1785 /// Spaces that the user is a member of. 1785 /// Spaces that the user is a member of.
1786 pub spaces: Vec<Arc<(MatrixRoom, Option<Tags>)>>, 1786 pub spaces: Vec<MatrixRoom>,
1787 1787
1788 /// Rooms that the user is a member of. 1788 /// Rooms that the user is a member of.
1789 pub rooms: Vec<Arc<(MatrixRoom, Option<Tags>)>>, 1789 pub rooms: Vec<MatrixRoom>,
1790 1790
1791 /// DMs that the user is a member of. 1791 /// DMs that the user is a member of.
1792 pub dms: Vec<Arc<(MatrixRoom, Option<Tags>)>>, 1792 pub dms: Vec<MatrixRoom>,
1793} 1793}
1794 1794
1795impl SyncInfo { 1795impl SyncInfo {
1796 pub fn rooms(&self) -> impl Iterator<Item = &RoomId> { 1796 pub fn rooms(&self) -> impl Iterator<Item = &RoomId> {
1797 self.rooms.iter().map(|r| r.0.room_id()) 1797 self.rooms.iter().map(|r| r.room_id())
1798 } 1798 }
1799 1799
1800 pub fn dms(&self) -> impl Iterator<Item = &RoomId> { 1800 pub fn dms(&self) -> impl Iterator<Item = &RoomId> {
1801 self.dms.iter().map(|r| r.0.room_id()) 1801 self.dms.iter().map(|r| r.room_id())
1802 } 1802 }
1803 1803
1804 pub fn chats(&self) -> impl Iterator<Item = &RoomId> { 1804 pub fn chats(&self) -> impl Iterator<Item = &RoomId> {
@@ -1977,9 +1977,11 @@ impl ChatStore {
1977 self.rooms.get_or_default(room_id) 1977 self.rooms.get_or_default(room_id)
1978 } 1978 }
1979 1979
1980 /// Set the name for a room. 1980 /// Set the name and tags for a room.
1981 pub fn set_room_name(&mut self, room_id: &RoomId, name: &str) { 1981 pub fn set_room_info(&mut self, room_id: OwnedRoomId, name: String, tags: Option<Tags>) {
1982 self.rooms.get_or_default(room_id.to_owned()).name = name.to_string().into(); 1982 let info = self.rooms.get_or_default(room_id);
1983 info.name = name.into();
1984 info.tags = tags;
1983 } 1985 }
1984} 1986}
1985 1987
src/windows/mod.rs +173 −551
@@ -12,8 +12,9 @@ use std::fmt::{self};
12 12
13use feruca::Collator; 13use feruca::Collator;
14use matrix_sdk::room::RoomMember; 14use matrix_sdk::room::RoomMember;
15use matrix_sdk::ruma::RoomAliasId;
16use matrix_sdk::ruma::events::room::member::MembershipState; 15use matrix_sdk::ruma::events::room::member::MembershipState;
16use matrix_sdk::ruma::{RoomAliasId, assign};
17use modalkit::editing::completion::CompletionMap;
17use modalkit_ratatui::Window; 18use modalkit_ratatui::Window;
18use modalkit_ratatui::list::{List, ListCursor, ListItem, ListState}; 19use modalkit_ratatui::list::{List, ListCursor, ListItem, ListState};
19 20
@@ -27,8 +28,6 @@ pub mod room;
27pub mod verify; 28pub mod verify;
28pub mod welcome; 29pub mod welcome;
29 30
30type MatrixRoomInfo = Arc<(MatrixRoom, Option<Tags>)>;
31
32const MEMBER_FETCH_DEBOUNCE: Duration = Duration::from_secs(5); 31const MEMBER_FETCH_DEBOUNCE: Duration = Duration::from_secs(5);
33 32
34#[inline] 33#[inline]
@@ -55,20 +54,10 @@ pub fn selected_style(selected: bool) -> Style {
55 } 54 }
56} 55}
57 56
58#[inline]
59fn selected_span(s: &str, selected: bool) -> Span<'_> {
60 Span::styled(s, selected_style(selected))
61}
62
63#[inline]
64fn selected_text(s: &str, selected: bool) -> Text<'_> {
65 Text::from(selected_span(s, selected))
66}
67
68fn name_and_labels<'a>( 57fn name_and_labels<'a>(
69 name: &'a str, 58 name: &'a str,
70 unread: &UnreadInfo, 59 unread: &UnreadInfo,
71 room: &MatrixRoom, 60 room_membership: MatrixRoomState,
72 style: Style, 61 style: Style,
73) -> (Span<'a>, Vec<Vec<Span<'static>>>) { 62) -> (Span<'a>, Vec<Vec<Span<'static>>>) {
74 // TODO: use different colors for "mention", "notification", "muted room" 63 // TODO: use different colors for "mention", "notification", "muted room"
@@ -82,7 +71,7 @@ fn name_and_labels<'a>(
82 71
83 let mut labels = vec![]; 72 let mut labels = vec![];
84 73
85 match room.state() { 74 match room_membership {
86 MatrixRoomState::Joined => {}, 75 MatrixRoomState::Joined => {},
87 MatrixRoomState::Left => labels.push(vec![Span::styled("Left", style)]), 76 MatrixRoomState::Left => labels.push(vec![Span::styled("Left", style)]),
88 MatrixRoomState::Banned => labels.push(vec![Span::styled("Banned", style)]), 77 MatrixRoomState::Banned => labels.push(vec![Span::styled("Banned", style)]),
@@ -263,6 +252,7 @@ trait RoomLikeItem {
263 fn alias(&self) -> Option<&RoomAliasId>; 252 fn alias(&self) -> Option<&RoomAliasId>;
264 fn name(&self) -> &str; 253 fn name(&self) -> &str;
265 fn is_invite(&self) -> bool; 254 fn is_invite(&self) -> bool;
255 fn has_mention(&self) -> bool;
266} 256}
267 257
268#[inline] 258#[inline]
@@ -313,17 +303,17 @@ macro_rules! delegate {
313} 303}
314 304
315pub enum IambWindow { 305pub enum IambWindow {
316 DirectList(DirectListState), 306 DirectList(RoomListState),
317 MemberList(MemberListState, OwnedRoomId, Option<Instant>), 307 MemberList(MemberListState, OwnedRoomId, Option<Instant>),
318 Room(RoomState), 308 Room(RoomState),
319 VerifyList(VerifyListState), 309 VerifyList(VerifyListState),
320 RoomList(RoomListState), 310 RoomList(RoomListState),
321 SpaceList(SpaceListState), 311 SpaceList(RoomListState),
322 Welcome(WelcomeState), 312 Welcome(WelcomeState),
323 ChatList(ChatListState), 313 ChatList(RoomListState),
324 UnreadList(UnreadListState), 314 UnreadList(RoomListState),
325 MentionsList(MentionsListState), 315 MentionsList(RoomListState),
326 InvitesList(InvitesListState), 316 InvitesList(RoomListState),
327} 317}
328 318
329impl IambWindow { 319impl IambWindow {
@@ -402,22 +392,10 @@ impl IambWindow {
402 } 392 }
403} 393}
404 394
405pub type DirectListState = ListState<DirectItem, IambInfo>;
406pub type MemberListState = ListState<MemberItem, IambInfo>; 395pub type MemberListState = ListState<MemberItem, IambInfo>;
407pub type RoomListState = ListState<RoomItem, IambInfo>; 396pub type RoomListState = ListState<GenericRoomItem, IambInfo>;
408pub type ChatListState = ListState<GenericChatItem, IambInfo>;
409pub type UnreadListState = ListState<GenericChatItem, IambInfo>;
410pub type MentionsListState = ListState<GenericChatItem, IambInfo>;
411pub type InvitesListState = ListState<GenericChatItem, IambInfo>;
412pub type SpaceListState = ListState<SpaceItem, IambInfo>;
413pub type VerifyListState = ListState<VerifyItem, IambInfo>; 397pub type VerifyListState = ListState<VerifyItem, IambInfo>;
414 398
415impl From<ChatListState> for IambWindow {
416 fn from(list: ChatListState) -> Self {
417 IambWindow::ChatList(list)
418 }
419}
420
421impl From<RoomState> for IambWindow { 399impl From<RoomState> for IambWindow {
422 fn from(room: RoomState) -> Self { 400 fn from(room: RoomState) -> Self {
423 IambWindow::Room(room) 401 IambWindow::Room(room)
@@ -430,24 +408,6 @@ impl From<VerifyListState> for IambWindow {
430 } 408 }
431} 409}
432 410
433impl From<DirectListState> for IambWindow {
434 fn from(list: DirectListState) -> Self {
435 IambWindow::DirectList(list)
436 }
437}
438
439impl From<RoomListState> for IambWindow {
440 fn from(list: RoomListState) -> Self {
441 IambWindow::RoomList(list)
442 }
443}
444
445impl From<SpaceListState> for IambWindow {
446 fn from(list: SpaceListState) -> Self {
447 IambWindow::SpaceList(list)
448 }
449}
450
451impl From<WelcomeState> for IambWindow { 411impl From<WelcomeState> for IambWindow {
452 fn from(win: WelcomeState) -> Self { 412 fn from(win: WelcomeState) -> Self {
453 IambWindow::Welcome(win) 413 IambWindow::Welcome(win)
@@ -511,23 +471,30 @@ impl TerminalCursor for IambWindow {
511 471
512impl WindowOps<IambInfo> for IambWindow { 472impl WindowOps<IambInfo> for IambWindow {
513 fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { 473 fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) {
474 let ChatStore {
475 collator,
476 names,
477 rooms,
478 settings,
479 sync_info,
480 verifications,
481 worker,
482 ..
483 } = &mut store.application;
484
514 match self { 485 match self {
515 IambWindow::Room(state) => state.draw(area, buf, focused, store), 486 IambWindow::Room(state) => state.draw(area, buf, focused, store),
516 IambWindow::DirectList(state) => { 487 IambWindow::DirectList(state) => {
517 let mut items = store 488 let mut items = sync_info
518 .application
519 .sync_info
520 .dms 489 .dms
521 .clone() 490 .iter()
522 .into_iter() 491 .map(|room| GenericRoomItem::new_unspecified(room, rooms, names))
523 .map(|room_info| DirectItem::new(room_info, store))
524 .collect::<Vec<_>>(); 492 .collect::<Vec<_>>();
525 let fields = &store.application.settings.tunables.sort.dms; 493 let fields = &settings.tunables.sort.dms;
526 let collator = &mut store.application.collator;
527 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); 494 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator));
528 495
529 state.set(items); 496 state.set(items);
530 state.set_ignorecase(store.application.settings.tunables.ignorecase); 497 state.set_ignorecase(settings.tunables.ignorecase);
531 498
532 List::new(store) 499 List::new(store)
533 .empty_message("No direct messages yet!") 500 .empty_message("No direct messages yet!")
@@ -541,18 +508,18 @@ impl WindowOps<IambInfo> for IambWindow {
541 None => true, 508 None => true,
542 }; 509 };
543 510
544 if need_fetch && let Ok(mems) = store.application.worker.members(room_id.clone()) { 511 if need_fetch && let Ok(mems) = worker.members(room_id.clone()) {
545 let mut items = mems 512 let mut items = mems
546 .into_iter() 513 .into_iter()
547 .map(|m| MemberItem::new(m, room_id.clone())) 514 .map(|m| MemberItem::new(m, room_id.clone()))
548 .collect::<Vec<_>>(); 515 .collect::<Vec<_>>();
549 let fields = &store.application.settings.tunables.sort.members; 516 let fields = &settings.tunables.sort.members;
550 items.sort_by(|a, b| user_fields_cmp(a, b, fields)); 517 items.sort_by(|a, b| user_fields_cmp(a, b, fields));
551 state.set(items); 518 state.set(items);
552 *last_fetch = Some(Instant::now()); 519 *last_fetch = Some(Instant::now());
553 } 520 }
554 521
555 state.set_ignorecase(store.application.settings.tunables.ignorecase); 522 state.set_ignorecase(settings.tunables.ignorecase);
556 523
557 List::new(store) 524 List::new(store)
558 .empty_message("No users here yet!") 525 .empty_message("No users here yet!")
@@ -561,20 +528,16 @@ impl WindowOps<IambInfo> for IambWindow {
561 .render(area, buf, state); 528 .render(area, buf, state);
562 }, 529 },
563 IambWindow::RoomList(state) => { 530 IambWindow::RoomList(state) => {
564 let mut items = store 531 let mut items = sync_info
565 .application
566 .sync_info
567 .rooms 532 .rooms
568 .clone() 533 .iter()
569 .into_iter() 534 .map(|room| GenericRoomItem::new_unspecified(room, rooms, names))
570 .map(|room_info| RoomItem::new(room_info, store))
571 .collect::<Vec<_>>(); 535 .collect::<Vec<_>>();
572 let fields = &store.application.settings.tunables.sort.rooms; 536 let fields = &settings.tunables.sort.rooms;
573 let collator = &mut store.application.collator;
574 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); 537 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator));
575 538
576 state.set(items); 539 state.set(items);
577 state.set_ignorecase(store.application.settings.tunables.ignorecase); 540 state.set_ignorecase(settings.tunables.ignorecase);
578 541
579 List::new(store) 542 List::new(store)
580 .empty_message("You haven't joined any rooms yet") 543 .empty_message("You haven't joined any rooms yet")
@@ -583,31 +546,18 @@ impl WindowOps<IambInfo> for IambWindow {
583 .render(area, buf, state); 546 .render(area, buf, state);
584 }, 547 },
585 IambWindow::ChatList(state) => { 548 IambWindow::ChatList(state) => {
586 let mut items = store 549 let mut items = sync_info
587 .application
588 .sync_info
589 .rooms 550 .rooms
590 .clone() 551 .iter()
591 .into_iter() 552 .chain(sync_info.dms.iter())
592 .map(|room_info| GenericChatItem::new(room_info, store, false)) 553 .map(|room| GenericRoomItem::new(room, rooms, names))
593 .collect::<Vec<_>>(); 554 .collect::<Vec<_>>();
594 555
595 let dms = store 556 let fields = &settings.tunables.sort.chats;
596 .application
597 .sync_info
598 .dms
599 .clone()
600 .into_iter()
601 .map(|room_info| GenericChatItem::new(room_info, store, true));
602
603 items.extend(dms);
604
605 let fields = &store.application.settings.tunables.sort.chats;
606 let collator = &mut store.application.collator;
607 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); 557 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator));
608 558
609 state.set(items); 559 state.set(items);
610 state.set_ignorecase(store.application.settings.tunables.ignorecase); 560 state.set_ignorecase(settings.tunables.ignorecase);
611 561
612 List::new(store) 562 List::new(store)
613 .empty_message("You do not have rooms or dms yet") 563 .empty_message("You do not have rooms or dms yet")
@@ -616,33 +566,19 @@ impl WindowOps<IambInfo> for IambWindow {
616 .render(area, buf, state); 566 .render(area, buf, state);
617 }, 567 },
618 IambWindow::UnreadList(state) => { 568 IambWindow::UnreadList(state) => {
619 let mut items = store 569 let mut items = sync_info
620 .application
621 .sync_info
622 .rooms 570 .rooms
623 .clone() 571 .iter()
624 .into_iter() 572 .chain(sync_info.dms.iter())
625 .map(|room_info| GenericChatItem::new(room_info, store, false)) 573 .map(|room| GenericRoomItem::new(room, rooms, names))
626 .filter(RoomLikeItem::is_unread) 574 .filter(RoomLikeItem::is_unread)
627 .collect::<Vec<_>>(); 575 .collect::<Vec<_>>();
628 576
629 let dms = store 577 let fields = &settings.tunables.sort.chats;
630 .application
631 .sync_info
632 .dms
633 .clone()
634 .into_iter()
635 .map(|room_info| GenericChatItem::new(room_info, store, true))
636 .filter(RoomLikeItem::is_unread);
637
638 items.extend(dms);
639
640 let fields = &store.application.settings.tunables.sort.chats;
641 let collator = &mut store.application.collator;
642 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); 578 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator));
643 579
644 state.set(items); 580 state.set(items);
645 state.set_ignorecase(store.application.settings.tunables.ignorecase); 581 state.set_ignorecase(settings.tunables.ignorecase);
646 582
647 List::new(store) 583 List::new(store)
648 .empty_message("You do not have any unreads yet") 584 .empty_message("You do not have any unreads yet")
@@ -651,33 +587,19 @@ impl WindowOps<IambInfo> for IambWindow {
651 .render(area, buf, state); 587 .render(area, buf, state);
652 }, 588 },
653 IambWindow::MentionsList(state) => { 589 IambWindow::MentionsList(state) => {
654 let mut items = store 590 let mut items = sync_info
655 .application
656 .sync_info
657 .rooms 591 .rooms
658 .clone() 592 .iter()
659 .into_iter() 593 .chain(sync_info.dms.iter())
660 .map(|room_info| GenericChatItem::new(room_info, store, false)) 594 .map(|room| GenericRoomItem::new(room, rooms, names))
661 .filter(GenericChatItem::has_mention) 595 .filter(RoomLikeItem::has_mention)
662 .collect::<Vec<_>>(); 596 .collect::<Vec<_>>();
663 597
664 let dms = store 598 let fields = &settings.tunables.sort.chats;
665 .application
666 .sync_info
667 .dms
668 .clone()
669 .into_iter()
670 .map(|room_info| GenericChatItem::new(room_info, store, true))
671 .filter(GenericChatItem::has_mention);
672
673 items.extend(dms);
674
675 let fields = &store.application.settings.tunables.sort.chats;
676 let collator = &mut store.application.collator;
677 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); 599 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator));
678 600
679 state.set(items); 601 state.set(items);
680 state.set_ignorecase(store.application.settings.tunables.ignorecase); 602 state.set_ignorecase(settings.tunables.ignorecase);
681 603
682 List::new(store) 604 List::new(store)
683 .empty_message("You do not have any unread mentions yet") 605 .empty_message("You do not have any unread mentions yet")
@@ -686,33 +608,19 @@ impl WindowOps<IambInfo> for IambWindow {
686 .render(area, buf, state); 608 .render(area, buf, state);
687 }, 609 },
688 IambWindow::InvitesList(state) => { 610 IambWindow::InvitesList(state) => {
689 let mut items = store 611 let mut items = sync_info
690 .application
691 .sync_info
692 .rooms 612 .rooms
693 .clone() 613 .iter()
694 .into_iter() 614 .chain(sync_info.dms.iter())
695 .map(|room_info| GenericChatItem::new(room_info, store, false)) 615 .map(|room| GenericRoomItem::new(room, rooms, names))
696 .filter(GenericChatItem::is_invite) 616 .filter(RoomLikeItem::is_invite)
697 .collect::<Vec<_>>(); 617 .collect::<Vec<_>>();
698 618
699 let dms = store 619 let fields = &settings.tunables.sort.chats;
700 .application
701 .sync_info
702 .dms
703 .clone()
704 .into_iter()
705 .map(|room_info| GenericChatItem::new(room_info, store, true))
706 .filter(GenericChatItem::is_invite);
707
708 items.extend(dms);
709
710 let fields = &store.application.settings.tunables.sort.chats;
711 let collator = &mut store.application.collator;
712 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); 620 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator));
713 621
714 state.set(items); 622 state.set(items);
715 state.set_ignorecase(store.application.settings.tunables.ignorecase); 623 state.set_ignorecase(settings.tunables.ignorecase);
716 624
717 List::new(store) 625 List::new(store)
718 .empty_message("You do not have any open invites") 626 .empty_message("You do not have any open invites")
@@ -721,20 +629,17 @@ impl WindowOps<IambInfo> for IambWindow {
721 .render(area, buf, state); 629 .render(area, buf, state);
722 }, 630 },
723 IambWindow::SpaceList(state) => { 631 IambWindow::SpaceList(state) => {
724 let mut items = store 632 let mut items = sync_info
725 .application
726 .sync_info
727 .spaces 633 .spaces
728 .clone() 634 .iter()
729 .into_iter() 635 .map(|room| GenericRoomItem::new_unspecified(room, rooms, names))
730 .map(|room| SpaceItem::new(room, store))
731 .collect::<Vec<_>>(); 636 .collect::<Vec<_>>();
732 let fields = &store.application.settings.tunables.sort.spaces; 637
733 let collator = &mut store.application.collator; 638 let fields = &settings.tunables.sort.spaces;
734 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); 639 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator));
735 640
736 state.set(items); 641 state.set(items);
737 state.set_ignorecase(store.application.settings.tunables.ignorecase); 642 state.set_ignorecase(settings.tunables.ignorecase);
738 643
739 List::new(store) 644 List::new(store)
740 .empty_message("You haven't joined any spaces yet") 645 .empty_message("You haven't joined any spaces yet")
@@ -743,9 +648,7 @@ impl WindowOps<IambInfo> for IambWindow {
743 .render(area, buf, state); 648 .render(area, buf, state);
744 }, 649 },
745 IambWindow::VerifyList(state) => { 650 IambWindow::VerifyList(state) => {
746 let mut items = store 651 let mut items = verifications
747 .application
748 .verifications
749 .iter() 652 .iter()
750 .map(|(_, req)| VerifyItem::new(req.to_owned())) 653 .map(|(_, req)| VerifyItem::new(req.to_owned()))
751 .collect::<Vec<_>>(); 654 .collect::<Vec<_>>();
@@ -758,7 +661,7 @@ impl WindowOps<IambInfo> for IambWindow {
758 } 661 }
759 662
760 state.set(items); 663 state.set(items);
761 state.set_ignorecase(store.application.settings.tunables.ignorecase); 664 state.set_ignorecase(settings.tunables.ignorecase);
762 665
763 List::new(store) 666 List::new(store)
764 .empty_message("No in-progress verifications") 667 .empty_message("No in-progress verifications")
@@ -773,18 +676,18 @@ impl WindowOps<IambInfo> for IambWindow {
773 fn dup(&self, store: &mut ProgramStore) -> Self { 676 fn dup(&self, store: &mut ProgramStore) -> Self {
774 match self { 677 match self {
775 IambWindow::Room(w) => w.dup(store).into(), 678 IambWindow::Room(w) => w.dup(store).into(),
776 IambWindow::DirectList(w) => w.dup(store).into(), 679 IambWindow::DirectList(w) => Self::DirectList(w.dup(store)),
777 IambWindow::MemberList(w, room_id, last_fetch) => { 680 IambWindow::MemberList(w, room_id, last_fetch) => {
778 IambWindow::MemberList(w.dup(store), room_id.clone(), *last_fetch) 681 IambWindow::MemberList(w.dup(store), room_id.clone(), *last_fetch)
779 }, 682 },
780 IambWindow::RoomList(w) => w.dup(store).into(), 683 IambWindow::RoomList(w) => Self::RoomList(w.dup(store)),
781 IambWindow::SpaceList(w) => w.dup(store).into(), 684 IambWindow::SpaceList(w) => Self::SpaceList(w.dup(store)),
782 IambWindow::VerifyList(w) => w.dup(store).into(), 685 IambWindow::VerifyList(w) => w.dup(store).into(),
783 IambWindow::Welcome(w) => w.dup(store).into(), 686 IambWindow::Welcome(w) => w.dup(store).into(),
784 IambWindow::ChatList(w) => w.dup(store).into(), 687 IambWindow::ChatList(w) => Self::ChatList(w.dup(store)),
785 IambWindow::UnreadList(w) => w.dup(store).into(), 688 IambWindow::UnreadList(w) => Self::UnreadList(w.dup(store)),
786 IambWindow::MentionsList(w) => w.dup(store).into(), 689 IambWindow::MentionsList(w) => Self::MentionsList(w.dup(store)),
787 IambWindow::InvitesList(w) => w.dup(store).into(), 690 IambWindow::InvitesList(w) => Self::InvitesList(w.dup(store)),
788 } 691 }
789 } 692 }
790 693
@@ -902,26 +805,26 @@ impl Window<IambInfo> for IambWindow {
902 return Ok(RoomState::not_joined(name).into()); 805 return Ok(RoomState::not_joined(name).into());
903 }, 806 },
904 IambId::DirectList => { 807 IambId::DirectList => {
905 let list = DirectListState::new(IambBufferId::DirectList, vec![]); 808 let list = RoomListState::new(IambBufferId::DirectList, vec![]);
906 809
907 return Ok(list.into()); 810 return Ok(Self::DirectList(list));
908 }, 811 },
909 IambId::MemberList(room_id) => { 812 IambId::MemberList(room_id) => {
910 let id = IambBufferId::MemberList(room_id.clone()); 813 let id = IambBufferId::MemberList(room_id.clone());
911 let list = MemberListState::new(id, vec![]); 814 let list = MemberListState::new(id, vec![]);
912 let win = IambWindow::MemberList(list, room_id, None); 815 let win = Self::MemberList(list, room_id, None);
913 816
914 return Ok(win); 817 return Ok(win);
915 }, 818 },
916 IambId::RoomList => { 819 IambId::RoomList => {
917 let list = RoomListState::new(IambBufferId::RoomList, vec![]); 820 let list = RoomListState::new(IambBufferId::RoomList, vec![]);
918 821
919 return Ok(list.into()); 822 return Ok(Self::RoomList(list));
920 }, 823 },
921 IambId::SpaceList => { 824 IambId::SpaceList => {
922 let list = SpaceListState::new(IambBufferId::SpaceList, vec![]); 825 let list = RoomListState::new(IambBufferId::SpaceList, vec![]);
923 826
924 return Ok(list.into()); 827 return Ok(Self::SpaceList(list));
925 }, 828 },
926 IambId::VerifyList => { 829 IambId::VerifyList => {
927 let list = VerifyListState::new(IambBufferId::VerifyList, vec![]); 830 let list = VerifyListState::new(IambBufferId::VerifyList, vec![]);
@@ -934,24 +837,24 @@ impl Window<IambInfo> for IambWindow {
934 return Ok(win.into()); 837 return Ok(win.into());
935 }, 838 },
936 IambId::ChatList => { 839 IambId::ChatList => {
937 let list = ChatListState::new(IambBufferId::ChatList, vec![]); 840 let list = RoomListState::new(IambBufferId::ChatList, vec![]);
938 841
939 Ok(list.into()) 842 return Ok(Self::ChatList(list));
940 }, 843 },
941 IambId::UnreadList => { 844 IambId::UnreadList => {
942 let list = UnreadListState::new(IambBufferId::UnreadList, vec![]); 845 let list = RoomListState::new(IambBufferId::UnreadList, vec![]);
943 846
944 Ok(IambWindow::UnreadList(list)) 847 Ok(Self::UnreadList(list))
945 }, 848 },
946 IambId::MentionsList => { 849 IambId::MentionsList => {
947 let list = MentionsListState::new(IambBufferId::MentionsList, vec![]); 850 let list = RoomListState::new(IambBufferId::MentionsList, vec![]);
948 851
949 Ok(IambWindow::MentionsList(list)) 852 Ok(Self::MentionsList(list))
950 }, 853 },
951 IambId::InvitesList => { 854 IambId::InvitesList => {
952 let list = InvitesListState::new(IambBufferId::InvitesList, vec![]); 855 let list = RoomListState::new(IambBufferId::InvitesList, vec![]);
953 856
954 Ok(IambWindow::InvitesList(list)) 857 Ok(Self::InvitesList(list))
955 }, 858 },
956 } 859 }
957 } 860 }
@@ -978,317 +881,130 @@ impl Window<IambInfo> for IambWindow {
978 } 881 }
979} 882}
980 883
981#[derive(Clone)] 884/// This is used to determine what tag to show on a [`GenericRoomItem`].
982pub struct GenericChatItem { 885#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
983 room_info: MatrixRoomInfo, 886enum RoomType {
984 name: String, 887 DM,
985 alias: Option<OwnedRoomAliasId>, 888 Room,
986 unread: UnreadInfo, 889 Space,
987 is_dm: bool,
988}
989
990impl GenericChatItem {
991 fn new(room_info: MatrixRoomInfo, store: &mut ProgramStore, is_dm: bool) -> Self {
992 let room = &room_info.deref().0;
993 let room_id = room.room_id();
994
995 let info = store.application.rooms.get_or_default(room_id.to_owned());
996 let name = info.name.clone().unwrap_or_default();
997 let alias = room.canonical_alias();
998 let unread = info.unreads(room);
999 info.tags.clone_from(&room_info.deref().1);
1000
1001 if let Some(alias) = &alias {
1002 store.application.names.insert(alias.to_owned(), room_id.to_owned());
1003 }
1004
1005 GenericChatItem { room_info, name, alias, is_dm, unread }
1006 }
1007
1008 #[inline]
1009 fn room(&self) -> &MatrixRoom {
1010 &self.room_info.deref().0
1011 }
1012
1013 #[inline]
1014 fn tags(&self) -> &Option<Tags> {
1015 &self.room_info.deref().1
1016 }
1017
1018 #[inline]
1019 fn has_mention(&self) -> bool {
1020 self.unread.has_mention()
1021 }
1022}
1023
1024impl RoomLikeItem for GenericChatItem {
1025 fn name(&self) -> &str {
1026 self.name.as_str()
1027 }
1028
1029 fn alias(&self) -> Option<&RoomAliasId> {
1030 self.alias.as_deref()
1031 }
1032
1033 fn room_id(&self) -> &RoomId {
1034 self.room().room_id()
1035 }
1036
1037 fn has_tag(&self, tag: TagName) -> bool {
1038 if let Some(tags) = &self.room_info.deref().1 {
1039 tags.contains_key(&tag)
1040 } else {
1041 false
1042 }
1043 }
1044
1045 fn recent_ts(&self) -> Option<&MessageTimeStamp> {
1046 self.unread.latest()
1047 }
1048
1049 fn is_unread(&self) -> bool {
1050 self.unread.is_unread()
1051 }
1052
1053 fn is_invite(&self) -> bool {
1054 self.room().state() == MatrixRoomState::Invited
1055 }
1056}
1057 890
1058impl Display for GenericChatItem { 891 /// Don't show a tag
1059 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 892 Unspecified,
1060 write!(f, "{}", self.name)
1061 }
1062} 893}
1063 894
1064impl ListItem<IambInfo> for GenericChatItem { 895impl RoomType {
1065 fn show( 896 fn text(self) -> Option<&'static str> {
1066 &self, 897 match self {
1067 selected: bool, 898 RoomType::DM => Some("DM"),
1068 _: &ViewportContext<ListCursor>, 899 RoomType::Room => Some("Room"),
1069 _: &mut ProgramStore, 900 RoomType::Space => Some("Space"),
1070 ) -> Text<'_> { 901 RoomType::Unspecified => None,
1071 let style = selected_style(selected);
1072 let (name, mut labels) = name_and_labels(&self.name, &self.unread, self.room(), style);
1073 let mut spans = vec![name];
1074
1075 labels.push(if self.is_dm {
1076 vec![Span::styled("DM", style)]
1077 } else {
1078 vec![Span::styled("Room", style)]
1079 });
1080
1081 if let Some(tags) = &self.tags() {
1082 labels.extend(tags.keys().map(|t| tag_to_span(t, style)));
1083 } 902 }
1084
1085 append_tags(labels, &mut spans, style);
1086 Text::from(Line::from(spans))
1087 }
1088
1089 fn get_word(&self) -> Option<String> {
1090 self.room_id().to_string().into()
1091 } 903 }
1092} 904}
1093 905
1094impl Promptable<ProgramContext, ProgramStore, IambInfo> for GenericChatItem { 906#[derive(Debug, Clone)]
1095 fn prompt( 907pub struct GenericRoomItem {
1096 &mut self, 908 room_id: OwnedRoomId,
1097 act: &PromptAction,
1098 ctx: &ProgramContext,
1099 _: &mut ProgramStore,
1100 ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> {
1101 room_prompt(self.room_id(), act, ctx)
1102 }
1103}
1104
1105#[derive(Clone)]
1106pub struct RoomItem {
1107 room_info: MatrixRoomInfo,
1108 name: String, 909 name: String,
1109 alias: Option<OwnedRoomAliasId>, 910 alias: Option<OwnedRoomAliasId>,
911 tags: Option<Tags>,
912 membership: MatrixRoomState,
1110 unread: UnreadInfo, 913 unread: UnreadInfo,
914
915 room_type: RoomType,
1111} 916}
1112 917
1113impl RoomItem { 918impl GenericRoomItem {
1114 fn new(room_info: MatrixRoomInfo, store: &mut ProgramStore) -> Self { 919 pub fn new_unspecified(
1115 let room = &room_info.deref().0; 920 room: &MatrixRoom,
1116 let room_id = room.room_id(); 921 rooms: &mut CompletionMap<OwnedRoomId, RoomInfo>,
922 names: &mut CompletionMap<OwnedRoomAliasId, OwnedRoomId>,
923 ) -> Self {
924 let room_id = room.room_id().to_owned();
1117 925
1118 let info = store.application.rooms.get_or_default(room_id.to_owned()); 926 let info = rooms.get_or_default(room_id.to_owned());
1119 let name = info.name.clone().unwrap_or_default(); 927 let name = info.name.clone().unwrap_or_default();
1120 let alias = room.canonical_alias(); 928 let alias = room.canonical_alias();
1121 let unread = info.unreads(room); 929 let unread = info.unreads(room);
1122 info.tags.clone_from(&room_info.deref().1); 930 let tags = info.tags.clone();
1123 931
1124 if let Some(alias) = &alias { 932 if let Some(alias) = &alias {
1125 store.application.names.insert(alias.to_owned(), room_id.to_owned()); 933 names.insert(alias.to_owned(), room_id.to_owned());
1126 } 934 }
1127 935
1128 RoomItem { room_info, name, alias, unread } 936 Self {
937 name,
938 room_id,
939 alias,
940 tags,
941 unread,
942 membership: room.state(),
943 room_type: RoomType::Unspecified,
944 }
1129 } 945 }
1130 946
1131 #[inline] 947 pub fn new(
1132 fn room(&self) -> &MatrixRoom { 948 room: &MatrixRoom,
1133 &self.room_info.deref().0 949 rooms: &mut CompletionMap<OwnedRoomId, RoomInfo>,
1134 } 950 names: &mut CompletionMap<OwnedRoomAliasId, OwnedRoomId>,
951 ) -> Self {
952 let room_type = if room.is_space() {
953 RoomType::Space
954 } else if room.is_dm() {
955 RoomType::DM
956 } else {
957 RoomType::Room
958 };
1135 959
1136 #[inline] 960 assign!(Self::new_unspecified(room, rooms, names), { room_type })
1137 fn tags(&self) -> &Option<Tags> {
1138 &self.room_info.deref().1
1139 } 961 }
1140} 962}
1141 963
1142impl RoomLikeItem for RoomItem { 964impl RoomLikeItem for GenericRoomItem {
1143 fn name(&self) -> &str {
1144 self.name.as_str()
1145 }
1146
1147 fn alias(&self) -> Option<&RoomAliasId> {
1148 self.alias.as_deref()
1149 }
1150
1151 fn room_id(&self) -> &RoomId { 965 fn room_id(&self) -> &RoomId {
1152 self.room().room_id() 966 &self.room_id
1153 } 967 }
1154 968
1155 fn has_tag(&self, tag: TagName) -> bool { 969 fn has_tag(&self, tag: TagName) -> bool {
1156 if let Some(tags) = &self.room_info.deref().1 { 970 self.tags.as_ref().is_some_and(|tags| tags.contains_key(&tag))
1157 tags.contains_key(&tag)
1158 } else {
1159 false
1160 }
1161 }
1162
1163 fn recent_ts(&self) -> Option<&MessageTimeStamp> {
1164 self.unread.latest()
1165 } 971 }
1166 972
1167 fn is_unread(&self) -> bool { 973 fn is_unread(&self) -> bool {
974 // XXX: check space children for space
1168 self.unread.is_unread() 975 self.unread.is_unread()
1169 } 976 }
1170 977
1171 fn is_invite(&self) -> bool { 978 fn recent_ts(&self) -> Option<&MessageTimeStamp> {
1172 self.room().state() == MatrixRoomState::Invited 979 // XXX: check space children for space
1173 } 980 self.unread.latest()
1174}
1175
1176impl Display for RoomItem {
1177 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1178 write!(f, "{}", self.name)
1179 }
1180}
1181
1182impl ListItem<IambInfo> for RoomItem {
1183 fn show(
1184 &self,
1185 selected: bool,
1186 _: &ViewportContext<ListCursor>,
1187 _: &mut ProgramStore,
1188 ) -> Text<'_> {
1189 let style = selected_style(selected);
1190 let (name, mut labels) = name_and_labels(&self.name, &self.unread, self.room(), style);
1191 let mut spans = vec![name];
1192
1193 if let Some(tags) = &self.tags() {
1194 labels.extend(tags.keys().map(|t| tag_to_span(t, style)));
1195 }
1196
1197 append_tags(labels, &mut spans, style);
1198
1199 Text::from(Line::from(spans))
1200 }
1201
1202 fn get_word(&self) -> Option<String> {
1203 self.room_id().to_string().into()
1204 }
1205}
1206
1207impl Promptable<ProgramContext, ProgramStore, IambInfo> for RoomItem {
1208 fn prompt(
1209 &mut self,
1210 act: &PromptAction,
1211 ctx: &ProgramContext,
1212 _: &mut ProgramStore,
1213 ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> {
1214 room_prompt(self.room_id(), act, ctx)
1215 }
1216}
1217
1218#[derive(Clone)]
1219pub struct DirectItem {
1220 room_info: MatrixRoomInfo,
1221 name: String,
1222 alias: Option<OwnedRoomAliasId>,
1223 unread: UnreadInfo,
1224}
1225
1226impl DirectItem {
1227 fn new(room_info: MatrixRoomInfo, store: &mut ProgramStore) -> Self {
1228 let room = &room_info.deref().0;
1229 let room_id = room_info.0.room_id().to_owned();
1230 let alias = room_info.0.canonical_alias();
1231
1232 let info = store.application.rooms.get_or_default(room_id);
1233 let name = info.name.clone().unwrap_or_default();
1234 let unread = info.unreads(room);
1235 info.tags.clone_from(&room_info.deref().1);
1236
1237 DirectItem { room_info, name, alias, unread }
1238 }
1239
1240 #[inline]
1241 fn room(&self) -> &MatrixRoom {
1242 &self.room_info.deref().0
1243 }
1244
1245 #[inline]
1246 fn tags(&self) -> &Option<Tags> {
1247 &self.room_info.deref().1
1248 }
1249}
1250
1251impl RoomLikeItem for DirectItem {
1252 fn name(&self) -> &str {
1253 self.name.as_str()
1254 } 981 }
1255 982
1256 fn alias(&self) -> Option<&RoomAliasId> { 983 fn alias(&self) -> Option<&RoomAliasId> {
1257 self.alias.as_deref() 984 self.alias.as_deref()
1258 } 985 }
1259 986
1260 fn has_tag(&self, tag: TagName) -> bool { 987 fn name(&self) -> &str {
1261 if let Some(tags) = &self.room_info.deref().1 { 988 &self.name
1262 tags.contains_key(&tag)
1263 } else {
1264 false
1265 }
1266 }
1267
1268 fn room_id(&self) -> &RoomId {
1269 self.room().room_id()
1270 }
1271
1272 fn recent_ts(&self) -> Option<&MessageTimeStamp> {
1273 self.unread.latest()
1274 } 989 }
1275 990
1276 fn is_unread(&self) -> bool { 991 fn is_invite(&self) -> bool {
1277 self.unread.is_unread() 992 self.membership == MatrixRoomState::Invited
1278 } 993 }
1279 994
1280 fn is_invite(&self) -> bool { 995 fn has_mention(&self) -> bool {
1281 self.room().state() == MatrixRoomState::Invited 996 // XXX: check space children for space
997 self.unread.has_mention()
1282 } 998 }
1283} 999}
1284 1000
1285impl Display for DirectItem { 1001impl Display for GenericRoomItem {
1286 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 1002 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1287 write!(f, ":verify request {}", self.name) 1003 write!(f, "{}", self.name)
1288 } 1004 }
1289} 1005}
1290 1006
1291impl ListItem<IambInfo> for DirectItem { 1007impl ListItem<IambInfo> for GenericRoomItem {
1292 fn show( 1008 fn show(
1293 &self, 1009 &self,
1294 selected: bool, 1010 selected: bool,
@@ -1296,121 +1012,23 @@ impl ListItem<IambInfo> for DirectItem {
1296 _: &mut ProgramStore, 1012 _: &mut ProgramStore,
1297 ) -> Text<'_> { 1013 ) -> Text<'_> {
1298 let style = selected_style(selected); 1014 let style = selected_style(selected);
1299 let (name, mut labels) = name_and_labels(&self.name, &self.unread, self.room(), style); 1015 let (name, mut labels) = name_and_labels(&self.name, &self.unread, self.membership, style);
1300 let mut spans = vec![name]; 1016 let mut spans = vec![name];
1301 1017
1302 if let Some(tags) = &self.tags() { 1018 if let Some(label) = self.room_type.text() {
1019 labels.push(vec![Span::styled(label, style)]);
1020 }
1021
1022 if let Some(tags) = &self.tags {
1303 labels.extend(tags.keys().map(|t| tag_to_span(t, style))); 1023 labels.extend(tags.keys().map(|t| tag_to_span(t, style)));
1304 } 1024 }
1305 1025
1306 append_tags(labels, &mut spans, style); 1026 append_tags(labels, &mut spans, style);
1307
1308 Text::from(Line::from(spans)) 1027 Text::from(Line::from(spans))
1309 } 1028 }
1310
1311 fn get_word(&self) -> Option<String> {
1312 self.room_id().to_string().into()
1313 }
1314}
1315
1316impl Promptable<ProgramContext, ProgramStore, IambInfo> for DirectItem {
1317 fn prompt(
1318 &mut self,
1319 act: &PromptAction,
1320 ctx: &ProgramContext,
1321 _: &mut ProgramStore,
1322 ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> {
1323 room_prompt(self.room_id(), act, ctx)
1324 }
1325}
1326
1327#[derive(Clone)]
1328pub struct SpaceItem {
1329 room_info: MatrixRoomInfo,
1330 name: String,
1331 alias: Option<OwnedRoomAliasId>,
1332}
1333
1334impl SpaceItem {
1335 fn new(room_info: MatrixRoomInfo, store: &mut ProgramStore) -> Self {
1336 let room_id = room_info.0.room_id();
1337 let name = store
1338 .application
1339 .get_room_info(room_id.to_owned())
1340 .name
1341 .clone()
1342 .unwrap_or_default();
1343 let alias = room_info.0.canonical_alias();
1344
1345 if let Some(alias) = &alias {
1346 store.application.names.insert(alias.to_owned(), room_id.to_owned());
1347 }
1348
1349 SpaceItem { room_info, name, alias }
1350 }
1351
1352 #[inline]
1353 fn room(&self) -> &MatrixRoom {
1354 &self.room_info.deref().0
1355 }
1356}
1357
1358impl RoomLikeItem for SpaceItem {
1359 fn name(&self) -> &str {
1360 self.name.as_str()
1361 }
1362
1363 fn room_id(&self) -> &RoomId {
1364 self.room().room_id()
1365 }
1366
1367 fn alias(&self) -> Option<&RoomAliasId> {
1368 self.alias.as_deref()
1369 }
1370
1371 fn has_tag(&self, _: TagName) -> bool {
1372 // I think that spaces can technically have tags, but afaik no client
1373 // exposes them, so we'll just always return false here for now.
1374 false
1375 }
1376
1377 fn recent_ts(&self) -> Option<&MessageTimeStamp> {
1378 // XXX: this needs to determine the room with most recent message and return its timestamp.
1379 None
1380 }
1381
1382 fn is_unread(&self) -> bool {
1383 // XXX: this needs to check whether the space contains rooms with unread messages
1384 false
1385 }
1386
1387 fn is_invite(&self) -> bool {
1388 self.room().state() == MatrixRoomState::Invited
1389 }
1390} 1029}
1391 1030
1392impl Display for SpaceItem { 1031impl Promptable<ProgramContext, ProgramStore, IambInfo> for GenericRoomItem {
1393 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1394 write!(f, "{}", self.name)
1395 }
1396}
1397
1398impl ListItem<IambInfo> for SpaceItem {
1399 fn show(
1400 &self,
1401 selected: bool,
1402 _: &ViewportContext<ListCursor>,
1403 _: &mut ProgramStore,
1404 ) -> Text<'_> {
1405 selected_text(self.name.as_str(), selected)
1406 }
1407
1408 fn get_word(&self) -> Option<String> {
1409 self.room_id().to_string().into()
1410 }
1411}
1412
1413impl Promptable<ProgramContext, ProgramStore, IambInfo> for SpaceItem {
1414 fn prompt( 1032 fn prompt(
1415 &mut self, 1033 &mut self,
1416 act: &PromptAction, 1034 act: &PromptAction,
@@ -1609,6 +1227,10 @@ mod tests {
1609 fn is_invite(&self) -> bool { 1227 fn is_invite(&self) -> bool {
1610 self.invite 1228 self.invite
1611 } 1229 }
1230
1231 fn has_mention(&self) -> bool {
1232 false
1233 }
1612 } 1234 }
1613 1235
1614 #[test] 1236 #[test]
src/windows/room/space.rs +10 −10
@@ -6,7 +6,7 @@ use matrix_sdk::ruma::events::space::child::SpaceChildEventContent;
6use modalkit_ratatui::list::{List, ListState}; 6use modalkit_ratatui::list::{List, ListState};
7 7
8use crate::prelude::*; 8use crate::prelude::*;
9use crate::windows::{RoomItem, RoomLikeItem, room_fields_cmp}; 9use crate::windows::{GenericRoomItem, RoomLikeItem, room_fields_cmp};
10 10
11const SPACE_HIERARCHY_DEBOUNCE: Duration = Duration::from_secs(5); 11const SPACE_HIERARCHY_DEBOUNCE: Duration = Duration::from_secs(5);
12 12
@@ -14,7 +14,7 @@ const SPACE_HIERARCHY_DEBOUNCE: Duration = Duration::from_secs(5);
14pub struct SpaceState { 14pub struct SpaceState {
15 room_id: OwnedRoomId, 15 room_id: OwnedRoomId,
16 room: MatrixRoom, 16 room: MatrixRoom,
17 list: ListState<RoomItem, IambInfo>, 17 list: ListState<GenericRoomItem, IambInfo>,
18 last_fetch: Option<Instant>, 18 last_fetch: Option<Instant>,
19} 19}
20 20
@@ -155,7 +155,7 @@ impl TerminalCursor for SpaceState {
155} 155}
156 156
157impl Deref for SpaceState { 157impl Deref for SpaceState {
158 type Target = ListState<RoomItem, IambInfo>; 158 type Target = ListState<GenericRoomItem, IambInfo>;
159 159
160 fn deref(&self) -> &Self::Target { 160 fn deref(&self) -> &Self::Target {
161 &self.list 161 &self.list
@@ -189,7 +189,9 @@ impl StatefulWidget for Space<'_> {
189 type State = SpaceState; 189 type State = SpaceState;
190 190
191 fn render(self, area: Rect, buffer: &mut Buffer, state: &mut Self::State) { 191 fn render(self, area: Rect, buffer: &mut Buffer, state: &mut Self::State) {
192 state.set_ignorecase(self.store.application.settings.tunables.ignorecase); 192 let ChatStore { rooms, names, worker, settings, collator, .. } =
193 &mut self.store.application;
194 state.set_ignorecase(settings.tunables.ignorecase);
193 195
194 let mut empty_message = None; 196 let mut empty_message = None;
195 let need_fetch = match state.last_fetch { 197 let need_fetch = match state.last_fetch {
@@ -198,26 +200,24 @@ impl StatefulWidget for Space<'_> {
198 }; 200 };
199 201
200 if need_fetch { 202 if need_fetch {
201 let res = self.store.application.worker.space_members(state.room_id.clone()); 203 let res = worker.space_members(state.room_id.clone());
202 204
203 match res { 205 match res {
204 Ok(members) => { 206 Ok(members) => {
205 let mut items = members 207 let mut items = members
206 .into_iter() 208 .into_iter()
207 .filter_map(|id| { 209 .filter_map(|id| {
208 let (room, _, tags) = 210 let (room, _, tags) = worker.get_room(id.clone()).ok()?;
209 self.store.application.worker.get_room(id.clone()).ok()?;
210 let room_info = std::sync::Arc::new((room, tags)); 211 let room_info = std::sync::Arc::new((room, tags));
211 212
212 if id != state.room_id { 213 if id != state.room_id {
213 Some(RoomItem::new(room_info, self.store)) 214 Some(GenericRoomItem::new(&room_info.0, rooms, names))
214 } else { 215 } else {
215 None 216 None
216 } 217 }
217 }) 218 })
218 .collect::<Vec<_>>(); 219 .collect::<Vec<_>>();
219 let fields = &self.store.application.settings.tunables.sort.rooms; 220 let fields = &settings.tunables.sort.rooms;
220 let collator = &mut self.store.application.collator;
221 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); 221 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator));
222 222
223 state.list.set(items); 223 state.list.set(items);
src/worker.rs +9 −9
@@ -397,7 +397,7 @@ async fn load_older_forever(client: &Client, store: &AsyncProgramStore) {
397} 397}
398 398
399async fn refresh_rooms(client: &Client, store: &AsyncProgramStore, first_sync: bool) { 399async fn refresh_rooms(client: &Client, store: &AsyncProgramStore, first_sync: bool) {
400 let mut names = vec![]; 400 let mut names_and_tags = vec![];
401 401
402 let mut spaces = vec![]; 402 let mut spaces = vec![];
403 let mut rooms = vec![]; 403 let mut rooms = vec![];
@@ -422,14 +422,14 @@ async fn refresh_rooms(client: &Client, store: &AsyncProgramStore, first_sync: b
422 let name = display.to_string(); 422 let name = display.to_string();
423 let tags = room.tags().await.unwrap_or_default(); 423 let tags = room.tags().await.unwrap_or_default();
424 424
425 names.push((room.room_id().to_owned(), name)); 425 names_and_tags.push((room.room_id().to_owned(), name, tags));
426 426
427 if room.is_direct().await.unwrap_or_default() { 427 if room.is_direct().await.unwrap_or_default() {
428 dms.push(Arc::new((room, tags))); 428 dms.push(room);
429 } else if room.is_space() { 429 } else if room.is_space() {
430 spaces.push(Arc::new((room, tags))); 430 spaces.push(room);
431 } else { 431 } else {
432 rooms.push(Arc::new((room, tags))); 432 rooms.push(room);
433 } 433 }
434 } 434 }
435 435
@@ -438,8 +438,8 @@ async fn refresh_rooms(client: &Client, store: &AsyncProgramStore, first_sync: b
438 locked.application.sync_info.rooms = rooms; 438 locked.application.sync_info.rooms = rooms;
439 locked.application.sync_info.dms = dms; 439 locked.application.sync_info.dms = dms;
440 440
441 for (room_id, name) in names { 441 for (room_id, name, tags) in names_and_tags {
442 locked.application.set_room_name(&room_id, &name); 442 locked.application.set_room_info(room_id, name, tags);
443 } 443 }
444} 444}
445 445
@@ -657,12 +657,12 @@ pub async fn do_first_sync(client: &Client, store: &AsyncProgramStore) -> Result
657 let ChatStore { sync_info, need_load, .. } = &mut locked.application; 657 let ChatStore { sync_info, need_load, .. } = &mut locked.application;
658 658
659 for room in sync_info.rooms.iter() { 659 for room in sync_info.rooms.iter() {
660 let room_id = room.as_ref().0.room_id().to_owned(); 660 let room_id = room.room_id().to_owned();
661 need_load.need_messages(room_id); 661 need_load.need_messages(room_id);
662 } 662 }
663 663
664 for room in sync_info.dms.iter() { 664 for room in sync_info.dms.iter() {
665 let room_id = room.as_ref().0.room_id().to_owned(); 665 let room_id = room.room_id().to_owned();
666 need_load.need_messages(room_id); 666 need_load.need_messages(room_id);
667 } 667 }
668 668