Browse Source

Rename Visibility to RoomVisibility.

main
Titouan Rigoudy 2 years ago
parent
commit
15f279e6bc
8 changed files with 53 additions and 37 deletions
  1. +3
    -3
      client/src/control/response.rs
  2. +6
    -6
      client/src/handlers/room_join_request_handler.rs
  3. +2
    -2
      client/src/handlers/room_join_response_handler.rs
  4. +6
    -3
      client/src/handlers/room_list_request_handler.rs
  5. +6
    -3
      client/src/handlers/room_list_response_handler.rs
  6. +6
    -6
      client/src/handlers/room_message_response_handler.rs
  7. +21
    -11
      client/src/room/map.rs
  8. +3
    -3
      client/src/room/state.rs

+ 3
- 3
client/src/control/response.rs View File

@ -110,7 +110,7 @@ mod tests {
use solstice_proto::{User, UserStatus}; use solstice_proto::{User, UserStatus};
use crate::room::{ use crate::room::{
Message, MessageHistory, RoomMembership, RoomState, Visibility,
Message, MessageHistory, RoomMembership, RoomState, RoomVisibility,
}; };
use super::{ use super::{
@ -196,7 +196,7 @@ mod tests {
room_name: "bleep".to_string(), room_name: "bleep".to_string(),
room: RoomState { room: RoomState {
membership: RoomMembership::Joining, membership: RoomMembership::Joining,
visibility: Visibility::PrivateOwned,
visibility: RoomVisibility::PrivateOwned,
operated: false, operated: false,
user_count: 3, user_count: 3,
owner: None, owner: None,
@ -271,7 +271,7 @@ mod tests {
"bleep".to_string(), "bleep".to_string(),
RoomState { RoomState {
membership: RoomMembership::Joining, membership: RoomMembership::Joining,
visibility: Visibility::PrivateOwned,
visibility: RoomVisibility::PrivateOwned,
operated: false, operated: false,
user_count: 3, user_count: 3,
owner: None, owner: None,


+ 6
- 6
client/src/handlers/room_join_request_handler.rs View File

@ -75,7 +75,7 @@ mod tests {
use crate::context::{ContextBundle, ContextOptions}; use crate::context::{ContextBundle, ContextOptions};
use crate::control; use crate::control;
use crate::message_handler::MessageHandler; use crate::message_handler::MessageHandler;
use crate::room::{RoomMembership, RoomState, Visibility};
use crate::room::{RoomMembership, RoomState, RoomVisibility};
use super::RoomJoinRequestHandler; use super::RoomJoinRequestHandler;
@ -99,7 +99,7 @@ mod tests {
#[test] #[test]
fn run_already_joined_responds_immediately() -> anyhow::Result<()> { fn run_already_joined_responds_immediately() -> anyhow::Result<()> {
let mut room = RoomState::new(Visibility::Public, 3);
let mut room = RoomState::new(RoomVisibility::Public, 3);
room.membership = RoomMembership::Member; room.membership = RoomMembership::Member;
let mut options = ContextOptions::default(); let mut options = ContextOptions::default();
@ -135,10 +135,10 @@ mod tests {
#[test] #[test]
fn run_success() -> anyhow::Result<()> { fn run_success() -> anyhow::Result<()> {
let mut options = ContextOptions::default(); let mut options = ContextOptions::default();
options
.initial_state
.rooms
.insert("bleep".to_string(), RoomState::new(Visibility::Public, 3));
options.initial_state.rooms.insert(
"bleep".to_string(),
RoomState::new(RoomVisibility::Public, 3),
);
let mut bundle = ContextBundle::new(options); let mut bundle = ContextBundle::new(options);
RoomJoinRequestHandler::default() RoomJoinRequestHandler::default()


+ 2
- 2
client/src/handlers/room_join_response_handler.rs View File

@ -55,13 +55,13 @@ mod tests {
use crate::context::{ContextBundle, ContextOptions}; use crate::context::{ContextBundle, ContextOptions};
use crate::control; use crate::control;
use crate::message_handler::MessageHandler; use crate::message_handler::MessageHandler;
use crate::room::{RoomMembership, RoomState, Visibility};
use crate::room::{RoomMembership, RoomState, RoomVisibility};
use super::RoomJoinResponseHandler; use super::RoomJoinResponseHandler;
#[test] #[test]
fn run_updates_room_state_and_forwards_response() { fn run_updates_room_state_and_forwards_response() {
let mut room = RoomState::new(Visibility::Public, 42);
let mut room = RoomState::new(RoomVisibility::Public, 42);
let mut options = ContextOptions::default(); let mut options = ContextOptions::default();
options options


+ 6
- 3
client/src/handlers/room_list_request_handler.rs View File

@ -45,7 +45,7 @@ mod tests {
use crate::context::{ContextBundle, ContextOptions}; use crate::context::{ContextBundle, ContextOptions};
use crate::control; use crate::control;
use crate::message_handler::MessageHandler; use crate::message_handler::MessageHandler;
use crate::room::{RoomState, Visibility};
use crate::room::{RoomState, RoomVisibility};
use super::RoomListRequestHandler; use super::RoomListRequestHandler;
@ -97,10 +97,13 @@ mod tests {
assert_eq!( assert_eq!(
rooms, rooms,
vec![ vec![
("apple".to_string(), RoomState::new(Visibility::Public, 42)),
(
"apple".to_string(),
RoomState::new(RoomVisibility::Public, 42)
),
( (
"potato".to_string(), "potato".to_string(),
RoomState::new(Visibility::Public, 123)
RoomState::new(RoomVisibility::Public, 123)
), ),
] ]
); );


+ 6
- 3
client/src/handlers/room_list_response_handler.rs View File

@ -41,7 +41,7 @@ mod tests {
use crate::context::ContextBundle; use crate::context::ContextBundle;
use crate::message_handler::MessageHandler; use crate::message_handler::MessageHandler;
use crate::room::{RoomState, Visibility};
use crate::room::{RoomState, RoomVisibility};
use super::RoomListResponseHandler; use super::RoomListResponseHandler;
@ -71,10 +71,13 @@ mod tests {
assert_eq!( assert_eq!(
rooms, rooms,
vec![ vec![
("apple".to_string(), RoomState::new(Visibility::Public, 42)),
(
"apple".to_string(),
RoomState::new(RoomVisibility::Public, 42)
),
( (
"potato".to_string(), "potato".to_string(),
RoomState::new(Visibility::Public, 123)
RoomState::new(RoomVisibility::Public, 123)
), ),
] ]
); );


+ 6
- 6
client/src/handlers/room_message_response_handler.rs View File

@ -58,7 +58,7 @@ mod tests {
use crate::context::{ContextBundle, ContextOptions}; use crate::context::{ContextBundle, ContextOptions};
use crate::control; use crate::control;
use crate::message_handler::MessageHandler; use crate::message_handler::MessageHandler;
use crate::room::{Message, RoomState, Visibility};
use crate::room::{Message, RoomState, RoomVisibility};
use super::RoomMessageResponseHandler; use super::RoomMessageResponseHandler;
@ -69,10 +69,10 @@ mod tests {
#[test] #[test]
fn run_forwards_response() { fn run_forwards_response() {
let mut options = ContextOptions::default(); let mut options = ContextOptions::default();
options
.initial_state
.rooms
.insert("apple".to_string(), RoomState::new(Visibility::Public, 1));
options.initial_state.rooms.insert(
"apple".to_string(),
RoomState::new(RoomVisibility::Public, 1),
);
options.simulated_clock = options.simulated_clock =
Some(SimulatedSystemClock::new(system_time_from_secs(42))); Some(SimulatedSystemClock::new(system_time_from_secs(42)));
@ -109,7 +109,7 @@ mod tests {
#[test] #[test]
fn run_stores_message() { fn run_stores_message() {
let mut room = RoomState::new(Visibility::Public, 42);
let mut room = RoomState::new(RoomVisibility::Public, 42);
room.messages.insert(Message { room.messages.insert(Message {
received_at: system_time_from_secs(42), received_at: system_time_from_secs(42),
user_name: "karandeep".to_string(), user_name: "karandeep".to_string(),


+ 21
- 11
client/src/room/map.rs View File

@ -5,7 +5,7 @@ use log::{error, info, warn};
use solstice_proto::{server, User}; use solstice_proto::{server, User};
use thiserror::Error; use thiserror::Error;
use crate::room::{RoomMembership, RoomState, Visibility};
use crate::room::{RoomMembership, RoomState, RoomVisibility};
/// The error returned by RoomMap functions. /// The error returned by RoomMap functions.
#[derive(Debug, Error)] #[derive(Debug, Error)]
@ -70,12 +70,12 @@ impl RoomMap {
fn update_one( fn update_one(
&mut self, &mut self,
name: String, name: String,
visibility: Visibility,
visibility: RoomVisibility,
user_count: u32, user_count: u32,
old_map: &mut HashMap<String, RoomState>, old_map: &mut HashMap<String, RoomState>,
) { ) {
let room = match old_map.remove(&name) { let room = match old_map.remove(&name) {
None => RoomState::new(Visibility::Public, user_count as usize),
None => RoomState::new(RoomVisibility::Public, user_count as usize),
Some(mut room) => { Some(mut room) => {
room.visibility = visibility; room.visibility = visibility;
room.user_count = user_count as usize; room.user_count = user_count as usize;
@ -95,17 +95,27 @@ impl RoomMap {
// Add all public rooms. // Add all public rooms.
for (name, user_count) in response.rooms.drain(..) { for (name, user_count) in response.rooms.drain(..) {
self.update_one(name, Visibility::Public, user_count, &mut old_map);
self.update_one(name, RoomVisibility::Public, user_count, &mut old_map);
} }
// Add all private, owned, rooms. // Add all private, owned, rooms.
for (name, user_count) in response.owned_private_rooms.drain(..) { for (name, user_count) in response.owned_private_rooms.drain(..) {
self.update_one(name, Visibility::PrivateOwned, user_count, &mut old_map);
self.update_one(
name,
RoomVisibility::PrivateOwned,
user_count,
&mut old_map,
);
} }
// Add all private, unowned, rooms. // Add all private, unowned, rooms.
for (name, user_count) in response.other_private_rooms.drain(..) { for (name, user_count) in response.other_private_rooms.drain(..) {
self.update_one(name, Visibility::PrivateOther, user_count, &mut old_map);
self.update_one(
name,
RoomVisibility::PrivateOther,
user_count,
&mut old_map,
);
} }
// Mark all operated rooms as necessary. // Mark all operated rooms as necessary.
@ -268,7 +278,7 @@ mod tests {
use solstice_proto::server::RoomListResponse; use solstice_proto::server::RoomListResponse;
use crate::room::{ use crate::room::{
Message, MessageHistory, RoomMembership, RoomState, Visibility,
Message, MessageHistory, RoomMembership, RoomState, RoomVisibility,
}; };
use super::RoomMap; use super::RoomMap;
@ -284,8 +294,8 @@ mod tests {
#[test] #[test]
fn deserialize_visibility() { fn deserialize_visibility() {
assert_eq!( assert_eq!(
serde_json::from_str::<Visibility>(r#""Public""#).unwrap(),
Visibility::Public
serde_json::from_str::<RoomVisibility>(r#""Public""#).unwrap(),
RoomVisibility::Public
); );
} }
@ -340,7 +350,7 @@ mod tests {
.unwrap(), .unwrap(),
RoomState { RoomState {
membership: RoomMembership::Joining, membership: RoomMembership::Joining,
visibility: Visibility::PrivateOwned,
visibility: RoomVisibility::PrivateOwned,
operated: false, operated: false,
user_count: 3, user_count: 3,
owner: None, owner: None,
@ -389,7 +399,7 @@ mod tests {
assert_eq!( assert_eq!(
rooms.get_strict("room a").unwrap(), rooms.get_strict("room a").unwrap(),
&RoomState::new(Visibility::Public, 42)
&RoomState::new(RoomVisibility::Public, 42)
); );
} }
} }

+ 3
- 3
client/src/room/state.rs View File

@ -21,7 +21,7 @@ pub enum RoomMembership {
/// This enumeration is the list of visibility types for rooms that the user is /// This enumeration is the list of visibility types for rooms that the user is
/// a member of. /// a member of.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)] #[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum Visibility {
pub enum RoomVisibility {
/// This room is visible to any user. /// This room is visible to any user.
Public, Public,
/// This room is visible only to members, and the user owns it. /// This room is visible only to members, and the user owns it.
@ -110,7 +110,7 @@ pub struct RoomState {
/// The membership state of the user for the room. /// The membership state of the user for the room.
pub membership: RoomMembership, pub membership: RoomMembership,
/// The visibility of the room. /// The visibility of the room.
pub visibility: Visibility,
pub visibility: RoomVisibility,
/// True if the user is one of the room's operators, False if the user is a /// True if the user is one of the room's operators, False if the user is a
/// regular member. /// regular member.
pub operated: bool, pub operated: bool,
@ -130,7 +130,7 @@ pub struct RoomState {
impl RoomState { impl RoomState {
/// Creates a new room with the given visibility and user count. /// Creates a new room with the given visibility and user count.
pub fn new(visibility: Visibility, user_count: usize) -> Self {
pub fn new(visibility: RoomVisibility, user_count: usize) -> Self {
Self { Self {
membership: RoomMembership::NonMember, membership: RoomMembership::NonMember,
visibility: visibility, visibility: visibility,


Loading…
Cancel
Save