From 45bd0449fb7f9fa8d09b2556a6cb2c8ff3c79d1e Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sun, 5 Oct 2014 10:46:31 +0200 Subject: [PATCH] sending initial ping before going online after login/resume to ensure that all presences and messages have been loaded --- .../conversations/xmpp/XmppConnection.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 76cfa6037..07cd2b45c 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -311,7 +311,8 @@ public class XmppConnection implements Runnable { } catch (NumberFormatException e) { } - changeStatus(Account.STATUS_ONLINE); + sendInitialPing(); + } else if (nextTag.isStart("r")) { tagReader.readElement(nextTag); AckPacket ack = new AckPacket(this.stanzasReceived, smVersion); @@ -351,6 +352,21 @@ public class XmppConnection implements Runnable { } } } + + private void sendInitialPing() { + Log.d(Config.LOGTAG,account.getJid()+": sending intial ping"); + IqPacket iq = new IqPacket(IqPacket.TYPE_GET); + iq.setFrom(account.getFullJid()); + iq.addChild("ping", "urn:xmpp:ping"); + this.sendIqPacket(iq, new OnIqPacketReceived() { + + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + Log.d(Config.LOGTAG,account.getJid()+": online with resource "+account.getResource()); + changeStatus(Account.STATUS_ONLINE); + } + }); + } private Element processPacket(Tag currentTag, int packetType) throws XmlPullParserException, IOException { @@ -681,7 +697,7 @@ public class XmppConnection implements Runnable { if (bindListener != null) { bindListener.onBind(account); } - changeStatus(Account.STATUS_ONLINE); + sendInitialPing(); } else { disconnect(true); }