@@ -36,7 +36,7 @@ use tokio::{fs::File, io::BufReader};
3636
3737use crate :: chat:: { self , Chat } ;
3838use crate :: constants:: Chattype ;
39- use crate :: contact:: ContactId ;
39+ use crate :: contact:: { Contact , ContactId } ;
4040use crate :: context:: Context ;
4141use crate :: events:: EventType ;
4242use crate :: key:: self_fingerprint;
@@ -111,6 +111,15 @@ pub struct WebxdcInfo {
111111 /// Address to be used for `window.webxdc.selfAddr` in JS land.
112112 pub self_addr : String ,
113113
114+ /// Address of the peer who initially shared the webxdc in the chat.
115+ /// Can be compared to `self_addr` to determine
116+ /// whether the app runs for the sender or a receiver.
117+ pub app_sender_addr : String ,
118+
119+ /// `true` if updates sent by the local user
120+ /// will only be seen by the app sender.
121+ pub can_only_send_updates_to_app_sender : bool ,
122+
114123 /// Milliseconds to wait before calling `sendUpdate()` again since the last call.
115124 /// Should be exposed to `window.sendUpdateInterval` in JS land.
116125 pub send_update_interval : usize ,
@@ -923,6 +932,12 @@ impl Message {
923932 let internet_access = is_integrated;
924933
925934 let self_addr = self . get_webxdc_self_addr ( context) . await ?;
935+ let app_sender_addr = self . get_webxdc_app_sender_addr ( context) . await ?;
936+
937+ let chat = Chat :: load_from_db ( context, self . chat_id )
938+ . await
939+ . with_context ( || "Failed to load chat from the database" ) ?;
940+ let can_only_send_updates_to_app_sender = chat. typ == Chattype :: InBroadcast ;
926941
927942 Ok ( WebxdcInfo {
928943 name : if let Some ( name) = manifest. name {
@@ -961,6 +976,8 @@ impl Message {
961976 request_integration,
962977 internet_access,
963978 self_addr,
979+ app_sender_addr,
980+ can_only_send_updates_to_app_sender,
964981 send_update_interval : context. ratelimit . read ( ) . await . update_interval ( ) ,
965982 send_update_max_size : RECOMMENDED_FILE_SIZE as usize ,
966983 } )
@@ -973,6 +990,29 @@ impl Message {
973990 Ok ( format ! ( "{hash:x}" ) )
974991 }
975992
993+ /// Computes the webxdc address of the message sender.
994+ async fn get_webxdc_app_sender_addr ( & self , context : & Context ) -> Result < String > {
995+ // UNDEFINED may be preset during drafts or tests, will be SELF on sending
996+ let fingerprint = if self . from_id == ContactId :: SELF || self . from_id == ContactId :: UNDEFINED
997+ {
998+ self_fingerprint ( context) . await ?. to_string ( )
999+ } else {
1000+ let contact = Contact :: get_by_id ( context, self . from_id ) . await ?;
1001+ contact
1002+ . fingerprint ( )
1003+ . with_context ( || {
1004+ format ! (
1005+ "No fingerprint for contact {} (webxdc sender)" ,
1006+ self . from_id
1007+ )
1008+ } ) ?
1009+ . hex ( )
1010+ } ;
1011+ let data = format ! ( "{}-{}" , fingerprint, self . rfc724_mid) ;
1012+ let hash = Sha256 :: digest ( data. as_bytes ( ) ) ;
1013+ Ok ( format ! ( "{hash:x}" ) )
1014+ }
1015+
9761016 /// Get link attached to an info message.
9771017 ///
9781018 /// The info message needs to be of type SystemMessage::WebxdcInfoMessage.
0 commit comments