aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java65
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java18
-rw-r--r--src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java10
-rw-r--r--src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java10
4 files changed, 99 insertions, 4 deletions
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index c949826a..f9af5741 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -147,6 +147,7 @@ public class XmppConnectionService extends Service {
@Override
public void onStatusChanged(Account account) {
+ XmppConnection connection = account.getXmppConnection();
if (mOnAccountUpdate != null) {
mOnAccountUpdate.onAccountUpdate();
;
@@ -166,6 +167,16 @@ public class XmppConnectionService extends Service {
sendUnsendMessages(conversations.get(i));
}
}
+ if (connection != null && connection.getFeatures().csi()) {
+ if (checkListeners()) {
+ Log.d(LOGTAG, account.getJid()
+ + " sending csi//inactive");
+ connection.sendInactive();
+ } else {
+ Log.d(LOGTAG, account.getJid() + " sending csi//active");
+ connection.sendActive();
+ }
+ }
syncDirtyContacts(account);
scheduleWakeupCall(PING_MAX_INTERVAL, true);
} else if (account.getStatus() == Account.STATUS_OFFLINE) {
@@ -179,7 +190,6 @@ public class XmppConnectionService extends Service {
reconnectAccount(account, true);
} else if ((account.getStatus() != Account.STATUS_CONNECTING)
&& (account.getStatus() != Account.STATUS_NO_INTERNET)) {
- XmppConnection connection = account.getXmppConnection();
if (connection != null) {
int next = connection.getTimeToNextAttempt();
Log.d(LOGTAG, account.getJid()
@@ -936,6 +946,9 @@ public class XmppConnectionService extends Service {
public void setOnConversationListChangedListener(
OnConversationUpdate listener) {
+ if (checkListeners()) {
+ switchToForeground();
+ }
this.mOnConversationUpdate = listener;
this.convChangedListenerCount++;
}
@@ -944,10 +957,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++;
}
@@ -956,15 +975,53 @@ 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() {
+ 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() {
+ 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) {
@@ -1392,11 +1449,11 @@ public class XmppConnectionService extends Service {
MessagePacket packet = mMessageGenerator.invite(conversation, contact);
sendMessagePacket(conversation.getAccount(), packet);
}
-
+
public void resetSendingToWaiting(Account account) {
- for(Conversation conversation : getConversations()) {
+ for (Conversation conversation : getConversations()) {
if (conversation.getAccount() == account) {
- for(Message message : conversation.getMessages()) {
+ for (Message message : conversation.getMessages()) {
if (message.getStatus() == Message.STATUS_UNSEND) {
markMessage(message, Message.STATUS_WAITING);
}
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java
index 961611fd..932b16f2 100644
--- a/src/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -48,6 +48,8 @@ import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
+import eu.siacs.conversations.xmpp.stanzas.csi.ActivePacket;
+import eu.siacs.conversations.xmpp.stanzas.csi.InactivePacket;
import eu.siacs.conversations.xmpp.stanzas.streammgmt.AckPacket;
import eu.siacs.conversations.xmpp.stanzas.streammgmt.EnablePacket;
import eu.siacs.conversations.xmpp.stanzas.streammgmt.RequestPacket;
@@ -938,6 +940,14 @@ public class XmppConnection implements Runnable {
}
}
+ public boolean csi() {
+ if (connection.streamFeatures == null) {
+ return false;
+ } else {
+ return connection.streamFeatures.hasChild("csi","urn:xmpp:csi:0");
+ }
+ }
+
public boolean pubsub() {
return hasDiscoFeature(account.getServer(), "http://jabber.org/protocol/pubsub#publish");
}
@@ -980,4 +990,12 @@ public class XmppConnection implements Runnable {
public long getLastPacketReceived() {
return this.lastPaketReceived;
}
+
+ public void sendActive() {
+ this.sendPacket(new ActivePacket(), null);
+ }
+
+ public void sendInactive() {
+ this.sendPacket(new InactivePacket(), null);
+ }
}
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java
new file mode 100644
index 00000000..78ab66d8
--- /dev/null
+++ b/src/eu/siacs/conversations/xmpp/stanzas/csi/ActivePacket.java
@@ -0,0 +1,10 @@
+package eu.siacs.conversations.xmpp.stanzas.csi;
+
+import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
+
+public class ActivePacket extends AbstractStanza {
+ public ActivePacket() {
+ super("active");
+ setAttribute("xmlns", "urn:xmpp:csi:0");
+ }
+}
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java
new file mode 100644
index 00000000..f109280f
--- /dev/null
+++ b/src/eu/siacs/conversations/xmpp/stanzas/csi/InactivePacket.java
@@ -0,0 +1,10 @@
+package eu.siacs.conversations.xmpp.stanzas.csi;
+
+import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
+
+public class InactivePacket extends AbstractStanza {
+ public InactivePacket() {
+ super("inactive");
+ setAttribute("xmlns", "urn:xmpp:csi:0");
+ }
+}