Commit beb8e5265d
Unregistered key
Layout: unified · split
docs/iamb.1 +6
| @@ -152,6 +152,12 @@ and | |||
| 152 | Follow the tombstone information to the upgraded room. | 152 | Follow the tombstone information to the upgraded room. |
| 153 | .It Sy ":follow previous" | 153 | .It Sy ":follow previous" |
| 154 | Follow the room creation information to the pre-upgraded room. | 154 | Follow the room creation information to the pre-upgraded room. |
| 155 | .It Sy ":ignore set [user]" | ||
| 156 | Add a user to your account's ignore list. | ||
| 157 | .It Sy ":ignore unset [user]" | ||
| 158 | Remove a user from your account's ignore list. | ||
| 159 | .It Sy ":ignore show" | ||
| 160 | Show all users in your account's ignore list. | ||
| 155 | .It Sy ":invite accept" | 161 | .It Sy ":invite accept" |
| 156 | Accept an invitation to the currently focused room. | 162 | Accept an invitation to the currently focused room. |
| 157 | .It Sy ":invite reject" | 163 | .It Sy ":invite reject" |
src/base.rs +33 −1
| @@ -454,6 +454,13 @@ impl Visitor<'_> for SortUserVisitor { | |||
| 454 | } | 454 | } |
| 455 | } | 455 | } |
| 456 | 456 | ||
| 457 | /// An account property. | ||
| 458 | #[derive(Clone, Debug, Eq, PartialEq)] | ||
| 459 | pub enum AccountField { | ||
| 460 | /// The account's ignore list. | ||
| 461 | Ignore, | ||
| 462 | } | ||
| 463 | |||
| 457 | /// A room property. | 464 | /// A room property. |
| 458 | #[derive(Clone, Debug, Eq, PartialEq)] | 465 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 459 | pub enum RoomField { | 466 | pub enum RoomField { |
| @@ -654,6 +661,15 @@ pub enum HomeserverAction { | |||
| 654 | /// Create a new room with an optional localpart. | 661 | /// Create a new room with an optional localpart. |
| 655 | CreateRoom(Option<String>, CreateRoomType, CreateRoomFlags), | 662 | CreateRoom(Option<String>, CreateRoomType, CreateRoomFlags), |
| 656 | 663 | ||
| 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 | |||
| 657 | /// "Knock" on a room, aka "request to join". | 673 | /// "Knock" on a room, aka "request to join". |
| 658 | KnockSend(OwnedRoomOrAliasId, Option<String>), | 674 | KnockSend(OwnedRoomOrAliasId, Option<String>), |
| 659 | 675 | ||
| @@ -918,7 +934,7 @@ pub enum IambError { | |||
| 918 | InvalidNotificationLevel(String), | 934 | InvalidNotificationLevel(String), |
| 919 | 935 | ||
| 920 | /// An invalid user identifier was specified. | 936 | /// An invalid user identifier was specified. |
| 921 | #[error("Invalid user identifier: {0}")] | 937 | #[error("Invalid user identifier: {0:?}")] |
| 922 | InvalidUserId(String), | 938 | InvalidUserId(String), |
| 923 | 939 | ||
| 924 | /// An invalid user identifier was specified. | 940 | /// An invalid user identifier was specified. |
| @@ -2482,6 +2498,22 @@ impl ChatStore { | |||
| 2482 | Ok(store) | 2498 | Ok(store) |
| 2483 | } | 2499 | } |
| 2484 | 2500 | ||
| 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 | |||
| 2485 | /// Get a joined room. | 2517 | /// Get a joined room. |
| 2486 | pub fn get_joined_room(&self, room_id: &RoomId) -> Option<MatrixRoom> { | 2518 | pub fn get_joined_room(&self, room_id: &RoomId) -> Option<MatrixRoom> { |
| 2487 | let room = self.worker.client.get_room(room_id)?; | 2519 | 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> { | |||
| 49 | Ok(tag) | 49 | Ok(tag) |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | fn 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 | |||
| 52 | fn iamb_invite(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | 84 | fn iamb_invite(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 53 | let args = desc.arg.strings()?; | 85 | let args = desc.arg.strings()?; |
| 54 | 86 | ||
| @@ -1123,6 +1155,11 @@ pub fn add_iamb_commands(cmds: &mut ProgramCommands) { | |||
| 1123 | aliases: vec![], | 1155 | aliases: vec![], |
| 1124 | f: iamb_forget, | 1156 | f: iamb_forget, |
| 1125 | }); | 1157 | }); |
| 1158 | cmds.add_command(ProgramCommand { | ||
| 1159 | name: "ignore".into(), | ||
| 1160 | aliases: vec![], | ||
| 1161 | f: iamb_ignore, | ||
| 1162 | }); | ||
| 1126 | cmds.add_command(ProgramCommand { | 1163 | cmds.add_command(ProgramCommand { |
| 1127 | name: "invite".into(), | 1164 | name: "invite".into(), |
| 1128 | aliases: vec![], | 1165 | aliases: vec![], |
src/completions.rs +11
| @@ -380,6 +380,16 @@ fn complete_iamb_verify(args: Vec<String>, store: &ChatStore) -> Vec<String> { | |||
| 380 | } | 380 | } |
| 381 | } | 381 | } |
| 382 | 382 | ||
| 383 | /// Tab completion for `:ignore` | ||
| 384 | fn 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 | |||
| 383 | /// Tab completion for `:self` | 393 | /// Tab completion for `:self` |
| 384 | fn complete_iamb_self(args: Vec<String>) -> Vec<String> { | 394 | fn complete_iamb_self(args: Vec<String>) -> Vec<String> { |
| 385 | let subcmds = ["avatar", "name", "nick", "timezone", "tz"]; | 395 | let subcmds = ["avatar", "name", "nick", "timezone", "tz"]; |
| @@ -585,6 +595,7 @@ fn complete_cmdarg( | |||
| 585 | 595 | ||
| 586 | "follow" => complete_choices(&args[0], &["next", "previous"]), | 596 | "follow" => complete_choices(&args[0], &["next", "previous"]), |
| 587 | 597 | ||
| 598 | "ignore" => complete_iamb_ignore(args, store), | ||
| 588 | "invite" => complete_iamb_invite(args, store), | 599 | "invite" => complete_iamb_invite(args, store), |
| 589 | 600 | ||
| 590 | "join" if args.len() == 1 => complete_matrix_names(&args[0], store), | 601 | "join" if args.len() == 1 => complete_matrix_names(&args[0], store), |
src/main.rs +57
| @@ -26,6 +26,7 @@ use std::sync::atomic::AtomicUsize; | |||
| 26 | use clap::{CommandFactory, Parser}; | 26 | use clap::{CommandFactory, Parser}; |
| 27 | use matrix_sdk::OwnedServerName; | 27 | use matrix_sdk::OwnedServerName; |
| 28 | use matrix_sdk::ruma::api::error::ErrorKind; | 28 | use matrix_sdk::ruma::api::error::ErrorKind; |
| 29 | use matrix_sdk::ruma::events::ignored_user_list::IgnoredUserListEventContent; | ||
| 29 | use modalkit::actions::{Commandable, TabAction, TabContainer, TabCount, WindowContainer}; | 30 | use modalkit::actions::{Commandable, TabAction, TabContainer, TabCount, WindowContainer}; |
| 30 | use modalkit::crossterm; | 31 | use modalkit::crossterm; |
| 31 | use modalkit::crossterm::cursor::SetCursorStyle; | 32 | use modalkit::crossterm::cursor::SetCursorStyle; |
| @@ -691,6 +692,62 @@ impl Application { | |||
| 691 | 692 | ||
| 692 | Ok(vec![(action.into(), ctx)]) | 693 | Ok(vec![(action.into(), ctx)]) |
| 693 | }, | 694 | }, |
| 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 | }, | ||
| 694 | HomeserverAction::KnockSend(alias, reason) => { | 751 | HomeserverAction::KnockSend(alias, reason) => { |
| 695 | let _ = self | 752 | let _ = self |
| 696 | .worker | 753 | .worker |
src/prelude.rs +1
| @@ -72,6 +72,7 @@ pub use unicode_width::UnicodeWidthStr; | |||
| 72 | pub use url::Url; | 72 | pub use url::Url; |
| 73 | 73 | ||
| 74 | pub use crate::base::{ | 74 | pub use crate::base::{ |
| 75 | AccountField, | ||
| 75 | AsyncProgramStore, | 76 | AsyncProgramStore, |
| 76 | ChatStore, | 77 | ChatStore, |
| 77 | IambAction, | 78 | IambAction, |
src/worker.rs +3 −3
| @@ -252,13 +252,13 @@ async fn load_plans(store: &AsyncProgramStore) -> Vec<Plan> { | |||
| 252 | let info = rooms.get_or_default(room_id.clone()); | 252 | let info = rooms.get_or_default(room_id.clone()); |
| 253 | 253 | ||
| 254 | if !info.recently_fetched() && !info.fetching { | 254 | if !info.recently_fetched() && !info.fetching { |
| 255 | info.fetch_last = Instant::now().into(); | ||
| 256 | info.fetching = true; | ||
| 257 | |||
| 258 | if info.reached_timeline_start { | 255 | if info.reached_timeline_start { |
| 259 | continue; | 256 | continue; |
| 260 | } | 257 | } |
| 261 | 258 | ||
| 259 | info.fetch_last = Instant::now().into(); | ||
| 260 | info.fetching = true; | ||
| 261 | |||
| 262 | plan.push(Plan::Messages(room_id.to_owned(), message_need)); | 262 | plan.push(Plan::Messages(room_id.to_owned(), message_need)); |
| 263 | } else { | 263 | } else { |
| 264 | need_load.need_messages_all(room_id.clone(), message_need); | 264 | need_load.need_messages_all(room_id.clone(), message_need); |