From 7f3f27ee508fbdc8a4dec3ca96bde4b0d219da03 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Mon, 16 Dec 2024 13:36:12 +0000 Subject: [PATCH] Remove any long running video calls that failed to be marked as ended --- .../impl/src/lifecycle/post_upgrade.rs | 8 +++++++- .../group/impl/src/lifecycle/post_upgrade.rs | 7 +++++-- .../libraries/chat_events/src/chat_events.rs | 18 ++++++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/backend/canisters/community/impl/src/lifecycle/post_upgrade.rs b/backend/canisters/community/impl/src/lifecycle/post_upgrade.rs index 0778503cb5..347a55a3b6 100644 --- a/backend/canisters/community/impl/src/lifecycle/post_upgrade.rs +++ b/backend/canisters/community/impl/src/lifecycle/post_upgrade.rs @@ -9,6 +9,7 @@ use ic_cdk::post_upgrade; use instruction_counts_log::InstructionCountFunctionId; use stable_memory::get_reader; use tracing::info; +use utils::env::Environment; #[post_upgrade] #[trace] @@ -23,9 +24,14 @@ fn post_upgrade(args: Args) { data.events.fix_role_changed_events(); + let env = init_env(data.rng_seed); + let now = env.now(); + for channel in data.channels.iter_mut() { + channel.chat.events.remove_spurious_video_call_in_progress(now); + } + canister_logger::init_with_logs(data.test_mode, errors, logs, traces); - let env = init_env(data.rng_seed); init_state(env, data, args.wasm_version); let completed_imports = read_state(|state| state.data.groups_being_imported.completed_imports()); diff --git a/backend/canisters/group/impl/src/lifecycle/post_upgrade.rs b/backend/canisters/group/impl/src/lifecycle/post_upgrade.rs index 348dca8f7a..c9f033ecfc 100644 --- a/backend/canisters/group/impl/src/lifecycle/post_upgrade.rs +++ b/backend/canisters/group/impl/src/lifecycle/post_upgrade.rs @@ -8,6 +8,7 @@ use ic_cdk::post_upgrade; use instruction_counts_log::InstructionCountFunctionId; use stable_memory::get_reader; use tracing::info; +use utils::env::Environment; #[post_upgrade] #[trace] @@ -17,12 +18,14 @@ fn post_upgrade(args: Args) { let memory = get_upgrades_memory(); let reader = get_reader(&memory); - let (data, errors, logs, traces): (Data, Vec, Vec, Vec) = + let (mut data, errors, logs, traces): (Data, Vec, Vec, Vec) = msgpack::deserialize(reader).unwrap(); + let env = init_env(data.rng_seed); + data.chat.events.remove_spurious_video_call_in_progress(env.now()); + canister_logger::init_with_logs(data.test_mode, errors, logs, traces); - let env = init_env(data.rng_seed); init_state(env, data, args.wasm_version); info!(version = %args.wasm_version, "Post-upgrade complete"); diff --git a/backend/libraries/chat_events/src/chat_events.rs b/backend/libraries/chat_events/src/chat_events.rs index 0700927230..3d959dda22 100644 --- a/backend/libraries/chat_events/src/chat_events.rs +++ b/backend/libraries/chat_events/src/chat_events.rs @@ -54,8 +54,22 @@ impl ChatEvents { // 3. More than 2 hours have passed since the call was started // THEN remove the video call in progress indicator - if self.video_call_is_spurious(now) { - self.video_call_in_progress = Timestamped::new(None, now); + let video_call_in_progress = self.video_call_in_progress.value.as_ref().map(|vc| vc.message_index); + + if let Some(message_index) = video_call_in_progress { + if self.video_call_is_spurious(now) { + self.video_call_in_progress = Timestamped::new(None, now); + + let _ = self.update_message(None, message_index.into(), EventIndex::default(), Some(now), |m, _| { + if let MessageContentInternal::VideoCall(vc) = &mut m.content { + if vc.ended.is_none() { + vc.ended = Some(now); + return Ok(()); + } + } + Err(UpdateEventError::NoChange(())) + }); + } } }