aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/juick/Message.java6
-rw-r--r--src/main/java/com/juick/service/MessagesService.java2
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java14
-rw-r--r--src/main/resources/schema.sql2
-rw-r--r--src/main/resources/templates/views/thread.html6
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java29
-rw-r--r--src/test/resources/data.sql1
7 files changed, 39 insertions, 21 deletions
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<String> recommendations;
+ private Set<User> recommendations;
private List<Entity> entities;
@@ -333,11 +333,11 @@ public class Message implements Comparable {
this.service = service;
}
- public Set<String> getRecommendations() {
+ public Set<User> getRecommendations() {
return recommendations;
}
- public void setRecommendations(Set<String> recommendations) {
+ public void setRecommendations(Set<User> 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<String> getMessageRecommendations(int mid);
+ List<User> getMessageRecommendations(int mid);
List<Integer> 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<String> getMessageRecommendations(final int mid) {
- return getJdbcTemplate().queryForList(
- "SELECT DISTINCT users.nick FROM favorites " +
+ public List<User> 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 %}
<div class="msg-recomms">{{ i18n("messages","message.recommendedBy") }}
{% for rec in recomm %}
- <a href="/{{ rec }}/">@{{ rec }}</a>{% if loop.index < (loop.length - 1) %}, {% endif %}
+ {% if rec.uri.toString() is empty %}
+ <a href="/{{ rec.name }}/">@{{ rec.name }}</a>{% if loop.index < (loop.length - 1) %}, {% endif %}
+ {% else %}
+ <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()) }}
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 5c421f07..c8f07d06 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -26,12 +26,12 @@ import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.css.StyleElement;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
-import com.github.jsonldjava.core.JsonLdOptions;
-import com.github.jsonldjava.core.JsonLdProcessor;
-import com.github.jsonldjava.utils.JsonUtils;
import com.jayway.jsonpath.JsonPath;
import com.juick.*;
-import com.juick.model.*;
+import com.juick.model.AnonymousUser;
+import com.juick.model.CommandResult;
+import com.juick.model.PrivateChats;
+import com.juick.model.TagStats;
import com.juick.server.*;
import com.juick.server.api.activity.model.Context;
import com.juick.server.api.activity.model.activities.*;
@@ -104,7 +104,6 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
-import java.net.ConnectException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
@@ -901,7 +900,7 @@ public class ServerTests {
mockMvc.perform(get("/api/thread?mid=" + mid + "&hash=" + freefdHash))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].recommendations.length()", is(1)))
- .andExpect(jsonPath("$[0].recommendations[0]", is(freefdName)));
+ .andExpect(jsonPath("$[0].recommendations[0].uname", is(freefdName)));
mockMvc.perform(post("/api/like?mid=" + freefdMid + "&hash=" + freefdHash))
.andExpect(status().isForbidden());
}
@@ -1354,11 +1353,18 @@ public class ServerTests {
assertThat(messagesService.recommendMessage(mid, ermineId), is(MessagesService.RecommendStatus.Added));
assertThat(messagesService.recommendMessage(mid, fmapId), is(MessagesService.RecommendStatus.Added));
assertThat(messagesService.recommendMessage(mid, pogoId), is(MessagesService.RecommendStatus.Added));
- assertThat(messagesService.getMessage(mid).get().getLikes(), is(3));
- assertThat(CollectionUtils.isEqualCollection(messagesService.getMessageRecommendations(mid), Arrays.asList("fmap", "ermine", "pogo")), is(true));
- privacyQueriesService.blacklistUser(userService.getUserByName("monstreek"), userService.getUserByName("pogo"));
- assertThat(messagesService.getMessage(mid).get().getLikes(), is(3));
- assertThat(CollectionUtils.isEqualCollection(messagesService.getMessageRecommendations(mid), Arrays.asList("fmap", "ermine")), is(true));
+ jdbcTemplate.update("INSERT INTO favorites(user_id, user_uri, message_id, like_id, ts) " +
+ "values (0, 'http://example.com/u/test', ?, 1, now())", mid);
+ assertThat(messagesService.getMessage(mid).get().getLikes(), is(4));
+ assertThat(CollectionUtils.isEqualCollection(messagesService.getMessageRecommendations(mid)
+ .stream().map(User::getName).collect(Collectors.toList()),
+ Arrays.asList("fmap", "ermine", "pogo", "Anonymous")), is(true));
+ privacyQueriesService.blacklistUser(userService.getUserByName("monstreek"),
+ userService.getUserByName("pogo"));
+ assertThat(messagesService.getMessage(mid).get().getLikes(), is(4));
+ assertThat(CollectionUtils.isEqualCollection(messagesService.getMessageRecommendations(mid)
+ .stream().map(User::getName).collect(Collectors.toList()),
+ Arrays.asList("fmap", "ermine", "Anonymous")), is(true));
}
@Test
public void bannedUserShouldNotBeVisibleToOthers() {
@@ -1708,6 +1714,7 @@ public class ServerTests {
replyNote.setTo(Collections.singletonList(activityPubManager.personUri(ugnich)));
replyNote.setContent("HI");
Create create = new Create();
+ create.setId(replyNote.getId());
create.setActor("http://localhost:8080/u/freefd");
create.setObject(replyNote);
signatureManager.post((Person) signatureManager.getContext(URI.create("http://localhost:8080/u/freefd")).get(),
diff --git a/src/test/resources/data.sql b/src/test/resources/data.sql
index 102b11f4..aff3e286 100644
--- a/src/test/resources/data.sql
+++ b/src/test/resources/data.sql
@@ -1,3 +1,4 @@
+INSERT INTO users(id, nick, passw) VALUES(0, 'Anonymous', 'password');
INSERT INTO tags(tag_id, name) VALUES(2, 'juick');
INSERT INTO reactions (like_id, description) VALUES (1, 'like');
INSERT INTO reactions (like_id, description) VALUES (2, 'love');