aboutsummaryrefslogtreecommitdiff
path: root/juick-core
diff options
context:
space:
mode:
Diffstat (limited to 'juick-core')
-rw-r--r--juick-core/src/main/java/com/juick/server/MessagesQueries.java1
-rw-r--r--juick-core/src/main/java/com/juick/server/protocol/JuickProtocol.java48
2 files changed, 47 insertions, 2 deletions
diff --git a/juick-core/src/main/java/com/juick/server/MessagesQueries.java b/juick-core/src/main/java/com/juick/server/MessagesQueries.java
index 40449e75..b824feba 100644
--- a/juick-core/src/main/java/com/juick/server/MessagesQueries.java
+++ b/juick-core/src/main/java/com/juick/server/MessagesQueries.java
@@ -547,7 +547,6 @@ public class MessagesQueries {
return sql.queryForList("SELECT message_id FROM favorites "
+ "WHERE user_id=? ORDER BY message_id DESC LIMIT 20",
Integer.class, UID);
-
}
}
diff --git a/juick-core/src/main/java/com/juick/server/protocol/JuickProtocol.java b/juick-core/src/main/java/com/juick/server/protocol/JuickProtocol.java
index 01f7d691..aff8010a 100644
--- a/juick-core/src/main/java/com/juick/server/protocol/JuickProtocol.java
+++ b/juick-core/src/main/java/com/juick/server/protocol/JuickProtocol.java
@@ -1,10 +1,12 @@
package com.juick.server.protocol;
import com.juick.*;
+import com.juick.Message;
import com.juick.formatters.PlainTextFormatter;
import com.juick.json.MessageSerializer;
import com.juick.server.*;
import com.juick.server.protocol.annotation.UserCommand;
+import com.juick.xmpp.*;
import com.juick.xmpp.extensions.JuickMessage;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -146,12 +148,56 @@ public class JuickProtocol {
return new ProtocolReply("Tag not found", Optional.empty());
}
+ @UserCommand(pattern = "@", help = "@ - Show recommendations and popular personal blogs")
+ public ProtocolReply commandUsers(User currentUser, String... args) {
+ StringBuilder msg = new StringBuilder();
+ msg.append("Recommended blogs");
+ List<String> recommendedUsers = ShowQueries.getRecommendedUsers(sql, currentUser);
+ if (recommendedUsers.size() > 0) {
+ for (String user : recommendedUsers) {
+ msg.append("\n@").append(user);
+ }
+ } else {
+ msg.append("\nNo recommendations now. Subscribe to more blogs. ;)");
+ }
+ msg.append("\n\nTop 10 personal blogs:");
+ List<String> topUsers = ShowQueries.getTopUsers(sql);
+ if (topUsers.size() > 0) {
+ for (String user : topUsers) {
+ msg.append("\n@").append(user);
+ }
+ } else {
+ msg.append("\nNo top users. Empty DB? ;)");
+ }
+ return new ProtocolReply(msg.toString(), Optional.empty());
+ }
+
+ @UserCommand(pattern = "\\*", help = "* - Show your tags")
+ public ProtocolReply commandTags(User currentUser, String... args) {
+ List<Tag> tags = TagQueries.getUserTagsAll(sql, currentUser.getUID());
+ String msg = "Your tags: (tag - messages)\n" +
+ tags.stream()
+ .map(t -> String.format("\n*%s - %d", t.getName(), t.UsageCnt)).collect(Collectors.joining());
+ return new ProtocolReply(msg, Optional.empty());
+ }
+
+ @UserCommand(pattern = "!", help = "! - Show your favorite messages")
+ public ProtocolReply commandFavorites(User currentUser, String... args) {
+ List<Integer> mids = MessagesQueries.getUserRecommendations(sql, currentUser.getUID(), 0);
+ if (mids.size() > 0) {
+ List<Message> messages = MessagesQueries.getMessages(sql, mids);
+ return new ProtocolReply("Favorite messages: \n" + String.join("\n", messages.stream().map(PlainTextFormatter::formatPost)
+ .collect(Collectors.toList())), Optional.of(json.serializeList(messages)));
+ }
+ return new ProtocolReply("No favorite messages, try to \"like\" something ;)", Optional.empty());
+ }
+
@UserCommand(pattern = "^\\@([^\\s\\n\\+]+)(\\+?)$",
help = "@username+ - Show user's info and last 10 messages (@username++ - second page, ..)")
public ProtocolReply commandUser(User user, String... arguments) {
User blogUser = UserQueries.getUserByName(sql, arguments[0]);
int page = arguments[1].length();
- if (blogUser.getUID() > 0) {
+ if (blogUser != null) {
List<Integer> mids = MessagesQueries.getUserBlog(sql, blogUser.getUID(), 0, page);
List<Message> messages = MessagesQueries.getMessages(sql, mids);
return new ProtocolReply(String.format("Last messages from @%s:\n%s", arguments[0],