aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java')
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java45
1 files changed, 38 insertions, 7 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 5f949821..537bb55e 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -59,6 +59,7 @@ import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicLong;
import de.duenndns.ssl.MemorizingTrustManager;
import eu.siacs.conversations.Config;
@@ -265,6 +266,7 @@ public class XmppConnectionService extends Service {
private int mucRosterChangedListenerCount = 0;
private OnKeyStatusUpdated mOnKeyStatusUpdated = null;
private int keyStatusUpdatedListenerCount = 0;
+ private AtomicLong mLastExpiryRun = new AtomicLong(0);
private SecureRandom mRandom;
private LruCache<Pair<String,String>,ServiceDiscoveryResult> discoCache = new LruCache<>(20);
private final OnBindListener mOnBindListener = new OnBindListener() {
@@ -645,6 +647,9 @@ public class XmppConnectionService extends Service {
}
}
}
+ if (SystemClock.elapsedRealtime() - mLastExpiryRun.get() >= Config.EXPIRY_INTERVAL) {
+ expireOldMessages();
+ }
return START_STICKY;
}
@@ -854,6 +859,20 @@ public class XmppConnectionService extends Service {
}
}
+ private void expireOldMessages() {
+ mLastExpiryRun.set(SystemClock.elapsedRealtime());
+ synchronized (this.conversations) {
+ long timestamp = getAutomaticMessageDeletionDate();
+ if (timestamp > 0) {
+ databaseBackend.expireOldMessages(timestamp);
+ for (Conversation conversation : this.conversations) {
+ conversation.expireOldMessages(timestamp);
+ }
+ updateConversationUi();
+ }
+ }
+ }
+
public boolean hasInternetConnection() {
ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -1232,13 +1251,11 @@ public class XmppConnectionService extends Service {
if (addToConversation) {
conversation.add(message);
}
- if (message.getEncryption() == Message.ENCRYPTION_NONE || saveEncryptedMessages()) {
if (saveInDb) {
databaseBackend.createMessage(message);
} else if (message.edited()) {
databaseBackend.updateMessage(message, message.getEditedId());
}
- }
updateConversationUi();
}
if (packet != null) {
@@ -1347,6 +1364,12 @@ public class XmppConnectionService extends Service {
Runnable runnable = new Runnable() {
@Override
public void run() {
+ long deletionDate = getAutomaticMessageDeletionDate();
+ mLastExpiryRun.set(SystemClock.elapsedRealtime());
+ if (deletionDate > 0) {
+ Log.d(Config.LOGTAG, "deleting messages that are older than "+AbstractGenerator.getTimestamp(deletionDate));
+ databaseBackend.expireOldMessages(deletionDate);
+ }
Log.d(Config.LOGTAG, "restoring roster");
for (Account account : accounts) {
databaseBackend.readRoster(account.getRoster());
@@ -1518,8 +1541,11 @@ public class XmppConnectionService extends Service {
MessageArchiveService.Query query = getMessageArchiveService().query(conversation, 0, timestamp);
if (query != null) {
query.setCallback(callback);
- }
callback.informUser(R.string.fetching_history_from_server);
+ } else {
+ callback.informUser(R.string.not_fetching_history_retention_period);
+ }
+
}
}
}
@@ -3046,6 +3072,15 @@ public class XmppConnectionService extends Service {
.getDefaultSharedPreferences(getApplicationContext());
}
+ public long getAutomaticMessageDeletionDate() {
+ try {
+ final long timeout = Long.parseLong(getPreferences().getString(SettingsActivity.AUTOMATIC_MESSAGE_DELETION, "0")) * 1000;
+ return timeout == 0 ? timeout : System.currentTimeMillis() - timeout;
+ } catch (NumberFormatException e) {
+ return 0;
+ }
+ }
+
public boolean confirmMessages() {
return getPreferences().getBoolean("confirm_messages", true);
}
@@ -3058,10 +3093,6 @@ public class XmppConnectionService extends Service {
return getPreferences().getBoolean("chat_states", false);
}
- public boolean saveEncryptedMessages() {
- return !getPreferences().getBoolean("dont_save_encrypted", false);
- }
-
private boolean respectAutojoin() {
return getPreferences().getBoolean("autojoin", true);
}