return correct videochat-type

This commit is contained in:
B. Petersen
2020-07-22 18:31:34 +02:00
parent 39364d1f6c
commit 72d95075a0
6 changed files with 69 additions and 21 deletions

View File

@@ -1633,13 +1633,14 @@ pub async fn send_videochat_invitation(context: &Context, chat_id: ChatId) -> Re
format!("{}{}", instance, room)
};
let url = instance.replace("basicwebrtc:", "");
let mut msg = Message::new(Viewtype::VideochatInvitation);
msg.param.set(Param::WebrtcInstance, &instance);
msg.text = Some(
context
.stock_string_repl_str(StockMessage::VideochatInviteMsgBody, url)
.stock_string_repl_str(
StockMessage::VideochatInviteMsgBody,
Message::parse_webrtc_instance(&instance).1,
)
.await,
);
send_msg(context, chat_id, &mut msg).await

View File

@@ -84,6 +84,19 @@ impl Default for KeyGenType {
}
}
#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive, FromSql, ToSql)]
#[repr(i8)]
pub enum VideochatType {
Unknown = 0,
BasicWebrtc = 1,
}
impl Default for VideochatType {
fn default() -> Self {
VideochatType::Unknown
}
}
pub const DC_HANDSHAKE_CONTINUE_NORMAL_PROCESSING: i32 = 0x01;
pub const DC_HANDSHAKE_STOP_NORMAL_PROCESSING: i32 = 0x02;
pub const DC_HANDSHAKE_ADD_DELETE_JOB: i32 = 0x04;

View File

@@ -638,22 +638,37 @@ impl Message {
None
}
pub async fn get_videochat_url(&self) -> Option<String> {
/// split a webrtc_instance as defined by the corresponding config-value into a type and a url
pub fn parse_webrtc_instance(instance: &str) -> (VideochatType, String) {
let mut split = instance.splitn(2, ':');
let type_str = split.next().unwrap_or_default().to_lowercase();
let url = split.next();
if type_str == "basicwebrtc" {
(
VideochatType::BasicWebrtc,
url.unwrap_or_default().to_string(),
)
} else {
(VideochatType::Unknown, instance.to_string())
}
}
pub fn get_videochat_url(&self) -> Option<String> {
if self.viewtype == Viewtype::VideochatInvitation {
if let Some(instance) = self.param.get(Param::WebrtcInstance) {
return Some(instance.replace("basicwebrtc:", ""));
return Some(Message::parse_webrtc_instance(instance).1);
}
}
None
}
pub fn is_basic_videochat(&self) -> bool {
pub fn get_videochat_type(&self) -> Option<VideochatType> {
if self.viewtype == Viewtype::VideochatInvitation {
if let Some(instance) = self.param.get(Param::WebrtcInstance) {
return instance.starts_with("basicwebrtc:");
return Some(Message::parse_webrtc_instance(instance).0);
}
}
false
None
}
pub fn set_text(&mut self, text: Option<String>) {
@@ -1824,4 +1839,19 @@ mod tests {
"Autocrypt Setup Message" // file name is not added for autocrypt setup messages
);
}
#[async_std::test]
async fn test_parse_webrtc_instance() {
let (webrtc_type, url) = Message::parse_webrtc_instance("basicwebrtc:https://foo/bar");
assert_eq!(webrtc_type, VideochatType::BasicWebrtc);
assert_eq!(url, "https://foo/bar");
let (webrtc_type, url) = Message::parse_webrtc_instance("bAsIcwEbrTc:url");
assert_eq!(webrtc_type, VideochatType::BasicWebrtc);
assert_eq!(url, "url");
let (webrtc_type, url) = Message::parse_webrtc_instance("https://foo/bar?key=val#key=val");
assert_eq!(webrtc_type, VideochatType::Unknown);
assert_eq!(url, "https://foo/bar?key=val#key=val");
}
}