-
-
Notifications
You must be signed in to change notification settings - Fork 129
fix: Send pre-message after successful sending of post-message (#8063) #8222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1723,23 +1723,19 @@ impl MimeFactory { | |
|
|
||
| let footer = if is_reaction { "" } else { &self.selfstatus }; | ||
|
|
||
| let message_text = if self.pre_message_mode == PreMessageMode::Post { | ||
| "".to_string() | ||
| } else { | ||
| format!( | ||
| "{}{}{}{}{}{}", | ||
| fwdhint.unwrap_or_default(), | ||
| quoted_text.unwrap_or_default(), | ||
| escape_message_footer_marks(final_text), | ||
| if !final_text.is_empty() && !footer.is_empty() { | ||
| "\r\n\r\n" | ||
| } else { | ||
| "" | ||
| }, | ||
| if !footer.is_empty() { "-- \r\n" } else { "" }, | ||
| footer | ||
| ) | ||
| }; | ||
| let message_text = format!( | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compat problem: duplicate text for ancient versions |
||
| "{}{}{}{}{}{}", | ||
| fwdhint.unwrap_or_default(), | ||
| quoted_text.unwrap_or_default(), | ||
| escape_message_footer_marks(final_text), | ||
| if !final_text.is_empty() && !footer.is_empty() { | ||
| "\r\n\r\n" | ||
| } else { | ||
| "" | ||
| }, | ||
| if !footer.is_empty() { "-- \r\n" } else { "" }, | ||
| footer | ||
| ); | ||
|
|
||
| let mut main_part = MimePart::new("text/plain", message_text); | ||
| if is_reaction { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -533,18 +533,10 @@ pub(crate) async fn receive_imf_inner( | |
| "Receiving message {rfc724_mid_orig:?}, seen={seen}...", | ||
| ); | ||
|
|
||
| // These checks must be done before processing of SecureJoin and other special messages. | ||
| if mime_parser.pre_message == mimeparser::PreMessageMode::Post { | ||
| // Post-Message just replaces the attachment and modifies Params, not the whole message. | ||
| // This is done in the `handle_post_message` method. | ||
| } else if let Some(msg_id) = message::rfc724_mid_exists(context, rfc724_mid_orig).await? { | ||
| info!( | ||
| context, | ||
| "Message {rfc724_mid} is already in some chat or deleted." | ||
| ); | ||
| if mime_parser.incoming { | ||
| return Ok(None); | ||
| } | ||
| let msg_id = message::rfc724_mid_exists(context, rfc724_mid_orig).await?; | ||
| if let Some(msg_id) = msg_id | ||
| && !mime_parser.incoming | ||
| { | ||
| // For the case if we missed a successful SMTP response. Be optimistic that the message is | ||
| // delivered also. | ||
| let self_addr = context.get_primary_self_addr().await?; | ||
|
|
@@ -559,6 +551,16 @@ pub(crate) async fn receive_imf_inner( | |
| if !msg_has_pending_smtp_job(context, msg_id).await? { | ||
| msg_id.set_delivered(context).await?; | ||
| } | ||
| } | ||
| // These checks must be done before processing of SecureJoin and other special messages. | ||
| if mime_parser.pre_message == mimeparser::PreMessageMode::Post { | ||
| // Post-Message just replaces the attachment and modifies Params, not the whole message. | ||
| // This is done in the `update_from_post_msg` method. | ||
| } else if msg_id.is_some() { | ||
| info!( | ||
| context, | ||
| "Message {rfc724_mid} is already in some chat or deleted." | ||
| ); | ||
| return Ok(None); | ||
| } | ||
|
|
||
|
|
@@ -2080,7 +2082,7 @@ async fn add_parts( | |
| } | ||
|
|
||
| handle_edit_delete(context, mime_parser, from_id).await?; | ||
| handle_post_message(context, mime_parser, from_id, state).await?; | ||
| update_from_post_msg(context, mime_parser, from_id, state).await?; | ||
|
|
||
| if mime_parser.is_system_message == SystemMessage::CallAccepted | ||
| || mime_parser.is_system_message == SystemMessage::CallEnded | ||
|
|
@@ -2274,8 +2276,7 @@ INSERT INTO msgs | |
|
|
||
| // Maybe set logging xdc and add gossip topics for webxdcs. | ||
| for (part, msg_id) in mime_parser.parts.iter().zip(&created_db_entries) { | ||
| if mime_parser.pre_message != PreMessageMode::Post | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compat problem: missing iroh topic id |
||
| && part.typ == Viewtype::Webxdc | ||
| if part.typ == Viewtype::Webxdc | ||
| && let Some(topic) = mime_parser.get_header(HeaderDef::IrohGossipTopic) | ||
| { | ||
| let topic = iroh_topic_from_str(topic)?; | ||
|
|
@@ -2424,7 +2425,7 @@ async fn handle_edit_delete( | |
| Ok(()) | ||
| } | ||
|
|
||
| async fn handle_post_message( | ||
| async fn update_from_post_msg( | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decided to rename it to underline that only an already existing message is updated, to avoid more bugs caused by not fully handling post-messages |
||
| context: &Context, | ||
| mime_parser: &MimeMessage, | ||
| from_id: ContactId, | ||
|
|
@@ -2442,15 +2443,15 @@ async fn handle_post_message( | |
| let Some(msg_id) = message::rfc724_mid_exists(context, &rfc724_mid).await? else { | ||
| warn!( | ||
| context, | ||
| "handle_post_message: {rfc724_mid}: Database entry does not exist." | ||
| "update_from_post_msg: {rfc724_mid}: Database entry does not exist." | ||
| ); | ||
| return Ok(()); | ||
| }; | ||
| let Some(original_msg) = Message::load_from_db_optional(context, msg_id).await? else { | ||
| // else: message is processed like a normal message | ||
| warn!( | ||
| context, | ||
| "handle_post_message: {rfc724_mid}: Pre-message was not downloaded yet so treat as normal message." | ||
| "update_from_post_msg: {rfc724_mid}: Pre-message was not downloaded yet so treat as normal message." | ||
| ); | ||
| return Ok(()); | ||
| }; | ||
|
|
@@ -2461,22 +2462,25 @@ async fn handle_post_message( | |
| // Do nothing if safety checks fail, the worst case is the message modifies the chat if the | ||
| // sender is a member. | ||
| if from_id != original_msg.from_id { | ||
| warn!(context, "handle_post_message: {rfc724_mid}: Bad sender."); | ||
| warn!(context, "update_from_post_msg: {rfc724_mid}: Bad sender."); | ||
| return Ok(()); | ||
| } | ||
| let post_msg_showpadlock = part | ||
| .param | ||
| .get_bool(Param::GuaranteeE2ee) | ||
| .unwrap_or_default(); | ||
| if !post_msg_showpadlock && original_msg.get_showpadlock() { | ||
| warn!(context, "handle_post_message: {rfc724_mid}: Not encrypted."); | ||
| warn!( | ||
| context, | ||
| "update_from_post_msg: {rfc724_mid}: Not encrypted." | ||
| ); | ||
| return Ok(()); | ||
| } | ||
|
|
||
| if !part.typ.has_file() { | ||
| warn!( | ||
| context, | ||
| "handle_post_message: {rfc724_mid}: First mime part's message-viewtype has no file." | ||
| "update_from_post_msg: {rfc724_mid}: First mime part's message-viewtype has no file." | ||
| ); | ||
| return Ok(()); | ||
| } | ||
|
|
@@ -2507,7 +2511,10 @@ WHERE id=? | |
| part.typ, | ||
| part.bytes as isize, | ||
| part.error.as_deref().unwrap_or_default(), | ||
| state, | ||
| match mime_parser.incoming { | ||
| true => state, | ||
| false => MessageState::Undefined, | ||
| }, | ||
| DownloadState::Done as u32, | ||
| original_msg.id, | ||
| ), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compat problem: extra traffic for older versions