api!: make Message.text non-optional

Message.set_text() and Message.get_text() are modified accordingly
to accept String and return String.

Messages which previously contained None text
are now represented as messages with empty text.
Use Message.set_text("".to_string())
instead of Message.set_text(None).
This commit is contained in:
link2xt
2023-07-03 13:34:13 +00:00
parent 8e17e400b3
commit 9c68fac4b6
33 changed files with 248 additions and 325 deletions

View File

@@ -3308,7 +3308,7 @@ pub unsafe extern "C" fn dc_msg_get_text(msg: *mut dc_msg_t) -> *mut libc::c_cha
return "".strdup(); return "".strdup();
} }
let ffi_msg = &*msg; let ffi_msg = &*msg;
ffi_msg.message.get_text().unwrap_or_default().strdup() ffi_msg.message.get_text().strdup()
} }
#[no_mangle] #[no_mangle]
@@ -3693,7 +3693,7 @@ pub unsafe extern "C" fn dc_msg_set_text(msg: *mut dc_msg_t, text: *const libc::
return; return;
} }
let ffi_msg = &mut *msg; let ffi_msg = &mut *msg;
ffi_msg.message.set_text(to_opt_string_lossy(text)) ffi_msg.message.set_text(to_string_lossy(text))
} }
#[no_mangle] #[no_mangle]

View File

@@ -901,7 +901,7 @@ impl CommandApi {
) -> Result<u32> { ) -> Result<u32> {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some(text)); msg.set_text(text);
let message_id = let message_id =
deltachat::chat::add_device_msg(&ctx, Some(&label), Some(&mut msg)).await?; deltachat::chat::add_device_msg(&ctx, Some(&label), Some(&mut msg)).await?;
Ok(message_id.to_u32()) Ok(message_id.to_u32())
@@ -1767,9 +1767,7 @@ impl CommandApi {
} else { } else {
Viewtype::Text Viewtype::Text
}); });
if data.text.is_some() { message.set_text(data.text.unwrap_or_default());
message.set_text(data.text);
}
if data.html.is_some() { if data.html.is_some() {
message.set_html(data.html); message.set_html(data.html);
} }
@@ -1950,7 +1948,7 @@ impl CommandApi {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some(text)); msg.set_text(text);
let message_id = deltachat::chat::send_msg(&ctx, ChatId::new(chat_id), &mut msg).await?; let message_id = deltachat::chat::send_msg(&ctx, ChatId::new(chat_id), &mut msg).await?;
Ok(message_id.to_u32()) Ok(message_id.to_u32())
@@ -1973,9 +1971,7 @@ impl CommandApi {
} else { } else {
Viewtype::Text Viewtype::Text
}); });
if text.is_some() { message.set_text(text.unwrap_or_default());
message.set_text(text);
}
if let Some(file) = file { if let Some(file) = file {
message.set_file(file, None); message.set_file(file, None);
} }
@@ -2019,9 +2015,7 @@ impl CommandApi {
} else { } else {
Viewtype::Text Viewtype::Text
}); });
if text.is_some() { draft.set_text(text.unwrap_or_default());
draft.set_text(text);
}
if let Some(file) = file { if let Some(file) = file {
draft.set_file(file, None); draft.set_file(file, None);
} }

View File

@@ -180,7 +180,7 @@ impl MessageObject {
from_id: message.get_from_id().to_u32(), from_id: message.get_from_id().to_u32(),
quote, quote,
parent_id, parent_id,
text: message.get_text(), text: Some(message.get_text()).filter(|s| !s.is_empty()),
has_location: message.has_location(), has_location: message.has_location(),
has_html: message.has_html(), has_html: message.has_html(),
view_type: message.get_viewtype().into(), view_type: message.get_viewtype().into(),
@@ -500,7 +500,7 @@ impl MessageSearchResult {
is_chat_protected: chat.is_protected(), is_chat_protected: chat.is_protected(),
is_chat_contact_request: chat.is_contact_request(), is_chat_contact_request: chat.is_contact_request(),
is_chat_archived: chat.get_visibility() == ChatVisibility::Archived, is_chat_archived: chat.get_visibility() == ChatVisibility::Archived,
message: message.get_text().unwrap_or_default(), message: message.get_text(),
timestamp: message.get_timestamp(), timestamp: message.get_timestamp(),
}) })
} }

View File

@@ -199,7 +199,7 @@ async fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: &Message) {
if msg.has_location() { "📍" } else { "" }, if msg.has_location() { "📍" } else { "" },
&contact_name, &contact_name,
contact_id, contact_id,
msgtext.unwrap_or_default(), msgtext,
if msg.has_html() { "[HAS-HTML]" } else { "" }, if msg.has_html() { "[HAS-HTML]" } else { "" },
if msg.get_from_id() == ContactId::SELF { if msg.get_from_id() == ContactId::SELF {
"" ""
@@ -912,9 +912,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
Viewtype::File Viewtype::File
}); });
msg.set_file(arg1, None); msg.set_file(arg1, None);
if !arg2.is_empty() { msg.set_text(arg2.to_string());
msg.set_text(Some(arg2.to_string()));
}
chat::send_msg(&context, sel_chat.as_ref().unwrap().get_id(), &mut msg).await?; chat::send_msg(&context, sel_chat.as_ref().unwrap().get_id(), &mut msg).await?;
} }
"sendhtml" => { "sendhtml" => {
@@ -926,11 +924,11 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_html(Some(html.to_string())); msg.set_html(Some(html.to_string()));
msg.set_text(Some(if arg2.is_empty() { msg.set_text(if arg2.is_empty() {
path.file_name().unwrap().to_string_lossy().to_string() path.file_name().unwrap().to_string_lossy().to_string()
} else { } else {
arg2.to_string() arg2.to_string()
})); });
chat::send_msg(&context, sel_chat.as_ref().unwrap().get_id(), &mut msg).await?; chat::send_msg(&context, sel_chat.as_ref().unwrap().get_id(), &mut msg).await?;
} }
"sendsyncmsg" => match context.send_sync_msg().await? { "sendsyncmsg" => match context.send_sync_msg().await? {
@@ -979,7 +977,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
if !arg1.is_empty() { if !arg1.is_empty() {
let mut draft = Message::new(Viewtype::Text); let mut draft = Message::new(Viewtype::Text);
draft.set_text(Some(arg1.to_string())); draft.set_text(arg1.to_string());
sel_chat sel_chat
.as_ref() .as_ref()
.unwrap() .unwrap()
@@ -1003,7 +1001,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
"Please specify text to add as device message." "Please specify text to add as device message."
); );
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some(arg1.to_string())); msg.set_text(arg1.to_string());
chat::add_device_msg(&context, None, Some(&mut msg)).await?; chat::add_device_msg(&context, None, Some(&mut msg)).await?;
} }
"listmedia" => { "listmedia" => {

View File

@@ -705,7 +705,7 @@ Authentication-Results: dkim=";
let received = tcm let received = tcm
.try_send_recv(&alice, &bob2, "My credit card number is 1234") .try_send_recv(&alice, &bob2, "My credit card number is 1234")
.await; .await;
assert!(!received.text.as_ref().unwrap().contains("1234")); assert!(!received.text.contains("1234"));
assert!(received.error.is_some()); assert!(received.error.is_some());
tcm.section("Turns out bob2 wasn't an attacker at all, Bob just has a new phone and DKIM just stopped working."); tcm.section("Turns out bob2 wasn't an attacker at all, Bob just has a new phone and DKIM just stopped working.");
@@ -786,7 +786,7 @@ Authentication-Results: dkim=";
.insert_str(0, "List-Post: <mailto:deltachat-community.example.net>\n"); .insert_str(0, "List-Post: <mailto:deltachat-community.example.net>\n");
let rcvd = alice.recv_msg(&sent).await; let rcvd = alice.recv_msg(&sent).await;
assert!(!rcvd.get_showpadlock()); assert!(!rcvd.get_showpadlock());
assert_eq!(&rcvd.text.unwrap(), "hellooo in the mailinglist again"); assert_eq!(&rcvd.text, "hellooo in the mailinglist again");
Ok(()) Ok(())
} }

View File

