diff --git a/src/chat.rs b/src/chat.rs index e4cb89057..60daad7dc 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -2636,7 +2636,7 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> { { if better_type != Viewtype::Webxdc || context - .ensure_sendable_webxdc_file(&blob.to_abs_path()) + .prepare_webxdc_file(&blob.to_abs_path(), msg) .await .is_ok() { @@ -2645,7 +2645,7 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> { } } else if msg.viewtype == Viewtype::Webxdc { context - .ensure_sendable_webxdc_file(&blob.to_abs_path()) + .prepare_webxdc_file(&blob.to_abs_path(), msg) .await?; } @@ -2913,7 +2913,7 @@ pub(crate) async fn create_send_msg_jobs(context: &Context, msg: &mut Message) - recipients.push(from); } - // Webxdc integrations are messages, however, shipped with main app and must not be sent out + // Webxdc integrations are local (shipped with app or added to "Saved Messages") and must not be sent out if msg.param.get_int(Param::WebxdcIntegration).is_some() { recipients.clear(); } diff --git a/src/webxdc.rs b/src/webxdc.rs index 78f5898d5..9fefae808 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -66,6 +66,9 @@ pub struct WebxdcManifest { /// Optional URL of webxdc source code. pub source_code_url: Option, + /// If the webxdc is an integration. + pub integration: Option, + /// If the webxdc requests network access. pub request_internet_access: Option, } @@ -220,7 +223,8 @@ impl Context { } /// Ensure that a file is an acceptable webxdc for sending. - pub(crate) async fn ensure_sendable_webxdc_file(&self, path: &Path) -> Result<()> { + /// Moreover, check if the webxdc is an integration and add that information to the message object. + pub(crate) async fn prepare_webxdc_file(&self, path: &Path, msg: &mut Message) -> Result<()> { let filename = path.to_str().unwrap_or_default(); if !filename.ends_with(WEBXDC_SUFFIX) { bail!("{} is not a valid webxdc file", filename); @@ -232,6 +236,16 @@ impl Context { warn!(self, "{} misses index.html", filename); false } else { + if let Ok(bytes) = get_blob(&archive, "manifest.toml").await { + if let Ok(manifest) = parse_webxdc_manifest(&bytes) { + if let Some(integration) = manifest.integration { + if integration == "maps" { + msg.param.set_int(Param::WebxdcIntegration, 1); + } + } + } + } + true } } diff --git a/src/webxdc/integration.rs b/src/webxdc/integration.rs index 500cd36bf..f7f99da4f 100644 --- a/src/webxdc/integration.rs +++ b/src/webxdc/integration.rs @@ -15,7 +15,7 @@ impl Context { let mut msg = Message::new(Viewtype::Webxdc); msg.set_file(file, None); msg.hidden = true; - msg.param.set_int(Param::WebxdcIntegration, 1); + msg.param.set_int(Param::WebxdcIntegration, 1); // can be removed when all UI upgraded to maps.xdc having integration=maps in the manifest msg.param.set_int(Param::GuaranteeE2ee, 1); // needed to pass `internet_access` requirements send_msg(self, chat_id, &mut msg).await?; Ok(())