mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +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,
|
promote: bool,
|
||||||
from_id: ContactId,
|
from_id: ContactId,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let msg_text = context.stock_protection_msg(protect, from_id).await;
|
|
||||||
let cmd = match protect {
|
let cmd = match protect {
|
||||||
ProtectionStatus::Protected => SystemMessage::ChatProtectionEnabled,
|
ProtectionStatus::Protected => SystemMessage::ChatProtectionEnabled,
|
||||||
ProtectionStatus::Unprotected => SystemMessage::ChatProtectionDisabled,
|
ProtectionStatus::Unprotected => SystemMessage::ChatProtectionDisabled,
|
||||||
@@ -424,7 +423,11 @@ impl ChatId {
|
|||||||
if promote {
|
if promote {
|
||||||
let mut msg = Message {
|
let mut msg = Message {
|
||||||
viewtype: Viewtype::Text,
|
viewtype: Viewtype::Text,
|
||||||
text: Some(msg_text),
|
text: Some(
|
||||||
|
context
|
||||||
|
.stock_protection_msg(protect, ByContact::SelfName)
|
||||||
|
.await,
|
||||||
|
),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
msg.param.set_cmd(cmd);
|
msg.param.set_cmd(cmd);
|
||||||
@@ -433,7 +436,9 @@ impl ChatId {
|
|||||||
add_info_msg_with_cmd(
|
add_info_msg_with_cmd(
|
||||||
context,
|
context,
|
||||||
self,
|
self,
|
||||||
&msg_text,
|
&context
|
||||||
|
.stock_protection_msg(protect, ByContact::YouOrName(from_id))
|
||||||
|
.await,
|
||||||
cmd,
|
cmd,
|
||||||
create_smeared_timestamp(context).await,
|
create_smeared_timestamp(context).await,
|
||||||
None,
|
None,
|
||||||
|
|||||||
@@ -1005,7 +1005,11 @@ async fn add_parts(
|
|||||||
// do not return an error as this would result in retrying the message
|
// 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,7 +1098,9 @@ pub(crate) async fn error_no_network(context: &Context) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Stock string: `Chat protection enabled.`.
|
/// Stock string: `Chat protection enabled.`.
|
||||||
pub(crate) async fn protection_enabled(context: &Context, by_contact: ContactId) -> String {
|
pub(crate) async fn protection_enabled(context: &Context, by_contact: ByContact) -> String {
|
||||||
|
match by_contact {
|
||||||
|
ByContact::YouOrName(by_contact) => {
|
||||||
if by_contact == ContactId::SELF {
|
if by_contact == ContactId::SELF {
|
||||||
translated(context, StockMessage::YouEnabledProtection).await
|
translated(context, StockMessage::YouEnabledProtection).await
|
||||||
} else {
|
} else {
|
||||||
@@ -1106,10 +1108,17 @@ pub(crate) async fn protection_enabled(context: &Context, by_contact: ContactId)
|
|||||||
.await
|
.await
|
||||||
.replace1(by_contact.get_stock_name(context).await)
|
.replace1(by_contact.get_stock_name(context).await)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
ByContact::SelfName => translated(context, StockMessage::ProtectionEnabledBy)
|
||||||
|
.await
|
||||||
|
.replace1(context.get_config_self_name().await),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stock string: `Chat protection disabled.`.
|
/// Stock string: `Chat protection disabled.`.
|
||||||
pub(crate) async fn protection_disabled(context: &Context, by_contact: ContactId) -> String {
|
pub(crate) async fn protection_disabled(context: &Context, by_contact: ByContact) -> String {
|
||||||
|
match by_contact {
|
||||||
|
ByContact::YouOrName(by_contact) => {
|
||||||
if by_contact == ContactId::SELF {
|
if by_contact == ContactId::SELF {
|
||||||
translated(context, StockMessage::YouDisabledProtection).await
|
translated(context, StockMessage::YouDisabledProtection).await
|
||||||
} else {
|
} else {
|
||||||
@@ -1117,6 +1126,11 @@ pub(crate) async fn protection_disabled(context: &Context, by_contact: ContactId
|
|||||||
.await
|
.await
|
||||||
.replace1(by_contact.get_stock_name(context).await)
|
.replace1(by_contact.get_stock_name(context).await)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
ByContact::SelfName => translated(context, StockMessage::ProtectionDisabledBy)
|
||||||
|
.await
|
||||||
|
.replace1(context.get_config_self_name().await),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stock string: `Reply`.
|
/// Stock string: `Reply`.
|
||||||
@@ -1392,7 +1406,7 @@ impl Context {
|
|||||||
pub(crate) async fn stock_protection_msg(
|
pub(crate) async fn stock_protection_msg(
|
||||||
&self,
|
&self,
|
||||||
protect: ProtectionStatus,
|
protect: ProtectionStatus,
|
||||||
from_id: ContactId,
|
from_id: ByContact,
|
||||||
) -> String {
|
) -> String {
|
||||||
match protect {
|
match protect {
|
||||||
ProtectionStatus::Unprotected => protection_enabled(self, from_id).await,
|
ProtectionStatus::Unprotected => protection_enabled(self, from_id).await,
|
||||||
|
|||||||
Reference in New Issue
Block a user