2021-03-17 11:08:01 +00:00
|
|
|
use crate::{room::Common, BaseRoom, Client, Result, RoomType};
|
2021-03-05 13:55:06 +00:00
|
|
|
use std::ops::Deref;
|
|
|
|
|
2021-03-08 23:12:59 +00:00
|
|
|
use matrix_sdk_common::api::r0::membership::forget_room;
|
|
|
|
|
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 {
|
|
|
|
inner: Common,
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2021-03-17 11:08:01 +00:00
|
|
|
pub fn new(client: Client, room: BaseRoom) -> Option<Self> {
|
2021-03-08 23:12:59 +00:00
|
|
|
// 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),
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
2021-03-08 23:12:59 +00:00
|
|
|
|
|
|
|
/// 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
|
|
|
|
}
|
|
|
|
}
|