aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/TelegramBotManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/server/TelegramBotManager.java')
-rw-r--r--src/main/java/com/juick/server/TelegramBotManager.java40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/main/java/com/juick/server/TelegramBotManager.java b/src/main/java/com/juick/server/TelegramBotManager.java
index f8948a68..f35a73d3 100644
--- a/src/main/java/com/juick/server/TelegramBotManager.java
+++ b/src/main/java/com/juick/server/TelegramBotManager.java
@@ -17,7 +17,7 @@
package com.juick.server;
-import com.juick.User;
+import com.juick.model.User;
import com.juick.model.AnonymousUser;
import com.juick.model.CommandResult;
import com.juick.server.api.SystemActivity;
@@ -139,17 +139,17 @@ public class TelegramBotManager implements NotificationListener {
int mid = originalMessageData.get().getLeft();
int rid = originalMessageData.get().getRight();
// TODO: this is copypaste from api, need switch to api
- com.juick.Message originalMessage = rid == 0 ? messagesService.getMessage(mid).orElseThrow(IllegalStateException::new)
+ com.juick.model.Message originalMessage = rid == 0 ? messagesService.getMessage(mid).orElseThrow(IllegalStateException::new)
: messagesService.getReply(mid, rid);
User author = originalMessage.getUser();
String newMessageText = StringUtils.defaultString(message.text());
if (user_from.equals(author) && canUpdateMessage(originalMessage, newMessageText)) {
if (messagesService.updateMessage(mid, rid, newMessageText)) {
- telegramNotify(message.chat().id(), "Message updated", new com.juick.Message());
+ telegramNotify(message.chat().id(), "Message updated", new com.juick.model.Message());
return;
}
}
- telegramNotify(message.chat().id(), "Error updating message", new com.juick.Message());
+ telegramNotify(message.chat().id(), "Error updating message", new com.juick.model.Message());
}
} else {
User user_from = userService.getUserByUID(telegramService.getUser(message.chat().id())).orElse(AnonymousUser.INSTANCE);
@@ -195,7 +195,7 @@ public class TelegramBotManager implements NotificationListener {
String msgUrl = "http://juick.com/login?hash=" + userService.getHashByUID(user_from.getUid());
String msg = String.format("Hi, %s!\nYou can post messages and images to Juick there.\n" +
"Tap to [log into website](%s) to get more info", user_from.getName(), msgUrl);
- telegramNotify(message.from().id().longValue(), msg, new com.juick.Message());
+ telegramNotify(message.from().id().longValue(), msg, new com.juick.model.Message());
} else {
Message replyMessage = message.replyToMessage();
if (replyMessage != null) {
@@ -235,11 +235,11 @@ public class TelegramBotManager implements NotificationListener {
}
} else {
telegramNotify(message.from().id().longValue(),
- "Can not reply to this message", replyMessage.messageId(), new com.juick.Message());
+ "Can not reply to this message", replyMessage.messageId(), new com.juick.model.Message());
}
} else {
telegramNotify(message.from().id().longValue(),
- "Can not reply to this message", replyMessage.messageId(), new com.juick.Message());
+ "Can not reply to this message", replyMessage.messageId(), new com.juick.model.Message());
}
} else {
executeCommand(message.messageId(), message.from().id().longValue(),
@@ -262,7 +262,7 @@ public class TelegramBotManager implements NotificationListener {
/*
validate user input
*/
- private boolean canUpdateMessage(com.juick.Message message, String newData) {
+ private boolean canUpdateMessage(com.juick.model.Message message, String newData) {
if (StringUtils.isEmpty(newData)) {
// allow empty text only when image is present
return StringUtils.isNotEmpty(message.getAttachmentType());
@@ -274,13 +274,13 @@ public class TelegramBotManager implements NotificationListener {
try {
CommandResult result = commandsManager.processCommand(user_from, text, attachment);
if (result.getNewMessage().isPresent()) {
- com.juick.Message newMessage = result.getNewMessage().get();
+ com.juick.model.Message newMessage = result.getNewMessage().get();
messagesService.setMessageProperty(newMessage.getMid(), newMessage.getRid(), "durovId",
String.valueOf(messageId));
}
String messageTxt = StringUtils.isNotEmpty(result.getMarkdown()) ? result.getMarkdown()
: "Unknown error or unsupported command";
- telegramNotify(userId, messageTxt, new com.juick.Message());
+ telegramNotify(userId, messageTxt, new com.juick.model.Message());
} catch (Exception e) {
logger.warn("telegram exception", e);
}
@@ -290,11 +290,11 @@ public class TelegramBotManager implements NotificationListener {
return e.offset() == 0 && e.type().equals(MessageEntity.Type.text_link) && e.length() == 2;
}
- public void telegramNotify(Long chatId, String msg, @Nonnull com.juick.Message source) {
+ public void telegramNotify(Long chatId, String msg, @Nonnull com.juick.model.Message source) {
telegramNotify(chatId, msg, 0, source);
}
- public void telegramNotify(Long chatId, String msg, Integer replyTo, @Nonnull com.juick.Message source) {
+ public void telegramNotify(Long chatId, String msg, Integer replyTo, @Nonnull com.juick.model.Message source) {
String attachment = MessageUtils.attachmentUrl(source);
boolean isSendTxt = true;
if (!StringUtils.isEmpty(attachment)) {
@@ -339,7 +339,7 @@ public class TelegramBotManager implements NotificationListener {
}
}
- private void processTelegramResponse(Long chatId, SendResponse response, com.juick.Message source) {
+ private void processTelegramResponse(Long chatId, SendResponse response, com.juick.model.Message source) {
int userId = telegramService.getUser(chatId);
if (!response.isOk()) {
if (response.errorCode() == 403) {
@@ -406,7 +406,7 @@ public class TelegramBotManager implements NotificationListener {
processFollow(activity.getFrom(), activity.getTo());
}
}
- private void processMessage(com.juick.Message jmsg, List<User> subscribedUsers) {
+ private void processMessage(com.juick.model.Message jmsg, List<User> subscribedUsers) {
if (jmsg.isService()) {
return;
}
@@ -432,17 +432,17 @@ public class TelegramBotManager implements NotificationListener {
}
}
- private void processLike(User liker, com.juick.Message message, List<User> subscribers) {
+ private void processLike(User liker, com.juick.model.Message message, List<User> subscribers) {
if (!liker.getName().equals(serviceUser)) {
logger.info("Like received in tg listener");
if (!userService.isInBLAny(message.getUser().getUid(), liker.getUid())) {
telegramService.getTelegramIdentifiers(Collections.singletonList(message.getUser()))
.forEach(c -> telegramNotify(c, String.format("%s recommends your [post](%s)",
- MessageUtils.getMarkdownUser(liker), formatUrl(message)), new com.juick.Message()));
+ MessageUtils.getMarkdownUser(liker), formatUrl(message)), new com.juick.model.Message()));
}
telegramService.getTelegramIdentifiers(subscribers)
.forEach(c -> telegramNotify(c, String.format("%s recommends you someone's [post](%s)",
- MessageUtils.getMarkdownUser(liker), formatUrl(message)), new com.juick.Message()));
+ MessageUtils.getMarkdownUser(liker), formatUrl(message)), new com.juick.model.Message()));
}
}
@@ -451,15 +451,15 @@ public class TelegramBotManager implements NotificationListener {
}
- private void processTop(com.juick.Message message) {
+ private void processTop(com.juick.model.Message message) {
telegramService.getTelegramIdentifiers(Collections.singletonList(message.getUser()))
.forEach(c -> telegramNotify(c, String.format("Your [post](%s) became popular!",
- formatUrl(message)), new com.juick.Message()));
+ formatUrl(message)), new com.juick.model.Message()));
}
private void processFollow(User subscriber, List<User> target) {
telegramService.getTelegramIdentifiers(target)
.forEach(c -> telegramNotify(c, String.format("%s subscribed to your blog",
- MessageUtils.getMarkdownUser(subscriber)), new com.juick.Message()));
+ MessageUtils.getMarkdownUser(subscriber)), new com.juick.model.Message()));
}
}