mirror of
https://github.com/chatmail/core.git
synced 2026-04-21 15:36:30 +03:00
handle webxdc updates for not downloaded instances (#3487)
* save webxdc-updates for not yet downloaded messages, that are probably webxdc instances then * test webxdc updates received while instance is not yet downloaded * keep msg_id on downloading messages keeping msg_id on downloading messages has the advantage that webxdc updates and other references to the msg_id can be processed as usual. if a message expands to multiple msg_id, the last one is kept, however, this does not affect webxdc at all. (alternatives may be to update `msgs_status_updates` but that seems more complicated and even less elegant, another alternative would be to use different keys (eg. `rfc274_mid`), but that also seems not to be much easier and would waste space as well. also both alternatives would need adaption for other foreign keys) * update CHANGELOG * do not emit WebxdcStatusUpdate event in case the message is not yet downloaded * move DELETE/UPDATE to an transaction * make merge_msg_id() a little less confusing * use some webxdc-update-param from placeholder (the placeholder may be updated, the just downloaded messages is not) * more precise function name * test not directly downloading status updates * test not directly downloading mdn
This commit is contained in:
@@ -14,6 +14,7 @@ use tokio::io::AsyncReadExt;
|
||||
use crate::chat::Chat;
|
||||
use crate::contact::ContactId;
|
||||
use crate::context::Context;
|
||||
use crate::download::DownloadState;
|
||||
use crate::message::{Message, MessageState, MsgId, Viewtype};
|
||||
use crate::mimeparser::SystemMessage;
|
||||
use crate::param::Param;
|
||||
@@ -330,10 +331,12 @@ impl Context {
|
||||
|
||||
let status_update_serial = StatusUpdateSerial(u32::try_from(rowid)?);
|
||||
|
||||
self.emit_event(EventType::WebxdcStatusUpdate {
|
||||
msg_id: instance.id,
|
||||
status_update_serial,
|
||||
});
|
||||
if instance.viewtype == Viewtype::Webxdc {
|
||||
self.emit_event(EventType::WebxdcStatusUpdate {
|
||||
msg_id: instance.id,
|
||||
status_update_serial,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(status_update_serial)
|
||||
}
|
||||
@@ -475,6 +478,8 @@ impl Context {
|
||||
} else if let Some(parent) = msg.parent(self).await? {
|
||||
if parent.viewtype == Viewtype::Webxdc {
|
||||
(msg.timestamp_sort, parent, true)
|
||||
} else if parent.download_state() != DownloadState::Done {
|
||||
(msg.timestamp_sort, parent, false)
|
||||
} else {
|
||||
bail!("receive_status_update: message is not the child of a webxdc message.")
|
||||
}
|
||||
@@ -730,7 +735,7 @@ mod tests {
|
||||
use crate::chatlist::Chatlist;
|
||||
use crate::config::Config;
|
||||
use crate::contact::Contact;
|
||||
use crate::receive_imf::receive_imf;
|
||||
use crate::receive_imf::{receive_imf, receive_imf_inner};
|
||||
use crate::test_utils::TestContext;
|
||||
|
||||
use super::*;
|
||||
@@ -1038,6 +1043,71 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_webxdc_update_for_not_downloaded_instance() -> Result<()> {
|
||||
// Alice sends a larger instance and an update
|
||||
let alice = TestContext::new_alice().await;
|
||||
let bob = TestContext::new_bob().await;
|
||||
let chat = alice.create_chat(&bob).await;
|
||||
bob.set_config(Config::DownloadLimit, Some("40000")).await?;
|
||||
let mut alice_instance = create_webxdc_instance(
|
||||
&alice,
|
||||
"chess.xdc",
|
||||
include_bytes!("../test-data/webxdc/chess.xdc"),
|
||||
)
|
||||
.await?;
|
||||
let sent1 = alice.send_msg(chat.id, &mut alice_instance).await;
|
||||
let alice_instance = Message::load_from_db(&alice, sent1.sender_msg_id).await?;
|
||||
alice
|
||||
.send_webxdc_status_update(
|
||||
alice_instance.id,
|
||||
r#"{"payload": 7, "summary":"sum", "document":"doc"}"#,
|
||||
"bla",
|
||||
)
|
||||
.await?;
|
||||
alice.flush_status_updates().await?;
|
||||
let sent2 = alice.pop_sent_msg().await;
|
||||
|
||||
// Bob does not download instance but already receives update
|
||||
receive_imf_inner(
|
||||
&bob,
|
||||
&alice_instance.rfc724_mid,
|
||||
sent1.payload().as_bytes(),
|
||||
false,
|
||||
Some(70790),
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
let bob_instance = bob.get_last_msg().await;
|
||||
bob_instance.chat_id.accept(&bob).await?;
|
||||
bob.recv_msg(&sent2).await;
|
||||
assert_eq!(bob_instance.download_state, DownloadState::Available);
|
||||
|
||||
// Bob downloads instance, updates should be assigned correctly
|
||||
receive_imf_inner(
|
||||
&bob,
|
||||
&alice_instance.rfc724_mid,
|
||||
sent1.payload().as_bytes(),
|
||||
false,
|
||||
None,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
let bob_instance = bob.get_last_msg().await;
|
||||
assert_eq!(bob_instance.viewtype, Viewtype::Webxdc);
|
||||
assert_eq!(bob_instance.download_state, DownloadState::Done);
|
||||
assert_eq!(
|
||||
bob.get_webxdc_status_updates(bob_instance.id, StatusUpdateSerial(0))
|
||||
.await?,
|
||||
r#"[{"payload":7,"document":"doc","summary":"sum","serial":1,"max_serial":1}]"#
|
||||
);
|
||||
let info = bob_instance.get_webxdc_info(&bob).await?;
|
||||
assert_eq!(info.document, "doc");
|
||||
assert_eq!(info.summary, "sum");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_delete_webxdc_instance() -> Result<()> {
|
||||
let t = TestContext::new_alice().await;
|
||||
|
||||
Reference in New Issue
Block a user