aboutsummaryrefslogtreecommitdiff
path: root/juick-core/src/main/java/com/juick/server/protocol/JuickProtocol.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-core/src/main/java/com/juick/server/protocol/JuickProtocol.java')
-rw-r--r--juick-core/src/main/java/com/juick/server/protocol/JuickProtocol.java50
1 files changed, 43 insertions, 7 deletions
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 024179a7..01f7d691 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
@@ -113,6 +113,39 @@ public class JuickProtocol {
return new ProtocolReply(txt, Optional.empty());
}
+ @UserCommand(pattern = "^bl\\s+@([^\\s\\n\\+]+)", patternFlags = Pattern.CASE_INSENSITIVE,
+ help = "BL @username - add @username to your blacklist")
+ public ProtocolReply blacklistUser(User from, String... arguments) {
+ User blUser = UserQueries.getUserByName(sql, arguments[0]);
+ if (blUser != null) {
+ PrivacyQueries.PrivacyResult result = PrivacyQueries.blacklistUser(sql, from, blUser);
+ if (result == PrivacyQueries.PrivacyResult.Added) {
+ return new ProtocolReply("User added to your blacklist", Optional.empty());
+ } else {
+ return new ProtocolReply("User removed from your blacklist", Optional.empty());
+ }
+ }
+ return new ProtocolReply("User not found", Optional.empty());
+ }
+
+ @UserCommand(pattern = "^bl\\s\\*(\\S+)$", patternFlags = Pattern.CASE_INSENSITIVE,
+ help = "BL *tag - add *tag to your blacklist")
+ public ProtocolReply blacklistTag(User from, String... arguments) {
+ User blUser = UserQueries.getUserByName(sql, arguments[0]);
+ if (blUser != null) {
+ Tag tag = TagQueries.getTag(sql, arguments[0], false);
+ if (tag != null) {
+ PrivacyQueries.PrivacyResult result = PrivacyQueries.blacklistTag(sql, from, tag);
+ if (result == PrivacyQueries.PrivacyResult.Added) {
+ return new ProtocolReply("Tag added to your blacklist", Optional.empty());
+ } else {
+ return new ProtocolReply("Tag removed from your blacklist", Optional.empty());
+ }
+ }
+ }
+ return new ProtocolReply("Tag not found", 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) {
@@ -263,14 +296,17 @@ public class JuickProtocol {
return new ProtocolReply("Error", Optional.empty());
}
Message msg = MessagesQueries.getMessage(sql, mid);
- if (showReplies) {
- List<Message> replies = MessagesQueries.getReplies(sql, mid);
- replies.add(0, msg);
- return new ProtocolReply(String.join("\n",
- replies.stream().map(PlainTextFormatter::formatPost).collect(Collectors.toList())),
- Optional.of(json.serializeList(replies)));
+ if (msg != null) {
+ if (showReplies) {
+ List<Message> replies = MessagesQueries.getReplies(sql, mid);
+ replies.add(0, msg);
+ return new ProtocolReply(String.join("\n",
+ replies.stream().map(PlainTextFormatter::formatPost).collect(Collectors.toList())),
+ Optional.of(json.serializeList(replies)));
+ }
+ return new ProtocolReply(PlainTextFormatter.formatPost(msg), Optional.of(json.serializeList(Collections.singletonList(msg))));
}
- return new ProtocolReply(msg.toString(), Optional.of(json.serializeList(Collections.singletonList(msg))));
+ return new ProtocolReply("Message not found", Optional.empty());
}
@UserCommand(pattern = "^(#|\\.)(\\d+)((\\.|\\-|\\/)(\\d+))?\\s([\\s\\S]+)",
help = "#1234 *tag *tag2 - edit tags\n#1234 text - reply to message")