aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/services
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-05-26 23:01:09 +0200
committerChristian Schneppe <christian@pix-art.de>2018-05-26 23:01:09 +0200
commitce98d4090857ce1461b0f68a71e43afd7c4094e1 (patch)
treeacae20c7bdd6ba4f42205c41714c733f56bb2ef5 /src/main/java/de/pixart/messenger/services
parent3cb9cd0a5df5400e25cd9bcac4593e39b2579116 (diff)
improve active_since implementation (XEP-0319: Last User Interaction in Presence)
* set contact to inactive if it becomes offline * send idle also in case app started in background
Diffstat (limited to 'src/main/java/de/pixart/messenger/services')
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 4aba18387..988f247f0 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -163,6 +163,7 @@ public class XmppConnectionService extends Service {
public static final String ACTION_FCM_TOKEN_REFRESH = "fcm_token_refresh";
public static final String ACTION_FCM_MESSAGE_RECEIVED = "fcm_message_received";
private static final String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
+ private static final String SETTING_LAST_ACTIVITY_TS = "last_activity_timestamp";
static {
URL.setURLStreamHandlerFactory(new CustomURLStreamHandlerFactory());
@@ -1079,6 +1080,9 @@ public class XmppConnectionService extends Service {
return bitmap.getByteCount() / 1024;
}
};
+ if (mLastActivity == 0) {
+ mLastActivity = getPreferences().getLong(SETTING_LAST_ACTIVITY_TS, System.currentTimeMillis());
+ }
Log.d(Config.LOGTAG, "initializing database...");
this.databaseBackend = DatabaseBackend.getInstance(getApplicationContext());
@@ -2116,7 +2120,6 @@ public class XmppConnectionService extends Service {
public void setOnConversationListChangedListener(OnConversationUpdate listener) {
synchronized (this) {
- this.mLastActivity = System.currentTimeMillis();
if (checkListeners()) {
switchToForeground();
}
@@ -2299,6 +2302,12 @@ public class XmppConnectionService extends Service {
private void switchToBackground() {
final boolean broadcastLastActivity = broadcastLastActivity();
+ if (broadcastLastActivity) {
+ mLastActivity = System.currentTimeMillis();
+ final SharedPreferences.Editor editor = getPreferences().edit();
+ editor.putLong(SETTING_LAST_ACTIVITY_TS, mLastActivity);
+ editor.apply();
+ }
for (Account account : getAccounts()) {
if (account.getStatus() == Account.State.ONLINE) {
XmppConnection connection = account.getXmppConnection();