Добавил общее действие перед отправкой для AnswerTextAction
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-02-17 21:37:21 +03:00
parent dc2051d85a
commit e5994c8052
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
5 changed files with 34 additions and 4 deletions

View File

@ -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);

View File

@ -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();
})

View File

@ -5,6 +5,6 @@ import io.smallrye.mutiny.Uni;
@FunctionalInterface
public interface ActionBeforeSending {
Uni<Void> execute();
Uni<Void> execute(String personId);
}

View File

@ -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);

View File

@ -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()) {