aboutsummaryrefslogtreecommitdiff
path: root/juick-commands/src/main/java/com/juick/command/ShowFavorites.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-commands/src/main/java/com/juick/command/ShowFavorites.java')
-rw-r--r--juick-commands/src/main/java/com/juick/command/ShowFavorites.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/juick-commands/src/main/java/com/juick/command/ShowFavorites.java b/juick-commands/src/main/java/com/juick/command/ShowFavorites.java
new file mode 100644
index 00000000..ced28936
--- /dev/null
+++ b/juick-commands/src/main/java/com/juick/command/ShowFavorites.java
@@ -0,0 +1,54 @@
+package com.juick.command;
+
+import com.juick.User;
+import com.juick.formatters.PlainTextFormatter;
+import com.juick.server.protocol.ProtocolListener;
+import com.juick.service.MessagesService;
+import lombok.Getter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * @author ma1uta
+ */
+@Component
+@Getter
+public class ShowFavorites implements Command {
+
+ private static final Pattern PATTERN = Pattern.compile("!", Pattern.CASE_INSENSITIVE);
+
+ private final MessagesService messagesService;
+
+ @Autowired
+ public ShowFavorites(MessagesService messagesService) {
+ this.messagesService = messagesService;
+ }
+
+ @Override
+ public Pattern pattern() {
+ return PATTERN;
+ }
+
+ @Override
+ public String help() {
+ return "! - Show your favorite messages";
+ }
+
+ @Override
+ public String execute(User sender, ProtocolListener protocolListener, String command) {
+ List<Integer> mids = getMessagesService().getUserRecommendations(sender.getUid(), 0);
+ if (mids.size() > 0) {
+ List<com.juick.Message> messages = getMessagesService().getMessages(mids);
+ return "Favorite messages: \n" + String.join("\n", messages.stream()
+ .sorted(Collections.reverseOrder())
+ .map(PlainTextFormatter::formatPost)
+ .collect(Collectors.toList()));
+ }
+ return "No favorite messages, try to \"like\" something ;)";
+ }
+}