Bunch of feedback: renames, simple functions, no cow

This commit is contained in:
Floris Bruynooghe
2021-02-11 22:24:56 +01:00
parent 29f184b4c4
commit 46a3226e43
22 changed files with 1216 additions and 1814 deletions

View File

@@ -32,7 +32,7 @@ use deltachat::context::Context;
use deltachat::ephemeral::Timer as EphemeralTimer;
use deltachat::key::DcKey;
use deltachat::message::MsgId;
use deltachat::stock::StockMessage;
use deltachat::stock_str::StockMessage;
use deltachat::*;
mod dc_array;

View File

@@ -1,6 +1,5 @@
//! # Chat module
use std::borrow::Cow;
use std::convert::TryFrom;
use std::str::FromStr;
use std::time::{Duration, SystemTime};
@@ -39,11 +38,7 @@ use crate::mimeparser::SystemMessage;
use crate::param::{Param, Params};
use crate::peerstate::{Peerstate, PeerstateVerifiedStatus};
use crate::sql;
use crate::stock::{
ArchivedChats, DeadDrop, DeviceMessages, E2eAvailable, E2ePreferred, EncrNone, MsgAddMember,
MsgDelMember, MsgGroupLeft, MsgGrpImgChanged, MsgGrpImgDeleted, MsgGrpName, NewGroupDraft,
SavedMessages, SelfDeletedMsgBody, VideochatInviteMsgBody,
};
use crate::stock_str;
/// An chat item, such as a message or a marker.
#[derive(Debug, Copy, Clone)]
@@ -401,7 +396,7 @@ impl ChatId {
if chat.is_self_talk() {
let mut msg = Message::new(Viewtype::Text);
msg.text = Some(SelfDeletedMsgBody::stock_str(context).await.into());
msg.text = Some(stock_str::self_deleted_msg_body(context).await);
add_device_msg(&context, None, Some(&mut msg)).await?;
}
@@ -667,10 +662,10 @@ impl ChatId {
})
.map(|peerstate| peerstate.prefer_encrypt)
{
Some(EncryptPreference::Mutual) => E2ePreferred::stock_str(context).await,
Some(EncryptPreference::NoPreference) => E2eAvailable::stock_str(context).await,
Some(EncryptPreference::Reset) => EncrNone::stock_str(context).await,
None => EncrNone::stock_str(context).await,
Some(EncryptPreference::Mutual) => stock_str::e2e_preferred(context).await,
Some(EncryptPreference::NoPreference) => stock_str::e2e_available(context).await,
Some(EncryptPreference::Reset) => stock_str::encr_none(context).await,
None => stock_str::encr_none(context).await,
};
if !ret.is_empty() {
ret.push('\n')
@@ -793,9 +788,9 @@ impl Chat {
}
Ok(mut chat) => {
if chat.id.is_deaddrop() {
chat.name = DeadDrop::stock_str(context).await.into();
chat.name = stock_str::dead_drop(context).await;
} else if chat.id.is_archived_link() {
let tempname = ArchivedChats::stock_str(context).await;
let tempname = stock_str::archived_chats(context).await;
let cnt = dc_get_archived_cnt(context).await;
chat.name = format!("{} ({})", tempname, cnt);
} else {
@@ -810,9 +805,9 @@ impl Chat {
chat.name = chat_name;
}
if chat.param.exists(Param::Selftalk) {
chat.name = SavedMessages::stock_str(context).await.into();
chat.name = stock_str::saved_messages(context).await;
} else if chat.param.exists(Param::Devicetalk) {
chat.name = DeviceMessages::stock_str(context).await.into();
chat.name = stock_str::device_messages(context).await;
}
}
Ok(chat)
@@ -1411,10 +1406,9 @@ pub(crate) async fn update_device_icon(context: &Context) -> Result<(), Error> {
async fn update_special_chat_name(
context: &Context,
contact_id: u32,
name: Cow<'static, str>,
name: String,
) -> Result<(), Error> {
if let Ok((chat_id, _)) = lookup_by_contact_id(context, contact_id).await {
let name: String = name.into();
// the `!= name` condition avoids unneeded writes
context
.sql
@@ -1431,13 +1425,13 @@ pub(crate) async fn update_special_chat_names(context: &Context) -> Result<(), E
update_special_chat_name(
context,
DC_CONTACT_ID_DEVICE,
DeviceMessages::stock_str(context).await,
stock_str::device_messages(context).await,
)
.await?;
update_special_chat_name(
context,
DC_CONTACT_ID_SELF,
SavedMessages::stock_str(context).await,
stock_str::saved_messages(context).await,
)
.await?;
Ok(())
@@ -1822,9 +1816,8 @@ pub async fn send_videochat_invitation(context: &Context, chat_id: ChatId) -> Re
let mut msg = Message::new(Viewtype::VideochatInvitation);
msg.param.set(Param::WebrtcRoom, &instance);
msg.text = Some(
VideochatInviteMsgBody::stock_str(context, Message::parse_webrtc_instance(&instance).1)
.await
.to_string(),
stock_str::videochat_invite_msg_body(context, Message::parse_webrtc_instance(&instance).1)
.await,
);
send_msg(context, chat_id, &mut msg).await
}
@@ -2161,9 +2154,7 @@ pub async fn create_group_chat(
let chat_name = improve_single_line_input(chat_name);
ensure!(!chat_name.is_empty(), "Invalid chat name");
let draft_txt = NewGroupDraft::stock_str(context, &chat_name)
.await
.to_string();
let draft_txt = stock_str::new_group_draft(context, &chat_name).await;
let grpid = dc_create_id();
context.sql.execute(
@@ -2340,11 +2331,8 @@ pub(crate) async fn add_contact_to_chat_ex(
}
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
msg.viewtype = Viewtype::Text;
msg.text = Some(
MsgAddMember::stock_str(context, contact.get_addr(), DC_CONTACT_ID_SELF)
.await
.to_string(),
);
msg.text =
Some(stock_str::msg_add_member(context, contact.get_addr(), DC_CONTACT_ID_SELF).await);
msg.param.set_cmd(SystemMessage::MemberAddedToGroup);
msg.param.set(Param::Arg, contact.get_addr());
msg.param.set_int(Param::Arg2, from_handshake.into());
@@ -2538,20 +2526,16 @@ pub async fn remove_contact_from_chat(
msg.viewtype = Viewtype::Text;
if contact.id == DC_CONTACT_ID_SELF {
set_group_explicitly_left(context, chat.grpid).await?;
msg.text = Some(
MsgGroupLeft::stock_str(context, DC_CONTACT_ID_SELF)
.await
.to_string(),
);
msg.text =
Some(stock_str::msg_group_left(context, DC_CONTACT_ID_SELF).await);
} else {
msg.text = Some(
MsgDelMember::stock_str(
stock_str::msg_del_member(
context,
contact.get_addr(),
DC_CONTACT_ID_SELF,
)
.await
.to_string(),
.await,
);
}
msg.param.set_cmd(SystemMessage::MemberRemovedFromGroup);
@@ -2647,9 +2631,8 @@ pub async fn set_chat_name(
if chat.is_promoted() && !chat.is_mailing_list() {
msg.viewtype = Viewtype::Text;
msg.text = Some(
MsgGrpName::stock_str(context, &chat.name, &new_name, DC_CONTACT_ID_SELF)
.await
.to_string(),
stock_str::msg_grp_name(context, &chat.name, &new_name, DC_CONTACT_ID_SELF)
.await,
);
msg.param.set_cmd(SystemMessage::GroupNameChanged);
if !chat.name.is_empty() {
@@ -2706,11 +2689,7 @@ pub async fn set_chat_profile_image(
if new_image.as_ref().is_empty() {
chat.param.remove(Param::ProfileImage);
msg.param.remove(Param::Arg);
msg.text = Some(
MsgGrpImgDeleted::stock_str(context, DC_CONTACT_ID_SELF)
.await
.to_string(),
);
msg.text = Some(stock_str::msg_grp_img_deleted(context, DC_CONTACT_ID_SELF).await);
} else {
let image_blob = match BlobObject::from_path(context, Path::new(new_image.as_ref())) {
Ok(blob) => Ok(blob),
@@ -2724,11 +2703,7 @@ pub async fn set_chat_profile_image(
image_blob.recode_to_avatar_size(context).await?;
chat.param.set(Param::ProfileImage, image_blob.as_name());
msg.param.set(Param::Arg, image_blob.as_name());
msg.text = Some(
MsgGrpImgChanged::stock_str(context, DC_CONTACT_ID_SELF)
.await
.to_string(),
);
msg.text = Some(stock_str::msg_grp_img_changed(context, DC_CONTACT_ID_SELF).await);
}
chat.update_param(context).await?;
if chat.is_promoted() && !chat.is_mailing_list() {
@@ -3206,7 +3181,7 @@ mod tests {
assert!(chat.visibility == ChatVisibility::Normal);
assert!(!chat.is_device_talk());
assert!(chat.can_send());
assert_eq!(chat.name, SavedMessages::stock_str(&t).await);
assert_eq!(chat.name, stock_str::saved_messages(&t).await);
assert!(chat.get_profile_image(&t).await.is_some());
}
@@ -3222,7 +3197,7 @@ mod tests {
assert!(chat.visibility == ChatVisibility::Normal);
assert!(!chat.is_device_talk());
assert!(!chat.can_send());
assert_eq!(chat.name, DeadDrop::stock_str(&t).await);
assert_eq!(chat.name, stock_str::dead_drop(&t).await);
}
#[async_std::test]
@@ -3299,7 +3274,7 @@ mod tests {
assert!(chat.is_device_talk());
assert!(!chat.is_self_talk());
assert!(!chat.can_send());
assert_eq!(chat.name, DeviceMessages::stock_str(&t).await);
assert_eq!(chat.name, stock_str::device_messages(&t).await);
assert!(chat.get_profile_image(&t).await.is_some());
// delete device message, make sure it is not added again

View File

@@ -14,7 +14,7 @@ use crate::context::Context;
use crate::ephemeral::delete_expired_messages;
use crate::lot::Lot;
use crate::message::{Message, MessageState, MsgId};
use crate::stock::NoMessages;
use crate::stock_str;
/// An object representing a single chatlist in memory.
///
@@ -385,7 +385,7 @@ impl Chatlist {
ret.text2 = None;
} else if lastmsg.is_none() || lastmsg.as_ref().unwrap().from_id == DC_CONTACT_ID_UNDEFINED
{
ret.text2 = Some(NoMessages::stock_str(context).await.to_string());
ret.text2 = Some(stock_str::no_messages(context).await.to_string());
} else {
ret.fill(&mut lastmsg.unwrap(), chat, lastcontact.as_ref(), context)
.await;
@@ -440,7 +440,7 @@ mod tests {
use crate::chat::{create_group_chat, ProtectionStatus};
use crate::constants::Viewtype;
use crate::stock::StockMessage;
use crate::stock_str::StockMessage;
use crate::test_utils::TestContext;
#[async_std::test]

View File

@@ -13,7 +13,7 @@ use crate::job;
use crate::message::MsgId;
use crate::mimefactory::RECOMMENDED_FILE_SIZE;
use crate::provider::{get_provider_by_id, Provider};
use crate::stock::StatusLine;
use crate::stock_str;
/// The available configuration keys.
#[derive(
@@ -173,7 +173,7 @@ impl Context {
// Default values
match key {
Config::Selfstatus => Some(StatusLine::stock_str(self).await.into_owned()),
Config::Selfstatus => Some(stock_str::status_line(self).await),
Config::ConfiguredInboxFolder => Some("INBOX".to_owned()),
_ => key.get_str("default").map(|s| s.to_string()),
}
@@ -258,7 +258,7 @@ impl Context {
}
}
Config::Selfstatus => {
let def = StatusLine::stock_str(self).await;
let def = stock_str::status_line(self).await;
let val = if value.is_none() || value.unwrap() == def {
None
} else {

View File

@@ -19,7 +19,7 @@ use crate::message::Message;
use crate::oauth2::dc_get_oauth2_addr;
use crate::provider::{Protocol, Socket, UsernamePattern};
use crate::smtp::Smtp;
use crate::stock::{ConfigurationFailed, ErrorNoNetwork};
use crate::stock_str;
use crate::{chat, e2ee, provider};
use crate::{config::Config, dc_tools::time};
use crate::{
@@ -127,14 +127,13 @@ impl Context {
self,
0,
Some(
ConfigurationFailed::stock_str(
stock_str::configuration_failed(
self,
// We are using Anyhow's .context() and to show the
// inner error, too, we need the {:#}:
format!("{:#}", err),
)
.await
.to_string()
)
);
Err(err)
@@ -591,7 +590,7 @@ async fn nicer_configuration_error(context: &Context, errors: Vec<ConfigurationE
.iter()
.all(|e| e.msg.to_lowercase().contains("could not resolve"))
{
return ErrorNoNetwork::stock_str(context).await.to_string();
return stock_str::error_no_network(context).await;
}
if errors.iter().all(|e| e.msg == first_err.msg) {

View File

@@ -25,7 +25,7 @@ use crate::message::MessageState;
use crate::mimeparser::AvatarAction;
use crate::param::{Param, Params};
use crate::peerstate::{Peerstate, PeerstateVerifiedStatus};
use crate::stock::{DeviceMessages, E2eAvailable, E2ePreferred, EncrNone, FingerPrints, SelfMsg};
use crate::stock_str;
/// An object representing a single contact in memory.
///
@@ -195,7 +195,7 @@ impl Contact {
)
.await?;
if contact_id == DC_CONTACT_ID_SELF {
res.name = SelfMsg::stock_str(context).await.to_string();
res.name = stock_str::self_msg(context).await;
res.addr = context
.get_config(Config::ConfiguredAddr)
.await
@@ -205,7 +205,7 @@ impl Contact {
.await
.unwrap_or_default();
} else if contact_id == DC_CONTACT_ID_DEVICE {
res.name = DeviceMessages::stock_str(context).await.to_string();
res.name = stock_str::device_messages(context).await;
res.addr = DC_CONTACT_ID_DEVICE_ADDR.to_string();
}
Ok(res)
@@ -632,7 +632,7 @@ impl Contact {
.get_config(Config::Displayname)
.await
.unwrap_or_default();
let self_name2 = SelfMsg::stock_str(context);
let self_name2 = stock_str::self_msg(context);
if let Some(query) = query {
if self_addr.contains(query.as_ref())
@@ -726,15 +726,15 @@ impl Contact {
.is_some()
}) {
let stock_message = match peerstate.prefer_encrypt {
EncryptPreference::Mutual => E2ePreferred::stock_str(context).await,
EncryptPreference::NoPreference => E2eAvailable::stock_str(context).await,
EncryptPreference::Reset => EncrNone::stock_str(context).await,
EncryptPreference::Mutual => stock_str::e2e_preferred(context).await,
EncryptPreference::NoPreference => stock_str::e2e_available(context).await,
EncryptPreference::Reset => stock_str::encr_none(context).await,
};
ret += &format!(
"{}\n{}:",
stock_message,
FingerPrints::stock_str(context).await
stock_str::finger_prints(context).await
);
let fingerprint_self = SignedPublicKey::load_self(context)
@@ -767,7 +767,7 @@ impl Contact {
cat_fingerprint(&mut ret, &loginparam.addr, &fingerprint_self, "");
}
} else {
ret += &EncrNone::stock_str(context).await;
ret += &stock_str::encr_none(context).await;
}
}
@@ -1507,7 +1507,7 @@ mod tests {
// check SELF
let contact = Contact::load_from_db(&t, DC_CONTACT_ID_SELF).await.unwrap();
assert_eq!(DC_CONTACT_ID_SELF, 1);
assert_eq!(contact.get_name(), SelfMsg::stock_str(&t).await);
assert_eq!(contact.get_name(), stock_str::self_msg(&t).await);
assert_eq!(contact.get_addr(), ""); // we're not configured
assert!(!contact.is_blocked());
}

View File

@@ -26,10 +26,7 @@ use crate::mimeparser::{parse_message_ids, AvatarAction, MimeMessage, SystemMess
use crate::param::{Param, Params};
use crate::peerstate::{Peerstate, PeerstateKeyType, PeerstateVerifiedStatus};
use crate::securejoin::{self, handle_securejoin_handshake, observe_securejoin_on_other_device};
use crate::stock::{
MsgAddMember, MsgDelMember, MsgGroupLeft, MsgGrpImgChanged, MsgGrpImgDeleted, MsgGrpName,
MsgLocationEnabled, UnknownSenderForChat,
};
use crate::stock_str;
use crate::{contact, location};
// IndexSet is like HashSet but maintains order of insertion
@@ -1168,9 +1165,7 @@ async fn create_or_lookup_group(
let mut better_msg: String = From::from("");
if mime_parser.is_system_message == SystemMessage::LocationStreamingEnabled {
better_msg = MsgLocationEnabled::stock_str_by(context, from_id)
.await
.to_string();
better_msg = stock_str::msg_location_enabled_by(context, from_id).await;
set_better_msg(mime_parser, &better_msg);
}
@@ -1235,11 +1230,9 @@ async fn create_or_lookup_group(
Some(contact_id) => {
mime_parser.is_system_message = SystemMessage::MemberRemovedFromGroup;
better_msg = if contact_id == from_id {
MsgGroupLeft::stock_str(context, from_id).await.to_string()
stock_str::msg_group_left(context, from_id).await
} else {
MsgDelMember::stock_str(context, &removed_addr, from_id)
.await
.to_string()
stock_str::msg_del_member(context, &removed_addr, from_id).await
};
}
None => warn!(context, "removed {:?} has no contact_id", removed_addr),
@@ -1248,13 +1241,11 @@ async fn create_or_lookup_group(
let field = mime_parser.get(HeaderDef::ChatGroupMemberAdded).cloned();
if let Some(added_member) = field {
mime_parser.is_system_message = SystemMessage::MemberAddedToGroup;
better_msg = MsgAddMember::stock_str(context, &added_member, from_id)
.await
.to_string();
better_msg = stock_str::msg_add_member(context, &added_member, from_id).await;
X_MrAddToGrp = Some(added_member);
} else if let Some(old_name) = mime_parser.get(HeaderDef::ChatGroupNameChanged) {
X_MrGrpNameChanged = true;
better_msg = MsgGrpName::stock_str(
better_msg = stock_str::msg_grp_name(
context,
old_name,
if let Some(ref name) = grpname {
@@ -1264,8 +1255,7 @@ async fn create_or_lookup_group(
},
from_id as u32,
)
.await
.to_string();
.await;
mime_parser.is_system_message = SystemMessage::GroupNameChanged;
} else if let Some(value) = mime_parser.get(HeaderDef::ChatContent) {
if value == "group-avatar-changed" {
@@ -1274,12 +1264,12 @@ async fn create_or_lookup_group(
// apart from that, the group-avatar is send along with various other messages
mime_parser.is_system_message = SystemMessage::GroupImageChanged;
better_msg = match avatar_action {
AvatarAction::Delete => MsgGrpImgDeleted::stock_str(context, from_id)
.await
.to_string(),
AvatarAction::Change(_) => MsgGrpImgChanged::stock_str(context, from_id)
.await
.to_string(),
AvatarAction::Delete => {
stock_str::msg_grp_img_deleted(context, from_id).await
}
AvatarAction::Change(_) => {
stock_str::msg_grp_img_changed(context, from_id).await
}
};
}
}
@@ -1298,7 +1288,7 @@ async fn create_or_lookup_group(
// but still show the message as part of the chat.
// After all, the sender has a reference/in-reply-to that
// points to this chat.
let s = UnknownSenderForChat::stock_str(context).await;
let s = stock_str::unknown_sender_for_chat(context).await;
mime_parser.repl_msg_by_error(s.to_string());
}
@@ -1976,16 +1966,13 @@ fn dc_create_incoming_rfc724_mid(
#[cfg(test)]
mod tests {
use super::*;
use crate::constants::{DC_CONTACT_ID_INFO, DC_GCL_NO_SPECIALS};
use crate::chat::{ChatItem, ChatVisibility};
use crate::chatlist::Chatlist;
use crate::constants::{DC_CHAT_ID_DEADDROP, DC_CONTACT_ID_INFO, DC_GCL_NO_SPECIALS};
use crate::message::ContactRequestDecision::*;
use crate::message::Message;
use crate::stock::FailedSendingTo;
use crate::test_utils::TestContext;
use crate::{
chat::{ChatItem, ChatVisibility},
constants::DC_CHAT_ID_DEADDROP,
};
use crate::{chatlist::Chatlist, test_utils::get_chat_msg};
use crate::test_utils::{get_chat_msg, TestContext};
#[test]
fn test_hex_hash() {
@@ -2647,7 +2634,7 @@ mod tests {
assert_eq!(
last_msg.text,
Some(
FailedSendingTo::stock_str(&t, "assidhfaaspocwaeofi@gmail.com")
stock_str::failed_sending_to(&t, "assidhfaaspocwaeofi@gmail.com")
.await
.to_string(),
)

View File

@@ -22,7 +22,7 @@ use crate::context::Context;
use crate::events::EventType;
use crate::message::Message;
use crate::provider::get_provider_update_timestamp;
use crate::stock::{BadTimeMsgBody, UpdateReminderMsgBody};
use crate::stock_str;
/// Shortens a string to a specified length and adds "[...]" to the
/// end of the shortened string.
@@ -169,15 +169,14 @@ async fn maybe_warn_on_bad_time(context: &Context, now: i64, known_past_timestam
if now < known_past_timestamp {
let mut msg = Message::new(Viewtype::Text);
msg.text = Some(
BadTimeMsgBody::stock_str(
stock_str::bad_time_msg_body(
context,
Local
.timestamp(now, 0)
.format("%Y-%m-%d %H:%M:%S")
.to_string(),
)
.await
.to_string(),
.await,
);
add_device_msg_with_importance(
context,
@@ -201,7 +200,7 @@ async fn maybe_warn_on_bad_time(context: &Context, now: i64, known_past_timestam
async fn maybe_warn_on_outdated(context: &Context, now: i64, approx_compile_time: i64) {
if now > approx_compile_time + DC_OUTDATED_WARNING_DAYS * 24 * 60 * 60 {
let mut msg = Message::new(Viewtype::Text);
msg.text = Some(UpdateReminderMsgBody::stock_str(context).await.into());
msg.text = Some(stock_str::update_reminder_msg_body(context).await);
add_device_msg(
context,
Some(

View File

@@ -56,7 +56,6 @@
//! the database entries which are expired either according to their
//! ephemeral message timers or global `delete_server_after` setting.
use std::borrow::Cow;
use std::convert::{TryFrom, TryInto};
use std::num::ParseIntError;
use std::str::FromStr;
@@ -76,12 +75,7 @@ use crate::events::EventType;
use crate::message::{Message, MessageState, MsgId};
use crate::mimeparser::SystemMessage;
use crate::sql;
use crate::stock::{
MsgEphemeralTimerDay, MsgEphemeralTimerDays, MsgEphemeralTimerDisabled,
MsgEphemeralTimerEnabled, MsgEphemeralTimerHour, MsgEphemeralTimerHours,
MsgEphemeralTimerMinute, MsgEphemeralTimerMinutes, MsgEphemeralTimerWeek,
MsgEphemeralTimerWeeks,
};
use crate::stock_str;
#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)]
pub enum Timer {
@@ -222,43 +216,43 @@ pub(crate) async fn stock_ephemeral_timer_changed(
context: &Context,
timer: Timer,
from_id: u32,
) -> Cow<'static, str> {
) -> String {
match timer {
Timer::Disabled => MsgEphemeralTimerDisabled::stock_str(context, from_id).await,
Timer::Disabled => stock_str::msg_ephemeral_timer_disabled(context, from_id).await,
Timer::Enabled { duration } => match duration {
0..=59 => {
MsgEphemeralTimerEnabled::stock_str(context, timer.to_string(), from_id).await
stock_str::msg_ephemeral_timer_enabled(context, timer.to_string(), from_id).await
}
60 => MsgEphemeralTimerMinute::stock_str(context, from_id).await,
60 => stock_str::msg_ephemeral_timer_minute(context, from_id).await,
61..=3599 => {
MsgEphemeralTimerMinutes::stock_str(
stock_str::msg_ephemeral_timer_minutes(
context,
format!("{}", (f64::from(duration) / 6.0).round() / 10.0),
from_id,
)
.await
}
3600 => MsgEphemeralTimerHour::stock_str(context, from_id).await,
3600 => stock_str::msg_ephemeral_timer_hour(context, from_id).await,
3601..=86399 => {
MsgEphemeralTimerHours::stock_str(
stock_str::msg_ephemeral_timer_hours(
context,
format!("{}", (f64::from(duration) / 360.0).round() / 10.0),
from_id,
)
.await
}
86400 => MsgEphemeralTimerDay::stock_str(context, from_id).await,
86400 => stock_str::msg_ephemeral_timer_day(context, from_id).await,
86401..=604_799 => {
MsgEphemeralTimerDays::stock_str(
stock_str::msg_ephemeral_timer_days(
context,
format!("{}", (f64::from(duration) / 8640.0).round() / 10.0),
from_id,
)
.await
}
604_800 => MsgEphemeralTimerWeek::stock_str(context, from_id).await,
604_800 => stock_str::msg_ephemeral_timer_week(context, from_id).await,
_ => {
MsgEphemeralTimerWeeks::stock_str(
stock_str::msg_ephemeral_timer_weeks(
context,
format!("{}", (f64::from(duration) / 60480.0).round() / 10.0),
from_id,

View File

@@ -35,7 +35,7 @@ use crate::oauth2::dc_get_oauth2_access_token;
use crate::param::Params;
use crate::provider::Socket;
use crate::scheduler::InterruptInfo;
use crate::stock::CannotLogin;
use crate::stock_str;
mod client;
mod idle;
@@ -255,9 +255,7 @@ impl Imap {
Err((err, _)) => {
let imap_user = self.config.lp.user.to_owned();
let message = CannotLogin::stock_str(context, &imap_user)
.await
.to_string();
let message = stock_str::cannot_login(context, &imap_user).await;
warn!(context, "{} ({})", message, err);

View File

@@ -29,7 +29,7 @@ use crate::mimeparser::SystemMessage;
use crate::param::Param;
use crate::pgp;
use crate::sql::{self, Sql};
use crate::stock::{AcSetupMsgBody, AcSetupMsgSubject};
use crate::stock_str;
use ::pgp::types::KeyTrait;
use async_tar::Archive;
@@ -275,8 +275,8 @@ pub async fn render_setup_file(context: &Context, passphrase: &str) -> Result<St
);
let pgp_msg = encr.replace("-----BEGIN PGP MESSAGE-----", &replacement);
let msg_subj = AcSetupMsgSubject::stock_str(context).await;
let msg_body = AcSetupMsgBody::stock_str(context).await;
let msg_subj = stock_str::ac_setup_msg_subject(context).await;
let msg_body = stock_str::ac_setup_msg_body(context).await;
let msg_body_html = msg_body.replace("\r", "").replace("\n", "<br>");
Ok(format!(
concat!(
@@ -904,7 +904,7 @@ mod tests {
use super::*;
use crate::pgp::{split_armored_data, HEADER_AUTOCRYPT, HEADER_SETUPCODE};
use crate::stock::StockMessage;
use crate::stock_str::StockMessage;
use crate::test_utils::{alice_keypair, TestContext};
use ::pgp::armor::BlockType;

View File

@@ -73,7 +73,7 @@ pub mod qr;
pub mod securejoin;
mod simplify;
mod smtp;
pub mod stock;
pub mod stock_str;
mod token;
#[macro_use]
mod dehtml;

View File

@@ -14,7 +14,7 @@ use crate::job::{self, Job};
use crate::message::{Message, MsgId};
use crate::mimeparser::SystemMessage;
use crate::param::Params;
use crate::stock::{MsgLocationDisabled, MsgLocationEnabled};
use crate::stock_str;
/// Location record
#[derive(Debug, Clone, Default)]
@@ -212,13 +212,13 @@ pub async fn send_locations_to_chat(context: &Context, chat_id: ChatId, seconds:
{
if 0 != seconds && !is_sending_locations_before {
let mut msg = Message::new(Viewtype::Text);
msg.text = Some(MsgLocationEnabled::stock_str(context).await.to_string());
msg.text = Some(stock_str::msg_location_enabled(context).await);
msg.param.set_cmd(SystemMessage::LocationStreamingEnabled);
chat::send_msg(context, chat_id, &mut msg)
.await
.unwrap_or_default();
} else if 0 == seconds && is_sending_locations_before {
let stock_str = MsgLocationDisabled::stock_str(context).await;
let stock_str = stock_str::msg_location_disabled(context).await;
chat::add_info_msg(context, chat_id, stock_str).await;
}
context.emit_event(EventType::ChatModified(chat_id));
@@ -710,7 +710,7 @@ pub(crate) async fn job_maybe_send_locations_ended(
paramsv![chat_id],
).await);
let stock_str = MsgLocationDisabled::stock_str(context).await;
let stock_str = stock_str::msg_location_disabled(context).await;
chat::add_info_msg(context, chat_id, stock_str).await;
context.emit_event(EventType::ChatModified(chat_id));
}

View File

@@ -26,10 +26,7 @@ use crate::lot::{Lot, LotState, Meaning};
use crate::mimeparser::{FailureReport, SystemMessage};
use crate::param::{Param, Params};
use crate::pgp::split_armored_data;
use crate::stock::{
AcSetupMsgSubject, Audio, Draft, FailedSendingTo, File, Gif, Image, Location, ReplyNoun,
SelfMsg, Sticker, Video, VideochatInvitation, VoiceMessage,
};
use crate::stock_str;
use std::collections::BTreeMap;
// In practice, the user additionally cuts the string themselves
@@ -1058,14 +1055,14 @@ impl Lot {
context: &Context,
) {
if msg.state == MessageState::OutDraft {
self.text1 = Some(Draft::stock_str(context).await.to_owned().into());
self.text1 = Some(stock_str::draft(context).await);
self.text1_meaning = Meaning::Text1Draft;
} else if msg.from_id == DC_CONTACT_ID_SELF {
if msg.is_info() || chat.is_self_talk() {
self.text1 = None;
self.text1_meaning = Meaning::None;
} else {
self.text1 = Some(SelfMsg::stock_str(context).await.to_owned().into());
self.text1 = Some(stock_str::self_msg(context).await);
self.text1_meaning = Meaning::Text1Self;
}
} else {
@@ -1098,7 +1095,7 @@ impl Lot {
.await;
if text2.is_empty() && msg.quoted_text().is_some() {
text2 = ReplyNoun::stock_str(context).await.into_owned()
text2 = stock_str::reply_noun(context).await
}
self.text2 = Some(text2);
@@ -1550,15 +1547,15 @@ pub async fn get_summarytext_by_raw(
) -> String {
let mut append_text = true;
let prefix = match viewtype {
Viewtype::Image => Image::stock_str(context).await.into_owned(),
Viewtype::Gif => Gif::stock_str(context).await.into_owned(),
Viewtype::Sticker => Sticker::stock_str(context).await.into_owned(),
Viewtype::Video => Video::stock_str(context).await.into_owned(),
Viewtype::Voice => VoiceMessage::stock_str(context).await.into_owned(),
Viewtype::Image => stock_str::image(context).await,
Viewtype::Gif => stock_str::gif(context).await,
Viewtype::Sticker => stock_str::sticker(context).await,
Viewtype::Video => stock_str::video(context).await,
Viewtype::Voice => stock_str::voice_message(context).await,
Viewtype::Audio | Viewtype::File => {
if param.get_cmd() == SystemMessage::AutocryptSetupMessage {
append_text = false;
AcSetupMsgSubject::stock_str(context).await.to_string()
stock_str::ac_setup_msg_subject(context).await
} else {
let file_name: String = param
.get_path(Param::File, context)
@@ -1569,23 +1566,23 @@ pub async fn get_summarytext_by_raw(
})
.unwrap_or_else(|| String::from("ErrFileName"));
let label = if viewtype == Viewtype::Audio {
Audio::stock_str(context).await
stock_str::audio(context).await
} else {
File::stock_str(context).await
stock_str::file(context).await
};
format!("{} {}", label, file_name)
}
}
Viewtype::VideochatInvitation => {
append_text = false;
VideochatInvitation::stock_str(context).await.into_owned()
stock_str::videochat_invitation(context).await
}
_ => {
if param.get_cmd() != SystemMessage::LocationOnly {
"".to_string()
} else {
append_text = false;
Location::stock_str(context).await.to_string()
stock_str::location(context).await
}
}
};
@@ -1844,7 +1841,7 @@ async fn ndn_maybe_add_info_msg(
let contact = Contact::load_from_db(context, contact_id).await?;
// Tell the user which of the recipients failed if we know that (because in
// a group, this might otherwise be unclear)
let text = FailedSendingTo::stock_str(context, contact.get_display_name()).await;
let text = stock_str::failed_sending_to(context, contact.get_display_name()).await;
chat::add_info_msg(context, chat_id, text).await;
context.emit_event(EventType::ChatModified(chat_id));
}

View File

@@ -21,10 +21,7 @@ use crate::mimeparser::SystemMessage;
use crate::param::Param;
use crate::peerstate::{Peerstate, PeerstateVerifiedStatus};
use crate::simplify::escape_message_footer_marks;
use crate::stock::{
AcSetupMsgBody, AcSetupMsgSubject, EncryptedMsg, ReadRcpt, ReadRcptMailBody, StatusLine,
SubjectForNewContact,
};
use crate::stock_str;
use std::convert::TryInto;
// attachments of 25 mb brutto should work on the majority of providers
@@ -142,7 +139,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
)
.await?;
let default_str = StatusLine::stock_str(context).await.to_string();
let default_str = stock_str::status_line(context).await;
let factory = MimeFactory {
from_addr,
from_displayname,
@@ -180,7 +177,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
.get_config(Config::Displayname)
.await
.unwrap_or_default();
let default_str = StatusLine::stock_str(context).await.to_string();
let default_str = stock_str::status_line(context).await;
let selfstatus = context
.get_config(Config::Selfstatus)
.await
@@ -342,9 +339,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
match self.loaded {
Loaded::Message { ref chat } => {
if self.msg.param.get_cmd() == SystemMessage::AutocryptSetupMessage {
AcSetupMsgSubject::stock_str(self.context)
.await
.into_owned()
stock_str::ac_setup_msg_subject(self.context).await
} else if chat.typ == Chattype::Group {
let re = if self.in_reply_to.is_empty() {
""
@@ -386,14 +381,12 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
.unwrap_or_default(),
};
SubjectForNewContact::stock_str(self.context, self_name)
.await
.to_string()
stock_str::subject_for_new_contact(self.context, self_name).await
}
}
}
}
Loaded::MDN { .. } => ReadRcpt::stock_str(self.context).await.into_owned(),
Loaded::MDN { .. } => stock_str::read_rcpt(self.context).await,
}
}
@@ -797,7 +790,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
unprotected_headers
.push(Header::new("Autocrypt-Setup-Message".into(), "v1".into()));
placeholdertext = Some(AcSetupMsgBody::stock_str(self.context).await.to_string());
placeholdertext = Some(stock_str::ac_setup_msg_body(self.context).await);
}
SystemMessage::SecurejoinMessage => {
let msg = &self.msg;
@@ -1055,11 +1048,11 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
.get_int(Param::GuaranteeE2ee)
.unwrap_or_default()
{
EncryptedMsg::stock_str(self.context).await.into_owned()
stock_str::encrypted_msg(self.context).await
} else {
self.msg.get_summarytext(self.context, 32).await
};
let p2 = ReadRcptMailBody::stock_str(self.context, p1).await;
let p2 = stock_str::read_rcpt_mail_body(self.context, p1).await;
let message_text = format!("{}\r\n", p2);
message = message.child(
PartBuilder::new()

View File

@@ -27,7 +27,7 @@ use crate::message;
use crate::param::{Param, Params};
use crate::peerstate::Peerstate;
use crate::simplify::simplify;
use crate::stock::CantDecryptMsgBody;
use crate::stock_str;
/// A parsed MIME message.
///
@@ -629,7 +629,7 @@ impl MimeMessage {
// we currently do not try to decrypt non-autocrypt messages
// at all. If we see an encrypted part, we set
// decrypting_failed.
let msg_body = CantDecryptMsgBody::stock_str(context).await;
let msg_body = stock_str::cant_decrypt_msg_body(context).await;
let txt = format!("[{}]", msg_body);
let part = Part {

View File

@@ -13,7 +13,7 @@ use crate::context::Context;
use crate::events::EventType;
use crate::key::{DcKey, Fingerprint, SignedPublicKey};
use crate::sql::Sql;
use crate::stock::ContactSetupChanged;
use crate::stock_str;
#[derive(Debug)]
pub enum PeerstateKeyType {
@@ -281,7 +281,7 @@ impl<'a> Peerstate<'a> {
.await
.unwrap_or_default();
let msg = ContactSetupChanged::stock_str(context, self.addr.clone()).await;
let msg = stock_str::contact_setup_changed(context, self.addr.clone()).await;
chat::add_info_msg(context, contact_chat_id, msg).await;
emit_event!(context, EventType::ChatModified(contact_chat_id));

View File

@@ -23,7 +23,7 @@ use crate::param::Param;
use crate::peerstate::{Peerstate, PeerstateKeyType, PeerstateVerifiedStatus, ToSave};
use crate::qr::check_qr;
use crate::sql;
use crate::stock::{ContactNotVerified, ContactVerified};
use crate::stock_str;
use crate::token;
mod bobstate;
@@ -822,7 +822,7 @@ async fn secure_connection_established(context: &Context, contact_chat_id: ChatI
} else {
"?"
};
let msg = ContactVerified::stock_str(context, addr).await;
let msg = stock_str::contact_verified(context, addr).await;
chat::add_info_msg(context, contact_chat_id, msg).await;
emit_event!(context, EventType::ChatModified(contact_chat_id));
info!(context, "StockMessage::ContactVerified posted to 1:1 chat");
@@ -835,7 +835,7 @@ async fn could_not_establish_secure_connection(
) {
let contact_id = chat_id_2_contact_id(context, contact_chat_id).await;
let contact = Contact::get_by_id(context, contact_id).await;
let msg = ContactNotVerified::stock_str(
let msg = stock_str::contact_not_verified(
context,
if let Ok(ref contact) = contact {
contact.get_addr()

View File

@@ -13,7 +13,7 @@ use crate::events::EventType;
use crate::login_param::{dc_build_tls, CertificateChecks, LoginParam, ServerLoginParam};
use crate::oauth2::dc_get_oauth2_access_token;
use crate::provider::Socket;
use crate::stock::ServerResponse;
use crate::stock_str;
/// SMTP write and read timeout in seconds.
const SMTP_TIMEOUT: u64 = 30;
@@ -111,13 +111,12 @@ impl Smtp {
)
.await;
if let Err(ref err) = res {
let message = ServerResponse::stock_str(
let message = stock_str::server_response(
context,
format!("SMTP {}:{}", lp.smtp.server, lp.smtp.port),
err.to_string(),
)
.await
.to_string();
.await;
context.emit_event(EventType::ErrorNetwork(message));
};

View File

@@ -22,7 +22,7 @@ use crate::message::Message;
use crate::param::{Param, Params};
use crate::peerstate::Peerstate;
use crate::provider::get_provider_by_domain;
use crate::stock::DeleteServerTurnedOff;
use crate::stock_str;
#[macro_export]
macro_rules! paramsv {
@@ -1541,7 +1541,7 @@ CREATE INDEX devmsglabels_index1 ON devmsglabels (label);
// So, for people who have delete_server enabled, disable it and add a hint to the devicechat:
if context.get_config_delete_server_after().await.is_some() {
let mut msg = Message::new(Viewtype::Text);
msg.text = Some(DeleteServerTurnedOff::stock_str(context).await.into());
msg.text = Some(stock_str::delete_server_turned_off(context).await);
add_device_msg(context, None, Some(&mut msg)).await?;
context.set_config(DeleteServerAfter, Some("0")).await?;
}

File diff suppressed because it is too large Load Diff

1084
src/stock_str.rs Normal file

File diff suppressed because it is too large Load Diff