prefix webrtc_instance by type, unify naming

This commit is contained in:
B. Petersen
2020-07-22 17:24:40 +02:00
parent f3b9f671ba
commit 39364d1f6c
8 changed files with 32 additions and 23 deletions

View File

@@ -1619,22 +1619,24 @@ pub async fn send_videochat_invitation(context: &Context, chat_id: ChatId) -> Re
chat_id
);
let url = if let Some(webrtc_instance) = context.get_config(Config::WebrtcInstance).await {
webrtc_instance
let instance = if let Some(instance) = context.get_config(Config::WebrtcInstance).await {
instance
} else {
bail!("webrtc_instance not set");
};
let room = dc_create_id();
let url = if url.contains("$ROOM") {
url.replace("$ROOM", &room)
let instance = if instance.contains("$ROOM") {
instance.replace("$ROOM", &room)
} else {
format!("{}{}", url, room)
format!("{}{}", instance, room)
};
let url = instance.replace("basicwebrtc:", "");
let mut msg = Message::new(Viewtype::VideochatInvitation);
msg.param.set(Param::VideochatUrl, &url);
msg.param.set(Param::WebrtcInstance, &instance);
msg.text = Some(
context
.stock_string_repl_str(StockMessage::VideochatInviteMsgBody, url)

View File

@@ -35,7 +35,7 @@ pub enum HeaderDef {
ChatContent,
ChatDuration,
ChatDispositionNotificationTo,
ChatVideochatUrl,
ChatWebrtcInstance,
Autocrypt,
AutocryptSetupMessage,
SecureJoin,

View File

@@ -640,16 +640,20 @@ impl Message {
pub async fn get_videochat_url(&self) -> Option<String> {
if self.viewtype == Viewtype::VideochatInvitation {
self.param.get(Param::VideochatUrl).map(|s| s.to_string())
} else {
None
if let Some(instance) = self.param.get(Param::WebrtcInstance) {
return Some(instance.replace("basicwebrtc:", ""));
}
}
None
}
pub fn is_basic_videochat(&self) -> bool {
// currently, all videochat-urls are of type basic-webrtc
self.viewtype == Viewtype::VideochatInvitation
&& self.param.get(Param::VideochatUrl).is_some()
if self.viewtype == Viewtype::VideochatInvitation {
if let Some(instance) = self.param.get(Param::WebrtcInstance) {
return instance.starts_with("basicwebrtc:");
}
}
false
}
pub fn set_text(&mut self, text: Option<String>) {

View File

@@ -881,10 +881,10 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
"videochat-invitation".into(),
));
protected_headers.push(Header::new(
"Chat-Videochat-Url".into(),
"Chat-Webrtc-Instance".into(),
self.msg
.param
.get(Param::VideochatUrl)
.get(Param::WebrtcInstance)
.unwrap_or_default()
.into(),
));

View File

@@ -245,10 +245,11 @@ impl MimeMessage {
fn parse_videochat_headers(&mut self) {
if let Some(value) = self.get(HeaderDef::ChatContent).cloned() {
if value == "videochat-invitation" {
let url = self.get(HeaderDef::ChatVideochatUrl).cloned();
let instance = self.get(HeaderDef::ChatWebrtcInstance).cloned();
if let Some(part) = self.parts.first_mut() {
part.typ = Viewtype::VideochatInvitation;
part.param.set(Param::VideochatUrl, url.unwrap_or_default());
part.param
.set(Param::WebrtcInstance, instance.unwrap_or_default());
}
}
}
@@ -1473,7 +1474,7 @@ mod tests {
assert_eq!(
mimeparser.parts[0]
.param
.get(Param::VideochatUrl)
.get(Param::WebrtcInstance)
.unwrap_or_default(),
"https://example.org/p2p/?roomname=6HiduoAn4xN"
);

View File

@@ -69,7 +69,7 @@ pub enum Param {
AttachGroupImage = b'A',
/// For Messages
VideochatUrl = b'V',
WebrtcInstance = b'V',
/// For Messages: space-separated list of messaged IDs of forwarded copies.
///