mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
feat: webxdc sending contexts
This commit is contained in:
@@ -4234,6 +4234,8 @@ char* dc_msg_get_webxdc_blob (const dc_msg_t* msg, const char*
|
|||||||
* true if the Webxdc should get internet access;
|
* true if the Webxdc should get internet access;
|
||||||
* this is the case i.e. for experimental maps integration.
|
* this is the case i.e. for experimental maps integration.
|
||||||
* - self_addr: address to be used for `window.webxdc.selfAddr` in JS land.
|
* - self_addr: address to be used for `window.webxdc.selfAddr` in JS land.
|
||||||
|
* - is_app_sender: Define if the local user is the one who initially shared the webxdc application in the chat.
|
||||||
|
* - is_broadcast: Define if the app runs in a broadcasting context.
|
||||||
* - send_update_interval: Milliseconds to wait before calling `sendUpdate()` again since the last call.
|
* - send_update_interval: Milliseconds to wait before calling `sendUpdate()` again since the last call.
|
||||||
* Should be exposed to `webxdc.sendUpdateInterval` in JS land.
|
* Should be exposed to `webxdc.sendUpdateInterval` in JS land.
|
||||||
* - send_update_max_size: Maximum number of bytes accepted for a serialized update object.
|
* - send_update_max_size: Maximum number of bytes accepted for a serialized update object.
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ pub struct WebxdcMessageInfo {
|
|||||||
internet_access: bool,
|
internet_access: bool,
|
||||||
/// Address to be used for `window.webxdc.selfAddr` in JS land.
|
/// Address to be used for `window.webxdc.selfAddr` in JS land.
|
||||||
self_addr: String,
|
self_addr: String,
|
||||||
|
/// Define if the local user is the one who initially shared the webxdc application in the chat.
|
||||||
|
is_app_sender: bool,
|
||||||
|
/// Define if the app runs in a broadcasting context.
|
||||||
|
is_broadcast: bool,
|
||||||
/// Milliseconds to wait before calling `sendUpdate()` again since the last call.
|
/// Milliseconds to wait before calling `sendUpdate()` again since the last call.
|
||||||
/// Should be exposed to `window.sendUpdateInterval` in JS land.
|
/// Should be exposed to `window.sendUpdateInterval` in JS land.
|
||||||
send_update_interval: usize,
|
send_update_interval: usize,
|
||||||
@@ -60,6 +64,8 @@ impl WebxdcMessageInfo {
|
|||||||
request_integration: _,
|
request_integration: _,
|
||||||
internet_access,
|
internet_access,
|
||||||
self_addr,
|
self_addr,
|
||||||
|
is_app_sender,
|
||||||
|
is_broadcast,
|
||||||
send_update_interval,
|
send_update_interval,
|
||||||
send_update_max_size,
|
send_update_max_size,
|
||||||
} = message.get_webxdc_info(context).await?;
|
} = message.get_webxdc_info(context).await?;
|
||||||
@@ -72,6 +78,8 @@ impl WebxdcMessageInfo {
|
|||||||
source_code_url: maybe_empty_string_to_option(source_code_url),
|
source_code_url: maybe_empty_string_to_option(source_code_url),
|
||||||
internet_access,
|
internet_access,
|
||||||
self_addr,
|
self_addr,
|
||||||
|
is_app_sender,
|
||||||
|
is_broadcast,
|
||||||
send_update_interval,
|
send_update_interval,
|
||||||
send_update_max_size,
|
send_update_max_size,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -111,6 +111,12 @@ pub struct WebxdcInfo {
|
|||||||
/// Address to be used for `window.webxdc.selfAddr` in JS land.
|
/// Address to be used for `window.webxdc.selfAddr` in JS land.
|
||||||
pub self_addr: String,
|
pub self_addr: String,
|
||||||
|
|
||||||
|
/// Define if the local user is the one who initially shared the webxdc application in the chat.
|
||||||
|
pub is_app_sender: bool,
|
||||||
|
|
||||||
|
/// Define if the app runs in a broadcasting context.
|
||||||
|
pub is_broadcast: bool,
|
||||||
|
|
||||||
/// Milliseconds to wait before calling `sendUpdate()` again since the last call.
|
/// Milliseconds to wait before calling `sendUpdate()` again since the last call.
|
||||||
/// Should be exposed to `window.sendUpdateInterval` in JS land.
|
/// Should be exposed to `window.sendUpdateInterval` in JS land.
|
||||||
pub send_update_interval: usize,
|
pub send_update_interval: usize,
|
||||||
@@ -923,6 +929,11 @@ impl Message {
|
|||||||
let internet_access = is_integrated;
|
let internet_access = is_integrated;
|
||||||
|
|
||||||
let self_addr = self.get_webxdc_self_addr(context).await?;
|
let self_addr = self.get_webxdc_self_addr(context).await?;
|
||||||
|
let is_app_sender = self.from_id == ContactId::SELF;
|
||||||
|
let chat = Chat::load_from_db(context, self.chat_id)
|
||||||
|
.await
|
||||||
|
.with_context(|| "Failed to load chat from the database")?;
|
||||||
|
let is_broadcast = chat.typ == Chattype::InBroadcast || chat.typ == Chattype::OutBroadcast;
|
||||||
|
|
||||||
Ok(WebxdcInfo {
|
Ok(WebxdcInfo {
|
||||||
name: if let Some(name) = manifest.name {
|
name: if let Some(name) = manifest.name {
|
||||||
@@ -961,6 +972,8 @@ impl Message {
|
|||||||
request_integration,
|
request_integration,
|
||||||
internet_access,
|
internet_access,
|
||||||
self_addr,
|
self_addr,
|
||||||
|
is_app_sender,
|
||||||
|
is_broadcast,
|
||||||
send_update_interval: context.ratelimit.read().await.update_interval(),
|
send_update_interval: context.ratelimit.read().await.update_interval(),
|
||||||
send_update_max_size: RECOMMENDED_FILE_SIZE as usize,
|
send_update_max_size: RECOMMENDED_FILE_SIZE as usize,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use crate::chatlist::Chatlist;
|
|||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::ephemeral;
|
use crate::ephemeral;
|
||||||
use crate::receive_imf::receive_imf;
|
use crate::receive_imf::receive_imf;
|
||||||
|
use crate::securejoin::get_securejoin_qr;
|
||||||
use crate::test_utils::{E2EE_INFO_MSGS, TestContext, TestContextManager};
|
use crate::test_utils::{E2EE_INFO_MSGS, TestContext, TestContextManager};
|
||||||
use crate::tools::{self, SystemTime};
|
use crate::tools::{self, SystemTime};
|
||||||
use crate::{message, sql};
|
use crate::{message, sql};
|
||||||
@@ -2195,3 +2196,42 @@ async fn test_self_addr_consistency() -> Result<()> {
|
|||||||
assert_eq!(db_msg.get_webxdc_self_addr(alice).await?, self_addr);
|
assert_eq!(db_msg.get_webxdc_self_addr(alice).await?, self_addr);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_webxdc_info_app_sender() -> Result<()> {
|
||||||
|
let mut tcm = TestContextManager::new();
|
||||||
|
let alice = &tcm.alice().await;
|
||||||
|
let bob = &tcm.bob().await;
|
||||||
|
|
||||||
|
// Alice sends webxdc in a group chat
|
||||||
|
let alice_chat_id = alice.create_group_with_members("Group", &[bob]).await;
|
||||||
|
let alice_instance = send_webxdc_instance(alice, alice_chat_id).await?;
|
||||||
|
let sent1 = alice.pop_sent_msg().await;
|
||||||
|
let alice_info = alice_instance.get_webxdc_info(alice).await?;
|
||||||
|
assert!(alice_info.is_app_sender);
|
||||||
|
assert!(!alice_info.is_broadcast);
|
||||||
|
|
||||||
|
// Bob receives group webxdc
|
||||||
|
let bob_instance = bob.recv_msg(&sent1).await;
|
||||||
|
let bob_info = bob_instance.get_webxdc_info(bob).await?;
|
||||||
|
assert!(!bob_info.is_app_sender);
|
||||||
|
assert!(!bob_info.is_broadcast);
|
||||||
|
|
||||||
|
// Alice sends webxdc to broadcast channel
|
||||||
|
let alice_chat_id = create_broadcast(alice, "Broadcast".to_string()).await?;
|
||||||
|
let qr = get_securejoin_qr(alice, Some(alice_chat_id)).await.unwrap();
|
||||||
|
tcm.exec_securejoin_qr(bob, alice, &qr).await;
|
||||||
|
let alice_instance = send_webxdc_instance(alice, alice_chat_id).await?;
|
||||||
|
let sent2 = alice.pop_sent_msg().await;
|
||||||
|
let alice_info = alice_instance.get_webxdc_info(alice).await?;
|
||||||
|
assert!(alice_info.is_app_sender);
|
||||||
|
assert!(alice_info.is_broadcast);
|
||||||
|
|
||||||
|
// Bob receives broadcast webxdc
|
||||||
|
let bob_instance = bob.recv_msg(&sent2).await;
|
||||||
|
let bob_info = bob_instance.get_webxdc_info(bob).await?;
|
||||||
|
assert!(!bob_info.is_app_sender);
|
||||||
|
assert!(bob_info.is_broadcast);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user