Use packet callbacks only for IqPackets. Removed unnecessary code
This commit is contained in:
parent
51f5b84ee4
commit
e32a927300
|
@ -803,7 +803,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
||||||
final IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET);
|
final IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET);
|
||||||
final Element query = iqPacket.query("jabber:iq:private");
|
final Element query = iqPacket.query("jabber:iq:private");
|
||||||
query.addChild("storage", "storage:bookmarks");
|
query.addChild("storage", "storage:bookmarks");
|
||||||
final PacketReceived callback = new OnIqPacketReceived() {
|
final OnIqPacketReceived callback = new OnIqPacketReceived() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onIqPacketReceived(final Account account, final IqPacket packet) {
|
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();
|
final XmppConnection connection = account.getXmppConnection();
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
connection.sendIqPacket(packet, callback);
|
connection.sendIqPacket(packet, callback);
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class XmppConnection implements Runnable {
|
||||||
private long lastConnect = 0;
|
private long lastConnect = 0;
|
||||||
private long lastSessionStarted = 0;
|
private long lastSessionStarted = 0;
|
||||||
private int attempt = 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 OnPresencePacketReceived presenceListener = null;
|
||||||
private OnJinglePacketReceived jingleListener = null;
|
private OnJinglePacketReceived jingleListener = null;
|
||||||
private OnIqPacketReceived unregisteredIqListener = null;
|
private OnIqPacketReceived unregisteredIqListener = null;
|
||||||
|
@ -444,50 +444,24 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (packetCallbacks.containsKey(packet.getId())) {
|
if (packetCallbacks.containsKey(packet.getId())) {
|
||||||
if (packetCallbacks.get(packet.getId()) instanceof OnIqPacketReceived) {
|
packetCallbacks.get(packet.getId()).onIqPacketReceived(account, packet);
|
||||||
((OnIqPacketReceived) packetCallbacks.get(packet.getId()))
|
|
||||||
.onIqPacketReceived(account, packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
packetCallbacks.remove(packet.getId());
|
packetCallbacks.remove(packet.getId());
|
||||||
} else if ((packet.getType() == IqPacket.TYPE_GET || packet
|
} else if ((packet.getType() == IqPacket.TYPE_GET || packet
|
||||||
.getType() == IqPacket.TYPE_SET)
|
.getType() == IqPacket.TYPE_SET)
|
||||||
&& this.unregisteredIqListener != null) {
|
&& this.unregisteredIqListener != null) {
|
||||||
this.unregisteredIqListener.onIqPacketReceived(account, packet);
|
this.unregisteredIqListener.onIqPacketReceived(account, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processMessage(final Tag currentTag) throws XmlPullParserException,
|
private void processMessage(final Tag currentTag) throws XmlPullParserException, IOException {
|
||||||
IOException {
|
final MessagePacket packet = (MessagePacket) processPacket(currentTag,PACKET_MESSAGE);
|
||||||
final MessagePacket packet = (MessagePacket) processPacket(currentTag,
|
this.messageListener.onMessagePacketReceived(account, packet);
|
||||||
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 processPresence(final Tag currentTag) throws XmlPullParserException,
|
private void processPresence(final Tag currentTag) throws XmlPullParserException, IOException {
|
||||||
IOException {
|
PresencePacket packet = (PresencePacket) processPacket(currentTag, PACKET_PRESENCE);
|
||||||
PresencePacket packet = (PresencePacket) processPacket(currentTag,
|
this.presenceListener.onPresencePacketReceived(account, packet);
|
||||||
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 sendStartTLS() throws IOException {
|
private void sendStartTLS() throws IOException {
|
||||||
|
@ -497,8 +471,7 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private SharedPreferences getPreferences() {
|
private SharedPreferences getPreferences() {
|
||||||
return PreferenceManager
|
return PreferenceManager.getDefaultSharedPreferences(applicationContext);
|
||||||
.getDefaultSharedPreferences(applicationContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean enableLegacySSL() {
|
private boolean enableLegacySSL() {
|
||||||
|
@ -676,7 +649,7 @@ public class XmppConnection implements Runnable {
|
||||||
final IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
|
final IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
|
||||||
iq.addChild("bind", "urn:ietf:params:xml:ns:xmpp-bind")
|
iq.addChild("bind", "urn:ietf:params:xml:ns:xmpp-bind")
|
||||||
.addChild("resource").setContent(account.getResource());
|
.addChild("resource").setContent(account.getResource());
|
||||||
this.sendUnboundIqPacket(iq, new OnIqPacketReceived() {
|
this.sendUnmodifiedIqPacket(iq, new OnIqPacketReceived() {
|
||||||
@Override
|
@Override
|
||||||
public void onIqPacketReceived(final Account account, final IqPacket packet) {
|
public void onIqPacketReceived(final Account account, final IqPacket packet) {
|
||||||
final Element bind = packet.findChild("bind");
|
final Element bind = packet.findChild("bind");
|
||||||
|
@ -719,12 +692,10 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (this.streamFeatures.hasChild("session")) {
|
if (this.streamFeatures.hasChild("session")) {
|
||||||
Log.d(Config.LOGTAG, account.getJid().toBareJid()
|
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending deprecated session");
|
||||||
+ ": sending deprecated session");
|
|
||||||
final IqPacket startSession = new IqPacket(IqPacket.TYPE_SET);
|
final IqPacket startSession = new IqPacket(IqPacket.TYPE_SET);
|
||||||
startSession.addChild("session",
|
startSession.addChild("session","urn:ietf:params:xml:ns:xmpp-session");
|
||||||
"urn:ietf:params:xml:ns:xmpp-session");
|
this.sendUnmodifiedIqPacket(startSession, null);
|
||||||
this.sendUnboundIqPacket(startSession, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -845,50 +816,45 @@ public class XmppConnection implements Runnable {
|
||||||
return new BigInteger(50, mXmppConnectionService.getRNG()).toString(32);
|
return new BigInteger(50, mXmppConnectionService.getRNG()).toString(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendIqPacket(final IqPacket packet, final PacketReceived callback) {
|
public void sendIqPacket(final IqPacket packet, final OnIqPacketReceived callback) {
|
||||||
if (packet.getId() == null) {
|
|
||||||
final String id = nextRandomId();
|
|
||||||
packet.setAttribute("id", id);
|
|
||||||
}
|
|
||||||
packet.setFrom(account.getJid());
|
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) {
|
if (packet.getId() == null) {
|
||||||
final String id = nextRandomId();
|
final String id = nextRandomId();
|
||||||
packet.setAttribute("id", id);
|
packet.setAttribute("id", id);
|
||||||
}
|
}
|
||||||
this.sendPacket(packet, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessagePacket(final MessagePacket packet) {
|
|
||||||
this.sendPacket(packet, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendPresencePacket(final PresencePacket packet) {
|
|
||||||
this.sendPacket(packet, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void sendPacket(final AbstractStanza packet, final PacketReceived callback) {
|
|
||||||
if (packet.getName().equals("iq") || packet.getName().equals("message")
|
|
||||||
|| packet.getName().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);
|
|
||||||
this.messageReceipts.put(stanzasSent, packet.getId());
|
|
||||||
tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion));
|
|
||||||
}
|
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
if (packet.getId() == null) {
|
if (packet.getId() == null) {
|
||||||
packet.setId(nextRandomId());
|
packet.setId(nextRandomId());
|
||||||
}
|
}
|
||||||
packetCallbacks.put(packet.getId(), callback);
|
packetCallbacks.put(packet.getId(), callback);
|
||||||
}
|
}
|
||||||
|
this.sendPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessagePacket(final MessagePacket packet) {
|
||||||
|
this.sendPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendPresencePacket(final PresencePacket packet) {
|
||||||
|
this.sendPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
this.messageReceipts.put(stanzasSent, packet.getId());
|
||||||
|
tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPing() {
|
public void sendPing() {
|
||||||
|
@ -1044,11 +1010,11 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendActive() {
|
public void sendActive() {
|
||||||
this.sendPacket(new ActivePacket(), null);
|
this.sendPacket(new ActivePacket());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendInactive() {
|
public void sendInactive() {
|
||||||
this.sendPacket(new InactivePacket(), null);
|
this.sendPacket(new InactivePacket());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Features {
|
public class Features {
|
||||||
|
|
Loading…
Reference in a new issue