aboutsummaryrefslogtreecommitdiff
path: root/juick-server
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server')
-rw-r--r--juick-server/src/main/java/com/juick/server/TelegramBotManager.java8
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Post.java2
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java18
3 files changed, 18 insertions, 10 deletions
diff --git a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
index 4b2e5278..17ad4630 100644
--- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
+++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
@@ -186,7 +186,9 @@ public class TelegramBotManager implements NotificationListener {
prefix = String.format("#%d/%d ", mid, rid);
}
CommandResult result = commandsManager.processCommand(user_from, null,prefix + text, attachment);
- telegramNotify(message.from().id().longValue(), result.getText(), StringUtils.EMPTY);
+ String messageTxt = StringUtils.isNotEmpty(result.getMarkdown()) ? result.getMarkdown()
+ : "Unknown error or unsupported command";
+ telegramNotify(message.from().id().longValue(), messageTxt, StringUtils.EMPTY);
} else {
logger.warn("invalid path: {}", path);
}
@@ -203,7 +205,9 @@ public class TelegramBotManager implements NotificationListener {
}
} else {
CommandResult result = commandsManager.processCommand(user_from, null, text, attachment);
- telegramNotify(message.from().id().longValue(), result.getText(), StringUtils.EMPTY);
+ String messageTxt = StringUtils.isNotEmpty(result.getMarkdown()) ? result.getMarkdown()
+ : "Unknown error or unsupported command";
+ telegramNotify(message.from().id().longValue(), messageTxt, StringUtils.EMPTY);
}
}
}
diff --git a/juick-server/src/main/java/com/juick/server/api/Post.java b/juick-server/src/main/java/com/juick/server/api/Post.java
index e949dad7..eddd1dd6 100644
--- a/juick-server/src/main/java/com/juick/server/api/Post.java
+++ b/juick-server/src/main/java/com/juick/server/api/Post.java
@@ -163,7 +163,7 @@ public class Post {
}
}
- return commandsManager.processCommand(visitor, null, body, attachmentFName).getNewMessage();
+ return commandsManager.processCommand(visitor, null, body, attachmentFName).getNewMessage().get();
}
Session session = Session.getDefaultInstance(new Properties());
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index a30403b0..0ef82f98 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -28,6 +28,7 @@ import com.juick.server.EmailManager;
import com.juick.server.XMPPConnection;
import com.juick.server.XMPPServer;
import com.juick.server.helpers.AnonymousUser;
+import com.juick.server.helpers.CommandResult;
import com.juick.server.helpers.TagStats;
import com.juick.server.util.HttpUtils;
import com.juick.service.*;
@@ -551,17 +552,20 @@ public class ServerTests {
int uid = userService.createUser("me", "secret");
User user = userService.getUserByUID(uid).orElse(new User());
Tag yo = tagService.getTag("yo", true);
- Message msg = commandsManager.processCommand(user, Jid.of("test@localhost"), "*yo yoyo", URI.create("http://static.juick.com/settings/facebook.png")).getNewMessage();
+ Message msg = commandsManager.processCommand(user, Jid.of("test@localhost"), "*yo yoyo", URI.create("http://static.juick.com/settings/facebook.png")).getNewMessage().get();
assertThat(msg.getAttachmentType(), is("png"));
- Message msgreply = commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + msg.getMid() + " yyy", HttpUtils.downloadImage(URI.create("http://static.juick.com/settings/xmpp.png").toURL(), tmpDir)).getNewMessage();
+ Message msgreply = commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + msg.getMid() + " yyy", HttpUtils.downloadImage(URI.create("http://static.juick.com/settings/xmpp.png").toURL(), tmpDir)).getNewMessage().get();
assertThat(msgreply.getAttachmentType(), equalTo("png"));
- int mid = messagesService.createMessage(uid, "yoyo", null, Collections.singletonList(yo));
- assertEquals("should be message", true,
- commandsManager.processCommand(user, Jid.of("test@localhost"), String.format("#%d", mid), emptyUri).getText().startsWith("@me"));
assertEquals("text should match", "yoyo",
- messagesService.getMessage(mid).getText());
+ messagesService.getMessage(msg.getMid()).getText());
assertEquals("tag should match", "yo",
- tagService.getMessageTags(mid).get(0).getTag().getName());
+ tagService.getMessageTags(msg.getMid()).get(0).getTag().getName());
+ CommandResult yoyoMsg = commandsManager.processCommand(user, null, "*yo", URI.create("http://static.juick.com/settings/facebook.png"));
+ assertTrue(yoyoMsg.getNewMessage().isPresent());
+ assertThat(yoyoMsg.getNewMessage().get().getTags().get(0), is(yo));
+ int mid = yoyoMsg.getNewMessage().get().getMid();
+ assertEquals("should be message", true,
+ commandsManager.processCommand(user, Jid.of("test@localhost"), String.format("#%d", mid), emptyUri).getText().startsWith("@me"));
int readerUid = userService.createUser("dummyReader", "dummySecret");
User readerUser = userService.getUserByUID(readerUid).orElse(new User());
Jid dummyJid = Jid.of("dummy@localhost");