diff --git a/src/sql/migrations.rs b/src/sql/migrations.rs index 28f952cce..a78ad0f2a 100644 --- a/src/sql/migrations.rs +++ b/src/sql/migrations.rs @@ -1651,7 +1651,7 @@ fn migrate_key_contacts( .collect::, _>>() .context("Step 26")?; - let mut keep_address_contacts = |reason: &str| { + let mut keep_address_contacts = |reason: &str| -> Result<()> { info!( context, "Chat {chat_id} will be an unencrypted chat with contacts identified by email address: {reason}." @@ -1659,6 +1659,15 @@ fn migrate_key_contacts( for (m, _) in &old_members { orphaned_contacts.remove(m); } + + // Unprotect this chat if it was protected. + // + // Otherwise we get protected chat with address-contact(s). + transaction + .execute("UPDATE chats SET protected=0 WHERE id=?", (chat_id,)) + .context("Step 26.0")?; + + Ok(()) }; let old_and_new_members: Vec<(u32, bool, Option)> = match typ { // 1:1 chats retain: @@ -1678,19 +1687,13 @@ fn migrate_key_contacts( }; let Some(new_contact) = map_to_key_contact(old_member) else { - keep_address_contacts("No peerstate, or peerstate in 'reset' state"); + keep_address_contacts("No peerstate, or peerstate in 'reset' state")?; continue; }; if !addr_cmp_stmt .query_row((old_member, new_contact), |row| row.get::<_, bool>(0))? { - // Unprotect this 1:1 chat if it was protected. - // - // Otherwise we get protected chat with address-contact. - transaction - .execute("UPDATE chats SET protected=0 WHERE id=?", (chat_id,))?; - - keep_address_contacts("key contact has different email"); + keep_address_contacts("key contact has different email")?; continue; } vec![(*old_member, true, Some(new_contact))] @@ -1701,7 +1704,7 @@ fn migrate_key_contacts( if grpid.is_empty() { // Ad-hoc group that has empty Chat-Group-ID // because it was created in response to receiving a non-chat email. - keep_address_contacts("Empty chat-Group-ID"); + keep_address_contacts("Empty chat-Group-ID")?; continue; } else if protected == 1 { old_members @@ -1720,7 +1723,7 @@ fn migrate_key_contacts( // Mailinglist 140 => { - keep_address_contacts("Mailinglist"); + keep_address_contacts("Mailinglist")?; continue; } @@ -1759,7 +1762,7 @@ fn migrate_key_contacts( transaction .execute("UPDATE chats SET grpid='' WHERE id=?", (chat_id,)) .context("Step 26.1")?; - keep_address_contacts("Group contains contact without peerstate"); + keep_address_contacts("Group contains contact without peerstate")?; continue; }