Skip to content

Commit

Permalink
saved-messages do not pop up in original chat in multi-device anymore
Browse files Browse the repository at this point in the history
fix #2020

When forwarding a message, the original `in_reply_to` stays in place.
I did not find any recent commit that changed anything about this,
but IIRC there was a bug that prevented setting the `in_reply_to` at
all.

So, for chat messages, do not look at the InReplyTo header (and also not
at the References header)
  • Loading branch information
Hocuri authored and link2xt committed Oct 23, 2020
1 parent c438691 commit e6b7a7e
Showing 1 changed file with 36 additions and 28 deletions.
64 changes: 36 additions & 28 deletions src/dc_receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,37 +1079,24 @@ async fn create_or_lookup_group(
set_better_msg(mime_parser, &better_msg);
}

let mut grpid = "".to_string();
if let Some(optional_field) = mime_parser.get(HeaderDef::ChatGroupId) {
grpid = optional_field.clone();
}
let grpid = try_getting_grpid(mime_parser);

if grpid.is_empty() {
if let Some(extracted_grpid) = mime_parser
.get(HeaderDef::MessageId)
.and_then(|value| dc_extract_grpid_from_rfc724_mid(&value))
{
grpid = extracted_grpid.to_string();
} else if let Some(extracted_grpid) = extract_grpid(mime_parser, HeaderDef::InReplyTo) {
grpid = extracted_grpid.to_string();
} else if let Some(extracted_grpid) = extract_grpid(mime_parser, HeaderDef::References) {
grpid = extracted_grpid.to_string();
} else {
return create_or_lookup_adhoc_group(
context,
mime_parser,
allow_creation,
create_blocked,
from_id,
to_ids,
)
.await
.map_err(|err| {
info!(context, "could not create adhoc-group: {:?}", err);
err
});
}
return create_or_lookup_adhoc_group(
context,
mime_parser,
allow_creation,
create_blocked,
from_id,
to_ids,
)
.await
.map_err(|err| {
info!(context, "could not create adhoc-group: {:?}", err);
err
});
}

// now we have a grpid that is non-empty
// but we might not know about this group

Expand Down Expand Up @@ -1378,6 +1365,27 @@ async fn create_or_lookup_group(
Ok((chat_id, chat_id_blocked))
}

fn try_getting_grpid(mime_parser: &MimeMessage) -> String {
if let Some(optional_field) = mime_parser.get(HeaderDef::ChatGroupId) {
return optional_field.clone();
}

if let Some(extracted_grpid) = mime_parser
.get(HeaderDef::MessageId)
.and_then(|value| dc_extract_grpid_from_rfc724_mid(&value))
{
return extracted_grpid.to_string();
}
if !mime_parser.has_chat_version() {
if let Some(extracted_grpid) = extract_grpid(mime_parser, HeaderDef::InReplyTo) {
return extracted_grpid.to_string();
} else if let Some(extracted_grpid) = extract_grpid(mime_parser, HeaderDef::References) {
return extracted_grpid.to_string();
}
}
"".to_string()
}

/// try extract a grpid from a message-id list header value
fn extract_grpid(mime_parser: &MimeMessage, headerdef: HeaderDef) -> Option<&str> {
let header = mime_parser.get(headerdef)?;
Expand Down

0 comments on commit e6b7a7e

Please sign in to comment.