From 47f4f2bd08f0da4e27b6e6a9a45221c4af18b869 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sun, 4 Oct 2020 18:29:36 +0200 Subject: [PATCH] use language of receiver for protection-messages, show correct sender --- src/chat.rs | 29 +++++++++++++++++++++-------- src/dc_receive_imf.rs | 18 +++++++++++++++++- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 57696bb76..3c6a9647a 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -226,14 +226,14 @@ impl ChatId { Ok(()) } - // adds or sends out a protection-info-message - pub(crate) async fn add_protection_msg( + /// returns a stock message saying that protection status gas changed. + pub(crate) async fn get_protection_msg( self, context: &Context, protect: ProtectionStatus, - promote: bool, - ) -> Result<(), Error> { - let msg_text = context + from_id: u32, + ) -> String { + context .stock_system_msg( match protect { ProtectionStatus::Protected => StockMessage::ProtectionEnabled, @@ -241,9 +241,20 @@ impl ChatId { }, "", "", - DC_CONTACT_ID_SELF as u32, + from_id, ) - .await; + .await + } + + /// adds or sends out a protection-info-message + pub(crate) async fn add_protection_msg( + self, + context: &Context, + protect: ProtectionStatus, + promote: bool, + from_id: u32, + ) -> Result<(), Error> { + let msg_text = self.get_protection_msg(context, protect, from_id).await; if promote { let mut msg = Message::default(); @@ -261,6 +272,7 @@ impl ChatId { Ok(()) } + /// Set protection and sends or adds a message. pub async fn set_protection( self, context: &Context, @@ -275,7 +287,8 @@ impl ChatId { return Err(e); } - self.add_protection_msg(context, protect, chat.is_promoted()).await + self.add_protection_msg(context, protect, chat.is_promoted(), DC_CONTACT_ID_SELF) + .await } /// Archives or unarchives a chat. diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 6e1ff2071..ce3228e15 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -712,6 +712,20 @@ async fn add_parts( // hour, only the message about the change to 1 // week is left. ephemeral_timer = EphemeralTimer::Disabled; + } else if mime_parser.is_system_message == SystemMessage::ChatProtectionEnabled { + set_better_msg( + mime_parser, + chat_id + .get_protection_msg(context, ProtectionStatus::Protected, from_id) + .await, + ); + } else if mime_parser.is_system_message == SystemMessage::ChatProtectionDisabled { + set_better_msg( + mime_parser, + chat_id + .get_protection_msg(context, ProtectionStatus::Unprotected, from_id) + .await, + ); } // change chat protection @@ -1240,7 +1254,9 @@ async fn create_or_lookup_group( recreate_member_list = true; if create_protected == ProtectionStatus::Protected { - chat_id.add_protection_msg(context, ProtectionStatus::Protected, false).await?; + chat_id + .add_protection_msg(context, ProtectionStatus::Protected, false, from_id) + .await?; } }