message.rs: resolve "should return bool" TODOs

This commit is contained in:
Alexander Krotov
2019-09-12 12:50:08 +03:00
parent 0f67b16f29
commit fad49e08d7
6 changed files with 21 additions and 46 deletions

View File

@@ -2152,7 +2152,7 @@ pub unsafe extern "C" fn dc_msg_is_sent(msg: *mut dc_msg_t) -> libc::c_int {
return 0; return 0;
} }
let ffi_msg = &*msg; let ffi_msg = &*msg;
message::dc_msg_is_sent(&ffi_msg.message) message::dc_msg_is_sent(&ffi_msg.message).into()
} }
#[no_mangle] #[no_mangle]
@@ -2172,7 +2172,7 @@ pub unsafe extern "C" fn dc_msg_is_forwarded(msg: *mut dc_msg_t) -> libc::c_int
return 0; return 0;
} }
let ffi_msg = &*msg; let ffi_msg = &*msg;
message::dc_msg_is_forwarded(&ffi_msg.message) message::dc_msg_is_forwarded(&ffi_msg.message).into()
} }
#[no_mangle] #[no_mangle]
@@ -2182,7 +2182,7 @@ pub unsafe extern "C" fn dc_msg_is_info(msg: *mut dc_msg_t) -> libc::c_int {
return 0; return 0;
} }
let ffi_msg = &*msg; let ffi_msg = &*msg;
message::dc_msg_is_info(&ffi_msg.message) message::dc_msg_is_info(&ffi_msg.message).into()
} }
#[no_mangle] #[no_mangle]
@@ -2192,7 +2192,7 @@ pub unsafe extern "C" fn dc_msg_is_increation(msg: *mut dc_msg_t) -> libc::c_int
return 0; return 0;
} }
let ffi_msg = &*msg; let ffi_msg = &*msg;
message::dc_msg_is_increation(&ffi_msg.message) message::dc_msg_is_increation(&ffi_msg.message).into()
} }
#[no_mangle] #[no_mangle]
@@ -2202,7 +2202,7 @@ pub unsafe extern "C" fn dc_msg_is_setupmessage(msg: *mut dc_msg_t) -> libc::c_i
return 0; return 0;
} }
let ffi_msg = &*msg; let ffi_msg = &*msg;
message::dc_msg_is_setupmessage(&ffi_msg.message) as libc::c_int message::dc_msg_is_setupmessage(&ffi_msg.message).into()
} }
#[no_mangle] #[no_mangle]

View File

@@ -248,11 +248,7 @@ unsafe fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: &Message) {
} else { } else {
"[FRESH]" "[FRESH]"
}, },
if 0 != dc_msg_is_info(msg) { if dc_msg_is_info(msg) { "[INFO]" } else { "" },
"[INFO]"
} else {
""
},
statestr, statestr,
&temp2, &temp2,
); );

View File

