From cfa69cf35acfd9dff52fe64175a089770ed16c8d Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Fri, 25 Oct 2019 18:16:18 +0300 Subject: [PATCH] Add Params::set_cmd and use SystemMessage constants --- src/chat.rs | 6 +++--- src/imex.rs | 3 ++- src/location.rs | 5 +++-- src/param.rs | 5 +++++ src/securejoin.rs | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index a68bd5abb..17d76137c 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1419,7 +1419,7 @@ pub(crate) fn add_contact_to_chat_ex( "", DC_CONTACT_ID_SELF as u32, )); - msg.param.set_int(Param::Cmd, 4); + msg.param.set_cmd(SystemMessage::MemberAddedToGroup); msg.param.set(Param::Arg, contact.get_addr()); msg.param.set_int(Param::Arg2, from_handshake.into()); msg.id = send_msg(context, chat_id, &mut msg)?; @@ -1531,7 +1531,7 @@ pub fn remove_contact_from_chat( DC_CONTACT_ID_SELF, )); } - msg.param.set_int(Param::Cmd, 5); + msg.param.set_cmd(SystemMessage::MemberRemovedFromGroup); msg.param.set(Param::Arg, contact.get_addr()); msg.id = send_msg(context, chat_id, &mut msg)?; context.call_cb(Event::MsgsChanged { @@ -1626,7 +1626,7 @@ pub fn set_chat_name( new_name.as_ref(), DC_CONTACT_ID_SELF, )); - msg.param.set_int(Param::Cmd, 2); + msg.param.set_cmd(SystemMessage::GroupNameChanged); if !chat.name.is_empty() { msg.param.set(Param::Arg, &chat.name); } diff --git a/src/imex.rs b/src/imex.rs index 288421efb..1ba925eb1 100644 --- a/src/imex.rs +++ b/src/imex.rs @@ -10,6 +10,7 @@ use crate::config::Config; use crate::configure::*; use crate::constants::*; use crate::context::Context; +use crate::dc_mimeparser::SystemMessage; use crate::dc_tools::*; use crate::e2ee; use crate::error::*; @@ -136,7 +137,7 @@ fn do_initiate_key_transfer(context: &Context) -> Result { msg.param .set(Param::MimeType, "application/autocrypt-setup"); - msg.param.set_int(Param::Cmd, 6); + msg.param.set_cmd(SystemMessage::AutocryptSetupMessage); msg.param .set_int(Param::ForcePlaintext, DC_FP_NO_AUTOCRYPT_HEADER); diff --git a/src/location.rs b/src/location.rs index 285588c1b..675d010ae 100644 --- a/src/location.rs +++ b/src/location.rs @@ -6,6 +6,7 @@ use crate::chat; use crate::config::Config; use crate::constants::*; use crate::context::*; +use crate::dc_mimeparser::SystemMessage; use crate::dc_tools::*; use crate::error::Error; use crate::events::Event; @@ -218,7 +219,7 @@ pub fn send_locations_to_chat(context: &Context, chat_id: u32, seconds: i64) { msg = Message::new(Viewtype::Text); msg.text = Some(context.stock_system_msg(StockMessage::MsgLocationEnabled, "", "", 0)); - msg.param.set_int(Param::Cmd, 8); + msg.param.set_cmd(SystemMessage::LocationStreamingEnabled); chat::send_msg(context, chat_id, &mut msg).unwrap_or_default(); } else if 0 == seconds && is_sending_locations_before { let stock_str = @@ -603,7 +604,7 @@ pub fn job_do_DC_JOB_MAYBE_SEND_LOCATIONS(context: &Context, _job: &Job) { // and dc_set_location() is typically called periodically, this is ok) let mut msg = Message::new(Viewtype::Text); msg.hidden = true; - msg.param.set_int(Param::Cmd, 9); + msg.param.set_cmd(SystemMessage::LocationOnly); Some((chat_id, msg)) } }) diff --git a/src/param.rs b/src/param.rs index 9ad8e1316..8e078c1b6 100644 --- a/src/param.rs +++ b/src/param.rs @@ -189,6 +189,11 @@ impl Params { .unwrap_or_default() } + /// Set the parameter behind `Param::Cmd`. + pub fn set_cmd(&mut self, value: SystemMessage) { + self.set_int(Param::Cmd, value as i32); + } + /// Get the given parameter and parse as `f64`. pub fn get_float(&self, key: Param) -> Option { self.get(key).and_then(|s| s.parse().ok()) diff --git a/src/securejoin.rs b/src/securejoin.rs index 9bb48275c..28ddbc309 100644 --- a/src/securejoin.rs +++ b/src/securejoin.rs @@ -257,7 +257,7 @@ fn send_handshake_msg( msg.type_0 = Viewtype::Text; msg.text = Some(format!("Secure-Join: {}", step)); msg.hidden = true; - msg.param.set_int(Param::Cmd, 7); + msg.param.set_cmd(SystemMessage::SecurejoinMessage); if step.is_empty() { msg.param.remove(Param::Arg); } else {