From 0523868a88e0fd98c4d2e22e351d40969f51da6e Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Sat, 21 Sep 2019 06:16:15 +0000 Subject: [PATCH] Avoid ok-to-continue pattern in "do_set_draft" function Note: I strongly suggest reviewing this commit in side-by-side mode. Note: This commit fails CI due incorrect formatting. It is done deliberately to simplify review process. --- src/chat.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 8c4ba3912..2098106f8 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -871,27 +871,27 @@ fn maybe_delete_draft(context: &Context, chat_id: u32) -> bool { /// /// Return true on success, false on database error. fn do_set_draft(context: &Context, chat_id: u32, msg: &mut Message) -> bool { - let mut OK_TO_CONTINUE = true; let mut sth_changed = false; - // save new draft - if msg.type_0 == Viewtype::Text { - OK_TO_CONTINUE = msg.text.as_ref().map_or(false, |s| !s.is_empty()); - } else if msgtype_has_file(msg.type_0) { + match msg.type_0 { + Viewtype::Unknown => return false, + Viewtype::Text => if msg.text.as_ref().map_or(false, |s| s.is_empty()) { + return false; + }, + _ => if let Some(path_filename) = msg.param.get(Param::File) { let mut path_filename = path_filename.to_string(); if dc_msg_is_increation(msg) && !dc_is_blobdir_path(context, &path_filename) { - OK_TO_CONTINUE = false; - } else if !dc_make_rel_and_copy(context, &mut path_filename) { - OK_TO_CONTINUE = false; - } else { - msg.param.set(Param::File, path_filename); + return false; } + if !dc_make_rel_and_copy(context, &mut path_filename) { + return false; + } + msg.param.set(Param::File, path_filename); } - } else { - OK_TO_CONTINUE = false; } - if OK_TO_CONTINUE { + + { if sql::execute( context, &context.sql,