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