From b45c3ce562471ec2827be38cf24d1e96d89333ad Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Sat, 10 Jul 2021 11:50:35 +0200 Subject: [PATCH] Now that get_publisher is optimized, use it instead of iterating over publishers in the room to send the blocked/unblocked event (closes #80) --- src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b0d4000..86b9207 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -541,8 +541,10 @@ fn process_block(from: &Arc, whom: UserId) -> MessageResult { janus_info!("Processing block from {:p} to {}", from.handle, whom); if let Some(joined) = from.join_state.get() { let mut switchboard = SWITCHBOARD.write()?; - let event = json!({ "event": "blocked", "by": &joined.user_id }); - notify_user(&event, &whom, switchboard.publishers_occupying(&joined.room_id)); + if let Some(publisher) = switchboard.get_publisher(&whom) { + let event = json!({ "event": "blocked", "by": &joined.user_id }); + notify_user(&event, &whom, &[publisher]); + } switchboard.establish_block(joined.user_id.clone(), whom); Ok(MessageResponse::msg(json!({}))) } else { @@ -557,9 +559,9 @@ fn process_unblock(from: &Arc, whom: UserId) -> MessageResult { switchboard.lift_block(&joined.user_id, &whom); if let Some(publisher) = switchboard.get_publisher(&whom) { send_fir(&[publisher]); + let event = json!({ "event": "unblocked", "by": &joined.user_id }); + notify_user(&event, &whom, &[publisher]); } - let event = json!({ "event": "unblocked", "by": &joined.user_id }); - notify_user(&event, &whom, switchboard.publishers_occupying(&joined.room_id)); Ok(MessageResponse::msg(json!({}))) } else { Err(From::from("Cannot unblock when not in a room."))