aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/services/XmppConnectionService.java
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-08-26 17:43:44 +0200
committeriNPUTmice <daniel@gultsch.de>2014-08-30 09:22:05 +0200
commit265bd062500dcd9524a0a5f70acf88350266ac26 (patch)
treec14719b6323faf697e5734f5f1983751a24c9a11 /src/eu/siacs/conversations/services/XmppConnectionService.java
parent9ad5c6925d103f5d0a030bd7af76cb8d15551189 (diff)
added basic csi
Diffstat (limited to 'src/eu/siacs/conversations/services/XmppConnectionService.java')
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index c535f1a3..ccf703fc 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -911,6 +911,9 @@ public class XmppConnectionService extends Service {
public void setOnConversationListChangedListener(
OnConversationUpdate listener) {
+ if (checkListeners()) {
+ switchToForeground();
+ }
this.mOnConversationUpdate = listener;
this.convChangedListenerCount++;
}
@@ -919,10 +922,16 @@ public class XmppConnectionService extends Service {
this.convChangedListenerCount--;
if (this.convChangedListenerCount == 0) {
this.mOnConversationUpdate = null;
+ if (checkListeners()) {
+ switchToBackground();
+ }
}
}
public void setOnAccountListChangedListener(OnAccountUpdate listener) {
+ if (checkListeners()) {
+ switchToForeground();
+ }
this.mOnAccountUpdate = listener;
this.accountChangedListenerCount++;
}
@@ -931,15 +940,54 @@ public class XmppConnectionService extends Service {
this.accountChangedListenerCount--;
if (this.accountChangedListenerCount == 0) {
this.mOnAccountUpdate = null;
+ if (checkListeners()) {
+ switchToBackground();
+ }
}
}
public void setOnRosterUpdateListener(OnRosterUpdate listener) {
+ if (checkListeners()) {
+ switchToForeground();
+ }
this.mOnRosterUpdate = listener;
}
public void removeOnRosterUpdateListener() {
this.mOnRosterUpdate = null;
+ if (checkListeners()) {
+ switchToBackground();
+ }
+ }
+
+ private boolean checkListeners() {
+ return (this.mOnAccountUpdate == null && this.mOnConversationUpdate == null && this.mOnRosterUpdate == null);
+ }
+
+ private void switchToForeground() {
+ Log.d(LOGTAG,"going into foreground");
+ for(Account account : getAccounts()) {
+ if (account.getStatus() == Account.STATUS_ONLINE) {
+ XmppConnection connection = account.getXmppConnection();
+ if (connection != null && connection.getFeatures().csi()) {
+ connection.sendActive();
+ Log.d(LOGTAG,account.getJid() + " sending csi//active");
+ }
+ }
+ }
+ }
+
+ private void switchToBackground() {
+ Log.d(LOGTAG,"going into background");
+ for(Account account : getAccounts()) {
+ if (account.getStatus() == Account.STATUS_ONLINE) {
+ XmppConnection connection = account.getXmppConnection();
+ if (connection != null && connection.getFeatures().csi()) {
+ connection.sendInactive();
+ Log.d(LOGTAG,account.getJid() + " sending csi//inactive");
+ }
+ }
+ }
}
public void connectMultiModeConversations(Account account) {