aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/com/juick/jabber/ws/XMPPConnection.java48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/com/juick/jabber/ws/XMPPConnection.java b/src/com/juick/jabber/ws/XMPPConnection.java
index 0eef26bf..a8af8c44 100644
--- a/src/com/juick/jabber/ws/XMPPConnection.java
+++ b/src/com/juick/jabber/ws/XMPPConnection.java
@@ -62,7 +62,16 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
JuickMessage jmsg = (JuickMessage) msg.getChild(JuickMessage.XMLNS);
if (jmsg != null) {
System.err.println("MID=" + jmsg.MID + "; RID=" + jmsg.RID);
- if (jmsg.RID == 0) {
+ if (jmsg.MID == 0) {
+ int uid_to = 0;
+ try {
+ uid_to = Integer.parseInt(msg.to.Username);
+ } catch (Exception e) {
+ }
+ if (uid_to > 0) {
+ onJuickPM(uid_to, jmsg);
+ }
+ } else if (jmsg.RID == 0) {
onJuickMessagePost(jmsg);
} else {
onJuickMessageReply(jmsg);
@@ -70,6 +79,43 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message.
}
}
+ private void onJuickPM(int uid_to, com.juick.Message jmsg) {
+ String json = com.juick.json.Message.toJSON(jmsg).toString();
+ ByteBuffer jsonbytes = Charset.forName("UTF-8").encode(json);
+ ByteBuffer bbMsg = ByteBuffer.allocate(10240);
+ bbMsg.put((byte) 0x81);
+ if (jsonbytes.limit() <= 125) {
+ bbMsg.put((byte) jsonbytes.limit());
+ } else {
+ bbMsg.put((byte) 126);
+ bbMsg.putShort((short) jsonbytes.limit());
+ }
+ bbMsg.put(jsonbytes);
+ bbMsg.flip();
+
+ synchronized (Main.clients) {
+ for (Iterator<SocketSubscribed> i = Main.clients.iterator(); i.hasNext();) {
+ SocketSubscribed s = i.next();
+ if (s.VUID == uid_to) {
+ bbMsg.rewind();
+ try {
+ s.sock.write(bbMsg);
+ } catch (Exception e) {
+ try {
+ s.sock.socket().close();
+ } catch (Exception ex) {
+ }
+ try {
+ s.sock.close();
+ } catch (Exception ex) {
+ }
+ i.remove();
+ }
+ }
+ }
+ }
+ }
+
private void onJuickMessagePost(com.juick.Message jmsg) {
String json = com.juick.json.Message.toJSON(jmsg).toString();
ByteBuffer jsonbytes = Charset.forName("UTF-8").encode(json);