diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java index 8899aec..e598176 100644 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java @@ -30,20 +30,20 @@ import static java.util.Collections.emptySet; public class GeneralAutoResponder { - protected final PersonSettingService personSettingService; + protected PersonSettingService personSettingService; protected final StorylineService storyLineService; protected Map> actionUnitMap = new HashMap<>(); protected List> modifiable; protected ErrorHandler errorHandler; - protected GeneralAutoResponder( - PersonSettingService personSettingService, - StorylineService storyLineService - ) { - this.personSettingService = personSettingService; + protected GeneralAutoResponder(StorylineService storyLineService) { this.storyLineService = storyLineService; } + public void setPersonSettingService(PersonSettingService personSettingService) { + this.personSettingService = personSettingService; + } + public void registrationActionUnit(ActionUnit actionUnit) { actionUnitMap.computeIfAbsent(actionUnit.getUnitType(), k -> new ArrayList<>()); actionUnitMap.get(actionUnit.getUnitType()).add(actionUnit); @@ -67,17 +67,24 @@ public class GeneralAutoResponder { public Uni processingNewMessage(M newMessage) { return Uni.createFrom().item(newMessage) .onItem().ifNotNull().transformToUni( - message -> personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId()) - .replaceIfNullWith(TRUE) - .chain( - state -> { - if (TRUE.equals(state)) { - return processing(newMessage); - } - return Uni.createFrom().voidItem(); - } - ) - ).replaceWithVoid(); + message -> { + if (checkNotNull(personSettingService)) { + return personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId()) + .replaceIfNullWith(TRUE) + .flatMap( + state -> { + if (TRUE.equals(state)) { + return processing(newMessage); + } + return Uni.createFrom().voidItem(); + } + ); + } else { + return processing(newMessage); + } + } + ) + .replaceWithVoid(); } public Uni processingNewMessages(List newMessages) { @@ -89,18 +96,24 @@ public class GeneralAutoResponder { final Set personIds = newMessages.stream() .map(Message::getFromPersonId) .collect(Collectors.toSet()); - return personSettingService.getAllPersonIdDisableMessages(personIds) - .replaceIfNullWith(emptySet()) - .onItem().transformToMulti( - disableIds -> { - final List allowedMessages = newMessages.stream() - .filter(message -> !disableIds.contains(message.getFromPersonId())) - .toList(); - return Multi.createFrom().iterable(allowedMessages); - } - ) - .onItem().transform(this::processing) - .toUni().replaceWithVoid(); + if (checkNotNull(personSettingService)) { + return personSettingService.getAllPersonIdDisableMessages(personIds) + .replaceIfNullWith(emptySet()) + .onItem().transformToMulti( + disableIds -> { + final List allowedMessages = newMessages.stream() + .filter(message -> !disableIds.contains(message.getFromPersonId())) + .toList(); + return Multi.createFrom().iterable(allowedMessages); + } + ) + .onItem().transform(this::processing) + .collect().asList().replaceWithVoid(); + } else { + return Multi.createFrom().iterable(newMessages) + .onItem().transform(this::processing) + .collect().asList().replaceWithVoid(); + } } ); }