From 843d7fe12d19756fe6ac2313323e90460d32abe0 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 20 Jan 2020 10:54:55 +0100 Subject: [PATCH] evict cached previews when file gets deleted --- .../eu/siacs/conversations/persistance/FileBackend.java | 2 ++ .../conversations/services/XmppConnectionService.java | 9 +++++++++ .../eu/siacs/conversations/ui/ConversationFragment.java | 1 + 3 files changed, 12 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 48f3d4343..57a129f70 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -508,6 +508,8 @@ public class FileBackend { return getFile(message, true); } + + public DownloadableFile getFileForPath(String path) { return getFileForPath(path, MimeUtils.guessMimeTypeFromExtension(MimeUtils.extractRelevantExtension(path))); } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 828721801..4280e6f00 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1854,6 +1854,9 @@ public class XmppConnectionService extends Service { for (Conversation conversation : getConversations()) { deleted |= conversation.markAsDeleted(uuids); } + for(final String uuid : uuids) { + evictPreview(uuid); + } if (deleted) { updateConversationUi(); } @@ -4575,6 +4578,12 @@ public class XmppConnectionService extends Service { sendIqPacket(account, set, null); } + public void evictPreview(String uuid) { + if (mBitmapCache.remove(uuid) != null) { + Log.d(Config.LOGTAG,"deleted cached preview"); + } + } + public interface OnMamPreferencesFetched { void onPreferencesFetched(Element prefs); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 8e2e228d4..036e35633 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1653,6 +1653,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke builder.setPositiveButton(R.string.confirm, (dialog, which) -> { if (activity.xmppConnectionService.getFileBackend().deleteFile(message)) { message.setDeleted(true); + activity.xmppConnectionService.evictPreview(message.getUuid()); activity.xmppConnectionService.updateMessage(message, false); activity.onConversationsListItemUpdated(); refresh();