Log all decisions when applying ephemeral timer to chats

This should make it easier to debug problems related to timer
rollbacks and reported failure to disable the timer in some chats.
This commit is contained in:
link2xt
2021-09-07 21:13:05 +00:00
parent bffb41326c
commit b1af486e10

View File

@@ -856,18 +856,42 @@ async fn add_parts(
// Apply ephemeral timer changes to the chat. // Apply ephemeral timer changes to the chat.
// //
// Only non-hidden timers are applied now. Timers from hidden // Only non-hidden timers are applied. Timers from hidden
// messages such as read receipts can be useful to detect // messages such as read receipts can be useful to detect
// ephemeral timer support, but timer changes without visible // ephemeral timer support, but timer changes without visible
// received messages may be confusing to the user. // received messages may be confusing to the user.
if !*hidden if !*hidden
&& !location_kml_is && !location_kml_is
&& !is_mdn && !is_mdn
&& (is_dc_message != MessengerMessage::Yes
|| parent.is_none()
|| parent.unwrap().ephemeral_timer != ephemeral_timer)
&& chat_id.get_ephemeral_timer(context).await? != ephemeral_timer && chat_id.get_ephemeral_timer(context).await? != ephemeral_timer
&& chat_id {
info!(
context,
"received new ephemeral timer value {:?} for chat {}, checking if it should be applied",
ephemeral_timer,
chat_id
);
if is_dc_message == MessengerMessage::Yes
&& mime_parser
.parts
.get(0)
.and_then(|part| part.param.get(Param::Quote))
.is_none()
&& parent.map(|p| p.ephemeral_timer) == Some(ephemeral_timer)
{
// The message is a Delta Chat message without a quote, so it must be a reply to the
// last message in the chat as seen by the sender. The timer is the same in both the
// received message and its parent, so we know that the sender has not seen any change
// of the timer between these messages. As our timer value is different, it means the
// sender has not received some timer update that we have seen or sent ourselves, so we
// ignore incoming timer to prevent a rollback.
warn!(
context,
"ignoring ephemeral timer change to {:?} for chat {} to avoid rollback",
ephemeral_timer,
chat_id
);
} else if chat_id
.update_timestamp(context, Param::EphemeralSettingsTimestamp, *sent_timestamp) .update_timestamp(context, Param::EphemeralSettingsTimestamp, *sent_timestamp)
.await? .await?
{ {
@@ -879,7 +903,12 @@ async fn add_parts(
context, context,
"failed to modify timer for chat {}: {}", chat_id, err "failed to modify timer for chat {}: {}", chat_id, err
); );
} else if mime_parser.is_system_message != SystemMessage::EphemeralTimerChanged { } else {
info!(
context,
"updated ephemeral timer to {:?} for chat {}", ephemeral_timer, chat_id
);
if mime_parser.is_system_message != SystemMessage::EphemeralTimerChanged {
chat::add_info_msg( chat::add_info_msg(
context, context,
chat_id, chat_id,
@@ -889,6 +918,13 @@ async fn add_parts(
.await; .await;
} }
} }
} else {
warn!(
context,
"ignoring ephemeral timer change to {:?} because it's outdated", ephemeral_timer
);
}
}
if mime_parser.is_system_message == SystemMessage::EphemeralTimerChanged { if mime_parser.is_system_message == SystemMessage::EphemeralTimerChanged {
set_better_msg( set_better_msg(