delete and reset device-messages on import; this avoids wrong information in the device chat and allows adding correct information again

This commit is contained in:
B. Petersen
2019-12-22 01:52:36 +01:00
committed by holger krekel
parent ce15ef2db9
commit 521a854635
2 changed files with 19 additions and 0 deletions

View File

@@ -2197,6 +2197,22 @@ pub fn was_device_msg_ever_added(context: &Context, label: &str) -> Result<bool,
Ok(false)
}
// needed on device-switches during export/import;
// - deletion in `msgs` with `DC_CONTACT_ID_DEVICE` makes sure,
// no wrong information are shown in the device chat
// - deletion in `devmsglabels` makes sure,
// deleted messages are resetted and useful messages can be added again
pub fn delete_and_reset_all_device_msgs(context: &Context) -> Result<(), Error> {
context.sql.execute(
"DELETE FROM msgs WHERE from_id=?;",
params![DC_CONTACT_ID_DEVICE],
)?;
context
.sql
.execute("DELETE FROM devmsglabels;", params![])?;
Ok(())
}
/// Adds an informational message to chat.
///
/// For example, it can be a message showing that a member was added to a group.

View File

@@ -8,6 +8,7 @@ use rand::{thread_rng, Rng};
use crate::blob::BlobObject;
use crate::chat;
use crate::chat::delete_and_reset_all_device_msgs;
use crate::config::Config;
use crate::configure::*;
use crate::constants::*;
@@ -441,6 +442,8 @@ fn import_backup(context: &Context, backup_to_import: impl AsRef<Path>) -> Resul
"could not re-open db"
);
delete_and_reset_all_device_msgs(&context)?;
let total_files_cnt = context
.sql
.query_get_value::<_, isize>(context, "SELECT COUNT(*) FROM backup_blobs;", params![])