diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-05-26 23:01:09 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-05-26 23:01:09 +0200 |
commit | ce98d4090857ce1461b0f68a71e43afd7c4094e1 (patch) | |
tree | acae20c7bdd6ba4f42205c41714c733f56bb2ef5 /src/main/java | |
parent | 3cb9cd0a5df5400e25cd9bcac4593e39b2579116 (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')
-rw-r--r-- | src/main/java/de/pixart/messenger/parser/PresenceParser.java | 3 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 11 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/PresenceParser.java b/src/main/java/de/pixart/messenger/parser/PresenceParser.java index 15fb36372..1da8553dc 100644 --- a/src/main/java/de/pixart/messenger/parser/PresenceParser.java +++ b/src/main/java/de/pixart/messenger/parser/PresenceParser.java @@ -283,6 +283,9 @@ public class PresenceParser extends AbstractParser implements } else { contact.removePresence(from.getResource()); } + if (contact.getShownStatus() == Presence.Status.OFFLINE) { + contact.flagInactive(); + } mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, false); } else if (type.equals("subscribe")) { if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) { 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(); |