From 964f60ff4bd6c2fcb9dbbf1b784ff24f25ccceca Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 15 Jul 2020 01:09:53 +0200 Subject: [PATCH] simple sync of Selfavatar when seeing our own profile image send from other devices, we use them as Selfavatar on the current device as well. as there is no special message sent on avatar changes, this is a simple approach to sync the avatar across devices. --- src/contact.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/contact.rs b/src/contact.rs index 5839a1eec..0a2bd7168 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1089,21 +1089,36 @@ async fn set_block_contact(context: &Context, contact_id: u32, new_blocking: boo } } +/// Set profile image for a contact. +/// +/// 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. +/// +/// For contact SELF, the image is not saved in the contact-database but as Config::Selfavatar; +/// this typically happens if we see message with our own profile image, sent from another device. pub(crate) async fn set_profile_image( context: &Context, contact_id: u32, 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).await?; let changed = match profile_image { AvatarAction::Change(profile_image) => { - contact.param.set(Param::ProfileImage, profile_image); + if contact_id == DC_CONTACT_ID_SELF { + context + .set_config(Config::Selfavatar, Some(profile_image)) + .await?; + } else { + contact.param.set(Param::ProfileImage, profile_image); + } true } AvatarAction::Delete => { - contact.param.remove(Param::ProfileImage); + if contact_id == DC_CONTACT_ID_SELF { + context.set_config(Config::Selfavatar, None).await?; + } else { + contact.param.remove(Param::ProfileImage); + } true } };