mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-20 05:39:52 -07:00
Add ban/unban/kick room commands (#327)
This commit is contained in:
parent
2a66496913
commit
df3896df9c
4 changed files with 145 additions and 0 deletions
|
@ -22,6 +22,7 @@ use matrix_sdk::{
|
|||
},
|
||||
OwnedEventId,
|
||||
OwnedRoomAliasId,
|
||||
OwnedUserId,
|
||||
RoomId,
|
||||
},
|
||||
DisplayName,
|
||||
|
@ -56,6 +57,7 @@ use crate::base::{
|
|||
IambId,
|
||||
IambInfo,
|
||||
IambResult,
|
||||
MemberUpdateAction,
|
||||
MessageAction,
|
||||
ProgramAction,
|
||||
ProgramContext,
|
||||
|
@ -269,6 +271,47 @@ impl RoomState {
|
|||
Err(IambError::NotJoined.into())
|
||||
}
|
||||
},
|
||||
RoomAction::MemberUpdate(mua, user, reason, skip_confirm) => {
|
||||
let Some(room) = store.application.worker.client.get_room(self.id()) else {
|
||||
return Err(IambError::NotJoined.into());
|
||||
};
|
||||
|
||||
let Ok(user_id) = OwnedUserId::try_from(user.as_str()) else {
|
||||
let err = IambError::InvalidUserId(user);
|
||||
|
||||
return Err(err.into());
|
||||
};
|
||||
|
||||
if !skip_confirm {
|
||||
let msg = format!("Do you really want to {mua} {user} from this room?");
|
||||
let act = RoomAction::MemberUpdate(mua, user, reason, true);
|
||||
let act = IambAction::from(act);
|
||||
let prompt = PromptYesNo::new(msg, vec![Action::from(act)]);
|
||||
let prompt = Box::new(prompt);
|
||||
|
||||
return Err(UIError::NeedConfirm(prompt));
|
||||
}
|
||||
|
||||
match mua {
|
||||
MemberUpdateAction::Ban => {
|
||||
room.ban_user(&user_id, reason.as_deref())
|
||||
.await
|
||||
.map_err(IambError::from)?;
|
||||
},
|
||||
MemberUpdateAction::Unban => {
|
||||
room.unban_user(&user_id, reason.as_deref())
|
||||
.await
|
||||
.map_err(IambError::from)?;
|
||||
},
|
||||
MemberUpdateAction::Kick => {
|
||||
room.kick_user(&user_id, reason.as_deref())
|
||||
.await
|
||||
.map_err(IambError::from)?;
|
||||
},
|
||||
}
|
||||
|
||||
Ok(vec![])
|
||||
},
|
||||
RoomAction::Members(mut cmd) => {
|
||||
let width = Count::Exact(30);
|
||||
let act =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue