add source_code_url to manifest and get_webxdc_info, add a test (#3314)

This commit is contained in:
bjoern
2022-05-13 21:00:36 +02:00
committed by GitHub
parent bd5b9573f6
commit 961612370d
3 changed files with 29 additions and 0 deletions

View File

@@ -5,6 +5,7 @@
### Changes
- send normal messages with higher priority than MDNs #3243
- make Scheduler stateless #3302
- support `source_code_url` from Webxdc manifests #3314
### API-Changes
- deprecate unused `marker1before` argument of `dc_get_chat_msgs`

View File

@@ -3731,6 +3731,10 @@ char* dc_msg_get_webxdc_blob (const dc_msg_t* msg, const char*
* - summary: short string describing the state of the app,
* sth. as "2 votes", "Highscore: 123",
* can be changed by the apps and defaults to an empty string.
* - source_code_url:
* URL where the source code of the Webxdc and other information can be found;
* defaults to an empty string.
* Implementations may offer an menu or a button to open this URL.
*
* @memberof dc_msg_t
* @param msg The webxdc instance.

View File

@@ -51,6 +51,7 @@ const WEBXDC_RECEIVING_LIMIT: u64 = 4194304;
struct WebxdcManifest {
name: Option<String>,
min_api: Option<u32>,
source_code_url: Option<String>,
}
/// Parsed information from WebxdcManifest and fallbacks.
@@ -59,6 +60,7 @@ pub struct WebxdcInfo {
pub name: String,
pub icon: String,
pub summary: String,
pub source_code_url: String,
}
/// Status Update ID.
@@ -538,12 +540,14 @@ impl Message {
WebxdcManifest {
name: None,
min_api: None,
source_code_url: None,
}
}
} else {
WebxdcManifest {
name: None,
min_api: None,
source_code_url: None,
}
};
@@ -573,6 +577,11 @@ impl Message {
.get(Param::WebxdcSummary)
.unwrap_or_default()
.to_string(),
source_code_url: if let Some(url) = manifest.source_code_url {
url
} else {
"".to_string()
},
})
}
}
@@ -1343,6 +1352,21 @@ sth_for_the = "future""#
Ok(())
}
#[async_std::test]
async fn test_parse_webxdc_manifest_source_code_url() -> Result<()> {
let result = parse_webxdc_manifest(r#"source_code_url = 3"#.as_bytes()).await;
assert!(result.is_err());
let manifest =
parse_webxdc_manifest(r#"source_code_url = "https://foo.bar""#.as_bytes()).await?;
assert_eq!(
manifest.source_code_url,
Some("https://foo.bar".to_string())
);
Ok(())
}
#[async_std::test]
async fn test_webxdc_min_api_too_large() -> Result<()> {
let t = TestContext::new_alice().await;