aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/xmpp/s2s/JuickBot.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-02-02 14:36:04 +0300
committerGravatar Vitaly Takmazov2016-02-02 14:36:04 +0300
commitbd3892546b51f0d31e959d45c138b009d35b2692 (patch)
tree3c3945f114472344cc3a8866391fa08f02975143 /src/main/java/com/juick/xmpp/s2s/JuickBot.java
parentf2a2660e753fa11478fd3edadfdff9c000b22cc9 (diff)
spring-jdbc
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/JuickBot.java')
-rw-r--r--src/main/java/com/juick/xmpp/s2s/JuickBot.java97
1 files changed, 40 insertions, 57 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/JuickBot.java b/src/main/java/com/juick/xmpp/s2s/JuickBot.java
index 182de10d..d82ed939 100644
--- a/src/main/java/com/juick/xmpp/s2s/JuickBot.java
+++ b/src/main/java/com/juick/xmpp/s2s/JuickBot.java
@@ -69,9 +69,7 @@ public class JuickBot {
} else if (p.type.equals(Presence.Type.probe)) {
int uid_to = 0;
if (!toJuick) {
- synchronized (XMPPComponent.sqlSync) {
- uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username);
- }
+ uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username);
}
if (toJuick || uid_to > 0) {
@@ -94,12 +92,10 @@ public class JuickBot {
if (toJuick) {
canSubscribe = true;
} else {
- synchronized (XMPPComponent.sqlSync) {
- int uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username);
- if (uid_to > 0) {
- PMQueries.addPMinRoster(XMPPComponent.sql, uid_to, p.from.Bare());
- canSubscribe = true;
- }
+ int uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username);
+ if (uid_to > 0) {
+ PMQueries.addPMinRoster(XMPPComponent.sql, uid_to, p.from.Bare());
+ canSubscribe = true;
}
}
@@ -122,11 +118,9 @@ public class JuickBot {
}
} else if (p.type.equals(Presence.Type.unsubscribe)) {
if (!toJuick) {
- synchronized (XMPPComponent.sqlSync) {
- int uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username);
- if (uid_to > 0) {
- PMQueries.removePMinRoster(XMPPComponent.sql, uid_to, p.from.Bare());
- }
+ int uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username);
+ if (uid_to > 0) {
+ PMQueries.removePMinRoster(XMPPComponent.sql, uid_to, p.from.Bare());
}
}
@@ -146,11 +140,9 @@ public class JuickBot {
User user_from = null;
String signuphash = "";
- synchronized (XMPPComponent.sqlSync) {
- user_from = UserQueries.getUserByJID(XMPPComponent.sql, msg.from.Bare());
- if (user_from == null) {
- signuphash = UserQueries.getSignUpHashByJID(XMPPComponent.sql, msg.from.Bare());
- }
+ user_from = UserQueries.getUserByJID(XMPPComponent.sql, msg.from.Bare());
+ if (user_from == null) {
+ signuphash = UserQueries.getSignUpHashByJID(XMPPComponent.sql, msg.from.Bare());
}
if (user_from == null) {
@@ -168,10 +160,7 @@ public class JuickBot {
return incomingMessageJuick(user_from, msg);
}
- int uid_to = 0;
- synchronized (XMPPComponent.sqlSync) {
- uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username);
- }
+ int uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, username);
if (uid_to == 0) {
Message reply = new Message(msg.to, msg.from, Message.Type.error);
@@ -182,20 +171,18 @@ public class JuickBot {
}
boolean success = false;
- synchronized (XMPPComponent.sqlSync) {
- if (!UserQueries.isInBLAny(XMPPComponent.sql, uid_to, user_from.getUID())) {
- success = PMQueries.createPM(XMPPComponent.sql, user_from.getUID(), uid_to, msg.body);
- }
+ if (!UserQueries.isInBLAny(XMPPComponent.sql, uid_to, user_from.getUID())) {
+ success = PMQueries.createPM(XMPPComponent.sql, user_from.getUID(), uid_to, msg.body);
}
+
if (success) {
Message m = new Message();
m.from = new JID("juick", "juick.com", null);
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(UserQueries.getUserByUID(XMPPComponent.sql, user_from.getUID()));
+
jmsg.setText(msg.body);
m.childs.add(jmsg);
XMPPComponent.connRouter.sendStanza(m.toString());
@@ -205,11 +192,9 @@ public class JuickBot {
String jid;
boolean inroster = false;
- synchronized (XMPPComponent.sqlSync) {
- jid = UserQueries.getJIDbyUID(XMPPComponent.sql, uid_to);
- if (jid != null) {
- inroster = PMQueries.havePMinRoster(XMPPComponent.sql, user_from.getUID(), jid);
- }
+ jid = UserQueries.getJIDbyUID(XMPPComponent.sql, uid_to);
+ if (jid != null) {
+ inroster = PMQueries.havePMinRoster(XMPPComponent.sql, user_from.getUID(), jid);
}
if (jid != null) {
@@ -303,32 +288,31 @@ public class JuickBot {
String jid_to = null;
boolean haveInRoster = false;
- synchronized (XMPPComponent.sqlSync) {
- if (user_to.indexOf('@') > 0) {
- uid_to = UserQueries.getUIDbyJID(XMPPComponent.sql, user_to);
- } else {
- uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, user_to);
- }
+ if (user_to.indexOf('@') > 0) {
+ uid_to = UserQueries.getUIDbyJID(XMPPComponent.sql, user_to);
+ } else {
+ uid_to = UserQueries.getUIDbyName(XMPPComponent.sql, user_to);
+ }
- 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);
- }
- ret = 200;
- } else {
- ret = 500;
+ 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);
}
+ ret = 200;
} else {
- ret = 403;
+ ret = 500;
}
} else {
- ret = 404;
+ ret = 403;
}
+ } else {
+ ret = 404;
}
+
if (ret == 200) {
Message msg = new Message();
msg.from = new JID("juick", "juick.com", null);
@@ -372,10 +356,9 @@ public class JuickBot {
List<User> blusers;
List<String> bltags;
- synchronized (XMPPComponent.sqlSync) {
- blusers = UserQueries.getUserBLUsers(XMPPComponent.sql, user_from.getUID());
- bltags = TagQueries.getUserBLTags(XMPPComponent.sql, user_from.getUID());
- }
+ blusers = UserQueries.getUserBLUsers(XMPPComponent.sql, user_from.getUID());
+ bltags = TagQueries.getUserBLTags(XMPPComponent.sql, user_from.getUID());
+
String txt = "";
if (bltags.size() > 0) {