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

49 lines
1.2 KiB
Rust
Raw Normal View History

use crate::{room::Common, Client, Result, Room, RoomType};
2021-03-05 13:55:06 +00:00
use std::ops::Deref;
/// A room in the invited state.
///
/// This struct contains all methodes specific to a `Room` with type `RoomType::Invited`.
/// Operations may fail once the underlaying `Room` changes `RoomType`.
#[derive(Debug, Clone)]
pub struct Invited {
inner: Common,
}
impl Invited {
/// Create a new `room::Invited` if the underlaying `Room` has type `RoomType::Invited`.
///
/// # Arguments
/// * `client` - The client used to make requests.
///
/// * `room` - The underlaying room.
pub fn new(client: Client, room: Room) -> Option<Self> {
// TODO: Make this private
2021-03-05 13:55:06 +00:00
if room.room_type() == RoomType::Invited {
Some(Self {
inner: Common::new(client, room),
})
} else {
None
}
}
/// Reject the invitation.
pub async fn reject_invitation(&self) -> Result<()> {
self.inner.leave().await
}
/// Accept the invitation.
pub async fn accept_invitation(&self) -> Result<()> {
self.inner.join().await
}
2021-03-05 13:55:06 +00:00
}
impl Deref for Invited {
type Target = Common;
fn deref(&self) -> &Self::Target {
&self.inner
}
}