diff --git a/src/calls.rs b/src/calls.rs index b8f6ec18d..30f9e7b1c 100644 --- a/src/calls.rs +++ b/src/calls.rs @@ -196,8 +196,10 @@ impl Context { ..Default::default() }; - // Set a placeholder parameter so the message is recognized as a call - // This will be used by mimefactory until the DB entry is available + // Set a placeholder parameter so the message is recognized as a call during sending. + // This ensures mimefactory can read the SDP during the brief window between + // send_msg() starting and the calls table entry being available. + // The param will be removed after send_msg() completes. call.param.set(Param::WebrtcRoom, &place_call_info); call.id = send_msg(self, chat_id, &mut call).await?; @@ -521,7 +523,9 @@ impl Context { return Ok(None); } - // Load SDP from calls table + // Load SDP from calls table. Returns empty strings if no record exists, + // which can happen for old messages from before the migration or for + // calls where SDPs have been cleaned up by housekeeping. let (place_call_info, accept_call_info) = self .sql .query_row_optional( diff --git a/src/sql.rs b/src/sql.rs index e3956941a..f5d2a8cb4 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -921,12 +921,13 @@ pub async fn housekeeping(context: &Context) -> Result<()> { .log_err(context) .ok(); - // Delete call SDPs for ended calls (older than 24 hours) or orphaned calls. + // Delete call SDPs for ended calls (older than 24 hours) or trashed calls. // We clean up calls that ended more than 24 hours ago to protect privacy // as SDPs contain IP addresses. Ended calls are identified by having - // the CALL_ENDED_TIMESTAMP parameter (Param::Arg4) set. - // The ON DELETE CASCADE foreign key will handle orphaned entries automatically, - // but we also check for trash and old ended calls. + // the CALL_ENDED_TIMESTAMP parameter (Param::Arg4='H') set. + // The pattern '%H=%' matches this parameter since params are stored as + // newline-separated key=value pairs (e.g., "E=123\nH=456\n"). + // The ON DELETE CASCADE foreign key handles orphaned entries automatically. context .sql .execute(