aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src')
-rw-r--r--juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java34
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java32
2 files changed, 40 insertions, 26 deletions
diff --git a/juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java
index c567b5cd..e8c32e77 100644
--- a/juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java
@@ -26,7 +26,6 @@ import org.springframework.dao.DuplicateKeyException;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.Assert;
import javax.annotation.Nonnull;
import javax.inject.Inject;
@@ -113,34 +112,17 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip
return Collections.emptyList();
}
- @Transactional(readOnly = true)
@Override
public List<User> getUsersSubscribedToUserRecommendations(final int uid, final int mid, final int muid) {
- List<Integer> tags = tagService.getMessageTagsIDs(mid);
-
- String query = "SELECT s.suser_id FROM subscr_users s WHERE s.user_id = :uid " +
- " AND NOT EXISTS (SELECT 1 FROM bl_users b WHERE b.bl_user_id = :muid and b.user_id = s.user_id) " +
- " AND NOT EXISTS (SELECT 1 FROM subscr_users s1 WHERE s1.user_id = :muid AND s.user_id = s1.suser_id) " +
- " AND NOT EXISTS (SELECT 1 FROM subscr_messages sm WHERE sm.message_id = :mid AND s.user_id = sm.suser_id) " +
- " AND NOT EXISTS (SELECT 1 FROM favorites WHERE favorites.message_id = :mid AND favorites.user_id = s.user_id) " +
- " AND s.user_id NOT IN (SELECT s2.suser_id FROM subscr_users s2 " +
- " INNER JOIN favorites f ON (f.message_id = :mid AND s2.user_id = f.user_id AND f.user_id != :uid))";
-
- MapSqlParameterSource sqlParameterSource = new MapSqlParameterSource()
- .addValue("uid", uid)
- .addValue("muid", muid)
- .addValue("mid", mid);
-
- if (!tags.isEmpty()) {
- sqlParameterSource.addValue("ids", tags);
- query += " AND NOT EXISTS (SELECT 1 FROM subscr_tags st WHERE st.tag_id IN (:ids) AND s.user_id = st.suser_id) " +
- " AND NOT EXISTS (SELECT 1 FROM bl_tags b WHERE b.tag_id IN (:ids) AND s.user_id = b.user_id)";
+ Message msg = messagesService.getMessage(mid);
+ List<String> msgTags = tagService.getMessageTags(mid).stream().map(t -> t.getTag().getName()).collect(Collectors.toList());
+ if (msg.getLikes() == 1) {
+ return userService.getUserReaders(uid).stream()
+ .filter(u -> !userService.isInBLAny(u.getUid(), muid))
+ .filter(u -> Collections.disjoint(tagService.getUserBLTags(u.getUid()), msgTags))
+ .collect(Collectors.toList());
}
-
- List<Integer> userids = getNamedParameterJdbcTemplate().queryForList(
- query, sqlParameterSource, Integer.class);
-
- return userService.getUsersByID(userids);
+ return Collections.emptyList();
}
@Transactional
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index 2d28dc9d..646e1443 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -1168,4 +1168,36 @@ public class ServerTests {
assertThat(editedComment.getUpdatedAt(), greaterThan(editedComment.getTimestamp()));
messagesService.deleteMessage(ugnich.getUid(), original.getMid());
}
+ @Test
+ public void subscribersToRecommendations() {
+ int readerId = userService.createUser("reader", "123456");
+ int recommenderId = userService.createUser("recommender", "123456");
+ int lateRecommenderId = userService.createUser("lateRecommender", "123456");
+ int posterId = userService.createUser("poster", "123456");
+ User reader = userService.getUserByName("reader");
+ User recommender = userService.getUserByName("recommender");
+ User lateRecommender = userService.getUserByName("lateRecommender");
+ User poster = userService.getUserByName("poster");
+ subscriptionService.subscribeUser(reader, recommender);
+ subscriptionService.subscribeUser(reader, lateRecommender);
+ Tag sampleTag = tagService.getTag("banned", true);
+ int posterMid = messagesService.createMessage(posterId, "YO", null, Collections.singletonList(sampleTag));
+ messagesService.recommendMessage(posterMid, recommenderId);
+ BiFunction<Integer, Integer, List<User>> subscribers = (recommId, msgId) ->
+ subscriptionService.getUsersSubscribedToUserRecommendations(recommId, msgId, posterId);
+ List<User> recommendSubscribers = subscribers.apply(recommenderId, posterMid);
+ assertThat(recommendSubscribers.size(), is(1));
+ assertThat(recommendSubscribers.get(0).getUid(), is(readerId));
+ privacyQueriesService.blacklistUser(reader, poster);
+ assertThat(subscribers.apply(recommenderId, posterMid).size(), is(0));
+ privacyQueriesService.blacklistUser(reader, poster);
+ assertThat(subscribers.apply(recommenderId, posterMid).size(), is(1));
+ tagService.blacklistTag(reader, sampleTag);
+ assertThat(subscribers.apply(recommenderId, posterMid).size(), is(0));
+ tagService.blacklistTag(reader, sampleTag);
+ assertThat(subscribers.apply(recommenderId, posterMid).size(), is(1));
+ messagesService.recommendMessage(posterMid, lateRecommenderId);
+ List<User> lateRecommendSubscribers = subscribers.apply(recommenderId, posterMid);
+ assertThat(lateRecommendSubscribers.size(), is(0));
+ }
}