fixed logic bug with cleaning of presences

This commit is contained in:
Daniel Gultsch 2014-03-14 20:43:54 +01:00
parent 29e128513d
commit bae7418756
3 changed files with 24 additions and 2 deletions

View file

@ -34,6 +34,7 @@ import eu.siacs.conversations.utils.OnPhoneContactsLoadedListener;
import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnBindListener;
import eu.siacs.conversations.xmpp.OnIqPacketReceived; import eu.siacs.conversations.xmpp.OnIqPacketReceived;
import eu.siacs.conversations.xmpp.OnMessagePacketReceived; import eu.siacs.conversations.xmpp.OnMessagePacketReceived;
import eu.siacs.conversations.xmpp.OnPresencePacketReceived; import eu.siacs.conversations.xmpp.OnPresencePacketReceived;
@ -186,7 +187,6 @@ public class XmppConnectionService extends Service {
accountChangedListener.onAccountListChangedListener(); accountChangedListener.onAccountListChangedListener();
} }
if (account.getStatus() == Account.STATUS_ONLINE) { if (account.getStatus() == Account.STATUS_ONLINE) {
databaseBackend.clearPresences(account);
if (account.getXmppConnection().hasFeatureRosterManagment()) { if (account.getXmppConnection().hasFeatureRosterManagment()) {
updateRoster(account, null); updateRoster(account, null);
} }
@ -541,6 +541,13 @@ public class XmppConnectionService extends Service {
} }
} }
}); });
connection.setOnBindListener(new OnBindListener() {
@Override
public void onBind(Account account) {
databaseBackend.clearPresences(account);
}
});
return connection; return connection;
} }

View file

@ -0,0 +1,7 @@
package eu.siacs.conversations.xmpp;
import eu.siacs.conversations.entities.Account;
public interface OnBindListener {
public void onBind(Account account);
}

View file

@ -86,7 +86,8 @@ public class XmppConnection implements Runnable {
private OnIqPacketReceived unregisteredIqListener = null; private OnIqPacketReceived unregisteredIqListener = null;
private OnMessagePacketReceived messageListener = null; private OnMessagePacketReceived messageListener = null;
private OnStatusChanged statusListener = null; private OnStatusChanged statusListener = null;
private OnTLSExceptionReceived tlsListener; private OnTLSExceptionReceived tlsListener = null;
private OnBindListener bindListener = null;
public XmppConnection(Account account, PowerManager pm) { public XmppConnection(Account account, PowerManager pm) {
this.account = account; this.account = account;
@ -540,6 +541,9 @@ public class XmppConnection implements Runnable {
String resource = packet.findChild("bind").findChild("jid") String resource = packet.findChild("bind").findChild("jid")
.getContent().split("/")[1]; .getContent().split("/")[1];
account.setResource(resource); account.setResource(resource);
if (bindListener !=null) {
bindListener.onBind(account);
}
account.setStatus(Account.STATUS_ONLINE); account.setStatus(Account.STATUS_ONLINE);
if (streamFeatures.hasChild("sm")) { if (streamFeatures.hasChild("sm")) {
EnablePacket enable = new EnablePacket(); EnablePacket enable = new EnablePacket();
@ -693,6 +697,10 @@ public class XmppConnection implements Runnable {
public void setOnTLSExceptionReceivedListener(OnTLSExceptionReceived listener) { public void setOnTLSExceptionReceivedListener(OnTLSExceptionReceived listener) {
this.tlsListener = listener; this.tlsListener = listener;
} }
public void setOnBindListener(OnBindListener listener) {
this.bindListener = listener;
}
public void disconnect(boolean force) { public void disconnect(boolean force) {
changeStatus(Account.STATUS_OFFLINE); changeStatus(Account.STATUS_OFFLINE);