aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart/messenger/services/XmppConnectionService.java')
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java20
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;