send out videochat-invitation message, set up fallback text

This commit is contained in:
B. Petersen
2020-07-20 12:45:53 +02:00
parent 11b369db0f
commit 29d4197340
5 changed files with 91 additions and 1 deletions

View File

@@ -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
/*
* @}

View File

@@ -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() {

View File

@@ -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<MsgId, Error> {
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,

View File

@@ -638,6 +638,14 @@ impl Message {
None
}
pub async fn get_videochat_url(&self) -> Option<String> {
None
}
pub fn is_basic_videochat(&self) -> bool {
false
}
pub fn set_text(&mut self, text: Option<String>) {
self.text = text;
}

View File

@@ -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,
}
/*