aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server-jdbc/src/main/java/com/juick')
-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 2497e94a6..b81ef5789 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