mirror of
https://github.com/chatmail/core.git
synced 2026-04-01 21:12:13 +03:00
Compare commits
3 Commits
822a99ea9c
...
r10s/repla
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41f0a0ecb4 | ||
|
|
b4f62fb199 | ||
|
|
01bb8f997b |
@@ -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();
|
||||
}
|
||||
|
||||
@@ -66,6 +66,9 @@ pub struct WebxdcManifest {
|
||||
/// Optional URL of webxdc source code.
|
||||
pub source_code_url: Option<String>,
|
||||
|
||||
/// If the webxdc is an integration.
|
||||
pub integration: Option<String>,
|
||||
|
||||
/// If the webxdc requests network access.
|
||||
pub request_internet_access: Option<bool>,
|
||||
}
|
||||
@@ -220,29 +223,26 @@ 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);
|
||||
}
|
||||
|
||||
let valid = match async_zip::read::fs::ZipFileReader::new(path).await {
|
||||
Ok(archive) => {
|
||||
if find_zip_entry(archive.file(), "index.html").is_none() {
|
||||
warn!(self, "{} misses index.html", filename);
|
||||
false
|
||||
} else {
|
||||
true
|
||||
let archive = async_zip::read::fs::ZipFileReader::new(path).await?;
|
||||
if find_zip_entry(archive.file(), "index.html").is_none() {
|
||||
bail!("{} misses index.html", filename);
|
||||
}
|
||||
|
||||
if let Ok(bytes) = get_blob(&archive, "manifest.toml").await {
|
||||
let manifest = parse_webxdc_manifest(&bytes)?;
|
||||
if let Some(integration) = manifest.integration {
|
||||
if integration == "maps" && msg.chat_id.is_self_talk(&self).await? {
|
||||
info!(self, "{} set as maps integration", filename);
|
||||
msg.param.set_int(Param::WebxdcIntegration, 1);
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
warn!(self, "{} cannot be opened as zip-file", filename);
|
||||
false
|
||||
}
|
||||
};
|
||||
|
||||
if !valid {
|
||||
bail!("{} is not a valid webxdc file", filename);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -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(())
|
||||
@@ -105,7 +105,10 @@ impl Message {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::chat;
|
||||
use crate::config::Config;
|
||||
use crate::context::Context;
|
||||
use crate::message::{Message, Viewtype};
|
||||
use crate::test_utils::TestContext;
|
||||
use anyhow::Result;
|
||||
use std::time::Duration;
|
||||
@@ -126,4 +129,55 @@ mod tests {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_overwrite_default_integration() -> Result<()> {
|
||||
let t = TestContext::new_alice().await;
|
||||
let self_chat = &t.get_self_chat().await;
|
||||
|
||||
async fn assert_integration(t: &Context, name: &str) -> Result<()> {
|
||||
let integration_id = t.init_webxdc_integration(None).await?.unwrap();
|
||||
let integration = Message::load_from_db(&t, integration_id).await?;
|
||||
let integration_info = integration.get_webxdc_info(&t).await?;
|
||||
assert_eq!(integration_info.name, name);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// set default integration
|
||||
let bytes = include_bytes!("../../test-data/webxdc/with-manifest-and-png-icon.xdc");
|
||||
let file = t.get_blobdir().join("maps.xdc");
|
||||
tokio::fs::write(&file, bytes).await.unwrap();
|
||||
t.set_webxdc_integration(file.to_str().unwrap()).await?;
|
||||
assert_integration(&t, "with some icon").await?;
|
||||
|
||||
// send a maps.xdc with insufficient manifest
|
||||
let mut msg = Message::new(Viewtype::Webxdc);
|
||||
msg.set_file_from_bytes(
|
||||
&t,
|
||||
"mapstest.xdc",
|
||||
include_bytes!("../../test-data/webxdc/mapstest-integration-unset.xdc"),
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
chat::send_msg(&t, self_chat.id, &mut msg).await?;
|
||||
let sent = t.pop_sent_msg_opt(Duration::from_secs(1)).await;
|
||||
assert!(sent.is_some());
|
||||
assert_integration(&t, "with some icon").await?; // still the default integration
|
||||
|
||||
// send a maps.xdc with manifest including the line `integration = "maps"`
|
||||
let mut msg = Message::new(Viewtype::Webxdc);
|
||||
msg.set_file_from_bytes(
|
||||
&t,
|
||||
"mapstest.xdc",
|
||||
include_bytes!("../../test-data/webxdc/mapstest-integration-set.xdc"),
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
chat::send_msg(&t, self_chat.id, &mut msg).await?;
|
||||
//let sent = t.pop_sent_msg_opt(Duration::from_secs(1)).await;
|
||||
//assert!(sent.is_some());
|
||||
assert_integration(&t, "Maps Test 2").await?; // still the default integration
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ mod tests {
|
||||
async fn test_maps_integration() -> Result<()> {
|
||||
let t = TestContext::new_alice().await;
|
||||
|
||||
let bytes = include_bytes!("../../test-data/webxdc/mapstest.xdc");
|
||||
let bytes = include_bytes!("../../test-data/webxdc/mapstest-integration-set.xdc");
|
||||
let file = t.get_blobdir().join("maps.xdc");
|
||||
tokio::fs::write(&file, bytes).await.unwrap();
|
||||
t.set_webxdc_integration(file.to_str().unwrap()).await?;
|
||||
@@ -198,7 +198,7 @@ mod tests {
|
||||
|
||||
let integration = Message::load_from_db(&t, integration_id).await?;
|
||||
let info = integration.get_webxdc_info(&t).await?;
|
||||
assert_eq!(info.name, "Maps Test");
|
||||
assert_eq!(info.name, "Maps Test 2");
|
||||
assert_eq!(info.internet_access, true);
|
||||
|
||||
t.send_webxdc_status_update(
|
||||
|
||||
BIN
test-data/webxdc/mapstest-integration-set.xdc
Normal file
BIN
test-data/webxdc/mapstest-integration-set.xdc
Normal file
Binary file not shown.
Reference in New Issue
Block a user