aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2014-03-03 05:01:02 +0100
committerDaniel Gultsch <daniel@gultsch.de>2014-03-03 05:01:02 +0100
commitc609eefefac5097c7c40a9f1b8741e9634da316f (patch)
tree53363dfbab46d84e81b8b95f49e586374dc358f0 /src/eu/siacs/conversations/xmpp
parent2ab6cb0ada6370e6ea83a73e0a6a39ea3ff90715 (diff)
api changes. muc options
Diffstat (limited to 'src/eu/siacs/conversations/xmpp')
-rw-r--r--src/eu/siacs/conversations/xmpp/OnIqPacketReceived.java2
-rw-r--r--src/eu/siacs/conversations/xmpp/OnMessagePacketReceived.java2
-rw-r--r--src/eu/siacs/conversations/xmpp/OnPresencePacketReceived.java2
-rw-r--r--src/eu/siacs/conversations/xmpp/PacketReceived.java5
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java57
5 files changed, 52 insertions, 16 deletions
diff --git a/src/eu/siacs/conversations/xmpp/OnIqPacketReceived.java b/src/eu/siacs/conversations/xmpp/OnIqPacketReceived.java
index 4e09282c..54909f88 100644
--- a/src/eu/siacs/conversations/xmpp/OnIqPacketReceived.java
+++ b/src/eu/siacs/conversations/xmpp/OnIqPacketReceived.java
@@ -2,6 +2,6 @@ package eu.siacs.conversations.xmpp;
import eu.siacs.conversations.entities.Account;
-public interface OnIqPacketReceived {
+public interface OnIqPacketReceived extends PacketReceived {
public void onIqPacketReceived(Account account, IqPacket packet);
}
diff --git a/src/eu/siacs/conversations/xmpp/OnMessagePacketReceived.java b/src/eu/siacs/conversations/xmpp/OnMessagePacketReceived.java
index 3d169300..6f0b387d 100644
--- a/src/eu/siacs/conversations/xmpp/OnMessagePacketReceived.java
+++ b/src/eu/siacs/conversations/xmpp/OnMessagePacketReceived.java
@@ -2,6 +2,6 @@ package eu.siacs.conversations.xmpp;
import eu.siacs.conversations.entities.Account;
-public interface OnMessagePacketReceived {
+public interface OnMessagePacketReceived extends PacketReceived {
public void onMessagePacketReceived(Account account, MessagePacket packet);
}
diff --git a/src/eu/siacs/conversations/xmpp/OnPresencePacketReceived.java b/src/eu/siacs/conversations/xmpp/OnPresencePacketReceived.java
index 058d8be9..55672fff 100644
--- a/src/eu/siacs/conversations/xmpp/OnPresencePacketReceived.java
+++ b/src/eu/siacs/conversations/xmpp/OnPresencePacketReceived.java
@@ -2,6 +2,6 @@ package eu.siacs.conversations.xmpp;
import eu.siacs.conversations.entities.Account;
-public interface OnPresencePacketReceived {
+public interface OnPresencePacketReceived extends PacketReceived {
public void onPresencePacketReceived(Account account, PresencePacket packet);
}
diff --git a/src/eu/siacs/conversations/xmpp/PacketReceived.java b/src/eu/siacs/conversations/xmpp/PacketReceived.java
new file mode 100644
index 00000000..d9f42459
--- /dev/null
+++ b/src/eu/siacs/conversations/xmpp/PacketReceived.java
@@ -0,0 +1,5 @@
+package eu.siacs.conversations.xmpp;
+
+abstract interface PacketReceived {
+
+}
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java
index 4583c145..6e65e1ed 100644
--- a/src/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -53,7 +53,7 @@ public class XmppConnection implements Runnable {
private static final int PACKET_MESSAGE = 1;
private static final int PACKET_PRESENCE = 2;
- private Hashtable<String, OnIqPacketReceived> iqPacketCallbacks = new Hashtable<String, OnIqPacketReceived>();
+ private Hashtable<String, PacketReceived> packetCallbacks = new Hashtable<String, PacketReceived>();
private OnPresencePacketReceived presenceListener = null;
private OnIqPacketReceived unregisteredIqListener = null;
private OnMessagePacketReceived messageListener = null;
@@ -212,24 +212,33 @@ public class XmppConnection implements Runnable {
return element;
}
- private IqPacket processIq(Tag currentTag) throws XmlPullParserException,
+ private void processIq(Tag currentTag) throws XmlPullParserException,
IOException {
IqPacket packet = (IqPacket) processPacket(currentTag, PACKET_IQ);
- if (iqPacketCallbacks.containsKey(packet.getId())) {
- iqPacketCallbacks.get(packet.getId()).onIqPacketReceived(account,
- packet);
- iqPacketCallbacks.remove(packet.getId());
+ if (packetCallbacks.containsKey(packet.getId())) {
+ if (packetCallbacks.get(packet.getId()) instanceof OnIqPacketReceived) {
+ ((OnIqPacketReceived) packetCallbacks.get(packet.getId())).onIqPacketReceived(account,
+ packet);
+ }
+
+ packetCallbacks.remove(packet.getId());
} else if (this.unregisteredIqListener != null) {
this.unregisteredIqListener.onIqPacketReceived(account, packet);
}
- return packet;
}
private void processMessage(Tag currentTag) throws XmlPullParserException,
IOException {
MessagePacket packet = (MessagePacket) processPacket(currentTag,
PACKET_MESSAGE);
- if (this.messageListener != null) {
+ 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);
}
}
@@ -238,7 +247,14 @@ public class XmppConnection implements Runnable {
IOException {
PresencePacket packet = (PresencePacket) processPacket(currentTag,
PACKET_PRESENCE);
- if (this.presenceListener != null) {
+ 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);
}
}
@@ -405,19 +421,34 @@ public class XmppConnection implements Runnable {
packet.setAttribute("id", id);
tagWriter.writeElement(packet);
if (callback != null) {
- iqPacketCallbacks.put(id, callback);
+ packetCallbacks.put(id, callback);
}
- //Log.d(LOGTAG, account.getJid() + ": sending: " + packet.toString());
}
public void sendMessagePacket(MessagePacket packet) {
- Log.d(LOGTAG,"sending message packet "+packet.toString());
+ this.sendMessagePacket(packet, null);
+ }
+
+ public void sendMessagePacket(MessagePacket packet, OnMessagePacketReceived callback) {
+ String id = nextRandomId();
+ packet.setAttribute("id", id);
tagWriter.writeElement(packet);
+ if (callback != null) {
+ packetCallbacks.put(id, callback);
+ }
}
public void sendPresencePacket(PresencePacket packet) {
+ this.sendPresencePacket(packet, null);
+ }
+
+ public void sendPresencePacket(PresencePacket packet, OnPresencePacketReceived callback) {
+ String id = nextRandomId();
+ packet.setAttribute("id", id);
tagWriter.writeElement(packet);
- Log.d(LOGTAG, account.getJid() + ": sending: " + packet.toString());
+ if (callback != null) {
+ packetCallbacks.put(id, callback);
+ }
}
public void setOnMessagePacketReceivedListener(