| @@ -12,8 +12,9 @@ use std::fmt::{self}; |
| 12 | 12 | |
| 13 | 13 | use feruca::Collator; |
| 14 | 14 | use matrix_sdk::room::RoomMember; |
| 15 | | use matrix_sdk::ruma::RoomAliasId; |
| 16 | 15 | use matrix_sdk::ruma::events::room::member::MembershipState; |
| 16 | use matrix_sdk::ruma::{RoomAliasId, assign}; |
| 17 | use modalkit::editing::completion::CompletionMap; |
| 17 | 18 | use modalkit_ratatui::Window; |
| 18 | 19 | use modalkit_ratatui::list::{List, ListCursor, ListItem, ListState}; |
| 19 | 20 | |
| @@ -27,8 +28,6 @@ pub mod room; |
| 27 | 28 | pub mod verify; |
| 28 | 29 | pub mod welcome; |
| 29 | 30 | |
| 30 | | type MatrixRoomInfo = Arc<(MatrixRoom, Option<Tags>)>; |
| 31 | | |
| 32 | 31 | const MEMBER_FETCH_DEBOUNCE: Duration = Duration::from_secs(5); |
| 33 | 32 | |
| 34 | 33 | #[inline] |
| @@ -55,20 +54,10 @@ pub fn selected_style(selected: bool) -> Style { |
| 55 | 54 | } |
| 56 | 55 | } |
| 57 | 56 | |
| 58 | | #[inline] |
| 59 | | fn selected_span(s: &str, selected: bool) -> Span<'_> { |
| 60 | | Span::styled(s, selected_style(selected)) |
| 61 | | } |
| 62 | | |
| 63 | | #[inline] |
| 64 | | fn selected_text(s: &str, selected: bool) -> Text<'_> { |
| 65 | | Text::from(selected_span(s, selected)) |
| 66 | | } |
| 67 | | |
| 68 | 57 | fn name_and_labels<'a>( |
| 69 | 58 | name: &'a str, |
| 70 | 59 | unread: &UnreadInfo, |
| 71 | | room: &MatrixRoom, |
| 60 | room_membership: MatrixRoomState, |
| 72 | 61 | style: Style, |
| 73 | 62 | ) -> (Span<'a>, Vec<Vec<Span<'static>>>) { |
| 74 | 63 | // TODO: use different colors for "mention", "notification", "muted room" |
| @@ -82,7 +71,7 @@ fn name_and_labels<'a>( |
| 82 | 71 | |
| 83 | 72 | let mut labels = vec![]; |
| 84 | 73 | |
| 85 | | match room.state() { |
| 74 | match room_membership { |
| 86 | 75 | MatrixRoomState::Joined => {}, |
| 87 | 76 | MatrixRoomState::Left => labels.push(vec![Span::styled("Left", style)]), |
| 88 | 77 | MatrixRoomState::Banned => labels.push(vec![Span::styled("Banned", style)]), |
| @@ -263,6 +252,7 @@ trait RoomLikeItem { |
| 263 | 252 | fn alias(&self) -> Option<&RoomAliasId>; |
| 264 | 253 | fn name(&self) -> &str; |
| 265 | 254 | fn is_invite(&self) -> bool; |
| 255 | fn has_mention(&self) -> bool; |
| 266 | 256 | } |
| 267 | 257 | |
| 268 | 258 | #[inline] |
| @@ -313,17 +303,17 @@ macro_rules! delegate { |
| 313 | 303 | } |
| 314 | 304 | |
| 315 | 305 | pub enum IambWindow { |
| 316 | | DirectList(DirectListState), |
| 306 | DirectList(RoomListState), |
| 317 | 307 | MemberList(MemberListState, OwnedRoomId, Option<Instant>), |
| 318 | 308 | Room(RoomState), |
| 319 | 309 | VerifyList(VerifyListState), |
| 320 | 310 | RoomList(RoomListState), |
| 321 | | SpaceList(SpaceListState), |
| 311 | SpaceList(RoomListState), |
| 322 | 312 | Welcome(WelcomeState), |
| 323 | | ChatList(ChatListState), |
| 324 | | UnreadList(UnreadListState), |
| 325 | | MentionsList(MentionsListState), |
| 326 | | InvitesList(InvitesListState), |
| 313 | ChatList(RoomListState), |
| 314 | UnreadList(RoomListState), |
| 315 | MentionsList(RoomListState), |
| 316 | InvitesList(RoomListState), |
| 327 | 317 | } |
| 328 | 318 | |
| 329 | 319 | impl IambWindow { |
| @@ -402,22 +392,10 @@ impl IambWindow { |
| 402 | 392 | } |
| 403 | 393 | } |
| 404 | 394 | |
| 405 | | pub type DirectListState = ListState<DirectItem, IambInfo>; |
| 406 | 395 | pub type MemberListState = ListState<MemberItem, IambInfo>; |
| 407 | | pub type RoomListState = ListState<RoomItem, IambInfo>; |
| 408 | | pub type ChatListState = ListState<GenericChatItem, IambInfo>; |
| 409 | | pub type UnreadListState = ListState<GenericChatItem, IambInfo>; |
| 410 | | pub type MentionsListState = ListState<GenericChatItem, IambInfo>; |
| 411 | | pub type InvitesListState = ListState<GenericChatItem, IambInfo>; |
| 412 | | pub type SpaceListState = ListState<SpaceItem, IambInfo>; |
| 396 | pub type RoomListState = ListState<GenericRoomItem, IambInfo>; |
| 413 | 397 | pub type VerifyListState = ListState<VerifyItem, IambInfo>; |
| 414 | 398 | |
| 415 | | impl From<ChatListState> for IambWindow { |
| 416 | | fn from(list: ChatListState) -> Self { |
| 417 | | IambWindow::ChatList(list) |
| 418 | | } |
| 419 | | } |
| 420 | | |
| 421 | 399 | impl From<RoomState> for IambWindow { |
| 422 | 400 | fn from(room: RoomState) -> Self { |
| 423 | 401 | IambWindow::Room(room) |
| @@ -430,24 +408,6 @@ impl From<VerifyListState> for IambWindow { |
| 430 | 408 | } |
| 431 | 409 | } |
| 432 | 410 | |
| 433 | | impl From<DirectListState> for IambWindow { |
| 434 | | fn from(list: DirectListState) -> Self { |
| 435 | | IambWindow::DirectList(list) |
| 436 | | } |
| 437 | | } |
| 438 | | |
| 439 | | impl From<RoomListState> for IambWindow { |
| 440 | | fn from(list: RoomListState) -> Self { |
| 441 | | IambWindow::RoomList(list) |
| 442 | | } |
| 443 | | } |
| 444 | | |
| 445 | | impl From<SpaceListState> for IambWindow { |
| 446 | | fn from(list: SpaceListState) -> Self { |
| 447 | | IambWindow::SpaceList(list) |
| 448 | | } |
| 449 | | } |
| 450 | | |
| 451 | 411 | impl From<WelcomeState> for IambWindow { |
| 452 | 412 | fn from(win: WelcomeState) -> Self { |
| 453 | 413 | IambWindow::Welcome(win) |
| @@ -511,23 +471,30 @@ impl TerminalCursor for IambWindow { |
| 511 | 471 | |
| 512 | 472 | impl WindowOps<IambInfo> for IambWindow { |
| 513 | 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 | 485 | match self { |
| 515 | 486 | IambWindow::Room(state) => state.draw(area, buf, focused, store), |
| 516 | 487 | IambWindow::DirectList(state) => { |
| 517 | | let mut items = store |
| 518 | | .application |
| 519 | | .sync_info |
| 488 | let mut items = sync_info |
| 520 | 489 | .dms |
| 521 | | .clone() |
| 522 | | .into_iter() |
| 523 | | .map(|room_info| DirectItem::new(room_info, store)) |
| 490 | .iter() |
| 491 | .map(|room| GenericRoomItem::new_unspecified(room, rooms, names)) |
| 524 | 492 | .collect::<Vec<_>>(); |
| 525 | | let fields = &store.application.settings.tunables.sort.dms; |
| 526 | | let collator = &mut store.application.collator; |
| 493 | let fields = &settings.tunables.sort.dms; |
| 527 | 494 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| 528 | 495 | |
| 529 | 496 | state.set(items); |
| 530 | | state.set_ignorecase(store.application.settings.tunables.ignorecase); |
| 497 | state.set_ignorecase(settings.tunables.ignorecase); |
| 531 | 498 | |
| 532 | 499 | List::new(store) |
| 533 | 500 | .empty_message("No direct messages yet!") |
| @@ -541,18 +508,18 @@ impl WindowOps<IambInfo> for IambWindow { |
| 541 | 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 | 512 | let mut items = mems |
| 546 | 513 | .into_iter() |
| 547 | 514 | .map(|m| MemberItem::new(m, room_id.clone())) |
| 548 | 515 | .collect::<Vec<_>>(); |
| 549 | | let fields = &store.application.settings.tunables.sort.members; |
| 516 | let fields = &settings.tunables.sort.members; |
| 550 | 517 | items.sort_by(|a, b| user_fields_cmp(a, b, fields)); |
| 551 | 518 | state.set(items); |
| 552 | 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 | 524 | List::new(store) |
| 558 | 525 | .empty_message("No users here yet!") |
| @@ -561,20 +528,16 @@ impl WindowOps<IambInfo> for IambWindow { |
| 561 | 528 | .render(area, buf, state); |
| 562 | 529 | }, |
| 563 | 530 | IambWindow::RoomList(state) => { |
| 564 | | let mut items = store |
| 565 | | .application |
| 566 | | .sync_info |
| 531 | let mut items = sync_info |
| 567 | 532 | .rooms |
| 568 | | .clone() |
| 569 | | .into_iter() |
| 570 | | .map(|room_info| RoomItem::new(room_info, store)) |
| 533 | .iter() |
| 534 | .map(|room| GenericRoomItem::new_unspecified(room, rooms, names)) |
| 571 | 535 | .collect::<Vec<_>>(); |
| 572 | | let fields = &store.application.settings.tunables.sort.rooms; |
| 573 | | let collator = &mut store.application.collator; |
| 536 | let fields = &settings.tunables.sort.rooms; |
| 574 | 537 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| 575 | 538 | |
| 576 | 539 | state.set(items); |
| 577 | | state.set_ignorecase(store.application.settings.tunables.ignorecase); |
| 540 | state.set_ignorecase(settings.tunables.ignorecase); |
| 578 | 541 | |
| 579 | 542 | List::new(store) |
| 580 | 543 | .empty_message("You haven't joined any rooms yet") |
| @@ -583,31 +546,18 @@ impl WindowOps<IambInfo> for IambWindow { |
| 583 | 546 | .render(area, buf, state); |
| 584 | 547 | }, |
| 585 | 548 | IambWindow::ChatList(state) => { |
| 586 | | let mut items = store |
| 587 | | .application |
| 588 | | .sync_info |
| 549 | let mut items = sync_info |
| 589 | 550 | .rooms |
| 590 | | .clone() |
| 591 | | .into_iter() |
| 592 | | .map(|room_info| GenericChatItem::new(room_info, store, false)) |
| 551 | .iter() |
| 552 | .chain(sync_info.dms.iter()) |
| 553 | .map(|room| GenericRoomItem::new(room, rooms, names)) |
| 593 | 554 | .collect::<Vec<_>>(); |
| 594 | 555 | |
| 595 | | let dms = store |
| 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; |
| 556 | let fields = &settings.tunables.sort.chats; |
| 607 | 557 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| 608 | 558 | |
| 609 | 559 | state.set(items); |
| 610 | | state.set_ignorecase(store.application.settings.tunables.ignorecase); |
| 560 | state.set_ignorecase(settings.tunables.ignorecase); |
| 611 | 561 | |
| 612 | 562 | List::new(store) |
| 613 | 563 | .empty_message("You do not have rooms or dms yet") |
| @@ -616,33 +566,19 @@ impl WindowOps<IambInfo> for IambWindow { |
| 616 | 566 | .render(area, buf, state); |
| 617 | 567 | }, |
| 618 | 568 | IambWindow::UnreadList(state) => { |
| 619 | | let mut items = store |
| 620 | | .application |
| 621 | | .sync_info |
| 569 | let mut items = sync_info |
| 622 | 570 | .rooms |
| 623 | | .clone() |
| 624 | | .into_iter() |
| 625 | | .map(|room_info| GenericChatItem::new(room_info, store, false)) |
| 571 | .iter() |
| 572 | .chain(sync_info.dms.iter()) |
| 573 | .map(|room| GenericRoomItem::new(room, rooms, names)) |
| 626 | 574 | .filter(RoomLikeItem::is_unread) |
| 627 | 575 | .collect::<Vec<_>>(); |
| 628 | 576 | |
| 629 | | let dms = store |
| 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; |
| 577 | let fields = &settings.tunables.sort.chats; |
| 642 | 578 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| 643 | 579 | |
| 644 | 580 | state.set(items); |
| 645 | | state.set_ignorecase(store.application.settings.tunables.ignorecase); |
| 581 | state.set_ignorecase(settings.tunables.ignorecase); |
| 646 | 582 | |
| 647 | 583 | List::new(store) |
| 648 | 584 | .empty_message("You do not have any unreads yet") |
| @@ -651,33 +587,19 @@ impl WindowOps<IambInfo> for IambWindow { |
| 651 | 587 | .render(area, buf, state); |
| 652 | 588 | }, |
| 653 | 589 | IambWindow::MentionsList(state) => { |
| 654 | | let mut items = store |
| 655 | | .application |
| 656 | | .sync_info |
| 590 | let mut items = sync_info |
| 657 | 591 | .rooms |
| 658 | | .clone() |
| 659 | | .into_iter() |
| 660 | | .map(|room_info| GenericChatItem::new(room_info, store, false)) |
| 661 | | .filter(GenericChatItem::has_mention) |
| 592 | .iter() |
| 593 | .chain(sync_info.dms.iter()) |
| 594 | .map(|room| GenericRoomItem::new(room, rooms, names)) |
| 595 | .filter(RoomLikeItem::has_mention) |
| 662 | 596 | .collect::<Vec<_>>(); |
| 663 | 597 | |
| 664 | | let dms = store |
| 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; |
| 598 | let fields = &settings.tunables.sort.chats; |
| 677 | 599 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| 678 | 600 | |
| 679 | 601 | state.set(items); |
| 680 | | state.set_ignorecase(store.application.settings.tunables.ignorecase); |
| 602 | state.set_ignorecase(settings.tunables.ignorecase); |
| 681 | 603 | |
| 682 | 604 | List::new(store) |
| 683 | 605 | .empty_message("You do not have any unread mentions yet") |
| @@ -686,33 +608,19 @@ impl WindowOps<IambInfo> for IambWindow { |
| 686 | 608 | .render(area, buf, state); |
| 687 | 609 | }, |
| 688 | 610 | IambWindow::InvitesList(state) => { |
| 689 | | let mut items = store |
| 690 | | .application |
| 691 | | .sync_info |
| 611 | let mut items = sync_info |
| 692 | 612 | .rooms |
| 693 | | .clone() |
| 694 | | .into_iter() |
| 695 | | .map(|room_info| GenericChatItem::new(room_info, store, false)) |
| 696 | | .filter(GenericChatItem::is_invite) |
| 613 | .iter() |
| 614 | .chain(sync_info.dms.iter()) |
| 615 | .map(|room| GenericRoomItem::new(room, rooms, names)) |
| 616 | .filter(RoomLikeItem::is_invite) |
| 697 | 617 | .collect::<Vec<_>>(); |
| 698 | 618 | |
| 699 | | let dms = store |
| 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; |
| 619 | let fields = &settings.tunables.sort.chats; |
| 712 | 620 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| 713 | 621 | |
| 714 | 622 | state.set(items); |
| 715 | | state.set_ignorecase(store.application.settings.tunables.ignorecase); |
| 623 | state.set_ignorecase(settings.tunables.ignorecase); |
| 716 | 624 | |
| 717 | 625 | List::new(store) |
| 718 | 626 | .empty_message("You do not have any open invites") |
| @@ -721,20 +629,17 @@ impl WindowOps<IambInfo> for IambWindow { |
| 721 | 629 | .render(area, buf, state); |
| 722 | 630 | }, |
| 723 | 631 | IambWindow::SpaceList(state) => { |
| 724 | | let mut items = store |
| 725 | | .application |
| 726 | | .sync_info |
| 632 | let mut items = sync_info |
| 727 | 633 | .spaces |
| 728 | | .clone() |
| 729 | | .into_iter() |
| 730 | | .map(|room| SpaceItem::new(room, store)) |
| 634 | .iter() |
| 635 | .map(|room| GenericRoomItem::new_unspecified(room, rooms, names)) |
| 731 | 636 | .collect::<Vec<_>>(); |
| 732 | | let fields = &store.application.settings.tunables.sort.spaces; |
| 733 | | let collator = &mut store.application.collator; |
| 637 | |
| 638 | let fields = &settings.tunables.sort.spaces; |
| 734 | 639 | items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator)); |
| 735 | 640 | |
| 736 | 641 | state.set(items); |
| 737 | | state.set_ignorecase(store.application.settings.tunables.ignorecase); |
| 642 | state.set_ignorecase(settings.tunables.ignorecase); |
| 738 | 643 | |
| 739 | 644 | List::new(store) |
| 740 | 645 | .empty_message("You haven't joined any spaces yet") |
| @@ -743,9 +648,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 743 | 648 | .render(area, buf, state); |
| 744 | 649 | }, |
| 745 | 650 | IambWindow::VerifyList(state) => { |
| 746 | | let mut items = store |
| 747 | | .application |
| 748 | | .verifications |
| 651 | let mut items = verifications |
| 749 | 652 | .iter() |
| 750 | 653 | .map(|(_, req)| VerifyItem::new(req.to_owned())) |
| 751 | 654 | .collect::<Vec<_>>(); |
| @@ -758,7 +661,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 758 | 661 | } |
| 759 | 662 | |
| 760 | 663 | state.set(items); |
| 761 | | state.set_ignorecase(store.application.settings.tunables.ignorecase); |
| 664 | state.set_ignorecase(settings.tunables.ignorecase); |
| 762 | 665 | |
| 763 | 666 | List::new(store) |
| 764 | 667 | .empty_message("No in-progress verifications") |
| @@ -773,18 +676,18 @@ impl WindowOps<IambInfo> for IambWindow { |
| 773 | 676 | fn dup(&self, store: &mut ProgramStore) -> Self { |
| 774 | 677 | match self { |
| 775 | 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 | 680 | IambWindow::MemberList(w, room_id, last_fetch) => { |
| 778 | 681 | IambWindow::MemberList(w.dup(store), room_id.clone(), *last_fetch) |
| 779 | 682 | }, |
| 780 | | IambWindow::RoomList(w) => w.dup(store).into(), |
| 781 | | IambWindow::SpaceList(w) => w.dup(store).into(), |
| 683 | IambWindow::RoomList(w) => Self::RoomList(w.dup(store)), |
| 684 | IambWindow::SpaceList(w) => Self::SpaceList(w.dup(store)), |
| 782 | 685 | IambWindow::VerifyList(w) => w.dup(store).into(), |
| 783 | 686 | IambWindow::Welcome(w) => w.dup(store).into(), |
| 784 | | IambWindow::ChatList(w) => w.dup(store).into(), |
| 785 | | IambWindow::UnreadList(w) => w.dup(store).into(), |
| 786 | | IambWindow::MentionsList(w) => w.dup(store).into(), |
| 787 | | IambWindow::InvitesList(w) => w.dup(store).into(), |
| 687 | IambWindow::ChatList(w) => Self::ChatList(w.dup(store)), |
| 688 | IambWindow::UnreadList(w) => Self::UnreadList(w.dup(store)), |
| 689 | IambWindow::MentionsList(w) => Self::MentionsList(w.dup(store)), |
| 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 | 805 | return Ok(RoomState::not_joined(name).into()); |
| 903 | 806 | }, |
| 904 | 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 | 812 | IambId::MemberList(room_id) => { |
| 910 | 813 | let id = IambBufferId::MemberList(room_id.clone()); |
| 911 | 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 | 817 | return Ok(win); |
| 915 | 818 | }, |
| 916 | 819 | IambId::RoomList => { |
| 917 | 820 | let list = RoomListState::new(IambBufferId::RoomList, vec![]); |
| 918 | 821 | |
| 919 | | return Ok(list.into()); |
| 822 | return Ok(Self::RoomList(list)); |
| 920 | 823 | }, |
| 921 | 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 | 829 | IambId::VerifyList => { |
| 927 | 830 | let list = VerifyListState::new(IambBufferId::VerifyList, vec![]); |
| @@ -934,24 +837,24 @@ impl Window<IambInfo> for IambWindow { |
| 934 | 837 | return Ok(win.into()); |
| 935 | 838 | }, |
| 936 | 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 | 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 | 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 | 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)] |
| 982 | | pub struct GenericChatItem { |
| 983 | | room_info: MatrixRoomInfo, |
| 984 | | name: String, |
| 985 | | alias: Option<OwnedRoomAliasId>, |
| 986 | | unread: UnreadInfo, |
| 987 | | is_dm: bool, |
| 988 | | } |
| 989 | | |
| 990 | | impl 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 | | |
| 1024 | | impl 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 | | } |
| 884 | /// This is used to determine what tag to show on a [`GenericRoomItem`]. |
| 885 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
| 886 | enum RoomType { |
| 887 | DM, |
| 888 | Room, |
| 889 | Space, |
| 1057 | 890 | |
| 1058 | | impl Display for GenericChatItem { |
| 1059 | | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 1060 | | write!(f, "{}", self.name) |
| 1061 | | } |
| 891 | /// Don't show a tag |
| 892 | Unspecified, |
| 1062 | 893 | } |
| 1063 | 894 | |
| 1064 | | impl ListItem<IambInfo> for GenericChatItem { |
| 1065 | | fn show( |
| 1066 | | &self, |
| 1067 | | selected: bool, |
| 1068 | | _: &ViewportContext<ListCursor>, |
| 1069 | | _: &mut ProgramStore, |
| 1070 | | ) -> Text<'_> { |
| 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))); |
| 895 | impl RoomType { |
| 896 | fn text(self) -> Option<&'static str> { |
| 897 | match self { |
| 898 | RoomType::DM => Some("DM"), |
| 899 | RoomType::Room => Some("Room"), |
| 900 | RoomType::Space => Some("Space"), |
| 901 | RoomType::Unspecified => None, |
| 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 | |
| 1094 | | impl Promptable<ProgramContext, ProgramStore, IambInfo> for GenericChatItem { |
| 1095 | | fn prompt( |
| 1096 | | &mut self, |
| 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)] |
| 1106 | | pub struct RoomItem { |
| 1107 | | room_info: MatrixRoomInfo, |
| 906 | #[derive(Debug, Clone)] |
| 907 | pub struct GenericRoomItem { |
| 908 | room_id: OwnedRoomId, |
| 1108 | 909 | name: String, |
| 1109 | 910 | alias: Option<OwnedRoomAliasId>, |
| 911 | tags: Option<Tags>, |
| 912 | membership: MatrixRoomState, |
| 1110 | 913 | unread: UnreadInfo, |
| 914 | |
| 915 | room_type: RoomType, |
| 1111 | 916 | } |
| 1112 | 917 | |
| 1113 | | impl RoomItem { |
| 1114 | | fn new(room_info: MatrixRoomInfo, store: &mut ProgramStore) -> Self { |
| 1115 | | let room = &room_info.deref().0; |
| 1116 | | let room_id = room.room_id(); |
| 918 | impl GenericRoomItem { |
| 919 | pub fn new_unspecified( |
| 920 | room: &MatrixRoom, |
| 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 | 927 | let name = info.name.clone().unwrap_or_default(); |
| 1120 | 928 | let alias = room.canonical_alias(); |
| 1121 | 929 | let unread = info.unreads(room); |
| 1122 | | info.tags.clone_from(&room_info.deref().1); |
| 930 | let tags = info.tags.clone(); |
| 1123 | 931 | |
| 1124 | 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] |
| 1132 | | fn room(&self) -> &MatrixRoom { |
| 1133 | | &self.room_info.deref().0 |
| 1134 | | } |
| 947 | pub fn new( |
| 948 | room: &MatrixRoom, |
| 949 | rooms: &mut CompletionMap<OwnedRoomId, RoomInfo>, |
| 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] |
| 1137 | | fn tags(&self) -> &Option<Tags> { |
| 1138 | | &self.room_info.deref().1 |
| 960 | assign!(Self::new_unspecified(room, rooms, names), { room_type }) |
| 1139 | 961 | } |
| 1140 | 962 | } |
| 1141 | 963 | |
| 1142 | | impl RoomLikeItem for RoomItem { |
| 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 | | |
| 964 | impl RoomLikeItem for GenericRoomItem { |
| 1151 | 965 | fn room_id(&self) -> &RoomId { |
| 1152 | | self.room().room_id() |
| 966 | &self.room_id |
| 1153 | 967 | } |
| 1154 | 968 | |
| 1155 | 969 | fn has_tag(&self, tag: TagName) -> bool { |
| 1156 | | if let Some(tags) = &self.room_info.deref().1 { |
| 1157 | | tags.contains_key(&tag) |
| 1158 | | } else { |
| 1159 | | false |
| 1160 | | } |
| 1161 | | } |
| 1162 | | |
| 1163 | | fn recent_ts(&self) -> Option<&MessageTimeStamp> { |
| 1164 | | self.unread.latest() |
| 970 | self.tags.as_ref().is_some_and(|tags| tags.contains_key(&tag)) |
| 1165 | 971 | } |
| 1166 | 972 | |
| 1167 | 973 | fn is_unread(&self) -> bool { |
| 974 | // XXX: check space children for space |
| 1168 | 975 | self.unread.is_unread() |
| 1169 | 976 | } |
| 1170 | 977 | |
| 1171 | | fn is_invite(&self) -> bool { |
| 1172 | | self.room().state() == MatrixRoomState::Invited |
| 1173 | | } |
| 1174 | | } |
| 1175 | | |
| 1176 | | impl Display for RoomItem { |
| 1177 | | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 1178 | | write!(f, "{}", self.name) |
| 1179 | | } |
| 1180 | | } |
| 1181 | | |
| 1182 | | impl 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 | | |
| 1207 | | impl 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)] |
| 1219 | | pub struct DirectItem { |
| 1220 | | room_info: MatrixRoomInfo, |
| 1221 | | name: String, |
| 1222 | | alias: Option<OwnedRoomAliasId>, |
| 1223 | | unread: UnreadInfo, |
| 1224 | | } |
| 1225 | | |
| 1226 | | impl 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 | | |
| 1251 | | impl RoomLikeItem for DirectItem { |
| 1252 | | fn name(&self) -> &str { |
| 1253 | | self.name.as_str() |
| 978 | fn recent_ts(&self) -> Option<&MessageTimeStamp> { |
| 979 | // XXX: check space children for space |
| 980 | self.unread.latest() |
| 1254 | 981 | } |
| 1255 | 982 | |
| 1256 | 983 | fn alias(&self) -> Option<&RoomAliasId> { |
| 1257 | 984 | self.alias.as_deref() |
| 1258 | 985 | } |
| 1259 | 986 | |
| 1260 | | fn has_tag(&self, tag: TagName) -> bool { |
| 1261 | | if let Some(tags) = &self.room_info.deref().1 { |
| 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() |
| 987 | fn name(&self) -> &str { |
| 988 | &self.name |
| 1274 | 989 | } |
| 1275 | 990 | |
| 1276 | | fn is_unread(&self) -> bool { |
| 1277 | | self.unread.is_unread() |
| 991 | fn is_invite(&self) -> bool { |
| 992 | self.membership == MatrixRoomState::Invited |
| 1278 | 993 | } |
| 1279 | 994 | |
| 1280 | | fn is_invite(&self) -> bool { |
| 1281 | | self.room().state() == MatrixRoomState::Invited |
| 995 | fn has_mention(&self) -> bool { |
| 996 | // XXX: check space children for space |
| 997 | self.unread.has_mention() |
| 1282 | 998 | } |
| 1283 | 999 | } |
| 1284 | 1000 | |
| 1285 | | impl Display for DirectItem { |
| 1001 | impl Display for GenericRoomItem { |
| 1286 | 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 | |
| 1291 | | impl ListItem<IambInfo> for DirectItem { |
| 1007 | impl ListItem<IambInfo> for GenericRoomItem { |
| 1292 | 1008 | fn show( |
| 1293 | 1009 | &self, |
| 1294 | 1010 | selected: bool, |
| @@ -1296,121 +1012,23 @@ impl ListItem<IambInfo> for DirectItem { |
| 1296 | 1012 | _: &mut ProgramStore, |
| 1297 | 1013 | ) -> Text<'_> { |
| 1298 | 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 | 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 | 1023 | labels.extend(tags.keys().map(|t| tag_to_span(t, style))); |
| 1304 | 1024 | } |
| 1305 | 1025 | |
| 1306 | 1026 | append_tags(labels, &mut spans, style); |
| 1307 | | |
| 1308 | 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 | | |
| 1316 | | impl 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)] |
| 1328 | | pub struct SpaceItem { |
| 1329 | | room_info: MatrixRoomInfo, |
| 1330 | | name: String, |
| 1331 | | alias: Option<OwnedRoomAliasId>, |
| 1332 | | } |
| 1333 | | |
| 1334 | | impl 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 | | |
| 1358 | | impl 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 | |
| 1392 | | impl Display for SpaceItem { |
| 1393 | | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 1394 | | write!(f, "{}", self.name) |
| 1395 | | } |
| 1396 | | } |
| 1397 | | |
| 1398 | | impl 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 | | |
| 1413 | | impl Promptable<ProgramContext, ProgramStore, IambInfo> for SpaceItem { |
| 1031 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for GenericRoomItem { |
| 1414 | 1032 | fn prompt( |
| 1415 | 1033 | &mut self, |
| 1416 | 1034 | act: &PromptAction, |
| @@ -1609,6 +1227,10 @@ mod tests { |
| 1609 | 1227 | fn is_invite(&self) -> bool { |
| 1610 | 1228 | self.invite |
| 1611 | 1229 | } |
| 1230 | |
| 1231 | fn has_mention(&self) -> bool { |
| 1232 | false |
| 1233 | } |
| 1612 | 1234 | } |
| 1613 | 1235 | |
| 1614 | 1236 | #[test] |