Do not remove rfc724_mid for unlinked messages

Message-ID is used to send read receipts. Instead, add a separate
"unlinked" column.
This commit is contained in:
Alexander Krotov
2020-02-24 20:26:55 +03:00
parent a653e469f2
commit b2f1d9f376
2 changed files with 15 additions and 5 deletions

View File

@@ -119,8 +119,7 @@ impl MsgId {
.ok(); .ok();
} }
/// Removes Message-ID, IMAP server UID, folder from the database /// Removes IMAP server UID and folder from the database record.
/// record.
/// ///
/// It is used to avoid trying to remove the message from the /// It is used to avoid trying to remove the message from the
/// server multiple times when there are multiple message records /// server multiple times when there are multiple message records
@@ -130,7 +129,7 @@ impl MsgId {
context, context,
&context.sql, &context.sql,
"UPDATE msgs \ "UPDATE msgs \
SET rfc724_mid='', server_folder='', server_uid=0 \ SET unlinked=1, server_folder='', server_uid=0 \
WHERE id=?", WHERE id=?",
params![self], params![self],
) )
@@ -1373,10 +1372,12 @@ pub fn get_deaddrop_msg_cnt(context: &Context) -> usize {
/// Counts number of database records pointing to specified /// Counts number of database records pointing to specified
/// Message-ID. /// Message-ID.
///
/// Unlinked messages are excluded.
pub fn rfc724_mid_cnt(context: &Context, rfc724_mid: &str) -> i32 { pub fn rfc724_mid_cnt(context: &Context, rfc724_mid: &str) -> i32 {
// check the number of messages with the same rfc724_mid // check the number of messages with the same rfc724_mid
match context.sql.query_row( match context.sql.query_row(
"SELECT COUNT(*) FROM msgs WHERE rfc724_mid=?;", "SELECT COUNT(*) FROM msgs WHERE rfc724_mid=? AND NOT unlinked",
&[rfc724_mid], &[rfc724_mid],
|row| row.get(0), |row| row.get(0),
) { ) {
@@ -1417,7 +1418,8 @@ pub fn update_server_uid(
server_uid: u32, server_uid: u32,
) { ) {
match context.sql.execute( match context.sql.execute(
"UPDATE msgs SET server_folder=?, server_uid=? WHERE rfc724_mid=?;", "UPDATE msgs SET server_folder=?, server_uid=? \
WHERE rfc724_mid=? AND NOT unlinked",
params![server_folder.as_ref(), server_uid, rfc724_mid], params![server_folder.as_ref(), server_uid, rfc724_mid],
) { ) {
Ok(_) => {} Ok(_) => {}

View File

@@ -898,6 +898,14 @@ fn open(
sql.execute("UPDATE chats SET grpid='' WHERE type=100", NO_PARAMS)?; sql.execute("UPDATE chats SET grpid='' WHERE type=100", NO_PARAMS)?;
sql.set_raw_config_int(context, "dbversion", 63)?; sql.set_raw_config_int(context, "dbversion", 63)?;
} }
if dbversion < 64 {
info!(context, "[migration] v64");
sql.execute(
"ALTER TABLE msgs ADD COLUMN unlinked INTEGER DEFAULT 0",
NO_PARAMS,
)?;
sql.set_raw_config_int(context, "dbversion", 64)?;
}
// (2) updates that require high-level objects // (2) updates that require high-level objects
// (the structure is complete now and all objects are usable) // (the structure is complete now and all objects are usable)