aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/juick/model/Message.java1
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java26
-rw-r--r--src/main/resources/templates/views/partial/message.html8
-rw-r--r--src/main/resources/templates/views/thread.html10
4 files changed, 27 insertions, 18 deletions
diff --git a/src/main/java/com/juick/model/Message.java b/src/main/java/com/juick/model/Message.java
index 5ad4fb26..0ae756b1 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 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;
diff --git a/src/main/resources/templates/views/partial/message.html b/src/main/resources/templates/views/partial/message.html
index 47dfb6c5..a41a3064 100644
--- a/src/main/resources/templates/views/partial/message.html
+++ b/src/main/resources/templates/views/partial/message.html
@@ -37,7 +37,7 @@
<a href="/{{ msg.mid }}" class="a-like msg-button">
<span class="msg-button-icon">
<i data-icon="ei-heart" data-size="s"></i>
- {% if msg.likes > 0 %}&nbsp;{{ msg.likes }}
+ {% if msg.recommendations.size() > 0 %}&nbsp;{{ msg.recommendations.size() }}
{% else %}
<span>&nbsp;{{ i18n("messages","message.recommend") }}</span>
{% endif %}
@@ -47,7 +47,7 @@
<a href="/post?body=!+%23{{ msg.mid }}" class="a-like msg-button">
<span class="msg-button-icon">
<i data-icon="ei-heart" data-size="s"></i>
- {% if msg.likes > 0 %}&nbsp;{{ msg.likes }}
+ {% if msg.recommendations.size() > 0 %}&nbsp;{{ msg.recommendations.size() }}
{% else %}
<span>&nbsp;{{ i18n("messages","message.recommend") }}</span>
{% endif %}
@@ -57,8 +57,8 @@
<a href="/login" class="a-login msg-button">
<span class="msg-button-icon">
<i data-icon="ei-heart" data-size="s"></i>
- {% if msg.likes > 0 %}
- {{ msg.likes }}
+ {% if msg.recommendations.size() > 0 %}
+ {{ msg.recommendations.size() }}
{% else %}
<span>&nbsp;{{ i18n("messages","message.recommend") }}</span>
{% endif %}
diff --git a/src/main/resources/templates/views/thread.html b/src/main/resources/templates/views/thread.html
index f1563a7c..6215aa9a 100644
--- a/src/main/resources/templates/views/thread.html
+++ b/src/main/resources/templates/views/thread.html
@@ -44,7 +44,7 @@
<a href="/{{ msg.mid }}" class="a-like msg-button">
<span class="msg-button-icon">
<i data-icon="ei-heart" data-size="s"></i>
- {% if msg.Likes > 0 %}&nbsp;{{ msg.Likes }}
+ {% if msg.recommendations.size() > 0 %}&nbsp;{{ msg.recommendations.size() }}
{% else %}
<span>&nbsp;{{ i18n("messages","message.recommend") }}</span>
{% endif %}
@@ -54,7 +54,7 @@
<a href="/post?body=!+%23{{ msg.mid }}" class="a-like msg-button">
<span class="msg-button-icon">
<i data-icon="ei-heart" data-size="s"></i>
- {% if msg.Likes > 0 %}&nbsp;{{ msg.Likes }}
+ {% if msg.recommendations.size() > 0 %}&nbsp;{{ msg.recommendations.size() }}
{% else %}
<span>&nbsp;{{ i18n("messages","message.recommend") }}</span>
{% endif %}
@@ -64,7 +64,7 @@
<a href="/login" class="a-login msg-button">
<span class="msg-button-icon">
<i data-icon="ei-heart" data-size="s"></i>
- {% if msg.Likes > 0 %}&nbsp;{{ msg.Likes }}
+ {% if msg.recommendations.size() > 0 %}&nbsp;{{ msg.recommendations.size() }}
{%else %}
<span>&nbsp;{{ i18n("messages","message.recommend") }}</span>
{% endif %}
@@ -111,8 +111,8 @@
<a href="{{ rec.uri }}" data-user-uri="1">@{{ rec.name }}</a>{% if loop.index < (loop.length - 1) %}, {% endif %}
{% endif %}
{% endfor %}
- {% if msg.likes > recomm.size() %}
- &nbsp;{{ i18n("messages","message.recommendedOthers", msg.likes - recomm.size()) }}
+ {% if msg.recommendations.size() > recomm.size() %}
+ &nbsp;{{ i18n("messages","message.recommendedOthers", msg.recommendations.size() - recomm.size()) }}
{% endif %}
</div>
{% endif %}