Commit ddf3bb2947

ddf3bb2947dda5732b81092827813d508985956c

parent: 4baa623504

Unregistered key

Ulyssa <git@ulyssa.dev> · 2026-10-05 00:46 UTC
committer: <noreply@github.com>

Add `:self invites` command for managing invite permissions (#781)

Layout: unified · split

docs/iamb.1 +7
@@ -321,6 +321,13 @@ Set the avatar URL for your profile.
321321Unset the avatar for your profile.
322322.It Sy ":self avatar show"
323323Show the current avatar URL for your profile.
324.It Sy ":self invites set [allow|block]"
325Set whether others are allowed to send you invites.
326.It Sy ":self invites unset"
327Shorthand for
328.Sy ":self invites set allow" .
329.It Sy ":self invites show"
330Show whether other users are currently allowed to send you invites.
324331.It Sy ":self name set [nickname]"
325332Set the display name for your profile.
326333.It Sy ":self name unset"
src/base.rs +3
@@ -459,6 +459,9 @@ impl Visitor<'_> for SortUserVisitor {
459459pub enum AccountField {
460460 /// The account's ignore list.
461461 Ignore,
462
463 /// Set whether other user's are allowed to invite the user to rooms.
464 Invites,
462465}
463466
464467/// A room property.
src/commands.rs +16
@@ -567,6 +567,22 @@ fn iamb_self(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
567567 },
568568 ("avatar", "unset", Some(_)) => return Result::Err(CommandError::InvalidArgument),
569569
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
570586 // :self name show
571587 ("name" | "nick", "show", None) => {
572588 HomeserverAction::ProfileFieldShow(ProfileFieldName::DisplayName).into()
src/main.rs +63
@@ -27,6 +27,10 @@ use clap::{CommandFactory, Parser};
2727use matrix_sdk::OwnedServerName;
2828use matrix_sdk::ruma::api::error::ErrorKind;
2929use matrix_sdk::ruma::events::ignored_user_list::IgnoredUserListEventContent;
30use matrix_sdk::ruma::events::invite_permission_config::{
31 InvitePermissionAction,
32 InvitePermissionConfigEventContent,
33};
3034use modalkit::actions::{Commandable, TabAction, TabContainer, TabCount, WindowContainer};
3135use modalkit::crossterm;
3236use modalkit::crossterm::cursor::SetCursorStyle;
@@ -692,6 +696,65 @@ impl Application {
692696
693697 Ok(vec![(action.into(), ctx)])
694698 },
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 },
695758 HomeserverAction::AccountSet(AccountField::Ignore, user) => {
696759 let Ok(user) = OwnedUserId::from_str(&user) else {
697760 return Err(IambError::InvalidUserId(user).into());
src/windows/room/mod.rs +4
@@ -983,6 +983,10 @@ impl TerminalCursor for RoomState {
983983
984984impl WindowOps<IambInfo> for RoomState {
985985 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
986990 if self.room_state() != Some(MatrixRoomState::Joined) {
987991 self.refresh_room(store);
988992 }