aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Gultsch <inputmice@siacs.eu>2015-01-04 12:09:39 +0100
committerDaniel Gultsch <inputmice@siacs.eu>2015-01-04 12:09:39 +0100
commite32a927300a96fc59adcabb2ebc16318e67de226 (patch)
tree35b282c099bf3ef507c63446840eead61e99b93c /src
parent51f5b84ee4188321d6d0bc954e69680aeb44845c (diff)
Use packet callbacks only for IqPackets. Removed unnecessary code
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java4
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java104
2 files changed, 37 insertions, 71 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 6bdc55a1..04fc04d3 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -803,7 +803,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
final IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET);
final Element query = iqPacket.query("jabber:iq:private");
query.addChild("storage", "storage:bookmarks");
- final PacketReceived callback = new OnIqPacketReceived() {
+ final OnIqPacketReceived callback = new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
@@ -2090,7 +2090,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
- public void sendIqPacket(final Account account, final IqPacket packet, final PacketReceived callback) {
+ public void sendIqPacket(final Account account, final IqPacket packet, final OnIqPacketReceived callback) {
final XmppConnection connection = account.getXmppConnection();
if (connection != null) {
connection.sendIqPacket(packet, callback);
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index f7f0c346..ff3210a4 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -104,7 +104,7 @@ public class XmppConnection implements Runnable {
private long lastConnect = 0;
private long lastSessionStarted = 0;
private int attempt = 0;
- private final Map<String, PacketReceived> packetCallbacks = new Hashtable<>();
+ private final Map<String, OnIqPacketReceived> packetCallbacks = new Hashtable<>();
private OnPresencePacketReceived presenceListener = null;
private OnJinglePacketReceived jingleListener = null;
private OnIqPacketReceived unregisteredIqListener = null;
@@ -444,50 +444,24 @@ public class XmppConnection implements Runnable {
}
} else {
if (packetCallbacks.containsKey(packet.getId())) {
- if (packetCallbacks.get(packet.getId()) instanceof OnIqPacketReceived) {
- ((OnIqPacketReceived) packetCallbacks.get(packet.getId()))
- .onIqPacketReceived(account, packet);
- }
-
+ packetCallbacks.get(packet.getId()).onIqPacketReceived(account, packet);
packetCallbacks.remove(packet.getId());
} else if ((packet.getType() == IqPacket.TYPE_GET || packet
.getType() == IqPacket.TYPE_SET)
&& this.unregisteredIqListener != null) {
this.unregisteredIqListener.onIqPacketReceived(account, packet);
- }
+ }
}
}
- private void processMessage(final Tag currentTag) throws XmlPullParserException,
- IOException {
- final MessagePacket packet = (MessagePacket) processPacket(currentTag,
- PACKET_MESSAGE);
- final String id = packet.getAttribute("id");
- if ((id != null) && (packetCallbacks.containsKey(id))) {
- if (packetCallbacks.get(id) instanceof OnMessagePacketReceived) {
- ((OnMessagePacketReceived) packetCallbacks.get(id))
- .onMessagePacketReceived(account, packet);
- }
- packetCallbacks.remove(id);
- } else if (this.messageListener != null) {
- this.messageListener.onMessagePacketReceived(account, packet);
- }
+ private void processMessage(final Tag currentTag) throws XmlPullParserException, IOException {
+ final MessagePacket packet = (MessagePacket) processPacket(currentTag,PACKET_MESSAGE);
+ this.messageListener.onMessagePacketReceived(account, packet);
}
- private void processPresence(final Tag currentTag) throws XmlPullParserException,
- IOException {
- PresencePacket packet = (PresencePacket) processPacket(currentTag,
- PACKET_PRESENCE);
- final String id = packet.getAttribute("id");
- if ((id != null) && (packetCallbacks.containsKey(id))) {
- if (packetCallbacks.get(id) instanceof OnPresencePacketReceived) {
- ((OnPresencePacketReceived) packetCallbacks.get(id))
- .onPresencePacketReceived(account, packet);
- }
- packetCallbacks.remove(id);
- } else if (this.presenceListener != null) {
- this.presenceListener.onPresencePacketReceived(account, packet);
- }
+ private void processPresence(final Tag currentTag) throws XmlPullParserException, IOException {
+ PresencePacket packet = (PresencePacket) processPacket(currentTag, PACKET_PRESENCE);
+ this.presenceListener.onPresencePacketReceived(account, packet);
}
private void sendStartTLS() throws IOException {
@@ -497,8 +471,7 @@ public class XmppConnection implements Runnable {
}
private SharedPreferences getPreferences() {
- return PreferenceManager
- .getDefaultSharedPreferences(applicationContext);
+ return PreferenceManager.getDefaultSharedPreferences(applicationContext);
}
private boolean enableLegacySSL() {
@@ -676,7 +649,7 @@ public class XmppConnection implements Runnable {
final IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
iq.addChild("bind", "urn:ietf:params:xml:ns:xmpp-bind")
.addChild("resource").setContent(account.getResource());
- this.sendUnboundIqPacket(iq, new OnIqPacketReceived() {
+ this.sendUnmodifiedIqPacket(iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
final Element bind = packet.findChild("bind");
@@ -719,12 +692,10 @@ public class XmppConnection implements Runnable {
}
});
if (this.streamFeatures.hasChild("session")) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid()
- + ": sending deprecated session");
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending deprecated session");
final IqPacket startSession = new IqPacket(IqPacket.TYPE_SET);
- startSession.addChild("session",
- "urn:ietf:params:xml:ns:xmpp-session");
- this.sendUnboundIqPacket(startSession, null);
+ startSession.addChild("session","urn:ietf:params:xml:ns:xmpp-session");
+ this.sendUnmodifiedIqPacket(startSession, null);
}
}
@@ -845,49 +816,44 @@ public class XmppConnection implements Runnable {
return new BigInteger(50, mXmppConnectionService.getRNG()).toString(32);
}
- public void sendIqPacket(final IqPacket packet, final PacketReceived callback) {
- if (packet.getId() == null) {
- final String id = nextRandomId();
- packet.setAttribute("id", id);
- }
+ public void sendIqPacket(final IqPacket packet, final OnIqPacketReceived callback) {
packet.setFrom(account.getJid());
- this.sendPacket(packet, callback);
+ this.sendUnmodifiedIqPacket(packet,callback);
+
}
- public void sendUnboundIqPacket(final IqPacket packet, final PacketReceived callback) {
+ private void sendUnmodifiedIqPacket(final IqPacket packet, final OnIqPacketReceived callback) {
if (packet.getId() == null) {
final String id = nextRandomId();
packet.setAttribute("id", id);
}
- this.sendPacket(packet, callback);
+ if (callback != null) {
+ if (packet.getId() == null) {
+ packet.setId(nextRandomId());
+ }
+ packetCallbacks.put(packet.getId(), callback);
+ }
+ this.sendPacket(packet);
}
public void sendMessagePacket(final MessagePacket packet) {
- this.sendPacket(packet, null);
+ this.sendPacket(packet);
}
public void sendPresencePacket(final PresencePacket packet) {
- this.sendPacket(packet, null);
+ this.sendPacket(packet);
}
- private synchronized void sendPacket(final AbstractStanza packet, final PacketReceived callback) {
- if (packet.getName().equals("iq") || packet.getName().equals("message")
- || packet.getName().equals("presence")) {
+ private synchronized void sendPacket(final AbstractStanza packet) {
+ final String name = packet.getName();
+ if (name.equals("iq") || name.equals("message") || name.equals("presence")) {
++stanzasSent;
- }
+ }
tagWriter.writeStanzaAsync(packet);
- if (packet instanceof MessagePacket && packet.getId() != null
- && this.streamId != null) {
- Log.d(Config.LOGTAG, "request delivery report for stanza "
- + stanzasSent);
+ if (packet instanceof MessagePacket && packet.getId() != null && this.streamId != null) {
+ Log.d(Config.LOGTAG, "request delivery report for stanza " + stanzasSent);
this.messageReceipts.put(stanzasSent, packet.getId());
tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion));
- }
- if (callback != null) {
- if (packet.getId() == null) {
- packet.setId(nextRandomId());
- }
- packetCallbacks.put(packet.getId(), callback);
}
}
@@ -1044,11 +1010,11 @@ public class XmppConnection implements Runnable {
}
public void sendActive() {
- this.sendPacket(new ActivePacket(), null);
+ this.sendPacket(new ActivePacket());
}
public void sendInactive() {
- this.sendPacket(new InactivePacket(), null);
+ this.sendPacket(new InactivePacket());
}
public class Features {