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.
321Unset the avatar for your profile. 321Unset the avatar for your profile.
322.It Sy ":self avatar show" 322.It Sy ":self avatar show"
323Show the current avatar URL for your profile. 323Show 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.
324.It Sy ":self name set [nickname]" 331.It Sy ":self name set [nickname]"
325Set the display name for your profile. 332Set the display name for your profile.
326.It Sy ":self name unset" 333.It Sy ":self name unset"
src/base.rs +3
@@ -459,6 +459,9 @@ impl Visitor<'_> for SortUserVisitor {
459pub enum AccountField { 459pub enum AccountField {
460 /// The account's ignore list. 460 /// The account's ignore list.
461 Ignore, 461 Ignore,
462
463 /// Set whether other user's are allowed to invite the user to rooms.
464 Invites,
462} 465}
463 466
464/// A room property. 467/// A room property.
src/commands.rs +16
@@ -567,6 +567,22 @@ fn iamb_self(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
567 }, 567 },
568 ("avatar", "unset", Some(_)) => return Result::Err(CommandError::InvalidArgument), 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 // :self name show 586 // :self name show
571 ("name" | "nick", "show", None) => { 587 ("name" | "nick", "show", None) => {
572 HomeserverAction::ProfileFieldShow(ProfileFieldName::DisplayName).into() 588 HomeserverAction::ProfileFieldShow(ProfileFieldName::DisplayName).into()
src/main.rs +63
@@ -27,6 +27,10 @@ use clap::{CommandFactory, Parser};
27use matrix_sdk::OwnedServerName; 27use matrix_sdk::OwnedServerName;
28use matrix_sdk::ruma::api::error::ErrorKind; 28use matrix_sdk::ruma::api::error::ErrorKind;
29use matrix_sdk::ruma::events::ignored_user_list::IgnoredUserListEventContent; 29use matrix_sdk::ruma::events::ignored_user_list::IgnoredUserListEventContent;
30use matrix_sdk::ruma::events::invite_permission_config::{
31 InvitePermissionAction,
32 InvitePermissionConfigEventContent,
33};
30use modalkit::actions::{Commandable, TabAction, TabContainer, TabCount, WindowContainer}; 34use modalkit::actions::{Commandable, TabAction, TabContainer, TabCount, WindowContainer};
31use modalkit::crossterm; 35use modalkit::crossterm;
32use modalkit::crossterm::cursor::SetCursorStyle; 36use modalkit::crossterm::cursor::SetCursorStyle;
@@ -692,6 +696,65 @@ impl Application {
692 696
693 Ok(vec![(action.into(), ctx)]) 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 HomeserverAction::AccountSet(AccountField::Ignore, user) => { 758 HomeserverAction::AccountSet(AccountField::Ignore, user) => {
696 let Ok(user) = OwnedUserId::from_str(&user) else { 759 let Ok(user) = OwnedUserId::from_str(&user) else {
697 return Err(IambError::InvalidUserId(user).into()); 760 return Err(IambError::InvalidUserId(user).into());
src/windows/room/mod.rs +4
@@ -983,6 +983,10 @@ impl TerminalCursor for RoomState {
983 983
984impl WindowOps<IambInfo> for RoomState { 984impl WindowOps<IambInfo> for RoomState {
985 fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { 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 if self.room_state() != Some(MatrixRoomState::Joined) { 990 if self.room_state() != Some(MatrixRoomState::Joined) {
987 self.refresh_room(store); 991 self.refresh_room(store);
988 } 992 }