Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions deltachat-ffi/deltachat.h
Original file line number Diff line number Diff line change
Expand Up @@ -4621,8 +4621,6 @@ int dc_msg_is_info (const dc_msg_t* msg);
* and also offer a way to fix the encryption, eg. by a button offering a QR scan
* - DC_INFO_WEBXDC_INFO_MESSAGE (32) - Info-message created by webxdc app sending `update.info`
* - DC_INFO_CHAT_E2EE (50) - Info-message for "Chat is end-to-end-encrypted"
* - DC_INFO_OUTGOING_CALL (60) - Info-message refers to an outgoing call
* - DC_INFO_INCOMING_CALL (65) - Info-message refers to an incoming call
*
* For the messages that refer to a CONTACT,
* dc_msg_get_info_contact_id() returns the contact ID.
Expand Down Expand Up @@ -4679,8 +4677,6 @@ uint32_t dc_msg_get_info_contact_id (const dc_msg_t* msg);
#define DC_INFO_INVALID_UNENCRYPTED_MAIL 13
#define DC_INFO_WEBXDC_INFO_MESSAGE 32
#define DC_INFO_CHAT_E2EE 50
#define DC_INFO_OUTGOING_CALL 60
#define DC_INFO_INCOMING_CALL 65


/**
Expand Down Expand Up @@ -5717,6 +5713,12 @@ int64_t dc_lot_get_timestamp (const dc_lot_t* lot);
#define DC_MSG_VIDEOCHAT_INVITATION 70


/**
* Message indicating an incoming or outgoing call.
*/
#define DC_MSG_CALL 71


