diff options
author | Vitaly Takmazov | 2016-01-28 17:29:55 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-01-28 17:29:55 +0300 |
commit | 27e6c9c5edb2642c31735fcb0effb9acd82bd4af (patch) | |
tree | 0ba8f3d62e7bcf55b11739ddb270f53dc0496c06 | |
parent | e746ca6970bea80ec9b5ae79dda8f6332254e301 (diff) |
fix build
-rw-r--r-- | build.gradle | 1 | ||||
-rw-r--r-- | src/main/java/com/juick/jabber/ws/XMPPConnection.java | 30 |
2 files changed, 19 insertions, 12 deletions
diff --git a/build.gradle b/build.gradle index 0091459a..63ba360a 100644 --- a/build.gradle +++ b/build.gradle @@ -54,6 +54,7 @@ dependencies { compile json compile "org.springframework:spring-jdbc:4.2.4.RELEASE" providedCompile 'javax.servlet:javax.servlet-api:3.1.0' + providedCompile 'javax.websocket:javax.websocket-api:1.0' def tomcatVersion = '7.0.+' tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}", diff --git a/src/main/java/com/juick/jabber/ws/XMPPConnection.java b/src/main/java/com/juick/jabber/ws/XMPPConnection.java index 39815da5..df403083 100644 --- a/src/main/java/com/juick/jabber/ws/XMPPConnection.java +++ b/src/main/java/com/juick/jabber/ws/XMPPConnection.java @@ -1,5 +1,6 @@ package com.juick.jabber.ws; +import com.juick.json.MessageSerializer; import com.juick.server.MessagesQueries; import com.juick.server.Utils; import com.juick.xmpp.JID; @@ -53,7 +54,7 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message. } @Override - public void onStreamFail(String msg) { + public void onStreamFail(Exception msg) { System.err.println("Stream failed: " + msg); } @@ -61,8 +62,8 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message. public void onMessage(com.juick.xmpp.Message msg) { JuickMessage jmsg = (JuickMessage) msg.getChild(JuickMessage.XMLNS); if (jmsg != null) { - System.err.println("MID=" + jmsg.MID + "; RID=" + jmsg.RID); - if (jmsg.MID == 0) { + System.err.println("MID=" + jmsg.getMID() + "; RID=" + jmsg.getRID()); + if (jmsg.getMID() == 0) { int uid_to = 0; try { uid_to = Integer.parseInt(msg.to.Username); @@ -71,7 +72,7 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message. if (uid_to > 0) { onJuickPM(uid_to, jmsg); } - } else if (jmsg.RID == 0) { + } else if (jmsg.getRID() == 0) { onJuickMessagePost(jmsg); } else { onJuickMessageReply(jmsg); @@ -79,8 +80,10 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message. } } + MessageSerializer messageSerializer = new MessageSerializer(); + private void onJuickPM(int uid_to, com.juick.Message jmsg) { - String json = com.juick.json.Message.toJSON(jmsg).toString(); + String json = messageSerializer.serialize(jmsg).toString(); ByteBuffer bbMsg = buildTextFrame(json); synchronized (Main.clients) { @@ -96,13 +99,15 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message. } private void onJuickMessagePost(com.juick.Message jmsg) { - String json = com.juick.json.Message.toJSON(jmsg).toString(); + String json = messageSerializer.serialize(jmsg).toString(); ByteBuffer bbMsg = buildTextFrame(json); ArrayList<Integer> uids = new ArrayList<Integer>(); - String query = "SELECT suser_id FROM subscr_users WHERE user_id=" + jmsg.User.UID + " AND suser_id NOT IN (SELECT user_id FROM bl_tags INNER JOIN messages_tags USING(tag_id) WHERE message_id=" + jmsg.MID + ")"; + String query = "SELECT suser_id FROM subscr_users WHERE user_id=" + jmsg.getUser().getUID() + + " AND suser_id NOT IN (SELECT user_id FROM bl_tags " + + "INNER JOIN messages_tags USING(tag_id) WHERE message_id=" + jmsg.getMID() + ")"; if (jmsg.Privacy < 0) { - query += " AND suser_id IN (SELECT wl_user_id FROM wl_users WHERE user_id=" + jmsg.User.UID + ")"; + query += " AND suser_id IN (SELECT wl_user_id FROM wl_users WHERE user_id=" + jmsg.getUser().getUID() + ")"; } Statement stmt = null; ResultSet rs = null; @@ -122,7 +127,8 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message. synchronized (Main.clients) { for (Iterator<SocketSubscribed> i = Main.clients.iterator(); i.hasNext();) { SocketSubscribed s = i.next(); - if (s.MID == 0 && s.allReplies == false && ((jmsg.Privacy >= 0 && (s.allMessages || s.UID == jmsg.User.UID)) || uids.contains(s.VUID))) { + if (s.MID == 0 && s.allReplies == false && ((jmsg.Privacy >= 0 + && (s.allMessages || s.UID == jmsg.getUser().getUID())) || uids.contains(s.VUID))) { if (!s.sendByteBuffer(bbMsg)) { i.remove(); } @@ -132,15 +138,15 @@ public class XMPPConnection implements Runnable, Stream.StreamListener, Message. } private void onJuickMessageReply(com.juick.Message jmsg) { - String json = com.juick.json.Message.toJSON(jmsg).toString(); + String json = messageSerializer.serialize(jmsg).toString(); ByteBuffer bbMsg = buildTextFrame(json); - int privacy = MessagesQueries.getMessagePrivacy(sql, jmsg.MID); + int privacy = MessagesQueries.getMessagePrivacy(sql, jmsg.getMID()); synchronized (Main.clients) { for (Iterator<SocketSubscribed> i = Main.clients.iterator(); i.hasNext();) { SocketSubscribed s = i.next(); - if ((privacy >= 0 && s.allReplies) || s.MID == jmsg.MID) { + if ((privacy >= 0 && s.allReplies) || s.MID == jmsg.getMID()) { if (!s.sendByteBuffer(bbMsg)) { i.remove(); } |