From b1a81ad87c0803006965ca299103a5ec32be3056 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 16 Jan 2017 14:20:20 +0300 Subject: juick-protocol: S command --- .../main/java/com/juick/server/protocol/JuickProtocol.java | 13 +++++++++++++ .../main/java/com/juick/service/SubscriptionService.java | 2 ++ .../java/com/juick/service/SubscriptionServiceImpl.java | 7 +++++++ 3 files changed, 22 insertions(+) (limited to 'juick-server/src') diff --git a/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java b/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java index be68fe62..06fbf2fc 100644 --- a/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java +++ b/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java @@ -198,6 +198,19 @@ public class JuickProtocol { return new ProtocolReply(msg); } + @UserCommand(pattern = "S", help = "S - Show your subscriptions") + public ProtocolReply commandSubscriptions(User currentUser, String... args) { + List friends = userService.getUserFriends(currentUser.getUid()); + List tags = subscriptionService.getSubscribedTags(currentUser); + String msg = friends.size() > 0 ? "You are subscribed to users:" + friends.stream().map(u -> "\n@" + u.getName()) + .collect(Collectors.joining()) + : "You are not subscribed to any user."; + msg += tags.size() > 0 ? "\nYou are subscribed to tags:" + tags.stream().map(t -> "\n*" + t) + .collect(Collectors.joining()) + : "\nYou are not subscribed to any tag."; + return new ProtocolReply(msg); + } + @UserCommand(pattern = "!", help = "! - Show your favorite messages") public ProtocolReply commandFavorites(User currentUser, String... args) { List mids = messagesService.getUserRecommendations(currentUser.getUid(), 0); diff --git a/juick-server/src/main/java/com/juick/service/SubscriptionService.java b/juick-server/src/main/java/com/juick/service/SubscriptionService.java index 00aee15d..074c73f5 100644 --- a/juick-server/src/main/java/com/juick/service/SubscriptionService.java +++ b/juick-server/src/main/java/com/juick/service/SubscriptionService.java @@ -30,6 +30,8 @@ public interface SubscriptionService { boolean unSubscribeTag(User user, Tag toTag); + List getSubscribedTags(User user); + NotifyOpts getNotifyOptions(User user); boolean setNotifyOptions(User user, NotifyOpts options); 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 4082e1ef..ae4af9df 100644 --- a/juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/SubscriptionServiceImpl.java @@ -171,6 +171,13 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip "DELETE FROM subscr_tags WHERE tag_id=? AND suser_id=?", toTag.TID, user.getUid()) > 0; } + @Transactional(readOnly = true) + @Override + public List getSubscribedTags(User user) { + return getJdbcTemplate().queryForList("SELECT tags.name FROM subscr_tags INNER JOIN tags USING(tag_id) " + + "WHERE subscr_tags.suser_id=? ORDER BY tags.name", String.class, user.getUid()); + } + @Transactional(readOnly = true) @Override public NotifyOpts getNotifyOptions(final User user) { -- cgit v1.2.3