mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 15:06:30 +03:00
use Chat-User-Avatar and Chat-Group-Avatar
we change the name on the wire as the old Chat-Group-Image header could not be used on random mails, it was the marker for a "Changed" message, if we would keep this names, things will fail for exising installations as messages are dropped and a "Group image changed" message is shown instead.
This commit is contained in:
committed by
holger krekel
parent
7c3d8356c4
commit
d681fa6cba
@@ -15,7 +15,7 @@ use crate::events::Event;
|
||||
use crate::key::*;
|
||||
use crate::login_param::LoginParam;
|
||||
use crate::message::{MessageState, MsgId};
|
||||
use crate::mimeparser::ImageAction;
|
||||
use crate::mimeparser::AvatarAction;
|
||||
use crate::param::*;
|
||||
use crate::peerstate::*;
|
||||
use crate::sql;
|
||||
@@ -966,21 +966,21 @@ fn set_block_contact(context: &Context, contact_id: u32, new_blocking: bool) {
|
||||
pub fn set_profile_image(
|
||||
context: &Context,
|
||||
contact_id: u32,
|
||||
profile_image: ImageAction,
|
||||
profile_image: AvatarAction,
|
||||
) -> Result<()> {
|
||||
// the given profile image is expected to be already in the blob directory
|
||||
// as profile images can be set only by receiving messages, this should be always the case, however.
|
||||
let mut contact = Contact::load_from_db(context, contact_id)?;
|
||||
let changed = match profile_image {
|
||||
ImageAction::Change(profile_image) => {
|
||||
AvatarAction::Change(profile_image) => {
|
||||
contact.param.set(Param::ProfileImage, profile_image);
|
||||
true
|
||||
}
|
||||
ImageAction::Delete => {
|
||||
AvatarAction::Delete => {
|
||||
contact.param.remove(Param::ProfileImage);
|
||||
true
|
||||
}
|
||||
ImageAction::None => false,
|
||||
AvatarAction::None => false,
|
||||
};
|
||||
if changed {
|
||||
contact.update_param(context)?;
|
||||
|
||||
@@ -237,8 +237,8 @@ pub fn dc_receive_imf(
|
||||
);
|
||||
}
|
||||
|
||||
if mime_parser.profile_image != ImageAction::None {
|
||||
match contact::set_profile_image(&context, from_id, mime_parser.profile_image) {
|
||||
if mime_parser.user_avatar != AvatarAction::None {
|
||||
match contact::set_profile_image(&context, from_id, mime_parser.user_avatar) {
|
||||
Ok(()) => {
|
||||
context.call_cb(Event::ChatModified(chat_id));
|
||||
true
|
||||
@@ -898,13 +898,13 @@ fn create_or_lookup_group(
|
||||
|
||||
mime_parser.is_system_message = SystemMessage::GroupNameChanged;
|
||||
} else if let Some(value) = mime_parser.get(HeaderDef::ChatContent).cloned() {
|
||||
if value == "group-avatar-changed" && mime_parser.group_avatar != ImageAction::None
|
||||
if value == "group-avatar-changed" && mime_parser.group_avatar != AvatarAction::None
|
||||
{
|
||||
// this is just an explicit message containing the group-avatar,
|
||||
// apart from that, the group-avatar is send along with various other messages
|
||||
mime_parser.is_system_message = SystemMessage::GroupImageChanged;
|
||||
better_msg = context.stock_system_msg(
|
||||
if mime_parser.group_avatar == ImageAction::Delete {
|
||||
if mime_parser.group_avatar == AvatarAction::Delete {
|
||||
StockMessage::MsgGrpImgDeleted
|
||||
} else {
|
||||
StockMessage::MsgGrpImgChanged
|
||||
@@ -1036,19 +1036,19 @@ fn create_or_lookup_group(
|
||||
}
|
||||
}
|
||||
}
|
||||
if mime_parser.group_avatar != ImageAction::None {
|
||||
if mime_parser.group_avatar != AvatarAction::None {
|
||||
info!(context, "group-avatar change for {}", chat_id);
|
||||
if let Ok(mut chat) = Chat::load_from_db(context, chat_id) {
|
||||
match &mime_parser.group_avatar {
|
||||
ImageAction::Change(profile_image) => {
|
||||
AvatarAction::Change(profile_image) => {
|
||||
chat.param.set(Param::ProfileImage, profile_image);
|
||||
true
|
||||
}
|
||||
ImageAction::Delete => {
|
||||
AvatarAction::Delete => {
|
||||
chat.param.remove(Param::ProfileImage);
|
||||
true
|
||||
}
|
||||
ImageAction::None => false,
|
||||
AvatarAction::None => false,
|
||||
};
|
||||
chat.update_param(context)?;
|
||||
send_EVENT_CHAT_MODIFIED = true;
|
||||
|
||||
@@ -20,7 +20,7 @@ pub enum HeaderDef {
|
||||
ChatGroupNameChanged,
|
||||
ChatVerified,
|
||||
ChatGroupAvatar,
|
||||
ChatProfileImage,
|
||||
ChatUserAvatar,
|
||||
ChatVoiceMessage,
|
||||
ChatGroupMemberRemoved,
|
||||
ChatGroupMemberAdded,
|
||||
|
||||
@@ -895,13 +895,11 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
||||
Some(path) => match build_selfavatar_file(context, path) {
|
||||
Ok((part, filename)) => {
|
||||
parts.push(part);
|
||||
protected_headers.push(Header::new("Chat-Profile-Image".into(), filename))
|
||||
protected_headers.push(Header::new("Chat-User-Avatar".into(), filename))
|
||||
}
|
||||
Err(err) => warn!(context, "mimefactory: cannot attach selfavatar: {}", err),
|
||||
},
|
||||
None => {
|
||||
protected_headers.push(Header::new("Chat-Profile-Image".into(), "0".into()))
|
||||
}
|
||||
None => protected_headers.push(Header::new("Chat-User-Avatar".into(), "0".into())),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,15 +37,15 @@ pub struct MimeParser<'a> {
|
||||
pub is_system_message: SystemMessage,
|
||||
pub location_kml: Option<location::Kml>,
|
||||
pub message_kml: Option<location::Kml>,
|
||||
pub profile_image: ImageAction,
|
||||
pub group_avatar: ImageAction,
|
||||
pub user_avatar: AvatarAction,
|
||||
pub group_avatar: AvatarAction,
|
||||
reports: Vec<Report>,
|
||||
mdns_enabled: bool,
|
||||
parsed_protected_headers: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum ImageAction {
|
||||
pub enum AvatarAction {
|
||||
None,
|
||||
Delete,
|
||||
Change(String),
|
||||
@@ -92,8 +92,8 @@ impl<'a> MimeParser<'a> {
|
||||
is_system_message: SystemMessage::Unknown,
|
||||
location_kml: None,
|
||||
message_kml: None,
|
||||
profile_image: ImageAction::None,
|
||||
group_avatar: ImageAction::None,
|
||||
user_avatar: AvatarAction::None,
|
||||
group_avatar: AvatarAction::None,
|
||||
mdns_enabled,
|
||||
parsed_protected_headers: false,
|
||||
};
|
||||
@@ -194,11 +194,11 @@ impl<'a> MimeParser<'a> {
|
||||
}
|
||||
|
||||
if let Some(header_value) = self.get(HeaderDef::ChatGroupAvatar).cloned() {
|
||||
self.group_avatar = self.image_action_from_header(header_value);
|
||||
self.group_avatar = self.avatar_action_from_header(header_value);
|
||||
}
|
||||
|
||||
if let Some(header_value) = self.get(HeaderDef::ChatProfileImage).cloned() {
|
||||
self.profile_image = self.image_action_from_header(header_value);
|
||||
if let Some(header_value) = self.get(HeaderDef::ChatUserAvatar).cloned() {
|
||||
self.user_avatar = self.avatar_action_from_header(header_value);
|
||||
}
|
||||
|
||||
if self.has_chat_version() && self.parts.len() == 2 {
|
||||
@@ -332,9 +332,9 @@ impl<'a> MimeParser<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn image_action_from_header(&mut self, header_value: String) -> ImageAction {
|
||||
fn avatar_action_from_header(&mut self, header_value: String) -> AvatarAction {
|
||||
if header_value == "0" {
|
||||
return ImageAction::Delete;
|
||||
return AvatarAction::Delete;
|
||||
} else {
|
||||
let mut i = 0;
|
||||
while i != self.parts.len() {
|
||||
@@ -342,7 +342,7 @@ impl<'a> MimeParser<'a> {
|
||||
if let Some(part_filename) = &part.org_filename {
|
||||
if part_filename == &header_value {
|
||||
if let Some(blob) = part.param.get(Param::File) {
|
||||
let res = ImageAction::Change(blob.to_string());
|
||||
let res = AvatarAction::Change(blob.to_string());
|
||||
self.parts.remove(i);
|
||||
return res;
|
||||
}
|
||||
@@ -352,7 +352,7 @@ impl<'a> MimeParser<'a> {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
ImageAction::None
|
||||
AvatarAction::None
|
||||
}
|
||||
|
||||
pub fn get_last_nonmeta(&self) -> Option<&Part> {
|
||||
@@ -1164,25 +1164,25 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mimeparser_with_profile_image() {
|
||||
fn test_mimeparser_with_user_avatar() {
|
||||
let t = dummy_context();
|
||||
|
||||
let raw = include_bytes!("../test-data/message/mail_attach_txt.eml");
|
||||
let mimeparser = MimeParser::from_bytes(&t.ctx, &raw[..]).unwrap();
|
||||
assert_eq!(mimeparser.profile_image, ImageAction::None);
|
||||
assert_eq!(mimeparser.group_avatar, ImageAction::None);
|
||||
assert_eq!(mimeparser.user_avatar, AvatarAction::None);
|
||||
assert_eq!(mimeparser.group_avatar, AvatarAction::None);
|
||||
|
||||
let raw = include_bytes!("../test-data/message/mail_with_profile_image.eml");
|
||||
let raw = include_bytes!("../test-data/message/mail_with_user_avatar.eml");
|
||||
let mimeparser = MimeParser::from_bytes(&t.ctx, &raw[..]).unwrap();
|
||||
assert_eq!(mimeparser.parts.len(), 1);
|
||||
assert_ne!(mimeparser.profile_image, ImageAction::None);
|
||||
assert_ne!(mimeparser.profile_image, ImageAction::Delete);
|
||||
assert_eq!(mimeparser.group_avatar, ImageAction::None);
|
||||
assert_ne!(mimeparser.user_avatar, AvatarAction::None);
|
||||
assert_ne!(mimeparser.user_avatar, AvatarAction::Delete);
|
||||
assert_eq!(mimeparser.group_avatar, AvatarAction::None);
|
||||
|
||||
let raw = include_bytes!("../test-data/message/mail_with_profile_image_deleted.eml");
|
||||
let raw = include_bytes!("../test-data/message/mail_with_user_avatar_deleted.eml");
|
||||
let mimeparser = MimeParser::from_bytes(&t.ctx, &raw[..]).unwrap();
|
||||
assert_eq!(mimeparser.parts.len(), 1);
|
||||
assert_eq!(mimeparser.profile_image, ImageAction::Delete);
|
||||
assert_eq!(mimeparser.group_avatar, ImageAction::None);
|
||||
assert_eq!(mimeparser.user_avatar, AvatarAction::Delete);
|
||||
assert_eq!(mimeparser.group_avatar, AvatarAction::None);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user