mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 22:46:29 +03:00
@@ -143,16 +143,16 @@ struct StatusUpdates {
|
||||
/// Update items as sent on the wire and as stored in the database.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub(crate) struct StatusUpdateItem {
|
||||
payload: Value,
|
||||
pub(crate) payload: Value,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
info: Option<String>,
|
||||
pub(crate) info: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
document: Option<String>,
|
||||
pub(crate) document: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
summary: Option<String>,
|
||||
pub(crate) summary: Option<String>,
|
||||
}
|
||||
|
||||
/// Update items as passed to the UIs.
|
||||
@@ -348,16 +348,10 @@ impl Context {
|
||||
self.emit_msgs_changed(instance.chat_id, instance.id);
|
||||
}
|
||||
|
||||
let rowid = self
|
||||
.sql
|
||||
.insert(
|
||||
"INSERT INTO msgs_status_updates (msg_id, update_item) VALUES(?, ?);",
|
||||
paramsv![instance.id, serde_json::to_string(&status_update_item)?],
|
||||
)
|
||||
let status_update_serial = self
|
||||
.write_status_update_inner(&instance.id, status_update_item)
|
||||
.await?;
|
||||
|
||||
let status_update_serial = StatusUpdateSerial(u32::try_from(rowid)?);
|
||||
|
||||
if instance.viewtype == Viewtype::Webxdc {
|
||||
self.emit_event(EventType::WebxdcStatusUpdate {
|
||||
msg_id: instance.id,
|
||||
@@ -368,6 +362,22 @@ impl Context {
|
||||
Ok(status_update_serial)
|
||||
}
|
||||
|
||||
pub(crate) async fn write_status_update_inner(
|
||||
&self,
|
||||
instance_id: &MsgId,
|
||||
status_update_item: StatusUpdateItem,
|
||||
) -> Result<StatusUpdateSerial> {
|
||||
let rowid = self
|
||||
.sql
|
||||
.insert(
|
||||
"INSERT INTO msgs_status_updates (msg_id, update_item) VALUES(?, ?);",
|
||||
paramsv![instance_id, serde_json::to_string(&status_update_item)?],
|
||||
)
|
||||
.await?;
|
||||
let status_update_serial = StatusUpdateSerial(u32::try_from(rowid)?);
|
||||
Ok(status_update_serial)
|
||||
}
|
||||
|
||||
/// Sends a status update for an webxdc instance.
|
||||
///
|
||||
/// If the instance is a draft,
|
||||
@@ -2415,4 +2425,42 @@ sth_for_the = "future""#
|
||||
.await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn change_logging_webxdc() -> Result<()> {
|
||||
let alice = TestContext::new_alice().await;
|
||||
let chat_id = ChatId::create_for_contact(&alice, ContactId::SELF).await?;
|
||||
|
||||
assert_eq!(
|
||||
alice
|
||||
.sql
|
||||
.count("SELECT COUNT(*) FROM msgs_status_updates;", paramsv![],)
|
||||
.await?,
|
||||
0
|
||||
);
|
||||
|
||||
let mut instance = create_webxdc_instance(
|
||||
&alice,
|
||||
"debug_logging.xdc",
|
||||
include_bytes!("../test-data/webxdc/minimal.xdc"),
|
||||
)
|
||||
.await?;
|
||||
assert!(alice.debug_logging.read().await.is_none());
|
||||
send_msg(&alice, chat_id, &mut instance).await?;
|
||||
assert!(alice.debug_logging.read().await.is_some());
|
||||
|
||||
alice.emit_event(EventType::Info("hi".to_string()));
|
||||
alice
|
||||
.evtracker
|
||||
.get_matching(|ev| matches!(*ev, EventType::WebxdcStatusUpdate { .. }))
|
||||
.await;
|
||||
assert!(
|
||||
alice
|
||||
.sql
|
||||
.count("SELECT COUNT(*) FROM msgs_status_updates;", paramsv![],)
|
||||
.await?
|
||||
> 0
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user