diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index 4a1e4dfd7..0a2245316 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -4596,8 +4596,10 @@ void dc_event_unref(dc_event_t* event); #define DC_STR_EPHEMERAL_DAY 79 #define DC_STR_EPHEMERAL_WEEK 80 #define DC_STR_EPHEMERAL_FOUR_WEEKS 81 +#define DC_STR_VIDEOCHAT_INVITATION 82 +#define DC_STR_VIDEOCHAT_INVITE_MSG_BODY 83 -#define DC_STR_COUNT 81 +#define DC_STR_COUNT 83 /* * @} diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 8578548f9..eb42050d6 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -710,6 +710,25 @@ pub unsafe extern "C" fn dc_send_text_msg( }) } +#[no_mangle] +pub unsafe extern "C" fn dc_send_videochat_invitation( + context: *mut dc_context_t, + chat_id: u32, +) -> u32 { + if context.is_null() { + eprintln!("ignoring careless call to dc_send_videochat_invitation()"); + return 0; + } + let ctx = &*context; + + block_on(async move { + chat::send_videochat_invitation(&ctx, ChatId::new(chat_id)) + .await + .map(|msg_id| msg_id.to_u32()) + .unwrap_or_log_default(&ctx, "Failed to send videochat invitation") + }) +} + #[no_mangle] pub unsafe extern "C" fn dc_set_draft( context: *mut dc_context_t, @@ -2820,6 +2839,29 @@ pub unsafe extern "C" fn dc_msg_is_setupmessage(msg: *mut dc_msg_t) -> libc::c_i ffi_msg.message.is_setupmessage().into() } +#[no_mangle] +pub unsafe extern "C" fn dc_msg_get_videochat_url(msg: *mut dc_msg_t) -> *mut libc::c_char { + if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_videochat_url()"); + return "".strdup(); + } + let ffi_msg = &*msg; + + block_on(ffi_msg.message.get_videochat_url()) + .unwrap_or_default() + .strdup() +} + +#[no_mangle] +pub unsafe extern "C" fn dc_msg_is_basic_videochat(msg: *mut dc_msg_t) -> libc::c_int { + if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_is_basic_videochat()"); + return 0; + } + let ffi_msg = &*msg; + ffi_msg.message.is_basic_videochat().into() +} + #[no_mangle] pub unsafe extern "C" fn dc_msg_get_setupcodebegin(msg: *mut dc_msg_t) -> *mut libc::c_char { if msg.is_null() { diff --git a/src/chat.rs b/src/chat.rs index f21ce144a..f75468952 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1611,6 +1611,38 @@ pub async fn send_text_msg( send_msg(context, chat_id, &mut msg).await } +pub async fn send_videochat_invitation(context: &Context, chat_id: ChatId) -> Result { + ensure!( + !chat_id.is_special(), + "videochat invitation cannot be sent to special chat: {}", + chat_id + ); + + let url = if let Some(basic_webrtc_instance) = + context.get_config(Config::BasicWebrtcInstance).await + { + basic_webrtc_instance + } else { + bail!("basic_webrtc_instance not set"); + }; + + let room = dc_create_id(); + + let url = if url.contains("$ROOM") { + url.replace("$ROOM", &room) + } else { + format!("{}{}", url, room) + }; + + let mut msg = Message::new(Viewtype::Text); + msg.text = Some( + context + .stock_string_repl_str(StockMessage::VideochatInviteMsgBody, url) + .await, + ); + send_msg(context, chat_id, &mut msg).await +} + pub async fn get_chat_msgs( context: &Context, chat_id: ChatId, diff --git a/src/message.rs b/src/message.rs index fa87fdca3..6c36ddeb2 100644 --- a/src/message.rs +++ b/src/message.rs @@ -638,6 +638,14 @@ impl Message { None } + pub async fn get_videochat_url(&self) -> Option { + None + } + + pub fn is_basic_videochat(&self) -> bool { + false + } + pub fn set_text(&mut self, text: Option) { self.text = text; } diff --git a/src/stock.rs b/src/stock.rs index 84ef72f09..7c6d788c3 100644 --- a/src/stock.rs +++ b/src/stock.rs @@ -210,6 +210,12 @@ pub enum StockMessage { #[strum(props(fallback = "Message deletion timer is set to 4 weeks."))] MsgEphemeralTimerFourWeeks = 81, + + #[strum(props(fallback = "Videochat invitation"))] + VideochatInvitation = 82, + + #[strum(props(fallback = "You are invited to an videochat, click %1$s to join."))] + VideochatInviteMsgBody = 83, } /*