fix remove chat profile img

This commit is contained in:
Simon Laux
2019-09-07 12:34:56 +02:00
committed by holger krekel
parent 275aa853f5
commit 0a8b187f80
2 changed files with 25 additions and 19 deletions

View File

@@ -898,9 +898,15 @@ pub unsafe extern "C" fn dc_set_chat_profile_image(
let context = &*context;
chat::set_chat_profile_image(context, chat_id, as_str(image))
.map(|_| 1)
.unwrap_or_log_default(context, "Failed to set profile image")
chat::set_chat_profile_image(context, chat_id, {
if image.is_null() {
""
} else {
as_str(image)
}
})
.map(|_| 1)
.unwrap_or_log_default(context, "Failed to set profile image")
}
#[no_mangle]

View File

@@ -1653,34 +1653,34 @@ pub unsafe fn set_chat_profile_image(
) -> Result<(), Error> {
ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat ID");
let mut OK_TO_CONTINUE = true;
let mut success = false;
let mut chat = Chat::load_from_db(context, chat_id)?;
let mut msg = dc_msg_new_untyped(context);
let mut new_image_rel = None;
if real_group_exists(context, chat_id) {
if !(is_contact_in_chat(context, chat_id, 1i32 as u32) == 1i32) {
log_event!(
context,
Event::ERROR_SELF_NOT_IN_GROUP,
0,
"Cannot set chat profile image; self not in group.",
);
} else {
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
(|| {
if real_group_exists(context, chat_id) {
if !(is_contact_in_chat(context, chat_id, 1i32 as u32) == 1i32) {
log_event!(
context,
Event::ERROR_SELF_NOT_IN_GROUP,
0,
"Cannot set chat profile image; self not in group.",
);
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
return;
}
if !new_image.as_ref().is_empty() {
let mut img = new_image.as_ref().to_string();
if !dc_make_rel_and_copy(context, &mut img) {
OK_TO_CONTINUE = false;
return;
}
new_image_rel = Some(img);
} else {
OK_TO_CONTINUE = false;
new_image_rel = Some("".to_string());
}
}
if OK_TO_CONTINUE {
if let Some(ref new_image_rel) = new_image_rel {
chat.param.set(Param::ProfileImage, new_image_rel);
}
@@ -1716,7 +1716,7 @@ pub unsafe fn set_chat_profile_image(
success = true;
}
}
}
})();
if !success {
bail!("Failed to set profile image");