aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-01-30 14:23:50 +0300
committerGravatar Vitaly Takmazov2018-01-30 14:23:50 +0300
commit2d6e1dc76e659b78b3103af2bcf1b7f13db62f0a (patch)
tree30f46c54d5ecd5bdac3de17998425288b96908c7 /juick-server-jdbc
parent1e5c0403d3339c40950106737ef17727d786f6d4 (diff)
xmpp: D #message
Diffstat (limited to 'juick-server-jdbc')
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
index 2497e94a..b81ef578 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -48,6 +48,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
/**
* Created by aalexeev on 11/13/16.
@@ -228,6 +229,15 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
}
@Transactional
+ void updateRepliesBy(int mid) {
+ List<String> users = getJdbcTemplate().queryForList("SELECT users.nick FROM replies " +
+ "INNER JOIN users ON replies.user_id=users.id WHERE replies.message_id=? " +
+ "GROUP BY replies.user_id ORDER BY COUNT(replies.reply_id) DESC LIMIT 5", String.class, mid);
+ String result = users.stream().map(u -> "@" + u).collect(Collectors.joining(","));
+ getJdbcTemplate().update("UPDATE messages_txt SET repliesby=? WHERE message_id=?", result, mid);
+ }
+
+ @Transactional
@Override
public boolean recommendMessage(final int mid, final int vuid) {
int wasDeleted = getJdbcTemplate()
@@ -822,6 +832,30 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
}
return false;
}
+ @Transactional
+ @Override
+ public boolean deleteReply(final int uid, final int mid, final int rid) {
+ User author = getMessageAuthor(mid);
+ SqlParameterSource sqlParameterSource = new MapSqlParameterSource()
+ .addValue("mid", mid)
+ .addValue("uid", uid)
+ .addValue("rid", rid);
+ boolean result;
+ if (author.getUid() == uid) {
+ result = getNamedParameterJdbcTemplate()
+ .update("DELETE FROM replies WHERE message_id=:mid AND reply_id=:rid", sqlParameterSource) > 0;
+ } else {
+ result = getNamedParameterJdbcTemplate()
+ .update("DELETE FROM replies WHERE message_id=:mid AND reply_id=:rid AND user_id=:uid"
+ , sqlParameterSource) > 0;
+ }
+ if (result) {
+ getNamedParameterJdbcTemplate().update("UPDATE replies SET replies=replies-1 WHERE message_id=:mid", sqlParameterSource);
+ updateRepliesBy(mid);
+ return true;
+ }
+ return false;
+ }
@Transactional(readOnly = true)
@Override