Commit ddf3bb2947
Unregistered key
Layout: unified · split
docs/iamb.1 +7
| @@ -321,6 +321,13 @@ Set the avatar URL for your profile. | ||
| 321 | 321 | Unset the avatar for your profile. |
| 322 | 322 | .It Sy ":self avatar show" |
| 323 | 323 | Show the current avatar URL for your profile. |
| 324 | .It Sy ":self invites set [allow|block]" | |
| 325 | Set whether others are allowed to send you invites. | |
| 326 | .It Sy ":self invites unset" | |
| 327 | Shorthand for | |
| 328 | .Sy ":self invites set allow" . | |
| 329 | .It Sy ":self invites show" | |
| 330 | Show whether other users are currently allowed to send you invites. | |
| 324 | 331 | .It Sy ":self name set [nickname]" |
| 325 | 332 | Set the display name for your profile. |
| 326 | 333 | .It Sy ":self name unset" |
src/base.rs +3
| @@ -459,6 +459,9 @@ impl Visitor<'_> for SortUserVisitor { | ||
| 459 | 459 | pub enum AccountField { |
| 460 | 460 | /// The account's ignore list. |
| 461 | 461 | Ignore, |
| 462 | ||
| 463 | /// Set whether other user's are allowed to invite the user to rooms. | |
| 464 | Invites, | |
| 462 | 465 | } |
| 463 | 466 | |
| 464 | 467 | /// A room property. |
src/commands.rs +16
| @@ -567,6 +567,22 @@ fn iamb_self(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 567 | 567 | }, |
| 568 | 568 | ("avatar", "unset", Some(_)) => return Result::Err(CommandError::InvalidArgument), |
| 569 | 569 | |
| 570 | // :self invites show | |
| 571 | ("invites", "show", None) => HomeserverAction::AccountShow(AccountField::Invites).into(), | |
| 572 | ("invites", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument), | |
| 573 | ||
| 574 | // :self invites set | |
| 575 | ("invites", "set", Some(s)) => { | |
| 576 | HomeserverAction::AccountSet(AccountField::Invites, s).into() | |
| 577 | }, | |
| 578 | ("invites", "set", None) => return Result::Err(CommandError::InvalidArgument), | |
| 579 | ||
| 580 | // :self invites unset | |
| 581 | ("invites", "unset", None) => { | |
| 582 | HomeserverAction::AccountUnset(AccountField::Invites, None).into() | |
| 583 | }, | |
| 584 | ("invites", "unset", Some(_)) => return Result::Err(CommandError::InvalidArgument), | |
| 585 | ||
| 570 | 586 | // :self name show |
| 571 | 587 | ("name" | "nick", "show", None) => { |
| 572 | 588 | HomeserverAction::ProfileFieldShow(ProfileFieldName::DisplayName).into() |
src/main.rs +63
| @@ -27,6 +27,10 @@ use clap::{CommandFactory, Parser}; | ||
| 27 | 27 | use matrix_sdk::OwnedServerName; |
| 28 | 28 | use matrix_sdk::ruma::api::error::ErrorKind; |
| 29 | 29 | use matrix_sdk::ruma::events::ignored_user_list::IgnoredUserListEventContent; |
| 30 | use matrix_sdk::ruma::events::invite_permission_config::{ | |
| 31 | InvitePermissionAction, | |
| 32 | InvitePermissionConfigEventContent, | |
| 33 | }; | |
| 30 | 34 | use modalkit::actions::{Commandable, TabAction, TabContainer, TabCount, WindowContainer}; |
| 31 | 35 | use modalkit::crossterm; |
| 32 | 36 | use modalkit::crossterm::cursor::SetCursorStyle; |
| @@ -692,6 +696,65 @@ impl Application { | ||
| 692 | 696 | |
| 693 | 697 | Ok(vec![(action.into(), ctx)]) |
| 694 | 698 | }, |
| 699 | HomeserverAction::AccountSet(AccountField::Invites, perms) => { | |
| 700 | let perms = match perms.as_str() { | |
| 701 | "allow" => None, | |
| 702 | "block" => Some(InvitePermissionAction::Block), | |
| 703 | perm => { | |
| 704 | return Err(UIError::Failure(format!( | |
| 705 | "{perm:?} is not a valid invite permission" | |
| 706 | ))); | |
| 707 | }, | |
| 708 | }; | |
| 709 | let mut content = InvitePermissionConfigEventContent::new(); | |
| 710 | content.default_action = perms; | |
| 711 | let _ = self | |
| 712 | .worker | |
| 713 | .client | |
| 714 | .account() | |
| 715 | .set_account_data(content) | |
| 716 | .await | |
| 717 | .map_err(IambError::from)?; | |
| 718 | Ok(vec![]) | |
| 719 | }, | |
| 720 | HomeserverAction::AccountUnset(AccountField::Invites, val) => { | |
| 721 | if let Some(val) = val { | |
| 722 | let msg = format!("Cannot unset invites with a value (given {val:?})"); | |
| 723 | return Err(UIError::Failure(msg)); | |
| 724 | } | |
| 725 | ||
| 726 | let mut content = InvitePermissionConfigEventContent::new(); | |
| 727 | content.default_action = None; | |
| 728 | let _ = self | |
| 729 | .worker | |
| 730 | .client | |
| 731 | .account() | |
| 732 | .set_account_data(content) | |
| 733 | .await | |
| 734 | .map_err(IambError::from)?; | |
| 735 | Ok(vec![]) | |
| 736 | }, | |
| 737 | HomeserverAction::AccountShow(AccountField::Invites) => { | |
| 738 | let resp = self | |
| 739 | .worker | |
| 740 | .client | |
| 741 | .account() | |
| 742 | .fetch_account_data_static::<InvitePermissionConfigEventContent>() | |
| 743 | .await | |
| 744 | .map_err(IambError::from)?; | |
| 745 | let resp = resp | |
| 746 | .map(|r| r.deserialize()) | |
| 747 | .transpose() | |
| 748 | .map_err(IambError::from)? | |
| 749 | .and_then(|r| r.default_action); | |
| 750 | let action = match resp.as_ref() { | |
| 751 | None => "allow", | |
| 752 | Some(InvitePermissionAction::Block) => "block", | |
| 753 | Some(other) => other.as_str(), | |
| 754 | }; | |
| 755 | let msg = format!("Current default invite permission: {action}"); | |
| 756 | Ok(vec![(Action::ShowInfoMessage(msg.into()), ctx)]) | |
| 757 | }, | |
| 695 | 758 | HomeserverAction::AccountSet(AccountField::Ignore, user) => { |
| 696 | 759 | let Ok(user) = OwnedUserId::from_str(&user) else { |
| 697 | 760 | return Err(IambError::InvalidUserId(user).into()); |
src/windows/room/mod.rs +4
| @@ -983,6 +983,10 @@ impl TerminalCursor for RoomState { | ||
| 983 | 983 | |
| 984 | 984 | impl WindowOps<IambInfo> for RoomState { |
| 985 | 985 | fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { |
| 986 | let theme = &store.application.settings.theme; | |
| 987 | let default_style = theme.timeline.default; | |
| 988 | buf.set_style(area, default_style); | |
| 989 | ||
| 986 | 990 | if self.room_state() != Some(MatrixRoomState::Joined) { |
| 987 | 991 | self.refresh_room(store); |
| 988 | 992 | } |