/**
* The message is a webxdc instance.
*
Expand Down
9 changes: 5 additions & 4 deletions deltachat-jsonrpc/src/api/types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ pub enum MessageViewtype {
/// Message is an invitation to a videochat.
VideochatInvitation,

/// Message is a call.
Call,

/// Message is an webxdc instance.
Webxdc,

Expand All @@ -346,6 +349,7 @@ impl From<Viewtype> for MessageViewtype {
Viewtype::Video => MessageViewtype::Video,
Viewtype::File => MessageViewtype::File,
Viewtype::VideochatInvitation => MessageViewtype::VideochatInvitation,
Viewtype::Call => MessageViewtype::Call,
Viewtype::Webxdc => MessageViewtype::Webxdc,
Viewtype::Vcard => MessageViewtype::Vcard,
}
Expand All @@ -365,6 +369,7 @@ impl From<MessageViewtype> for Viewtype {
MessageViewtype::Video => Viewtype::Video,
MessageViewtype::File => Viewtype::File,
MessageViewtype::VideochatInvitation => Viewtype::VideochatInvitation,
MessageViewtype::Call => Viewtype::Call,
MessageViewtype::Webxdc => Viewtype::Webxdc,
MessageViewtype::Vcard => Viewtype::Vcard,
}
Expand Down Expand Up @@ -438,8 +443,6 @@ pub enum SystemMessageType {
/// This message contains a users iroh node address.
IrohNodeAddr,

OutgoingCall,
IncomingCall,
CallAccepted,
CallEnded,
}
Expand Down Expand Up @@ -468,8 +471,6 @@ impl From<deltachat::mimeparser::SystemMessage> for SystemMessageType {
SystemMessage::IrohNodeAddr => SystemMessageType::IrohNodeAddr,
SystemMessage::SecurejoinWait => SystemMessageType::SecurejoinWait,
SystemMessage::SecurejoinWaitTimeout => SystemMessageType::SecurejoinWaitTimeout,
SystemMessage::OutgoingCall => SystemMessageType::OutgoingCall,
SystemMessage::IncomingCall => SystemMessageType::IncomingCall,
SystemMessage::CallAccepted => SystemMessageType::CallAccepted,
SystemMessage::CallEnded => SystemMessageType::CallEnded,
}
Expand Down
112 changes: 52 additions & 60 deletions src/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! This means, the "Call ID" is a "Message ID" currently - similar to webxdc.
use crate::chat::{Chat, ChatId, send_msg};
use crate::constants::Chattype;
use crate::contact::ContactId;
use crate::context::Context;
use crate::events::EventType;
use crate::headerdef::HeaderDef;
Expand Down Expand Up @@ -82,11 +83,10 @@ impl Context {
ensure!(chat.typ == Chattype::Single && !chat.is_self_talk());

let mut call = Message {
viewtype: Viewtype::Text,
viewtype: Viewtype::Call,
text: "Calling...".into(),
..Default::default()
};
call.param.set_cmd(SystemMessage::OutgoingCall);
call.param.set(Param::WebrtcRoom, &place_call_info);
call.id = send_msg(self, chat_id, &mut call).await?;

Expand Down Expand Up @@ -184,60 +184,61 @@ impl Context {
mime_message: &MimeMessage,
call_id: MsgId,
) -> Result<()> {
match mime_message.is_system_message {
SystemMessage::IncomingCall => {
let call = self.load_call_by_id(call_id).await?;
if call.is_incoming {
if call.is_stale_call() {
call.update_text(self, "Missed call").await?;
self.emit_incoming_msg(call.msg.chat_id, call_id);
if mime_message.is_call() {
let call = self.load_call_by_id(call_id).await?;
if call.is_incoming {
if call.is_stale_call() {
call.update_text(self, "Missed call").await?;
self.emit_incoming_msg(call.msg.chat_id, call_id);
} else {
self.emit_msgs_changed(call.msg.chat_id, call_id);
self.emit_event(EventType::IncomingCall {
msg_id: call.msg.id,
place_call_info: call.place_call_info.to_string(),
});
let wait = call.remaining_ring_seconds();
task::spawn(Context::emit_end_call_if_unaccepted(
self.clone(),
wait.try_into()?,
call.msg.id,
));
}
} else {
self.emit_msgs_changed(call.msg.chat_id, call_id);
}
} else {
match mime_message.is_system_message {
SystemMessage::CallAccepted => {
let call = self.load_call_by_id(call_id).await?;
self.emit_msgs_changed(call.msg.chat_id, call_id);
if call.is_incoming {
self.emit_event(EventType::IncomingCallAccepted {
msg_id: call.msg.id,
accept_call_info: call.accept_call_info,
});
} else {
self.emit_msgs_changed(call.msg.chat_id, call_id);
self.emit_event(EventType::IncomingCall {
let accept_call_info = mime_message
.get_header(HeaderDef::ChatWebrtcAccepted)
.unwrap_or_default();
call.msg
.clone()
.mark_call_as_accepted(self, accept_call_info.to_string())
.await?;
self.emit_event(EventType::OutgoingCallAccepted {
msg_id: call.msg.id,
place_call_info: call.place_call_info.to_string(),
accept_call_info: accept_call_info.to_string(),
});
let wait = call.remaining_ring_seconds();
task::spawn(Context::emit_end_call_if_unaccepted(
self.clone(),
wait.try_into()?,
call.msg.id,
));
}
} else {
self.emit_msgs_changed(call.msg.chat_id, call_id);
}
}
SystemMessage::CallAccepted => {
let call = self.load_call_by_id(call_id).await?;
self.emit_msgs_changed(call.msg.chat_id, call_id);
if call.is_incoming {
self.emit_event(EventType::IncomingCallAccepted {
msg_id: call.msg.id,
accept_call_info: call.accept_call_info,
});
} else {
let accept_call_info = mime_message
.get_header(HeaderDef::ChatWebrtcAccepted)
.unwrap_or_default();
call.msg
.clone()
.mark_call_as_accepted(self, accept_call_info.to_string())
.await?;
self.emit_event(EventType::OutgoingCallAccepted {
SystemMessage::CallEnded => {
let call = self.load_call_by_id(call_id).await?;
self.emit_msgs_changed(call.msg.chat_id, call_id);
self.emit_event(EventType::CallEnded {
msg_id: call.msg.id,
accept_call_info: accept_call_info.to_string(),
});
}
_ => {}
}
SystemMessage::CallEnded => {
let call = self.load_call_by_id(call_id).await?;
self.emit_msgs_changed(call.msg.chat_id, call_id);
self.emit_event(EventType::CallEnded {
msg_id: call.msg.id,
});
}
_ => {}
}
Ok(())
}
Expand All @@ -255,13 +256,10 @@ impl Context {
}

fn load_call_by_message(&self, call: Message) -> Result<CallInfo> {
ensure!(
call.get_info_type() == SystemMessage::IncomingCall
|| call.get_info_type() == SystemMessage::OutgoingCall
);
ensure!(call.viewtype == Viewtype::Call);

Ok(CallInfo {
is_incoming: call.get_info_type() == SystemMessage::IncomingCall,
is_incoming: call.get_from_id() != ContactId::SELF,
is_accepted: call.is_call_accepted()?,
place_call_info: call
.param
Expand All @@ -284,21 +282,15 @@ impl Message {
context: &Context,
accept_call_info: String,
) -> Result<()> {
ensure!(
self.get_info_type() == SystemMessage::IncomingCall
|| self.get_info_type() == SystemMessage::OutgoingCall
);
ensure!(self.viewtype == Viewtype::Call);
self.param.set_int(Param::Arg, 1);
self.param.set(Param::WebrtcAccepted, accept_call_info);
self.update_param(context).await?;
Ok(())
}

fn is_call_accepted(&self) -> Result<bool> {
ensure!(
self.get_info_type() == SystemMessage::IncomingCall
|| self.get_info_type() == SystemMessage::OutgoingCall
);
ensure!(self.viewtype == Viewtype::Call);
Ok(self.param.get_int(Param::Arg) == Some(1))
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/calls/calls_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ async fn setup_call() -> Result<CallSetup> {
let alice_call = Message::load_from_db(&alice, sent1.sender_msg_id).await?;
let alice2_call = alice2.recv_msg(&sent1).await;
for (t, m) in [(&alice, &alice_call), (&alice2, &alice2_call)] {
assert!(m.is_info());
assert_eq!(m.get_info_type(), SystemMessage::OutgoingCall);
assert!(!m.is_info());
assert_eq!(m.viewtype, Viewtype::Call);
let info = t.load_call_by_id(m.id).await?;
assert!(!info.is_incoming);
assert!(!info.is_accepted);
assert_eq!(info.place_call_info, "place_info");
}
Expand All @@ -45,12 +46,13 @@ async fn setup_call() -> Result<CallSetup> {
let bob_call = bob.recv_msg(&sent1).await;
let bob2_call = bob2.recv_msg(&sent1).await;
for (t, m) in [(&bob, &bob_call), (&bob2, &bob2_call)] {
assert!(m.is_info());
assert_eq!(m.get_info_type(), SystemMessage::IncomingCall);
assert!(!m.is_info());
assert_eq!(m.viewtype, Viewtype::Call);
t.evtracker
.get_matching(|evt| matches!(evt, EventType::IncomingCall { .. }))
.await;
let info = t.load_call_by_id(m.id).await?;
assert!(info.is_incoming);
assert!(!info.is_accepted);
assert_eq!(info.place_call_info, "place_info");
}
Expand Down
6 changes: 5 additions & 1 deletion src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2691,7 +2691,10 @@ impl ChatIdBlocked {
}

async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> {
if msg.viewtype == Viewtype::Text || msg.viewtype == Viewtype::VideochatInvitation {
if msg.viewtype == Viewtype::Text
|| msg.viewtype == Viewtype::VideochatInvitation
|| msg.viewtype == Viewtype::Call
{
// the caller should check if the message text is empty
} else if msg.viewtype.has_file() {
let viewtype_orig = msg.viewtype;
Expand Down Expand Up @@ -3167,6 +3170,7 @@ pub async fn send_edit_request(context: &Context, msg_id: MsgId, new_text: Strin
original_msg.viewtype != Viewtype::VideochatInvitation,
"Cannot edit videochat invitations"
);
ensure!(original_msg.viewtype != Viewtype::Call, "Cannot edit calls");
ensure!(
!original_msg.text.is_empty(), // avoid complexity in UI element changes. focus is typos and rewordings
"Cannot add text"
Expand Down
6 changes: 4 additions & 2 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,6 @@ impl Message {
| SystemMessage::WebxdcStatusUpdate
| SystemMessage::WebxdcInfoMessage
| SystemMessage::IrohNodeAddr
| SystemMessage::OutgoingCall
| SystemMessage::IncomingCall
| SystemMessage::CallAccepted
| SystemMessage::CallEnded
| SystemMessage::Unknown => Ok(None),
Expand Down Expand Up @@ -2280,6 +2278,9 @@ pub enum Viewtype {
/// Message is an invitation to a videochat.
VideochatInvitation = 70,

/// Message is an incoming or outgoing call.
Call = 71,

/// Message is an webxdc instance.
Webxdc = 80,

Expand All @@ -2303,6 +2304,7 @@ impl Viewtype {
Viewtype::Video => true,
Viewtype::File => true,
Viewtype::VideochatInvitation => false,
Viewtype::Call => false,
Viewtype::Webxdc => true,
Viewtype::Vcard => true,
}
Expand Down
16 changes: 6 additions & 10 deletions src/mimefactory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::collections::{BTreeSet, HashSet};
use std::io::Cursor;

use anyhow::{Context as _, Result, anyhow, bail, ensure};
use anyhow::{Context as _, Result, bail, ensure};
use base64::Engine as _;
use data_encoding::BASE32_NOPAD;
use deltachat_contact_tools::sanitize_bidi_characters;
Expand Down Expand Up @@ -1533,15 +1533,6 @@ impl MimeFactory {
.into(),
));
}
SystemMessage::OutgoingCall => {
headers.push((
"Chat-Content",
mail_builder::headers::raw::Raw::new("call").into(),
));
}
SystemMessage::IncomingCall => {
return Err(anyhow!("Unexpected incoming call rendering."));
}
SystemMessage::CallAccepted => {
headers.push((
"Chat-Content",
Expand Down Expand Up @@ -1578,6 +1569,11 @@ impl MimeFactory {
"Chat-Content",
mail_builder::headers::raw::Raw::new("videochat-invitation").into(),
));
} else if msg.viewtype == Viewtype::Call {
headers.push((
"Chat-Content",
mail_builder::headers::raw::Raw::new("call").into(),
));
}

if msg.param.exists(Param::WebrtcRoom) {
Expand Down
Loading
Loading