diff --git a/src/chat.rs b/src/chat.rs index 405772c2f..23f800fdd 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -415,7 +415,6 @@ impl ChatId { promote: bool, from_id: ContactId, ) -> Result<()> { - let msg_text = context.stock_protection_msg(protect, from_id).await; let cmd = match protect { ProtectionStatus::Protected => SystemMessage::ChatProtectionEnabled, ProtectionStatus::Unprotected => SystemMessage::ChatProtectionDisabled, @@ -424,7 +423,11 @@ impl ChatId { if promote { let mut msg = Message { viewtype: Viewtype::Text, - text: Some(msg_text), + text: Some( + context + .stock_protection_msg(protect, ByContact::SelfName) + .await, + ), ..Default::default() }; msg.param.set_cmd(cmd); @@ -433,7 +436,9 @@ impl ChatId { add_info_msg_with_cmd( context, self, - &msg_text, + &context + .stock_protection_msg(protect, ByContact::YouOrName(from_id)) + .await, cmd, create_smeared_timestamp(context).await, None, diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 2a6b4cbf0..fb0f41476 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1005,7 +1005,11 @@ async fn add_parts( // do not return an error as this would result in retrying the message } } - better_msg = Some(context.stock_protection_msg(new_status, from_id).await); + better_msg = Some( + context + .stock_protection_msg(new_status, ByContact::YouOrName(from_id)) + .await, + ); } } } diff --git a/src/stock_str.rs b/src/stock_str.rs index bea880ada..47c0830ba 100644 --- a/src/stock_str.rs +++ b/src/stock_str.rs @@ -1098,24 +1098,38 @@ pub(crate) async fn error_no_network(context: &Context) -> String { } /// Stock string: `Chat protection enabled.`. -pub(crate) async fn protection_enabled(context: &Context, by_contact: ContactId) -> String { - if by_contact == ContactId::SELF { - translated(context, StockMessage::YouEnabledProtection).await - } else { - translated(context, StockMessage::ProtectionEnabledBy) +pub(crate) async fn protection_enabled(context: &Context, by_contact: ByContact) -> String { + match by_contact { + ByContact::YouOrName(by_contact) => { + if by_contact == ContactId::SELF { + translated(context, StockMessage::YouEnabledProtection).await + } else { + translated(context, StockMessage::ProtectionEnabledBy) + .await + .replace1(by_contact.get_stock_name(context).await) + } + } + ByContact::SelfName => translated(context, StockMessage::ProtectionEnabledBy) .await - .replace1(by_contact.get_stock_name(context).await) + .replace1(context.get_config_self_name().await), } } /// Stock string: `Chat protection disabled.`. -pub(crate) async fn protection_disabled(context: &Context, by_contact: ContactId) -> String { - if by_contact == ContactId::SELF { - translated(context, StockMessage::YouDisabledProtection).await - } else { - translated(context, StockMessage::ProtectionDisabledBy) +pub(crate) async fn protection_disabled(context: &Context, by_contact: ByContact) -> String { + match by_contact { + ByContact::YouOrName(by_contact) => { + if by_contact == ContactId::SELF { + translated(context, StockMessage::YouDisabledProtection).await + } else { + translated(context, StockMessage::ProtectionDisabledBy) + .await + .replace1(by_contact.get_stock_name(context).await) + } + } + ByContact::SelfName => translated(context, StockMessage::ProtectionDisabledBy) .await - .replace1(by_contact.get_stock_name(context).await) + .replace1(context.get_config_self_name().await), } } @@ -1392,7 +1406,7 @@ impl Context { pub(crate) async fn stock_protection_msg( &self, protect: ProtectionStatus, - from_id: ContactId, + from_id: ByContact, ) -> String { match protect { ProtectionStatus::Unprotected => protection_enabled(self, from_id).await,