mirror of
https://github.com/chatmail/core.git
synced 2026-05-06 06:46:35 +03:00
Send system message to chat when user changes autodelete timer
This commit is contained in:
36
src/chat.rs
36
src/chat.rs
@@ -2582,10 +2582,15 @@ pub fn get_autodelete_timer(context: &Context, chat_id: ChatId) -> u32 {
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set autodelete timer value in seconds.
|
/// Set autodelete timer value without sending a message.
|
||||||
///
|
///
|
||||||
/// If timer value is 0, disable autodelete timer.
|
/// Used when a message arrives indicating that someone else has
|
||||||
pub fn set_autodelete_timer(context: &Context, chat_id: ChatId, timer: u32) -> Result<(), Error> {
|
/// changed the timer value for a chat.
|
||||||
|
pub(crate) fn inner_set_autodelete_timer(
|
||||||
|
context: &Context,
|
||||||
|
chat_id: ChatId,
|
||||||
|
timer: u32,
|
||||||
|
) -> Result<(), Error> {
|
||||||
context.sql.execute(
|
context.sql.execute(
|
||||||
"UPDATE chats
|
"UPDATE chats
|
||||||
SET autodelete_timer=?
|
SET autodelete_timer=?
|
||||||
@@ -2595,6 +2600,31 @@ pub fn set_autodelete_timer(context: &Context, chat_id: ChatId, timer: u32) -> R
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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> {
|
||||||
|
if timer == get_autodelete_timer(context, chat_id) {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
inner_set_autodelete_timer(context, chat_id, timer)?;
|
||||||
|
let mut msg = Message::new(Viewtype::Text);
|
||||||
|
msg.text = Some(context.stock_system_msg(
|
||||||
|
StockMessage::MsgAutodeleteTimerChanged,
|
||||||
|
timer.to_string(),
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
));
|
||||||
|
msg.param.set_cmd(SystemMessage::AutodeleteTimerChanged);
|
||||||
|
if let Err(err) = send_msg(context, chat_id, &mut msg) {
|
||||||
|
warn!(
|
||||||
|
context,
|
||||||
|
"Failed to send a message about autodelete timer change: {:?}", err
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ pub fn dc_receive_imf(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if chat::get_autodelete_timer(context, chat_id) != timer {
|
if chat::get_autodelete_timer(context, chat_id) != timer {
|
||||||
match chat::set_autodelete_timer(context, chat_id, timer) {
|
match chat::inner_set_autodelete_timer(context, chat_id, timer) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
let stock_str = context.stock_system_msg(
|
let stock_str = context.stock_system_msg(
|
||||||
StockMessage::MsgAutodeleteTimerChanged,
|
StockMessage::MsgAutodeleteTimerChanged,
|
||||||
|
|||||||
Reference in New Issue
Block a user