Do not store NULL values in msgs.autodelete_* columns

This commit is contained in:
Alexander Krotov
2020-05-16 22:56:47 +03:00
parent f017ffa0b3
commit cdc15ce980
3 changed files with 14 additions and 12 deletions

View File

@@ -883,8 +883,12 @@ impl Chat {
}
// get autodelete timer
let autodelete_timer = Some(get_autodelete_timer(context, self.id)).filter(|&x| x != 0);
let autodelete_timestamp = autodelete_timer.map(|x| timestamp + i64::from(x));
let autodelete_timer = get_autodelete_timer(context, self.id);
let autodelete_timestamp = if autodelete_timer == 0 {
0
} else {
timestamp + i64::from(autodelete_timer)
};
// add message to the database

View File

@@ -247,8 +247,8 @@ pub struct Message {
pub(crate) timestamp_sort: i64,
pub(crate) timestamp_sent: i64,
pub(crate) timestamp_rcvd: i64,
pub(crate) autodelete_timer: Option<i64>,
pub(crate) autodelete_timestamp: Option<i64>,
pub(crate) autodelete_timer: i64,
pub(crate) autodelete_timestamp: i64,
pub(crate) text: Option<String>,
pub(crate) rfc724_mid: String,
pub(crate) in_reply_to: Option<String>,
@@ -871,16 +871,14 @@ pub fn get_msg_info(context: &Context, msg_id: MsgId) -> String {
ret += "\n";
}
if let Some(autodelete_timer) = msg.autodelete_timer {
if autodelete_timer != 0 {
ret += &format!("Autodelete timer: {}\n", autodelete_timer);
}
if msg.autodelete_timer != 0 {
ret += &format!("Autodelete timer: {}\n", msg.autodelete_timer);
}
if let Some(autodelete_timestamp) = msg.autodelete_timestamp {
if msg.autodelete_timestamp != 0 {
ret += &format!(
"Expires: {}\n",
dc_timestamp_to_str(autodelete_timestamp)
dc_timestamp_to_str(msg.autodelete_timestamp)
);
}

View File

@@ -916,7 +916,7 @@ fn open(
// timer starts when message is read, so we want to have
// the value stored here until the timer starts.
sql.execute(
"ALTER TABLE msgs ADD COLUMN autodelete_timer INTEGER;",
"ALTER TABLE msgs ADD COLUMN autodelete_timer INTEGER DEFAULT 0;",
NO_PARAMS,
)?;
// Timestamp indicating when the message should be
@@ -924,7 +924,7 @@ fn open(
// needs this value to display how much time is left until
// the message is deleted.
sql.execute(
"ALTER TABLE msgs ADD COLUMN autodelete_timestamp INTEGER;",
"ALTER TABLE msgs ADD COLUMN autodelete_timestamp INTEGER DEFAULT 0;",
NO_PARAMS,
)?;
sql.set_raw_config_int(context, "dbversion", 65)?;