Добавил общее действие перед отправкой для AnswerTextAction
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:
parent
dc2051d85a
commit
e5994c8052
@ -62,6 +62,10 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
this.modifiable = modifiable;
|
||||
}
|
||||
|
||||
public void initTextAnswerActionUnit(AnswerTextAction action) {
|
||||
actionUnitMap.put(TypeUnit.TEXT, action);
|
||||
}
|
||||
|
||||
public void initActionUnit(String typeUnit, ActionUnit<? extends MainUnit<M>, M> actionUnit) {
|
||||
if (!actionUnitMap.containsKey(typeUnit)) {
|
||||
actionUnitMap.put(typeUnit, actionUnit);
|
||||
|
@ -20,10 +20,16 @@ public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message
|
||||
|
||||
private final Sending sending;
|
||||
|
||||
private ActionBeforeSending actionBeforeSending;
|
||||
|
||||
public AnswerTextAction(Sending sending) {
|
||||
this.sending = sending;
|
||||
}
|
||||
|
||||
public void setActionBeforeSending(ActionBeforeSending actionBeforeSending) {
|
||||
this.actionBeforeSending = actionBeforeSending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uni<UnitRequest<MainUnit, Message>> action(UnitRequest<AnswerText<Message>, Message> unitRequest) {
|
||||
final Message message = unitRequest.getMessage();
|
||||
@ -31,9 +37,15 @@ public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message
|
||||
|
||||
return unit.getAnswer().processing(message)
|
||||
.onItem().ifNotNull().call(v -> {
|
||||
final ActionBeforeSending actionBeforeSending = unit.getActionBeforeSending();
|
||||
if (checkNotNull(actionBeforeSending)) {
|
||||
return actionBeforeSending.execute();
|
||||
return actionBeforeSending.execute(message.getPersonId());
|
||||
}
|
||||
return Uni.createFrom().nullItem();
|
||||
})
|
||||
.onItem().ifNotNull().call(v -> {
|
||||
final ActionBeforeSending unitActionBeforeSending = unit.getActionBeforeSending();
|
||||
if (checkNotNull(unitActionBeforeSending)) {
|
||||
return unitActionBeforeSending.execute(message.getPersonId());
|
||||
}
|
||||
return Uni.createFrom().nullItem();
|
||||
})
|
||||
|
@ -5,6 +5,6 @@ import io.smallrye.mutiny.Uni;
|
||||
@FunctionalInterface
|
||||
public interface ActionBeforeSending {
|
||||
|
||||
Uni<Void> execute();
|
||||
Uni<Void> execute(String personId);
|
||||
|
||||
}
|
||||
|
@ -61,6 +61,10 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
this.modifiable = modifiable;
|
||||
}
|
||||
|
||||
public void initTextAnswerActionUnit(AnswerTextAction action) {
|
||||
actionUnitMap.put(TypeUnit.TEXT, action);
|
||||
}
|
||||
|
||||
public void initActionUnit(String typeUnit, ActionUnit<? extends MainUnit<M>, M> actionUnit) {
|
||||
if (!actionUnitMap.containsKey(typeUnit)) {
|
||||
actionUnitMap.put(typeUnit, actionUnit);
|
||||
|
@ -24,10 +24,16 @@ public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message
|
||||
|
||||
private final Sending sending;
|
||||
|
||||
private ActionBeforeSending actionBeforeSending;
|
||||
|
||||
public AnswerTextAction(Sending sending) {
|
||||
this.sending = sending;
|
||||
}
|
||||
|
||||
public void setActionBeforeSending(ActionBeforeSending actionBeforeSending) {
|
||||
this.actionBeforeSending = actionBeforeSending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitRequest<MainUnit, Message> action(UnitRequest<AnswerText<Message>, Message> unitRequest) {
|
||||
final Message message = unitRequest.getMessage();
|
||||
@ -41,11 +47,15 @@ public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message
|
||||
|
||||
answer.setRecipientIfNull(message.getPersonId());
|
||||
|
||||
final ActionBeforeSending actionBeforeSending = unit.getActionBeforeSending();
|
||||
if (checkNotNull(actionBeforeSending)) {
|
||||
actionBeforeSending.execute(message.getPersonId());
|
||||
}
|
||||
|
||||
final ActionBeforeSending unitActionBeforeSending = unit.getActionBeforeSending();
|
||||
if (checkNotNull(unitActionBeforeSending)) {
|
||||
unitActionBeforeSending.execute(message.getPersonId());
|
||||
}
|
||||
|
||||
final Optional<? extends SentBox> optSentBox = sending.send(answer);
|
||||
final CallBackConsumer callBack = unit.getCallBack();
|
||||
if (checkNotNull(callBack) && optAnswer.isPresent()) {
|
||||
|
Loading…
Reference in New Issue
Block a user