feat: delete avatars referred to by parameters of special contacts

It is not clear if old versions stored SELF avatar in parameters
or if it happened due to a bug, but if it happens,
we can safely delete the avatar.

get_profile_image_ext() is refactored to make it
not try to load avatars for any special contacts.
This commit is contained in:
link2xt
2026-08-27 21:34:35 +00:00
committed by l
parent 322dd11d99
commit 4d5ebe9ff4
2 changed files with 12 additions and 2 deletions

View File

@@ -1639,7 +1639,10 @@ WHERE addr=?
}
} else if self.id == ContactId::DEVICE {
Ok(Some(chat::get_device_icon(context).await?))
} else if show_fallback_icon && !self.id.is_special() && !self.is_key_contact() {
} else if self.id.is_special() {
// All special contacts are handled above.
Ok(None)
} else if show_fallback_icon && !self.is_key_contact() {
Ok(Some(chat::get_unencrypted_icon(context).await?))
} else if let Some(image_rel) = self.param.get(Param::ProfileImage)
&& !image_rel.is_empty()

View File

@@ -1002,10 +1002,17 @@ pub async fn remove_unused_files(context: &Context) -> Result<()> {
Param::ProfileImage,
)
.await?;
// Only non-special contacts are selected
// because special contacts don't store profile image in parameters.
// ContactId::DEVICE has a hardcoded profile image
// and ContactId::SELF has the avatar stored in Config::Selfavatar.
// If some special contact has a profile image set
// e.g due to a bug, the file can be safely deleted.
maybe_add_from_param(
&context.sql,
&mut files_in_use,
"SELECT param FROM contacts;",
"SELECT param FROM contacts WHERE id > 9;",
Param::ProfileImage,
)
.await?;