-
-
Notifications
You must be signed in to change notification settings - Fork 116
feat: pre-messages / next version of download on demand #7371
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
Draft
Simon-Laux
wants to merge
12
commits into
main
Choose a base branch
from
pre-messages
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a98fe05
feat: message previews
Simon-Laux eb489bc
remove "Contact" stock string again, use emoji like in summaries
link2xt 78f884f
fix: Add additional_text also to the summary, in order to prevent emp…
Hocuri 411126f
refactor: Rename download_when_normal_starts->download_later
Hocuri 96fa64d
refactor: use more idiomatic way of creating Vec, and remove prematur…
Hocuri a8f0a6d
improve error message
link2xt 4458663
move download_msgs call
link2xt 60b28cb
log request to download
link2xt 53dc1c7
rustfmt
link2xt 73a2c94
test: add pre-message test
link2xt 2b3d35b
fix: Properly advance uid_next when skipping a post-message
Hocuri 3f5fc45
Merge branch 'main' into pre-messages
Hocuri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -488,11 +488,11 @@ char* dc_get_blobdir (const dc_context_t* context); | |||||
| * 0=use IMAP IDLE if the server supports it. | ||||||
| * This is a developer option used for testing polling used as an IDLE fallback. | ||||||
| * - `download_limit` = Messages up to this number of bytes are downloaded automatically. | ||||||
| * For larger messages, only the header is downloaded and a placeholder is shown. | ||||||
| * For messages with large attachments, two messages are sent: | ||||||
| * a Pre-Message containing metadata and a Post-Message containing the attachment. | ||||||
| * Pre-Messages are always downloaded and show a placeholder message. | ||||||
| * These messages can be downloaded fully using dc_download_full_msg() later. | ||||||
| * The limit is compared against raw message sizes, including headers. | ||||||
| * The actually used limit may be corrected | ||||||
| * to not mess up with non-delivery-reports or read-receipts. | ||||||
| * Post-Messages are automatically downloaded if they are smaller than the download_limit. | ||||||
| * 0=no limit (default). | ||||||
| * Changes affect future messages only. | ||||||
| * - `protect_autocrypt` = Enable Header Protection for Autocrypt header. | ||||||
|
|
@@ -4310,7 +4310,8 @@ char* dc_msg_get_webxdc_info (const dc_msg_t* msg); | |||||
|
|
||||||
| /** | ||||||
| * Get the size of the file. Returns the size of the file associated with a | ||||||
| * message, if applicable. | ||||||
| * message, if applicable. | ||||||
| * If message is a pre-message, then this returns size of the to be downloaded file. | ||||||
|
Collaborator
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.
Suggested change
|
||||||
| * | ||||||
| * Typically, this is used to show the size of document files, e.g. a PDF. | ||||||
| * | ||||||
|
|
@@ -7263,22 +7264,9 @@ void dc_event_unref(dc_event_t* event); | |||||
| /// `%1$s` will be replaced by the percentage used | ||||||
| #define DC_STR_QUOTA_EXCEEDING_MSG_BODY 98 | ||||||
|
|
||||||
| /// "%1$s message" | ||||||
| /// | ||||||
| /// Used as the message body when a message | ||||||
| /// was not yet downloaded completely | ||||||
| /// (dc_msg_get_download_state() is e.g. @ref DC_DOWNLOAD_AVAILABLE). | ||||||
| /// | ||||||
| /// `%1$s` will be replaced by human-readable size (e.g. "1.2 MiB"). | ||||||
| /// @deprecated Deprecated 2025-11-12, this string is no longer needed. | ||||||
| #define DC_STR_PARTIAL_DOWNLOAD_MSG_BODY 99 | ||||||
|
|
||||||
| /// "Download maximum available until %1$s" | ||||||
| /// | ||||||
| /// Appended after some separator to @ref DC_STR_PARTIAL_DOWNLOAD_MSG_BODY. | ||||||
| /// | ||||||
| /// `%1$s` will be replaced by human-readable date and time. | ||||||
| #define DC_STR_DOWNLOAD_AVAILABILITY 100 | ||||||
|
|
||||||
| /// "Multi Device Synchronization" | ||||||
| /// | ||||||
| /// Used in subjects of outgoing sync messages. | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -92,6 +92,9 @@ pub struct MessageObject { | |||||
|
|
||||||
| file: Option<String>, | ||||||
| file_mime: Option<String>, | ||||||
|
|
||||||
| /// The size of the file in bytes, if applicable. | ||||||
| /// If message is a pre-message, then this is the size of the to be downloaded file. | ||||||
|
Collaborator
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.
Suggested change
|
||||||
| file_bytes: u64, | ||||||
| file_name: Option<String>, | ||||||
|
|
||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,13 +5,12 @@ | |
| import os | ||
| import socket | ||
| import subprocess | ||
| import time | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from deltachat_rpc_client import Contact, EventType, Message, events | ||
| from deltachat_rpc_client.const import DownloadState, MessageState | ||
| from deltachat_rpc_client import EventType, events | ||
| from deltachat_rpc_client.const import MessageState, DownloadState | ||
| from deltachat_rpc_client.pytestplugin import E2EE_INFO_MSGS | ||
| from deltachat_rpc_client.rpc import JsonRpcError | ||
|
|
||
|
|
@@ -333,7 +332,7 @@ def test_receive_imf_failure(acfactory) -> None: | |
| alice_contact_bob = alice.create_contact(bob, "Bob") | ||
| alice_chat_bob = alice_contact_bob.create_chat() | ||
|
|
||
| bob.set_config("fail_on_receiving_full_msg", "1") | ||
| bob.set_config("simulate_receive_imf_error", "1") | ||
| alice_chat_bob.send_text("Hello!") | ||
| event = bob.wait_for_event(EventType.MSGS_CHANGED) | ||
| assert event.chat_id == bob.get_device_chat().id | ||
|
|
@@ -343,18 +342,17 @@ def test_receive_imf_failure(acfactory) -> None: | |
| version = bob.get_info()["deltachat_core_version"] | ||
| assert ( | ||
| snapshot.text == "❌ Failed to receive a message:" | ||
| " Condition failed: `!context.get_config_bool(Config::FailOnReceivingFullMsg).await?`." | ||
| " Condition failed: `!context.get_config_bool(Config::SimulateReceiveImfError).await?`." | ||
| f" Core version {version}." | ||
| " Please report this bug to [email protected] or https://support.delta.chat/." | ||
| ) | ||
|
|
||
| # The failed message doesn't break the IMAP loop. | ||
| bob.set_config("fail_on_receiving_full_msg", "0") | ||
| bob.set_config("simulate_receive_imf_error", "0") | ||
| alice_chat_bob.send_text("Hello again!") | ||
| message = bob.wait_for_incoming_msg() | ||
| snapshot = message.get_snapshot() | ||
| assert snapshot.text == "Hello again!" | ||
| assert snapshot.download_state == DownloadState.DONE | ||
| assert snapshot.error is None | ||
|
|
||
|
|
||
|
|
@@ -687,94 +685,6 @@ def test_mdn_doesnt_break_autocrypt(acfactory) -> None: | |
| assert snapshot.show_padlock | ||
|
|
||
|
|
||
| def test_reaction_to_partially_fetched_msg(acfactory, tmp_path): | ||
| """See https://github.com/deltachat/deltachat-core-rust/issues/3688 "Partially downloaded | ||
| messages are received out of order". | ||
|
|
||
| If the Inbox contains X small messages followed by Y large messages followed by Z small | ||
| messages, Delta Chat first downloaded a batch of X+Z messages, and then a batch of Y messages. | ||
|
|
||
| This bug was discovered by @Simon-Laux while testing reactions PR #3644 and can be reproduced | ||
| with online test as follows: | ||
| - Bob enables download limit and goes offline. | ||
| - Alice sends a large message to Bob and reacts to this message with a thumbs-up. | ||
| - Bob goes online | ||
| - Bob first processes a reaction message and throws it away because there is no corresponding | ||
| message, then processes a partially downloaded message. | ||
| - As a result, Bob does not see a reaction | ||
| """ | ||
| download_limit = 300000 | ||
| ac1, ac2 = acfactory.get_online_accounts(2) | ||
| ac1_addr = ac1.get_config("addr") | ||
| chat = ac1.create_chat(ac2) | ||
| ac2.set_config("download_limit", str(download_limit)) | ||
| ac2.stop_io() | ||
|
|
||
| logging.info("sending small+large messages from ac1 to ac2") | ||
| msgs = [] | ||
| msgs.append(chat.send_text("hi")) | ||
| path = tmp_path / "large" | ||
| path.write_bytes(os.urandom(download_limit + 1)) | ||
| msgs.append(chat.send_file(str(path))) | ||
| for m in msgs: | ||
| m.wait_until_delivered() | ||
|
|
||
| logging.info("sending a reaction to the large message from ac1 to ac2") | ||
| # TODO: Find the reason of an occasional message reordering on the server (so that the reaction | ||
| # has a lower UID than the previous message). W/a is to sleep for some time to let the reaction | ||
| # have a later INTERNALDATE. | ||
| time.sleep(1.1) | ||
| react_str = "\N{THUMBS UP SIGN}" | ||
| msgs.append(msgs[-1].send_reaction(react_str)) | ||
| msgs[-1].wait_until_delivered() | ||
|
|
||
| ac2.start_io() | ||
|
|
||
| logging.info("wait for ac2 to receive a reaction") | ||
| msg2 = Message(ac2, ac2.wait_for_reactions_changed().msg_id) | ||
| assert msg2.get_sender_contact().get_snapshot().address == ac1_addr | ||
| assert msg2.get_snapshot().download_state == DownloadState.AVAILABLE | ||
| reactions = msg2.get_reactions() | ||
| contacts = [Contact(ac2, int(i)) for i in reactions.reactions_by_contact] | ||
| assert len(contacts) == 1 | ||
| assert contacts[0].get_snapshot().address == ac1_addr | ||
| assert list(reactions.reactions_by_contact.values())[0] == [react_str] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("n_accounts", [3, 2]) | ||
| def test_download_limit_chat_assignment(acfactory, tmp_path, n_accounts): | ||
| download_limit = 300000 | ||
|
|
||
| alice, *others = acfactory.get_online_accounts(n_accounts) | ||
| bob = others[0] | ||
|
|
||
| alice_group = alice.create_group("test group") | ||
| for account in others: | ||
| chat = account.create_chat(alice) | ||
| chat.send_text("Hello Alice!") | ||
| assert alice.wait_for_incoming_msg().get_snapshot().text == "Hello Alice!" | ||
|
|
||
| contact = alice.create_contact(account) | ||
| alice_group.add_contact(contact) | ||
|
|
||
| bob.set_config("download_limit", str(download_limit)) | ||
|
|
||
| alice_group.send_text("hi") | ||
| snapshot = bob.wait_for_incoming_msg().get_snapshot() | ||
| assert snapshot.text == "hi" | ||
| bob_group = snapshot.chat | ||
|
|
||
| path = tmp_path / "large" | ||
| path.write_bytes(os.urandom(download_limit + 1)) | ||
|
|
||
| for i in range(10): | ||
| logging.info("Sending message %s", i) | ||
| alice_group.send_file(str(path)) | ||
| snapshot = bob.wait_for_incoming_msg().get_snapshot() | ||
| assert snapshot.download_state == DownloadState.AVAILABLE | ||
| assert snapshot.chat == bob_group | ||
|
|
||
|
|
||
| def test_markseen_contact_request(acfactory): | ||
| """ | ||
| Test that seen status is synchronized for contact request messages | ||
|
|
@@ -1152,3 +1062,21 @@ def test_synchronize_member_list_on_group_rejoin(acfactory, log): | |
|
|
||
| assert chat.num_contacts() == 2 | ||
| assert msg.get_snapshot().chat.num_contacts() == 2 | ||
|
|
||
|
|
||
| def test_large_message(acfactory) -> None: | ||
| """ | ||
| Test sending large message without download limit set, | ||
| so it is sent with pre-message but downloaded without user interaction. | ||
| """ | ||
| alice, bob = acfactory.get_online_accounts(2) | ||
|
|
||
| alice_chat_bob = alice.create_chat(bob) | ||
| alice_chat_bob.send_message( | ||
| "Hello World, this message is bigger than 5 bytes", | ||
| file="../test-data/image/screenshot.jpg", | ||
| ) | ||
|
|
||
| msg = bob.wait_for_incoming_msg() | ||
| snapshot = msg.get_snapshot() | ||
| assert snapshot.text == "Hello World, this message is bigger than 5 bytes" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ use super::*; | |
| use crate::chat::forward_msgs; | ||
| use crate::config::Config; | ||
| use crate::constants::DC_CHAT_ID_TRASH; | ||
| use crate::receive_imf::{receive_imf, receive_imf_from_inbox}; | ||
| use crate::receive_imf::receive_imf; | ||
| use crate::test_utils::{TestContext, TestContextManager}; | ||
|
|
||
| struct CallSetup { | ||
|
|
@@ -610,65 +610,3 @@ async fn test_end_text_call() -> Result<()> { | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Tests that partially downloaded "call ended" | ||
| /// messages are not processed. | ||
| #[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
| async fn test_no_partial_calls() -> Result<()> { | ||
| let mut tcm = TestContextManager::new(); | ||
| let alice = &tcm.alice().await; | ||
|
|
||
| let seen = false; | ||
|
|
||
| // The messages in the test | ||
| // have no `Date` on purpose, | ||
| // so they are treated as new. | ||
| let received_call = receive_imf( | ||
| alice, | ||
| b"From: [email protected]\n\ | ||
| To: [email protected]\n\ | ||
| Message-ID: <[email protected]>\n\ | ||
| Chat-Version: 1.0\n\ | ||
| Chat-Content: call\n\ | ||
| Chat-Webrtc-Room: YWFhYWFhYWFhCg==\n\ | ||
| \n\ | ||
| Hello, this is a call\n", | ||
| seen, | ||
| ) | ||
| .await? | ||
| .unwrap(); | ||
| assert_eq!(received_call.msg_ids.len(), 1); | ||
| let call_msg = Message::load_from_db(alice, received_call.msg_ids[0]) | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!(call_msg.viewtype, Viewtype::Call); | ||
| assert_eq!(call_state(alice, call_msg.id).await?, CallState::Alerting); | ||
|
|
||
| let imf_raw = b"From: [email protected]\n\ | ||
| To: [email protected]\n\ | ||
| Message-ID: <[email protected]>\n\ | ||
| In-Reply-To: <[email protected]>\n\ | ||
| Chat-Version: 1.0\n\ | ||
| Chat-Content: call-ended\n\ | ||
| \n\ | ||
| Call ended\n"; | ||
| receive_imf_from_inbox( | ||
| alice, | ||
| "[email protected]", | ||
| imf_raw, | ||
| seen, | ||
| Some(imf_raw.len().try_into().unwrap()), | ||
| ) | ||
| .await?; | ||
|
|
||
| // The call is still not ended. | ||
| assert_eq!(call_state(alice, call_msg.id).await?, CallState::Alerting); | ||
|
|
||
| // Fully downloading the message ends the call. | ||
| receive_imf_from_inbox(alice, "[email protected]", imf_raw, seen, None) | ||
| .await | ||
| .context("Failed to fully download end call message")?; | ||
| assert_eq!(call_state(alice, call_msg.id).await?, CallState::Missed); | ||
|
|
||
| Ok(()) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
"Full message" was a better term, "post-message" is literally "smth going after the message". And the full message should contain metadata as well, but the documentation doesn't say that