@@ -461,7 +461,7 @@ 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 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,
@@ -470,7 +470,7 @@ 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,
..Default::default() ..Default::default()
}; };
msg.param.set_cmd(cmd); msg.param.set_cmd(cmd);
@@ -479,7 +479,7 @@ impl ChatId {
add_info_msg_with_cmd( add_info_msg_with_cmd(
context, context,
self, self,
&msg_text, &text,
cmd, cmd,
create_smeared_timestamp(context), create_smeared_timestamp(context),
None, None,
@@ -642,7 +642,7 @@ impl ChatId {
if chat.is_self_talk() { if chat.is_self_talk() {
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some(stock_str::self_deleted_msg_body(context).await); msg.text = stock_str::self_deleted_msg_body(context).await;
add_device_msg(context, None, Some(&mut msg)).await?; add_device_msg(context, None, Some(&mut msg)).await?;
} }
@@ -724,7 +724,7 @@ impl ChatId {
match msg.viewtype { match msg.viewtype {
Viewtype::Unknown => bail!("Can not set draft of unknown type."), Viewtype::Unknown => bail!("Can not set draft of unknown type."),
Viewtype::Text => { Viewtype::Text => {
if msg.text.is_none_or_empty() && msg.in_reply_to.is_none_or_empty() { if msg.text.is_empty() && msg.in_reply_to.is_none_or_empty() {
bail!("No text and no quote in draft"); bail!("No text and no quote in draft");
} }
} }
@@ -770,7 +770,7 @@ impl ChatId {
( (
time(), time(),
msg.viewtype, msg.viewtype,
msg.text.as_deref().unwrap_or(""), &msg.text,
msg.param.to_string(), msg.param.to_string(),
msg.in_reply_to.as_deref().unwrap_or_default(), msg.in_reply_to.as_deref().unwrap_or_default(),
msg.id, msg.id,
@@ -804,7 +804,7 @@ impl ChatId {
time(), time(),
msg.viewtype, msg.viewtype,
MessageState::OutDraft, MessageState::OutDraft,
msg.text.as_deref().unwrap_or(""), &msg.text,
msg.param.to_string(), msg.param.to_string(),
1, 1,
msg.in_reply_to.as_deref().unwrap_or_default(), msg.in_reply_to.as_deref().unwrap_or_default(),
@@ -1358,7 +1358,7 @@ impl Chat {
/// deltachat, and the data returned is still subject to change. /// deltachat, and the data returned is still subject to change.
pub async fn get_info(&self, context: &Context) -> Result<ChatInfo> { pub async fn get_info(&self, context: &Context) -> Result<ChatInfo> {
let draft = match self.id.get_draft(context).await? { let draft = match self.id.get_draft(context).await? {
Some(message) => message.text.unwrap_or_default(), Some(message) => message.text,
_ => String::new(), _ => String::new(),
}; };
Ok(ChatInfo { Ok(ChatInfo {
@@ -1604,7 +1604,7 @@ impl Chat {
timestamp, timestamp,
msg.viewtype, msg.viewtype,
msg.state, msg.state,
msg.text.as_ref().cloned().unwrap_or_default(), msg.text,
&msg.subject, &msg.subject,
msg.param.to_string(), msg.param.to_string(),
msg.hidden, msg.hidden,
@@ -1653,7 +1653,7 @@ impl Chat {
timestamp, timestamp,
msg.viewtype, msg.viewtype,
msg.state, msg.state,
msg.text.as_ref().cloned().unwrap_or_default(), msg.text,
&msg.subject, &msg.subject,
msg.param.to_string(), msg.param.to_string(),
msg.hidden, msg.hidden,
@@ -2204,9 +2204,7 @@ pub async fn send_msg_sync(context: &Context, chat_id: ChatId, msg: &mut Message
async fn send_msg_inner(context: &Context, chat_id: ChatId, msg: &mut Message) -> Result<MsgId> { async fn send_msg_inner(context: &Context, chat_id: ChatId, msg: &mut Message) -> Result<MsgId> {
// protect all system messages againts RTLO attacks // protect all system messages againts RTLO attacks
if msg.is_system_message() { if msg.is_system_message() {
if let Some(text) = &msg.text { msg.text = strip_rtlo_characters(&msg.text);
msg.text = Some(strip_rtlo_characters(text.as_ref()));
}
} }
if prepare_send_msg(context, chat_id, msg).await?.is_some() { if prepare_send_msg(context, chat_id, msg).await?.is_some() {
@@ -2397,7 +2395,7 @@ pub async fn send_text_msg(
); );
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some(text_to_send); msg.text = text_to_send;
send_msg(context, chat_id, &mut msg).await send_msg(context, chat_id, &mut msg).await
} }
@@ -2423,10 +2421,9 @@ pub async fn send_videochat_invitation(context: &Context, chat_id: ChatId) -> Re
let mut msg = Message::new(Viewtype::VideochatInvitation); let mut msg = Message::new(Viewtype::VideochatInvitation);
msg.param.set(Param::WebrtcRoom, &instance); msg.param.set(Param::WebrtcRoom, &instance);
msg.text = Some( msg.text =
stock_str::videochat_invite_msg_body(context, &Message::parse_webrtc_instance(&instance).1) stock_str::videochat_invite_msg_body(context, &Message::parse_webrtc_instance(&instance).1)
.await, .await;
);
send_msg(context, chat_id, &mut msg).await send_msg(context, chat_id, &mut msg).await
} }
@@ -3057,8 +3054,7 @@ pub(crate) async fn add_contact_to_chat_ex(
if chat.typ == Chattype::Group && chat.is_promoted() { if chat.typ == Chattype::Group && chat.is_promoted() {
msg.viewtype = Viewtype::Text; msg.viewtype = Viewtype::Text;
msg.text = msg.text = stock_str::msg_add_member(context, contact.get_addr(), ContactId::SELF).await;
Some(stock_str::msg_add_member(context, contact.get_addr(), ContactId::SELF).await);
msg.param.set_cmd(SystemMessage::MemberAddedToGroup); msg.param.set_cmd(SystemMessage::MemberAddedToGroup);
msg.param.set(Param::Arg, contact.get_addr()); msg.param.set(Param::Arg, contact.get_addr());
msg.param.set_int(Param::Arg2, from_handshake.into()); msg.param.set_int(Param::Arg2, from_handshake.into());
@@ -3198,12 +3194,11 @@ pub async fn remove_contact_from_chat(
msg.viewtype = Viewtype::Text; msg.viewtype = Viewtype::Text;
if contact.id == ContactId::SELF { if contact.id == ContactId::SELF {
set_group_explicitly_left(context, &chat.grpid).await?; set_group_explicitly_left(context, &chat.grpid).await?;
msg.text = Some(stock_str::msg_group_left(context, ContactId::SELF).await); msg.text = stock_str::msg_group_left(context, ContactId::SELF).await;
} else { } else {
msg.text = Some( msg.text =
stock_str::msg_del_member(context, contact.get_addr(), ContactId::SELF) stock_str::msg_del_member(context, contact.get_addr(), ContactId::SELF)
.await, .await;
);
} }
msg.param.set_cmd(SystemMessage::MemberRemovedFromGroup); msg.param.set_cmd(SystemMessage::MemberRemovedFromGroup);
msg.param.set(Param::Arg, contact.get_addr()); msg.param.set(Param::Arg, contact.get_addr());
@@ -3285,9 +3280,8 @@ pub async fn set_chat_name(context: &Context, chat_id: ChatId, new_name: &str) -
&& improve_single_line_input(&chat.name) != new_name && improve_single_line_input(&chat.name) != new_name
{ {
msg.viewtype = Viewtype::Text; msg.viewtype = Viewtype::Text;
msg.text = Some( msg.text =
stock_str::msg_grp_name(context, &chat.name, &new_name, ContactId::SELF).await, stock_str::msg_grp_name(context, &chat.name, &new_name, ContactId::SELF).await;
);
msg.param.set_cmd(SystemMessage::GroupNameChanged); msg.param.set_cmd(SystemMessage::GroupNameChanged);
if !chat.name.is_empty() { if !chat.name.is_empty() {
msg.param.set(Param::Arg, &chat.name); msg.param.set(Param::Arg, &chat.name);
@@ -3336,13 +3330,13 @@ pub async fn set_chat_profile_image(
if new_image.is_empty() { if new_image.is_empty() {
chat.param.remove(Param::ProfileImage); chat.param.remove(Param::ProfileImage);
msg.param.remove(Param::Arg); msg.param.remove(Param::Arg);
msg.text = Some(stock_str::msg_grp_img_deleted(context, ContactId::SELF).await); msg.text = stock_str::msg_grp_img_deleted(context, ContactId::SELF).await;
} else { } else {
let mut image_blob = BlobObject::new_from_path(context, Path::new(new_image)).await?; let mut image_blob = BlobObject::new_from_path(context, Path::new(new_image)).await?;
image_blob.recode_to_avatar_size(context).await?; image_blob.recode_to_avatar_size(context).await?;
chat.param.set(Param::ProfileImage, image_blob.as_name()); chat.param.set(Param::ProfileImage, image_blob.as_name());
msg.param.set(Param::Arg, image_blob.as_name()); msg.param.set(Param::Arg, image_blob.as_name());
msg.text = Some(stock_str::msg_grp_img_changed(context, ContactId::SELF).await); msg.text = stock_str::msg_grp_img_changed(context, ContactId::SELF).await;
} }
chat.update_param(context).await?; chat.update_param(context).await?;
if chat.is_promoted() && !chat.is_mailing_list() { if chat.is_promoted() && !chat.is_mailing_list() {
@@ -3617,7 +3611,7 @@ pub async fn add_device_msg_with_importance(
timestamp_sent, // timestamp_sent equals timestamp_rcvd timestamp_sent, // timestamp_sent equals timestamp_rcvd
msg.viewtype, msg.viewtype,
state, state,
msg.text.as_ref().cloned().unwrap_or_default(), &msg.text,
msg.param.to_string(), msg.param.to_string(),
rfc724_mid, rfc724_mid,
), ),
@@ -3854,7 +3848,7 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
let chat_id = &t.get_self_chat().await.id; let chat_id = &t.get_self_chat().await.id;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("hello".to_string())); msg.set_text("hello".to_string());
chat_id.set_draft(&t, Some(&mut msg)).await.unwrap(); chat_id.set_draft(&t, Some(&mut msg)).await.unwrap();
let draft = chat_id.get_draft(&t).await.unwrap().unwrap(); let draft = chat_id.get_draft(&t).await.unwrap().unwrap();
@@ -3869,12 +3863,12 @@ mod tests {
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "abc").await?; let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "abc").await?;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("hi!".to_string())); msg.set_text("hi!".to_string());
chat_id.set_draft(&t, Some(&mut msg)).await?; chat_id.set_draft(&t, Some(&mut msg)).await?;
assert!(chat_id.get_draft(&t).await?.is_some()); assert!(chat_id.get_draft(&t).await?.is_some());
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("another".to_string())); msg.set_text("another".to_string());
chat_id.set_draft(&t, Some(&mut msg)).await?; chat_id.set_draft(&t, Some(&mut msg)).await?;
assert!(chat_id.get_draft(&t).await?.is_some()); assert!(chat_id.get_draft(&t).await?.is_some());
@@ -3889,7 +3883,7 @@ mod tests {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let chat_id = &t.get_self_chat().await.id; let chat_id = &t.get_self_chat().await.id;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("hello".to_string())); msg.set_text("hello".to_string());
chat_id.set_draft(&t, Some(&mut msg)).await?; chat_id.set_draft(&t, Some(&mut msg)).await?;
assert_eq!(msg.id, chat_id.get_draft(&t).await?.unwrap().id); assert_eq!(msg.id, chat_id.get_draft(&t).await?.unwrap().id);
@@ -3903,7 +3897,7 @@ mod tests {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let chat_id = &t.get_self_chat().await.id; let chat_id = &t.get_self_chat().await.id;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("hello".to_string())); msg.set_text("hello".to_string());
assert_eq!(msg.id, MsgId::new_unset()); assert_eq!(msg.id, MsgId::new_unset());
assert!(chat_id.get_draft_msg_id(&t).await?.is_none()); assert!(chat_id.get_draft_msg_id(&t).await?.is_none());
@@ -3916,7 +3910,7 @@ mod tests {
); );
assert_eq!(id_after_1st_set, chat_id.get_draft(&t).await?.unwrap().id); assert_eq!(id_after_1st_set, chat_id.get_draft(&t).await?.unwrap().id);
msg.set_text(Some("hello2".to_string())); msg.set_text("hello2".to_string());
chat_id.set_draft(&t, Some(&mut msg)).await?; chat_id.set_draft(&t, Some(&mut msg)).await?;
let id_after_2nd_set = msg.id; let id_after_2nd_set = msg.id;
@@ -3928,7 +3922,7 @@ mod tests {
let test = chat_id.get_draft(&t).await?.unwrap(); let test = chat_id.get_draft(&t).await?.unwrap();
assert_eq!(id_after_2nd_set, test.id); assert_eq!(id_after_2nd_set, test.id);
assert_eq!(id_after_2nd_set, msg.id); assert_eq!(id_after_2nd_set, msg.id);
assert_eq!(test.text, Some("hello2".to_string())); assert_eq!(test.text, "hello2".to_string());
assert_eq!(test.state, MessageState::OutDraft); assert_eq!(test.state, MessageState::OutDraft);
let id_after_prepare = prepare_msg(&t, *chat_id, &mut msg).await?; let id_after_prepare = prepare_msg(&t, *chat_id, &mut msg).await?;
@@ -3956,11 +3950,11 @@ mod tests {
// save a draft // save a draft
let mut draft = Message::new(Viewtype::Text); let mut draft = Message::new(Viewtype::Text);
draft.set_text(Some("draft text".to_string())); draft.set_text("draft text".to_string());
chat_id.set_draft(&t, Some(&mut draft)).await?; chat_id.set_draft(&t, Some(&mut draft)).await?;
let test = Message::load_from_db(&t, draft.id).await?; let test = Message::load_from_db(&t, draft.id).await?;
assert_eq!(test.text, Some("draft text".to_string())); assert_eq!(test.text, "draft text".to_string());
assert!(test.quoted_text().is_none()); assert!(test.quoted_text().is_none());
assert!(test.quoted_message(&t).await?.is_none()); assert!(test.quoted_message(&t).await?.is_none());
@@ -3969,17 +3963,17 @@ mod tests {
chat_id.set_draft(&t, Some(&mut draft)).await?; chat_id.set_draft(&t, Some(&mut draft)).await?;
let test = Message::load_from_db(&t, draft.id).await?; let test = Message::load_from_db(&t, draft.id).await?;
assert_eq!(test.text, Some("draft text".to_string())); assert_eq!(test.text, "draft text".to_string());
assert_eq!(test.quoted_text(), Some("quote1".to_string())); assert_eq!(test.quoted_text(), Some("quote1".to_string()));
assert_eq!(test.quoted_message(&t).await?.unwrap().id, quote1.id); assert_eq!(test.quoted_message(&t).await?.unwrap().id, quote1.id);
// change quote on same message object // change quote on same message object
draft.set_text(Some("another draft text".to_string())); draft.set_text("another draft text".to_string());
draft.set_quote(&t, Some(&quote2)).await?; draft.set_quote(&t, Some(&quote2)).await?;
chat_id.set_draft(&t, Some(&mut draft)).await?; chat_id.set_draft(&t, Some(&mut draft)).await?;
let test = Message::load_from_db(&t, draft.id).await?; let test = Message::load_from_db(&t, draft.id).await?;
assert_eq!(test.text, Some("another draft text".to_string())); assert_eq!(test.text, "another draft text".to_string());
assert_eq!(test.quoted_text(), Some("quote2".to_string())); assert_eq!(test.quoted_text(), Some("quote2".to_string()));
assert_eq!(test.quoted_message(&t).await?.unwrap().id, quote2.id); assert_eq!(test.quoted_message(&t).await?.unwrap().id, quote2.id);
@@ -3988,7 +3982,7 @@ mod tests {
chat_id.set_draft(&t, Some(&mut draft)).await?; chat_id.set_draft(&t, Some(&mut draft)).await?;
let test = Message::load_from_db(&t, draft.id).await?; let test = Message::load_from_db(&t, draft.id).await?;
assert_eq!(test.text, Some("another draft text".to_string())); assert_eq!(test.text, "another draft text".to_string());
assert!(test.quoted_text().is_none()); assert!(test.quoted_text().is_none());
assert!(test.quoted_message(&t).await?.is_none()); assert!(test.quoted_message(&t).await?.is_none());
@@ -4251,7 +4245,7 @@ mod tests {
t2.recv_msg(&sent_msg).await; t2.recv_msg(&sent_msg).await;
let chat = &t2.get_self_chat().await; let chat = &t2.get_self_chat().await;
let msg = t2.get_last_msg_in(chat.id).await; let msg = t2.get_last_msg_in(chat.id).await;
assert_eq!(msg.text, Some("foo self".to_string())); assert_eq!(msg.text, "foo self".to_string());
assert_eq!(msg.from_id, ContactId::SELF); assert_eq!(msg.from_id, ContactId::SELF);
assert_eq!(msg.to_id, ContactId::SELF); assert_eq!(msg.to_id, ContactId::SELF);
assert!(msg.get_showpadlock()); assert!(msg.get_showpadlock());
@@ -4265,12 +4259,12 @@ mod tests {
// add two device-messages // add two device-messages
let mut msg1 = Message::new(Viewtype::Text); let mut msg1 = Message::new(Viewtype::Text);
msg1.text = Some("first message".to_string()); msg1.set_text("first message".to_string());
let msg1_id = add_device_msg(&t, None, Some(&mut msg1)).await; let msg1_id = add_device_msg(&t, None, Some(&mut msg1)).await;
assert!(msg1_id.is_ok()); assert!(msg1_id.is_ok());
let mut msg2 = Message::new(Viewtype::Text); let mut msg2 = Message::new(Viewtype::Text);
msg2.text = Some("second message".to_string()); msg2.set_text("second message".to_string());
let msg2_id = add_device_msg(&t, None, Some(&mut msg2)).await; let msg2_id = add_device_msg(&t, None, Some(&mut msg2)).await;
assert!(msg2_id.is_ok()); assert!(msg2_id.is_ok());
assert_ne!(msg1_id.as_ref().unwrap(), msg2_id.as_ref().unwrap()); assert_ne!(msg1_id.as_ref().unwrap(), msg2_id.as_ref().unwrap());
@@ -4279,7 +4273,7 @@ mod tests {
let msg1 = message::Message::load_from_db(&t, msg1_id.unwrap()).await; let msg1 = message::Message::load_from_db(&t, msg1_id.unwrap()).await;
assert!(msg1.is_ok()); assert!(msg1.is_ok());
let msg1 = msg1.unwrap(); let msg1 = msg1.unwrap();
assert_eq!(msg1.text.as_ref().unwrap(), "first message"); assert_eq!(msg1.text, "first message");
assert_eq!(msg1.from_id, ContactId::DEVICE); assert_eq!(msg1.from_id, ContactId::DEVICE);
assert_eq!(msg1.to_id, ContactId::SELF); assert_eq!(msg1.to_id, ContactId::SELF);
assert!(!msg1.is_info()); assert!(!msg1.is_info());
@@ -4288,7 +4282,7 @@ mod tests {
let msg2 = message::Message::load_from_db(&t, msg2_id.unwrap()).await; let msg2 = message::Message::load_from_db(&t, msg2_id.unwrap()).await;
assert!(msg2.is_ok()); assert!(msg2.is_ok());
let msg2 = msg2.unwrap(); let msg2 = msg2.unwrap();
assert_eq!(msg2.text.as_ref().unwrap(), "second message"); assert_eq!(msg2.text, "second message");
// check device chat // check device chat
assert_eq!(msg2.chat_id.get_msg_cnt(&t).await.unwrap(), 2); assert_eq!(msg2.chat_id.get_msg_cnt(&t).await.unwrap(), 2);
@@ -4300,13 +4294,13 @@ mod tests {
// add two device-messages with the same label (second attempt is not added) // add two device-messages with the same label (second attempt is not added)
let mut msg1 = Message::new(Viewtype::Text); let mut msg1 = Message::new(Viewtype::Text);
msg1.text = Some("first message".to_string()); msg1.text = "first message".to_string();
let msg1_id = add_device_msg(&t, Some("any-label"), Some(&mut msg1)).await; let msg1_id = add_device_msg(&t, Some("any-label"), Some(&mut msg1)).await;
assert!(msg1_id.is_ok()); assert!(msg1_id.is_ok());
assert!(!msg1_id.as_ref().unwrap().is_unset()); assert!(!msg1_id.as_ref().unwrap().is_unset());
let mut msg2 = Message::new(Viewtype::Text); let mut msg2 = Message::new(Viewtype::Text);
msg2.text = Some("second message".to_string()); msg2.text = "second message".to_string();
let msg2_id = add_device_msg(&t, Some("any-label"), Some(&mut msg2)).await; let msg2_id = add_device_msg(&t, Some("any-label"), Some(&mut msg2)).await;
assert!(msg2_id.is_ok()); assert!(msg2_id.is_ok());
assert!(msg2_id.as_ref().unwrap().is_unset()); assert!(msg2_id.as_ref().unwrap().is_unset());
@@ -4314,7 +4308,7 @@ mod tests {
// check added message // check added message
let msg1 = message::Message::load_from_db(&t, *msg1_id.as_ref().unwrap()).await?; let msg1 = message::Message::load_from_db(&t, *msg1_id.as_ref().unwrap()).await?;
assert_eq!(msg1_id.as_ref().unwrap(), &msg1.id); assert_eq!(msg1_id.as_ref().unwrap(), &msg1.id);
assert_eq!(msg1.text.as_ref().unwrap(), "first message"); assert_eq!(msg1.text, "first message");
assert_eq!(msg1.from_id, ContactId::DEVICE); assert_eq!(msg1.from_id, ContactId::DEVICE);
assert_eq!(msg1.to_id, ContactId::SELF); assert_eq!(msg1.to_id, ContactId::SELF);
assert!(!msg1.is_info()); assert!(!msg1.is_info());
@@ -4354,7 +4348,7 @@ mod tests {
assert!(res.is_ok()); assert!(res.is_ok());
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("message text".to_string()); msg.set_text("message text".to_string());
let msg_id = add_device_msg(&t, Some("some-label"), Some(&mut msg)).await; let msg_id = add_device_msg(&t, Some("some-label"), Some(&mut msg)).await;
assert!(msg_id.is_ok()); assert!(msg_id.is_ok());
@@ -4372,7 +4366,7 @@ mod tests {
assert!(was_device_msg_ever_added(&t, "some-label").await.unwrap()); assert!(was_device_msg_ever_added(&t, "some-label").await.unwrap());
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("message text".to_string()); msg.set_text("message text".to_string());
add_device_msg(&t, Some("another-label"), Some(&mut msg)) add_device_msg(&t, Some("another-label"), Some(&mut msg))
.await .await
.ok(); .ok();
@@ -4390,7 +4384,7 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("message text".to_string()); msg.set_text("message text".to_string());
add_device_msg(&t, Some("some-label"), Some(&mut msg)) add_device_msg(&t, Some("some-label"), Some(&mut msg))
.await .await
.ok(); .ok();
@@ -4414,7 +4408,7 @@ mod tests {
.unwrap(); .unwrap();
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("message text".to_string()); msg.set_text("message text".to_string());
assert!(send_msg(&t, device_chat_id, &mut msg).await.is_err()); assert!(send_msg(&t, device_chat_id, &mut msg).await.is_err());
assert!(prepare_msg(&t, device_chat_id, &mut msg).await.is_err()); assert!(prepare_msg(&t, device_chat_id, &mut msg).await.is_err());
@@ -4426,7 +4420,7 @@ mod tests {
async fn test_delete_and_reset_all_device_msgs() { async fn test_delete_and_reset_all_device_msgs() {
let t = TestContext::new().await; let t = TestContext::new().await;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("message text".to_string()); msg.set_text("message text".to_string());
let msg_id1 = add_device_msg(&t, Some("some-label"), Some(&mut msg)) let msg_id1 = add_device_msg(&t, Some("some-label"), Some(&mut msg))
.await .await
.unwrap(); .unwrap();
@@ -4459,7 +4453,7 @@ mod tests {
// create two chats // create two chats
let t = TestContext::new().await; let t = TestContext::new().await;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("foo".to_string()); msg.set_text("foo".to_string());
let msg_id = add_device_msg(&t, None, Some(&mut msg)).await.unwrap(); let msg_id = add_device_msg(&t, None, Some(&mut msg)).await.unwrap();
let chat_id1 = message::Message::load_from_db(&t, msg_id) let chat_id1 = message::Message::load_from_db(&t, msg_id)
.await .await
@@ -4740,7 +4734,7 @@ mod tests {
// create 3 chats, wait 1 second in between to get a reliable order (we order by time) // create 3 chats, wait 1 second in between to get a reliable order (we order by time)
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("foo".to_string()); msg.set_text("foo".to_string());
let msg_id = add_device_msg(&t, None, Some(&mut msg)).await.unwrap(); let msg_id = add_device_msg(&t, None, Some(&mut msg)).await.unwrap();
let chat_id1 = message::Message::load_from_db(&t, msg_id) let chat_id1 = message::Message::load_from_db(&t, msg_id)
.await .await
@@ -4818,7 +4812,7 @@ mod tests {
); );
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("hi!".into())); msg.set_text("hi!".into());
let sent_msg = bob.send_msg(bob_chat_id, &mut msg).await; let sent_msg = bob.send_msg(bob_chat_id, &mut msg).await;
let msg = alice.recv_msg(&sent_msg).await; let msg = alice.recv_msg(&sent_msg).await;
assert_eq!(msg.chat_id, alice_chat_id); assert_eq!(msg.chat_id, alice_chat_id);
@@ -4956,7 +4950,7 @@ mod tests {
let msg = t.get_last_msg_in(chat_id).await; let msg = t.get_last_msg_in(chat_id).await;
assert_eq!(msg.get_chat_id(), chat_id); assert_eq!(msg.get_chat_id(), chat_id);
assert_eq!(msg.get_viewtype(), Viewtype::Text); assert_eq!(msg.get_viewtype(), Viewtype::Text);
assert_eq!(msg.get_text().unwrap(), "foo info"); assert_eq!(msg.get_text(), "foo info");
assert!(msg.is_info()); assert!(msg.is_info());
assert_eq!(msg.get_info_type(), SystemMessage::Unknown); assert_eq!(msg.get_info_type(), SystemMessage::Unknown);
assert!(msg.parent(&t).await?.is_none()); assert!(msg.parent(&t).await?.is_none());
@@ -4983,7 +4977,7 @@ mod tests {
let msg = Message::load_from_db(&t, msg_id).await?; let msg = Message::load_from_db(&t, msg_id).await?;
assert_eq!(msg.get_chat_id(), chat_id); assert_eq!(msg.get_chat_id(), chat_id);
assert_eq!(msg.get_viewtype(), Viewtype::Text); assert_eq!(msg.get_viewtype(), Viewtype::Text);
assert_eq!(msg.get_text().unwrap(), "foo bar info"); assert_eq!(msg.get_text(), "foo bar info");
assert!(msg.is_info()); assert!(msg.is_info());
assert_eq!(msg.get_info_type(), SystemMessage::EphemeralTimerChanged); assert_eq!(msg.get_info_type(), SystemMessage::EphemeralTimerChanged);
assert!(msg.parent(&t).await?.is_none()); assert!(msg.parent(&t).await?.is_none());
@@ -5170,7 +5164,7 @@ mod tests {
receive_imf(&alice, msg.as_bytes(), false).await.unwrap(); receive_imf(&alice, msg.as_bytes(), false).await.unwrap();
let msg = alice.get_last_msg().await; let msg = alice.get_last_msg().await;
assert_eq!(msg.chat_id, alice_chat_id); assert_eq!(msg.chat_id, alice_chat_id);
assert_eq!(msg.text, Some("ho!".to_string())); assert_eq!(msg.text, "ho!".to_string());
assert_eq!(get_chat_msgs(&alice, alice_chat_id).await?.len(), 2); assert_eq!(get_chat_msgs(&alice, alice_chat_id).await?.len(), 2);
Ok(()) Ok(())
} }
@@ -5464,7 +5458,7 @@ mod tests {
let bob_chat = bob.create_chat(&alice).await; let bob_chat = bob.create_chat(&alice).await;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("Hi Bob".to_owned())); msg.set_text("Hi Bob".to_owned());
let sent_msg = alice.send_msg(alice_chat.get_id(), &mut msg).await; let sent_msg = alice.send_msg(alice_chat.get_id(), &mut msg).await;
let msg = bob.recv_msg(&sent_msg).await; let msg = bob.recv_msg(&sent_msg).await;
@@ -5472,7 +5466,7 @@ mod tests {
let forwarded_msg = bob.pop_sent_msg().await; let forwarded_msg = bob.pop_sent_msg().await;
let msg = alice.recv_msg(&forwarded_msg).await; let msg = alice.recv_msg(&forwarded_msg).await;
assert!(msg.get_text().unwrap() == "Hi Bob"); assert_eq!(msg.get_text(), "Hi Bob");
assert!(msg.is_forwarded()); assert!(msg.is_forwarded());
Ok(()) Ok(())
} }
@@ -5487,7 +5481,7 @@ mod tests {
add_contact_to_chat(&t, chat_id1, bob_id).await?; add_contact_to_chat(&t, chat_id1, bob_id).await?;
let msg1 = t.get_last_msg_in(chat_id1).await; let msg1 = t.get_last_msg_in(chat_id1).await;
assert!(msg1.is_info()); assert!(msg1.is_info());
assert!(msg1.get_text().unwrap().contains("bob@example.net")); assert!(msg1.get_text().contains("bob@example.net"));
let chat_id2 = ChatId::create_for_contact(&t, bob_id).await?; let chat_id2 = ChatId::create_for_contact(&t, bob_id).await?;
assert_eq!(get_chat_msgs(&t, chat_id2).await?.len(), 0); assert_eq!(get_chat_msgs(&t, chat_id2).await?.len(), 0);
@@ -5497,7 +5491,7 @@ mod tests {
assert_eq!(msg2.get_info_type(), SystemMessage::Unknown); assert_eq!(msg2.get_info_type(), SystemMessage::Unknown);
assert_ne!(msg2.from_id, ContactId::INFO); assert_ne!(msg2.from_id, ContactId::INFO);
assert_ne!(msg2.to_id, ContactId::INFO); assert_ne!(msg2.to_id, ContactId::INFO);
assert_eq!(msg2.get_text().unwrap(), msg1.get_text().unwrap()); assert_eq!(msg2.get_text(), msg1.get_text());
assert!(msg2.is_forwarded()); assert!(msg2.is_forwarded());
Ok(()) Ok(())
@@ -5516,7 +5510,7 @@ mod tests {
// Bob quotes received message and sends a reply to Alice. // Bob quotes received message and sends a reply to Alice.
let mut reply = Message::new(Viewtype::Text); let mut reply = Message::new(Viewtype::Text);
reply.set_text(Some("Reply".to_owned())); reply.set_text("Reply".to_owned());
reply.set_quote(&bob, Some(&received_msg)).await?; reply.set_quote(&bob, Some(&received_msg)).await?;
let sent_reply = bob.send_msg(bob_chat.id, &mut reply).await; let sent_reply = bob.send_msg(bob_chat.id, &mut reply).await;
let received_reply = alice.recv_msg(&sent_reply).await; let received_reply = alice.recv_msg(&sent_reply).await;
@@ -5567,13 +5561,13 @@ mod tests {
// Alice sends a message to Bob. // Alice sends a message to Bob.
let sent_msg = alice.send_text(alice_chat.id, "Hi Bob").await; let sent_msg = alice.send_text(alice_chat.id, "Hi Bob").await;
let received_msg = bob.recv_msg(&sent_msg).await; let received_msg = bob.recv_msg(&sent_msg).await;
assert_eq!(received_msg.get_text(), Some("Hi Bob".to_string())); assert_eq!(received_msg.get_text(), "Hi Bob");
assert_eq!(received_msg.chat_id, bob_chat.id); assert_eq!(received_msg.chat_id, bob_chat.id);
// Alice sends another message to Bob, this has first message as a parent. // Alice sends another message to Bob, this has first message as a parent.
let sent_msg = alice.send_text(alice_chat.id, "Hello Bob").await; let sent_msg = alice.send_text(alice_chat.id, "Hello Bob").await;
let received_msg = bob.recv_msg(&sent_msg).await; let received_msg = bob.recv_msg(&sent_msg).await;
assert_eq!(received_msg.get_text(), Some("Hello Bob".to_string())); assert_eq!(received_msg.get_text(), "Hello Bob");
assert_eq!(received_msg.chat_id, bob_chat.id); assert_eq!(received_msg.chat_id, bob_chat.id);
// Bob forwards message to a group chat with Alice. // Bob forwards message to a group chat with Alice.
@@ -5600,7 +5594,7 @@ mod tests {
create_group_chat(&alice, ProtectionStatus::Unprotected, "secretgrpname").await?; create_group_chat(&alice, ProtectionStatus::Unprotected, "secretgrpname").await?;
add_contact_to_chat(&alice, group_id, bob_id).await?; add_contact_to_chat(&alice, group_id, bob_id).await?;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("bla foo".to_owned())); msg.set_text("bla foo".to_owned());
let sent_msg = alice.send_msg(group_id, &mut msg).await; let sent_msg = alice.send_msg(group_id, &mut msg).await;
assert!(sent_msg.payload().contains("secretgrpname")); assert!(sent_msg.payload().contains("secretgrpname"));
assert!(sent_msg.payload().contains("secretname")); assert!(sent_msg.payload().contains("secretname"));
@@ -5657,7 +5651,7 @@ mod tests {
// Bob receives all messages // Bob receives all messages
let bob = TestContext::new_bob().await; let bob = TestContext::new_bob().await;
let msg = bob.recv_msg(&sent1).await; let msg = bob.recv_msg(&sent1).await;
assert_eq!(msg.get_text().unwrap(), "alice->bob"); assert_eq!(msg.get_text(), "alice->bob");
assert_eq!(get_chat_contacts(&bob, msg.chat_id).await?.len(), 2); assert_eq!(get_chat_contacts(&bob, msg.chat_id).await?.len(), 2);
assert_eq!(get_chat_msgs(&bob, msg.chat_id).await?.len(), 1); assert_eq!(get_chat_msgs(&bob, msg.chat_id).await?.len(), 1);
bob.recv_msg(&sent2).await; bob.recv_msg(&sent2).await;
@@ -5674,7 +5668,7 @@ mod tests {
claire.configure_addr("claire@example.org").await; claire.configure_addr("claire@example.org").await;
claire.recv_msg(&sent2).await; claire.recv_msg(&sent2).await;
let msg = claire.recv_msg(&sent3).await; let msg = claire.recv_msg(&sent3).await;
assert_eq!(msg.get_text().unwrap(), "alice->bob"); assert_eq!(msg.get_text(), "alice->bob");
assert_eq!(get_chat_contacts(&claire, msg.chat_id).await?.len(), 3); assert_eq!(get_chat_contacts(&claire, msg.chat_id).await?.len(), 3);
assert_eq!(get_chat_msgs(&claire, msg.chat_id).await?.len(), 2); assert_eq!(get_chat_msgs(&claire, msg.chat_id).await?.len(), 2);
let msg_from = Contact::get_by_id(&claire, msg.get_from_id()).await?; let msg_from = Contact::get_by_id(&claire, msg.get_from_id()).await?;
@@ -5822,7 +5816,7 @@ mod tests {
assert_eq!(msg.chat_id, chat.id); assert_eq!(msg.chat_id, chat.id);
let msg = bob.recv_msg(&alice.pop_sent_msg().await).await; let msg = bob.recv_msg(&alice.pop_sent_msg().await).await;
assert_eq!(msg.get_text(), Some("ola!".to_string())); assert_eq!(msg.get_text(), "ola!");
assert!(!msg.get_showpadlock()); // avoid leaking recipients in encryption data assert!(!msg.get_showpadlock()); // avoid leaking recipients in encryption data
let chat = Chat::load_from_db(&bob, msg.chat_id).await?; let chat = Chat::load_from_db(&bob, msg.chat_id).await?;
assert_eq!(chat.typ, Chattype::Single); assert_eq!(chat.typ, Chattype::Single);

View File

@@ -424,7 +424,7 @@ mod tests {
// 2s here. // 2s here.
for chat_id in &[chat_id1, chat_id3, chat_id2] { for chat_id in &[chat_id1, chat_id3, chat_id2] {
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("hello".to_string())); msg.set_text("hello".to_string());
chat_id.set_draft(&t, Some(&mut msg)).await.unwrap(); chat_id.set_draft(&t, Some(&mut msg)).await.unwrap();
} }
@@ -636,7 +636,7 @@ mod tests {
.unwrap(); .unwrap();
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("foo:\nbar \r\n test".to_string())); msg.set_text("foo:\nbar \r\n test".to_string());
chat_id1.set_draft(&t, Some(&mut msg)).await.unwrap(); chat_id1.set_draft(&t, Some(&mut msg)).await.unwrap();
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();

View File

@@ -146,7 +146,7 @@ async fn on_configure_completed(
if !provider.after_login_hint.is_empty() { if !provider.after_login_hint.is_empty() {
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some(provider.after_login_hint.to_string()); msg.text = provider.after_login_hint.to_string();
if chat::add_device_msg(context, Some("core-provider-info"), Some(&mut msg)) if chat::add_device_msg(context, Some("core-provider-info"), Some(&mut msg))
.await .await
.is_err() .is_err()
@@ -161,7 +161,7 @@ async fn on_configure_completed(
if !addr_cmp(&new_addr, &old_addr) { if !addr_cmp(&new_addr, &old_addr) {
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = msg.text =
Some(stock_str::aeap_explanation_and_link(context, &old_addr, &new_addr).await); stock_str::aeap_explanation_and_link(context, &old_addr, &new_addr).await;
chat::add_device_msg(context, None, Some(&mut msg)) chat::add_device_msg(context, None, Some(&mut msg))
.await .await
.context("Cannot add AEAP explanation") .context("Cannot add AEAP explanation")

View File

@@ -1304,11 +1304,11 @@ mod tests {
// Add messages to chat with Bob. // Add messages to chat with Bob.
let mut msg1 = Message::new(Viewtype::Text); let mut msg1 = Message::new(Viewtype::Text);
msg1.set_text(Some("foobar".to_string())); msg1.set_text("foobar".to_string());
send_msg(&alice, chat.id, &mut msg1).await?; send_msg(&alice, chat.id, &mut msg1).await?;
let mut msg2 = Message::new(Viewtype::Text); let mut msg2 = Message::new(Viewtype::Text);
msg2.set_text(Some("barbaz".to_string())); msg2.set_text("barbaz".to_string());
send_msg(&alice, chat.id, &mut msg2).await?; send_msg(&alice, chat.id, &mut msg2).await?;
// Global search with a part of text finds the message. // Global search with a part of text finds the message.
@@ -1404,7 +1404,7 @@ mod tests {
// Add 999 messages // Add 999 messages
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("foobar".to_string())); msg.set_text("foobar".to_string());
for _ in 0..999 { for _ in 0..999 {
send_msg(&alice, chat.id, &mut msg).await?; send_msg(&alice, chat.id, &mut msg).await?;
} }

View File

@@ -399,7 +399,7 @@ mod tests {
let bob = TestContext::new_bob().await; let bob = TestContext::new_bob().await;
receive_imf(&bob, attachment_mime, false).await?; receive_imf(&bob, attachment_mime, false).await?;
let msg = bob.get_last_msg().await; let msg = bob.get_last_msg().await;
assert_eq!(msg.text.as_deref(), Some("Hello from Thunderbird!")); assert_eq!(msg.text, "Hello from Thunderbird!");
Ok(()) Ok(())
} }

View File

@@ -308,7 +308,7 @@ mod tests {
let chat = t.create_chat_with_contact("Bob", "bob@example.org").await; let chat = t.create_chat_with_contact("Bob", "bob@example.org").await;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("Hi Bob".to_owned())); msg.set_text("Hi Bob".to_owned());
let msg_id = send_msg(&t, chat.id, &mut msg).await?; let msg_id = send_msg(&t, chat.id, &mut msg).await?;
let msg = Message::load_from_db(&t, msg_id).await?; let msg = Message::load_from_db(&t, msg_id).await?;
assert_eq!(msg.download_state(), DownloadState::Done); assert_eq!(msg.download_state(), DownloadState::Done);
@@ -355,7 +355,6 @@ mod tests {
assert_eq!(msg.get_subject(), "foo"); assert_eq!(msg.get_subject(), "foo");
assert!(msg assert!(msg
.get_text() .get_text()
.unwrap()
.contains(&stock_str::partial_download_msg_body(&t, 100000).await)); .contains(&stock_str::partial_download_msg_body(&t, 100000).await));
receive_imf_inner( receive_imf_inner(
@@ -370,7 +369,7 @@ mod tests {
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
assert_eq!(msg.download_state(), DownloadState::Done); assert_eq!(msg.download_state(), DownloadState::Done);
assert_eq!(msg.get_subject(), "foo"); assert_eq!(msg.get_subject(), "foo");
assert_eq!(msg.get_text(), Some("100k text...".to_string())); assert_eq!(msg.get_text(), "100k text...");
Ok(()) Ok(())
} }

View File

@@ -219,7 +219,7 @@ impl ChatId {
if self.is_promoted(context).await? { if self.is_promoted(context).await? {
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some(stock_ephemeral_timer_changed(context, timer, ContactId::SELF).await); msg.text = stock_ephemeral_timer_changed(context, timer, ContactId::SELF).await;
msg.param.set_cmd(SystemMessage::EphemeralTimerChanged); msg.param.set_cmd(SystemMessage::EphemeralTimerChanged);
if let Err(err) = send_msg(context, self, &mut msg).await { if let Err(err) = send_msg(context, self, &mut msg).await {
error!( error!(
@@ -1062,7 +1062,7 @@ mod tests {
delete_expired_messages(t, not_deleted_at).await?; delete_expired_messages(t, not_deleted_at).await?;
let loaded = Message::load_from_db(t, msg_id).await?; let loaded = Message::load_from_db(t, msg_id).await?;
assert_eq!(loaded.text.unwrap(), "Message text"); assert_eq!(loaded.text, "Message text");
assert_eq!(loaded.chat_id, chat.id); assert_eq!(loaded.chat_id, chat.id);
assert!(next_expiration < deleted_at); assert!(next_expiration < deleted_at);
@@ -1082,7 +1082,7 @@ mod tests {
.await; .await;
let loaded = Message::load_from_db(t, msg_id).await?; let loaded = Message::load_from_db(t, msg_id).await?;
assert_eq!(loaded.text.unwrap(), ""); assert_eq!(loaded.text, "");
assert_eq!(loaded.chat_id, DC_CHAT_ID_TRASH); assert_eq!(loaded.chat_id, DC_CHAT_ID_TRASH);
// Check that the msg was deleted locally. // Check that the msg was deleted locally.
@@ -1105,7 +1105,7 @@ mod tests {
if let Ok(msg) = Message::load_from_db(t, msg_id).await { if let Ok(msg) = Message::load_from_db(t, msg_id).await {
assert_eq!(msg.from_id, ContactId::UNDEFINED); assert_eq!(msg.from_id, ContactId::UNDEFINED);
assert_eq!(msg.to_id, ContactId::UNDEFINED); assert_eq!(msg.to_id, ContactId::UNDEFINED);
assert!(msg.text.is_none_or_empty(), "{:?}", msg.text); assert_eq!(msg.text, "");
let rawtxt: Option<String> = t let rawtxt: Option<String> = t
.sql .sql
.query_get_value("SELECT txt_raw FROM msgs WHERE id=?;", (msg_id,)) .query_get_value("SELECT txt_raw FROM msgs WHERE id=?;", (msg_id,))

View File

@@ -456,7 +456,7 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
assert_ne!(msg.get_from_id(), ContactId::SELF); assert_ne!(msg.get_from_id(), ContactId::SELF);
assert_eq!(msg.is_dc_message, MessengerMessage::No); assert_eq!(msg.is_dc_message, MessengerMessage::No);
assert!(!msg.is_forwarded()); assert!(!msg.is_forwarded());
assert!(msg.get_text().unwrap().contains("this is plain")); assert!(msg.get_text().contains("this is plain"));
assert!(msg.has_html()); assert!(msg.has_html());
let html = msg.get_id().get_html(&alice).await.unwrap().unwrap(); let html = msg.get_id().get_html(&alice).await.unwrap().unwrap();
assert!(html.contains("this is <b>html</b>")); assert!(html.contains("this is <b>html</b>"));
@@ -470,7 +470,7 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
assert_eq!(msg.get_from_id(), ContactId::SELF); assert_eq!(msg.get_from_id(), ContactId::SELF);
assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert_eq!(msg.is_dc_message, MessengerMessage::Yes);
assert!(msg.is_forwarded()); assert!(msg.is_forwarded());
assert!(msg.get_text().unwrap().contains("this is plain")); assert!(msg.get_text().contains("this is plain"));
assert!(msg.has_html()); assert!(msg.has_html());
let html = msg.get_id().get_html(&alice).await.unwrap().unwrap(); let html = msg.get_id().get_html(&alice).await.unwrap().unwrap();
assert!(html.contains("this is <b>html</b>")); assert!(html.contains("this is <b>html</b>"));
@@ -483,7 +483,7 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
assert_ne!(msg.get_from_id(), ContactId::SELF); assert_ne!(msg.get_from_id(), ContactId::SELF);
assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert_eq!(msg.is_dc_message, MessengerMessage::Yes);
assert!(msg.is_forwarded()); assert!(msg.is_forwarded());
assert!(msg.get_text().unwrap().contains("this is plain")); assert!(msg.get_text().contains("this is plain"));
assert!(msg.has_html()); assert!(msg.has_html());
let html = msg.get_id().get_html(&bob).await.unwrap().unwrap(); let html = msg.get_id().get_html(&bob).await.unwrap().unwrap();
assert!(html.contains("this is <b>html</b>")); assert!(html.contains("this is <b>html</b>"));
@@ -526,7 +526,7 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert_eq!(msg.is_dc_message, MessengerMessage::Yes);
assert!(msg.get_showpadlock()); assert!(msg.get_showpadlock());
assert!(msg.is_forwarded()); assert!(msg.is_forwarded());
assert!(msg.get_text().unwrap().contains("this is plain")); assert!(msg.get_text().contains("this is plain"));
assert!(msg.has_html()); assert!(msg.has_html());
let html = msg.get_id().get_html(&alice).await.unwrap().unwrap(); let html = msg.get_id().get_html(&alice).await.unwrap().unwrap();
assert!(html.contains("this is <b>html</b>")); assert!(html.contains("this is <b>html</b>"));
@@ -540,14 +540,14 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
// alice sends a message with html-part to bob // alice sends a message with html-part to bob
let chat_id = alice.create_chat(&bob).await.id; let chat_id = alice.create_chat(&bob).await.id;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("plain text".to_string())); msg.set_text("plain text".to_string());
msg.set_html(Some("<b>html</b> text".to_string())); msg.set_html(Some("<b>html</b> text".to_string()));
assert!(msg.mime_modified); assert!(msg.mime_modified);
chat::send_msg(&alice, chat_id, &mut msg).await.unwrap(); chat::send_msg(&alice, chat_id, &mut msg).await.unwrap();
// check the message is written correctly to alice's db // check the message is written correctly to alice's db
let msg = alice.get_last_msg_in(chat_id).await; let msg = alice.get_last_msg_in(chat_id).await;
assert_eq!(msg.get_text(), Some("plain text".to_string())); assert_eq!(msg.get_text(), "plain text");
assert!(!msg.is_forwarded()); assert!(!msg.is_forwarded());
assert!(msg.mime_modified); assert!(msg.mime_modified);
let html = msg.get_id().get_html(&alice).await.unwrap().unwrap(); let html = msg.get_id().get_html(&alice).await.unwrap().unwrap();
@@ -557,7 +557,7 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
let chat_id = bob.create_chat(&alice).await.id; let chat_id = bob.create_chat(&alice).await.id;
let msg = bob.recv_msg(&alice.pop_sent_msg().await).await; let msg = bob.recv_msg(&alice.pop_sent_msg().await).await;
assert_eq!(msg.chat_id, chat_id); assert_eq!(msg.chat_id, chat_id);
assert_eq!(msg.get_text(), Some("plain text".to_string())); assert_eq!(msg.get_text(), "plain text");
assert!(!msg.is_forwarded()); assert!(!msg.is_forwarded());
assert!(msg.mime_modified); assert!(msg.mime_modified);
let html = msg.get_id().get_html(&bob).await.unwrap().unwrap(); let html = msg.get_id().get_html(&bob).await.unwrap().unwrap();
@@ -575,7 +575,7 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
.await?; .await?;
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
assert_eq!(msg.viewtype, Viewtype::Text); assert_eq!(msg.viewtype, Viewtype::Text);
assert!(msg.text.as_ref().unwrap().contains("foo bar ä ö ü ß")); assert!(msg.text.contains("foo bar ä ö ü ß"));
assert!(msg.has_html()); assert!(msg.has_html());
let html = msg.get_id().get_html(&t).await?.unwrap(); let html = msg.get_id().get_html(&t).await?.unwrap();
println!("{html}"); println!("{html}");

View File

@@ -412,7 +412,7 @@ impl Imap {
drop(lock); drop(lock);
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some(message.clone()); msg.text = message.clone();
if let Err(e) = if let Err(e) =
chat::add_device_msg_with_importance(context, None, Some(&mut msg), true) chat::add_device_msg_with_importance(context, None, Some(&mut msg), true)
.await .await

View File

@@ -253,12 +253,10 @@ async fn maybe_add_bcc_self_device_msg(context: &Context) -> Result<()> {
if !context.sql.get_raw_config_bool("bcc_self").await? { if !context.sql.get_raw_config_bool("bcc_self").await? {
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
// TODO: define this as a stockstring once the wording is settled. // TODO: define this as a stockstring once the wording is settled.
msg.text = Some( msg.text = "It seems you are using multiple devices with Delta Chat. Great!\n\n\
"It seems you are using multiple devices with Delta Chat. Great!\n\n\
If you also want to synchronize outgoing messages across all devices, \ If you also want to synchronize outgoing messages across all devices, \
go to \"Settings → Advanced\" and enable \"Send Copy to Self\"." go to \"Settings → Advanced\" and enable \"Send Copy to Self\"."
.to_string(), .to_string();
);
chat::add_device_msg(context, Some("bcc-self-hint"), Some(&mut msg)).await?; chat::add_device_msg(context, Some("bcc-self-hint"), Some(&mut msg)).await?;
} }
Ok(()) Ok(())
@@ -1030,10 +1028,7 @@ mod tests {
// not synchronized yet. // not synchronized yet.
let sent = alice2.send_text(msg.chat_id, "Test").await; let sent = alice2.send_text(msg.chat_id, "Test").await;
alice.recv_msg(&sent).await; alice.recv_msg(&sent).await;
assert_ne!( assert_ne!(alice.get_last_msg().await.get_text(), "Test");
alice.get_last_msg().await.get_text(),
Some("Test".to_string())
);
// Transfer the key. // Transfer the key.
continue_key_transfer(&alice2, msg.id, &setup_code).await?; continue_key_transfer(&alice2, msg.id, &setup_code).await?;
@@ -1041,10 +1036,7 @@ mod tests {
// Alice sends a message to self from the new device. // Alice sends a message to self from the new device.
let sent = alice2.send_text(msg.chat_id, "Test").await; let sent = alice2.send_text(msg.chat_id, "Test").await;
alice.recv_msg(&sent).await; alice.recv_msg(&sent).await;
assert_eq!( assert_eq!(alice.get_last_msg().await.get_text(), "Test");
alice.get_last_msg().await.get_text(),
Some("Test".to_string())
);
Ok(()) Ok(())
} }

View File

@@ -275,7 +275,7 @@ impl BackupProvider {
Ok(_) => { Ok(_) => {
context.emit_event(SendProgress::Completed.into()); context.emit_event(SendProgress::Completed.into());
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some(backup_transfer_msg_body(context).await); msg.text = backup_transfer_msg_body(context).await;
add_device_msg(context, None, Some(&mut msg)).await?; add_device_msg(context, None, Some(&mut msg)).await?;
} }
Err(err) => { Err(err) => {
@@ -611,7 +611,7 @@ mod tests {
// Write a message in the self chat // Write a message in the self chat
let self_chat = ctx0.get_self_chat().await; let self_chat = ctx0.get_self_chat().await;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("hi there".to_string())); msg.set_text("hi there".to_string());
send_msg(&ctx0, self_chat.id, &mut msg).await.unwrap(); send_msg(&ctx0, self_chat.id, &mut msg).await.unwrap();
// Send an attachment in the self chat // Send an attachment in the self chat
@@ -643,7 +643,7 @@ mod tests {
_ => panic!("wrong chat item"), _ => panic!("wrong chat item"),
}; };
let msg = Message::load_from_db(&ctx1, *msgid).await.unwrap(); let msg = Message::load_from_db(&ctx1, *msgid).await.unwrap();
let text = msg.get_text().unwrap(); let text = msg.get_text();
assert_eq!(text, "hi there"); assert_eq!(text, "hi there");
let msgid = match msgs.get(1).unwrap() { let msgid = match msgs.get(1).unwrap() {
ChatItem::Message { msg_id } => msg_id, ChatItem::Message { msg_id } => msg_id,

View File

@@ -280,7 +280,7 @@ pub async fn send_locations_to_chat(
.await?; .await?;
if 0 != seconds && !is_sending_locations_before { if 0 != seconds && !is_sending_locations_before {
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some(stock_str::msg_location_enabled(context).await); msg.text = stock_str::msg_location_enabled(context).await;
msg.param.set_cmd(SystemMessage::LocationStreamingEnabled); msg.param.set_cmd(SystemMessage::LocationStreamingEnabled);
chat::send_msg(context, chat_id, &mut msg) chat::send_msg(context, chat_id, &mut msg)
.await .await
@@ -885,7 +885,7 @@ Text message."#,
) )
.await?; .await?;
let received_msg = alice.get_last_msg().await; let received_msg = alice.get_last_msg().await;
assert_eq!(received_msg.text.unwrap(), "Text message."); assert_eq!(received_msg.text, "Text message.");
receive_imf( receive_imf(
&alice, &alice,

View File

@@ -258,7 +258,7 @@ pub struct Message {
pub(crate) timestamp_rcvd: i64, pub(crate) timestamp_rcvd: i64,
pub(crate) ephemeral_timer: EphemeralTimer, pub(crate) ephemeral_timer: EphemeralTimer,
pub(crate) ephemeral_timestamp: i64, pub(crate) ephemeral_timestamp: i64,
pub(crate) text: Option<String>, pub(crate) text: String,
/// Message subject. /// Message subject.
/// ///
@@ -367,7 +367,7 @@ impl Message {
.filter(|error| !error.is_empty()), .filter(|error| !error.is_empty()),
is_dc_message: row.get("msgrmsg")?, is_dc_message: row.get("msgrmsg")?,
mime_modified: row.get("mime_modified")?, mime_modified: row.get("mime_modified")?,
text: Some(text), text,
subject: row.get("subject")?, subject: row.get("subject")?,
param: row.get::<_, String>("param")?.parse().unwrap_or_default(), param: row.get::<_, String>("param")?.parse().unwrap_or_default(),
hidden: row.get("hidden")?, hidden: row.get("hidden")?,
@@ -515,8 +515,8 @@ impl Message {
} }
/// Returns the text of the message. /// Returns the text of the message.
pub fn get_text(&self) -> Option<String> { pub fn get_text(&self) -> String {
self.text.as_ref().map(|s| s.to_string()) self.text.clone()
} }
/// Returns message subject. /// Returns message subject.
@@ -792,7 +792,7 @@ impl Message {
} }
/// Sets or unsets message text. /// Sets or unsets message text.
pub fn set_text(&mut self, text: Option<String>) { pub fn set_text(&mut self, text: String) {
self.text = text; self.text = text;
} }
@@ -884,7 +884,7 @@ impl Message {
self.param.set(Param::GuaranteeE2ee, "1"); self.param.set(Param::GuaranteeE2ee, "1");
} }
let text = quote.get_text().unwrap_or_default(); let text = quote.get_text();
self.param.set( self.param.set(
Param::Quote, Param::Quote,
if text.is_empty() { if text.is_empty() {
@@ -2252,7 +2252,7 @@ mod tests {
let chat = d.create_chat_with_contact("", "dest@example.com").await; let chat = d.create_chat_with_contact("", "dest@example.com").await;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("Quoted message".to_string())); msg.set_text("Quoted message".to_string());
// Prepare message for sending, so it gets a Message-Id. // Prepare message for sending, so it gets a Message-Id.
assert!(msg.rfc724_mid.is_empty()); assert!(msg.rfc724_mid.is_empty());
@@ -2264,14 +2264,14 @@ mod tests {
msg2.set_quote(ctx, Some(&msg)) msg2.set_quote(ctx, Some(&msg))
.await .await
.expect("can't set quote"); .expect("can't set quote");
assert!(msg2.quoted_text() == msg.get_text()); assert_eq!(msg2.quoted_text().unwrap(), msg.get_text());
let quoted_msg = msg2 let quoted_msg = msg2
.quoted_message(ctx) .quoted_message(ctx)
.await .await
.expect("error while retrieving quoted message") .expect("error while retrieving quoted message")
.expect("quoted message not found"); .expect("quoted message not found");
assert!(quoted_msg.get_text() == msg2.quoted_text()); assert_eq!(quoted_msg.get_text(), msg2.quoted_text().unwrap());
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
@@ -2295,7 +2295,7 @@ mod tests {
// check chat-id of this message // check chat-id of this message
let msg = alice.get_last_msg().await; let msg = alice.get_last_msg().await;
assert!(!msg.get_chat_id().is_special()); assert!(!msg.get_chat_id().is_special());
assert_eq!(msg.get_text().unwrap(), "hello".to_string()); assert_eq!(msg.get_text(), "hello".to_string());
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
@@ -2312,7 +2312,7 @@ mod tests {
let contact = Contact::get_by_id(&alice, contact_id).await.unwrap(); let contact = Contact::get_by_id(&alice, contact_id).await.unwrap();
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("bla blubb".to_string())); msg.set_text("bla blubb".to_string());
msg.set_override_sender_name(Some("over ride".to_string())); msg.set_override_sender_name(Some("over ride".to_string()));
assert_eq!( assert_eq!(
msg.get_override_sender_name(), msg.get_override_sender_name(),
@@ -2332,7 +2332,7 @@ mod tests {
let contact = Contact::get_by_id(&bob, contact_id).await.unwrap(); let contact = Contact::get_by_id(&bob, contact_id).await.unwrap();
let msg = bob.recv_msg(&alice.pop_sent_msg().await).await; let msg = bob.recv_msg(&alice.pop_sent_msg().await).await;
assert_eq!(msg.chat_id, chat.id); assert_eq!(msg.chat_id, chat.id);
assert_eq!(msg.text, Some("bla blubb".to_string())); assert_eq!(msg.text, "bla blubb");
assert_eq!( assert_eq!(
msg.get_override_sender_name(), msg.get_override_sender_name(),
Some("over ride".to_string()) Some("over ride".to_string())
@@ -2352,7 +2352,7 @@ mod tests {
let bob = TestContext::new_bob().await; let bob = TestContext::new_bob().await;
let alice_chat = alice.create_chat(&bob).await; let alice_chat = alice.create_chat(&bob).await;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("this is the text!".to_string())); msg.set_text("this is the text!".to_string());
// alice sends to bob, // alice sends to bob,
assert_eq!(Chatlist::try_load(&bob, 0, None, None).await?.len(), 0); assert_eq!(Chatlist::try_load(&bob, 0, None, None).await?.len(), 0);
@@ -2438,7 +2438,7 @@ mod tests {
// check outgoing messages states on sender side // check outgoing messages states on sender side
let mut alice_msg = Message::new(Viewtype::Text); let mut alice_msg = Message::new(Viewtype::Text);
alice_msg.set_text(Some("hi!".to_string())); alice_msg.set_text("hi!".to_string());
assert_eq!(alice_msg.get_state(), MessageState::Undefined); // message not yet in db, assert_state() won't work assert_eq!(alice_msg.get_state(), MessageState::Undefined); // message not yet in db, assert_state() won't work
alice_chat alice_chat
@@ -2494,7 +2494,7 @@ mod tests {
) )
.await?; .await?;
let msg = alice.get_last_msg().await; let msg = alice.get_last_msg().await;
assert_eq!(msg.get_text().unwrap(), "hello".to_string()); assert_eq!(msg.get_text(), "hello".to_string());
assert!(msg.is_bot()); assert!(msg.is_bot());
// Alice receives a message from Bob who is not the bot anymore. // Alice receives a message from Bob who is not the bot anymore.
@@ -2511,7 +2511,7 @@ mod tests {
) )
.await?; .await?;
let msg = alice.get_last_msg().await; let msg = alice.get_last_msg().await;
assert_eq!(msg.get_text().unwrap(), "hello again".to_string()); assert_eq!(msg.get_text(), "hello again".to_string());
assert!(!msg.is_bot()); assert!(!msg.is_bot());
Ok(()) Ok(())
@@ -2550,13 +2550,13 @@ mod tests {
let sent = alice.send_text(chat.id, "> First quote").await; let sent = alice.send_text(chat.id, "> First quote").await;
let received = bob.recv_msg(&sent).await; let received = bob.recv_msg(&sent).await;
assert_eq!(received.text.as_deref(), Some("> First quote")); assert_eq!(received.text, "> First quote");
assert!(received.quoted_text().is_none()); assert!(received.quoted_text().is_none());
assert!(received.quoted_message(&bob).await?.is_none()); assert!(received.quoted_message(&bob).await?.is_none());
let sent = alice.send_text(chat.id, "> Second quote").await; let sent = alice.send_text(chat.id, "> Second quote").await;
let received = bob.recv_msg(&sent).await; let received = bob.recv_msg(&sent).await;
assert_eq!(received.text.as_deref(), Some("> Second quote")); assert_eq!(received.text, "> Second quote");
assert!(received.quoted_text().is_none()); assert!(received.quoted_text().is_none());
assert!(received.quoted_message(&bob).await?.is_none()); assert!(received.quoted_message(&bob).await?.is_none());
@@ -2573,24 +2573,24 @@ mod tests {
let text = " Foo bar"; let text = " Foo bar";
let sent = alice.send_text(chat.id, text).await; let sent = alice.send_text(chat.id, text).await;
let received = bob.recv_msg(&sent).await; let received = bob.recv_msg(&sent).await;
assert_eq!(received.text.as_deref(), Some(text)); assert_eq!(received.text, text);
let text = "Foo bar baz"; let text = "Foo bar baz";
let sent = alice.send_text(chat.id, text).await; let sent = alice.send_text(chat.id, text).await;
let received = bob.recv_msg(&sent).await; let received = bob.recv_msg(&sent).await;
assert_eq!(received.text.as_deref(), Some(text)); assert_eq!(received.text, text);
let text = "> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > A"; let text = "> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx > A";
let sent = alice.send_text(chat.id, text).await; let sent = alice.send_text(chat.id, text).await;
let received = bob.recv_msg(&sent).await; let received = bob.recv_msg(&sent).await;
assert_eq!(received.text.as_deref(), Some(text)); assert_eq!(received.text, text);
let python_program = "\ let python_program = "\
def hello(): def hello():
return 'Hello, world!'"; return 'Hello, world!'";
let sent = alice.send_text(chat.id, python_program).await; let sent = alice.send_text(chat.id, python_program).await;
let received = bob.recv_msg(&sent).await; let received = bob.recv_msg(&sent).await;
assert_eq!(received.text.as_deref(), Some(python_program)); assert_eq!(received.text, python_program);
Ok(()) Ok(())
} }

View File

@@ -1138,14 +1138,10 @@ impl<'a> MimeFactory<'a> {
} else { } else {
None None
}; };
let final_text = { let final_text = if let Some(ref text) = placeholdertext {
if let Some(ref text) = placeholdertext {
text
} else if let Some(ref text) = self.msg.text {
text text
} else { } else {
"" &self.msg.text
}
}; };
let mut quoted_text = self let mut quoted_text = self
@@ -1792,7 +1788,7 @@ mod tests {
quote: Option<&Message>, quote: Option<&Message>,
) -> Result<String> { ) -> Result<String> {
let mut new_msg = Message::new(Viewtype::Text); let mut new_msg = Message::new(Viewtype::Text);
new_msg.set_text(Some("Hi".to_string())); new_msg.set_text("Hi".to_string());
if let Some(q) = quote { if let Some(q) = quote {
new_msg.set_quote(t, Some(q)).await?; new_msg.set_quote(t, Some(q)).await?;
} }
@@ -1879,7 +1875,7 @@ mod tests {
let chat_id = ChatId::create_for_contact(&t, contact_id).await.unwrap(); let chat_id = ChatId::create_for_contact(&t, contact_id).await.unwrap();
let mut new_msg = Message::new(Viewtype::Text); let mut new_msg = Message::new(Viewtype::Text);
new_msg.set_text(Some("Hi".to_string())); new_msg.set_text("Hi".to_string());
new_msg.chat_id = chat_id; new_msg.chat_id = chat_id;
chat::prepare_msg(&t, chat_id, &mut new_msg).await.unwrap(); chat::prepare_msg(&t, chat_id, &mut new_msg).await.unwrap();
@@ -1987,7 +1983,7 @@ mod tests {
chat_id.accept(context).await.unwrap(); chat_id.accept(context).await.unwrap();
let mut new_msg = Message::new(Viewtype::Text); let mut new_msg = Message::new(Viewtype::Text);
new_msg.set_text(Some("Hi".to_string())); new_msg.set_text("Hi".to_string());
new_msg.chat_id = chat_id; new_msg.chat_id = chat_id;
chat::prepare_msg(context, chat_id, &mut new_msg) chat::prepare_msg(context, chat_id, &mut new_msg)
.await .await
@@ -2105,7 +2101,7 @@ mod tests {
// send message to bob: that should get multipart/mixed because of the avatar moved to inner header; // send message to bob: that should get multipart/mixed because of the avatar moved to inner header;
// make sure, `Subject:` stays in the outer header (imf header) // make sure, `Subject:` stays in the outer header (imf header)
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("this is the text!".to_string())); msg.set_text("this is the text!".to_string());
let sent_msg = t.send_msg(chat.id, &mut msg).await; let sent_msg = t.send_msg(chat.id, &mut msg).await;
let mut payload = sent_msg.payload().splitn(3, "\r\n\r\n"); let mut payload = sent_msg.payload().splitn(3, "\r\n\r\n");
@@ -2165,7 +2161,7 @@ mod tests {
// send message to bob: that should get multipart/mixed because of the avatar moved to inner header; // send message to bob: that should get multipart/mixed because of the avatar moved to inner header;
// make sure, `Subject:` stays in the outer header (imf header) // make sure, `Subject:` stays in the outer header (imf header)
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("this is the text!".to_string())); msg.set_text("this is the text!".to_string());
let sent_msg = t.send_msg(chat.id, &mut msg).await; let sent_msg = t.send_msg(chat.id, &mut msg).await;
let mut payload = sent_msg.payload().splitn(4, "\r\n\r\n"); let mut payload = sent_msg.payload().splitn(4, "\r\n\r\n");
@@ -2277,7 +2273,7 @@ mod tests {
// send message to bob: that should get multipart/mixed because of the avatar moved to inner header; // send message to bob: that should get multipart/mixed because of the avatar moved to inner header;
// make sure, `Subject:` stays in the outer header (imf header) // make sure, `Subject:` stays in the outer header (imf header)
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("this is the text!".to_string())); msg.set_text("this is the text!".to_string());
let sent_msg = t.send_msg(chat.id, &mut msg).await; let sent_msg = t.send_msg(chat.id, &mut msg).await;
let payload = sent_msg.payload(); let payload = sent_msg.payload();

View File

@@ -3221,10 +3221,7 @@ On 2020-10-25, Bob wrote:
let msg_id = chats.get_msg_id(0).unwrap().unwrap(); let msg_id = chats.get_msg_id(0).unwrap().unwrap();
let msg = Message::load_from_db(&t.ctx, msg_id).await.unwrap(); let msg = Message::load_from_db(&t.ctx, msg_id).await.unwrap();
assert_eq!( assert_eq!(msg.text, "subj with important info body text");
msg.text.as_ref().unwrap(),
"subj with important info body text"
);
assert_eq!(msg.viewtype, Viewtype::Image); assert_eq!(msg.viewtype, Viewtype::Image);
assert_eq!(msg.error(), None); assert_eq!(msg.error(), None);
assert_eq!(msg.is_dc_message, MessengerMessage::No); assert_eq!(msg.is_dc_message, MessengerMessage::No);
@@ -3393,9 +3390,9 @@ Some reply
receive_imf(&t, raw, false).await?; receive_imf(&t, raw, false).await?;
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
assert_eq!(msg.get_text().unwrap(), "Some reply"); assert_eq!(msg.get_text(), "Some reply");
let quoted_message = msg.quoted_message(&t).await?.unwrap(); let quoted_message = msg.quoted_message(&t).await?.unwrap();
assert_eq!(quoted_message.get_text().unwrap(), "Some quote."); assert_eq!(quoted_message.get_text(), "Some quote.");
Ok(()) Ok(())
} }

View File

@@ -156,7 +156,7 @@ impl Context {
self.set_config(Config::QuotaExceeding, Some(&highest.to_string())) self.set_config(Config::QuotaExceeding, Some(&highest.to_string()))
.await?; .await?;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some(stock_str::quota_exceeding(self, highest).await); msg.text = stock_str::quota_exceeding(self, highest).await;
add_device_msg_with_importance(self, None, Some(&mut msg), true).await?; add_device_msg_with_importance(self, None, Some(&mut msg), true).await?;
} else if highest <= QUOTA_ALLCLEAR_PERCENTAGE { } else if highest <= QUOTA_ALLCLEAR_PERCENTAGE {
self.set_config(Config::QuotaExceeding, None).await?; self.set_config(Config::QuotaExceeding, None).await?;

View File

@@ -214,7 +214,7 @@ pub async fn send_reaction(context: &Context, msg_id: MsgId, reaction: &str) ->
let reaction: Reaction = reaction.into(); let reaction: Reaction = reaction.into();
let mut reaction_msg = Message::new(Viewtype::Text); let mut reaction_msg = Message::new(Viewtype::Text);
reaction_msg.text = Some(reaction.as_str().to_string()); reaction_msg.text = reaction.as_str().to_string();
reaction_msg.set_reaction(); reaction_msg.set_reaction();
reaction_msg.in_reply_to = Some(msg.rfc724_mid); reaction_msg.in_reply_to = Some(msg.rfc724_mid);
reaction_msg.hidden = true; reaction_msg.hidden = true;

View File

@@ -250,7 +250,7 @@ async fn test_read_receipt_and_unarchive() -> Result<()> {
.await?; .await?;
let msg = get_chat_msg(&t, group_id, 0, 1).await; let msg = get_chat_msg(&t, group_id, 0, 1).await;
assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert_eq!(msg.is_dc_message, MessengerMessage::Yes);
assert_eq!(msg.text.unwrap(), "hello"); assert_eq!(msg.text, "hello");
assert_eq!(msg.state, MessageState::OutDelivered); assert_eq!(msg.state, MessageState::OutDelivered);
let group = Chat::load_from_db(&t, group_id).await?; let group = Chat::load_from_db(&t, group_id).await?;
assert!(group.get_visibility() == ChatVisibility::Normal); assert!(group.get_visibility() == ChatVisibility::Normal);
@@ -415,7 +415,7 @@ async fn test_escaped_from() {
); );
let msg = get_chat_msg(&t, chat_id, 0, 1).await; let msg = get_chat_msg(&t, chat_id, 0, 1).await;
assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert_eq!(msg.is_dc_message, MessengerMessage::Yes);
assert_eq!(msg.text.unwrap(), "hello"); assert_eq!(msg.text, "hello");
assert_eq!(msg.param.get_int(Param::WantsMdn).unwrap(), 1); assert_eq!(msg.param.get_int(Param::WantsMdn).unwrap(), 1);
} }
@@ -461,7 +461,7 @@ async fn test_escaped_recipients() {
.await .await
.unwrap(); .unwrap();
assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert_eq!(msg.is_dc_message, MessengerMessage::Yes);
assert_eq!(msg.text.unwrap(), "hello"); assert_eq!(msg.text, "hello");
assert_eq!(msg.param.get_int(Param::WantsMdn).unwrap(), 1); assert_eq!(msg.param.get_int(Param::WantsMdn).unwrap(), 1);
} }
@@ -713,7 +713,7 @@ async fn test_parse_ndn_group_msg() -> Result<()> {
assert_eq!( assert_eq!(
last_msg.text, last_msg.text,
Some(stock_str::failed_sending_to(&t, "assidhfaaspocwaeofi@gmail.com").await,) stock_str::failed_sending_to(&t, "assidhfaaspocwaeofi@gmail.com").await
); );
assert_eq!(last_msg.from_id, ContactId::INFO); assert_eq!(last_msg.from_id, ContactId::INFO);
Ok(()) Ok(())
@@ -734,7 +734,7 @@ async fn load_imf_email(context: &Context, imf_raw: &[u8]) -> Message {
async fn test_html_only_mail() { async fn test_html_only_mail() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let msg = load_imf_email(&t, include_bytes!("../../test-data/message/wrong-html.eml")).await; let msg = load_imf_email(&t, include_bytes!("../../test-data/message/wrong-html.eml")).await;
assert_eq!(msg.text.unwrap(), "Guten Abend,\n\nLots of text\n\ntext with Umlaut ä...\n\nMfG\n\n--------------------------------------\n\n[Camping ](https://example.com/)\n\nsomeaddress\n\nsometown"); assert_eq!(msg.text, "Guten Abend,\n\nLots of text\n\ntext with Umlaut ä...\n\nMfG\n\n--------------------------------------\n\n[Camping ](https://example.com/)\n\nsomeaddress\n\nsometown");
} }
static GH_MAILINGLIST: &[u8] = static GH_MAILINGLIST: &[u8] =
@@ -1158,10 +1158,7 @@ async fn test_dhl_mailing_list() -> Result<()> {
.await .await
.unwrap(); .unwrap();
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
assert_eq!( assert_eq!(msg.text, "Ihr Paket ist in der Packstation 123 bla bla");
msg.text,
Some("Ihr Paket ist in der Packstation 123 bla bla".to_string())
);
assert!(msg.has_html()); assert!(msg.has_html());
let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap(); let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap();
assert_eq!(chat.typ, Chattype::Mailinglist); assert_eq!(chat.typ, Chattype::Mailinglist);
@@ -1186,10 +1183,7 @@ async fn test_dpd_mailing_list() -> Result<()> {
.await .await
.unwrap(); .unwrap();
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
assert_eq!( assert_eq!(msg.text, "Bald ist Ihr DPD Paket da bla bla");
msg.text,
Some("Bald ist Ihr DPD Paket da bla bla".to_string())
);
assert!(msg.has_html()); assert!(msg.has_html());
let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap(); let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap();
assert_eq!(chat.typ, Chattype::Mailinglist); assert_eq!(chat.typ, Chattype::Mailinglist);
@@ -1294,10 +1288,7 @@ async fn test_mailing_list_with_mimepart_footer() {
.await .await
.unwrap(); .unwrap();
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
assert_eq!( assert_eq!(msg.text, "[Intern] important stuff Hi mr ... [text part]");
msg.text,
Some("[Intern] important stuff Hi mr ... [text part]".to_string())
);
assert!(msg.has_html()); assert!(msg.has_html());
let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap(); let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap();
assert_eq!(get_chat_msgs(&t, msg.chat_id).await.unwrap().len(), 1); assert_eq!(get_chat_msgs(&t, msg.chat_id).await.unwrap().len(), 1);
@@ -1320,7 +1311,7 @@ async fn test_mailing_list_with_mimepart_footer_signed() {
.unwrap(); .unwrap();
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
assert_eq!(get_chat_msgs(&t, msg.chat_id).await.unwrap().len(), 1); assert_eq!(get_chat_msgs(&t, msg.chat_id).await.unwrap().len(), 1);
let text = msg.text.clone().unwrap(); let text = msg.text.clone();
assert!(text.contains("content text")); assert!(text.contains("content text"));
assert!(!text.contains("footer text")); assert!(!text.contains("footer text"));
assert!(msg.has_html()); assert!(msg.has_html());
@@ -1384,7 +1375,7 @@ async fn test_mailing_list_chat_message() {
.await .await
.unwrap(); .unwrap();
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
assert_eq!(msg.text, Some("hello, this is a test 👋\n\n_______________________________________________\nTest1 mailing list -- test1@example.net\nTo unsubscribe send an email to test1-leave@example.net".to_string())); assert_eq!(msg.text, "hello, this is a test 👋\n\n_______________________________________________\nTest1 mailing list -- test1@example.net\nTo unsubscribe send an email to test1-leave@example.net".to_string());
assert!(!msg.has_html()); assert!(!msg.has_html());
let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap(); let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap();
assert_eq!(chat.typ, Chattype::Mailinglist); assert_eq!(chat.typ, Chattype::Mailinglist);
@@ -1464,7 +1455,7 @@ async fn test_pdf_filename_simple() {
) )
.await; .await;
assert_eq!(msg.viewtype, Viewtype::File); assert_eq!(msg.viewtype, Viewtype::File);
assert_eq!(msg.text.unwrap(), "mail body"); assert_eq!(msg.text, "mail body");
assert_eq!(msg.param.get(Param::File).unwrap(), "$BLOBDIR/simple.pdf"); assert_eq!(msg.param.get(Param::File).unwrap(), "$BLOBDIR/simple.pdf");
} }
@@ -1478,7 +1469,7 @@ async fn test_pdf_filename_continuation() {
) )
.await; .await;
assert_eq!(msg.viewtype, Viewtype::File); assert_eq!(msg.viewtype, Viewtype::File);
assert_eq!(msg.text.unwrap(), "mail body"); assert_eq!(msg.text, "mail body");
assert_eq!( assert_eq!(
msg.param.get(Param::File).unwrap(), msg.param.get(Param::File).unwrap(),
"$BLOBDIR/test pdf äöüß.pdf" "$BLOBDIR/test pdf äöüß.pdf"
@@ -1557,7 +1548,7 @@ async fn test_in_reply_to() {
.unwrap(); .unwrap();
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
assert_eq!(msg.get_text().unwrap(), "reply foo"); assert_eq!(msg.get_text(), "reply foo");
// Load the first message from the same chat. // Load the first message from the same chat.
let msgs = chat::get_chat_msgs(&t, msg.chat_id).await.unwrap(); let msgs = chat::get_chat_msgs(&t, msg.chat_id).await.unwrap();
@@ -1568,7 +1559,7 @@ async fn test_in_reply_to() {
}; };
let reply_msg = Message::load_from_db(&t, *msg_id).await.unwrap(); let reply_msg = Message::load_from_db(&t, *msg_id).await.unwrap();
assert_eq!(reply_msg.get_text().unwrap(), "hello foo"); assert_eq!(reply_msg.get_text(), "hello foo");
// Check that reply got into the same chat as the original message. // Check that reply got into the same chat as the original message.
assert_eq!(msg.chat_id, reply_msg.chat_id); assert_eq!(msg.chat_id, reply_msg.chat_id);
@@ -1626,7 +1617,7 @@ async fn test_in_reply_to_two_member_group() {
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap(); let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap();
assert_eq!(chat.typ, Chattype::Group); assert_eq!(chat.typ, Chattype::Group);
assert_eq!(msg.get_text().unwrap(), "classic reply"); assert_eq!(msg.get_text(), "classic reply");
// Receive a Delta Chat reply from Alice. // Receive a Delta Chat reply from Alice.
// It is assigned to group chat, because it has a group ID. // It is assigned to group chat, because it has a group ID.
@@ -1652,7 +1643,7 @@ async fn test_in_reply_to_two_member_group() {
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap(); let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap();
assert_eq!(chat.typ, Chattype::Group); assert_eq!(chat.typ, Chattype::Group);
assert_eq!(msg.get_text().unwrap(), "chat reply"); assert_eq!(msg.get_text(), "chat reply");
// Receive a private Delta Chat reply from Alice. // Receive a private Delta Chat reply from Alice.
// It is assigned to 1:1 chat, because it has no group ID, // It is assigned to 1:1 chat, because it has no group ID,
@@ -1679,7 +1670,7 @@ async fn test_in_reply_to_two_member_group() {
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap(); let chat = Chat::load_from_db(&t, msg.chat_id).await.unwrap();
assert_eq!(chat.typ, Chattype::Single); assert_eq!(chat.typ, Chattype::Single);
assert_eq!(msg.get_text().unwrap(), "private reply"); assert_eq!(msg.get_text(), "private reply");
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
@@ -1690,7 +1681,7 @@ async fn test_save_mime_headers_off() -> anyhow::Result<()> {
chat::send_text_msg(&alice, chat_alice.id, "hi!".to_string()).await?; chat::send_text_msg(&alice, chat_alice.id, "hi!".to_string()).await?;
let msg = bob.recv_msg(&alice.pop_sent_msg().await).await; let msg = bob.recv_msg(&alice.pop_sent_msg().await).await;
assert_eq!(msg.get_text(), Some("hi!".to_string())); assert_eq!(msg.get_text(), "hi!");
assert!(!msg.get_showpadlock()); assert!(!msg.get_showpadlock());
let mime = message::get_mime_headers(&bob, msg.id).await?; let mime = message::get_mime_headers(&bob, msg.id).await?;
assert!(mime.is_empty()); assert!(mime.is_empty());
@@ -1709,7 +1700,7 @@ async fn test_save_mime_headers_on() -> anyhow::Result<()> {
chat::send_text_msg(&alice, chat_alice.id, "hi!".to_string()).await?; chat::send_text_msg(&alice, chat_alice.id, "hi!".to_string()).await?;
let msg = bob.recv_msg(&alice.pop_sent_msg().await).await; let msg = bob.recv_msg(&alice.pop_sent_msg().await).await;
assert_eq!(msg.get_text(), Some("hi!".to_string())); assert_eq!(msg.get_text(), "hi!");
assert!(!msg.get_showpadlock()); assert!(!msg.get_showpadlock());
let mime = message::get_mime_headers(&bob, msg.id).await?; let mime = message::get_mime_headers(&bob, msg.id).await?;
let mime_str = String::from_utf8_lossy(&mime); let mime_str = String::from_utf8_lossy(&mime);
@@ -1720,7 +1711,7 @@ async fn test_save_mime_headers_on() -> anyhow::Result<()> {
let chat_bob = bob.create_chat(&alice).await; let chat_bob = bob.create_chat(&alice).await;
chat::send_text_msg(&bob, chat_bob.id, "ho!".to_string()).await?; chat::send_text_msg(&bob, chat_bob.id, "ho!".to_string()).await?;
let msg = alice.recv_msg(&bob.pop_sent_msg().await).await; let msg = alice.recv_msg(&bob.pop_sent_msg().await).await;
assert_eq!(msg.get_text(), Some("ho!".to_string())); assert_eq!(msg.get_text(), "ho!");
assert!(msg.get_showpadlock()); assert!(msg.get_showpadlock());
let mime = message::get_mime_headers(&alice, msg.id).await?; let mime = message::get_mime_headers(&alice, msg.id).await?;
let mime_str = String::from_utf8_lossy(&mime); let mime_str = String::from_utf8_lossy(&mime);
@@ -1780,7 +1771,7 @@ async fn create_test_alias(chat_request: bool, group_request: bool) -> (TestCont
let msg = alice.get_last_msg().await; let msg = alice.get_last_msg().await;
assert_eq!(msg.get_subject(), "i have a question"); assert_eq!(msg.get_subject(), "i have a question");
assert!(msg.get_text().unwrap().contains("hi support!")); assert!(msg.get_text().contains("hi support!"));
let chat = Chat::load_from_db(&alice, msg.chat_id).await.unwrap(); let chat = Chat::load_from_db(&alice, msg.chat_id).await.unwrap();
assert_eq!(chat.typ, Chattype::Group); assert_eq!(chat.typ, Chattype::Group);
assert_eq!(get_chat_msgs(&alice, chat.id).await.unwrap().len(), 1); assert_eq!(get_chat_msgs(&alice, chat.id).await.unwrap().len(), 1);
@@ -1805,7 +1796,7 @@ async fn create_test_alias(chat_request: bool, group_request: bool) -> (TestCont
let msg = Message::load_from_db(&claire, msg_id).await.unwrap(); let msg = Message::load_from_db(&claire, msg_id).await.unwrap();
msg.chat_id.accept(&claire).await.unwrap(); msg.chat_id.accept(&claire).await.unwrap();
assert_eq!(msg.get_subject(), "i have a question"); assert_eq!(msg.get_subject(), "i have a question");
assert!(msg.get_text().unwrap().contains("hi support!")); assert!(msg.get_text().contains("hi support!"));
let chat = Chat::load_from_db(&claire, msg.chat_id).await.unwrap(); let chat = Chat::load_from_db(&claire, msg.chat_id).await.unwrap();
if group_request { if group_request {
assert_eq!(chat.typ, Chattype::Group); assert_eq!(chat.typ, Chattype::Group);
@@ -1826,7 +1817,7 @@ async fn check_alias_reply(reply: &[u8], chat_request: bool, group_request: bool
receive_imf(&alice, reply, false).await.unwrap(); receive_imf(&alice, reply, false).await.unwrap();
let answer = alice.get_last_msg().await; let answer = alice.get_last_msg().await;
assert_eq!(answer.get_subject(), "Re: i have a question"); assert_eq!(answer.get_subject(), "Re: i have a question");
assert!(answer.get_text().unwrap().contains("the version is 1.0")); assert!(answer.get_text().contains("the version is 1.0"));
assert_eq!(answer.chat_id, request.chat_id); assert_eq!(answer.chat_id, request.chat_id);
let chat_contacts = get_chat_contacts(&alice, answer.chat_id) let chat_contacts = get_chat_contacts(&alice, answer.chat_id)
.await .await
@@ -1849,7 +1840,7 @@ async fn check_alias_reply(reply: &[u8], chat_request: bool, group_request: bool
receive_imf(&claire, reply, false).await.unwrap(); receive_imf(&claire, reply, false).await.unwrap();
let answer = claire.get_last_msg().await; let answer = claire.get_last_msg().await;
assert_eq!(answer.get_subject(), "Re: i have a question"); assert_eq!(answer.get_subject(), "Re: i have a question");
assert!(answer.get_text().unwrap().contains("the version is 1.0")); assert!(answer.get_text().contains("the version is 1.0"));
assert_eq!(answer.chat_id, request.chat_id); assert_eq!(answer.chat_id, request.chat_id);
assert_eq!( assert_eq!(
answer.get_override_sender_name().unwrap(), answer.get_override_sender_name().unwrap(),
@@ -1921,7 +1912,7 @@ async fn test_dont_assign_to_trash_by_parent() {
chat_id.accept(&t).await.unwrap(); chat_id.accept(&t).await.unwrap();
let msg = get_chat_msg(&t, chat_id, 0, 1).await; // Make sure that the message is actually in the chat let msg = get_chat_msg(&t, chat_id, 0, 1).await; // Make sure that the message is actually in the chat
assert!(!msg.chat_id.is_special()); assert!(!msg.chat_id.is_special());
assert_eq!(msg.text.unwrap(), "Hi hello"); assert_eq!(msg.text, "Hi hello");
println!("\n========= Delete the message =========="); println!("\n========= Delete the message ==========");
msg.id.trash(&t).await.unwrap(); msg.id.trash(&t).await.unwrap();
@@ -1945,7 +1936,7 @@ async fn test_dont_assign_to_trash_by_parent() {
.unwrap(); .unwrap();
let msg = t.get_last_msg().await; let msg = t.get_last_msg().await;
assert!(!msg.chat_id.is_special()); // Esp. check that the chat_id is not TRASH assert!(!msg.chat_id.is_special()); // Esp. check that the chat_id is not TRASH
assert_eq!(msg.text.unwrap(), "Reply"); assert_eq!(msg.text, "Reply");
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
@@ -1996,7 +1987,7 @@ Message content",
// Outgoing email should create a chat. // Outgoing email should create a chat.
let msg = alice.get_last_msg().await; let msg = alice.get_last_msg().await;
assert_eq!(msg.get_text().unwrap(), "Subj Message content"); assert_eq!(msg.get_text(), "Subj Message content");
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
@@ -2243,7 +2234,7 @@ Message-ID: <Gr.eJ_llQIXf0K.buxmrnMmG0Y@gmx.de>"
let group_msg = t.get_last_msg().await; let group_msg = t.get_last_msg().await;
assert_eq!( assert_eq!(
group_msg.text.unwrap(), group_msg.text,
if *outgoing_is_classical { if *outgoing_is_classical {
"single reply-to Hello, I\'ve just created the group \"single reply-to\" for us." "single reply-to Hello, I\'ve just created the group \"single reply-to\" for us."
} else { } else {
@@ -2283,7 +2274,7 @@ Private reply"#,
.unwrap(); .unwrap();
let private_msg = t.get_last_msg().await; let private_msg = t.get_last_msg().await;
assert_eq!(private_msg.text.unwrap(), "Private reply"); assert_eq!(private_msg.text, "Private reply");
let private_chat = Chat::load_from_db(&t, private_msg.chat_id).await.unwrap(); let private_chat = Chat::load_from_db(&t, private_msg.chat_id).await.unwrap();
assert_eq!(private_chat.typ, Chattype::Single); assert_eq!(private_chat.typ, Chattype::Single);
assert_ne!(private_msg.chat_id, group_msg.chat_id); assert_ne!(private_msg.chat_id, group_msg.chat_id);
@@ -2332,7 +2323,7 @@ Message-ID: <Gr.iy1KCE2y65_.mH2TM52miv9@testrun.org>"
.unwrap(); .unwrap();
let group_msg = t.get_last_msg().await; let group_msg = t.get_last_msg().await;
assert_eq!( assert_eq!(
group_msg.text.unwrap(), group_msg.text,
if *outgoing_is_classical { if *outgoing_is_classical {
"single reply-to Hello, I\'ve just created the group \"single reply-to\" for us." "single reply-to Hello, I\'ve just created the group \"single reply-to\" for us."
} else { } else {
@@ -2378,7 +2369,7 @@ Sent with my Delta Chat Messenger: https://delta.chat
.unwrap(); .unwrap();
let private_msg = t.get_last_msg().await; let private_msg = t.get_last_msg().await;
assert_eq!(private_msg.text.unwrap(), "Private reply"); assert_eq!(private_msg.text, "Private reply");
let private_chat = Chat::load_from_db(&t, private_msg.chat_id).await.unwrap(); let private_chat = Chat::load_from_db(&t, private_msg.chat_id).await.unwrap();
assert_eq!(private_chat.typ, Chattype::Single); assert_eq!(private_chat.typ, Chattype::Single);
assert_ne!(private_msg.chat_id, group_msg.chat_id); assert_ne!(private_msg.chat_id, group_msg.chat_id);
@@ -2420,7 +2411,7 @@ Message-ID: <Gr.eJ_llQIXf0K.buxmrnMmG0Y@gmx.de>"
let group_msg = t.get_last_msg().await; let group_msg = t.get_last_msg().await;
assert_eq!( assert_eq!(
group_msg.text.unwrap(), group_msg.text,
if *outgoing_is_classical { if *outgoing_is_classical {
"single reply-to Hello, I\'ve just created the group \"single reply-to\" for us." "single reply-to Hello, I\'ve just created the group \"single reply-to\" for us."
} else { } else {
@@ -2457,7 +2448,7 @@ Outgoing reply to all"#,
.unwrap(); .unwrap();
let reply = t.get_last_msg().await; let reply = t.get_last_msg().await;
assert_eq!(reply.text.unwrap(), "Out subj Outgoing reply to all"); assert_eq!(reply.text, "Out subj Outgoing reply to all");
let reply_chat = Chat::load_from_db(&t, reply.chat_id).await.unwrap(); let reply_chat = Chat::load_from_db(&t, reply.chat_id).await.unwrap();
assert_eq!(reply_chat.typ, Chattype::Group); assert_eq!(reply_chat.typ, Chattype::Group);
assert_eq!(reply.chat_id, group_msg.chat_id); assert_eq!(reply.chat_id, group_msg.chat_id);
@@ -2480,7 +2471,7 @@ Reply to all"#,
.unwrap(); .unwrap();
let reply = t.get_last_msg().await; let reply = t.get_last_msg().await;
assert_eq!(reply.text.unwrap(), "In subj Reply to all"); assert_eq!(reply.text, "In subj Reply to all");
let reply_chat = Chat::load_from_db(&t, reply.chat_id).await.unwrap(); let reply_chat = Chat::load_from_db(&t, reply.chat_id).await.unwrap();
assert_eq!(reply_chat.typ, Chattype::Group); assert_eq!(reply_chat.typ, Chattype::Group);
assert_eq!(reply.chat_id, group_msg.chat_id); assert_eq!(reply.chat_id, group_msg.chat_id);
@@ -2766,7 +2757,7 @@ Hi, I created a group"#,
.await?; .await?;
let msg_out = t.get_last_msg().await; let msg_out = t.get_last_msg().await;
assert_eq!(msg_out.from_id, ContactId::SELF); assert_eq!(msg_out.from_id, ContactId::SELF);
assert_eq!(msg_out.text.unwrap(), "Hi, I created a group"); assert_eq!(msg_out.text, "Hi, I created a group");
assert_eq!(msg_out.in_reply_to, None); assert_eq!(msg_out.in_reply_to, None);
// Bob replies from a different address // Bob replies from a different address
@@ -2790,7 +2781,7 @@ Reply from different address
.await?; .await?;
let msg_in = t.get_last_msg().await; let msg_in = t.get_last_msg().await;
assert_eq!(msg_in.to_id, ContactId::SELF); assert_eq!(msg_in.to_id, ContactId::SELF);
assert_eq!(msg_in.text.unwrap(), "Reply from different address"); assert_eq!(msg_in.text, "Reply from different address");
assert_eq!( assert_eq!(
msg_in.in_reply_to.unwrap(), msg_in.in_reply_to.unwrap(),
"Gr.qetqsutor7a.Aresxresy-4@deltachat.de" "Gr.qetqsutor7a.Aresxresy-4@deltachat.de"
@@ -2868,22 +2859,22 @@ async fn test_accept_outgoing() -> Result<()> {
alice1.recv_msg(&sent).await; alice1.recv_msg(&sent).await;
alice2.recv_msg(&sent).await; alice2.recv_msg(&sent).await;
let alice1_msg = bob2.recv_msg(&sent).await; let alice1_msg = bob2.recv_msg(&sent).await;
assert_eq!(alice1_msg.text.unwrap(), "Hello!"); assert_eq!(alice1_msg.text, "Hello!");
let alice1_chat = chat::Chat::load_from_db(&alice1, alice1_msg.chat_id).await?; let alice1_chat = chat::Chat::load_from_db(&alice1, alice1_msg.chat_id).await?;
assert!(alice1_chat.is_contact_request()); assert!(alice1_chat.is_contact_request());
let alice2_msg = alice2.get_last_msg().await; let alice2_msg = alice2.get_last_msg().await;
assert_eq!(alice2_msg.text.unwrap(), "Hello!"); assert_eq!(alice2_msg.text, "Hello!");
let alice2_chat = chat::Chat::load_from_db(&alice2, alice2_msg.chat_id).await?; let alice2_chat = chat::Chat::load_from_db(&alice2, alice2_msg.chat_id).await?;
assert!(alice2_chat.is_contact_request()); assert!(alice2_chat.is_contact_request());
let bob1_msg = bob1.get_last_msg().await; let bob1_msg = bob1.get_last_msg().await;
assert_eq!(bob1_msg.text.unwrap(), "Hello!"); assert_eq!(bob1_msg.text, "Hello!");
let bob1_chat = chat::Chat::load_from_db(&bob1, bob1_msg.chat_id).await?; let bob1_chat = chat::Chat::load_from_db(&bob1, bob1_msg.chat_id).await?;
assert!(!bob1_chat.is_contact_request()); assert!(!bob1_chat.is_contact_request());
let bob2_msg = bob2.get_last_msg().await; let bob2_msg = bob2.get_last_msg().await;
assert_eq!(bob2_msg.text.unwrap(), "Hello!"); assert_eq!(bob2_msg.text, "Hello!");
let bob2_chat = chat::Chat::load_from_db(&bob2, bob2_msg.chat_id).await?; let bob2_chat = chat::Chat::load_from_db(&bob2, bob2_msg.chat_id).await?;
assert!(!bob2_chat.is_contact_request()); assert!(!bob2_chat.is_contact_request());
@@ -2929,7 +2920,7 @@ async fn test_outgoing_private_reply_multidevice() -> Result<()> {
assert_eq!(received.from_id, alice1_bob_contact.id); assert_eq!(received.from_id, alice1_bob_contact.id);
assert_eq!(received.to_id, ContactId::SELF); assert_eq!(received.to_id, ContactId::SELF);
assert!(!received.hidden); assert!(!received.hidden);
assert_eq!(received.text, Some("Hello all!".to_string())); assert_eq!(received.text, "Hello all!");
assert_eq!(received.in_reply_to, None); assert_eq!(received.in_reply_to, None);
assert_eq!(received.chat_blocked, Blocked::Request); assert_eq!(received.chat_blocked, Blocked::Request);
@@ -2939,7 +2930,7 @@ async fn test_outgoing_private_reply_multidevice() -> Result<()> {
assert_eq!(received_group.can_send(&alice1).await?, false); // Can't send because it's Blocked::Request assert_eq!(received_group.can_send(&alice1).await?, false); // Can't send because it's Blocked::Request
let mut msg_out = Message::new(Viewtype::Text); let mut msg_out = Message::new(Viewtype::Text);
msg_out.set_text(Some("Private reply".to_string())); msg_out.set_text("Private reply".to_string());
assert_eq!(received_group.blocked, Blocked::Request); assert_eq!(received_group.blocked, Blocked::Request);
msg_out.set_quote(&alice1, Some(&received)).await?; msg_out.set_quote(&alice1, Some(&received)).await?;
@@ -2957,10 +2948,10 @@ async fn test_outgoing_private_reply_multidevice() -> Result<()> {
assert_eq!(received.from_id, ContactId::SELF); assert_eq!(received.from_id, ContactId::SELF);
assert_eq!(received.to_id, alice2_bob_contact.id); assert_eq!(received.to_id, alice2_bob_contact.id);
assert!(!received.hidden); assert!(!received.hidden);
assert_eq!(received.text, Some("Private reply".to_string())); assert_eq!(received.text, "Private reply");
assert_eq!( assert_eq!(
received.parent(&alice2).await?.unwrap().text, received.parent(&alice2).await?.unwrap().text,
Some("Hello all!".to_string()) "Hello all!".to_string()
); );
assert_eq!(received.chat_blocked, Blocked::Not); assert_eq!(received.chat_blocked, Blocked::Not);
@@ -3021,13 +3012,13 @@ async fn test_no_private_reply_to_blocked_account() -> Result<()> {
// =============== Alice replies private to Bob ============== // =============== Alice replies private to Bob ==============
let received = alice.get_last_msg().await; let received = alice.get_last_msg().await;
assert_eq!(received.text, Some("Hello all!".to_string())); assert_eq!(received.text, "Hello all!");
let received_group = Chat::load_from_db(&alice, received.chat_id).await?; let received_group = Chat::load_from_db(&alice, received.chat_id).await?;
assert_eq!(received_group.typ, Chattype::Group); assert_eq!(received_group.typ, Chattype::Group);
let mut msg_out = Message::new(Viewtype::Text); let mut msg_out = Message::new(Viewtype::Text);
msg_out.set_text(Some("Private reply".to_string())); msg_out.set_text("Private reply".to_string());
msg_out.set_quote(&alice, Some(&received)).await?; msg_out.set_quote(&alice, Some(&received)).await?;
let alice_bob_chat = alice.create_chat(&bob).await; let alice_bob_chat = alice.create_chat(&bob).await;
@@ -3043,7 +3034,7 @@ async fn test_no_private_reply_to_blocked_account() -> Result<()> {
// since only chat is a group, no new open chat has been created // since only chat is a group, no new open chat has been created
assert_eq!(chat.typ, Chattype::Group); assert_eq!(chat.typ, Chattype::Group);
let received = bob.get_last_msg().await; let received = bob.get_last_msg().await;
assert_eq!(received.text, Some("Hello all!".to_string())); assert_eq!(received.text, "Hello all!");
// =============== Bob unblocks Alice ================ // =============== Bob unblocks Alice ================
// test if the blocked chat is restored correctly // test if the blocked chat is restored correctly
@@ -3054,7 +3045,7 @@ async fn test_no_private_reply_to_blocked_account() -> Result<()> {
let chat = Chat::load_from_db(&bob, chat_id).await.unwrap(); let chat = Chat::load_from_db(&bob, chat_id).await.unwrap();
assert_eq!(chat.typ, Chattype::Single); assert_eq!(chat.typ, Chattype::Single);
let received = bob.get_last_msg().await; let received = bob.get_last_msg().await;
assert_eq!(received.text, Some("Private reply".to_string())); assert_eq!(received.text, "Private reply");
Ok(()) Ok(())
} }

View File

@@ -178,7 +178,7 @@ async fn send_alice_handshake_msg(
) -> Result<()> { ) -> Result<()> {
let mut msg = Message { let mut msg = Message {
viewtype: Viewtype::Text, viewtype: Viewtype::Text,
text: Some(format!("Secure-Join: {step}")), text: format!("Secure-Join: {step}"),
hidden: true, hidden: true,
..Default::default() ..Default::default()
}; };
@@ -933,8 +933,7 @@ mod tests {
.expect("No messages in Alice's 1:1 chat"); .expect("No messages in Alice's 1:1 chat");
let msg = Message::load_from_db(&alice.ctx, msg_id).await.unwrap(); let msg = Message::load_from_db(&alice.ctx, msg_id).await.unwrap();
assert!(msg.is_info()); assert!(msg.is_info());
let text = msg.get_text().unwrap(); assert!(msg.get_text().contains("bob@example.net verified"));
assert!(text.contains("bob@example.net verified"));
} }
// Check Alice sent the right message to Bob. // Check Alice sent the right message to Bob.
@@ -982,8 +981,7 @@ mod tests {
.expect("No messages in Bob's 1:1 chat"); .expect("No messages in Bob's 1:1 chat");
let msg = Message::load_from_db(&bob.ctx, msg_id).await.unwrap(); let msg = Message::load_from_db(&bob.ctx, msg_id).await.unwrap();
assert!(msg.is_info()); assert!(msg.is_info());
let text = msg.get_text().unwrap(); assert!(msg.get_text().contains("alice@example.org verified"));
assert!(text.contains("alice@example.org verified"));
} }
// Check Bob sent the final message // Check Bob sent the final message
@@ -1292,8 +1290,7 @@ mod tests {
.expect("No messages in Alice's group chat"); .expect("No messages in Alice's group chat");
let msg = Message::load_from_db(&alice.ctx, msg_id).await.unwrap(); let msg = Message::load_from_db(&alice.ctx, msg_id).await.unwrap();
assert!(msg.is_info()); assert!(msg.is_info());
let text = msg.get_text().unwrap(); assert!(msg.get_text().contains("bob@example.net verified"));
assert!(text.contains("bob@example.net verified"));
} }
// Bob should not yet have Alice verified // Bob should not yet have Alice verified
@@ -1328,7 +1325,7 @@ mod tests {
for item in chat::get_chat_msgs(&bob.ctx, bob_chatid).await.unwrap() { for item in chat::get_chat_msgs(&bob.ctx, bob_chatid).await.unwrap() {
if let chat::ChatItem::Message { msg_id } = item { if let chat::ChatItem::Message { msg_id } = item {
let msg = Message::load_from_db(&bob.ctx, msg_id).await.unwrap(); let msg = Message::load_from_db(&bob.ctx, msg_id).await.unwrap();
let text = msg.get_text().unwrap(); let text = msg.get_text();
println!("msg {msg_id} text: {text}"); println!("msg {msg_id} text: {text}");
} }
} }
@@ -1340,7 +1337,7 @@ mod tests {
match msg_iter.next() { match msg_iter.next() {
Some(chat::ChatItem::Message { msg_id }) => { Some(chat::ChatItem::Message { msg_id }) => {
let msg = Message::load_from_db(&bob.ctx, msg_id).await.unwrap(); let msg = Message::load_from_db(&bob.ctx, msg_id).await.unwrap();
let text = msg.get_text().unwrap(); let text = msg.get_text();
match text.contains("alice@example.org verified") { match text.contains("alice@example.org verified") {
true => { true => {
assert!(msg.is_info()); assert!(msg.is_info());

View File

@@ -422,7 +422,7 @@ async fn send_handshake_message(
) -> Result<()> { ) -> Result<()> {
let mut msg = Message { let mut msg = Message {
viewtype: Viewtype::Text, viewtype: Viewtype::Text,
text: Some(step.body_text(invite)), text: step.body_text(invite),
hidden: true, hidden: true,
..Default::default() ..Default::default()
}; };

View File

@@ -245,7 +245,7 @@ impl Sql {
// So, for people who have delete_server enabled, disable it and add a hint to the devicechat: // 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() { if context.get_config_delete_server_after().await?.is_some() {
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some(stock_str::delete_server_turned_off(context).await); msg.set_text(stock_str::delete_server_turned_off(context).await);
add_device_msg(context, None, Some(&mut msg)).await?; add_device_msg(context, None, Some(&mut msg)).await?;
context context
.set_config(Config::DeleteServerAfter, Some("0")) .set_config(Config::DeleteServerAfter, Some("0"))
@@ -1102,13 +1102,13 @@ mod tests {
let chat = t.create_chat_with_contact("bob", "bob@example.com").await; let chat = t.create_chat_with_contact("bob", "bob@example.com").await;
let mut new_draft = Message::new(Viewtype::Text); let mut new_draft = Message::new(Viewtype::Text);
new_draft.set_text(Some("This is my draft".to_string())); new_draft.set_text("This is my draft".to_string());
chat.id.set_draft(&t, Some(&mut new_draft)).await.unwrap(); chat.id.set_draft(&t, Some(&mut new_draft)).await.unwrap();
housekeeping(&t).await.unwrap(); housekeeping(&t).await.unwrap();
let loaded_draft = chat.id.get_draft(&t).await.unwrap(); let loaded_draft = chat.id.get_draft(&t).await.unwrap();
assert_eq!(loaded_draft.unwrap().text.unwrap(), "This is my draft"); assert_eq!(loaded_draft.unwrap().text, "This is my draft");
} }
/// Tests that `housekeeping` deletes the blobs backup dir which is created normally by /// Tests that `housekeeping` deletes the blobs backup dir which is created normally by

View File

@@ -1313,7 +1313,7 @@ impl Context {
chat::add_device_msg(self, Some("core-welcome-image"), Some(&mut msg)).await?; chat::add_device_msg(self, Some("core-welcome-image"), Some(&mut msg)).await?;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some(welcome_message(self).await); msg.text = welcome_message(self).await;
chat::add_device_msg(self, Some("core-welcome"), Some(&mut msg)).await?; chat::add_device_msg(self, Some("core-welcome"), Some(&mut msg)).await?;
Ok(()) Ok(())
} }

View File

@@ -175,16 +175,12 @@ impl Message {
return prefix; return prefix;
} }
let summary_content = if let Some(text) = &self.text { let summary_content = if self.text.is_empty() {
if text.is_empty() {
prefix prefix
} else if prefix.is_empty() { } else if prefix.is_empty() {
text.to_string() self.text.to_string()
} else { } else {
format!("{prefix} {text}") format!("{prefix} {}", self.text)
}
} else {
prefix
}; };
let summary = if self.is_forwarded() { let summary = if self.is_forwarded() {
@@ -211,19 +207,16 @@ mod tests {
let d = test::TestContext::new().await; let d = test::TestContext::new().await;
let ctx = &d.ctx; let ctx = &d.ctx;
let some_text = Some(" bla \t\n\tbla\n\t".to_string()); let some_text = " bla \t\n\tbla\n\t".to_string();
let empty_text = Some("".to_string());
let no_text: Option<String> = None;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(some_text.clone()); msg.set_text(some_text.to_string());
assert_eq!( assert_eq!(
msg.get_summary_text(ctx).await, msg.get_summary_text(ctx).await,
"bla bla" // for simple text, the type is not added to the summary "bla bla" // for simple text, the type is not added to the summary
); );
let mut msg = Message::new(Viewtype::Image); let mut msg = Message::new(Viewtype::Image);
msg.set_text(no_text.clone());
msg.set_file("foo.bar", None); msg.set_file("foo.bar", None);
assert_eq!( assert_eq!(
msg.get_summary_text(ctx).await, msg.get_summary_text(ctx).await,
@@ -231,7 +224,6 @@ mod tests {
); );
let mut msg = Message::new(Viewtype::Video); let mut msg = Message::new(Viewtype::Video);
msg.set_text(no_text.clone());
msg.set_file("foo.bar", None); msg.set_file("foo.bar", None);
assert_eq!( assert_eq!(
msg.get_summary_text(ctx).await, msg.get_summary_text(ctx).await,
@@ -239,7 +231,6 @@ mod tests {
); );
let mut msg = Message::new(Viewtype::Gif); let mut msg = Message::new(Viewtype::Gif);
msg.set_text(no_text.clone());
msg.set_file("foo.bar", None); msg.set_file("foo.bar", None);
assert_eq!( assert_eq!(
msg.get_summary_text(ctx).await, msg.get_summary_text(ctx).await,
@@ -247,7 +238,6 @@ mod tests {
); );
let mut msg = Message::new(Viewtype::Sticker); let mut msg = Message::new(Viewtype::Sticker);
msg.set_text(no_text.clone());
msg.set_file("foo.bar", None); msg.set_file("foo.bar", None);
assert_eq!( assert_eq!(
msg.get_summary_text(ctx).await, msg.get_summary_text(ctx).await,
@@ -255,7 +245,6 @@ mod tests {
); );
let mut msg = Message::new(Viewtype::Voice); let mut msg = Message::new(Viewtype::Voice);
msg.set_text(empty_text.clone());
msg.set_file("foo.bar", None); msg.set_file("foo.bar", None);
assert_eq!( assert_eq!(
msg.get_summary_text(ctx).await, msg.get_summary_text(ctx).await,
@@ -263,7 +252,6 @@ mod tests {
); );
let mut msg = Message::new(Viewtype::Voice); let mut msg = Message::new(Viewtype::Voice);
msg.set_text(no_text.clone());
msg.set_file("foo.bar", None); msg.set_file("foo.bar", None);
assert_eq!( assert_eq!(
msg.get_summary_text(ctx).await, msg.get_summary_text(ctx).await,
@@ -279,7 +267,6 @@ mod tests {
); );
let mut msg = Message::new(Viewtype::Audio); let mut msg = Message::new(Viewtype::Audio);
msg.set_text(no_text.clone());
msg.set_file("foo.bar", None); msg.set_file("foo.bar", None);
assert_eq!( assert_eq!(
msg.get_summary_text(ctx).await, msg.get_summary_text(ctx).await,
@@ -287,7 +274,6 @@ mod tests {
); );
let mut msg = Message::new(Viewtype::Audio); let mut msg = Message::new(Viewtype::Audio);
msg.set_text(empty_text.clone());
msg.set_file("foo.bar", None); msg.set_file("foo.bar", None);
assert_eq!( assert_eq!(
msg.get_summary_text(ctx).await, msg.get_summary_text(ctx).await,
@@ -329,7 +315,6 @@ mod tests {
); );
let mut msg = Message::new(Viewtype::File); let mut msg = Message::new(Viewtype::File);
msg.set_text(no_text.clone());
msg.param.set(Param::File, "foo.bar"); msg.param.set(Param::File, "foo.bar");
msg.param.set_cmd(SystemMessage::AutocryptSetupMessage); msg.param.set_cmd(SystemMessage::AutocryptSetupMessage);
assert_eq!( assert_eq!(

View File

@@ -130,7 +130,7 @@ impl Context {
let mut msg = Message { let mut msg = Message {
chat_id, chat_id,
viewtype: Viewtype::Text, viewtype: Viewtype::Text,
text: Some(stock_str::sync_msg_body(self).await), text: stock_str::sync_msg_body(self).await,
hidden: true, hidden: true,
subject: stock_str::sync_msg_subject(self).await, subject: stock_str::sync_msg_subject(self).await,
..Default::default() ..Default::default()

View File

@@ -118,7 +118,7 @@ impl TestContextManager {
/// - Assert that the message arrived /// - Assert that the message arrived
pub async fn send_recv(&self, from: &TestContext, to: &TestContext, msg: &str) -> Message { pub async fn send_recv(&self, from: &TestContext, to: &TestContext, msg: &str) -> Message {
let received_msg = self.try_send_recv(from, to, msg).await; let received_msg = self.try_send_recv(from, to, msg).await;
assert_eq!(received_msg.text.as_ref().unwrap(), msg); assert_eq!(received_msg.text, msg);
received_msg received_msg
} }
@@ -608,7 +608,7 @@ impl TestContext {
/// the message. /// the message.
pub async fn send_text(&self, chat_id: ChatId, txt: &str) -> SentMessage<'_> { pub async fn send_text(&self, chat_id: ChatId, txt: &str) -> SentMessage<'_> {
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some(txt.to_string())); msg.text = txt.to_string();
self.send_msg(chat_id, &mut msg).await self.send_msg(chat_id, &mut msg).await
} }
@@ -1104,7 +1104,7 @@ async fn write_msg(context: &Context, prefix: &str, msg: &Message, buf: &mut Str
if msg.has_location() { "📍" } else { "" }, if msg.has_location() { "📍" } else { "" },
&contact_name, &contact_name,
contact_id, contact_id,
msgtext.unwrap_or_default(), msgtext,
if msg.get_from_id() == ContactId::SELF { if msg.get_from_id() == ContactId::SELF {
"" ""
} else if msg.get_state() == MessageState::InSeen { } else if msg.get_state() == MessageState::InSeen {

View File

@@ -32,7 +32,7 @@ async fn test_change_primary_self_addr() -> Result<()> {
// Alice set up message forwarding so that she still receives // Alice set up message forwarding so that she still receives
// the message with her new address // the message with her new address
let alice_msg = alice.recv_msg(&sent).await; let alice_msg = alice.recv_msg(&sent).await;
assert_eq!(alice_msg.text, Some("hi back".to_string())); assert_eq!(alice_msg.text, "hi back".to_string());
assert_eq!(alice_msg.get_showpadlock(), true); assert_eq!(alice_msg.get_showpadlock(), true);
let alice_bob_chat = alice.create_chat(&bob).await; let alice_bob_chat = alice.create_chat(&bob).await;
assert_eq!(alice_msg.chat_id, alice_bob_chat.id); assert_eq!(alice_msg.chat_id, alice_bob_chat.id);
@@ -57,10 +57,7 @@ Message w/out In-Reply-To
let alice_msg = alice.get_last_msg().await; let alice_msg = alice.get_last_msg().await;
assert_eq!( assert_eq!(alice_msg.text, "Message w/out In-Reply-To");
alice_msg.text,
Some("Message w/out In-Reply-To".to_string())
);
assert_eq!(alice_msg.get_showpadlock(), false); assert_eq!(alice_msg.get_showpadlock(), false);
assert_eq!(alice_msg.chat_id, alice_bob_chat.id); assert_eq!(alice_msg.chat_id, alice_bob_chat.id);
@@ -216,7 +213,7 @@ async fn check_aeap_transition(
.await; .await;
let recvd = bob.recv_msg(&sent).await; let recvd = bob.recv_msg(&sent).await;
let sent_timestamp = recvd.timestamp_sent; let sent_timestamp = recvd.timestamp_sent;
assert_eq!(recvd.text.unwrap(), "Hello from my new addr!"); assert_eq!(recvd.text, "Hello from my new addr!");
tcm.section("Check that the AEAP transition worked"); tcm.section("Check that the AEAP transition worked");
check_that_transition_worked( check_that_transition_worked(
@@ -245,7 +242,7 @@ async fn check_aeap_transition(
.send_text(chat_to_send, "Hello from my old addr!") .send_text(chat_to_send, "Hello from my old addr!")
.await; .await;
let recvd = bob.recv_msg(&sent).await; let recvd = bob.recv_msg(&sent).await;
assert_eq!(recvd.text.unwrap(), "Hello from my old addr!"); assert_eq!(recvd.text, "Hello from my old addr!");
check_that_transition_worked( check_that_transition_worked(
&groups[2..], &groups[2..],
@@ -291,13 +288,13 @@ async fn check_that_transition_worked(
let info_msg = get_last_info_msg(bob, *group).await.unwrap(); let info_msg = get_last_info_msg(bob, *group).await.unwrap();
let expected_text = let expected_text =
stock_str::aeap_addr_changed(bob, name, old_alice_addr, new_alice_addr).await; stock_str::aeap_addr_changed(bob, name, old_alice_addr, new_alice_addr).await;
assert_eq!(info_msg.text.unwrap(), expected_text); assert_eq!(info_msg.text, expected_text);
assert_eq!(info_msg.from_id, ContactId::INFO); assert_eq!(info_msg.from_id, ContactId::INFO);
let msg = format!("Sending to group {group}"); let msg = format!("Sending to group {group}");
let sent = bob.send_text(*group, &msg).await; let sent = bob.send_text(*group, &msg).await;
let recvd = alice.recv_msg(&sent).await; let recvd = alice.recv_msg(&sent).await;
assert_eq!(recvd.text.unwrap(), msg); assert_eq!(recvd.text, msg);
} }
} }

View File

@@ -185,16 +185,14 @@ pub(crate) async fn maybe_add_time_based_warnings(context: &Context) {
async fn maybe_warn_on_bad_time(context: &Context, now: i64, known_past_timestamp: i64) -> bool { async fn maybe_warn_on_bad_time(context: &Context, now: i64, known_past_timestamp: i64) -> bool {
if now < known_past_timestamp { if now < known_past_timestamp {
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some( msg.text = stock_str::bad_time_msg_body(
stock_str::bad_time_msg_body(
context, context,
&Local.timestamp_opt(now, 0).single().map_or_else( &Local.timestamp_opt(now, 0).single().map_or_else(
|| "YY-MM-DD hh:mm:ss".to_string(), || "YY-MM-DD hh:mm:ss".to_string(),
|ts| ts.format("%Y-%m-%d %H:%M:%S").to_string(), |ts| ts.format("%Y-%m-%d %H:%M:%S").to_string(),
), ),
) )
.await, .await;
);
if let Some(timestamp) = chrono::NaiveDateTime::from_timestamp_opt(now, 0) { if let Some(timestamp) = chrono::NaiveDateTime::from_timestamp_opt(now, 0) {
add_device_msg_with_importance( add_device_msg_with_importance(
context, context,
@@ -221,7 +219,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) { 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 { if now > approx_compile_time + DC_OUTDATED_WARNING_DAYS * 24 * 60 * 60 {
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some(stock_str::update_reminder_msg_body(context).await); msg.text = stock_str::update_reminder_msg_body(context).await;
if let Some(timestamp) = chrono::NaiveDateTime::from_timestamp_opt(now, 0) { if let Some(timestamp) = chrono::NaiveDateTime::from_timestamp_opt(now, 0) {
add_device_msg( add_device_msg(
context, context,

View File

@@ -518,7 +518,7 @@ impl Context {
let mut status_update = Message { let mut status_update = Message {
chat_id: instance.chat_id, chat_id: instance.chat_id,
viewtype: Viewtype::Text, viewtype: Viewtype::Text,
text: Some(descr.to_string()), text: descr.to_string(),
hidden: true, hidden: true,
..Default::default() ..Default::default()
}; };
@@ -1464,7 +1464,7 @@ mod tests {
assert!(alice_update.hidden); assert!(alice_update.hidden);
assert_eq!(alice_update.viewtype, Viewtype::Text); assert_eq!(alice_update.viewtype, Viewtype::Text);
assert_eq!(alice_update.get_filename(), None); assert_eq!(alice_update.get_filename(), None);
assert_eq!(alice_update.text, Some("descr text".to_string())); assert_eq!(alice_update.text, "descr text".to_string());
assert_eq!(alice_update.chat_id, alice_instance.chat_id); assert_eq!(alice_update.chat_id, alice_instance.chat_id);
assert_eq!( assert_eq!(
alice_update.parent(&alice).await?.unwrap().id, alice_update.parent(&alice).await?.unwrap().id,
@@ -2131,10 +2131,7 @@ sth_for_the = "future""#
assert!(info_msg.is_info()); assert!(info_msg.is_info());
assert_eq!(info_msg.get_info_type(), SystemMessage::WebxdcInfoMessage); assert_eq!(info_msg.get_info_type(), SystemMessage::WebxdcInfoMessage);
assert_eq!(info_msg.from_id, ContactId::SELF); assert_eq!(info_msg.from_id, ContactId::SELF);
assert_eq!( assert_eq!(info_msg.get_text(), "this appears in-chat");
info_msg.get_text(),
Some("this appears in-chat".to_string())
);
assert_eq!( assert_eq!(
info_msg.parent(&alice).await?.unwrap().id, info_msg.parent(&alice).await?.unwrap().id,
alice_instance.id alice_instance.id
@@ -2156,10 +2153,7 @@ sth_for_the = "future""#
assert!(info_msg.is_info()); assert!(info_msg.is_info());
assert_eq!(info_msg.get_info_type(), SystemMessage::WebxdcInfoMessage); assert_eq!(info_msg.get_info_type(), SystemMessage::WebxdcInfoMessage);
assert!(!info_msg.from_id.is_special()); assert!(!info_msg.from_id.is_special());
assert_eq!( assert_eq!(info_msg.get_text(), "this appears in-chat");
info_msg.get_text(),
Some("this appears in-chat".to_string())
);
assert_eq!(info_msg.parent(&bob).await?.unwrap().id, bob_instance.id); assert_eq!(info_msg.parent(&bob).await?.unwrap().id, bob_instance.id);
assert!(info_msg.quoted_message(&bob).await?.is_none()); assert!(info_msg.quoted_message(&bob).await?.is_none());
assert_eq!( assert_eq!(
@@ -2178,10 +2172,7 @@ sth_for_the = "future""#
assert!(info_msg.is_info()); assert!(info_msg.is_info());
assert_eq!(info_msg.get_info_type(), SystemMessage::WebxdcInfoMessage); assert_eq!(info_msg.get_info_type(), SystemMessage::WebxdcInfoMessage);
assert_eq!(info_msg.from_id, ContactId::SELF); assert_eq!(info_msg.from_id, ContactId::SELF);
assert_eq!( assert_eq!(info_msg.get_text(), "this appears in-chat");
info_msg.get_text(),
Some("this appears in-chat".to_string())
);
assert_eq!( assert_eq!(
info_msg.parent(&alice2).await?.unwrap().id, info_msg.parent(&alice2).await?.unwrap().id,
alice2_instance.id alice2_instance.id
@@ -2220,7 +2211,7 @@ sth_for_the = "future""#
let sent3 = &alice.pop_sent_msg().await; let sent3 = &alice.pop_sent_msg().await;
assert_eq!(alice_chat.id.get_msg_cnt(&alice).await?, 2); assert_eq!(alice_chat.id.get_msg_cnt(&alice).await?, 2);
let info_msg = alice.get_last_msg().await; let info_msg = alice.get_last_msg().await;
assert_eq!(info_msg.get_text(), Some("i2".to_string())); assert_eq!(info_msg.get_text(), "i2");
// When Bob receives the messages, they should be cleaned up as well // When Bob receives the messages, they should be cleaned up as well
let bob_instance = bob.recv_msg(sent1).await; let bob_instance = bob.recv_msg(sent1).await;
@@ -2230,7 +2221,7 @@ sth_for_the = "future""#
bob.recv_msg(sent3).await; bob.recv_msg(sent3).await;
assert_eq!(bob_chat_id.get_msg_cnt(&bob).await?, 2); assert_eq!(bob_chat_id.get_msg_cnt(&bob).await?, 2);
let info_msg = bob.get_last_msg().await; let info_msg = bob.get_last_msg().await;
assert_eq!(info_msg.get_text(), Some("i2".to_string())); assert_eq!(info_msg.get_text(), "i2");
Ok(()) Ok(())
} }
@@ -2383,26 +2374,20 @@ sth_for_the = "future""#
include_bytes!("../test-data/webxdc/minimal.xdc"), include_bytes!("../test-data/webxdc/minimal.xdc"),
) )
.await?; .await?;
alice_instance.set_text(Some("user added text".to_string())); alice_instance.set_text("user added text".to_string());
send_msg(&alice, alice_chat.id, &mut alice_instance).await?; send_msg(&alice, alice_chat.id, &mut alice_instance).await?;
let alice_instance = alice.get_last_msg().await; let alice_instance = alice.get_last_msg().await;
assert_eq!( assert_eq!(alice_instance.get_text(), "user added text");
alice_instance.get_text(),
Some("user added text".to_string())
);
// Bob receives that instance // Bob receives that instance
let sent1 = alice.pop_sent_msg().await; let sent1 = alice.pop_sent_msg().await;
let bob_instance = bob.recv_msg(&sent1).await; let bob_instance = bob.recv_msg(&sent1).await;
assert_eq!(bob_instance.get_text(), Some("user added text".to_string())); assert_eq!(bob_instance.get_text(), "user added text");
// Alice's second device receives the instance as well // Alice's second device receives the instance as well
let alice2 = TestContext::new_alice().await; let alice2 = TestContext::new_alice().await;
let alice2_instance = alice2.recv_msg(&sent1).await; let alice2_instance = alice2.recv_msg(&sent1).await;
assert_eq!( assert_eq!(alice2_instance.get_text(), "user added text");
alice2_instance.get_text(),
Some("user added text".to_string())
);
Ok(()) Ok(())
} }