|
|
|
@ -10,14 +10,17 @@ use crate::room::RoomError; |
|
|
|
#[derive(Debug, Default)]
|
|
|
|
pub struct RoomJoinRequestHandler;
|
|
|
|
|
|
|
|
fn start_joining(context: &Context, room_name: &str) -> Result<(), RoomError> {
|
|
|
|
let mut guard = context.state.lock();
|
|
|
|
let result = guard.rooms.start_joining(room_name);
|
|
|
|
fn start_joining(
|
|
|
|
context: &mut Context,
|
|
|
|
room_name: &str,
|
|
|
|
) -> Result<(), RoomError> {
|
|
|
|
let result = context.state.rooms.start_joining(room_name);
|
|
|
|
|
|
|
|
if let Err(RoomError::MembershipChangeInvalid(_, _)) = result {
|
|
|
|
// This `expect()` should never fail since the error was not
|
|
|
|
// `RoomNotFound` but `MembershipChangeInvalid`.
|
|
|
|
let room = guard
|
|
|
|
let room = context
|
|
|
|
.state
|
|
|
|
.rooms
|
|
|
|
.get_strict(room_name)
|
|
|
|
.expect("querying room state");
|
|
|
|
@ -44,7 +47,7 @@ impl MessageHandler for RoomJoinRequestHandler { |
|
|
|
|
|
|
|
fn run(
|
|
|
|
self,
|
|
|
|
context: &Context,
|
|
|
|
context: &mut Context,
|
|
|
|
room_name: &Self::Message,
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
start_joining(context, room_name).context("joining room")?;
|
|
|
|
@ -80,11 +83,11 @@ mod tests { |
|
|
|
let mut bundle = ContextBundle::default();
|
|
|
|
|
|
|
|
RoomJoinRequestHandler::default()
|
|
|
|
.run(&bundle.context, &"bleep".to_string())
|
|
|
|
.run(&mut bundle.context, &"bleep".to_string())
|
|
|
|
.unwrap_err();
|
|
|
|
|
|
|
|
// Room state has not changed.
|
|
|
|
assert_eq!(bundle.context.state.lock().rooms.get_room_list(), vec![]);
|
|
|
|
assert_eq!(bundle.context.state.rooms.get_room_list(), vec![]);
|
|
|
|
|
|
|
|
// Close the channel, so we can observe it was empty without hanging.
|
|
|
|
drop(bundle.context.server_request_tx);
|
|
|
|
@ -106,12 +109,12 @@ mod tests { |
|
|
|
let mut bundle = ContextBundle::new(options);
|
|
|
|
|
|
|
|
RoomJoinRequestHandler::default()
|
|
|
|
.run(&bundle.context, &"bleep".to_string())
|
|
|
|
.run(&mut bundle.context, &"bleep".to_string())
|
|
|
|
.unwrap_err();
|
|
|
|
|
|
|
|
// Room state has not changed.
|
|
|
|
assert_eq!(
|
|
|
|
bundle.context.state.lock().rooms.get_room_list(),
|
|
|
|
bundle.context.state.rooms.get_room_list(),
|
|
|
|
vec![("bleep".to_string(), room.clone())]
|
|
|
|
);
|
|
|
|
|
|
|
|
@ -138,7 +141,7 @@ mod tests { |
|
|
|
let mut bundle = ContextBundle::new(options);
|
|
|
|
|
|
|
|
RoomJoinRequestHandler::default()
|
|
|
|
.run(&bundle.context, &"bleep".to_string())
|
|
|
|
.run(&mut bundle.context, &"bleep".to_string())
|
|
|
|
.context("running handler")?;
|
|
|
|
|
|
|
|
let request = bundle.server_request_rx.blocking_recv().unwrap();
|
|
|
|
@ -148,7 +151,6 @@ mod tests { |
|
|
|
bundle
|
|
|
|
.context
|
|
|
|
.state
|
|
|
|
.lock()
|
|
|
|
.rooms
|
|
|
|
.get_strict("bleep")
|
|
|
|
.context("getting room")?
|
|
|
|
|