diff options
11 files changed, 46 insertions, 98 deletions
diff --git a/juick-common/src/main/java/com/juick/service/SubscriptionService.java b/juick-common/src/main/java/com/juick/service/SubscriptionService.java index 47f81415..3bd58aed 100644 --- a/juick-common/src/main/java/com/juick/service/SubscriptionService.java +++ b/juick-common/src/main/java/com/juick/service/SubscriptionService.java @@ -17,6 +17,7 @@ package com.juick.service; +import com.juick.Message; import com.juick.Tag; import com.juick.User; import com.juick.server.helpers.NotifyOpts; @@ -31,7 +32,7 @@ public interface SubscriptionService { List<User> getSubscribedUsers(int uid, int mid); - List<User> getUsersSubscribedToComments(int mid, int ignore_uid); + List<User> getUsersSubscribedToComments(Message msg, Message reply); List<User> getUsersSubscribedToUserRecommendations(int uid, int mid, int muid); diff --git a/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java index eb3f79a9..77735b0c 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java @@ -17,6 +17,7 @@ package com.juick.service; +import com.juick.Message; import com.juick.Tag; import com.juick.User; import com.juick.server.helpers.NotifyOpts; @@ -27,6 +28,7 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; +import javax.annotation.Nonnull; import javax.inject.Inject; import java.util.Collections; import java.util.HashSet; @@ -102,15 +104,17 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip @Transactional(readOnly = true) @Override - public List<User> getUsersSubscribedToComments(final int mid, final int ignore_uid) { + public List<User> getUsersSubscribedToComments(@Nonnull final Message msg, @Nonnull final Message reply) { List<Integer> userids = getJdbcTemplate().queryForList( "SELECT suser_id FROM subscr_messages WHERE message_id=? AND suser_id!=?", Integer.class, - mid, ignore_uid); - - if (!userids.isEmpty()) - return userService.getUsersByID(userids); + msg.getMid(), reply.getUser().getUid()); + if (!userids.isEmpty()) { + return userService.getUsersByID(userids.stream() + .filter(u -> !userService.isInBLAny(u, reply.getUser().getUid())) + .collect(Collectors.toList())); + } return Collections.emptyList(); } 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 4ef06789..57e0970a 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 @@ -179,8 +179,11 @@ public class MessageServiceTest extends AbstractJUnit4SpringContextTests { assertEquals("weather", msg3.getTags().get(0).getName()); assertEquals(ugnich.getUid(), userService.checkPassword(ugnich.getName(), "x")); assertEquals(-1, userService.checkPassword(ugnich.getName(), "xy")); + subscriptionService.subscribeMessage(msg.getMid(), user.getUid()); subscriptionService.subscribeMessage(msg.getMid(), ugnich.getUid()); - assertEquals(1, subscriptionService.getUsersSubscribedToComments(msg.getMid(), user.getUid()).size()); + int reply_id = messagesService.createReply(msg.getMid(), 0, ugnich_id, "comment", null); + assertEquals(1, subscriptionService.getUsersSubscribedToComments(msg, + messagesService.getReply(msg.getMid(), reply_id)).size()); assertThat(messagesService.getDiscussions(ugnich.getUid(), Instant.now().toEpochMilli()).get(0), equalTo(msg.getMid())); messagesService.deleteMessage(user_id, mid); diff --git a/juick-server/src/main/java/com/juick/server/EmailManager.java b/juick-server/src/main/java/com/juick/server/EmailManager.java index 8dd7e06e..83db3ac3 100644 --- a/juick-server/src/main/java/com/juick/server/EmailManager.java +++ b/juick-server/src/main/java/com/juick/server/EmailManager.java @@ -52,9 +52,10 @@ public class EmailManager implements ApplicationListener<MessageEvent> { } else if (msg.getRid() > 0) { Message originalMessage = messagesService.getMessage(msg.getMid()); String subject = String.format("New reply to %s", originalMessage.getUser().getName()); - subscriptionService.getUsersSubscribedToComments(msg.getMid(), msg.getUser().getUid()) - .forEach(user -> emailService.getEmails(user.getUid(), true) - .forEach(email -> emailNotify(email, subject, msg))); + subscriptionService.getUsersSubscribedToComments(originalMessage, msg) + .stream().filter(user -> !userService.isInBLAny(user.getUid(), msg.getUser().getUid())) + .flatMap(user -> emailService.getEmails(user.getUid(), true).stream()) + .forEach(email -> emailNotify(email, subject, msg)); } } diff --git a/juick-server/src/main/java/com/juick/server/MessengerManager.java b/juick-server/src/main/java/com/juick/server/MessengerManager.java index 14a43d6a..1fe04aca 100644 --- a/juick-server/src/main/java/com/juick/server/MessengerManager.java +++ b/juick-server/src/main/java/com/juick/server/MessengerManager.java @@ -112,12 +112,11 @@ public class MessengerManager implements ApplicationListener<MessageEvent> { .forEach(user -> messengerService.getSenderId(user) .ifPresent(t -> messengerNotify(t, subject, formatUrl(msg)))); } else if (msg.getRid() > 0) { - // get quote - com.juick.Message jmsg = messagesService.getReply(msg.getMid(), msg.getRid()); - String subject = formatPost(jmsg); - subscriptionService.getUsersSubscribedToComments(msg.getMid(), msg.getUser().getUid()) + Message op = messagesService.getMessage(msg.getMid()); + String subject = formatPost(msg); + subscriptionService.getUsersSubscribedToComments(op, msg) .forEach(user -> messengerService.getSenderId(user) - .ifPresent(t -> messengerNotify(t, subject, formatUrl(jmsg)))); + .ifPresent(t -> messengerNotify(t, subject, formatUrl(msg)))); } } diff --git a/juick-server/src/main/java/com/juick/server/ServerManager.java b/juick-server/src/main/java/com/juick/server/ServerManager.java index 30740a76..ca22aa35 100644 --- a/juick-server/src/main/java/com/juick/server/ServerManager.java +++ b/juick-server/src/main/java/com/juick/server/ServerManager.java @@ -226,8 +226,9 @@ public class ServerManager implements AutoCloseable { private void onJuickMessageReply(final com.juick.Message jmsg) throws JsonProcessingException { String json = jsonMapper.writeValueAsString(jmsg); + com.juick.Message op = messagesService.getMessage(jmsg.getMid()); List<Integer> threadUsers = - subscriptionService.getUsersSubscribedToComments(jmsg.getMid(), jmsg.getUser().getUid()) + subscriptionService.getUsersSubscribedToComments(op, jmsg) .stream().map(User::getUid).collect(Collectors.toList()); synchronized (wsHandler.getClients()) { wsHandler.getClients().stream().filter(c -> diff --git a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java index 697f6dd1..2793f906 100644 --- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java +++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java @@ -230,11 +230,10 @@ public class TelegramBotManager implements ApplicationListener<MessageEvent> { // anonymous chats.stream().filter(u -> telegramService.getUser(u) == 0).forEach(c -> telegramNotify(c, msg, MessageUtils.attachmentUrl(jmsg))); } else if (jmsg.getRid() > 0) { - // get quote - com.juick.Message msg = messagesService.getReply(jmsg.getMid(), jmsg.getRid()); - String fmsg = String.format("[%s](%s) %s", MSG_LINK, msgUrl, formatPost(msg, true)); + com.juick.Message op = messagesService.getMessage(jmsg.getMid()); + String fmsg = String.format("[%s](%s) %s", MSG_LINK, msgUrl, formatPost(jmsg, true)); telegramService.getTelegramIdentifiers( - subscriptionService.getUsersSubscribedToComments(jmsg.getMid(), jmsg.getUser().getUid()) + subscriptionService.getUsersSubscribedToComments(op, jmsg) ).forEach(c -> telegramNotify(c, fmsg, MessageUtils.attachmentUrl(jmsg))); } } diff --git a/juick-server/src/main/java/com/juick/server/XMPPConnection.java b/juick-server/src/main/java/com/juick/server/XMPPConnection.java index 4bfcd833..69d39c18 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java @@ -160,7 +160,9 @@ public class XMPPConnection implements AutoCloseable { sendJuickRecommendation(jmsg); } else { if (jmsg.getRid() > 0) { - sendJuickComment(jmsg); + // to get quote and attachment + com.juick.Message reply = messagesService.getReply(jmsg.getMid(), jmsg.getRid()); + sendJuickComment(reply); } else if (jmsg.getMid() > 0) { sendJuickMessage(jmsg); } @@ -332,7 +334,8 @@ public class XMPPConnection implements AutoCloseable { String replyQuote; String replyTo; - users = subscriptionService.getUsersSubscribedToComments(jmsg.getMid(), jmsg.getUser().getUid()); + com.juick.Message op = messagesService.getMessage(jmsg.getMid()); + users = subscriptionService.getUsersSubscribedToComments(op, jmsg); com.juick.Message replyMessage = jmsg.getReplyto() > 0 ? messagesService.getReply(jmsg.getMid(), jmsg.getReplyto()) : messagesService.getMessage(jmsg.getMid()); replyTo = replyMessage.getUser().getName(); diff --git a/juick-server/src/main/java/com/juick/server/api/Notifications.java b/juick-server/src/main/java/com/juick/server/api/Notifications.java index 16601b7f..94b66746 100644 --- a/juick-server/src/main/java/com/juick/server/api/Notifications.java +++ b/juick-server/src/main/java/com/juick/server/api/Notifications.java @@ -84,8 +84,9 @@ public class Notifications { if (msg != null) { List<User> users; if (rid > 0) { + Message op = messagesService.getMessage(mid); Message reply = messagesService.getReply(mid, rid); - users = subscriptionService.getUsersSubscribedToComments(mid, reply.getUser().getUid()); + users = subscriptionService.getUsersSubscribedToComments(op, reply); } else { users = subscriptionService.getSubscribedUsers(msg.getUser().getUid(), mid); } diff --git a/juick-server/src/main/java/com/juick/server/api/Service.java b/juick-server/src/main/java/com/juick/server/api/Service.java deleted file mode 100644 index 12ffee9c..00000000 --- a/juick-server/src/main/java/com/juick/server/api/Service.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.server.api; - -import com.juick.Message; -import com.juick.User; -import com.juick.server.util.HttpBadRequestException; -import com.juick.server.util.HttpForbiddenException; -import com.juick.server.util.UserUtils; -import com.juick.service.CrosspostService; -import com.juick.service.MessagesService; -import com.juick.service.SubscriptionService; -import com.juick.service.UserService; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import springfox.documentation.annotations.ApiIgnore; - -import javax.inject.Inject; -import java.io.IOException; -import java.util.List; - -/** - * TODO: configure spring-security to allow only admin role - */ -@ApiIgnore -@RestController -public class Service { - @Inject - private SubscriptionService subscriptionService; - @Inject - private MessagesService messagesService; - @Inject - private CrosspostService crosspostService; - @Inject - private UserService userService; - - @RequestMapping(value = "/subscriptions", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) - public List<User> doGet( - @RequestParam(defaultValue = "0") int mid, - @RequestParam(defaultValue = "0") int uid) throws IOException { - User visitor = UserUtils.getCurrentUser(); - if ((visitor.getUid() == 0) && !(visitor.getName().equals("juick"))) { - throw new HttpForbiddenException(); - } - if (uid > 0) { - return subscriptionService.getSubscribedUsers(uid, mid); - } else { - // thread - Message msg = messagesService.getMessage(mid); - if (msg != null) { - return subscriptionService.getUsersSubscribedToComments(mid, msg.getUser().getUid()); - } - } - throw new HttpBadRequestException(); - } -} 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 99453f32..f831141b 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 @@ -96,6 +96,8 @@ public class ServerTests extends AbstractJUnit4SpringContextTests { @Inject private SubscriptionService subscriptionService; @Inject + private PrivacyQueriesService privacyQueriesService; + @Inject private JdbcTemplate jdbcTemplate; @Value("${hostname:localhost}") private Jid jid; @@ -389,8 +391,16 @@ public class ServerTests extends AbstractJUnit4SpringContextTests { assertEquals("should be favorited", "Message added to your recommendations", juickProtocol.getReply(readerUser, "! #" + mid)); */ + int rid = messagesService.createReply(mid, 0, uid, "comment", null); assertEquals("number of subscribed users should match", 1, - subscriptionService.getUsersSubscribedToComments(mid, uid).size()); + subscriptionService.getUsersSubscribedToComments( + messagesService.getMessage(mid), + messagesService.getReply(mid, rid)).size()); + privacyQueriesService.blacklistUser(user, readerUser); + assertEquals("number of subscribed users should match", 0, + subscriptionService.getUsersSubscribedToComments( + messagesService.getMessage(mid), + messagesService.getReply(mid, rid)).size()); /* assertEquals("should be subscribed", "Subscribed", bot.processCommand(readerUser, Jid.of("dummy@localhost"), "S @" + user.getName()).get()); |