From 4af4914e32e88fd6f01317c60507fec5cf25baaf Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 13 Jan 2022 12:42:24 +0100 Subject: [PATCH] simplify WebxdcStatusUpdate handling --- src/webxdc.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/webxdc.rs b/src/webxdc.rs index a705d717a..39737d8a7 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -86,6 +86,8 @@ impl Context { Ok(false) } + /// Takes a payload and writes it to the database. + /// Moreover, events are handled. async fn create_status_update_record( &self, instance_msg_id: MsgId, @@ -105,7 +107,14 @@ impl Context { paramsv![instance_msg_id, serde_json::to_string(&status_update_item)?], ) .await?; - Ok(StatusUpdateId(u32::try_from(rowid)?)) + let status_update_id = StatusUpdateId(u32::try_from(rowid)?); + + self.emit_event(EventType::WebxdcStatusUpdate { + msg_id: instance_msg_id, + status_update_id, + }); + + Ok(status_update_id) } /// Sends a status update for an webxdc instance. @@ -129,10 +138,6 @@ impl Context { let status_update_id = self .create_status_update_record(instance_msg_id, payload) .await?; - self.emit_event(EventType::WebxdcStatusUpdate { - msg_id: instance_msg_id, - status_update_id, - }); match instance.state { MessageState::Undefined | MessageState::OutPreparing | MessageState::OutDraft => { // send update once the instance is actually send @@ -202,16 +207,11 @@ impl Context { let updates: StatusUpdates = serde_json::from_str(json)?; for update_item in updates.updates { - let status_update_id = self - .create_status_update_record( - instance.id, - &*serde_json::to_string(&update_item.payload)?, - ) - .await?; - self.emit_event(EventType::WebxdcStatusUpdate { - msg_id: instance.id, - status_update_id, - }); + self.create_status_update_record( + instance.id, + &*serde_json::to_string(&update_item.payload)?, + ) + .await?; } Ok(())