Browse Source

Handle UserJoinedRoomResponse correctly.

wip
Titouan Rigoudy 9 years ago
parent
commit
c232855047
4 changed files with 29 additions and 15 deletions
  1. +17
    -3
      src/client.rs
  2. +6
    -6
      src/proto/server/response.rs
  3. +4
    -4
      src/room.rs
  4. +2
    -2
      src/user.rs

+ 17
- 3
src/client.rs View File

@ -232,6 +232,9 @@ impl Client {
ServerResponse::RoomListResponse(response) => ServerResponse::RoomListResponse(response) =>
self.handle_room_list_response(response), self.handle_room_list_response(response),
ServerResponse::UserJoinedRoomResponse(response) =>
self.handle_user_joined_room_response(response),
ServerResponse::UnknownResponse(code) => ServerResponse::UnknownResponse(code) =>
warn!("Unknown response: code {}", code), warn!("Unknown response: code {}", code),
@ -266,9 +269,11 @@ impl Client {
room.membership = room::Membership::Member; room.membership = room::Membership::Member;
room.user_count = response.users.len(); room.user_count = response.users.len();
room.owner = response.owner; room.owner = response.owner;
room.operators = response.operators;
for &(ref name, _) in response.users.iter() {
room.members.push(name.clone());
for user_name in response.operators.drain(..) {
room.operators.insert(user_name.clone());
}
for &(ref user_name, _) in response.users.iter() {
room.members.insert(user_name.clone());
} }
// Then update the user structs based on the info we just got. // Then update the user structs based on the info we just got.
@ -322,4 +327,13 @@ impl Client {
{ {
self.users.update_privileges(response); self.users.update_privileges(response);
} }
fn handle_user_joined_room_response(
&mut self, mut response: UserJoinedRoomResponse)
{
if let Some(room) = self.rooms.get_mut(&response.room_name) {
room.members.insert(response.user_name.clone());
self.users.insert(response.user_name, response.user);
}
}
} }

+ 6
- 6
src/proto/server/response.rs View File

@ -170,7 +170,7 @@ impl FromPacket for JoinRoomResponse {
num_files: 0, num_files: 0,
num_folders: 0, num_folders: 0,
num_free_slots: 0, num_free_slots: 0,
country: None,
country: String::new(),
}; };
Ok((name, user)) Ok((name, user))
}); });
@ -226,7 +226,7 @@ impl JoinRoomResponse {
let num_countries_res: result::Result<usize> = let num_countries_res: result::Result<usize> =
packet.read_array_with(|packet, i| { packet.read_array_with(|packet, i| {
if let Some(&mut (_, ref mut user)) = self.users.get_mut(i) { if let Some(&mut (_, ref mut user)) = self.users.get_mut(i) {
user.country = Some(try!(packet.read_str()));
user.country = try!(packet.read_str());
} }
Ok(()) Ok(())
}); });
@ -454,9 +454,9 @@ impl RoomListResponse {
#[derive(Debug)] #[derive(Debug)]
pub struct UserJoinedRoomResponse { pub struct UserJoinedRoomResponse {
room_name: String,
user_name: String,
user: user::User,
pub room_name: String,
pub user_name: String,
pub user: user::User,
} }
impl FromPacket for UserJoinedRoomResponse { impl FromPacket for UserJoinedRoomResponse {
@ -487,7 +487,7 @@ impl FromPacket for UserJoinedRoomResponse {
num_files: num_files, num_files: num_files,
num_folders: num_folders, num_folders: num_folders,
num_free_slots: num_free_slots, num_free_slots: num_free_slots,
country: Some(country),
country: country,
} }
}) })
} }


+ 4
- 4
src/room.rs View File

@ -48,9 +48,9 @@ pub struct Room {
/// The name of the room's owner, if any. /// The name of the room's owner, if any.
pub owner: Option<String>, pub owner: Option<String>,
/// The names of the room's operators. /// The names of the room's operators.
pub operators: Vec<String>,
pub operators: collections::HashSet<String>,
/// The names of the room's members. /// The names of the room's members.
pub members: Vec<String>,
pub members: collections::HashSet<String>,
} }
impl Room { impl Room {
@ -62,8 +62,8 @@ impl Room {
operated: false, operated: false,
user_count: user_count, user_count: user_count,
owner: None, owner: None,
operators: Vec::new(),
members: Vec::new(),
operators: collections::HashSet::new(),
members: collections::HashSet::new(),
} }
} }


+ 2
- 2
src/user.rs View File

@ -56,8 +56,8 @@ pub struct User {
pub num_folders: usize, pub num_folders: usize,
/// The number of free download slots of this user. /// The number of free download slots of this user.
pub num_free_slots: usize, pub num_free_slots: usize,
/// The user's country code. If unknown, set to None.
pub country: Option<String>,
/// The user's country code.
pub country: String,
} }
/// Contains the mapping from user names to user data and provides a clean /// Contains the mapping from user names to user data and provides a clean


Loading…
Cancel
Save