@@ -868,7 +868,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: u32, mut msg: Option<&mut Me
} else if msgtype_has_file(msg.type_0) { } else if msgtype_has_file(msg.type_0) {
if let Some(path_filename) = msg.param.get(Param::File) { if let Some(path_filename) = msg.param.get(Param::File) {
let mut path_filename = path_filename.to_string(); let mut path_filename = path_filename.to_string();
if 0 != dc_msg_is_increation(msg) && !dc_is_blobdir_path(context, &path_filename) { if dc_msg_is_increation(msg) && !dc_is_blobdir_path(context, &path_filename) {
OK_TO_CONTINUE = false; OK_TO_CONTINUE = false;
} else if !dc_make_rel_and_copy(context, &mut path_filename) { } else if !dc_make_rel_and_copy(context, &mut path_filename) {
OK_TO_CONTINUE = false; OK_TO_CONTINUE = false;

View File

@@ -168,7 +168,7 @@ pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
} }
std::thread::sleep(std::time::Duration::from_secs(1)); std::thread::sleep(std::time::Duration::from_secs(1));
if let Ok(msg) = dc_get_msg(context, msg_id) { if let Ok(msg) = dc_get_msg(context, msg_id) {
if 0 != dc_msg_is_sent(&msg) { if dc_msg_is_sent(&msg) {
info!(context, "... setup message sent.",); info!(context, "... setup message sent.",);
break; break;
} }

View File

@@ -39,7 +39,7 @@ pub struct dc_mimefactory_t<'a> {
pub loaded: dc_mimefactory_loaded_t, pub loaded: dc_mimefactory_loaded_t,
pub msg: Message, pub msg: Message,
pub chat: Option<Chat>, pub chat: Option<Chat>,
pub increation: libc::c_int, pub increation: bool,
pub in_reply_to: *mut libc::c_char, pub in_reply_to: *mut libc::c_char,
pub references: *mut libc::c_char, pub references: *mut libc::c_char,
pub req_mdn: libc::c_int, pub req_mdn: libc::c_int,
@@ -102,7 +102,7 @@ pub unsafe fn dc_mimefactory_load_msg(
loaded: DC_MF_NOTHING_LOADED, loaded: DC_MF_NOTHING_LOADED,
msg, msg,
chat: Some(chat), chat: Some(chat),
increation: 0, increation: false,
in_reply_to: ptr::null_mut(), in_reply_to: ptr::null_mut(),
references: ptr::null_mut(), references: ptr::null_mut(),
req_mdn: 0, req_mdn: 0,
@@ -290,7 +290,7 @@ pub unsafe fn dc_mimefactory_load_mdn<'a>(
loaded: DC_MF_NOTHING_LOADED, loaded: DC_MF_NOTHING_LOADED,
msg, msg,
chat: None, chat: None,
increation: 0, increation: false,
in_reply_to: ptr::null_mut(), in_reply_to: ptr::null_mut(),
references: ptr::null_mut(), references: ptr::null_mut(),
req_mdn: 0, req_mdn: 0,

View File

@@ -87,7 +87,7 @@ impl Lot {
self.text1 = Some(context.stock_str(StockMessage::Draft).to_owned().into()); self.text1 = Some(context.stock_str(StockMessage::Draft).to_owned().into());
self.text1_meaning = Meaning::Text1Draft; self.text1_meaning = Meaning::Text1Draft;
} else if msg.from_id == DC_CONTACT_ID_SELF { } else if msg.from_id == DC_CONTACT_ID_SELF {
if 0 != dc_msg_is_info(msg) || chat.is_self_talk() { if dc_msg_is_info(msg) || chat.is_self_talk() {
self.text1 = None; self.text1 = None;
self.text1_meaning = Meaning::None; self.text1_meaning = Meaning::None;
} else { } else {
@@ -95,7 +95,7 @@ impl Lot {
self.text1_meaning = Meaning::Text1Self; self.text1_meaning = Meaning::Text1Self;
} }
} else if chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup { } else if chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup {
if 0 != dc_msg_is_info(msg) || contact.is_none() { if dc_msg_is_info(msg) || contact.is_none() {
self.text1 = None; self.text1 = None;
self.text1_meaning = Meaning::None; self.text1_meaning = Meaning::None;
} else { } else {
@@ -820,48 +820,27 @@ pub unsafe fn dc_msg_has_deviating_timestamp(msg: &Message) -> libc::c_int {
(sort_timestamp / 86400 != send_timestamp / 86400) as libc::c_int (sort_timestamp / 86400 != send_timestamp / 86400) as libc::c_int
} }
// TODO should return bool /rtn pub fn dc_msg_is_sent(msg: &Message) -> bool {
pub fn dc_msg_is_sent(msg: &Message) -> libc::c_int { msg.state as i32 >= MessageState::OutDelivered as i32
if msg.state as i32 >= MessageState::OutDelivered as i32 {
1
} else {
0
}
} }
pub fn dc_msg_is_starred(msg: &Message) -> bool { pub fn dc_msg_is_starred(msg: &Message) -> bool {
msg.starred msg.starred
} }
// TODO should return bool /rtn pub fn dc_msg_is_forwarded(msg: &Message) -> bool {
pub fn dc_msg_is_forwarded(msg: &Message) -> libc::c_int { 0 != msg.param.get_int(Param::Forwarded).unwrap_or_default()
if 0 != msg.param.get_int(Param::Forwarded).unwrap_or_default() {
1
} else {
0
}
} }
// TODO should return bool /rtn pub fn dc_msg_is_info(msg: &Message) -> bool {
pub fn dc_msg_is_info(msg: &Message) -> libc::c_int {
let cmd = msg.param.get_int(Param::Cmd).unwrap_or_default(); let cmd = msg.param.get_int(Param::Cmd).unwrap_or_default();
if msg.from_id == 2i32 as libc::c_uint msg.from_id == 2i32 as libc::c_uint
|| msg.to_id == 2i32 as libc::c_uint || msg.to_id == 2i32 as libc::c_uint
|| 0 != cmd && cmd != 6i32 || 0 != cmd && cmd != 6i32
{
return 1;
}
0
} }
// TODO should return bool /rtn pub fn dc_msg_is_increation(msg: &Message) -> bool {
pub fn dc_msg_is_increation(msg: &Message) -> libc::c_int { chat::msgtype_has_file(msg.type_0) && msg.state == MessageState::OutPreparing
if chat::msgtype_has_file(msg.type_0) && msg.state == MessageState::OutPreparing {
1
} else {
0
}
} }
pub fn dc_msg_is_setupmessage(msg: &Message) -> bool { pub fn dc_msg_is_setupmessage(msg: &Message) -> bool {