less duplicate code on calling inner_set_protection()

This commit is contained in:
B. Petersen
2020-10-13 14:04:38 +02:00
parent 50f3af58f8
commit 7f882a6406

View File

@@ -715,25 +715,15 @@ async fn add_parts(
}
// change chat protection
if mime_parser.is_system_message == SystemMessage::ChatProtectionEnabled {
chat_id
.inner_set_protection(context, ProtectionStatus::Protected)
.await?;
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?;
set_better_msg(
mime_parser,
context
.stock_protection_msg(ProtectionStatus::Protected, from_id)
.await,
);
} else if mime_parser.is_system_message == SystemMessage::ChatProtectionDisabled {
chat_id
.inner_set_protection(context, ProtectionStatus::Unprotected)
.await?;
set_better_msg(
mime_parser,
context
.stock_protection_msg(ProtectionStatus::Unprotected, from_id)
.await,
context.stock_protection_msg(new_status, from_id).await,
);
}