Skip to content
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

Prefer Chat-Group-ID over In-Reply-To and References #5551

Merged
merged 4 commits into from May 13, 2024

Conversation

link2xt
Copy link
Collaborator

@link2xt link2xt commented May 10, 2024

  • refactor: add MimeMessage.get_chat_group_id()
  • fix: never treat message with Chat-Group-ID as a private reply
  • fix: always prefer Chat-Group-ID over In-Reply-To and References
  • fix: ignore parent message if message references itself

Fixes #5549

Chat-Group-ID always correctly identifies the chat
message was sent to, while In-Reply-To and References
may point to a message that has itself been incorrectly
assigned to a chat.
When there are no parent references,
Delta Chat inserts Message-ID into References.
Such references should be ignored
because otherwise fully downloaded message
may be assigned to the same chat as previously incorrectly assigned
partially downloaded message.

Fixes receive_imf::tests::test_create_group_with_big_msg
@link2xt link2xt force-pushed the link2xt/chat-group-id-priority branch from d3a6811 to a784a6b Compare May 10, 2024 22:43
if chat_id.is_none() {
if let Some(grpid) = mime_parser.get_chat_group_id() {
if let Some((id, _protected, blocked)) =
chat::get_chat_id_by_grpid(context, grpid).await?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this doesn't create a group, only looks it up, maybe we need to call create_or_lookup_group() instead? And also otherwise we have the duplicated logic here and in create_or_lookup_group()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this only looks up the group and only using Chat-Group-ID header. This ensures that it only happens for fully downloaded messages and group ID is not exctracted from Message-ID or References to messages send by old Delta Chat that included group ID into Message-IDs.

I want to make a minimal change to always assign fully downloaded group messages to known groups first. create_or_lookup_group() I think should be split to factor out group lookup and only call it when we were not able to assign to existing group, but this refactoring is for later PR.

@@ -810,6 +811,12 @@ impl MimeMessage {
self.headers.get(headerdef.get_headername())
}

/// Returns `Chat-Group-ID` header value if it is a valid group ID.
pub fn get_chat_group_id(&self) -> Option<&String> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably return the more idiomatic &str? Not that it matters much, feel free to ignore

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what .get_header() returns, I just passed it though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a follow-up PR fixing both functions: #5559

Comment on lines +706 to +708
let parent = get_parent_message(context, mime_parser)
.await?
.filter(|p| Some(p.id) != replace_msg_id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this may lead to the message suddenly disappear after clicking the "Download" button, which may be equally confusing. OTOH, we can just merge it and see whether people complain, and then think about which behavior is better (or whether whether we should even send a toast "Oops, this message actually belongs to group XY, fixed it now", which ofc would need support from the UIs)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this may lead to the message suddenly disappear after clicking the "Download" button

This was already the case before, most messages don't reference themselves. Delta Chat puts self-reference into References only if there are no better references found.

@link2xt link2xt merged commit 0d3c0a3 into main May 13, 2024
37 of 38 checks passed
@link2xt link2xt deleted the link2xt/chat-group-id-priority branch May 13, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prefer Chat-Group-Id header over In-Reply-To or References
3 participants