From dafee9c471e154e375cca19f5e96c9c6fc89033f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 26 Feb 2019 14:48:02 +0300 Subject: Display federated likes --- src/main/java/com/juick/Message.java | 6 +++--- src/main/java/com/juick/service/MessagesService.java | 2 +- src/main/java/com/juick/service/MessagesServiceImpl.java | 14 ++++++++++---- src/main/resources/schema.sql | 2 +- src/main/resources/templates/views/thread.html | 6 +++++- 5 files changed, 20 insertions(+), 10 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/juick/Message.java b/src/main/java/com/juick/Message.java index 00527b41..617ed834 100644 --- a/src/main/java/com/juick/Message.java +++ b/src/main/java/com/juick/Message.java @@ -81,7 +81,7 @@ public class Message implements Comparable { private URI replyToUri; private boolean html; - private Set recommendations; + private Set recommendations; private List entities; @@ -333,11 +333,11 @@ public class Message implements Comparable { this.service = service; } - public Set getRecommendations() { + public Set getRecommendations() { return recommendations; } - public void setRecommendations(Set recommendations) { + public void setRecommendations(Set recommendations) { this.recommendations = recommendations; } diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java index 4bcdba46..37da98a8 100644 --- a/src/main/java/com/juick/service/MessagesService.java +++ b/src/main/java/com/juick/service/MessagesService.java @@ -68,7 +68,7 @@ public interface MessagesService { User getMessageAuthor(int mid); - List getMessageRecommendations(int mid); + List getMessageRecommendations(int mid); List getAll(int visitorUid, int before); diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index c3d319d5..01e96d6e 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -477,15 +477,21 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override - public List getMessageRecommendations(final int mid) { - return getJdbcTemplate().queryForList( - "SELECT DISTINCT users.nick FROM favorites " + + public List getMessageRecommendations(final int mid) { + return getJdbcTemplate().query( + "SELECT DISTINCT users.id, users.nick, favorites.user_uri FROM favorites " + "INNER JOIN users ON (favorites.message_id = ? AND favorites.user_id = users.id) " + "INNER JOIN messages m ON favorites.message_id=m.message_id WHERE favorites.like_id=1 " + "AND NOT EXISTS (SELECT 1 FROM bl_users WHERE " + "(user_id = favorites.user_id AND bl_user_id = m.user_id) " + "OR (user_id = m.user_id AND bl_user_id = favorites.user_id))", - String.class, mid); + (rs, rowNum) -> { + User user = new User(); + user.setUid(rs.getInt(1)); + user.setName(rs.getString(2)); + user.setUri(URI.create(rs.getString(3))); + return user; + }, mid); } @Transactional(readOnly = true) diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 2e8fad9b..423fc375 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -258,7 +258,7 @@ CREATE TABLE IF NOT EXISTS `useroptions` ( ); CREATE TABLE IF NOT EXISTS `users` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `id` int(10) unsigned NOT NULL AUTO_INCREMENT(0), `nick` char(64) NOT NULL, `passw` char(32) NOT NULL, `lang` enum('en','ru','fr','fa','__') NOT NULL DEFAULT '__', diff --git a/src/main/resources/templates/views/thread.html b/src/main/resources/templates/views/thread.html index 47dfd000..90c9d4a0 100644 --- a/src/main/resources/templates/views/thread.html +++ b/src/main/resources/templates/views/thread.html @@ -99,7 +99,11 @@ {% if recomm is not empty %}
{{ i18n("messages","message.recommendedBy") }} {% for rec in recomm %} - @{{ rec }}{% if loop.index < (loop.length - 1) %}, {% endif %} + {% if rec.uri.toString() is empty %} + @{{ rec.name }}{% if loop.index < (loop.length - 1) %}, {% endif %} + {% else %} + @{{ rec.name }}{% if loop.index < (loop.length - 1) %}, {% endif %} + {% endif %} {% endfor %} {% if msg.likes > recomm.size() %}  {{ i18n("messages","message.recommendedOthers", msg.likes - recomm.size()) }} -- cgit v1.2.3