Browse Source

Add SetRoomListHandler.

wip
Titouan Rigoudy 4 years ago
parent
commit
ca8f580406
3 changed files with 71 additions and 1 deletions
  1. +2
    -0
      client/src/handlers/mod.rs
  2. +68
    -0
      client/src/handlers/set_room_list_handler.rs
  3. +1
    -1
      client/src/room.rs

+ 2
- 0
client/src/handlers/mod.rs View File

@ -1,3 +1,5 @@
mod set_privileged_users_handler;
mod set_room_list_handler;
pub use set_privileged_users_handler::SetPrivilegedUsersHandler;
pub use set_room_list_handler::SetRoomListHandler;

+ 68
- 0
client/src/handlers/set_room_list_handler.rs View File

@ -0,0 +1,68 @@
use std::io;
use solstice_proto::server::RoomListResponse;
use crate::context::Context;
use crate::message_handler::MessageHandler;
#[derive(Debug, Default)]
pub struct SetRoomListHandler;
impl MessageHandler<RoomListResponse> for SetRoomListHandler {
fn run(
self,
context: &Context,
message: &RoomListResponse,
) -> io::Result<()> {
let response = (*message).clone();
context.state.lock().rooms.set_room_list(response);
Ok(())
}
fn name() -> String {
"SetRoomListHandler".to_string()
}
}
#[cfg(test)]
mod tests {
use solstice_proto::server::RoomListResponse;
use crate::context::ContextBundle;
use crate::message_handler::MessageHandler;
use crate::room::{Room, Visibility};
use super::SetRoomListHandler;
// Cannot get the compiler to be satisfied when borrowing the name...
fn room_name(pair: &(String, Room)) -> String {
pair.0.clone()
}
#[test]
fn run_sets_room_list() {
let bundle = ContextBundle::default();
let response = RoomListResponse {
rooms: vec![("potato".to_string(), 123), ("apple".to_string(), 42)],
owned_private_rooms: vec![],
other_private_rooms: vec![],
operated_private_room_names: vec![],
};
SetRoomListHandler::default()
.run(&bundle.context, &response)
.unwrap();
let mut rooms = bundle.context.state.lock().rooms.get_room_list();
rooms.sort_by_key(room_name);
assert_eq!(
rooms,
vec![
("apple".to_string(), Room::new(Visibility::Public, 42)),
("potato".to_string(), Room::new(Visibility::Public, 123)),
]
);
}
}

+ 1
- 1
client/src/room.rs View File

@ -67,7 +67,7 @@ pub struct Room {
impl Room {
/// Creates a new room with the given visibility and user count.
fn new(visibility: Visibility, user_count: usize) -> Self {
pub fn new(visibility: Visibility, user_count: usize) -> Self {
Room {
membership: Membership::NonMember,
visibility: visibility,


Loading…
Cancel
Save