Skip to content

Commit

Permalink
Remove any long running video calls that failed to be marked as ended
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Dec 16, 2024
1 parent 1c05c60 commit 7f3f27e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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());
Expand Down
7 changes: 5 additions & 2 deletions backend/canisters/group/impl/src/lifecycle/post_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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<LogEntry>, Vec<LogEntry>, Vec<LogEntry>) =
let (mut data, errors, logs, traces): (Data, Vec<LogEntry>, Vec<LogEntry>, Vec<LogEntry>) =
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");
Expand Down
18 changes: 16 additions & 2 deletions backend/libraries/chat_events/src/chat_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(()))
});
}
}
}

Expand Down

0 comments on commit 7f3f27e

Please sign in to comment.