From 0dccd5fce11502a39842557d5981ed2c81f58c9f Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 29 Aug 2022 14:09:33 -0500 Subject: [PATCH] Handle prev from completed or canceled properly Still show the close button (not a cancel button) on a completed or canceled flow that supports prev. --- .../conversations/entities/Conversation.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index b26d2c2fe2affdf540ee60f174146d1a4821fcb1..4ced6b4d72a55c6910b32e4e6982a4a89033b165 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -2057,11 +2057,17 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl // This is probably a spec violation, but we should do *something* actionsAdapter.add("execute"); } + + if (!actionsAdapter.isEmpty()) { + if (command.getAttribute("status").equals("completed") || command.getAttribute("status").equals("canceled")) { + actionsAdapter.add("close"); + } else if (actionsAdapter.getPosition("cancel") < 0) { + actionsAdapter.insert("cancel", 0); + } + } } - if (actionsAdapter.getCount() > 0) { - if (actionsAdapter.getPosition("cancel") < 0) actionsAdapter.insert("cancel", 0); - } else { + if (actionsAdapter.isEmpty()) { actionsAdapter.add("close"); } @@ -2250,12 +2256,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public boolean execute(String action) { - if (!action.equals("cancel") && !validate()) return false; + if (!action.equals("cancel") && !action.equals("prev") && !validate()) return false; if (response == null) return true; Element command = response.findChild("command", "http://jabber.org/protocol/commands"); if (command == null) return true; String status = command.getAttribute("status"); - if (status == null || !status.equals("executing")) return true; + if (status == null || (!status.equals("executing") && !action.equals("prev"))) return true; final IqPacket packet = new IqPacket(IqPacket.TYPE.SET); packet.setTo(response.getFrom()); @@ -2266,6 +2272,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl String formType = responseElement == null ? null : responseElement.getAttribute("type"); if (!action.equals("cancel") && + !action.equals("prev") && responseElement != null && responseElement.getName().equals("x") && responseElement.getNamespace().equals("jabber:x:data") &&