mirror of
https://github.com/chatmail/core.git
synced 2026-04-23 00:16:34 +03:00
address @r10s and @flub review comments, and fix some docstrings/test meta docs
This commit is contained in:
@@ -1786,7 +1786,7 @@ pub unsafe extern "C" fn dc_chat_get_profile_image(chat: *mut dc_chat_t) -> *mut
|
||||
let chat = &*chat;
|
||||
|
||||
match chat.get_profile_image() {
|
||||
Some(i) => i.strdup(),
|
||||
Some(p) => p.to_str().unwrap().to_string().strdup(),
|
||||
None => ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
@@ -2403,7 +2403,7 @@ pub unsafe extern "C" fn dc_contact_get_profile_image(
|
||||
|
||||
contact
|
||||
.get_profile_image()
|
||||
.map(|s| s.strdup())
|
||||
.map(|p| p.to_str().unwrap().to_string().strdup())
|
||||
.unwrap_or_else(|| std::ptr::null_mut())
|
||||
}
|
||||
|
||||
|
||||
@@ -350,7 +350,7 @@ class Chat(object):
|
||||
"""Get group profile image.
|
||||
|
||||
For groups, this is the image set by any group member using
|
||||
dc_set_chat_profile_image(). For normal chats, this is the image
|
||||
set_chat_profile_image(). For normal chats, this is the image
|
||||
set by each remote user on their own using dc_set_config(context,
|
||||
"selfavatar", image).
|
||||
:returns: path to profile image, None if no profile image exists.
|
||||
|
||||
@@ -609,15 +609,15 @@ class TestOnlineAccount:
|
||||
chat = ac1.create_group_chat("hello")
|
||||
p = data.get_path("d.png")
|
||||
|
||||
lp.sec("set profile image")
|
||||
lp.sec("ac1: set profile image on unpromoted chat")
|
||||
chat.set_profile_image(p)
|
||||
ac1._evlogger.get_matching("DC_EVENT_CHAT_MODIFIED")
|
||||
assert not chat.is_promoted()
|
||||
|
||||
# XXX first promote the chat before setting group image
|
||||
# because DC does not honor it before promotion happened
|
||||
# unless you add yet another member, see step below.
|
||||
|
||||
lp.sec("ac1: send text to promote chat (XXX without contact added)")
|
||||
# XXX first promote the chat before adding contact
|
||||
# because DC does not send out profile images for unpromoted chats
|
||||
# otherwise
|
||||
chat.send_text("ac1: initial message to promote chat (workaround)")
|
||||
assert chat.is_promoted()
|
||||
|
||||
@@ -628,7 +628,7 @@ class TestOnlineAccount:
|
||||
|
||||
lp.sec("ac1: add ac2 to promoted group chat")
|
||||
c2 = ac1.create_contact(email=ac2.get_config("addr"))
|
||||
contact1 = chat.add_contact(c2)
|
||||
chat.add_contact(c2)
|
||||
|
||||
lp.sec("ac1: send a first message to ac2")
|
||||
chat.send_text("hi")
|
||||
@@ -654,9 +654,3 @@ class TestOnlineAccount:
|
||||
chat1b = ac1.create_chat_by_message(ev[2])
|
||||
assert chat1b.get_profile_image() is None
|
||||
assert chat.get_profile_image() is None
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
15
src/chat.rs
15
src/chat.rs
@@ -1,5 +1,5 @@
|
||||
use std::ffi::CString;
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::chatlist::*;
|
||||
use crate::constants::*;
|
||||
@@ -187,15 +187,10 @@ impl<'a> Chat<'a> {
|
||||
.ok()
|
||||
}
|
||||
|
||||
pub fn get_profile_image(&self) -> Option<String> {
|
||||
pub fn get_profile_image(&self) -> Option<PathBuf> {
|
||||
if let Some(image_rel) = self.param.get(Param::ProfileImage) {
|
||||
if !image_rel.is_empty() {
|
||||
return Some(
|
||||
dc_get_abs_path_safe(self.context, image_rel)
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
);
|
||||
return Some(dc_get_abs_path_safe(self.context, image_rel));
|
||||
}
|
||||
} else if self.typ == Chattype::Single {
|
||||
let contacts = get_chat_contacts(self.context, self.id);
|
||||
@@ -1658,13 +1653,14 @@ pub unsafe fn set_chat_name(
|
||||
pub fn set_chat_profile_image(
|
||||
context: &Context,
|
||||
chat_id: u32,
|
||||
new_image: impl AsRef<str>,
|
||||
new_image: impl AsRef<str>, // XXX use PathBuf
|
||||
) -> Result<(), Error> {
|
||||
ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat ID");
|
||||
|
||||
let mut chat = Chat::load_from_db(context, chat_id)?;
|
||||
|
||||
if real_group_exists(context, chat_id) {
|
||||
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
|
||||
if !(is_contact_in_chat(context, chat_id, DC_CONTACT_ID_SELF) == 1i32) {
|
||||
log_event!(
|
||||
context,
|
||||
@@ -1672,7 +1668,6 @@ pub fn set_chat_profile_image(
|
||||
0,
|
||||
"Cannot set chat profile image; self not in group.",
|
||||
);
|
||||
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
|
||||
bail!("Failed to set profile image");
|
||||
}
|
||||
let mut new_image_rel: String;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use deltachat_derive::*;
|
||||
use itertools::Itertools;
|
||||
use rusqlite;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::aheader::EncryptPreference;
|
||||
use crate::config::Config;
|
||||
@@ -766,9 +767,11 @@ impl<'a> Contact<'a> {
|
||||
/// Get the contact's profile image.
|
||||
/// This is the image set by each remote user on their own
|
||||
/// using dc_set_config(context, "selfavatar", image).
|
||||
pub fn get_profile_image(&self) -> Option<String> {
|
||||
pub fn get_profile_image(&self) -> Option<PathBuf> {
|
||||
if self.id == DC_CONTACT_ID_SELF {
|
||||
return self.context.get_config(Config::Selfavatar);
|
||||
if let Some(p) = self.context.get_config(Config::Selfavatar) {
|
||||
return Some(PathBuf::from(p));
|
||||
}
|
||||
}
|
||||
// TODO: else get image_abs from contact param
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user