[fractal/fix-account-settings] fractal-gtk: Remove avatar from cache on update
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fix-account-settings] fractal-gtk: Remove avatar from cache on update
- Date: Wed, 22 Jul 2020 09:42:37 +0000 (UTC)
commit cd012a8a170872e768621f17e8fa64cc49d3cfd4
Author: Daniel GarcĂa Moreno <dani danigm net>
Date: Wed Jul 22 11:39:57 2020 +0200
fractal-gtk: Remove avatar from cache on update
When the avatar is updated the cached image should be removed in order
to force a download of the new one.
This patch adds a new function to remove a user info from the cache and
do call to this new function when the user avatar is updated.
fractal-gtk/src/appop/account.rs | 5 ++++-
fractal-gtk/src/cache/mod.rs | 12 ++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/fractal-gtk/src/appop/account.rs b/fractal-gtk/src/appop/account.rs
index 31acb8f0..d311209e 100644
--- a/fractal-gtk/src/appop/account.rs
+++ b/fractal-gtk/src/appop/account.rs
@@ -13,7 +13,7 @@ use crate::i18n::i18n;
use crate::widgets;
use crate::widgets::AvatarExt;
-use crate::cache::download_to_cache;
+use crate::cache::{download_to_cache, remove_from_cache};
use fractal_api::r0::contact::get_identifiers::ThirdPartyIdentifier;
use fractal_api::r0::Medium;
@@ -501,6 +501,9 @@ impl AppOp {
});
avatar_spinner.hide();
avatar_btn.set_sensitive(true);
+ if let Some(login_data) = &self.login_data {
+ remove_from_cache(self.user_info_cache.clone(), &login_data.uid);
+ }
self.show_avatar();
}
diff --git a/fractal-gtk/src/cache/mod.rs b/fractal-gtk/src/cache/mod.rs
index 980f0e82..7f7b6939 100644
--- a/fractal-gtk/src/cache/mod.rs
+++ b/fractal-gtk/src/cache/mod.rs
@@ -1,6 +1,7 @@
use crate::appop::UserInfoCache;
use crate::backend::user;
use crate::backend::ThreadPool;
+use crate::util::cache_dir_path;
use crate::util::ResultExpectLog;
use fractal_api::r0::AccessToken;
use fractal_api::url::Url;
@@ -71,6 +72,10 @@ impl<K: Clone + Eq + Hash, V: Clone> CacheMap<K, V> {
let now = Instant::now();
self.map.insert(k, (now, v));
}
+
+ pub fn remove(&mut self, k: &K) -> Option<V> {
+ self.map.remove(k).map(|v| v.1)
+ }
}
// TODO: remove this struct
@@ -143,6 +148,13 @@ pub fn load() -> Result<CacheData, Error> {
Ok(data)
}
+pub fn remove_from_cache(user_info_cache: UserInfoCache, user_id: &UserId) {
+ user_info_cache.lock().unwrap().remove(&user_id);
+ if let Ok(dest) = cache_dir_path(None, &user_id.to_string()) {
+ let _ = std::fs::remove_file(dest);
+ }
+}
+
/// this downloads a avatar and stores it in the cache folder
pub fn download_to_cache(
thread_pool: ThreadPool,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]