diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 14ffdf497..234bbd89a 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -1163,10 +1163,10 @@ impl<'a> MimeFactory<'a> { let json = self.msg.param.get(Param::Arg).unwrap_or_default(); parts.push(context.build_status_update_part(json).await); } else if self.msg.viewtype == Viewtype::Webxdc { - let json = context + if let Some(json) = context .render_webxdc_status_update_object(self.msg.id, None) - .await?; - if json != r#"{{"updates":[]}}"# { + .await? + { parts.push(context.build_status_update_part(&json).await); } } diff --git a/src/webxdc.rs b/src/webxdc.rs index c81ace9fe..a705d717a 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -157,7 +157,8 @@ impl Context { instance_msg_id, Some(status_update_id), ) - .await?, + .await? + .ok_or_else(|| format_err!("Status object expected."))?, ); status_update.set_quote(self, Some(&instance)).await?; let status_update_msg_id = @@ -257,11 +258,15 @@ impl Context { &self, instance_msg_id: MsgId, status_update_id: Option, - ) -> Result { + ) -> Result> { let updates_array = self .get_webxdc_status_updates(instance_msg_id, status_update_id) .await?; - Ok(format!(r#"{{"updates":{}}}"#, updates_array)) + if updates_array == "[]" { + Ok(None) + } else { + Ok(Some(format!(r#"{{"updates":{}}}"#, updates_array))) + } } } @@ -717,6 +722,31 @@ mod tests { Ok(()) } + #[async_std::test] + async fn test_render_webxdc_status_update_object() -> Result<()> { + let t = TestContext::new_alice().await; + let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "a chat").await?; + let mut instance = create_webxdc_instance( + &t, + "minimal.xdc", + include_bytes!("../test-data/webxdc/minimal.xdc"), + ) + .await?; + chat_id.set_draft(&t, Some(&mut instance)).await?; + assert!(t + .render_webxdc_status_update_object(instance.id, None) + .await? + .is_none()); + + t.send_webxdc_status_update(instance.id, "1", "bla").await?; + assert!(t + .render_webxdc_status_update_object(instance.id, None) + .await? + .is_some()); + + Ok(()) + } + #[async_std::test] async fn test_draft_and_send_webxdc_status_update() -> Result<()> { let alice = TestContext::new_alice().await;