From 1c44135b412da0bae26835ca10e4793f402ae008 Mon Sep 17 00:00:00 2001 From: link2xt Date: Thu, 12 Jan 2023 14:41:41 +0000 Subject: [PATCH] Remove deprecated `attach_selfavatar` config According to the comment it was added in Dec 2019 with an intention to remove it "after some time". --- CHANGELOG.md | 1 + src/chat.rs | 17 ++++++++--------- src/config.rs | 3 --- src/mimefactory.rs | 1 + 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91263fafd..33d183b9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### API-Changes - jsonrpc: add verified-by information to `Contact`-Object +- Remove `attach_selfavatar` config #3951 ## 1.106.0 diff --git a/src/chat.rs b/src/chat.rs index cef50d3d1..0b54efc50 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -2902,14 +2902,12 @@ pub(crate) async fn add_contact_to_chat_ex( Ok(true) } +/// Returns true if an avatar should be attached in the given chat. +/// +/// This function does not check if the avatar is set. +/// If avatar is not set and this function returns `true`, +/// a `Chat-User-Avatar: 0` header should be sent to reset the avatar. pub(crate) async fn shall_attach_selfavatar(context: &Context, chat_id: ChatId) -> Result { - // versions before 12/2019 already allowed to set selfavatar, however, it was never sent to others. - // to avoid sending out previously set selfavatars unexpectedly we added this additional check. - // it can be removed after some time. - if !context.sql.get_raw_config_bool("attach_selfavatar").await? { - return Ok(false); - } - let timestamp_some_days_ago = time() - DC_RESEND_USER_AVATAR_DAYS * 24 * 60 * 60; let needs_attach = context .sql @@ -4700,12 +4698,13 @@ mod tests { ) .await?; add_contact_to_chat(&t, chat_id, contact_id).await?; - assert!(!shall_attach_selfavatar(&t, chat_id).await?); - t.set_config(Config::Selfavatar, None).await?; // setting to None also forces re-sending assert!(shall_attach_selfavatar(&t, chat_id).await?); chat_id.set_selfavatar_timestamp(&t, time()).await?; assert!(!shall_attach_selfavatar(&t, chat_id).await?); + + t.set_config(Config::Selfavatar, None).await?; // setting to None also forces re-sending + assert!(shall_attach_selfavatar(&t, chat_id).await?); Ok(()) } diff --git a/src/config.rs b/src/config.rs index 40cddcc8d..41b884fab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -292,9 +292,6 @@ impl Context { self.sql .execute("UPDATE contacts SET selfavatar_sent=0;", paramsv![]) .await?; - self.sql - .set_raw_config_bool("attach_selfavatar", true) - .await?; match value { Some(value) => { let mut blob = BlobObject::new_from_path(self, value.as_ref()).await?; diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 7f1f7b5d2..bd198329d 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -76,6 +76,7 @@ pub struct MimeFactory<'a> { /// and must be deleted if the message is actually queued for sending. sync_ids_to_delete: Option, + /// True if the avatar should be attached. attach_selfavatar: bool, }