diff --git a/pom.xml b/pom.xml index c4a486d..35b6005 100644 --- a/pom.xml +++ b/pom.xml @@ -38,28 +38,28 @@ UTF-8 UTF-8 - 1.2.0 + 1.3.0 - 6.8.0 + 6.9.7.1 - 3.3.0 + 3.13.1 - 2.7.2 + 3.0.3 - 3.11.0 + 3.13.0 - 1.6.13 + 1.7.0 - 3.3.0 + 3.3.1 - 3.6.0 + 3.7.0 - 3.1.0 + 3.2.4 - 3.0.1 + 3.1.0 diff --git a/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java b/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java index c671648..87c46d6 100644 --- a/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java +++ b/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java @@ -16,6 +16,7 @@ import dev.struchkov.godfather.telegram.simple.context.service.TelegramConnect; import org.jetbrains.annotations.NotNull; import org.telegram.telegrambots.meta.api.objects.CallbackQuery; import org.telegram.telegrambots.meta.api.objects.ChatMemberUpdated; +import org.telegram.telegrambots.meta.api.objects.MaybeInaccessibleMessage; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.User; @@ -87,29 +88,23 @@ public class EventDistributorService implements EventDistributor { } private void processionCallback(CallbackQuery callbackQuery) { - final Message message = callbackQuery.getMessage(); + final MaybeInaccessibleMessage maybeInaccessibleMessage = callbackQuery.getMessage(); if (checkNotBlank(callbackQuery.getInlineMessageId())) { return; } - if (checkNotNull(message)) { - final Long fromId = message.getChat().getId(); - if (fromId < 0) { - - } else { - final Mail mail = CallbackQueryConvert.apply(callbackQuery); - eventDispatching.dispatch(new EventContainer<>(Mail.class, mail)); - } + if (checkNotNull(maybeInaccessibleMessage) && maybeInaccessibleMessage.isUserMessage()) { + final Mail mail = CallbackQueryConvert.apply(callbackQuery); + eventDispatching.dispatch(new EventContainer<>(Mail.class, mail)); } } private void processionMessage(Message message) { - final Long fromId = message.getChat().getId(); - if (fromId < 0) { - final ChatMail chatMail = MessageChatMailConvert.apply(message); - eventDispatching.dispatch(new EventContainer<>(ChatMail.class, chatMail)); - } else { + if (message.isUserMessage()) { final Mail mail = MessageMailConvert.apply(message); eventDispatching.dispatch(new EventContainer<>(Mail.class, mail)); + } else { + final ChatMail chatMail = MessageChatMailConvert.apply(message); + eventDispatching.dispatch(new EventContainer<>(ChatMail.class, chatMail)); } } diff --git a/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/CallbackQueryConvert.java b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/CallbackQueryConvert.java index e1bc51f..d13e5b5 100644 --- a/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/CallbackQueryConvert.java +++ b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/CallbackQueryConvert.java @@ -3,6 +3,7 @@ package dev.struchkov.godfather.telegram.main.context.convert; import dev.struchkov.godfather.main.domain.content.Mail; import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment; import org.telegram.telegrambots.meta.api.objects.CallbackQuery; +import org.telegram.telegrambots.meta.api.objects.MaybeInaccessibleMessage; import org.telegram.telegrambots.meta.api.objects.Message; import org.telegram.telegrambots.meta.api.objects.User; @@ -19,10 +20,12 @@ public class CallbackQueryConvert { final String callbackData = callbackQuery.getData(); final Mail mail = new Mail(); - mail.setId(callbackQuery.getMessage().getMessageId().toString()); + final MaybeInaccessibleMessage maybeInaccessibleMessage = callbackQuery.getMessage(); + + mail.setId(maybeInaccessibleMessage.getMessageId().toString()); mail.setCreateDate(LocalDateTime.now()); mail.setText(callbackData); - mail.addAttachment(convertToButtonClick(callbackData, callbackQuery.getMessage())); + mail.addAttachment(convertToButtonClick(callbackData, maybeInaccessibleMessage)); final Long chatId = callbackQuery.getFrom().getId(); mail.setFromPersonId(chatId.toString()); @@ -33,10 +36,13 @@ public class CallbackQueryConvert { return mail; } - private static ButtonClickAttachment convertToButtonClick(String callbackData, Message message) { + private static ButtonClickAttachment convertToButtonClick(String callbackData, MaybeInaccessibleMessage maybeInaccessibleMessage) { final ButtonClickAttachment buttonClickAttachment = new ButtonClickAttachment(); buttonClickAttachment.setRawCallBackData(callbackData); - buttonClickAttachment.setMessage(MessageMailConvert.apply(message)); + if (maybeInaccessibleMessage instanceof Message message) { + buttonClickAttachment.setMaybeInaccessibleMessage(MessageMailConvert.apply(message)); + } + if (callbackData.charAt(0) == '[' && callbackData.charAt(callbackData.length() - 1) == ']') { final String[] args = callbackData.substring(1, callbackData.length() - 1).split(";"); for (String arg : args) { diff --git a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/ButtonClickAttachment.java b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/ButtonClickAttachment.java index 9c2cc00..d7de9f4 100644 --- a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/ButtonClickAttachment.java +++ b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/ButtonClickAttachment.java @@ -19,7 +19,7 @@ import static dev.struchkov.haiti.utils.Inspector.isNotNull; public class ButtonClickAttachment extends Attachment { private String rawCallBackData; - private Mail message; + private Mail maybeInaccessibleMessage; private Map args = new HashMap<>(); @@ -27,6 +27,11 @@ public class ButtonClickAttachment extends Attachment { super(TelegramAttachmentType.BUTTON_CLICK.name()); } + @JsonIgnore + public Optional getMessage() { + return Optional.ofNullable(maybeInaccessibleMessage); + } + @JsonIgnore public void addClickArg(String type, String value) { isNotNull(type, value);