added basic csi
This commit is contained in:
parent
9ad5c6925d
commit
265bd06250
|
@ -911,6 +911,9 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
public void setOnConversationListChangedListener(
|
public void setOnConversationListChangedListener(
|
||||||
OnConversationUpdate listener) {
|
OnConversationUpdate listener) {
|
||||||
|
if (checkListeners()) {
|
||||||
|
switchToForeground();
|
||||||
|
}
|
||||||
this.mOnConversationUpdate = listener;
|
this.mOnConversationUpdate = listener;
|
||||||
this.convChangedListenerCount++;
|
this.convChangedListenerCount++;
|
||||||
}
|
}
|
||||||
|
@ -919,10 +922,16 @@ public class XmppConnectionService extends Service {
|
||||||
this.convChangedListenerCount--;
|
this.convChangedListenerCount--;
|
||||||
if (this.convChangedListenerCount == 0) {
|
if (this.convChangedListenerCount == 0) {
|
||||||
this.mOnConversationUpdate = null;
|
this.mOnConversationUpdate = null;
|
||||||
|
if (checkListeners()) {
|
||||||
|
switchToBackground();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnAccountListChangedListener(OnAccountUpdate listener) {
|
public void setOnAccountListChangedListener(OnAccountUpdate listener) {
|
||||||
|
if (checkListeners()) {
|
||||||
|
switchToForeground();
|
||||||
|
}
|
||||||
this.mOnAccountUpdate = listener;
|
this.mOnAccountUpdate = listener;
|
||||||
this.accountChangedListenerCount++;
|
this.accountChangedListenerCount++;
|
||||||
}
|
}
|
||||||
|
@ -931,15 +940,54 @@ public class XmppConnectionService extends Service {
|
||||||
this.accountChangedListenerCount--;
|
this.accountChangedListenerCount--;
|
||||||
if (this.accountChangedListenerCount == 0) {
|
if (this.accountChangedListenerCount == 0) {
|
||||||
this.mOnAccountUpdate = null;
|
this.mOnAccountUpdate = null;
|
||||||
|
if (checkListeners()) {
|
||||||
|
switchToBackground();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnRosterUpdateListener(OnRosterUpdate listener) {
|
public void setOnRosterUpdateListener(OnRosterUpdate listener) {
|
||||||
|
if (checkListeners()) {
|
||||||
|
switchToForeground();
|
||||||
|
}
|
||||||
this.mOnRosterUpdate = listener;
|
this.mOnRosterUpdate = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeOnRosterUpdateListener() {
|
public void removeOnRosterUpdateListener() {
|
||||||
this.mOnRosterUpdate = null;
|
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) {
|
public void connectMultiModeConversations(Account account) {
|
||||||
|
|
|
@ -47,6 +47,8 @@ import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
|
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
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.AckPacket;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.streammgmt.EnablePacket;
|
import eu.siacs.conversations.xmpp.stanzas.streammgmt.EnablePacket;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.streammgmt.RequestPacket;
|
import eu.siacs.conversations.xmpp.stanzas.streammgmt.RequestPacket;
|
||||||
|
@ -900,6 +902,14 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean csi() {
|
||||||
|
if (connection.streamFeatures == null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return connection.streamFeatures.hasChild("csi");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean pubsub() {
|
public boolean pubsub() {
|
||||||
return hasDiscoFeature(account.getServer(), "http://jabber.org/protocol/pubsub#publish");
|
return hasDiscoFeature(account.getServer(), "http://jabber.org/protocol/pubsub#publish");
|
||||||
}
|
}
|
||||||
|
@ -942,4 +952,12 @@ public class XmppConnection implements Runnable {
|
||||||
public long getLastPacketReceived() {
|
public long getLastPacketReceived() {
|
||||||
return this.lastPaketReceived;
|
return this.lastPaketReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendActive() {
|
||||||
|
this.sendPacket(new ActivePacket(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendInactive() {
|
||||||
|
this.sendPacket(new InactivePacket(), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,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");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue