From 185d8b552c01a4622e0b44fa23df2dbc5398f1de Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 7 Jun 2024 19:22:00 +0200 Subject: [PATCH] show integration state in summary --- src/webxdc.rs | 12 ++++++++++-- src/webxdc/integration.rs | 20 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/webxdc.rs b/src/webxdc.rs index 51802dd81a..0fc6dbac89 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -824,6 +824,9 @@ impl Message { } } + let request_integration = manifest.integration.unwrap_or_default(); + let is_integrated = self.is_set_as_webxdc_integration(context).await?; + let internet_access = manifest.request_internet_access.unwrap_or_default() && self.chat_id.is_self_talk(context).await.unwrap_or_default() && self.get_showpadlock(); @@ -846,7 +849,12 @@ impl Message { .get(Param::WebxdcDocument) .unwrap_or_default() .to_string(), - summary: if internet_access { + summary: if is_integrated { + "🌍 Used as map. Delete to use default. Do not enter sensitive data".to_string() + } else if request_integration == "maps" { + "🌏 To use as map, forward to \"Saved Messages\" again. Do not enter sensitive data" + .to_string() + } else if internet_access { "Dev Mode: Do not enter sensitive data!".to_string() } else { self.param @@ -859,7 +867,7 @@ impl Message { } else { "".to_string() }, - integration: manifest.integration.unwrap_or_default(), + integration: request_integration, internet_access, }) } diff --git a/src/webxdc/integration.rs b/src/webxdc/integration.rs index fe2346948a..d320e98ffb 100644 --- a/src/webxdc/integration.rs +++ b/src/webxdc/integration.rs @@ -121,6 +121,18 @@ impl Message { None } } + + // Check if the message is an actually used as Webxdc integration. + pub(crate) async fn is_set_as_webxdc_integration(&self, context: &Context) -> Result { + if let Some(integration_id) = context + .get_config_parsed::(Config::WebxdcIntegration) + .await? + { + Ok(integration_id == self.id.to_u32()) + } else { + Ok(false) + } + } } #[cfg(test)] @@ -193,11 +205,15 @@ mod tests { ) .await?; let sent = t.send_msg(self_chat.id, &mut msg).await; + let info = msg.get_webxdc_info(&t).await?; + assert!(info.summary.contains("Used as map")); assert_integration(&t, "Maps Test 2").await?; - // when maps.xdc is received on another device, the integration is not accepted + // when maps.xdc is received on another device, the integration is not accepted (needs to be forwarded again) let t2 = TestContext::new_alice().await; - t2.recv_msg(&sent).await; + let msg2 = t2.recv_msg(&sent).await; + let info = msg2.get_webxdc_info(&t2).await?; + assert!(info.summary.contains("To use as map,")); assert!(t2.init_webxdc_integration(None).await?.is_none()); // deleting maps.xdc removes the user's integration - the UI will go back to default calling set_webxdc_integration() then