diff options
author | Vitaly Takmazov | 2022-06-25 01:14:09 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2022-06-25 01:14:09 +0300 |
commit | 8f3d85a8afa851f4457163d3aade01c1f63075a0 (patch) | |
tree | b1ea8dd6a3c4335b96136604cb5acf9e3f4f4315 /src/main/java/com/juick/service/MessagesServiceImpl.java | |
parent | 4ebc9ab55553a33ef7c3bedb8628ffaf74333f84 (diff) |
Fix recommendations counters in html templates
* deprecate `likes` message field, use `recommendations` where possible
Diffstat (limited to 'src/main/java/com/juick/service/MessagesServiceImpl.java')
-rw-r--r-- | src/main/java/com/juick/service/MessagesServiceImpl.java | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index 4cbd09ee..77200077 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; |