detect maps-integration based on manifest entry

This commit is contained in:
B. Petersen
2024-06-06 01:07:38 +02:00
parent 25b8a482bc
commit 01bb8f997b
3 changed files with 19 additions and 5 deletions

View File

@@ -2636,7 +2636,7 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> {
{ {
if better_type != Viewtype::Webxdc if better_type != Viewtype::Webxdc
|| context || context
.ensure_sendable_webxdc_file(&blob.to_abs_path()) .prepare_webxdc_file(&blob.to_abs_path(), msg)
.await .await
.is_ok() .is_ok()
{ {
@@ -2645,7 +2645,7 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> {
} }
} else if msg.viewtype == Viewtype::Webxdc { } else if msg.viewtype == Viewtype::Webxdc {
context context
.ensure_sendable_webxdc_file(&blob.to_abs_path()) .prepare_webxdc_file(&blob.to_abs_path(), msg)
.await?; .await?;
} }
@@ -2913,7 +2913,7 @@ pub(crate) async fn create_send_msg_jobs(context: &Context, msg: &mut Message) -
recipients.push(from); 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() { if msg.param.get_int(Param::WebxdcIntegration).is_some() {
recipients.clear(); recipients.clear();
} }

View File

@@ -66,6 +66,9 @@ pub struct WebxdcManifest {
/// Optional URL of webxdc source code. /// Optional URL of webxdc source code.
pub source_code_url: Option<String>, pub source_code_url: Option<String>,
/// If the webxdc is an integration.
pub integration: Option<String>,
/// If the webxdc requests network access. /// If the webxdc requests network access.
pub request_internet_access: Option<bool>, pub request_internet_access: Option<bool>,
} }
@@ -220,7 +223,8 @@ impl Context {
} }
/// Ensure that a file is an acceptable webxdc for sending. /// 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(); let filename = path.to_str().unwrap_or_default();
if !filename.ends_with(WEBXDC_SUFFIX) { if !filename.ends_with(WEBXDC_SUFFIX) {
bail!("{} is not a valid webxdc file", filename); bail!("{} is not a valid webxdc file", filename);
@@ -232,6 +236,16 @@ impl Context {
warn!(self, "{} misses index.html", filename); warn!(self, "{} misses index.html", filename);
false false
} else { } 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 true
} }
} }

View File

@@ -15,7 +15,7 @@ impl Context {
let mut msg = Message::new(Viewtype::Webxdc); let mut msg = Message::new(Viewtype::Webxdc);
msg.set_file(file, None); msg.set_file(file, None);
msg.hidden = true; 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 msg.param.set_int(Param::GuaranteeE2ee, 1); // needed to pass `internet_access` requirements
send_msg(self, chat_id, &mut msg).await?; send_msg(self, chat_id, &mut msg).await?;
Ok(()) Ok(())