mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
Add autodelete timer to the database
This commit is contained in:
31
src/chat.rs
31
src/chat.rs
@@ -663,6 +663,7 @@ impl Chat {
|
|||||||
profile_image: self.get_profile_image(context).unwrap_or_else(PathBuf::new),
|
profile_image: self.get_profile_image(context).unwrap_or_else(PathBuf::new),
|
||||||
draft,
|
draft,
|
||||||
is_muted: self.is_muted(),
|
is_muted: self.is_muted(),
|
||||||
|
autodelete_timer: get_autodelete_timer(context, self.id),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1022,6 +1023,8 @@ pub struct ChatInfo {
|
|||||||
// - [ ] lastUpdated,
|
// - [ ] lastUpdated,
|
||||||
// - [ ] freshMessageCounter,
|
// - [ ] freshMessageCounter,
|
||||||
// - [ ] email
|
// - [ ] email
|
||||||
|
/// Automatic message deletion timer.
|
||||||
|
pub autodelete_timer: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a chat from a message ID.
|
/// Create a chat from a message ID.
|
||||||
@@ -2567,6 +2570,31 @@ pub(crate) fn add_info_msg(context: &Context, chat_id: ChatId, text: impl AsRef<
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get autodelete timer value in seconds.
|
||||||
|
pub fn get_autodelete_timer(context: &Context, chat_id: ChatId) -> u32 {
|
||||||
|
context
|
||||||
|
.sql
|
||||||
|
.query_get_value(
|
||||||
|
context,
|
||||||
|
"SELECT autodelete_timer FROM chats WHERE id=?;",
|
||||||
|
params![chat_id],
|
||||||
|
)
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set autodelete timer value in seconds.
|
||||||
|
///
|
||||||
|
/// If timer value is 0, disable autodelete timer.
|
||||||
|
pub fn set_autodelete_timer(context: &Context, chat_id: ChatId, timer: u32) -> Result<(), Error> {
|
||||||
|
context.sql.execute(
|
||||||
|
"UPDATE chats
|
||||||
|
SET autodelete_timer=?
|
||||||
|
WHERE id=?;",
|
||||||
|
params![timer, chat_id],
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -2597,7 +2625,8 @@ mod tests {
|
|||||||
"color": 15895624,
|
"color": 15895624,
|
||||||
"profile_image": "",
|
"profile_image": "",
|
||||||
"draft": "",
|
"draft": "",
|
||||||
"is_muted": false
|
"is_muted": false,
|
||||||
|
"autodelete_timer": 0
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
|
|||||||
@@ -902,6 +902,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 chats ADD COLUMN autodelete_timer 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)
|
||||||
|
|||||||
Reference in New Issue
Block a user