mirror of
https://github.com/chatmail/core.git
synced 2026-04-02 05:22:14 +03:00
Compare commits
4 Commits
822a99ea9c
...
fix_remove
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f731b0f98 | ||
|
|
99c5674a10 | ||
|
|
c4fe0316d4 | ||
|
|
176417dc99 |
@@ -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]
|
||||
|
||||
89
src/chat.rs
89
src/chat.rs
@@ -1722,12 +1722,9 @@ 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;
|
||||
let new_image_rel;
|
||||
|
||||
if real_group_exists(context, chat_id) {
|
||||
if !(is_contact_in_chat(context, chat_id, 1i32 as u32) == 1i32) {
|
||||
@@ -1737,61 +1734,55 @@ pub unsafe fn set_chat_profile_image(
|
||||
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 !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;
|
||||
}
|
||||
new_image_rel = Some(img);
|
||||
} else {
|
||||
OK_TO_CONTINUE = false;
|
||||
}
|
||||
bail!("Failed to set profile image");
|
||||
}
|
||||
if OK_TO_CONTINUE {
|
||||
if let Some(ref new_image_rel) = new_image_rel {
|
||||
chat.param.set(Param::ProfileImage, new_image_rel);
|
||||
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) {
|
||||
bail!("Failed to set profile image");
|
||||
}
|
||||
if chat.update_param().is_ok() {
|
||||
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
||||
msg.param.set_int(Param::Cmd, 3);
|
||||
if let Some(ref new_image_rel) = new_image_rel {
|
||||
msg.param.set(Param::Arg, new_image_rel);
|
||||
}
|
||||
msg.type_0 = Viewtype::Text;
|
||||
msg.text = Some(context.stock_system_msg(
|
||||
if new_image_rel.is_some() {
|
||||
StockMessage::MsgGrpImgChanged
|
||||
} else {
|
||||
StockMessage::MsgGrpImgDeleted
|
||||
},
|
||||
"",
|
||||
"",
|
||||
DC_CONTACT_ID_SELF,
|
||||
));
|
||||
msg.id = send_msg(context, chat_id, &mut msg).unwrap_or_default();
|
||||
context.call_cb(
|
||||
Event::MSGS_CHANGED,
|
||||
chat_id as uintptr_t,
|
||||
msg.id as uintptr_t,
|
||||
);
|
||||
new_image_rel = Some(img);
|
||||
} else {
|
||||
new_image_rel = Some("".to_string());
|
||||
}
|
||||
|
||||
if let Some(ref new_image_rel) = new_image_rel {
|
||||
chat.param.set(Param::ProfileImage, new_image_rel);
|
||||
}
|
||||
if chat.update_param().is_ok() {
|
||||
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
||||
msg.param.set_int(Param::Cmd, 3);
|
||||
if let Some(ref new_image_rel) = new_image_rel {
|
||||
msg.param.set(Param::Arg, new_image_rel);
|
||||
}
|
||||
msg.type_0 = Viewtype::Text;
|
||||
msg.text = Some(context.stock_system_msg(
|
||||
if new_image_rel.is_some() {
|
||||
StockMessage::MsgGrpImgChanged
|
||||
} else {
|
||||
StockMessage::MsgGrpImgDeleted
|
||||
},
|
||||
"",
|
||||
"",
|
||||
DC_CONTACT_ID_SELF,
|
||||
));
|
||||
msg.id = send_msg(context, chat_id, &mut msg).unwrap_or_default();
|
||||
context.call_cb(
|
||||
Event::CHAT_MODIFIED,
|
||||
Event::MSGS_CHANGED,
|
||||
chat_id as uintptr_t,
|
||||
0i32 as uintptr_t,
|
||||
msg.id as uintptr_t,
|
||||
);
|
||||
success = true;
|
||||
}
|
||||
context.call_cb(
|
||||
Event::CHAT_MODIFIED,
|
||||
chat_id as uintptr_t,
|
||||
0i32 as uintptr_t,
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
if !success {
|
||||
bail!("Failed to set profile image");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
bail!("Failed to set profile image");
|
||||
}
|
||||
|
||||
pub unsafe fn forward_msgs(
|
||||
|
||||
Reference in New Issue
Block a user