Add types related to room listing API

This commit is contained in:
Alejandro Domínguez 2019-01-14 11:10:33 +01:00
parent ce6582d623
commit 32ff088156

View file

@ -141,6 +141,21 @@ impl Room {
} }
} }
impl From<PublicRoomsChunk> for Room {
fn from(input: PublicRoomsChunk) -> Self {
let mut room = Self::new(input.room_id, RoomMembership::None);
room.alias = input.canonical_alias;
room.name = input.name;
room.avatar = input.avatar_url;
room.topic = input.topic;
room.n_members = input.num_joined_members;
room.world_readable = input.world_readable;
room.guest_can_join = input.guest_can_join;
room
}
}
impl PartialEq for Room { impl PartialEq for Room {
fn eq(&self, other: &Room) -> bool { fn eq(&self, other: &Room) -> bool {
self.id == other.id self.id == other.id
@ -148,3 +163,24 @@ impl PartialEq for Room {
} }
pub type RoomList = HashMap<String, Room>; pub type RoomList = HashMap<String, Room>;
#[derive(Clone, Debug, Deserialize)]
pub struct PublicRoomsResponse {
pub chunk: Vec<PublicRoomsChunk>,
pub next_batch: Option<String>,
pub prev_batch: Option<String>,
pub total_room_count_estimate: Option<u64>,
}
#[derive(Clone, Debug, Deserialize)]
pub struct PublicRoomsChunk {
pub aliases: Option<Vec<String>>,
pub avatar_url: Option<String>,
pub canonical_alias: Option<String>,
pub guest_can_join: bool,
pub name: Option<String>,
pub num_joined_members: i32,
pub room_id: String,
pub topic: Option<String>,
pub world_readable: bool,
}