matrix-rust-sdk/matrix_sdk/src/room/left.rs

55 lines
1.4 KiB
Rust
Raw Normal View History

2021-03-05 13:55:06 +00:00
use std::ops::Deref;
use matrix_sdk_common::api::r0::membership::forget_room;
use crate::{room::Common, BaseRoom, Client, Result, RoomType};
2021-03-05 13:55:06 +00:00
/// A room in the left state.
///
/// This struct contains all methodes specific to a `Room` with type `RoomType::Left`.
/// Operations may fail once the underlaying `Room` changes `RoomType`.
#[derive(Debug, Clone)]
pub struct Left {
pub(crate) inner: Common,
2021-03-05 13:55:06 +00:00
}
impl Left {
/// Create a new `room::Left` if the underlaying `Room` has type `RoomType::Left`.
///
/// # Arguments
/// * `client` - The client used to make requests.
///
/// * `room` - The underlaying room.
pub fn new(client: Client, room: BaseRoom) -> Option<Self> {
// TODO: Make this private
2021-03-05 13:55:06 +00:00
if room.room_type() == RoomType::Left {
Some(Self { inner: Common::new(client, room) })
2021-03-05 13:55:06 +00:00
} else {
None
}
}
/// Join this room.
pub async fn join(&self) -> Result<()> {
self.inner.join().await
}
/// Forget this room.
///
/// This communicates to the homeserver that it should forget the room.
pub async fn forget(&self) -> Result<()> {
let request = forget_room::Request::new(self.inner.room_id());
let _response = self.client.send(request, None).await?;
Ok(())
}
2021-03-05 13:55:06 +00:00
}
impl Deref for Left {
type Target = Common;
fn deref(&self) -> &Self::Target {
&self.inner
}
}