From 5f340d979d4757f263bfe73c7c86f8768ca1eac1 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 3 Jun 2024 17:07:55 -0400 Subject: [PATCH] Fix issue with avatar / icon deletion when saving settings. - Fixes #4763 --- crates/api_common/src/request.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/api_common/src/request.rs b/crates/api_common/src/request.rs index c304bcba7..6f1a86e0a 100644 --- a/crates/api_common/src/request.rs +++ b/crates/api_common/src/request.rs @@ -338,16 +338,18 @@ async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> Lemm } } -/// When adding a new avatar or similar image, delete the old one. +/// When adding a new avatar, banner or similar image, delete the old one. pub async fn replace_image( new_image: &Option, old_image: &Option, context: &Data, ) -> LemmyResult<()> { - if new_image.is_some() { - // Ignore errors because image may be stored externally. - if let Some(avatar) = &old_image { - let image = LocalImage::delete_by_url(&mut context.pool(), avatar) + if let (Some(new_image), Some(old_image)) = (new_image, old_image) { + // Note: Oftentimes front ends will include the current image in the form, + // so only delete if the urls are different. + if new_image != old_image.as_str() { + // Ignore errors because image may be stored externally. + let image = LocalImage::delete_by_url(&mut context.pool(), old_image) .await .ok(); if let Some(image) = image {