aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r--src/main/java/com/juick/model/Message.java1
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java26
2 files changed, 18 insertions, 9 deletions
diff --git a/src/main/java/com/juick/model/Message.java b/src/main/java/com/juick/model/Message.java
index 5ad4fb268..0ae756b14 100644
--- a/src/main/java/com/juick/model/Message.java
+++ b/src/main/java/com/juick/model/Message.java
@@ -258,6 +258,7 @@ public class Message implements Comparable<Message>, Serializable {
}
@XmlTransient
+ @Deprecated
public int getLikes() {
return likes;
}
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index 4cbd09eec..77200077a 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -394,6 +394,11 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
Map<Integer, Set<Reaction>> reactionStats = updateReactionsFor(Collections.singletonList(mid));
message.setReactions(reactionStats.get(message.getMid()));
message.setEntities(MessageUtils.getEntities(message));
+ List<Pair<Integer, User>> allRecommendations = getMessagesRecommendations(List.of(mid));
+
+ message.setRecommendations(new HashSet<>(allRecommendations.stream()
+ .filter(r -> r.getLeft().equals(mid)).map(Pair::getRight).collect(Collectors.toList())));
+ message.getRecommendations().forEach(r -> r.setAvatar(webApp.getAvatarUrl(r)));
return Optional.of(message);
}
return Optional.empty();
@@ -703,21 +708,24 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Transactional(readOnly = true)
@Override
- public List<Integer> getUserBlogWithRecommendations(final User user, final User visitor, final int privacy, final int before) {
+ public List<Integer> getUserBlogWithRecommendations(final User user, final User visitor, final int privacy,
+ final int before) {
SqlParameterSource sqlParameterSource = new MapSqlParameterSource()
- .addValue("uid", user.getUid())
- .addValue("vid", visitor.getUid())
- .addValue("privacy", privacy).addValue("before", before);
+ .addValue("uid", user.getUid())
+ .addValue("vid", visitor.getUid())
+ .addValue("privacy", privacy).addValue("before", before);
return getNamedParameterJdbcTemplate()
- .queryForList("SELECT message_id FROM " + "(SELECT favorites.message_id FROM favorites "
+ .queryForList("SELECT message_id FROM " + "(SELECT favorites.message_id FROM favorites "
+ " INNER JOIN messages ON messages.message_id = favorites.message_id"
- + " INNER JOIN users ON messages.user_id = users.id" + " WHERE favorites.user_id = :uid AND users.banned = 0"
+ + " INNER JOIN users ON messages.user_id = users.id"
+ + " WHERE favorites.user_id = :uid AND users.banned = 0"
+ " AND NOT EXISTS (SELECT 1 FROM bl_users b WHERE b.user_id = :vid and b.bl_user_id = messages.user_id) "
+ " AND NOT EXISTS (SELECT 1 FROM bl_tags bt WHERE bt.tag_id IN "
+ "(SELECT tag_id FROM messages_tags WHERE message_id = favorites.message_id) and :vid = bt.user_id)"
+ (before > 0 ? " AND messages.message_id < :before " : StringUtils.EMPTY)
- + " ORDER BY messages.message_id DESC LIMIT 20) as r" + " UNION ALL " + "SELECT message_id FROM "
+ + " ORDER BY messages.message_id DESC LIMIT 20) as r" + " UNION ALL "
+ + "SELECT message_id FROM "
+ "(SELECT message_id FROM messages" + " INNER JOIN users" + " ON messages.user_id = users.id"
+ " WHERE user_id = :uid AND users.banned = 0"
+ " AND NOT EXISTS (SELECT 1 FROM bl_users b WHERE b.user_id = :vid and b.bl_user_id = messages.user_id) "
@@ -945,8 +953,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
} else {
// only archive author replies
return getNamedParameterJdbcTemplate().update(
- "UPDATE replies SET user_id=:archive_uid WHERE message_id=:mid AND reply_id=:rid AND user_id=:uid",
- parameters) > 0;
+ "UPDATE replies SET user_id=:archive_uid WHERE message_id=:mid AND reply_id=:rid AND user_id=:uid",
+ parameters) > 0;
}
}
return false;