Browse Source

room: Remove (accept/decline)_invite methods

They are only used by the Invite view, other places do the same thing
with set_category.
fractal-9
Kévin Commaille 2 years ago committed by Kévin Commaille
parent
commit
b0356547ef
  1. 41
      src/session/model/room/mod.rs
  2. 5
      src/session/view/content/invite.rs

41
src/session/model/room/mod.rs

@ -2089,47 +2089,6 @@ impl Room {
}
}
/// Accept the invitation to this room.
pub async fn accept_invite(&self) -> MatrixResult<()> {
let matrix_room = self.matrix_room();
if matrix_room.state() != RoomState::Invited {
error!("Can’t accept invite, because this room isn’t an invited room");
return Ok(());
}
let matrix_room = matrix_room.clone();
let handle = spawn_tokio!(async move { matrix_room.join().await });
match handle.await.expect("task was not aborted") {
Ok(_) => Ok(()),
Err(error) => {
error!("Accepting invitation failed: {error}");
Err(error)
}
}
}
/// Decline the invitation to this room.
pub async fn decline_invite(&self) -> MatrixResult<()> {
let matrix_room = self.matrix_room();
if matrix_room.state() != RoomState::Invited {
error!("Cannot decline invite, because this room is not an invited room");
return Ok(());
}
let matrix_room = matrix_room.clone();
let handle = spawn_tokio!(async move { matrix_room.leave().await });
match handle.await.expect("task was not aborted") {
Ok(_) => Ok(()),
Err(error) => {
error!("Declining invitation failed: {error}");
Err(error)
}
}
}
/// Forget a room that is left.
pub async fn forget(&self) -> MatrixResult<()> {
if self.category() != RoomCategory::Left {

5
src/session/view/content/invite.rs

@ -239,8 +239,7 @@ impl Invite {
imp.accept_button.set_is_loading(true);
imp.accept_requests.borrow_mut().insert(room.clone());
let result = room.accept_invite().await;
if result.is_err() {
if room.set_category(RoomCategory::Normal).await.is_err() {
toast!(
self,
gettext(
@ -274,7 +273,7 @@ impl Invite {
let ignored_inviter = response.ignore_inviter.then(|| room.inviter()).flatten();
let closed = match room.decline_invite().await {
let closed = match room.set_category(RoomCategory::Left).await {
Ok(_) => {
// A room where we were invited is usually empty so just close it.
let _ = self.activate_action("session.close-room", None);

Loading…
Cancel
Save