From 1621fb481fe91b084a48326419969f3a22ccbbe2 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 29 Sep 2018 16:39:37 +0300 Subject: Mentions --- .../java/com/juick/server/CommandsManager.java | 2 +- .../main/java/com/juick/server/EmailManager.java | 6 ++--- .../main/java/com/juick/server/XMPPConnection.java | 2 +- .../java/com/juick/server/api/Notifications.java | 2 +- .../com/juick/service/SubscriptionServiceImpl.java | 26 +++++++++++++++------- 5 files changed, 24 insertions(+), 14 deletions(-) (limited to 'juick-server/src/main/java') diff --git a/juick-server/src/main/java/com/juick/server/CommandsManager.java b/juick-server/src/main/java/com/juick/server/CommandsManager.java index 53b93d4c..e9cf11de 100644 --- a/juick-server/src/main/java/com/juick/server/CommandsManager.java +++ b/juick-server/src/main/java/com/juick/server/CommandsManager.java @@ -123,7 +123,7 @@ public class CommandsManager { subscriptionService.subscribeMessage(msg, user); applicationEventPublisher.publishEvent(new MessageReadEvent(this, Collections.singletonList(user), msg)); - applicationEventPublisher.publishEvent(new MessageEvent(this, msg, subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg.getMid()))); + applicationEventPublisher.publishEvent(new MessageEvent(this, msg, subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg))); return CommandResult.build(msg, "New message posted.\n#" + msg.getMid() + " https://juick.com/m/" + msg.getMid(), String.format("[New message](%s) posted", PlainTextFormatter.formatUrl(msg))); } 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 0acabeff..2be21127 100644 --- a/juick-server/src/main/java/com/juick/server/EmailManager.java +++ b/juick-server/src/main/java/com/juick/server/EmailManager.java @@ -83,12 +83,12 @@ public class EmailManager implements ApplicationListener { headers.put("In-Reply-To", String.format("<%d.%d@juick.com>", original.getMid(), original.getRid())); } } - String plainText = String.format("%s\n\n--\nYou are receiving this because you are subscribed to this user " + - ", discussion or tag. Reply to this email directly or view it on Juick: %s.", + String plainText = String.format("%s\n\n--\nYou are receiving this because you are subscribed to this user," + + " discussion, tag or mentioned. Reply to this email directly or view it on Juick: %s.", formatPost(msg), formatUrl(msg)); String hash = userService.getHashByUID(userService.getUserByEmail(email).getUid()); String htmlText = String.format("%s

--
You are receiving this because you are subscribed to this user" + - ", discussion or tag. Reply to this email directly or view it on Juick." + + ", discussion, tag or mentioned. Reply to this email directly or view it on Juick." + "
Configure or disable notifications", MessageUtils.formatHtml(msg), formatUrl(msg), msg.getMid(), msg.getRid(), hash, hash); 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 ba155fe7..fdbb5fe6 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java @@ -586,7 +586,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { subscriptionService.getUsersSubscribedToComments(original, reply))); } else if (!MessageUtils.isPM(jmsg)) { applicationEventPublisher.publishEvent(new MessageEvent(this, - messagesService.getMessage(jmsg.getMid()), subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid()))); + messagesService.getMessage(jmsg.getMid()), subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg))); } } else { URI attachment = URI.create(StringUtils.EMPTY); 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 b0d64292..67e52851 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 @@ -89,7 +89,7 @@ public class Notifications { Message reply = messagesService.getReply(mid, rid); users = subscriptionService.getUsersSubscribedToComments(op, reply); } else { - users = subscriptionService.getSubscribedUsers(msg.getUser().getUid(), mid); + users = subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg); } return ResponseEntity.ok(users.stream().map(User::getUid) 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 492fef1c..2032576c 100644 --- a/juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java @@ -21,6 +21,10 @@ import com.juick.Message; import com.juick.Tag; import com.juick.User; import com.juick.model.NotifyOpts; +import com.juick.util.MessageUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.IteratorUtils; +import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.dao.DuplicateKeyException; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -61,16 +65,20 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip @Transactional(readOnly = true) @Override - public List getSubscribedUsers(final int uid, final int mid) { + public List getSubscribedUsers(final int uid, final Message msg) { + int mid = msg.getMid(); User author = messagesService.getMessageAuthor(mid); - List userids = userService.getUserReaders(uid); + List subscribers = userService.getUserReaders(uid); + List mentionedUsers = userService.getUsersByName(MessageUtils.getMentions(msg).stream() + .map(u -> u.substring(1)).collect(Collectors.toList())); + List users = ListUtils.union(subscribers, mentionedUsers); List tags = tagService.getMessageTagsIDs(mid); List tagsStr = tagService.getMessageTags(mid).stream().map(t -> t.getTag().getName()).collect(Collectors.toList()); Set set = new HashSet<>(); set.addAll( - userids.stream() + users.stream() .map(User::getUid).filter(u -> Collections.disjoint(tagService.getUserBLTags(u), tagsStr)) .collect(Collectors.toList())); @@ -99,13 +107,15 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip @Override public List getUsersSubscribedToComments(@Nonnull final Message msg, @Nonnull final Message reply, boolean blacklisted) { - List userids = getJdbcTemplate().queryForList( + List subscribers = userService.getUsersByID(getJdbcTemplate().queryForList( "SELECT suser_id FROM subscr_messages WHERE message_id=? AND suser_id!=?", Integer.class, - msg.getMid(), reply.getUser().getUid()); - - if (!userids.isEmpty()) { - return userService.getUsersByID(userids).stream() + msg.getMid(), reply.getUser().getUid())); + List mentionedUsers = userService.getUsersByName(MessageUtils.getMentions(reply).stream() + .map(u -> u.substring(1)).collect(Collectors.toList())); + List users = IteratorUtils.toList(CollectionUtils.union(subscribers, mentionedUsers).iterator()); + if (!users.isEmpty()) { + return users.stream() .filter(u -> blacklisted || !userService.isReplyToBL(u, reply)) .collect(Collectors.toList()); } -- cgit v1.2.3