Code style (I hope it got better)

This commit is contained in:
Hocuri
2020-04-13 16:02:01 +02:00
parent 4e174d0c2f
commit b1536b3893

View File

@@ -434,7 +434,7 @@ fn add_parts(
}, },
create_blocked, create_blocked,
list_id_header, list_id_header,
)?; );
*chat_id = new_chat_id; *chat_id = new_chat_id;
chat_id_blocked = new_chat_id_blocked; chat_id_blocked = new_chat_id_blocked;
if !chat_id.is_unset() if !chat_id.is_unset()
@@ -1127,7 +1127,7 @@ fn create_or_lookup_mailinglist(
allow_creation: bool, allow_creation: bool,
create_blocked: Blocked, create_blocked: Blocked,
list_id_header: &str, list_id_header: &str,
) -> Result<(ChatId, Blocked)> { ) -> (ChatId, Blocked) {
let re = Regex::new(r"^(.*.)<(.*.)>$").unwrap(); let re = Regex::new(r"^(.*.)<(.*.)>$").unwrap();
let (name, listid) = match re.captures(list_id_header) { let (name, listid) = match re.captures(list_id_header) {
Some(cap) => (cap[1].trim().to_string(), cap[2].trim().to_string()), Some(cap) => (cap[1].trim().to_string(), cap[2].trim().to_string()),
@@ -1137,31 +1137,26 @@ fn create_or_lookup_mailinglist(
), ),
}; };
match chat::get_chat_id_by_mailinglistid(context, &listid) { chat::get_chat_id_by_mailinglistid(context, &listid).unwrap_or_else(|_e| {
Ok((chat_id, blocked)) => Ok((chat_id, blocked)), if allow_creation {
Err(_) => {
// list does not exist but should be created // list does not exist but should be created
if !allow_creation {
info!(context, "creating list forbidden by caller");
return Ok((ChatId::new(0), Blocked::Not));
}
let chat_id = create_mailinglist_record(context, &listid, &name, create_blocked) let chat_id = create_mailinglist_record(context, &listid, &name, create_blocked)
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
warn!( warn!(
context, context,
"Failed to create group '{}' for grpid={}: {}", "Failed to create mailinglist '{}' for grpid={}: {}",
&name, &name,
&listid, &listid,
e.to_string() e.to_string()
); );
ChatId::new(0) ChatId::new(0)
}); });
Ok((chat_id, create_blocked)) (chat_id, create_blocked)
} else {
info!(context, "creating list forbidden by caller");
(ChatId::new(0), Blocked::Not)
} }
} })
} }
/// try extract a grpid from a message-id list header value /// try extract a grpid from a message-id list header value
@@ -1788,7 +1783,6 @@ mod tests {
assert_eq!(chat.name, "deltachat/deltachat-core-rust"); assert_eq!(chat.name, "deltachat/deltachat-core-rust");
assert_eq!(chat::get_chat_contacts(&t.ctx, chat_id).len(), 0); assert_eq!(chat::get_chat_contacts(&t.ctx, chat_id).len(), 0);
dc_receive_imf(&t.ctx, MAILINGLIST2, "INBOX", 1, false).unwrap(); dc_receive_imf(&t.ctx, MAILINGLIST2, "INBOX", 1, false).unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).unwrap(); let chats = Chatlist::try_load(&t.ctx, 0, None, None).unwrap();