diff --git a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingBot.java b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingBot.java index c1f4a5f..77a800d 100644 --- a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingBot.java +++ b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingBot.java @@ -3,8 +3,11 @@ package dev.struchkov.godfather.telegram.quarkus.core; import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig; import dev.struchkov.godfather.telegram.quarkus.context.service.EventDistributor; import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot; +import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.infrastructure.Infrastructure; import io.vertx.core.Vertx; +import io.vertx.core.impl.ContextInternal; +import io.vertx.mutiny.core.Context; import lombok.SneakyThrows; import org.jetbrains.annotations.NotNull; import org.telegram.telegrambots.bots.DefaultBotOptions; @@ -13,7 +16,6 @@ import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.bots.AbsSender; import java.lang.reflect.Field; -import java.util.concurrent.Executors; /** * TODO: Добавить описание класса. @@ -53,11 +55,22 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr private void handleUpdate(Update update) { if (update != null && eventDistributor != null) { - eventDistributor.processing(update) + Uni.createFrom().voidItem() + .emitOn(command -> Context.newInstance(getOrCreateDuplicatedContext(vertx)).runOnContext(command)) + .replaceWith(() -> eventDistributor.processing(update)) .subscribe().asCompletionStage(); } } + public static io.vertx.core.Context getOrCreateDuplicatedContext(Vertx vertx) { + io.vertx.core.Context context = vertx.getOrCreateContext(); + if (((ContextInternal) context).isDuplicate()) { + return context; + } else { + return ((ContextInternal) context).duplicate(); + } + } + @Override public String getBotUsername() { return telegramBotConfig.getUsername();