mirror of
https://github.com/chatmail/core.git
synced 2026-04-25 01:16:29 +03:00
use ByContact enum also for protection stock strings
This commit is contained in:
11
src/chat.rs
11
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,
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user