Compare commits

...

1 Commits

Author SHA1 Message Date
B. Petersen
fdbfe0eb21 allow quotes without a real parent
there was the question if it is possible to allow
dc_msg_set_quote() to accept a quoted text but no parent set
(so, RFC Message-ID unset).

while writing tests,
however, it turns out, this is not possible with the current data fields:
- replies in a chat always result in "parent" aka "In-Reply-To" being set -
  this parent is either the last message or the quoted message
- when a quoted text is found _and_ the parent is set,
  this one is used to enrich the quote.
- there is no field for "Quoted from" or so
  that can be set independently of "Parent" -
  so, having a "unparented" quote, shown in grey in the UI,
  is currently only possible if the original message is deleted

tl;dr: random quotes, not referring to an existing message
would probably require more work and states to be tracked,

not sure if that is worth the effort,
also as this openes another possibility of bugs on another area.
maybe just create these quotes by a `>` as the first character,
currently, this is not rendered great in Delta Chat,
but still.
2022-07-02 12:42:53 +02:00
2 changed files with 49 additions and 5 deletions

View File

@@ -3665,6 +3665,50 @@ mod tests {
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_quote_without_rfc_message_id() -> Result<()> {
let alice = TestContext::new_alice().await;
let bob = TestContext::new_bob().await;
let chat = alice.create_chat(&bob).await;
// Alice sends two messages: the second one has a quote without RFC Message-ID set,
// but is still be a child of the first one
let mut msg1 = Message::new(Viewtype::Text);
msg1.set_text(Some("message text 1".to_string()));
send_msg(&alice, chat.id, &mut msg1).await?;
let sent1 = alice.pop_sent_msg().await;
let msg1 = Message::load_from_db(&alice, sent1.sender_msg_id).await?;
assert!(msg1.quoted_message(&alice).await?.is_none());
assert!(msg1.quoted_text().is_none());
assert!(msg1.parent(&alice).await?.is_none());
let mut quote = Message::new(Viewtype::Text);
quote.set_text(Some("quoted text".to_string()));
let mut msg2 = Message::new(Viewtype::Text);
msg2.set_quote(&alice, Some(&quote)).await?;
msg2.set_text(Some("message text 2".to_string()));
send_msg(&alice, chat.id, &mut msg2).await?;
let sent2 = alice.pop_sent_msg().await;
let msg2 = Message::load_from_db(&alice, sent2.sender_msg_id).await?;
assert!(msg2.quoted_message(&alice).await?.is_none());
assert_eq!(msg2.quoted_text(), Some("quoted text".to_string()));
assert_eq!(msg2.parent(&alice).await?.unwrap().rfc724_mid, msg1.rfc724_mid);
// check that the messages are received correctly by Bob and Alice's second device
let msg2 = bob.recv_msg(&sent2).await;
assert!(msg2.quoted_message(&bob).await?.is_none());
assert_eq!(msg2.quoted_text(), Some("quoted text".to_string()));
assert_eq!(msg2.parent(&alice).await?.unwrap().rfc724_mid, msg1.rfc724_mid);
let alice2 = TestContext::new_alice().await;
let msg2 = alice2.recv_msg(&sent2).await;
assert!(msg2.quoted_message(&alice2).await?.is_none());
assert_eq!(msg2.quoted_text(), Some("quoted text".to_string()));
assert_eq!(msg2.parent(&alice).await?.unwrap().rfc724_mid, msg1.rfc724_mid);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_add_contact_to_chat_ex_add_self() {
// Adding self to a contact should succeed, even though it's pointless.

View File

@@ -779,11 +779,11 @@ impl Message {
/// it may even be deleted from the database by the time the message is prepared.
pub async fn set_quote(&mut self, context: &Context, quote: Option<&Message>) -> Result<()> {
if let Some(quote) = quote {
ensure!(
!quote.rfc724_mid.is_empty(),
"Message without Message-Id cannot be quoted"
);
self.in_reply_to = Some(quote.rfc724_mid.clone());
self.in_reply_to = if quote.rfc724_mid.is_empty() {
None
} else {
Some(quote.rfc724_mid.clone())
};
if quote
.param