aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs')
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java49
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java89
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractAcknowledgeableStanza.java17
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java8
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java2
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java2
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/stanzas/PresencePacket.java2
7 files changed, 83 insertions, 86 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 36d6cd49..b08a71bf 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -150,13 +150,23 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
@Override
public void onBind(final Account account) {
account.getRoster().clearPresences();
- account.pendingConferenceJoins.clear();
- account.pendingConferenceLeaves.clear();
fetchRosterFromServer(account);
fetchBookmarks(account);
sendPresence(account);
connectMultiModeConversations(account);
- updateConversationUi();
+ for (Conversation conversation : account.pendingConferenceLeaves) {
+ leaveMuc(conversation);
+ }
+ account.pendingConferenceLeaves.clear();
+ for (Conversation conversation : account.pendingConferenceJoins) {
+ joinMuc(conversation);
+ }
+ account.pendingConferenceJoins.clear();
+ mMessageArchiveService.executePendingQueries(account);
+ mJingleConnectionManager.cancelInTransmission();
+ syncDirtyContacts(account);
+ account.getAxolotlService().publishOwnDeviceIdIfNeeded();
+ account.getAxolotlService().publishBundlesIfNeeded();
}
};
private final OnMessageAcknowledged mOnMessageAcknowledgedListener = new OnMessageAcknowledged() {
@@ -248,14 +258,15 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
mOnAccountUpdate.onAccountUpdate();
}
if (account.getStatus() == Account.State.ONLINE) {
- for (Conversation conversation : account.pendingConferenceLeaves) {
- leaveMuc(conversation);
- }
- for (Conversation conversation : account.pendingConferenceJoins) {
- joinMuc(conversation);
+ if (connection != null && connection.getFeatures().csi()) {
+ if (checkListeners()) {
+ Log.d(Config.LOGTAG, account.getJid().toBareJid()+ " sending csi//inactive");
+ connection.sendInactive();
+ } else {
+ Log.d(Config.LOGTAG, account.getJid().toBareJid()+ " sending csi//active");
+ connection.sendActive();
+ }
}
- mMessageArchiveService.executePendingQueries(account);
- mJingleConnectionManager.cancelInTransmission();
List<Conversation> conversations = getConversations();
for (Conversation conversation : conversations) {
if (conversation.getAccount() == account) {
@@ -263,21 +274,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
sendUnsentMessages(conversation);
}
}
- if (connection != null && connection.getFeatures().csi()) {
- if (checkListeners()) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid()
- + " sending csi//inactive");
- connection.sendInactive();
- } else {
- Log.d(Config.LOGTAG, account.getJid().toBareJid()
- + " sending csi//active");
- connection.sendActive();
- }
- }
- syncDirtyContacts(account);
- account.getAxolotlService().publishOwnDeviceIdIfNeeded();
- account.getAxolotlService().publishBundlesIfNeeded();
-
scheduleWakeUpCall(Config.PING_MAX_INTERVAL, account.getUuid().hashCode());
} else if (account.getStatus() == Account.State.OFFLINE) {
resetSendingToWaiting(account);
@@ -860,7 +856,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching roster");
}
iqPacket.query(Xmlns.ROSTER).setAttribute("ver", account.getRosterVersion());
- sendIqPacket(account,iqPacket,mIqParser);
+ sendIqPacket(account, iqPacket, mIqParser);
}
public void fetchBookmarks(final Account account) {
@@ -1482,6 +1478,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
+
public void joinMuc(Conversation conversation) {
Account account = conversation.getAccount();
account.pendingConferenceJoins.remove(conversation);
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index 604325be..37685832 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -48,6 +48,7 @@ import eu.siacs.conversations.crypto.sasl.Plain;
import eu.siacs.conversations.crypto.sasl.SaslMechanism;
import eu.siacs.conversations.crypto.sasl.ScramSha1;
import eu.siacs.conversations.entities.Account;
+import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.generator.IqGenerator;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper;
@@ -61,6 +62,7 @@ import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.jingle.OnJinglePacketReceived;
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
+import eu.siacs.conversations.xmpp.stanzas.AbstractAcknowledgeableStanza;
import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
@@ -90,7 +92,7 @@ public class XmppConnection implements Runnable {
private String streamId = null;
private int smVersion = 3;
- private final SparseArray<String> mStanzaReceipts = new SparseArray<>();
+ private final SparseArray<AbstractAcknowledgeableStanza> mStanzaQueue = new SparseArray<>();
private int stanzasReceived = 0;
private int stanzasSent = 0;
@@ -314,7 +316,7 @@ public class XmppConnection implements Runnable {
+ ") enabled (resumable)");
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString()
- + ": stream managment(" + smVersion + ") enabled");
+ + ": stream management(" + smVersion + ") enabled");
}
this.lastSessionStarted = SystemClock.elapsedRealtime();
this.stanzasReceived = 0;
@@ -334,22 +336,26 @@ public class XmppConnection implements Runnable {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": session resumed");
}
acknowledgeStanzaUpTo(serverCount);
- ArrayList<IqPacket> failedIqPackets = new ArrayList<>();
- for(int i = 0; i < this.mStanzaReceipts.size(); ++i) {
- String id = mStanzaReceipts.valueAt(i);
- Pair<IqPacket,OnIqPacketReceived> pair = id == null ? null : this.packetCallbacks.get(id);
- if (pair != null) {
- failedIqPackets.add(pair.first);
- }
+ ArrayList<AbstractAcknowledgeableStanza> failedStanzas = new ArrayList<>();
+ for(int i = 0; i < this.mStanzaQueue.size(); ++i) {
+ failedStanzas.add(mStanzaQueue.valueAt(i));
}
- mStanzaReceipts.clear();
- Log.d(Config.LOGTAG,"resending "+failedIqPackets.size()+" iq stanza");
- for(IqPacket packet : failedIqPackets) {
- sendUnmodifiedIqPacket(packet,null);
+ mStanzaQueue.clear();
+ Log.d(Config.LOGTAG,"resending "+failedStanzas.size()+" stanzas");
+ for(AbstractAcknowledgeableStanza packet : failedStanzas) {
+ if (packet instanceof MessagePacket) {
+ MessagePacket message = (MessagePacket) packet;
+ mXmppConnectionService.markMessage(account,
+ message.getTo().toBareJid(),
+ message.getId(),
+ Message.STATUS_UNSEND);
+ }
+ sendPacket(packet);
}
} catch (final NumberFormatException ignored) {
}
- sendInitialPing();
+ Log.d(Config.LOGTAG, account.getJid().toBareJid()+ ": online with resource " + account.getResource());
+ changeStatus(Account.State.ONLINE);
} else if (nextTag.isStart("r")) {
tagReader.readElement(nextTag);
if (Config.EXTENDED_SM_LOGGING) {
@@ -391,39 +397,22 @@ public class XmppConnection implements Runnable {
}
private void acknowledgeStanzaUpTo(int serverCount) {
- for (int i = 0; i < mStanzaReceipts.size(); ++i) {
- if (serverCount >= mStanzaReceipts.keyAt(i)) {
+ for (int i = 0; i < mStanzaQueue.size(); ++i) {
+ if (serverCount >= mStanzaQueue.keyAt(i)) {
if (Config.EXTENDED_SM_LOGGING) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server acknowledged stanza #" + mStanzaReceipts.keyAt(i));
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server acknowledged stanza #" + mStanzaQueue.keyAt(i));
}
- String id = mStanzaReceipts.valueAt(i);
- if (acknowledgedListener != null) {
- acknowledgedListener.onMessageAcknowledged(account, id);
+ AbstractAcknowledgeableStanza stanza = mStanzaQueue.valueAt(i);
+ if (stanza instanceof MessagePacket && acknowledgedListener != null) {
+ MessagePacket packet = (MessagePacket) stanza;
+ acknowledgedListener.onMessageAcknowledged(account, packet.getId());
}
- mStanzaReceipts.removeAt(i);
+ mStanzaQueue.removeAt(i);
i--;
}
}
}
- private void sendInitialPing() {
- Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": sending intial ping");
- final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
- iq.setFrom(account.getJid());
- iq.addChild("ping", "urn:xmpp:ping");
- this.sendIqPacket(iq, new OnIqPacketReceived() {
- @Override
- public void onIqPacketReceived(final Account account, final IqPacket packet) {
- if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": online with resource " + account.getResource());
- changeStatus(Account.State.ONLINE);
- } else {
- Log.d(Config.LOGTAG,account.getJid().toBareJid()+": initial ping failed");
- }
- }
- });
- }
-
private Element processPacket(final Tag currentTag, final int packetType)
throws XmlPullParserException, IOException {
Element element;
@@ -786,7 +775,7 @@ public class XmppConnection implements Runnable {
final EnablePacket enable = new EnablePacket(smVersion);
tagWriter.writeStanzaAsync(enable);
stanzasSent = 0;
- mStanzaReceipts.clear();
+ mStanzaQueue.clear();
}
features.carbonsEnabled = false;
features.blockListRequested = false;
@@ -794,10 +783,11 @@ public class XmppConnection implements Runnable {
sendServiceDiscoveryInfo(account.getServer());
sendServiceDiscoveryInfo(account.getJid().toBareJid());
sendServiceDiscoveryItems(account.getServer());
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": online with resource " + account.getResource());
+ changeStatus(Account.State.ONLINE);
if (bindListener != null) {
bindListener.onBind(account);
}
- sendInitialPing();
}
private void sendServiceDiscoveryInfo(final Jid jid) {
@@ -959,16 +949,17 @@ public class XmppConnection implements Runnable {
return;
}
final String name = packet.getName();
- if (name.equals("iq") || name.equals("message") || name.equals("presence")) {
- ++stanzasSent;
- }
tagWriter.writeStanzaAsync(packet);
- if ((packet instanceof MessagePacket || packet instanceof IqPacket) && packet.getId() != null && this.streamId != null) {
- if (Config.EXTENDED_SM_LOGGING) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": requesting ack for stanza #" + stanzasSent);
+ if (packet instanceof AbstractAcknowledgeableStanza) {
+ AbstractAcknowledgeableStanza stanza = (AbstractAcknowledgeableStanza) packet;
+ ++stanzasSent;
+ this.mStanzaQueue.put(stanzasSent, stanza);
+ if (stanza instanceof MessagePacket && stanza.getId() != null && this.streamId != null) {
+ if (Config.EXTENDED_SM_LOGGING) {
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": requesting ack for message stanza #" + stanzasSent);
+ }
+ tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion));
}
- this.mStanzaReceipts.put(stanzasSent, packet.getId());
- tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion));
}
}
diff --git a/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractAcknowledgeableStanza.java b/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractAcknowledgeableStanza.java
new file mode 100644
index 00000000..a5de4a84
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractAcknowledgeableStanza.java
@@ -0,0 +1,17 @@
+package eu.siacs.conversations.xmpp.stanzas;
+
+abstract public class AbstractAcknowledgeableStanza extends AbstractStanza {
+
+ protected AbstractAcknowledgeableStanza(String name) {
+ super(name);
+ }
+
+
+ public String getId() {
+ return this.getAttribute("id");
+ }
+
+ public void setId(final String id) {
+ setAttribute("id", id);
+ }
+}
diff --git a/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java b/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java
index bd706b57..a6144df2 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java
@@ -18,10 +18,6 @@ public class AbstractStanza extends Element {
return getAttributeAsJid("from");
}
- public String getId() {
- return this.getAttribute("id");
- }
-
public void setTo(final Jid to) {
if (to != null) {
setAttribute("to", to.toString());
@@ -34,10 +30,6 @@ public class AbstractStanza extends Element {
}
}
- public void setId(final String id) {
- setAttribute("id", id);
- }
-
public boolean fromServer(final Account account) {
return getFrom() == null
|| getFrom().equals(account.getServer())
diff --git a/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java b/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java
index 49b27408..4d16f2e5 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java
@@ -2,7 +2,7 @@ package eu.siacs.conversations.xmpp.stanzas;
import eu.siacs.conversations.xml.Element;
-public class IqPacket extends AbstractStanza {
+public class IqPacket extends AbstractAcknowledgeableStanza {
public enum TYPE {
ERROR,
diff --git a/src/main/java/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java b/src/main/java/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java
index 6b690912..941b4b5f 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java
@@ -5,7 +5,7 @@ import android.util.Pair;
import eu.siacs.conversations.parser.AbstractParser;
import eu.siacs.conversations.xml.Element;
-public class MessagePacket extends AbstractStanza {
+public class MessagePacket extends AbstractAcknowledgeableStanza {
public static final int TYPE_CHAT = 0;
public static final int TYPE_NORMAL = 2;
public static final int TYPE_GROUPCHAT = 3;
diff --git a/src/main/java/eu/siacs/conversations/xmpp/stanzas/PresencePacket.java b/src/main/java/eu/siacs/conversations/xmpp/stanzas/PresencePacket.java
index 7ea32099..c321498d 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/stanzas/PresencePacket.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/stanzas/PresencePacket.java
@@ -1,6 +1,6 @@
package eu.siacs.conversations.xmpp.stanzas;
-public class PresencePacket extends AbstractStanza {
+public class PresencePacket extends AbstractAcknowledgeableStanza {
public PresencePacket() {
super("presence");