Skip to content

Commit 40c9678

Browse files
committed
set WebrtcRoom for calls
1 parent 1bcb782 commit 40c9678

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

deltachat-ffi/deltachat.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,8 @@ uint32_t dc_init_webxdc_integration (dc_context_t* context, uint32_t c
12441244
* - callee ends the call using dc_end_call(), caller receives #DC_EVENT_CALL_ENDED
12451245
* - caller ends the call using dc_end_call(), callee receives #DC_EVENT_CALL_ENDED
12461246
*
1247+
* The call URL is avauilable at dc_msg_get_videochat_url().
1248+
*
12471249
* Note, that the events are for updating the call screen,
12481250
* possible status messages are added and updated as usual, including the known events.
12491251
* In the UI, the sorted chatlist is used as an overview about calls as well as messages.
@@ -6670,7 +6672,8 @@ void dc_event_unref(dc_event_t* event);
66706672
* Otherwise, ringing should end on #DC_EVENT_CALL_ENDED
66716673
* or #DC_EVENT_INCOMING_CALL_ACCEPTED
66726674
*
6673-
* @param data1 (int) msg_id ID of the info-message referring to the call
6675+
* @param data1 (int) msg_id ID of the info-message referring to the call.
6676+
* The call URL is avauilable at dc_msg_get_videochat_url().
66746677
*/
66756678
#define DC_EVENT_INCOMING_CALL 2550
66766679

src/calls.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
//! So, no database changes are needed at this stage.
66
//! When it comes to relay calls over iroh, we may need a dedicated table, and this may change.
77
use crate::chat::{send_msg, Chat, ChatId};
8+
use crate::config::Config;
89
use crate::constants::Chattype;
910
use crate::context::Context;
1011
use crate::events::EventType;
1112
use crate::message::{self, rfc724_mid_exists, Message, MsgId, Viewtype};
1213
use crate::mimeparser::{MimeMessage, SystemMessage};
1314
use crate::param::Param;
1415
use crate::sync::SyncData;
15-
use crate::tools::time;
16-
use anyhow::{ensure, Result};
16+
use crate::tools::{create_id, time};
17+
use anyhow::{bail, ensure, Result};
1718
use std::time::Duration;
1819
use tokio::task;
1920
use tokio::time::sleep;
@@ -71,12 +72,24 @@ impl Context {
7172
let chat = Chat::load_from_db(self, chat_id).await?;
7273
ensure!(chat.typ == Chattype::Single && !chat.is_self_talk());
7374

75+
let instance = if let Some(instance) = self.get_config(Config::WebrtcInstance).await? {
76+
if !instance.is_empty() {
77+
instance
78+
} else {
79+
bail!("webrtc_instance is empty");
80+
}
81+
} else {
82+
bail!("webrtc_instance not set");
83+
};
84+
let instance = Message::create_webrtc_instance(&instance, &create_id());
85+
7486
let mut call = Message {
7587
viewtype: Viewtype::Text,
7688
text: "Calling...".into(),
7789
..Default::default()
7890
};
7991
call.param.set_cmd(SystemMessage::OutgoingCall);
92+
call.param.set(Param::WebrtcRoom, &instance);
8093
call.id = send_msg(self, chat_id, &mut call).await?;
8194

8295
let wait = RINGING_SECONDS;
@@ -284,6 +297,8 @@ mod tests {
284297
let bob2 = tcm.bob().await;
285298
for t in [&alice, &alice2, &bob, &bob2] {
286299
t.set_config_bool(Config::SyncMsgs, true).await?;
300+
t.set_config(Config::WebrtcInstance, Some("https://foo.bar"))
301+
.await?;
287302
}
288303

289304
// Alice creates a chat with Bob and places an outgoing call there.
@@ -295,12 +310,17 @@ mod tests {
295310
assert_eq!(sent1.sender_msg_id, test_msg_id);
296311
assert!(alice_call.is_info());
297312
assert_eq!(alice_call.get_info_type(), SystemMessage::OutgoingCall);
313+
let alice_url = alice_call.get_videochat_url().unwrap();
314+
assert!(alice_url.starts_with("https://foo.bar/"));
298315
let info = alice.load_call_by_root_id(alice_call.id).await?;
299316
assert!(!info.accepted);
300317

301318
let alice2_call = alice2.recv_msg(&sent1).await;
302319
assert!(alice2_call.is_info());
303320
assert_eq!(alice2_call.get_info_type(), SystemMessage::OutgoingCall);
321+
let alice2_url = alice2_call.get_videochat_url().unwrap();
322+
assert!(alice2_url.starts_with("https://foo.bar/"));
323+
assert_eq!(alice_url, alice2_url);
304324
let info = alice2.load_call_by_root_id(alice2_call.id).await?;
305325
assert!(!info.accepted);
306326

@@ -312,6 +332,9 @@ mod tests {
312332
.await;
313333
assert!(bob_call.is_info());
314334
assert_eq!(bob_call.get_info_type(), SystemMessage::IncomingCall);
335+
let bob_url = bob_call.get_videochat_url().unwrap();
336+
assert!(bob_url.starts_with("https://foo.bar/"));
337+
assert_eq!(alice_url, bob_url);
315338

316339
let bob2_call = bob2.recv_msg(&sent1).await;
317340
assert!(bob2_call.is_info());

src/message.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,10 +1085,8 @@ impl Message {
10851085

10861086
/// Returns videochat URL if the message is a videochat invitation.
10871087
pub fn get_videochat_url(&self) -> Option<String> {
1088-
if self.viewtype == Viewtype::VideochatInvitation {
1089-
if let Some(instance) = self.param.get(Param::WebrtcRoom) {
1090-
return Some(Message::parse_webrtc_instance(instance).1);
1091-
}
1088+
if let Some(instance) = self.param.get(Param::WebrtcRoom) {
1089+
return Some(Message::parse_webrtc_instance(instance).1);
10921090
}
10931091
None
10941092
}

src/mimefactory.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,9 @@ impl MimeFactory {
14441444
"Chat-Content",
14451445
mail_builder::headers::raw::Raw::new("videochat-invitation").into(),
14461446
));
1447+
}
1448+
1449+
if msg.param.exists(Param::WebrtcRoom) {
14471450
headers.push((
14481451
"Chat-Webrtc-Room",
14491452
mail_builder::headers::raw::Raw::new(

src/mimeparser.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -712,16 +712,18 @@ impl MimeMessage {
712712
}
713713

714714
fn parse_videochat_headers(&mut self) {
715-
if let Some(value) = self.get_header(HeaderDef::ChatContent) {
716-
if value == "videochat-invitation" {
717-
let instance = self
718-
.get_header(HeaderDef::ChatWebrtcRoom)
719-
.map(|s| s.to_string());
720-
if let Some(part) = self.parts.first_mut() {
715+
let is_videochat_invite =
716+
self.get_header(HeaderDef::ChatContent).unwrap_or_default() == "videochat-invitation";
717+
let instance = self
718+
.get_header(HeaderDef::ChatWebrtcRoom)
719+
.map(|s| s.to_string());
720+
if let Some(part) = self.parts.first_mut() {
721+
//
722+
if let Some(instance) = instance {
723+
if is_videochat_invite {
721724
part.typ = Viewtype::VideochatInvitation;
722-
part.param
723-
.set(Param::WebrtcRoom, instance.unwrap_or_default());
724725
}
726+
part.param.set(Param::WebrtcRoom, instance);
725727
}
726728
}
727729
}

0 commit comments

Comments
 (0)