edit message's text (#6550)

> _greetings from the ice of the deutsche bahn 🚂🚃🚃🚃 always a pleasure to
see how well delta chat meanwhile performs in bad networks :)_

this PR adds an API to request other chat members to replace the message
text of an already sent message. scope is mainly to fix typos. this
feature is known from whatsapp, telegram, signal, and is
[requested](https://support.delta.chat/t/retract-edit-sent-messages/1918)
[since](https://support.delta.chat/t/edit-messages-in-delta-chat/899)
[years](https://github.com/deltachat/deltachat-android/issues/198).

technically, a message with an
[`Obsoletes:`](https://datatracker.ietf.org/doc/html/rfc2076#section-3.6)
header is sent out.

```
From: alice@nine
To: bob@nine
Message-ID: 2000@nine
In-Reply-To: 1000@nine
Obsoletes: 1000@nine

Edited: this is the new text
```

the body is the new text, prefixed by the static text `Edited:` (which
is not a header). the latter is to make the message appear more nicely
in Non-Delta-MUA. save for the `In-Reply-To` header. the `Edited:`
prefix is removed by Delta Chat on receiving.

headers should be protected and moved to e2ee part as usual.

corrected message text is flagged, and UI should show this state, in
practise as "Edited" beside the date.

in case, the original message is not found, nothing happens and the
correction message is trashes (assuming the original was deleted).
question: is the `Obsoletes:` header a good choice? i _thought_ there is
some more specifica RFC, but i cannot find sth. in any case, it should
be an header that is not used otherwise by MUA, to make sure no wanted
messages disappear.

what is NOT done and out of scope:
- optimise if messages are not yet sent out. this is doable, but
introduces quite some cornercaes and may not be worth the effort
- replaces images or other attachments. this is also a bit cornercasy
and beyond "typo fixing", and better be handled by "delete for me and
others" (which may come soon, having the idea now, it seems easy :)
- get edit history in any way. not sure if this is worth the effort,
remember, as being a private messenger, we assume trust among chat
members. it is also questionable wrt privacy, seized devices etc.
- add text where nothing was before; again, scope is "typo fixing",
better avoid cornercases
- saved messages are not edited (this is anyway questionable)
- quoted texts, that are used for the case the original message is
deleted, are not updated
- edits are ignored when the original message is not there yet (out of
order, not yet downloaded)
- message status indicator does not show if edits are sent out or not -
similar to reactions, webxdc updates, sync messages. signal has the same
issue :) still, connectivity should show if there are messages pending

<img width="366" alt="Screenshot 2025-02-17 at 17 25 02"
src="https://github.com/user-attachments/assets/a4a53996-438b-47ef-9004-2c9062eea5d7"
/>

corresponding iOS branch (no PR yet):
https://github.com/deltachat/deltachat-ios/compare/main...r10s/edit-messages

---------

Co-authored-by: l <link2xt@testrun.org>
This commit is contained in:
bjoern
2025-02-21 16:25:42 +01:00
committed by GitHub
parent 85cd3836e0
commit 85cbfde6e4
11 changed files with 254 additions and 5 deletions

View File

@@ -3645,3 +3645,68 @@ async fn test_one_to_one_chat_no_group_member_timestamps() {
let payload = sent.payload;
assert!(!payload.contains("Chat-Group-Member-Timestamps:"));
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_send_edit_request() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let alice_chat = alice.create_chat(bob).await;
// Alice sends a message with typos, followed by a correction message
let sent1 = alice.send_text(alice_chat.id, "zext me in delra.cat").await;
let alice_msg = sent1.load_from_db().await;
assert_eq!(alice_msg.text, "zext me in delra.cat");
send_edit_request(alice, alice_msg.id, "Text me on Delta.Chat".to_string()).await?;
let sent2 = alice.pop_sent_msg().await;
let test = Message::load_from_db(alice, alice_msg.id).await?;
assert_eq!(test.text, "Text me on Delta.Chat");
// Bob receives both messages and has the correct text at the end
let bob_msg = bob.recv_msg(&sent1).await;
assert_eq!(bob_msg.text, "zext me in delra.cat");
bob.recv_msg_opt(&sent2).await;
let test = Message::load_from_db(bob, bob_msg.id).await?;
assert_eq!(test.text, "Text me on Delta.Chat");
// alice has another device, and sees the correction also there
let alice2 = tcm.alice().await;
let alice2_msg = alice2.recv_msg(&sent1).await;
assert_eq!(alice2_msg.text, "zext me in delra.cat");
alice2.recv_msg_opt(&sent2).await;
let test = Message::load_from_db(&alice2, alice2_msg.id).await?;
assert_eq!(test.text, "Text me on Delta.Chat");
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_receive_edit_request_after_removal() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let alice_chat = alice.create_chat(bob).await;
// Alice sends a messag with typos, followed by a correction message
let sent1 = alice.send_text(alice_chat.id, "zext me in delra.cat").await;
let alice_msg = sent1.load_from_db().await;
send_edit_request(alice, alice_msg.id, "Text me on Delta.Chat".to_string()).await?;
let sent2 = alice.pop_sent_msg().await;
// Bob receives first message, deletes it and then ignores the correction
let bob_msg = bob.recv_msg(&sent1).await;
let bob_chat_id = bob_msg.chat_id;
assert_eq!(bob_msg.text, "zext me in delra.cat");
assert_eq!(bob_chat_id.get_msg_cnt(bob).await?, 1);
delete_msgs(bob, &[bob_msg.id]).await?;
assert_eq!(bob_chat_id.get_msg_cnt(bob).await?, 0);
bob.recv_msg_trash(&sent2).await;
assert_eq!(bob_chat_id.get_msg_cnt(bob).await?, 0);
Ok(())
}