From 2c41b3f3e0daabcf404600e241094f13c4e732ce Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sat, 8 Aug 2020 04:32:12 +0300 Subject: [PATCH] Always translate EphemeralTimerChanged message An EphemeralTimerChanged message with the same timer as already set can be received when there are large delays or lost messages. Even though inner_set_ephemeral_timer should not be called in this case, because it emits an event indicating timer change, system message will be added to the chat, so it should be translated with set_better_msg in any case. --- src/dc_receive_imf.rs | 57 ++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 7d0100a23..77a9e3623 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -663,42 +663,39 @@ async fn add_parts( && !is_mdn && (*chat_id).get_ephemeral_timer(context).await? != ephemeral_timer { - match (*chat_id) + if let Err(err) = (*chat_id) .inner_set_ephemeral_timer(context, ephemeral_timer) .await { - Ok(()) => { - if mime_parser.is_system_message == SystemMessage::EphemeralTimerChanged { - set_better_msg( - mime_parser, - stock_ephemeral_timer_changed(context, ephemeral_timer, from_id).await, - ); - - // Do not delete the system message itself. - // - // This prevents confusion when timer is changed - // to 1 week, and then changed to 1 hour: after 1 - // hour, only the message about the change to 1 - // week is left. - ephemeral_timer = EphemeralTimer::Disabled; - } else { - chat::add_info_msg( - context, - *chat_id, - stock_ephemeral_timer_changed(context, ephemeral_timer, from_id).await, - ) - .await; - } - } - Err(err) => { - warn!( - context, - "failed to modify timer for chat {}: {}", chat_id, err - ); - } + warn!( + context, + "failed to modify timer for chat {}: {}", chat_id, err + ); + } else if mime_parser.is_system_message != SystemMessage::EphemeralTimerChanged { + chat::add_info_msg( + context, + *chat_id, + stock_ephemeral_timer_changed(context, ephemeral_timer, from_id).await, + ) + .await; } } + if mime_parser.is_system_message == SystemMessage::EphemeralTimerChanged { + set_better_msg( + mime_parser, + stock_ephemeral_timer_changed(context, ephemeral_timer, from_id).await, + ); + + // Do not delete the system message itself. + // + // This prevents confusion when timer is changed + // to 1 week, and then changed to 1 hour: after 1 + // hour, only the message about the change to 1 + // week is left. + ephemeral_timer = EphemeralTimer::Disabled; + } + // correct message_timestamp, it should not be used before, // however, we cannot do this earlier as we need from_id to be set let in_fresh = state == MessageState::InFresh;