Skip to content

Commit fa76c3a

Browse files
committed
feat: webxdc sending contexts
1 parent 8292495 commit fa76c3a

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

deltachat-ffi/deltachat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4234,6 +4234,9 @@ char* dc_msg_get_webxdc_blob (const dc_msg_t* msg, const char*
42344234
* true if the Webxdc should get internet access;
42354235
* this is the case i.e. for experimental maps integration.
42364236
* - self_addr: address to be used for `window.webxdc.selfAddr` in JS land.
4237+
* - is_app_sender: Define if the local user is the one who initially shared the webxdc application in the chat.
4238+
* - is_broadcast: Define if the app runs in a broadcasting context.
4239+
* will only be seen by the app sender.
42374240
* - send_update_interval: Milliseconds to wait before calling `sendUpdate()` again since the last call.
42384241
* Should be exposed to `webxdc.sendUpdateInterval` in JS land.
42394242
* - send_update_max_size: Maximum number of bytes accepted for a serialized update object.

deltachat-jsonrpc/src/api/types/webxdc.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ pub struct WebxdcMessageInfo {
3737
internet_access: bool,
3838
/// Address to be used for `window.webxdc.selfAddr` in JS land.
3939
self_addr: String,
40+
/// Define if the local user is the one who initially shared the webxdc application in the chat.
41+
is_app_sender: String,
42+
/// Define if the app runs in a broadcasting context.
43+
is_broadcast: bool,
4044
/// Milliseconds to wait before calling `sendUpdate()` again since the last call.
4145
/// Should be exposed to `window.sendUpdateInterval` in JS land.
4246
send_update_interval: usize,
@@ -60,6 +64,8 @@ impl WebxdcMessageInfo {
6064
request_integration: _,
6165
internet_access,
6266
self_addr,
67+
is_app_sender,
68+
is_broadcast,
6369
send_update_interval,
6470
send_update_max_size,
6571
} = message.get_webxdc_info(context).await?;
@@ -72,6 +78,8 @@ impl WebxdcMessageInfo {
7278
source_code_url: maybe_empty_string_to_option(source_code_url),
7379
internet_access,
7480
self_addr,
81+
is_app_sender,
82+
is_broadcast,
7583
send_update_interval,
7684
send_update_max_size,
7785
})

src/webxdc.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ pub struct WebxdcInfo {
111111
/// Address to be used for `window.webxdc.selfAddr` in JS land.
112112
pub self_addr: String,
113113

114+
/// Define if the local user is the one who initially shared the webxdc application in the chat.
115+
pub is_app_sender: bool,
116+
117+
/// Define if the app runs in a broadcasting context.
118+
pub is_broadcast: bool,
119+
114120
/// Milliseconds to wait before calling `sendUpdate()` again since the last call.
115121
/// Should be exposed to `window.sendUpdateInterval` in JS land.
116122
pub send_update_interval: usize,
@@ -923,6 +929,11 @@ impl Message {
923929
let internet_access = is_integrated;
924930

925931
let self_addr = self.get_webxdc_self_addr(context).await?;
932+
let is_app_sender = self.from_id == ContactId::SELF;
933+
let chat = Chat::load_from_db(context, self.chat_id)
934+
.await
935+
.with_context(|| "Failed to load chat from the database")?;
936+
let is_broadcast = chat.typ == Chattype::InBroadcast || chat.typ == Chattype::OutBroadcast;
926937

927938
Ok(WebxdcInfo {
928939
name: if let Some(name) = manifest.name {
@@ -961,6 +972,8 @@ impl Message {
961972
request_integration,
962973
internet_access,
963974
self_addr,
975+
is_app_sender,
976+
is_broadcast,
964977
send_update_interval: context.ratelimit.read().await.update_interval(),
965978
send_update_max_size: RECOMMENDED_FILE_SIZE as usize,
966979
})

src/webxdc/webxdc_tests.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::chatlist::Chatlist;
1212
use crate::config::Config;
1313
use crate::ephemeral;
1414
use crate::receive_imf::receive_imf;
15+
use crate::securejoin::get_securejoin_qr;
1516
use crate::test_utils::{E2EE_INFO_MSGS, TestContext, TestContextManager};
1617
use crate::tools::{self, SystemTime};
1718
use crate::{message, sql};
@@ -2195,3 +2196,42 @@ async fn test_self_addr_consistency() -> Result<()> {
21952196
assert_eq!(db_msg.get_webxdc_self_addr(alice).await?, self_addr);
21962197
Ok(())
21972198
}
2199+
2200+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
2201+
async fn test_webxdc_info_app_sender() -> Result<()> {
2202+
let mut tcm = TestContextManager::new();
2203+
let alice = &tcm.alice().await;
2204+
let bob = &tcm.bob().await;
2205+
2206+
// Alice sends webxdc in a group chat
2207+
let alice_chat_id = alice.create_group_with_members("Group", &[bob]).await;
2208+
let alice_instance = send_webxdc_instance(alice, alice_chat_id).await?;
2209+
let sent1 = alice.pop_sent_msg().await;
2210+
let alice_info = alice_instance.get_webxdc_info(alice).await?;
2211+
assert!(alice_info.is_app_sender);
2212+
assert!(!alice_info.is_broadcast);
2213+
2214+
// Bob receives group webxdc
2215+
let bob_instance = bob.recv_msg(&sent1).await;
2216+
let bob_info = bob_instance.get_webxdc_info(bob).await?;
2217+
assert!(!bob_info.is_app_sender);
2218+
assert!(!bob_info.is_broadcast);
2219+
2220+
// Alice sends webxdc to broadcast channel
2221+
let alice_chat_id = create_broadcast(alice, "Broadcast".to_string()).await?;
2222+
let qr = get_securejoin_qr(alice, Some(alice_chat_id)).await.unwrap();
2223+
tcm.exec_securejoin_qr(bob, alice, &qr).await;
2224+
let alice_instance = send_webxdc_instance(alice, alice_chat_id).await?;
2225+
let sent2 = alice.pop_sent_msg().await;
2226+
let alice_info = alice_instance.get_webxdc_info(alice).await?;
2227+
assert!(alice_info.is_app_sender);
2228+
assert!(alice_info.is_broadcast);
2229+
2230+
// Bob receives broadcast webxdc
2231+
let bob_instance = bob.recv_msg(&sent2).await;
2232+
let bob_info = bob_instance.get_webxdc_info(bob).await?;
2233+
assert!(!bob_info.is_app_sender);
2234+
assert!(bob_info.is_broadcast);
2235+
2236+
Ok(())
2237+
}

0 commit comments

Comments
 (0)