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 mozilla#80)
  • Loading branch information
vincentfretin committed Feb 12, 2022
1 parent 22926cf commit 4e45968
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 @@ -541,8 +541,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 @@ -557,9 +559,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 4e45968

Please sign in to comment.