Commit beb8e5265d

beb8e5265d46c22e781a71f6e27728136d3af5e5

parent: f89c546e44

Unregistered key

Ulyssa <git@ulyssa.dev> · 2026-10-04 22:51 UTC
committer: <noreply@github.com>

Add `:ignore` commands for managing ignore list (#780)

Layout: unified · split

docs/iamb.1 +6
@@ -152,6 +152,12 @@ and
152152Follow the tombstone information to the upgraded room.
153153.It Sy ":follow previous"
154154Follow the room creation information to the pre-upgraded room.
155.It Sy ":ignore set [user]"
156Add a user to your account's ignore list.
157.It Sy ":ignore unset [user]"
158Remove a user from your account's ignore list.
159.It Sy ":ignore show"
160Show all users in your account's ignore list.
155161.It Sy ":invite accept"
156162Accept an invitation to the currently focused room.
157163.It Sy ":invite reject"
src/base.rs +33 −1
@@ -454,6 +454,13 @@ impl Visitor<'_> for SortUserVisitor {
454454 }
455455}
456456
457/// An account property.
458#[derive(Clone, Debug, Eq, PartialEq)]
459pub enum AccountField {
460 /// The account's ignore list.
461 Ignore,
462}
463
457464/// A room property.
458465#[derive(Clone, Debug, Eq, PartialEq)]
459466pub enum RoomField {
@@ -654,6 +661,15 @@ pub enum HomeserverAction {
654661 /// Create a new room with an optional localpart.
655662 CreateRoom(Option<String>, CreateRoomType, CreateRoomFlags),
656663
664 /// Update an account property.
665 AccountSet(AccountField, String),
666
667 /// Show information about an account property.
668 AccountShow(AccountField),
669
670 /// Remove a user from the account's ignore list.
671 AccountUnset(AccountField, Option<String>),
672
657673 /// "Knock" on a room, aka "request to join".
658674 KnockSend(OwnedRoomOrAliasId, Option<String>),
659675
@@ -918,7 +934,7 @@ pub enum IambError {
918934 InvalidNotificationLevel(String),
919935
920936 /// An invalid user identifier was specified.
921 #[error("Invalid user identifier: {0}")]
937 #[error("Invalid user identifier: {0:?}")]
922938 InvalidUserId(String),
923939
924940 /// An invalid user identifier was specified.
@@ -2482,6 +2498,22 @@ impl ChatStore {
24822498 Ok(store)
24832499 }
24842500
2501 /// Clear the `EventCache` for all rooms.
2502 ///
2503 /// This forces a re-fetch of the most recent messages in joined rooms afterwards,
2504 /// which makes sure that we re-fetch any missing events (such as those sent by
2505 /// recently unignored users that a re-fetch would make appear in the timeline).
2506 pub async fn clear_room_cache(&mut self, client: &Client) -> Result<(), IambError> {
2507 client.event_cache().clear_all_rooms().await?;
2508 for room in client.joined_rooms() {
2509 let room_id = room.room_id().to_owned();
2510 let room = self.rooms.get_or_default(room_id.clone());
2511 room.reached_timeline_start = false;
2512 self.need_load.need_messages(room_id.to_owned());
2513 }
2514 Ok(())
2515 }
2516
24852517 /// Get a joined room.
24862518 pub fn get_joined_room(&self, room_id: &RoomId) -> Option<MatrixRoom> {
24872519 let room = self.worker.client.get_room(room_id)?;
src/commands.rs +37
@@ -49,6 +49,38 @@ fn tag_name(name: String) -> Result<TagName, CommandError> {
4949 Ok(tag)
5050}
5151
52fn iamb_ignore(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
53 let mut iter = desc.arg.strings()?.into_iter();
54 let action = iter.next().ok_or(CommandError::InvalidArgument)?;
55 let arg = iter.next();
56
57 if iter.next().is_some() {
58 return Err(CommandError::InvalidArgument);
59 }
60
61 let act: IambAction = match (action.as_str(), arg) {
62 ("set", Some(user)) => HomeserverAction::AccountSet(AccountField::Ignore, user).into(),
63 ("set", None) => return Err(CommandError::InvalidArgument),
64
65 ("show", None) => HomeserverAction::AccountShow(AccountField::Ignore).into(),
66 ("show", Some(_)) => return Err(CommandError::InvalidArgument),
67
68 ("unset", Some(user)) => {
69 HomeserverAction::AccountUnset(AccountField::Ignore, Some(user)).into()
70 },
71 ("unset", None) => return Err(CommandError::InvalidArgument),
72
73 (op, _) => {
74 let msg = format!("unknown `:ignore` operation: {op:?}");
75 return Err(CommandError::Error(msg));
76 },
77 };
78
79 let step = CommandStep::Continue(act.into(), ctx.context.clone());
80
81 return Ok(step);
82}
83
5284fn iamb_invite(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
5385 let args = desc.arg.strings()?;
5486
@@ -1123,6 +1155,11 @@ pub fn add_iamb_commands(cmds: &mut ProgramCommands) {
11231155 aliases: vec![],
11241156 f: iamb_forget,
11251157 });
1158 cmds.add_command(ProgramCommand {
1159 name: "ignore".into(),
1160 aliases: vec![],
1161 f: iamb_ignore,
1162 });
11261163 cmds.add_command(ProgramCommand {
11271164 name: "invite".into(),
11281165 aliases: vec![],
src/completions.rs +11
@@ -380,6 +380,16 @@ fn complete_iamb_verify(args: Vec<String>, store: &ChatStore) -> Vec<String> {
380380 }
381381}
382382
383/// Tab completion for `:ignore`
384fn complete_iamb_ignore(args: Vec<String>, store: &ChatStore) -> Vec<String> {
385 let subcmds = ["set", "unset", "show"];
386 match args.len() {
387 1 => complete_choices(&args[0], &subcmds),
388 2 if subcmds[0..2].contains(&args[0].as_str()) => complete_users(args[1].as_str(), store),
389 _ => vec![],
390 }
391}
392
383393/// Tab completion for `:self`
384394fn complete_iamb_self(args: Vec<String>) -> Vec<String> {
385395 let subcmds = ["avatar", "name", "nick", "timezone", "tz"];
@@ -585,6 +595,7 @@ fn complete_cmdarg(
585595
586596 "follow" => complete_choices(&args[0], &["next", "previous"]),
587597
598 "ignore" => complete_iamb_ignore(args, store),
588599 "invite" => complete_iamb_invite(args, store),
589600
590601 "join" if args.len() == 1 => complete_matrix_names(&args[0], store),
src/main.rs +57
@@ -26,6 +26,7 @@ use std::sync::atomic::AtomicUsize;
2626use clap::{CommandFactory, Parser};
2727use matrix_sdk::OwnedServerName;
2828use matrix_sdk::ruma::api::error::ErrorKind;
29use matrix_sdk::ruma::events::ignored_user_list::IgnoredUserListEventContent;
2930use modalkit::actions::{Commandable, TabAction, TabContainer, TabCount, WindowContainer};
3031use modalkit::crossterm;
3132use modalkit::crossterm::cursor::SetCursorStyle;
@@ -691,6 +692,62 @@ impl Application {
691692
692693 Ok(vec![(action.into(), ctx)])
693694 },
695 HomeserverAction::AccountSet(AccountField::Ignore, user) => {
696 let Ok(user) = OwnedUserId::from_str(&user) else {
697 return Err(IambError::InvalidUserId(user).into());
698 };
699 self.worker
700 .client
701 .account()
702 .ignore_user(&user)
703 .await
704 .map_err(IambError::from)?;
705 Ok(vec![])
706 },
707 HomeserverAction::AccountUnset(AccountField::Ignore, user) => {
708 let Some(user) = user else {
709 return Err(IambError::InvalidUserId("".into()).into());
710 };
711 let Ok(user) = OwnedUserId::from_str(&user) else {
712 return Err(IambError::InvalidUserId(user).into());
713 };
714 self.worker
715 .client
716 .account()
717 .unignore_user(&user)
718 .await
719 .map_err(IambError::from)?;
720 store.application.clear_room_cache(&self.worker.client).await?;
721 Ok(vec![])
722 },
723 HomeserverAction::AccountShow(AccountField::Ignore) => {
724 let ignored = self
725 .worker
726 .client
727 .account()
728 .account_data::<IgnoredUserListEventContent>()
729 .await
730 .map_err(IambError::from)?;
731 let ignored_users = ignored
732 .map(|raw| raw.deserialize())
733 .transpose()
734 .map_err(IambError::from)?
735 .map(|c| c.ignored_users);
736
737 let msg = match ignored_users {
738 Some(users) if !users.is_empty() => {
739 let mut s = String::from("You are currently ignoring:");
740 users.keys().for_each(|u| {
741 s.push_str("\n - ");
742 s.push_str(u.as_ref());
743 });
744 s
745 },
746 _ => "You have no users in your ignore list.".into(),
747 };
748
749 Ok(vec![(Action::ShowInfoMessage(InfoMessage::Pager(msg)), ctx)])
750 },
694751 HomeserverAction::KnockSend(alias, reason) => {
695752 let _ = self
696753 .worker
src/prelude.rs +1
@@ -72,6 +72,7 @@ pub use unicode_width::UnicodeWidthStr;
7272pub use url::Url;
7373
7474pub use crate::base::{
75 AccountField,
7576 AsyncProgramStore,
7677 ChatStore,
7778 IambAction,
src/worker.rs +3 −3
@@ -252,13 +252,13 @@ async fn load_plans(store: &AsyncProgramStore) -> Vec<Plan> {
252252 let info = rooms.get_or_default(room_id.clone());
253253
254254 if !info.recently_fetched() && !info.fetching {
255 info.fetch_last = Instant::now().into();
256 info.fetching = true;
257
258255 if info.reached_timeline_start {
259256 continue;
260257 }
261258
259 info.fetch_last = Instant::now().into();
260 info.fetching = true;
261
262262 plan.push(Plan::Messages(room_id.to_owned(), message_need));
263263 } else {
264264 need_load.need_messages_all(room_id.clone(), message_need);