aboutsummaryrefslogtreecommitdiff
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
parente24f7a7ce9eb765aa2f581defbe20433a647700d (diff)
server: MessageEvent now have list of subscribers
-rw-r--r--juick-common/src/main/java/com/juick/server/CommandsManager.java11
-rw-r--r--juick-common/src/main/java/com/juick/server/component/LikeEvent.java10
-rw-r--r--juick-common/src/main/java/com/juick/server/component/MessageEvent.java11
-rw-r--r--juick-notifications/src/main/java/com/juick/components/Notifications.java11
-rw-r--r--juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java5
-rw-r--r--juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java26
-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
13 files changed, 71 insertions, 59 deletions
diff --git a/juick-common/src/main/java/com/juick/server/CommandsManager.java b/juick-common/src/main/java/com/juick/server/CommandsManager.java
index cde6a4bf..9b7cda32 100644
--- a/juick-common/src/main/java/com/juick/server/CommandsManager.java
+++ b/juick-common/src/main/java/com/juick/server/CommandsManager.java
@@ -110,7 +110,7 @@ public class CommandsManager {
imagesService.saveImageWithPreviews(attachmentFName, fname);
}
com.juick.Message msg = messagesService.getMessage(mid);
- applicationEventPublisher.publishEvent(new MessageEvent(this, msg));
+ applicationEventPublisher.publishEvent(new MessageEvent(this, msg, subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg.getMid())));
return CommandResult.build(msg, "New message posted.\n#" + msg.getMid() + " https://juick.com/" + msg.getMid(), String.format("[New message](%s) posted", PlainTextFormatter.formatUrl(msg)));
}
@@ -148,7 +148,7 @@ public class CommandsManager {
jmsg.setUser(user_from);
jmsg.setTo(user_to);
jmsg.setText(body);
- applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg));
+ applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg, Collections.singletonList(user_to)));
return CommandResult.fromString("Private message sent");
}
}
@@ -283,7 +283,9 @@ public class CommandsManager {
MessagesService.RecommendStatus status = messagesService.recommendMessage(mid, user.getUid());
switch (status) {
case Added:
- applicationEventPublisher.publishEvent(new LikeEvent(this, user, msg));
+ applicationEventPublisher.publishEvent(new LikeEvent(this, user, msg,
+ subscriptionService.getUsersSubscribedToUserRecommendations(
+ user.getUid(), msg.getMid(), msg.getUser().getUid())));
return CommandResult.fromString("Message is added to your recommendations");
case Deleted:
return CommandResult.fromString("Message deleted from your recommendations.");
@@ -485,8 +487,9 @@ public class CommandsManager {
String fname = String.format("%d-%d.%s", mid, newrid, attachmentType);
imagesService.saveImageWithPreviews(attachmentFName, fname);
}
+ Message original = messagesService.getMessage(mid);
Message reply = messagesService.getReply(mid, newrid);
- applicationEventPublisher.publishEvent(new MessageEvent(this, reply));
+ applicationEventPublisher.publishEvent(new MessageEvent(this, reply, subscriptionService.getUsersSubscribedToComments(original, reply)));
return CommandResult.build(reply,"Reply posted.\n#" + mid + "/" + newrid + " "
+ "https://juick.com/" + mid + "#" + newrid,
String.format("[Reply](%s) posted", PlainTextFormatter.formatUrl(reply)));
diff --git a/juick-common/src/main/java/com/juick/server/component/LikeEvent.java b/juick-common/src/main/java/com/juick/server/component/LikeEvent.java
index 8ff0a184..678a84a9 100644
--- a/juick-common/src/main/java/com/juick/server/component/LikeEvent.java
+++ b/juick-common/src/main/java/com/juick/server/component/LikeEvent.java
@@ -4,18 +4,22 @@ import com.juick.Message;
import com.juick.User;
import org.springframework.context.ApplicationEvent;
+import java.util.List;
+
public class LikeEvent extends ApplicationEvent {
private User user;
private Message message;
+ private List<User> subscribers;
/**
* Create a new ApplicationEvent.
*
* @param source the object on which the event initially occurred (never {@code null})
*/
- public LikeEvent(Object source, User user, Message message) {
+ public LikeEvent(Object source, User user, Message message, List<User> subscribers) {
super(source);
this.message = message;
this.user = user;
+ this.subscribers = subscribers;
}
public User getUser() {
@@ -25,4 +29,8 @@ public class LikeEvent extends ApplicationEvent {
public Message getMessage() {
return message;
}
+
+ public List<User> getSubscribers() {
+ return subscribers;
+ }
}
diff --git a/juick-common/src/main/java/com/juick/server/component/MessageEvent.java b/juick-common/src/main/java/com/juick/server/component/MessageEvent.java
index 048de6a6..c0c60228 100644
--- a/juick-common/src/main/java/com/juick/server/component/MessageEvent.java
+++ b/juick-common/src/main/java/com/juick/server/component/MessageEvent.java
@@ -1,22 +1,31 @@
package com.juick.server.component;
import com.juick.Message;
+import com.juick.User;
import org.springframework.context.ApplicationEvent;
+import java.util.List;
+
public class MessageEvent extends ApplicationEvent {
private Message message;
+ private List<User> users;
/**
* Create a new ApplicationEvent.
*
* @param source the object on which the event initially occurred (never {@code null})
* @param message app message
+ * @param interestedUsers users interested in notification
*/
- public MessageEvent(Object source, Message message) {
+ public MessageEvent(Object source, Message message, List<User> interestedUsers) {
super(source);
this.message = message;
+ this.users = interestedUsers;
}
public Message getMessage() {
return message;
}
+ public List<User> getUsers() {
+ return users;
+ }
}
diff --git a/juick-notifications/src/main/java/com/juick/components/Notifications.java b/juick-notifications/src/main/java/com/juick/components/Notifications.java
index 5f6630fb..ce89de32 100644
--- a/juick-notifications/src/main/java/com/juick/components/Notifications.java
+++ b/juick-notifications/src/main/java/com/juick/components/Notifications.java
@@ -22,7 +22,6 @@ import com.google.android.gcm.server.*;
import com.juick.ExternalToken;
import com.juick.User;
import com.juick.formatters.PlainTextFormatter;
-import com.juick.server.component.MessageEvent;
import com.juick.util.MessageUtils;
import com.turo.pushy.apns.ApnsClient;
import com.turo.pushy.apns.PushNotificationResponse;
@@ -33,7 +32,6 @@ import org.apache.commons.text.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.ApplicationListener;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
@@ -41,6 +39,7 @@ import org.springframework.web.client.RestTemplate;
import javax.annotation.Nonnull;
import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
import javax.inject.Inject;
import java.io.IOException;
import java.util.*;
@@ -52,7 +51,7 @@ import java.util.stream.Collectors;
* @author Ugnich Anton
*/
@Component
-public class Notifications implements NotificationClientListener, AutoCloseable, ApplicationListener<MessageEvent> {
+public class Notifications implements NotificationClientListener {
private static Logger logger = LoggerFactory.getLogger(Notifications.class);
@Inject
@@ -78,9 +77,7 @@ public class Notifications implements NotificationClientListener, AutoCloseable,
public void init() throws IOException {
mpnsClient.setListener(this);
}
- @Override
- public void onApplicationEvent(@Nonnull MessageEvent event) {
- com.juick.Message jmsg = event.getMessage();
+ public void messageReceived(@Nonnull com.juick.Message jmsg) {
User pmTo = jmsg.getTo();
final List<User> users = new ArrayList<>();
@@ -205,7 +202,7 @@ public class Notifications implements NotificationClientListener, AutoCloseable,
}
}
- @Override
+ @PreDestroy
public void close() throws Exception {
apns.close();
diff --git a/juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java b/juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java
index eecddc70..0f62e702 100644
--- a/juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java
+++ b/juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java
@@ -1,6 +1,7 @@
package com.juick.components.service;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.juick.components.Notifications;
import com.juick.server.component.DisconnectedEvent;
import com.juick.server.component.MessageEvent;
import org.slf4j.Logger;
@@ -26,6 +27,8 @@ public class JuickServerComponent extends TextWebSocketHandler {
@Inject
private ApplicationEventPublisher applicationEventPublisher;
@Inject
+ private Notifications notifications;
+ @Inject
private ObjectMapper jsonMapper;
private WebSocketSession session;
@@ -54,7 +57,7 @@ public class JuickServerComponent extends TextWebSocketHandler {
if (logger.isInfoEnabled()) // prevent writeValueAsString execution if logger disabled
logger.info("got jmsg: {}", jsonMapper.writeValueAsString(jmsg));
if (!closeFlag.get()) {
- applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg));
+ notifications.messageReceived(jmsg);
}
}
diff --git a/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java b/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java
index 884b1563..bf3f54e1 100644
--- a/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java
+++ b/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java
@@ -74,6 +74,7 @@ import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@@ -261,13 +262,12 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
return stanzaWriter.toString();
}
- private void sendJuickMessage(com.juick.Message jmsg) {
+ private void sendJuickMessage(com.juick.Message jmsg, List<User> users) {
List<String> jids = new ArrayList<>();
if (jmsg.FriendsOnly) {
jids = subscriptionService.getJIDSubscribedToUser(jmsg.getUser().getUid(), jmsg.FriendsOnly);
} else {
- List<User> users = subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid());
for (User user : users) {
jids.addAll(userService.getJIDsbyUID(user.getUid()));
}
@@ -304,13 +304,10 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
}
}
- public void sendJuickComment(com.juick.Message jmsg) {
- List<User> users;
+ public void sendJuickComment(com.juick.Message jmsg, List<User> users) {
String replyQuote;
String replyTo;
- 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();
@@ -340,6 +337,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
@Override
public void processMessageEvent(MessageEvent event) {
com.juick.Message msg = event.getMessage();
+ List<User> subscribers = event.getUsers();
if (MessageUtils.isPM(msg)) {
userService.getJIDsbyUID(msg.getTo().getUid())
.forEach(userJid -> {
@@ -357,10 +355,10 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
router.send(ClientMessage.from(mm));
});
} else if (MessageUtils.isReply(msg)) {
- sendJuickComment(msg);
+ sendJuickComment(msg, subscribers);
}
else {
- sendJuickMessage(msg);
+ sendJuickMessage(msg, subscribers);
}
}
@@ -380,11 +378,9 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
@Override
public void processLikeEvent(LikeEvent likeEvent) {
- List<User> users;
+ List<User> users = likeEvent.getSubscribers();
com.juick.Message jmsg = likeEvent.getMessage();
User liker = likeEvent.getUser();
- users = subscriptionService.getUsersSubscribedToUserRecommendations(liker.getUid(),
- jmsg.getMid(), jmsg.getUser().getUid());
String txt = "Recommended by @" + liker.getName() + ":\n";
txt += "@" + jmsg.getUser().getName() + ":" + MessageUtils.getTagsString(jmsg) + "\n";
@@ -551,15 +547,17 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
com.juick.Message jmsg = msg.getExtension(com.juick.Message.class);
if (jmsg != null) {
if (to.getLocal().equals("pm")) {
- applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg));
+ applicationEventPublisher.publishEvent(new MessageEvent(this, jmsg, Collections.singletonList(jmsg.getTo())));
} else {
if (MessageUtils.isReply(jmsg)) {
// to get quote and attachment
+ com.juick.Message original = messagesService.getMessage(jmsg.getMid());
com.juick.Message reply = messagesService.getReply(jmsg.getMid(), jmsg.getRid());
- applicationEventPublisher.publishEvent(new MessageEvent(this, reply));
+ applicationEventPublisher.publishEvent(new MessageEvent(this, reply,
+ subscriptionService.getUsersSubscribedToComments(original, reply)));
} else if (!MessageUtils.isPM(jmsg)) {
applicationEventPublisher.publishEvent(new MessageEvent(this,
- messagesService.getMessage(jmsg.getMid())));
+ messagesService.getMessage(jmsg.getMid()), subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid())));
}
}
} else {
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;
}