From 49c4b7f3ccbd4e22f500ea2f46e520786d8a8ab1 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 11 Sep 2017 21:00:02 +0300 Subject: no more recommended tab --- .../java/com/juick/api/controllers/Messages.java | 2 +- .../java/com/juick/api/tests/MessagesTests.java | 6 ++-- .../test/java/com/juick/rss/tests/RSSTests.java | 2 +- .../com/juick/server/protocol/JuickProtocol.java | 2 +- .../java/com/juick/service/MessagesService.java | 2 +- .../com/juick/service/MessagesServiceImpl.java | 8 ++++- .../java/com/juick/service/MessageServiceTest.java | 34 +++++++++++++++------- .../main/java/com/juick/www/controllers/Home.java | 2 +- .../webapp/WEB-INF/views/partial/navigation.html | 1 - .../src/test/java/com/juick/www/WebAppTests.java | 6 ++-- 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 mids = messagesService.getMyFeed(vuid, before_mid); + List 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 mids = messagesService.getMyFeed(user.getUid(), page); + List mids = messagesService.getMyFeed(user.getUid(), page, false); List 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 getPlace(int placeId, int visitorUid, int before); - List getMyFeed(int uid, int before); + List getMyFeed(int uid, int before, boolean recommended); List 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 getMyFeed(final int uid, final int before) { + public List 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 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 @@
  • {{ i18n("messages","link.my") }}
  • {{ i18n("messages","link.privateMessages") }}
  • {{ i18n("messages","link.discuss") }}
  • -
  • {{ i18n("messages","link.recommended") }}