|
|
@ -13,29 +13,21 @@ use crate::user::UserMap; |
|
|
use crate::Config;
|
|
|
use crate::Config;
|
|
|
|
|
|
|
|
|
/// Contains all the different bits of client state.
|
|
|
/// Contains all the different bits of client state.
|
|
|
#[derive(Debug)]
|
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
pub struct State {
|
|
|
pub struct State {
|
|
|
pub user_name: String,
|
|
|
|
|
|
pub rooms: RoomMap,
|
|
|
pub rooms: RoomMap,
|
|
|
pub users: UserMap,
|
|
|
pub users: UserMap,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl Default for State {
|
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
|
return State {
|
|
|
|
|
|
user_name: Config::default().credentials.user_name().to_string(),
|
|
|
|
|
|
rooms: RoomMap::default(),
|
|
|
|
|
|
users: UserMap::default(),
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Holds process-wide context for message handlers to execute against.
|
|
|
/// Holds process-wide context for message handlers to execute against.
|
|
|
#[derive(Debug)]
|
|
|
#[derive(Debug)]
|
|
|
pub struct Context {
|
|
|
pub struct Context {
|
|
|
/// Mutable state.
|
|
|
/// Mutable state.
|
|
|
pub state: State,
|
|
|
pub state: State,
|
|
|
|
|
|
|
|
|
|
|
|
/// The user name with which we logged in to the server.
|
|
|
|
|
|
pub user_name: String,
|
|
|
|
|
|
|
|
|
/// Sender half of a channel used to send requests to the server.
|
|
|
/// Sender half of a channel used to send requests to the server.
|
|
|
pub server_request_tx: Sender<ServerRequest>,
|
|
|
pub server_request_tx: Sender<ServerRequest>,
|
|
|
|
|
|
|
|
|
@ -65,6 +57,9 @@ pub struct ContextOptions { |
|
|
/// The state to start out with.
|
|
|
/// The state to start out with.
|
|
|
pub initial_state: State,
|
|
|
pub initial_state: State,
|
|
|
|
|
|
|
|
|
|
|
|
/// The user name with which we logged in to the server.
|
|
|
|
|
|
pub user_name: String,
|
|
|
|
|
|
|
|
|
/// The buffer size of the server request channel.
|
|
|
/// The buffer size of the server request channel.
|
|
|
pub server_request_buffer: usize,
|
|
|
pub server_request_buffer: usize,
|
|
|
|
|
|
|
|
|
@ -80,6 +75,7 @@ impl Default for ContextOptions { |
|
|
fn default() -> Self {
|
|
|
fn default() -> Self {
|
|
|
Self {
|
|
|
Self {
|
|
|
initial_state: State::default(),
|
|
|
initial_state: State::default(),
|
|
|
|
|
|
user_name: Config::default().credentials.user_name().to_string(),
|
|
|
server_request_buffer: 100,
|
|
|
server_request_buffer: 100,
|
|
|
control_response_buffer: 100,
|
|
|
control_response_buffer: 100,
|
|
|
#[cfg(test)]
|
|
|
#[cfg(test)]
|
|
|
@ -104,6 +100,7 @@ impl ContextBundle { |
|
|
Self {
|
|
|
Self {
|
|
|
context: Context {
|
|
|
context: Context {
|
|
|
state: options.initial_state,
|
|
|
state: options.initial_state,
|
|
|
|
|
|
user_name: options.user_name,
|
|
|
server_request_tx,
|
|
|
server_request_tx,
|
|
|
control_response_tx,
|
|
|
control_response_tx,
|
|
|
system_clock,
|
|
|
system_clock,
|
|
|
|