| @@ -12,8 +12,9 @@ use std::fmt::{self}; |
| 12 | |
12 | |
| 13 | use feruca::Collator; |
13 | use feruca::Collator; |
| 14 | use matrix_sdk::room::RoomMember; |
14 | use matrix_sdk::room::RoomMember; |
| 15 | use matrix_sdk::ruma::RoomAliasId; |
| |
| 16 | use matrix_sdk::ruma::events::room::member::MembershipState; |
15 | use matrix_sdk::ruma::events::room::member::MembershipState; |
| |
16 | use matrix_sdk::ruma::{RoomAliasId, assign}; |
| |
17 | use modalkit::editing::completion::CompletionMap; |
| 17 | use modalkit_ratatui::Window; |
18 | use modalkit_ratatui::Window; |
| 18 | use modalkit_ratatui::list::{List, ListCursor, ListItem, ListState}; |
19 | use modalkit_ratatui::list::{List, ListCursor, ListItem, ListState}; |
| 19 | |
20 | |
| @@ -27,8 +28,6 @@ pub mod room; |
| 27 | pub mod verify; |
28 | pub mod verify; |
| 28 | pub mod welcome; |
29 | pub mod welcome; |
| 29 | |
30 | |
| 30 | type MatrixRoomInfo = Arc<(MatrixRoom, Option<Tags>)>; |
| |
| 31 | |
| |
| 32 | const MEMBER_FETCH_DEBOUNCE: Duration = Duration::from_secs(5); |
31 | const 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] |
| |
| 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 | fn name_and_labels<'a>( |
57 | fn 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 | |
| 315 | pub enum IambWindow { |
305 | pub 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 | |
| 329 | impl IambWindow { |
319 | impl IambWindow { |
| @@ -402,22 +392,10 @@ impl IambWindow { |
| 402 | } |
392 | } |
| 403 | } |
393 | } |
| 404 | |
394 | |
| 405 | pub type DirectListState = ListState<DirectItem, IambInfo>; |
| |
| 406 | pub type MemberListState = ListState<MemberItem, IambInfo>; |
395 | pub type MemberListState = ListState<MemberItem, IambInfo>; |
| 407 | pub type RoomListState = ListState<RoomItem, IambInfo>; |
396 | pub type RoomListState = ListState<GenericRoomItem, 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>; |
| |
| 413 | pub type VerifyListState = ListState<VerifyItem, IambInfo>; |
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 | impl From<RoomState> for IambWindow { |
399 | impl 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 | |
| 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 | impl From<WelcomeState> for IambWindow { |
411 | impl 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 | |
| 512 | impl WindowOps<IambInfo> for IambWindow { |
472 | impl 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`]. |
| 982 | pub struct GenericChatItem { |
885 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
| 983 | room_info: MatrixRoomInfo, |
886 | enum RoomType { |
| 984 | name: String, |
887 | DM, |
| 985 | alias: Option<OwnedRoomAliasId>, |
888 | Room, |
| 986 | unread: UnreadInfo, |
889 | Space, |
| 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 | } |
| |
| 1057 | |
890 | |
| 1058 | impl 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 | |
| 1064 | impl ListItem<IambInfo> for GenericChatItem { |
895 | impl 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 | |
| 1094 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for GenericChatItem { |
906 | #[derive(Debug, Clone)] |
| 1095 | fn prompt( |
907 | pub 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)] |
| |
| 1106 | pub 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 | |
| 1113 | impl RoomItem { |
918 | impl 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 | |
| 1142 | impl RoomLikeItem for RoomItem { |
964 | impl 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 | |
| |
| 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() |
| |
| 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 | |
| 1285 | impl Display for DirectItem { |
1001 | impl 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 | |
| 1291 | impl ListItem<IambInfo> for DirectItem { |
1007 | impl 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 | |
| |
| 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 { |
1031 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for GenericRoomItem { |
| 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 { |
| |
| 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] |