diff options
author | Vitaly Takmazov | 2018-09-29 16:39:37 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-09-29 16:39:37 +0300 |
commit | 1621fb481fe91b084a48326419969f3a22ccbbe2 (patch) | |
tree | be6aa4acd21ee5d8e7edf8cde95cffe64590ec0e /juick-server/src/main/java/com/juick/service | |
parent | 80f305e6f5d22abc38807fd6fad37b5cb450c249 (diff) |
Mentions
Diffstat (limited to 'juick-server/src/main/java/com/juick/service')
-rw-r--r-- | juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java | 26 |
1 files changed, 18 insertions, 8 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 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<User> getSubscribedUsers(final int uid, final int mid) { + public List<User> getSubscribedUsers(final int uid, final Message msg) { + int mid = msg.getMid(); User author = messagesService.getMessageAuthor(mid); - List<User> userids = userService.getUserReaders(uid); + List<User> subscribers = userService.getUserReaders(uid); + List<User> mentionedUsers = userService.getUsersByName(MessageUtils.getMentions(msg).stream() + .map(u -> u.substring(1)).collect(Collectors.toList())); + List<User> users = ListUtils.union(subscribers, mentionedUsers); List<Integer> tags = tagService.getMessageTagsIDs(mid); List<String> tagsStr = tagService.getMessageTags(mid).stream().map(t -> t.getTag().getName()).collect(Collectors.toList()); Set<Integer> 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<User> getUsersSubscribedToComments(@Nonnull final Message msg, @Nonnull final Message reply, boolean blacklisted) { - List<Integer> userids = getJdbcTemplate().queryForList( + List<User> 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<User> mentionedUsers = userService.getUsersByName(MessageUtils.getMentions(reply).stream() + .map(u -> u.substring(1)).collect(Collectors.toList())); + List<User> users = IteratorUtils.toList(CollectionUtils.union(subscribers, mentionedUsers).iterator()); + if (!users.isEmpty()) { + return users.stream() .filter(u -> blacklisted || !userService.isReplyToBL(u, reply)) .collect(Collectors.toList()); } |