diff options
author | Anatoliy Sablin | 2017-11-06 16:27:11 +0300 |
---|---|---|
committer | Anatoliy Sablin | 2017-11-06 16:27:11 +0300 |
commit | d77ff16de5543b5820ee3b185660a052c5f57a15 (patch) | |
tree | ba701d56a441dc7e9caea89bad96929bc3a70d95 /juick-commands/src/main/java/com/juick/command/ShowSubscriptions.java | |
parent | 41b885d84958d07ade536850829b3ba394a4f8f9 (diff) |
Added rest commands.
Diffstat (limited to 'juick-commands/src/main/java/com/juick/command/ShowSubscriptions.java')
-rw-r--r-- | juick-commands/src/main/java/com/juick/command/ShowSubscriptions.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/juick-commands/src/main/java/com/juick/command/ShowSubscriptions.java b/juick-commands/src/main/java/com/juick/command/ShowSubscriptions.java new file mode 100644 index 00000000..ad35a4c2 --- /dev/null +++ b/juick-commands/src/main/java/com/juick/command/ShowSubscriptions.java @@ -0,0 +1,53 @@ +package com.juick.command; + +import com.juick.User; +import com.juick.server.protocol.ProtocolListener; +import com.juick.service.SubscriptionService; +import com.juick.service.UserService; +import lombok.Getter; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +/** + * @author ma1uta + */ +@Component +@Getter +public class ShowSubscriptions implements Command { + + private static final Pattern PATTERN = Pattern.compile("S", Pattern.CASE_INSENSITIVE); + + private final UserService userService; + private final SubscriptionService subscriptionService; + + public ShowSubscriptions(UserService userService, SubscriptionService subscriptionService) { + this.userService = userService; + this.subscriptionService = subscriptionService; + } + + @Override + public Pattern pattern() { + return PATTERN; + } + + @Override + public String help() { + return "S - Show your subscriptions"; + } + + @Override + public String execute(User sender, ProtocolListener protocolListener, String command) { + List<User> friends = getUserService().getUserFriends(sender.getUid()); + List<String> tags = getSubscriptionService().getSubscribedTags(sender); + 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 msg; + } +} |