Skip to content

Commit

Permalink
Now that get_publisher is optimized, use it instead of iterating over…
Browse files Browse the repository at this point in the history
… publishers in the room to send the blocked/unblocked event (closes #80)
  • Loading branch information
vincentfretin committed Jul 10, 2021
1 parent f16c42c commit c310e03
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,10 @@ fn process_block(from: &Arc<Session>, 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 {
Expand All @@ -550,9 +552,9 @@ fn process_unblock(from: &Arc<Session>, 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."))
Expand Down

0 comments on commit c310e03

Please sign in to comment.