diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-06-21 21:40:16 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-06-21 21:40:16 +0200 |
commit | c71aa059f9a344e052f6218132a156acf360be21 (patch) | |
tree | 331c15ed46161fd48a904af3569a74566480728d /src/main/java/de/pixart/messenger/services | |
parent | 81c0944245b84824f1ba76ce225225ea996f57c1 (diff) |
shedule webpreview cache deletion
Diffstat (limited to 'src/main/java/de/pixart/messenger/services')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 539f89553..b57d9846f 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -66,6 +66,7 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; @@ -169,6 +170,7 @@ import static de.pixart.messenger.ui.SettingsActivity.CONFIRM_MESSAGES; import static de.pixart.messenger.ui.SettingsActivity.ENABLE_MULTI_ACCOUNTS; import static de.pixart.messenger.ui.SettingsActivity.INDICATE_RECEIVED; import static de.pixart.messenger.ui.SettingsActivity.SHOW_OWN_ACCOUNTS; +import static de.pixart.messenger.utils.RichPreview.RICH_LINK_METADATA; public class XmppConnectionService extends Service { @@ -757,10 +759,28 @@ public class XmppConnectionService extends Service { } if (SystemClock.elapsedRealtime() - mLastExpiryRun.get() >= Config.EXPIRY_INTERVAL) { expireOldMessages(); + deleteWebpreviewCache(); } return START_STICKY; } + private void deleteWebpreviewCache() { + final String path = getApplicationContext().getCacheDir() + "/" + RICH_LINK_METADATA; + final Calendar time = Calendar.getInstance(); + time.add(Calendar.DAY_OF_YEAR, -7); + final File directory = new File(path); + final File[] files = directory.listFiles(); + int count = 0; + for (File file : files) { + Date lastModified = new Date(file.lastModified()); + if (lastModified.before(time.getTime())) { + file.delete(); + count++; + } + } + Log.d(Config.LOGTAG, "Deleted " + count + " old webpreview cache files"); + } + private boolean processAccountState(Account account, boolean interactive, boolean isUiAction, boolean isAccountPushed, HashSet<Account> pingCandidates) { storeNumberOfAccounts(this.getAccounts().size()); boolean pingNow = false; |