aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/xmpp/s2s/JuickBot.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-06-27 13:16:43 +0300
committerGravatar Vitaly Takmazov2016-06-27 13:16:43 +0300
commit606f43f50904f7d811cf9b438e0e820e586be900 (patch)
tree55904b790d79ba15033469bd378342883322bb5d /src/main/java/com/juick/xmpp/s2s/JuickBot.java
parent0d93073c6988a22246db61a59b97c2fd7c9f462b (diff)
spring-jdbc near complete
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/JuickBot.java')
-rw-r--r--src/main/java/com/juick/xmpp/s2s/JuickBot.java118
1 files changed, 56 insertions, 62 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/JuickBot.java b/src/main/java/com/juick/xmpp/s2s/JuickBot.java
index 25c75dfe..1172d75f 100644
--- a/src/main/java/com/juick/xmpp/s2s/JuickBot.java
+++ b/src/main/java/com/juick/xmpp/s2s/JuickBot.java
@@ -194,7 +194,7 @@ public class JuickBot {
m.to = new JID(Integer.toString(uid_to), "push.juick.com", null);
JuickMessage jmsg = new JuickMessage();
synchronized (XMPPComponent.sqlSync) {
- jmsg.setUser(UserQueries.getUserByUID(XMPPComponent.sql, user_from.getUID()));
+ jmsg.setUser(user_from);
}
jmsg.setText(msg.body);
m.childs.add(jmsg);
@@ -203,29 +203,25 @@ public class JuickBot {
m.to.Host = "ws.juick.com";
XMPPComponent.connRouter.router.send(m.toString());
- String jid;
+ List<String> jids;
boolean inroster = false;
synchronized (XMPPComponent.sqlSync) {
- jid = UserQueries.getJIDbyUID(XMPPComponent.sql, uid_to);
- if (jid != null) {
+ jids = UserQueries.getJIDsbyUID(XMPPComponent.sql, uid_to);
+ for (String jid : jids) {
+ Message mm = new Message();
+ mm.to = new JID(jid);
+ mm.type = Message.Type.chat;
inroster = PMQueries.havePMinRoster(XMPPComponent.sql, user_from.getUID(), jid);
+ if (inroster) {
+ mm.from = new JID(jmsg.getUser().getUName(), "juick.com", "Juick");
+ mm.body = msg.body;
+ } else {
+ mm.from = new JID("juick", "juick.com", "Juick");
+ mm.body = "Private message from @" + jmsg.getUser().getUName() + ":\n" + msg.body;
+ }
+ XMPPComponent.sendOut(mm);
}
}
-
- if (jid != null) {
- Message mm = new Message();
- mm.to = new JID(jid);
- mm.type = Message.Type.chat;
- if (inroster) {
- mm.from = new JID(jmsg.getUser().getUName(), "juick.com", "Juick");
- mm.body = msg.body;
- } else {
- mm.from = new JID("juick", "juick.com", "Juick");
- mm.body = "Private message from @" + jmsg.getUser().getUName() + ":\n" + msg.body;
- }
- XMPPComponent.sendOut(mm);
- }
-
} else {
Message reply = new Message(msg.to, msg.from, Message.Type.error);
reply.id = msg.id;
@@ -300,7 +296,7 @@ public class JuickBot {
int ret = 0;
int uid_to = 0;
- String jid_to = null;
+ List<String> jids_to = null;
boolean haveInRoster = false;
synchronized (XMPPComponent.sqlSync) {
@@ -313,10 +309,7 @@ public class JuickBot {
if (uid_to > 0) {
if (!UserQueries.isInBLAny(XMPPComponent.sql, uid_to, user_from.getUID())) {
if (PMQueries.createPM(XMPPComponent.sql, user_from.getUID(), uid_to, body)) {
- jid_to = UserQueries.getJIDbyUID(XMPPComponent.sql, uid_to);
- if (jid_to != null) {
- haveInRoster = PMQueries.havePMinRoster(XMPPComponent.sql, user_from.getUID(), jid_to);
- }
+ jids_to = UserQueries.getJIDsbyUID(XMPPComponent.sql, uid_to);
ret = 200;
} else {
ret = 500;
@@ -327,45 +320,46 @@ public class JuickBot {
} else {
ret = 404;
}
- }
- if (ret == 200) {
- Message msg = new Message();
- msg.from = new JID("juick", "juick.com", null);
- msg.to = new JID(Integer.toString(uid_to), "push.juick.com", null);
- JuickMessage jmsg = new JuickMessage();
- jmsg.setUser(user_from);
- jmsg.setText(body);
- msg.childs.add(jmsg);
- XMPPComponent.connRouter.router.send(msg.toString());
-
- msg.to.Host = "ws.juick.com";
- XMPPComponent.connRouter.router.send(msg.toString());
-
- if (jid_to != null) {
- Message mm = new Message();
- mm.to = new JID(jid_to);
- mm.type = Message.Type.chat;
- if (haveInRoster) {
- mm.from = new JID(user_from.getUName(), "juick.com", "Juick");
- mm.body = body;
- } else {
- mm.from = new JID("juick", "juick.com", "Juick");
- mm.body = "Private message from @" + user_from.getUName() + ":\n" + body;
+ if (ret == 200) {
+ Message msg = new Message();
+ msg.from = new JID("juick", "juick.com", null);
+ msg.to = new JID(Integer.toString(uid_to), "push.juick.com", null);
+ JuickMessage jmsg = new JuickMessage();
+ jmsg.setUser(user_from);
+ jmsg.setText(body);
+ msg.childs.add(jmsg);
+ XMPPComponent.connRouter.router.send(msg.toString());
+
+ msg.to.Host = "ws.juick.com";
+ XMPPComponent.connRouter.router.send(msg.toString());
+
+ for (String jid : jids_to) {
+ Message mm = new Message();
+ mm.to = new JID(jid);
+ mm.type = Message.Type.chat;
+ haveInRoster = PMQueries.havePMinRoster(XMPPComponent.sql, user_from.getUID(), jid);
+ if (haveInRoster) {
+ mm.from = new JID(user_from.getUName(), "juick.com", "Juick");
+ mm.body = body;
+ } else {
+ mm.from = new JID("juick", "juick.com", "Juick");
+ mm.body = "Private message from @" + user_from.getUName() + ":\n" + body;
+ }
+ XMPPComponent.sendOut(mm);
}
- XMPPComponent.sendOut(mm);
}
- }
- Message reply = new Message(m.to, m.from);
- if (ret == 200) {
- reply.type = m.type;
- reply.body = "Private message sent";
- } else {
- reply.type = Message.Type.error;
- reply.body = "Error " + ret;
+ Message reply = new Message(m.to, m.from);
+ if (ret == 200) {
+ reply.type = m.type;
+ reply.body = "Private message sent";
+ } else {
+ reply.type = Message.Type.error;
+ reply.body = "Error " + ret;
+ }
+ XMPPComponent.sendOut(reply);
}
- XMPPComponent.sendOut(reply);
}
private static void commandBLShow(Message m, User user_from) throws Exception {
@@ -379,8 +373,8 @@ public class JuickBot {
String txt = "";
if (bltags.size() > 0) {
- for (int i = 0; i < bltags.size(); i++) {
- txt += "*" + bltags.get(i) + "\n";
+ for (String bltag : bltags) {
+ txt += "*" + bltag + "\n";
}
if (blusers.size() > 0) {
@@ -388,8 +382,8 @@ public class JuickBot {
}
}
if (blusers.size() > 0) {
- for (int i = 0; i < blusers.size(); i++) {
- txt += "@" + blusers.get(i).getUName() + "\n";
+ for (User bluser : blusers) {
+ txt += "@" + bluser.getUName() + "\n";
}
}
if (txt.isEmpty()) {