Commit 480888a1fc
Unregistered key
Layout: unified · split
docs/iamb.1 +4
| @@ -61,6 +61,8 @@ Log out of | ||
| 61 | 61 | View a list of joined rooms. |
| 62 | 62 | .It Sy ":spaces" |
| 63 | 63 | View a list of joined spaces. |
| 64 | .It Sy ":unreads" | |
| 65 | View a list of unread rooms. | |
| 64 | 66 | .It Sy ":welcome" |
| 65 | 67 | View the startup Welcome window. |
| 66 | 68 | .El |
| @@ -95,6 +97,8 @@ React to the selected message with an Emoji. | ||
| 95 | 97 | Redact the selected message. |
| 96 | 98 | .It Sy ":reply" |
| 97 | 99 | Reply to the selected message. |
| 100 | .It Sy ":unreads clear" | |
| 101 | Mark all unread rooms as read. | |
| 98 | 102 | .It Sy ":unreact [shortcode]" |
| 99 | 103 | Remove your reaction from the selected message. |
| 100 | 104 | When no arguments are given, remove all of your reactions from the message. |
src/base.rs +45
| @@ -510,6 +510,9 @@ pub enum IambAction { | ||
| 510 | 510 | |
| 511 | 511 | /// Toggle the focus within the focused room. |
| 512 | 512 | ToggleScrollbackFocus, |
| 513 | ||
| 514 | /// Clear all unread messages. | |
| 515 | ClearUnreads, | |
| 513 | 516 | } |
| 514 | 517 | |
| 515 | 518 | impl IambAction { |
| @@ -546,6 +549,7 @@ impl From<SendAction> for IambAction { | ||
| 546 | 549 | impl ApplicationAction for IambAction { |
| 547 | 550 | fn is_edit_sequence(&self, _: &EditContext) -> SequenceStatus { |
| 548 | 551 | match self { |
| 552 | IambAction::ClearUnreads => SequenceStatus::Break, | |
| 549 | 553 | IambAction::Homeserver(..) => SequenceStatus::Break, |
| 550 | 554 | IambAction::Keys(..) => SequenceStatus::Break, |
| 551 | 555 | IambAction::Message(..) => SequenceStatus::Break, |
| @@ -560,6 +564,7 @@ impl ApplicationAction for IambAction { | ||
| 560 | 564 | |
| 561 | 565 | fn is_last_action(&self, _: &EditContext) -> SequenceStatus { |
| 562 | 566 | match self { |
| 567 | IambAction::ClearUnreads => SequenceStatus::Atom, | |
| 563 | 568 | IambAction::Homeserver(..) => SequenceStatus::Atom, |
| 564 | 569 | IambAction::Keys(..) => SequenceStatus::Atom, |
| 565 | 570 | IambAction::Message(..) => SequenceStatus::Atom, |
| @@ -574,6 +579,7 @@ impl ApplicationAction for IambAction { | ||
| 574 | 579 | |
| 575 | 580 | fn is_last_selection(&self, _: &EditContext) -> SequenceStatus { |
| 576 | 581 | match self { |
| 582 | IambAction::ClearUnreads => SequenceStatus::Ignore, | |
| 577 | 583 | IambAction::Homeserver(..) => SequenceStatus::Ignore, |
| 578 | 584 | IambAction::Keys(..) => SequenceStatus::Ignore, |
| 579 | 585 | IambAction::Message(..) => SequenceStatus::Ignore, |
| @@ -588,6 +594,7 @@ impl ApplicationAction for IambAction { | ||
| 588 | 594 | |
| 589 | 595 | fn is_switchable(&self, _: &EditContext) -> bool { |
| 590 | 596 | match self { |
| 597 | IambAction::ClearUnreads => false, | |
| 591 | 598 | IambAction::Homeserver(..) => false, |
| 592 | 599 | IambAction::Message(..) => false, |
| 593 | 600 | IambAction::Room(..) => false, |
| @@ -1148,6 +1155,14 @@ impl RoomInfo { | ||
| 1148 | 1155 | self.user_receipts.insert(user_id, event_id); |
| 1149 | 1156 | } |
| 1150 | 1157 | |
| 1158 | pub fn fully_read(&mut self, user_id: OwnedUserId) { | |
| 1159 | let Some(((_, event_id), _)) = self.messages.last_key_value() else { | |
| 1160 | return; | |
| 1161 | }; | |
| 1162 | ||
| 1163 | self.set_receipt(user_id, event_id.clone()); | |
| 1164 | } | |
| 1165 | ||
| 1151 | 1166 | pub fn get_receipt(&self, user_id: &UserId) -> Option<&OwnedEventId> { |
| 1152 | 1167 | self.user_receipts.get(user_id) |
| 1153 | 1168 | } |
| @@ -1309,6 +1324,20 @@ pub struct SyncInfo { | ||
| 1309 | 1324 | pub dms: Vec<Arc<(MatrixRoom, Option<Tags>)>>, |
| 1310 | 1325 | } |
| 1311 | 1326 | |
| 1327 | impl SyncInfo { | |
| 1328 | pub fn rooms(&self) -> impl Iterator<Item = &RoomId> { | |
| 1329 | self.rooms.iter().map(|r| r.0.room_id()) | |
| 1330 | } | |
| 1331 | ||
| 1332 | pub fn dms(&self) -> impl Iterator<Item = &RoomId> { | |
| 1333 | self.dms.iter().map(|r| r.0.room_id()) | |
| 1334 | } | |
| 1335 | ||
| 1336 | pub fn chats(&self) -> impl Iterator<Item = &RoomId> { | |
| 1337 | self.rooms().chain(self.dms()) | |
| 1338 | } | |
| 1339 | } | |
| 1340 | ||
| 1312 | 1341 | bitflags::bitflags! { |
| 1313 | 1342 | /// Load-needs |
| 1314 | 1343 | #[derive(Debug, Default, PartialEq)] |
| @@ -1480,6 +1509,9 @@ pub enum IambId { | ||
| 1480 | 1509 | |
| 1481 | 1510 | /// The `:chats` window. |
| 1482 | 1511 | ChatList, |
| 1512 | ||
| 1513 | /// The `:unreads` window. | |
| 1514 | UnreadList, | |
| 1483 | 1515 | } |
| 1484 | 1516 | |
| 1485 | 1517 | impl Display for IambId { |
| @@ -1500,6 +1532,7 @@ impl Display for IambId { | ||
| 1500 | 1532 | IambId::VerifyList => f.write_str("iamb://verify"), |
| 1501 | 1533 | IambId::Welcome => f.write_str("iamb://welcome"), |
| 1502 | 1534 | IambId::ChatList => f.write_str("iamb://chats"), |
| 1535 | IambId::UnreadList => f.write_str("iamb://unreads"), | |
| 1503 | 1536 | } |
| 1504 | 1537 | } |
| 1505 | 1538 | } |
| @@ -1631,6 +1664,13 @@ impl<'de> Visitor<'de> for IambIdVisitor { | ||
| 1631 | 1664 | |
| 1632 | 1665 | Ok(IambId::ChatList) |
| 1633 | 1666 | }, |
| 1667 | Some("unreads") => { | |
| 1668 | if url.path() != "" { | |
| 1669 | return Err(E::custom("iamb://unreads takes no path")); | |
| 1670 | } | |
| 1671 | ||
| 1672 | Ok(IambId::UnreadList) | |
| 1673 | }, | |
| 1634 | 1674 | Some(s) => Err(E::custom(format!("{s:?} is not a valid window"))), |
| 1635 | 1675 | None => Err(E::custom("Invalid iamb window URL")), |
| 1636 | 1676 | } |
| @@ -1691,6 +1731,9 @@ pub enum IambBufferId { | ||
| 1691 | 1731 | |
| 1692 | 1732 | /// The `:chats` window. |
| 1693 | 1733 | ChatList, |
| 1734 | ||
| 1735 | /// The `:unreads` window. | |
| 1736 | UnreadList, | |
| 1694 | 1737 | } |
| 1695 | 1738 | |
| 1696 | 1739 | impl IambBufferId { |
| @@ -1706,6 +1749,7 @@ impl IambBufferId { | ||
| 1706 | 1749 | IambBufferId::VerifyList => IambId::VerifyList, |
| 1707 | 1750 | IambBufferId::Welcome => IambId::Welcome, |
| 1708 | 1751 | IambBufferId::ChatList => IambId::ChatList, |
| 1752 | IambBufferId::UnreadList => IambId::UnreadList, | |
| 1709 | 1753 | }; |
| 1710 | 1754 | |
| 1711 | 1755 | Some(id) |
| @@ -1740,6 +1784,7 @@ impl ApplicationInfo for IambInfo { | ||
| 1740 | 1784 | IambBufferId::VerifyList => vec![], |
| 1741 | 1785 | IambBufferId::Welcome => vec![], |
| 1742 | 1786 | IambBufferId::ChatList => vec![], |
| 1787 | IambBufferId::UnreadList => vec![], | |
| 1743 | 1788 | } |
| 1744 | 1789 | } |
| 1745 | 1790 | |
src/commands.rs +29
| @@ -307,6 +307,30 @@ fn iamb_chats(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 307 | 307 | return Ok(step); |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | fn iamb_unreads(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | |
| 311 | let mut args = desc.arg.strings()?; | |
| 312 | ||
| 313 | if args.len() > 1 { | |
| 314 | return Result::Err(CommandError::InvalidArgument); | |
| 315 | } | |
| 316 | ||
| 317 | match args.pop().as_deref() { | |
| 318 | Some("clear") => { | |
| 319 | let clear = IambAction::ClearUnreads; | |
| 320 | let step = CommandStep::Continue(clear.into(), ctx.context.clone()); | |
| 321 | ||
| 322 | return Ok(step); | |
| 323 | }, | |
| 324 | Some(_) => return Result::Err(CommandError::InvalidArgument), | |
| 325 | None => { | |
| 326 | let open = ctx.switch(OpenTarget::Application(IambId::UnreadList)); | |
| 327 | let step = CommandStep::Continue(open, ctx.context.clone()); | |
| 328 | ||
| 329 | return Ok(step); | |
| 330 | }, | |
| 331 | } | |
| 332 | } | |
| 333 | ||
| 310 | 334 | fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 311 | 335 | if !desc.arg.text.is_empty() { |
| 312 | 336 | return Result::Err(CommandError::InvalidArgument); |
| @@ -648,6 +672,11 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) { | ||
| 648 | 672 | aliases: vec![], |
| 649 | 673 | f: iamb_spaces, |
| 650 | 674 | }); |
| 675 | cmds.add_command(ProgramCommand { | |
| 676 | name: "unreads".into(), | |
| 677 | aliases: vec![], | |
| 678 | f: iamb_unreads, | |
| 679 | }); | |
| 651 | 680 | cmds.add_command(ProgramCommand { |
| 652 | 681 | name: "unreact".into(), |
| 653 | 682 | aliases: vec![], |
src/main.rs +12
| @@ -529,6 +529,18 @@ impl Application { | ||
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | let info = match action { |
| 532 | IambAction::ClearUnreads => { | |
| 533 | let user_id = &store.application.settings.profile.user_id; | |
| 534 | ||
| 535 | for room_id in store.application.sync_info.chats() { | |
| 536 | if let Some(room) = store.application.rooms.get_mut(room_id) { | |
| 537 | room.fully_read(user_id.clone()); | |
| 538 | } | |
| 539 | } | |
| 540 | ||
| 541 | None | |
| 542 | }, | |
| 543 | ||
| 532 | 544 | IambAction::ToggleScrollbackFocus => { |
| 533 | 545 | self.screen.current_window_mut()?.focus_toggle(); |
| 534 | 546 | |
src/windows/mod.rs +45
| @@ -315,6 +315,7 @@ macro_rules! delegate { | ||
| 315 | 315 | IambWindow::VerifyList($id) => $e, |
| 316 | 316 | IambWindow::Welcome($id) => $e, |
| 317 | 317 | IambWindow::ChatList($id) => $e, |
| 318 | IambWindow::UnreadList($id) => $e, | |
| 318 | 319 | } |
| 319 | 320 | }; |
| 320 | 321 | } |
| @@ -328,6 +329,7 @@ pub enum IambWindow { | ||
| 328 | 329 | SpaceList(SpaceListState), |
| 329 | 330 | Welcome(WelcomeState), |
| 330 | 331 | ChatList(ChatListState), |
| 332 | UnreadList(UnreadListState), | |
| 331 | 333 | } |
| 332 | 334 | |
| 333 | 335 | impl IambWindow { |
| @@ -383,6 +385,7 @@ pub type DirectListState = ListState<DirectItem, IambInfo>; | ||
| 383 | 385 | pub type MemberListState = ListState<MemberItem, IambInfo>; |
| 384 | 386 | pub type RoomListState = ListState<RoomItem, IambInfo>; |
| 385 | 387 | pub type ChatListState = ListState<GenericChatItem, IambInfo>; |
| 388 | pub type UnreadListState = ListState<GenericChatItem, IambInfo>; | |
| 386 | 389 | pub type SpaceListState = ListState<SpaceItem, IambInfo>; |
| 387 | 390 | pub type VerifyListState = ListState<VerifyItem, IambInfo>; |
| 388 | 391 | |
| @@ -579,6 +582,39 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 579 | 582 | .focus(focused) |
| 580 | 583 | .render(area, buf, state); |
| 581 | 584 | }, |
| 585 | IambWindow::UnreadList(state) => { | |
| 586 | let mut items = store | |
| 587 | .application | |
| 588 | .sync_info | |
| 589 | .rooms | |
| 590 | .clone() | |
| 591 | .into_iter() | |
| 592 | .map(|room_info| GenericChatItem::new(room_info, store, false)) | |
| 593 | .filter(RoomLikeItem::is_unread) | |
| 594 | .collect::<Vec<_>>(); | |
| 595 | ||
| 596 | let dms = store | |
| 597 | .application | |
| 598 | .sync_info | |
| 599 | .dms | |
| 600 | .clone() | |
| 601 | .into_iter() | |
| 602 | .map(|room_info| GenericChatItem::new(room_info, store, true)) | |
| 603 | .filter(RoomLikeItem::is_unread); | |
| 604 | ||
| 605 | items.extend(dms); | |
| 606 | ||
| 607 | let fields = &store.application.settings.tunables.sort.chats; | |
| 608 | items.sort_by(|a, b| room_fields_cmp(a, b, fields)); | |
| 609 | ||
| 610 | state.set(items); | |
| 611 | ||
| 612 | List::new(store) | |
| 613 | .empty_message("You do not have rooms or dms yet") | |
| 614 | .empty_alignment(Alignment::Center) | |
| 615 | .focus(focused) | |
| 616 | .render(area, buf, state); | |
| 617 | }, | |
| 582 | 618 | IambWindow::SpaceList(state) => { |
| 583 | 619 | let mut items = store |
| 584 | 620 | .application |
| @@ -630,6 +666,7 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 630 | 666 | IambWindow::VerifyList(w) => w.dup(store).into(), |
| 631 | 667 | IambWindow::Welcome(w) => w.dup(store).into(), |
| 632 | 668 | IambWindow::ChatList(w) => w.dup(store).into(), |
| 669 | IambWindow::UnreadList(w) => w.dup(store).into(), | |
| 633 | 670 | } |
| 634 | 671 | } |
| 635 | 672 | |
| @@ -670,6 +707,7 @@ impl Window<IambInfo> for IambWindow { | ||
| 670 | 707 | IambWindow::VerifyList(_) => IambId::VerifyList, |
| 671 | 708 | IambWindow::Welcome(_) => IambId::Welcome, |
| 672 | 709 | IambWindow::ChatList(_) => IambId::ChatList, |
| 710 | IambWindow::UnreadList(_) => IambId::UnreadList, | |
| 673 | 711 | } |
| 674 | 712 | } |
| 675 | 713 | |
| @@ -681,6 +719,7 @@ impl Window<IambInfo> for IambWindow { | ||
| 681 | 719 | IambWindow::VerifyList(_) => bold_spans("Verifications"), |
| 682 | 720 | IambWindow::Welcome(_) => bold_spans("Welcome to iamb"), |
| 683 | 721 | IambWindow::ChatList(_) => bold_spans("DMs & Rooms"), |
| 722 | IambWindow::UnreadList(_) => bold_spans("Unread Messages"), | |
| 684 | 723 | |
| 685 | 724 | IambWindow::Room(w) => { |
| 686 | 725 | let title = store.application.get_room_title(w.id()); |
| @@ -708,6 +747,7 @@ impl Window<IambInfo> for IambWindow { | ||
| 708 | 747 | IambWindow::VerifyList(_) => bold_spans("Verifications"), |
| 709 | 748 | IambWindow::Welcome(_) => bold_spans("Welcome to iamb"), |
| 710 | 749 | IambWindow::ChatList(_) => bold_spans("DMs & Rooms"), |
| 750 | IambWindow::UnreadList(_) => bold_spans("Unread Messages"), | |
| 711 | 751 | |
| 712 | 752 | IambWindow::Room(w) => w.get_title(store), |
| 713 | 753 | IambWindow::MemberList(state, room_id, _) => { |
| @@ -769,6 +809,11 @@ impl Window<IambInfo> for IambWindow { | ||
| 769 | 809 | |
| 770 | 810 | Ok(list.into()) |
| 771 | 811 | }, |
| 812 | IambId::UnreadList => { | |
| 813 | let list = UnreadListState::new(IambBufferId::UnreadList, vec![]); | |
| 814 | ||
| 815 | Ok(IambWindow::UnreadList(list)) | |
| 816 | }, | |
| 772 | 817 | } |
| 773 | 818 | } |
| 774 | 819 | |