From 01015fa1e3e63805bc5c506fd8968fa1ed1d5e68 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 7 Mar 2021 19:36:48 +0100 Subject: [PATCH] Close call when user is removed from a conversation --- src/controllers/calls_controller.rs | 15 +++++++++++++++ src/controllers/conversations_controller.rs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/controllers/calls_controller.rs b/src/controllers/calls_controller.rs index c67828c..b1b062a 100644 --- a/src/controllers/calls_controller.rs +++ b/src/controllers/calls_controller.rs @@ -447,6 +447,21 @@ pub fn handle_event(e: &events_helper::Event) -> Res { })?; } + // Call active call of user (if any) + Event::RemovedUserFromConversation(user_id, conv_id) => { + let mut conn = None; + user_ws_controller::foreach_connection(|f| { + if f.user_id() == user_id && f.is_having_call_with_conversation(conv_id) { + conn = Some(f.clone()); + } + Ok(()) + })?; + + if let Some(c) = conn { + make_user_leave_call(conv_id, &c)?; + } + } + _ => {} } diff --git a/src/controllers/conversations_controller.rs b/src/controllers/conversations_controller.rs index 4fd22d6..5af9f36 100644 --- a/src/controllers/conversations_controller.rs +++ b/src/controllers/conversations_controller.rs @@ -517,7 +517,7 @@ pub fn handle_event(e: &events_helper::Event) -> Res { None:: _>, )?; - // Disconnected users + // Disconnect users from conversation user_ws_controller::foreach_connection(|f| { if f.user_id() == user_id && f.conversations.contains(conv_id) { f.clone().replace(|w| {