diff --git a/src/chat.rs b/src/chat.rs index 59bb3bf6a..aa9665755 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1940,9 +1940,17 @@ pub fn add_device_msg_once( ) -> Result { let (chat_id, _blocked) = create_or_lookup_by_contact_id(context, DC_CONTACT_ID_DEVICE, Blocked::Not)?; - let rfc724_mid = format!("{}@device", label); + let rfc724_mid = dc_create_outgoing_rfc724_mid(None, "@device"); - if let Ok((_, _, msg_id)) = message::rfc724_mid_exists(context, &rfc724_mid) { + // chat_id has an sql-index so it makes sense to add this although redundant + if let Ok(msg_id) = context.sql.query_row( + "SELECT id FROM msgs WHERE chat_id=? AND label=?", + params![chat_id, label], + |row| { + let msg_id: MsgId = row.get(0)?; + Ok(msg_id) + }, + ) { info!( context, "device-message {} already exist as {}", label, msg_id @@ -1954,8 +1962,8 @@ pub fn add_device_msg_once( unarchive(context, chat_id)?; context.sql.execute( - "INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,param,rfc724_mid) \ - VALUES (?,?,?, ?,?,?, ?,?,?);", + "INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,param,rfc724_mid,label) \ + VALUES (?,?,?, ?,?,?, ?,?,?,?);", params![ chat_id, DC_CONTACT_ID_DEVICE, @@ -1966,6 +1974,7 @@ pub fn add_device_msg_once( msg.text.as_ref().map_or("", String::as_str), msg.param.to_string(), rfc724_mid, + label, ], )?; diff --git a/src/imex.rs b/src/imex.rs index e7fe1d81c..004057996 100644 --- a/src/imex.rs +++ b/src/imex.rs @@ -160,6 +160,7 @@ fn do_initiate_key_transfer(context: &Context) -> Result { // it would be too much noise to have two things popping up at the same time. // maybe_add_bcc_self_device_msg() is called on the other device // once the transfer is completed. + maybe_add_bcc_self_device_msg(context)?; Ok(setup_code) } diff --git a/src/sql.rs b/src/sql.rs index bf989142c..b1f210277 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -806,12 +806,19 @@ fn open( )?; sql.set_raw_config_int(context, "dbversion", 55)?; } - if dbversion < 56 { - info!(context, "[migration] v56"); + if dbversion < 57 { + info!(context, "[migration] v57"); + // label is a unique name and is currently used for device-messages only. + // in contrast to rfc724_mid and other fields, the label is generated on the device + // and allows reliable identifications this way. + sql.execute( + "ALTER TABLE msgs ADD COLUMN label TEXT DEFAULT '';", + params![], + )?; if exists_before_update && sql.get_raw_config_int(context, "bcc_self").is_none() { sql.set_raw_config_int(context, "bcc_self", 1)?; } - sql.set_raw_config_int(context, "dbversion", 56)?; + sql.set_raw_config_int(context, "dbversion", 57)?; } // (2) updates that require high-level objects