aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-12 14:17:46 +0300
committerGravatar Vitaly Takmazov2018-04-12 14:17:46 +0300
commit9e5a6b3f2f6907f18f22718bcb6f0ac7f79c95cd (patch)
tree06d4eab436f56607f324cd2c43808854c35a6dfc /juick-server/src
parente24f7a7ce9eb765aa2f581defbe20433a647700d (diff)
server: MessageEvent now have list of subscribers
Diffstat (limited to 'juick-server/src')
-rw-r--r--juick-server/src/main/java/com/juick/server/EmailManager.java10
-rw-r--r--juick-server/src/main/java/com/juick/server/MessengerManager.java8
-rw-r--r--juick-server/src/main/java/com/juick/server/ServerManager.java21
-rw-r--r--juick-server/src/main/java/com/juick/server/TelegramBotManager.java11
-rw-r--r--juick-server/src/main/java/com/juick/server/TwitterManager.java1
-rw-r--r--juick-server/src/main/java/com/juick/server/WebsocketManager.java2
-rw-r--r--juick-server/src/main/java/com/juick/server/api/PM.java3
7 files changed, 25 insertions, 31 deletions
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 b185de5c..2bea7060 100644
--- a/juick-server/src/main/java/com/juick/server/EmailManager.java
+++ b/juick-server/src/main/java/com/juick/server/EmailManager.java
@@ -1,6 +1,7 @@
package com.juick.server;
import com.juick.Message;
+import com.juick.User;
import com.juick.server.component.MessageEvent;
import com.juick.service.EmailService;
import com.juick.service.MessagesService;
@@ -22,6 +23,7 @@ import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
+import java.util.List;
import java.util.Properties;
import static com.juick.formatters.PlainTextFormatter.formatPost;
@@ -36,14 +38,13 @@ public class EmailManager implements ApplicationListener<MessageEvent> {
@Inject
private EmailService emailService;
@Inject
- private SubscriptionService subscriptionService;
- @Inject
private MessagesService messagesService;
@Inject
private UserService userService;
@Override
public void onApplicationEvent(@Nonnull MessageEvent event) {
Message msg = event.getMessage();
+ List<User> subscribedUsers = event.getUsers();
if (MessageUtils.isPM(msg)) {
String subject = String.format("Private message from %s", msg.getUser().getName());
emailService.getEmails(msg.getTo().getUid(), true).forEach(email -> {
@@ -52,13 +53,12 @@ public class EmailManager implements ApplicationListener<MessageEvent> {
} else if (MessageUtils.isReply(msg)) {
Message originalMessage = messagesService.getMessage(msg.getMid());
String subject = String.format("New reply to %s", originalMessage.getUser().getName());
- subscriptionService.getUsersSubscribedToComments(originalMessage, msg)
- .stream().filter(user -> !userService.isInBLAny(user.getUid(), msg.getUser().getUid()))
+ subscribedUsers.stream()
.flatMap(user -> emailService.getEmails(user.getUid(), true).stream())
.forEach(email -> emailNotify(email, subject, msg));
} else {
String subject = String.format("New message from %s", msg.getUser().getName());
- subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg.getMid())
+ subscribedUsers
.forEach(user -> emailService.getEmails(user.getUid(), true)
.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 9192288f..323eef7c 100644
--- a/juick-server/src/main/java/com/juick/server/MessengerManager.java
+++ b/juick-server/src/main/java/com/juick/server/MessengerManager.java
@@ -34,6 +34,7 @@ import java.net.URI;
import java.net.URL;
import java.time.Instant;
import java.util.Collections;
+import java.util.List;
import java.util.Optional;
import static com.juick.formatters.PlainTextFormatter.formatPost;
@@ -45,8 +46,6 @@ public class MessengerManager implements ApplicationListener<MessageEvent> {
@Inject
private MessagesService messagesService;
@Inject
- private SubscriptionService subscriptionService;
- @Inject
private UserService userService;
@Inject
private MessengerService messengerService;
@@ -111,15 +110,16 @@ public class MessengerManager implements ApplicationListener<MessageEvent> {
@Override
public void onApplicationEvent(@Nonnull MessageEvent event) {
Message msg = event.getMessage();
+ List<User> subscribedUsers = event.getUsers();
if (msg.getMid() > 0 && msg.getRid() == 0) {
String subject = formatPost(msg);
- subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg.getMid())
+ subscribedUsers
.forEach(user -> messengerService.getSenderId(user)
.ifPresent(t -> messengerNotify(t, subject, formatUrl(msg))));
} else if (msg.getRid() > 0) {
Message op = messagesService.getMessage(msg.getMid());
String subject = formatPost(msg);
- subscriptionService.getUsersSubscribedToComments(op, msg)
+ subscribedUsers
.forEach(user -> messengerService.getSenderId(user)
.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 40de9d3e..f209d934 100644
--- a/juick-server/src/main/java/com/juick/server/ServerManager.java
+++ b/juick-server/src/main/java/com/juick/server/ServerManager.java
@@ -22,18 +22,16 @@ import com.juick.User;
import com.juick.server.component.MessageEvent;
import com.juick.service.MessagesService;
import com.juick.service.SubscriptionService;
-import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
-import rocks.xmpp.addr.Jid;
+import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.io.IOException;
-import java.net.URI;
import java.util.List;
import java.util.stream.Collectors;
@@ -49,8 +47,6 @@ public class ServerManager implements ApplicationListener<MessageEvent> {
@Inject
private MessagesService messagesService;
@Inject
- private SubscriptionService subscriptionService;
- @Inject
private WebsocketManager wsHandler;
@Value("${service_user:juick}")
private String serviceUser;
@@ -77,10 +73,10 @@ public class ServerManager implements ApplicationListener<MessageEvent> {
}
}
- private void onJuickMessagePost(final com.juick.Message jmsg) {
+ private void onJuickMessagePost(final com.juick.Message jmsg, List<User> subscribedUsers) {
try {
String json = jsonMapper.writeValueAsString(jmsg);
- List<Integer> uids = subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid())
+ List<Integer> uids = subscribedUsers
.stream().map(User::getUid).collect(Collectors.toList());
synchronized (wsHandler.getClients()) {
wsHandler.getClients().stream().filter(c ->
@@ -111,13 +107,13 @@ public class ServerManager implements ApplicationListener<MessageEvent> {
}
}
- private void onJuickMessageReply(final com.juick.Message jmsg) {
+ private void onJuickMessageReply(final com.juick.Message jmsg, final List<User> subscribedUsers) {
try {
String json = jsonMapper.writeValueAsString(jmsg);
com.juick.Message op = messagesService.getMessage(jmsg.getMid());
List<Integer> threadUsers =
- subscriptionService.getUsersSubscribedToComments(op, jmsg)
+ subscribedUsers
.stream().map(User::getUid).collect(Collectors.toList());
synchronized (wsHandler.getClients()) {
wsHandler.getClients().stream().filter(c ->
@@ -149,19 +145,20 @@ public class ServerManager implements ApplicationListener<MessageEvent> {
}
@Override
- public void onApplicationEvent(MessageEvent event) {
+ public void onApplicationEvent(@Nonnull MessageEvent event) {
com.juick.Message jmsg = event.getMessage();
+ List<User> subscribedUsers = event.getUsers();
if (jmsg.getMid() == 0) {
if (jmsg.getTo().getUid() > 0) {
onJuickPM(jmsg.getTo().getUid(), jmsg);
}
} else if (jmsg.getRid() == 0) {
// to get full message with attachment, etc.
- onJuickMessagePost(messagesService.getMessage(jmsg.getMid()));
+ onJuickMessagePost(messagesService.getMessage(jmsg.getMid()), subscribedUsers);
} else {
// to get quote and attachment
com.juick.Message reply = messagesService.getReply(jmsg.getMid(), jmsg.getRid());
- onJuickMessageReply(reply);
+ onJuickMessageReply(reply, subscribedUsers);
}
}
}
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 e1bdad1f..95d91679 100644
--- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
+++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
@@ -77,8 +77,6 @@ public class TelegramBotManager implements NotificationListener {
@Inject
private MessagesService messagesService;
@Inject
- private SubscriptionService subscriptionService;
- @Inject
private UserService userService;
@Inject
private CommandsManager commandsManager;
@@ -321,6 +319,7 @@ public class TelegramBotManager implements NotificationListener {
@Override
public void processMessageEvent(MessageEvent messageEvent) {
com.juick.Message jmsg = messageEvent.getMessage();
+ List<User> subscribedUsers = messageEvent.getUsers();
String msgUrl = formatUrl(jmsg);
if (MessageUtils.isPM(jmsg)) {
telegramService.getTelegramIdentifiers(Collections.singletonList(jmsg.getTo()))
@@ -329,12 +328,12 @@ public class TelegramBotManager implements NotificationListener {
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(op, jmsg)
+ subscribedUsers
).forEach(c -> telegramNotify(c, fmsg, MessageUtils.attachmentUrl(jmsg)));
} else {
String msg = String.format("[%s](%s) %s", MSG_LINK, msgUrl, formatPost(jmsg, true));
- List<Long> users = telegramService.getTelegramIdentifiers(subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid()));
+ List<Long> users = telegramService.getTelegramIdentifiers(subscribedUsers);
List<Long> chats = telegramService.getChats();
// registered subscribed users
@@ -347,12 +346,12 @@ public class TelegramBotManager implements NotificationListener {
public void processLikeEvent(LikeEvent likeEvent) {
User liker = likeEvent.getUser();
com.juick.Message message = likeEvent.getMessage();
+ List<User> subscribers = likeEvent.getSubscribers();
logger.info("Like received in tg listener");
telegramService.getTelegramIdentifiers(Collections.singletonList(message.getUser()))
.forEach(c -> telegramNotify(c, String.format("%s recommends your [post](%s)",
MessageUtils.getMarkdownUser(liker), formatUrl(message)),null));
- telegramService.getTelegramIdentifiers(subscriptionService.getUsersSubscribedToUserRecommendations(
- liker.getUid(), message.getMid(), message.getUser().getUid()))
+ telegramService.getTelegramIdentifiers(subscribers)
.forEach(c -> telegramNotify(c, String.format("%s recommends you someone's [post](%s)",
MessageUtils.getMarkdownUser(liker), formatUrl(message)), null));
}
diff --git a/juick-server/src/main/java/com/juick/server/TwitterManager.java b/juick-server/src/main/java/com/juick/server/TwitterManager.java
index 7d4f8ccc..35dca744 100644
--- a/juick-server/src/main/java/com/juick/server/TwitterManager.java
+++ b/juick-server/src/main/java/com/juick/server/TwitterManager.java
@@ -31,7 +31,6 @@ import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;
import javax.annotation.Nonnull;
-import javax.annotation.PostConstruct;
import javax.inject.Inject;
/**
diff --git a/juick-server/src/main/java/com/juick/server/WebsocketManager.java b/juick-server/src/main/java/com/juick/server/WebsocketManager.java
index 4beb3190..c43e191c 100644
--- a/juick-server/src/main/java/com/juick/server/WebsocketManager.java
+++ b/juick-server/src/main/java/com/juick/server/WebsocketManager.java
@@ -63,8 +63,6 @@ public class WebsocketManager extends TextWebSocketHandler {
private UserService userService;
@Inject
private MessagesService messagesService;
- @Inject
- private SubscriptionService subscriptionService;
@Value("${service_user:juick}")
private String serviceUser;
@Inject
diff --git a/juick-server/src/main/java/com/juick/server/api/PM.java b/juick-server/src/main/java/com/juick/server/api/PM.java
index 357b68dc..a09ecc2d 100644
--- a/juick-server/src/main/java/com/juick/server/api/PM.java
+++ b/juick-server/src/main/java/com/juick/server/api/PM.java
@@ -35,6 +35,7 @@ import rocks.xmpp.addr.Jid;
import rocks.xmpp.core.stanza.model.Message;
import javax.inject.Inject;
+import java.util.Collections;
import java.util.List;
/**
@@ -98,7 +99,7 @@ public class PM {
jmsg.setUser(visitor);
jmsg.setText(body);
jmsg.setTo(userTo);
- applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg));
+ applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg, Collections.singletonList(jmsg.getTo())));
return jmsg;
}