aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/xmpp
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-02 16:05:15 +0100
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-02 16:05:15 +0100
commitd365bbe480bdd26a042b425c45227785ab4fbf51 (patch)
tree4389b79b60d89724fd74eebf5674834888e9b436 /src/de/gultsch/chat/xmpp
parent53d9c9997a508985f0e19aba928bfa25c80ba23e (diff)
fetching roster. fixed sending messages as type chat
Diffstat (limited to 'src/de/gultsch/chat/xmpp')
-rw-r--r--src/de/gultsch/chat/xmpp/MessagePacket.java32
-rw-r--r--src/de/gultsch/chat/xmpp/XmppConnection.java13
2 files changed, 45 insertions, 0 deletions
diff --git a/src/de/gultsch/chat/xmpp/MessagePacket.java b/src/de/gultsch/chat/xmpp/MessagePacket.java
index 313fb355..de486a5d 100644
--- a/src/de/gultsch/chat/xmpp/MessagePacket.java
+++ b/src/de/gultsch/chat/xmpp/MessagePacket.java
@@ -3,6 +3,8 @@ package de.gultsch.chat.xmpp;
import de.gultsch.chat.xml.Element;
public class MessagePacket extends Element {
+ public static final int TYPE_CHAT = 0;
+
private MessagePacket(String name) {
super(name);
}
@@ -10,6 +12,10 @@ public class MessagePacket extends Element {
public MessagePacket() {
super("message");
}
+
+ public String getTo() {
+ return getAttribute("to");
+ }
public String getFrom() {
return getAttribute("from");
@@ -18,4 +24,30 @@ public class MessagePacket extends Element {
public String getBody() {
return this.findChild("body").getContent();
}
+
+ public void setTo(String to) {
+ setAttribute("to", to);
+ }
+
+ public void setFrom(String from) {
+ setAttribute("from",from);
+ }
+
+ public void setBody(String text) {
+ Element body = new Element("body");
+ body.setContent(text);
+ this.children.add(body);
+ }
+
+ public void setType(int type) {
+ switch (type) {
+ case TYPE_CHAT:
+ this.setAttribute("type","chat");
+ break;
+
+ default:
+ this.setAttribute("type","chat");
+ break;
+ }
+ }
}
diff --git a/src/de/gultsch/chat/xmpp/XmppConnection.java b/src/de/gultsch/chat/xmpp/XmppConnection.java
index 441e4b2d..f82c401e 100644
--- a/src/de/gultsch/chat/xmpp/XmppConnection.java
+++ b/src/de/gultsch/chat/xmpp/XmppConnection.java
@@ -52,6 +52,8 @@ public class XmppConnection implements Runnable {
private OnPresencePacketReceived presenceListener = null;
private OnIqPacketReceived unregisteredIqListener = null;
private OnMessagePacketReceived messageListener = null;
+
+ private String resource = null;
public XmppConnection(Account account, PowerManager pm) {
this.account = account;
@@ -96,6 +98,12 @@ public class XmppConnection implements Runnable {
public void run() {
while(shouldReConnect) {
connect();
+ try {
+ Thread.sleep(30000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
}
@@ -260,7 +268,9 @@ public class XmppConnection implements Runnable {
this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
+ resource = packet.findChild("bind").findChild("jid").getContent().split("/")[1];
Log.d(LOGTAG,"answer for our bind was: "+packet.toString());
+ Log.d(LOGTAG,"new resource is "+resource);
}
});
}
@@ -291,15 +301,18 @@ public class XmppConnection implements Runnable {
if (callback != null) {
iqPacketCallbacks.put(id, callback);
}
+ tagWriter.flush();
Log.d(LOGTAG,"sending: "+packet.toString());
}
public void sendMessagePacket(MessagePacket packet) throws IOException {
tagWriter.writeElement(packet);
+ tagWriter.flush();
}
public void sendPresencePacket(PresencePacket packet) throws IOException {
tagWriter.writeElement(packet);
+ tagWriter.flush();
}
public void setOnMessagePacketReceivedListener(OnMessagePacketReceived listener) {