Добавление getOrCreateDuplicatedContext
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user