aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-30 18:58:11 +0300
committerGravatar Vitaly Takmazov2018-04-30 18:58:11 +0300
commiteeb59ea1f2e2bd4307573d01238c8c4ce35d4179 (patch)
treea2c10298c4ac25c075fcb2ec5450d41dcbfa37e5
parentcf61b2fc3c3ae6201e7a007ac11690700a6d619a (diff)
server: fix classic likes counter
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java10
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java5
2 files changed, 10 insertions, 5 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 8554b35f..b64d7fd9 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
@@ -217,7 +217,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Transactional
void updateRepliesBy(int mid) {
- List<String> users = getJdbcTemplate().queryForList("SELECT users.nick FROM replies " +
+ List<String> users = getJdbcTemplate().queryForList("SELECT DISTINCT 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(","));
@@ -243,7 +243,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Override
public List<Reaction> listReactions() {
- return jdbcTemplate.query("SELECT like_id, description FROM reactions", (RowMapper<Reaction>) (rs, rowNum) -> {
+ return jdbcTemplate.query("SELECT like_id, description FROM reactions", (rs, rowNum) -> {
Reaction reaction = new Reaction(rs.getInt("like_id"));
reaction.setDescription(rs.getString("description"));
return reaction;
@@ -330,7 +330,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "messages.ts,"
+ "messages.readonly, messages.privacy, messages.replies,"
+ "messages.attach, messages.place_id, messages.lat,"
- + "messages.lon, COUNT(favorites.user_id) as likes, messages.hidden,"
+ + "messages.lon, COUNT(DISTINCT favorites.user_id) as likes, messages.hidden,"
+ "txt.tags, txt.repliesby, txt.txt, '' as q, messages.updated, 0 as to_uid, "
+ "NULL as to_name FROM messages "
+ "INNER JOIN users ON messages.user_id = users.id "
@@ -421,7 +421,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Override
public List<String> getMessageRecommendations(final int mid) {
return getJdbcTemplate().queryForList(
- "SELECT users.nick FROM favorites INNER JOIN users " +
+ "SELECT DISTINCT users.nick FROM favorites INNER JOIN users " +
"ON (favorites.message_id = ? AND favorites.user_id = users.id) WHERE favorites.like_id=1",
new Object[]{mid},
String.class);
@@ -783,7 +783,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "messages.ts,"
+ "messages.readonly,messages.privacy,messages.replies,"
+ "messages.attach,messages.place_id,messages.lat,"
- + "messages.lon,COUNT(favorites.user_id) AS likes,messages.hidden,"
+ + "messages.lon,COUNT(DISTINCT favorites.user_id) AS likes,messages.hidden,"
+ "messages_txt.tags,messages_txt.repliesby, messages_txt.txt, '' as q, "
+ "messages.updated, 0 as to_uid, NULL as to_name "
+ "FROM (messages INNER JOIN messages_txt "
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index d719c183..692cc182 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -858,6 +858,11 @@ public class ServerTests {
assertThat(messagesService.getMessages(Collections.singletonList(mid1)).get(0).getLikes(), is(0));
Assert.assertEquals(1, msg4.getReactions().stream().filter(r -> r.getId() == 2)
.findFirst().orElseThrow(IllegalStateException::new).getCount());
+ mockMvc.perform(post("/react?mid=" + mid1 + "&hash=" + freefdHash+ "&reactionId=1"))
+ .andExpect(status().isOk());
+ mockMvc.perform(post("/react?mid=" + mid1 + "&hash=" + freefdHash+ "&reactionId=1"))
+ .andExpect(status().isOk());
+ assertThat(messagesService.getMessage(mid1).getLikes(), is(1));
}
@Test