mirror of
https://github.com/chatmail/core.git
synced 2026-04-22 07:56:29 +03:00
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:
61
src/chat.rs
61
src/chat.rs
@@ -25,7 +25,7 @@ use crate::color::str_to_color;
|
||||
use crate::config::Config;
|
||||
use crate::constants::{
|
||||
self, Blocked, Chattype, DC_CHAT_ID_ALLDONE_HINT, DC_CHAT_ID_ARCHIVED_LINK,
|
||||
DC_CHAT_ID_LAST_SPECIAL, DC_CHAT_ID_TRASH, DC_RESEND_USER_AVATAR_DAYS,
|
||||
DC_CHAT_ID_LAST_SPECIAL, DC_CHAT_ID_TRASH, DC_RESEND_USER_AVATAR_DAYS, EDITED_PREFIX,
|
||||
TIMESTAMP_SENT_TOLERANCE,
|
||||
};
|
||||
use crate::contact::{self, Contact, ContactId, Origin};
|
||||
@@ -3142,6 +3142,65 @@ pub async fn send_text_msg(
|
||||
send_msg(context, chat_id, &mut msg).await
|
||||
}
|
||||
|
||||
/// Sends chat members a request to edit the given message's text.
|
||||
pub async fn send_edit_request(context: &Context, msg_id: MsgId, new_text: String) -> Result<()> {
|
||||
let mut original_msg = Message::load_from_db(context, msg_id).await?;
|
||||
ensure!(
|
||||
original_msg.from_id == ContactId::SELF,
|
||||
"Can edit only own messages"
|
||||
);
|
||||
ensure!(!original_msg.is_info(), "Cannot edit info messages");
|
||||
ensure!(
|
||||
original_msg.viewtype != Viewtype::VideochatInvitation,
|
||||
"Cannot edit videochat invitations"
|
||||
);
|
||||
ensure!(
|
||||
!original_msg.text.is_empty(), // avoid complexity in UI element changes. focus is typos and rewordings
|
||||
"Cannot add text"
|
||||
);
|
||||
ensure!(!new_text.trim().is_empty(), "Edited text cannot be empty");
|
||||
if original_msg.text == new_text {
|
||||
info!(context, "Text unchanged.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
save_text_edit_to_db(context, &mut original_msg, &new_text).await?;
|
||||
|
||||
let mut edit_msg = Message::new_text(EDITED_PREFIX.to_owned() + &new_text); // prefix only set for nicer display in Non-Delta-MUAs
|
||||
edit_msg.set_quote(context, Some(&original_msg)).await?; // quote only set for nicer display in Non-Delta-MUAs
|
||||
if original_msg.get_showpadlock() {
|
||||
edit_msg.param.set_int(Param::GuaranteeE2ee, 1);
|
||||
}
|
||||
edit_msg
|
||||
.param
|
||||
.set(Param::TextEditFor, original_msg.rfc724_mid);
|
||||
edit_msg.hidden = true;
|
||||
send_msg(context, original_msg.chat_id, &mut edit_msg).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn save_text_edit_to_db(
|
||||
context: &Context,
|
||||
original_msg: &mut Message,
|
||||
new_text: &str,
|
||||
) -> Result<()> {
|
||||
original_msg.param.set_int(Param::IsEdited, 1);
|
||||
context
|
||||
.sql
|
||||
.execute(
|
||||
"UPDATE msgs SET txt=?, txt_normalized=?, param=? WHERE id=?",
|
||||
(
|
||||
new_text,
|
||||
message::normalize_text(new_text),
|
||||
original_msg.param.to_string(),
|
||||
original_msg.id,
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
context.emit_msgs_changed(original_msg.chat_id, original_msg.id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sends invitation to a videochat.
|
||||
pub async fn send_videochat_invitation(context: &Context, chat_id: ChatId) -> Result<MsgId> {
|
||||
ensure!(
|
||||
|
||||
Reference in New Issue
Block a user