Skip to content

Commit

Permalink
show integration state in summary
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Jul 10, 2024
1 parent d4ee89d commit a603a9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/webxdc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -859,7 +867,7 @@ impl Message {
} else {
"".to_string()
},
integration: manifest.integration.unwrap_or_default(),
integration: request_integration,
internet_access,
})
}
Expand Down
20 changes: 18 additions & 2 deletions src/webxdc/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
if let Some(integration_id) = context
.get_config_parsed::<u32>(Config::WebxdcIntegration)
.await?
{
Ok(integration_id == self.id.to_u32())
} else {
Ok(false)
}
}
}

#[cfg(test)]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a603a9a

Please sign in to comment.