fix processing of protection-changed messages

by #2001, processing of protection-enabled and protection-disabled
messages is only done if verification-checks pass.

unfortunately, these verification checks
were only applied on already protected chats,
so that enabling via a protection-enabled message was not possible.

this is fixed by this pr.
moreover, when inner_set_protection() fails,
the error is shown in the chat.
This commit is contained in:
B. Petersen
2020-10-19 00:59:40 +02:00
committed by holger krekel
parent e15372531e
commit 9bf8799484

View File

@@ -717,7 +717,13 @@ async fn add_parts(
// if a chat is protected, check additional properties
if !chat_id.is_special() {
let chat = Chat::load_from_db(context, *chat_id).await?;
if chat.is_protected() {
let new_status = match mime_parser.is_system_message {
SystemMessage::ChatProtectionEnabled => Some(ProtectionStatus::Protected),
SystemMessage::ChatProtectionDisabled => Some(ProtectionStatus::Unprotected),
_ => None,
};
if chat.is_protected() || new_status.is_some() {
if let Err(err) =
check_verified_properties(context, mime_parser, from_id as u32, to_ids).await
{
@@ -726,12 +732,16 @@ async fn add_parts(
mime_parser.repl_msg_by_error(s);
} else {
// change chat protection only when verification check passes
if let Some(new_status) = match mime_parser.is_system_message {
SystemMessage::ChatProtectionEnabled => Some(ProtectionStatus::Protected),
SystemMessage::ChatProtectionDisabled => Some(ProtectionStatus::Unprotected),
_ => None,
} {
chat_id.inner_set_protection(context, new_status).await?;
if let Some(new_status) = new_status {
if let Err(e) = chat_id.inner_set_protection(context, new_status).await {
chat::add_info_msg(
context,
*chat_id,
format!("Cannot set protection: {}", e),
)
.await;
return Ok(()); // do not return an error as this would result in retrying the message
}
set_better_msg(
mime_parser,
context.stock_protection_msg(new_status, from_id).await,