Browse Source

Add comments to room module, rename RoomKind to Visibility.

wip
Titouan Rigoudy 9 years ago
parent
commit
dd95fd80bc
3 changed files with 60 additions and 12 deletions
  1. +17
    -10
      src/client.rs
  2. +14
    -2
      src/room.rs
  3. +29
    -0
      src/user.rs

+ 17
- 10
src/client.rs View File

@ -28,6 +28,7 @@ pub struct Client {
control_tx: mpsc::Sender<control::Response>,
control_rx: mpsc::Receiver<control::Request>,
controller_connected: bool,
login_status: LoginStatus,
@ -46,8 +47,10 @@ impl Client {
Client {
proto_tx: proto_tx,
proto_rx: proto_rx,
control_tx: control_tx,
control_rx: control_rx,
controller_connected: false,
login_status: LoginStatus::Pending,
@ -100,11 +103,15 @@ impl Client {
fn handle_control_request(&mut self, request: control::Request) {
match request {
control::Request::ConnectNotification =>
info!("Controller client connected"),
control::Request::ConnectNotification => {
info!("Controller client connected");
self.controller_connected = true;
},
control::Request::DisconnectNotification =>
info!("Controller client disconnected"),
control::Request::DisconnectNotification => {
info!("Controller client disconnected");
self.controller_connected = false;
},
control::Request::LoginStatusRequest =>
self.handle_login_status_request(),
@ -218,30 +225,30 @@ impl Client {
{
self.rooms.clear();
for (name, user_count) in response.rooms.drain(..) {
self.rooms.insert(name, room::Room{
kind: room::RoomKind::Public,
self.rooms.insert(name, room::Room {
visibility: room::Visibility::Public,
operated: false,
user_count: user_count as usize,
});
}
for (name, user_count) in response.owned_private_rooms.drain(..) {
let room = room::Room {
kind: room::RoomKind::PrivateOwned,
visibility: room::Visibility::PrivateOwned,
operated: false,
user_count: user_count as usize,
};
if let Some(_) = self.rooms.insert(name, room) {
error!("Room is both normal and owned_private");
error!("Room is both public and owned_private");
}
}
for (name, user_count) in response.other_private_rooms.drain(..) {
let room = room::Room {
kind: room::RoomKind::PrivateOther,
visibility: room::Visibility::PrivateOther,
operated: false,
user_count: user_count as usize,
};
if let Some(_) = self.rooms.insert(name, room) {
error!("Room is both normal and other_private");
error!("Room is both public and other_private");
}
}
for name in response.operated_private_room_names.drain(..) {


+ 14
- 2
src/room.rs View File

@ -1,13 +1,25 @@
/// This enumeration is the list of visibility types for rooms that the user is
/// a member of.
#[derive(Clone, Copy, Debug, RustcDecodable, RustcEncodable)]
pub enum RoomKind {
pub enum Visibility {
/// This room is visible to any user.
Public,
/// This room is visible only to members, and the user owns it.
PrivateOwned,
/// This room is visible only to members, and someone else owns it.
PrivateOther,
}
/// This structure contains the last known information about a chat room.
/// It does not store the name, as that is stored implicitly as the key in the
/// room hash table.
#[derive(Clone, Copy, Debug, RustcDecodable, RustcEncodable)]
pub struct Room {
pub kind: RoomKind,
/// The visibility of the room.
pub visibility: Visibility,
/// True if the user is one of the room's operators, False if the user is a
/// regular member.
pub operated: bool,
/// The number of users that are members of the room.
pub user_count: usize,
}

+ 29
- 0
src/user.rs View File

@ -0,0 +1,29 @@
/// This enumeration is the list of possible user statuses.
#[derive(Clone, Copy, Debug)]
pub enum Status {
/// The user if offline.
Offline = 1,
/// The user is connected, but AFK.
Away = 2,
/// The user is present.
Online = 3,
}
/// This structure contains the last known information about a fellow user.
/// It does not store the name, as that is stored implicitly as the key in the
/// user hash table.
#[derive(Clone, Copy, Debug)]
pub struct User {
/// The last known status of the user.
pub status: Status,
/// The average upload speed of the user.
pub average_speed: usize,
/// ???
pub num_downloads: usize,
/// The number of files this user shares.
pub num_files: usize,
/// The number of folders this user shares.
pub num_folders: usize,
/// True if the user has free download slots, False if the user doesn't.
pub has_free_slots: bool,
}

Loading…
Cancel
Save