From adf003b51b1b573b5e3a1ccadd25cf1555fc17d3 Mon Sep 17 00:00:00 2001 From: Rob Moffat Date: Tue, 1 Feb 2022 10:59:18 +0000 Subject: [PATCH] Fixed Teams double-response issue #286 --- .DS_Store | Bin 6148 -> 6148 bytes .../history/StorageIDResponseHandler.java | 15 ++++++++++++++- .../messages/MessageActivityHandler.java | 8 +++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.DS_Store b/.DS_Store index 4c33048b4ad0609a40bfe40537c3344e64ff085d..301f2747008284cfc3fc6a06d11b0c44a38c6cfb 100644 GIT binary patch delta 30 mcmZoMXfc@J&&WD4U^gS{WFE#Dn~yR&u}v&c+|17LmmdI^n+e$f delta 56 zcmZoMXfc@J&&W10U^gS%WFE#DGMo%045dJv&rrmW$&kp9!%&=3oSc)CpP$3Hc_E`a K+h%r-zx)8UED!kr diff --git a/libs/teams/teams-chat-workflow-spring-boot-starter/src/main/java/org/finos/springbot/teams/history/StorageIDResponseHandler.java b/libs/teams/teams-chat-workflow-spring-boot-starter/src/main/java/org/finos/springbot/teams/history/StorageIDResponseHandler.java index 15c434232..1015ed7b6 100644 --- a/libs/teams/teams-chat-workflow-spring-boot-starter/src/main/java/org/finos/springbot/teams/history/StorageIDResponseHandler.java +++ b/libs/teams/teams-chat-workflow-spring-boot-starter/src/main/java/org/finos/springbot/teams/history/StorageIDResponseHandler.java @@ -2,9 +2,11 @@ import java.util.Map; +import org.finos.springbot.workflow.annotations.Work; import org.finos.springbot.workflow.response.Response; import org.finos.springbot.workflow.response.WorkResponse; import org.finos.springbot.workflow.response.handlers.ResponseHandler; +import org.finos.springbot.workflow.tags.TagSupport; /** * This class is responsible for generating a unique storage ID number and adding it @@ -30,12 +32,23 @@ public StorageIDResponseHandler(TeamsHistory th) { public void accept(Response t) { if (t instanceof WorkResponse) { Map data = ((WorkResponse) t).getData(); - if ((data != null) && (!data.containsKey(STORAGE_ID_KEY))) { + if ((data != null) && (!data.containsKey(STORAGE_ID_KEY)) && (needsStoring(data))) { data.put(STORAGE_ID_KEY, th.createStorageId()); } } } + private boolean needsStoring(Map data) { + for(Object o2: data.values()) { + Work w = o2 != null ? o2.getClass().getAnnotation(Work.class) : null; + if ((w != null) && (w.index())) { + return true; + } + } + + return false; + } + @Override public int getOrder() { return ResponseHandler.HIGHEST_PRECEDENCE; diff --git a/libs/teams/teams-chat-workflow-spring-boot-starter/src/main/java/org/finos/springbot/teams/messages/MessageActivityHandler.java b/libs/teams/teams-chat-workflow-spring-boot-starter/src/main/java/org/finos/springbot/teams/messages/MessageActivityHandler.java index f564d50ef..8ca572e35 100644 --- a/libs/teams/teams-chat-workflow-spring-boot-starter/src/main/java/org/finos/springbot/teams/messages/MessageActivityHandler.java +++ b/libs/teams/teams-chat-workflow-spring-boot-starter/src/main/java/org/finos/springbot/teams/messages/MessageActivityHandler.java @@ -60,6 +60,11 @@ public MessageActivityHandler( @Override protected CompletableFuture onMessageActivity(TurnContext turnContext) { + return CompletableFuture.completedFuture(null) + .thenRun(() -> handleActivity(turnContext)); + } + + protected void handleActivity(TurnContext turnContext) { try { Activity a = turnContext.getActivity(); @@ -81,9 +86,6 @@ protected CompletableFuture onMessageActivity(TurnContext turnContext) { } finally { CurrentTurnContext.CURRENT_CONTEXT.set(null); } - - // errors are handled using Spring's ErrorHandler rather than this. - return new CompletableFuture(); } protected FormAction processForm(TurnContext turnContext, Activity a) throws ClassNotFoundException {