aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Messages.java2
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java6
-rw-r--r--juick-rss/src/test/java/com/juick/rss/tests/RSSTests.java2
-rw-r--r--juick-server-core/src/main/java/com/juick/server/protocol/JuickProtocol.java2
-rw-r--r--juick-server-core/src/main/java/com/juick/service/MessagesService.java2
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java8
-rw-r--r--juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java34
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/Home.java2
-rw-r--r--juick-www/src/main/webapp/WEB-INF/views/partial/navigation.html1
-rw-r--r--juick-www/src/test/java/com/juick/www/WebAppTests.java6
10 files changed, 42 insertions, 23 deletions
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Messages.java b/juick-api/src/main/java/com/juick/api/controllers/Messages.java
index 3f3c9959..bc324996 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Messages.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/Messages.java
@@ -67,7 +67,7 @@ public class Messages {
User visitor = UserUtils.getCurrentUser();
if (!visitor.isAnonymous()) {
int vuid = visitor.getUid();
- List<Integer> mids = messagesService.getMyFeed(vuid, before_mid);
+ List<Integer> mids = messagesService.getMyFeed(vuid, before_mid, true);
if (!mids.isEmpty())
return ResponseEntity.ok(messagesService.getMessages(mids));
diff --git a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
index be21c3fc..e8045cc2 100644
--- a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
+++ b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
@@ -152,7 +152,7 @@ public class MessagesTests {
Message msg = MockUtils.mockMessage(1, ugnich, msgText);
- when(messagesService.getMyFeed(1, 0))
+ when(messagesService.getMyFeed(1, 0, true))
.thenReturn(Collections.singletonList(1));
when(messagesService.getMessages(Collections.singletonList(1)))
.thenReturn(Collections.singletonList(msg));
@@ -183,7 +183,7 @@ public class MessagesTests {
.thenReturn(Optional.of(user));
when(userService.getFullyUserByName(ugnichName))
.thenReturn(user);
- when(messagesService.getMyFeed(1, 0))
+ when(messagesService.getMyFeed(1, 0, true))
.thenReturn(Collections.singletonList(1));
when(messagesService.getMessages(Collections.singletonList(1)))
.thenReturn(Collections.singletonList(msg));
@@ -213,7 +213,7 @@ public class MessagesTests {
.thenReturn(user);
when(userService.getUserByName(ugnichName))
.thenReturn(user);
- when(messagesService.getMyFeed(1, 0))
+ when(messagesService.getMyFeed(1, 0, false))
.thenReturn(Collections.singletonList(1));
when(messagesService.getMessages(Collections.singletonList(1)))
.thenReturn(Collections.singletonList(msg));
diff --git a/juick-rss/src/test/java/com/juick/rss/tests/RSSTests.java b/juick-rss/src/test/java/com/juick/rss/tests/RSSTests.java
index 2b7430f8..1edfe0d2 100644
--- a/juick-rss/src/test/java/com/juick/rss/tests/RSSTests.java
+++ b/juick-rss/src/test/java/com/juick/rss/tests/RSSTests.java
@@ -154,7 +154,7 @@ public class RSSTests {
Message msg = getMessage(ugnich, msgText);
- when(messagesService.getMyFeed(1, 0))
+ when(messagesService.getMyFeed(1, 0, false))
.thenReturn(Collections.singletonList(1));
when(messagesService.getMessages(Collections.singletonList(1)))
.thenReturn(Collections.singletonList(msg));
diff --git a/juick-server-core/src/main/java/com/juick/server/protocol/JuickProtocol.java b/juick-server-core/src/main/java/com/juick/server/protocol/JuickProtocol.java
index d2d7e1c2..1d5b8dbf 100644
--- a/juick-server-core/src/main/java/com/juick/server/protocol/JuickProtocol.java
+++ b/juick-server-core/src/main/java/com/juick/server/protocol/JuickProtocol.java
@@ -271,7 +271,7 @@ public class JuickProtocol {
public String commandMyFeed(User user, String... arguments) {
// number of # is the page count
int page = arguments[0].length() - 1;
- List<Integer> mids = messagesService.getMyFeed(user.getUid(), page);
+ List<Integer> mids = messagesService.getMyFeed(user.getUid(), page, false);
List<Message> messages = messagesService.getMessages(mids);
// TODO: add instructions for empty feed
return "Your feed: \n" + String.join("\n",
diff --git a/juick-server-core/src/main/java/com/juick/service/MessagesService.java b/juick-server-core/src/main/java/com/juick/service/MessagesService.java
index 6b3d6a53..0644dd99 100644
--- a/juick-server-core/src/main/java/com/juick/service/MessagesService.java
+++ b/juick-server-core/src/main/java/com/juick/service/MessagesService.java
@@ -59,7 +59,7 @@ public interface MessagesService {
List<Integer> getPlace(int placeId, int visitorUid, int before);
- List<Integer> getMyFeed(int uid, int before);
+ List<Integer> getMyFeed(int uid, int before, boolean recommended);
List<Integer> getPrivate(int uid, int before);
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
index caffda14..3533d701 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -445,7 +445,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Transactional(readOnly = true)
@Override
- public List<Integer> getMyFeed(final int uid, final int before) {
+ public List<Integer> getMyFeed(final int uid, final int before, boolean recommended) {
SqlParameterSource sqlParameterSource = new MapSqlParameterSource()
.addValue("uid", uid)
.addValue("before", before);
@@ -462,6 +462,12 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
" (SELECT message_id FROM messages WHERE user_id=:uid " +
(before > 0 ?
" AND message_id < :before " : StringUtils.EMPTY) +
+ (recommended ?
+ ") UNION " +
+ " (SELECT f.message_id as message_id FROM favorites f WHERE " +
+ "EXISTS (SELECT 1 FROM subscr_users s WHERE s.suser_id = :uid and f.user_id = s.user_id)" +
+ (before > 0 ?
+ " AND f.message_id < :before " : StringUtils.EMPTY) : StringUtils.EMPTY) +
") ORDER BY message_id DESC LIMIT 20",
sqlParameterSource,
Integer.class);
diff --git a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java
index fae938cc..64de9424 100644
--- a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java
+++ b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java
@@ -18,11 +18,13 @@
package com.juick.service;
import com.juick.configuration.RepositoryConfiguration;
+import com.juick.server.helpers.AnonymousUser;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import javax.inject.Inject;
+import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@@ -36,20 +38,32 @@ public class MessageServiceTest extends AbstractJUnit4SpringContextTests {
private MessagesService messagesService;
@Inject
private UserService userService;
+ @Inject
+ private SubscriptionService subscriptionService;
+
+ int ugnichId, freefdId, mid;
@Test
public void getMyFeed() {
- messagesService.getMyFeed(1, 1000000);
- }
- @Test
- public void likesCountShouldMatch() {
- int uid = userService.createUser("ugnich", "secret");
- int mid = messagesService.createMessage(uid, "test", null, null);
- int mid2 = messagesService.createMessage(uid, "test2", null, null);
- assertThat(messagesService.recommendMessage(mid, uid), equalTo(true));
+ ugnichId = userService.createUser("ugnich", "secret");
+ freefdId = userService.createUser("freefd", "secret");
+ mid = messagesService.createMessage(ugnichId, "test", null, null);
+ int mid2 = messagesService.createMessage(ugnichId, "test2", null, null);
+ subscriptionService.subscribeUser(userService.getUserByUID(freefdId).orElse(AnonymousUser.INSTANCE),
+ userService.getUserByUID(ugnichId).orElse(AnonymousUser.INSTANCE));
+ List<Integer> freefdFeed = messagesService.getMyFeed(freefdId, 0, false);
+ assertThat(freefdFeed.size(), equalTo(2));
+ int tonyaid = userService.createUser("Tonya", "secret");
+ int mid3 = messagesService.createMessage(tonyaid, "test3", null, null);
+ messagesService.recommendMessage(mid3, ugnichId);
+ assertThat(messagesService.getMyFeed(freefdId, 0, false).size(), equalTo(2));
+ assertThat(messagesService.getMyFeed(freefdId, 0, true).size(), equalTo(3));
+ assertThat(messagesService.getMyFeed(freefdId, mid2, true).size(), equalTo(1));
+ assertThat(messagesService.getMyFeed(freefdId, mid, false).size(), equalTo(0));
+ assertThat(messagesService.recommendMessage(mid, ugnichId), equalTo(true));
assertThat(messagesService.getMessage(mid).getLikes(), equalTo(1));
- assertThat(messagesService.recommendMessage(mid, uid), equalTo(false));
+ assertThat(messagesService.recommendMessage(mid, ugnichId), equalTo(false));
assertThat(messagesService.getMessage(mid).getLikes(), equalTo(0));
- assertThat(messagesService.getAll(uid, 0).size(), equalTo(2));
+ assertThat(messagesService.getAll(ugnichId, 0).size(), equalTo(3));
}
}
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Home.java b/juick-www/src/main/java/com/juick/www/controllers/Home.java
index f46187ed..763d829e 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/Home.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/Home.java
@@ -126,7 +126,7 @@ public class Home {
return "redirect:/";
} else if (paramShow.equals("my") && visitor != null) {
title = "Моя лента";
- mids = messagesService.getMyFeed(visitor.getUid(), paramBefore);
+ mids = messagesService.getMyFeed(visitor.getUid(), paramBefore, true);
} else if (paramShow.equals("private") && visitor != null) {
title = "Приватные";
mids = messagesService.getPrivate(visitor.getUid(), paramBefore);
diff --git a/juick-www/src/main/webapp/WEB-INF/views/partial/navigation.html b/juick-www/src/main/webapp/WEB-INF/views/partial/navigation.html
index 6930e9a9..552532b1 100644
--- a/juick-www/src/main/webapp/WEB-INF/views/partial/navigation.html
+++ b/juick-www/src/main/webapp/WEB-INF/views/partial/navigation.html
@@ -20,7 +20,6 @@
<li><a href="/?show=my">{{ i18n("messages","link.my") }}</a></li>
<li><a href="/pm/inbox">{{ i18n("messages","link.privateMessages") }}</a></li>
<li><a href="/?show=discuss">{{ i18n("messages","link.discuss") }}</a></li>
- <li><a href="/?show=recommended">{{ i18n("messages","link.recommended") }}</a></li>
</ul>
</nav>
<nav id="actions">
diff --git a/juick-www/src/test/java/com/juick/www/WebAppTests.java b/juick-www/src/test/java/com/juick/www/WebAppTests.java
index 0aba7e37..c2f6b0d9 100644
--- a/juick-www/src/test/java/com/juick/www/WebAppTests.java
+++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java
@@ -127,7 +127,7 @@ public class WebAppTests {
.thenReturn(Optional.of(user));
when(userService.getFullyUserByName(ugnichName))
.thenReturn(user);
- when(messagesService.getMyFeed(1, 0))
+ when(messagesService.getMyFeed(1, 0, false))
.thenReturn(Collections.singletonList(1));
when(messagesService.getMessages(Collections.singletonList(1)))
.thenReturn(Collections.singletonList(msg));
@@ -158,7 +158,7 @@ public class WebAppTests {
.thenReturn(Optional.of(user));
when(userService.getFullyUserByName(userName))
.thenReturn(user);
- when(messagesService.getMyFeed(2, 0))
+ when(messagesService.getMyFeed(2, 0, false))
.thenReturn(Collections.singletonList(2));
when(messagesService.getMessages(Collections.singletonList(2)))
.thenReturn(Collections.singletonList(msg));
@@ -234,7 +234,7 @@ public class WebAppTests {
.thenReturn(Optional.of(user));
when(userService.getFullyUserByName(ugnichName))
.thenReturn(user);
- when(messagesService.getMyFeed(1, 0))
+ when(messagesService.getMyFeed(1, 0, false))
.thenReturn(Collections.singletonList(1));
when(messagesService.getMessages(Collections.singletonList(1)))
.thenReturn(Collections.singletonList(msg));