Skip to content

Commit 5b043e2

Browse files
committed
set WebrtcRoom for calls
1 parent 5222e69 commit 5b043e2

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.
@@ -6731,7 +6733,8 @@ void dc_event_unref(dc_event_t* event);
67316733
* Otherwise, ringing should end on #DC_EVENT_CALL_ENDED
67326734
* or #DC_EVENT_INCOMING_CALL_ACCEPTED
67336735
*
6734-
* @param data1 (int) msg_id ID of the info-message referring to the call
6736+
* @param data1 (int) msg_id ID of the info-message referring to the call.
6737+
* The call URL is avauilable at dc_msg_get_videochat_url().
67356738
*/
67366739
#define DC_EVENT_INCOMING_CALL 2550
67376740

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
@@ -1077,10 +1077,8 @@ impl Message {
10771077

10781078
/// Returns videochat URL if the message is a videochat invitation.
10791079
pub fn get_videochat_url(&self) -> Option<String> {
1080-
if self.viewtype == Viewtype::VideochatInvitation {
1081-
if let Some(instance) = self.param.get(Param::WebrtcRoom) {
1082-
return Some(Message::parse_webrtc_instance(instance).1);
1083-
}
1080+
if let Some(instance) = self.param.get(Param::WebrtcRoom) {
1081+
return Some(Message::parse_webrtc_instance(instance).1);
10841082
}
10851083
None
10861084
}

src/mimefactory.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,9 @@ impl MimeFactory {
15521552
"Chat-Content",
15531553
mail_builder::headers::raw::Raw::new("videochat-invitation").into(),
15541554
));
1555+
}
1556+
1557+
if msg.param.exists(Param::WebrtcRoom) {
15551558
headers.push((
15561559
"Chat-Webrtc-Room",
15571560
mail_builder::headers::raw::Raw::new(

src/mimeparser.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -695,16 +695,18 @@ impl MimeMessage {
695695
}
696696

697697
fn parse_videochat_headers(&mut self) {
698-
if let Some(value) = self.get_header(HeaderDef::ChatContent) {
699-
if value == "videochat-invitation" {
700-
let instance = self
701-
.get_header(HeaderDef::ChatWebrtcRoom)
702-
.map(|s| s.to_string());
703-
if let Some(part) = self.parts.first_mut() {
698+
let is_videochat_invite =
699+
self.get_header(HeaderDef::ChatContent).unwrap_or_default() == "videochat-invitation";
700+
let instance = self
701+
.get_header(HeaderDef::ChatWebrtcRoom)
702+
.map(|s| s.to_string());
703+
if let Some(part) = self.parts.first_mut() {
704+
//
705+
if let Some(instance) = instance {
706+
if is_videochat_invite {
704707
part.typ = Viewtype::VideochatInvitation;
705-
part.param
706-
.set(Param::WebrtcRoom, instance.unwrap_or_default());
707708
}
709+
part.param.set(Param::WebrtcRoom, instance);
708710
}
709711
}
710712
}

0 commit comments

Comments
 (0)